You are given an integer $$$n$$$ from $$$1$$$ to $$$10^{18}$$$ without leading zeroes.In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.What is the minimum number of moves you have to make to obtain a number that is divisible by $$$25$$$? Print -1 if it is impossible to obtain a number that is divisible by $$$25$$$.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^{18}$$$). It is guaranteed that the first (left) digit of the number $$$n$$$ is not a zero.

If it is impossible to obtain a number that is divisible by $$$25$$$, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number.

NoteIn the first example one of the possible sequences of moves is 5071 $$$\rightarrow$$$ 5701 $$$\rightarrow$$$ 7501 $$$\rightarrow$$$ 7510 $$$\rightarrow$$$ 7150.

def swap(ar,ind1,ind2):
    if ind2 > ind1:
        for i in range(ind1,ind2):
            temp = ar[i]
            ar[i] = ar[i+1]
            ar[i+1] = temp
    else:
        for i in range(ind1,ind2,-1):
            temp = ar[i]
            ar[i] = ar[i-1]
            ar[i-1] = temp

n = list(input())
n2 = len(n)
ans = 100
for i in range(n2):
    for j in range(n2):
        nc = [0]*n2
        for i2 in range(n2):
            nc[i2] = n[i2]
        swap(nc,i,n2-1)
        swap(nc,j,n2-2)
        num = 0
        for z in range(n2):
            if nc[z] != "0":
                num = z
                break
        swap(nc,0,num)
        if int("".join(nc)) % 25 == 0:
             ans = min(ans,abs(n2-2-j)+abs(n2-1-i)+num)

if ans == 100:
    print(-1)
else:
    print(ans)

def finder(n,ind):
    i=ind-1
    while(i>=0):
        if(n[i]=="0"):
            break
        else:
            i=i-1

    return(i)

def zeros(n):
    count=0
    pol=1
    while(pol<l):
        if(n[pol]=="0"):
            count=count+1
        else:
            break
        pol=pol+1

    return(count)

n=input()
ans=[]
l=len(n)

if("2" in n and "5" in n):
    c2=l-n.rfind("2")-2
    c5=l-n.rfind("5")-1

    if(c2<c5):
        k=c2+c5+1
    else:
        k=c2+c5

    if(n[0]=="2" or n[0]=="5"):
        k=k+zeros(n)

    ans.append(k)

if("5" in n and "0" in n):
    c5=l-n.rfind("5")-2
    c0=l-n.rfind("0")-1

    if(c5<c0):
        k=c5+c0+1
    else:
        k=c5+c0

    ans.append(k)

if("7" in n and "5" in n):
    c7=l-n.rfind("7")-2
    c5=l-n.rfind("5")-1

    if(c7<c5):
        k=c7+c5+1
    else:
        k=c7+c5

    if(n[0]=="7" or n[0]=="5"):
        k=k+zeros(n)

    ans.append(k)

if(n.count("0")>=2):
    c01=l-n.rfind("0")-2
    c02=l-finder(n,n.rfind("0"))-1

    ans.append(c01+c02)

if(int(n)%25==0):
    print(0)
elif(len(ans)==0):
    print(-1)
else:
    print(min(ans))

INF = 1000

def compute_pair(s, pair):
    n = len(s)
    try:
        l2 = s.rindex(pair[1])
        l1 = s.rindex(pair[0])
        if pair[0] == '0':
            l1 = s[:l2].rindex(pair[1])
    except:
        return INF

    steps = abs((n - 2) - l1) + abs((n - 1) - l2)
    if l1 > l2 and l1 != n - 1:
        steps += 1

    if l1 == n - 1:
        steps -= 1

    l1, l2 = min(l1, l2), max(l1, l2)
    new_s = s[:l1] + s[l1+1:l2] + s[l2+1:]
    if new_s.startswith('0'):
        for i, q in enumerate(new_s):
            if q != '0':
                steps += i
                break

    return steps

def main():
    s = input()
    best = INF
    if int(s) < 10:
        print(-1)
        return

    for pair in ['00', '25', '50', '75']:
        l = compute_pair(s, pair)
        if l < best:
            best = l

    if best == INF:
        best = -1

    print(best)

if __name__ == '__main__':
    main()

num = str(input())
n =len(num)
num_r = num[::-1]
s0, s5 = num_r.find('0'),num_r.find('5')
if s0 != -1:
    newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['0','5']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s0 = s0 + s
    else:
        s0 = 999999999
else:
    s0 = 999999999
if s5 != n-1 or num.find('0') != 1:
    if s5 != -1:
        newnum_r = num_r[:s5] + num_r[s5+1:]
        c= []
        for a in ['2','7']:
            if newnum_r.find(a) != -1:
                c.append(newnum_r.find(a))
        if c != []:
            s = min(c)
            s5 = s5 + s
        else:
            s5 = 999999999
    else:
        s5 = 999999999
    ssr = min(s0,s5)
    if ssr != 999999999:
        print(ssr)
    else:
        print(-1)
else:
    if s5 != -1:
        newnum_r = num_r[:s5] + num_r[s5+1:]
        c= []
        for a in ['2','7']:
            if newnum_r.find(a) != -1:
                c.append(newnum_r.find(a))
        if c != []:
            s = min(c)
            sk = 0
            for i in range(1,n-1):
                if num[i] == '0':
                    sk = sk + 1
                else:
                    break
            s5 = s5 + s + sk
        else:
            s5 = 999999999
    else:
        s5 = 999999999
    ssr = min(s0,s5)
    if ssr != 999999999:
        print(ssr)
    else:
        print(-1)

def go():
    s = input()
    n = len(s)
    if '5' not in s and '0' not in s:
        return -1
    k = ['00', '25', '50', '75']
    m = float('inf')
    for x in k:
        if x == '00' and s.count('0') > 1:
            first = s.rfind('0')
            second = s[:first].rfind('0')
            d = n - 1 - first + n - 2 - second
            m = min(m, d)
        elif x != '00' and x[0] in s and x[1] in s:
            first = s.rfind(x[0])
            second = s.rfind(x[1])
            d = n - 1 - second + n - 2 - first
            if second == 0:
                i = 1
                while s[i] == '0':
                    i += 1
                    d += 1
            if second < first:
                d += 1
            m = min(m, d)
    if float('inf') == m:
        return -1
    return m

print(go())

def go(n, c1, c2):
    l = len(n)
    pos2 = n.rfind(c2)
    pos1 = n.rfind(c1)
    if c1 == c2:
        pos1 = n[:pos2].rfind(c1)
    if pos1 == -1 or pos2 == -1:
        return 10 ** 10
    #print(pos1, pos2)
    nxt = 0
    if min(pos1, pos2) == 0:
        nxt = 1
        if max(pos1, pos2) == 1:
            nxt = 2
    ans = 0
    if nxt != l:
        while nxt < l and n[nxt] == '0':
            ans += 1
            nxt += 1
        if nxt == l:
            return 10 ** 10
    ans += l - pos2 - 1
    if pos1 > pos2:
        pos1 -= 1
    ans += (l - pos1 - 2)
    return ans

n = input()
ans = min([go(n, '2', '5'), go(n, '0', '0'), go(n, '7',  '5'), go(n, '5', '0')])
if ans == 10 ** 10:
    print(-1)
else:
    print(ans)

def main():
    ar = list(input())
    size = len(ar)
    ans = 1e5
    for i in range(size):
        for j in range(size):
            if i == j:
                continue
            s = list(ar)
            cost = 0
            for k in range(i, size - 1):
                tmp = s[k]
                s[k] = s[k + 1]
                s[k + 1] = tmp
                cost += 1
            if i < j:
                for k in range(j - 1, size - 2):
                    tmp = s[k]
                    s[k] = s[k + 1]
                    s[k + 1] = tmp
                    cost += 1
            else:
                for k in range(j, size - 2):
                    tmp = s[k]
                    s[k] = s[k + 1]
                    s[k + 1] = tmp
                    cost += 1
            pos = -1
            for k in range(size):
                if s[k] != '0':
                    pos = k
                    break
            for k in range(pos, 0, -1):
                tmp = s[k]
                s[k] = s[k - 1]
                s[k - 1] = tmp
                cost += 1
            curr_num = int(''.join(s))
            if curr_num % 25 == 0:
                ans = min(ans, cost)
    if ans == 1e5:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()

s = input()

globans = 10 ** 9

for i_ in range(len(s)):
    for j_ in range(len(s)):
        i = i_
        j = j_

        if j == i:
            continue

        if i == len(s) - 1:
            ans = abs(len(s) - j - 1)
        else:
            ans = abs(len(s) - i - 2) + abs(len(s) - j - 1) + int(j < i)

        if i > j:
            i, j = j, i

        nw = s[:i] + s[i + 1:j] + s[j + 1:] + s[i_] + s[j_]

        for x in range(len(s)):
            if nw[x] == "0":
                continue
            ans += x
            nw = nw[x] + nw[:x] + nw[x + 1:]
            break

        if int(nw) % 25 == 0:
            globans = min(globans, ans)

if globans == 10 ** 9:
    print(-1)
else:
    print(globans)

z=input()
n=len(z)
maxa=10**18
y=int(z)
if(y%25==0):
    print(0)
    quit()
if(n==1):
    print(-1)
    quit()
for i in range(n):
    for j in range(n):
        if(i==j):
            continue
        copy=list(z)
        swaps=0
        for k in range(i,n-1):
            copy[k],copy[k+1]=copy[k+1],copy[k]
            swaps+=1
        if(j>i):
            j-=1
        for k in range(j,n-2):
            copy[k],copy[k+1]=copy[k+1],copy[k]
            swaps+=1
        if((10*(ord(copy[n-2])-48)+(ord(copy[n-1])-48))%25):
            continue
        if(copy[0]=='0'):
            done=0
            for yo in range(n-2):
                if(copy[yo]!='0'):
                    done=1
                    swaps+=(yo)
                    break
            if(done):
                maxa=min(maxa,swaps)
            else:
                continue
        maxa=min(maxa,swaps)
if(maxa==10**18):
    print(-1)
else:
    print(maxa)

n=int(input())
l=(list(str(n)))[::-1]
g=[]
def verif(l):
    if l[-1]!='0':return(0)
    else: return(1+verif(l[:-1]))
def permut(l,c,c1):
    i=l.copy()
    k=0
    while(True):
        if i.index(c)==0:break
        else:
            j=i.index(c)
            i[j],i[j-1]=i[j-1],i[j]
            k+=1
    m=i[1:]
    while(True):
        if m.index(c1)==0:break
        else:
            j=m.index(c1)
            m[j],m[j-1]=m[j-1],m[j]
            k+=1
    k+=verif(i)
    return(k)

if (('2'in l) and ('5' in l)):
    g.append(permut(l,'5','2'))
if (('5'in l) and ('0' in l)):
    g.append(permut(l,'0','5'))
if (('7'in l) and ('5' in l)):
    g.append(permut(l,'5','7'))
if l.count('0')>1:
    g.append(permut(l,'0','0'))
if g==[]:print(-1)
else:print(min(g))

k = input()
import sys
Min = sys.maxsize
if '5' in k and '0' in k:
    temp = (len(k)-2) - k.rfind('5') + (len(k)-1) - k.rfind('0')
    if (k.rfind('5') > k.rfind('0')):
        add = 0
        i = 1
        while k[i] == '0':
            add += 1
            i += 1
        temp += add
    if (temp<Min):
        Min = temp
if '2' in k and '5' in k:
    temp = (len(k)-2) - k.rfind('2') + (len(k)-1) - k.rfind('5')
    if k.rfind('5')==0 and k[1]=='0' and len(k)>3:
        add = 0
        i = 1
        while k[i] == '0':
            add += 1
            i += 1
        temp += add
    if (k.rfind('2') > k.rfind('5')):
        temp += 1
    if (temp<Min):
        Min = temp
if '7' in k and '5' in k:
    temp = (len(k)-2) - k.rfind('7') + (len(k)-1) - k.rfind('5')
    if k.rfind('5')==0 and k[1]=='0' and len(k)>3:
        add = 0
        i = 1
        while k[i] == '0':
            add += 1
            i += 1
        temp += add
    if (k.rfind('7') > k.rfind('5')):
        temp += 1
    if (temp<Min):
        Min = temp
if k.count('0')>1:
    css = k.rfind('0')
    temp = (len(k)-1) - css
    k = k[:css] + k[css+1:]
    temp += (len(k)-1) - k.rfind('0')
    if (temp<Min):
        Min = temp
if Min==sys.maxsize:
    print(-1)
else:
    print(Min)

import sys
import queue

INFINITY = 10**10

def main():
    n = input()
    print(solve(n))

def solve(n):
    if int(n) < 1000:
        return brute(n)

    forward = min([calc(str(n), last_digits) for last_digits in ["00", "25", "50", "75"]])
    reverse = min([calc(str(n), last_digits) + 1 for last_digits in ["52", "05", "57"]])
    res = min(forward, reverse)

    if res >= INFINITY:
        res = -1

    return res

def calc(n, last_digits):
    if not last_digits:
        return 0

    idx = n.rfind(last_digits[-1])
    if idx == -1:
        return INFINITY

    res = len(n) - idx - 1
    n = n[:idx] + n[(idx+1):]
    last_digits = last_digits[:-1]

    extra = 0
    if n and n[0] == '0':
        idx = len(n)
        for digit in "123456789":
            if n.find(digit) != -1:
                idx = min(idx, n.find(digit))

        if idx == len(n):
            return idx

        n = swap(n, 0, idx)
        extra = idx

    return res + calc(n, last_digits) + extra

def brute(n):
    q = queue.Queue()
    dis = dict()

    q.put(str(n))
    dis[str(n)] = 0

    while not q.empty():
        s = q.get()
        if int(s) % 25 == 0:
            return dis[s]

        for i in range(1, len(s)):
            j = i - 1
            t = swap(s, i, j)

            if t not in dis and t[0] != '0':
                dis[t] = dis[s] + 1
                q.put(t)

    return -1

def swap(s, i, j):
    chars = list(s)
    chars[i], chars[j] = chars[j], chars[i]
    return "".join(char for char in chars)

if __name__ == '__main__':
    main()

def digits(n):
	return len(str(n))

def digit(n, i):
	if i < digits(n):
		return int(str(n)[digits(n) - i - 1])

	return 0

def swap_digits(n, i, j):
	return n + digit(n, i) * (10**j - 10**i) + digit(n, j) * (10**i - 10**j)

n = int(input())

if n % 25 == 0:
	print(0)
	exit()

ans = []

for i in range(digits(n)):
	for j in range(digits(n)):
		if i == j:
			continue

		x, y, cur, cur_ans = i, j, n, 0

		if y > x:
			x += 1

		while y > 0:
			cur = swap_digits(cur, y, y - 1)
			y -= 1
			cur_ans += 1

		while x > 1:
			cur = swap_digits(cur, x, x - 1)
			x -= 1
			cur_ans += 1

		for k in range(digits(n), -1, -1):
			if digit(cur, k) != 0:
				cur_ans += (digits(n) - 1) - k
				break

		if cur % 25 == 0:
			ans.append(cur_ans)

print(min(ans) if len(ans) != 0 else -1)

s=input()
arr=[]
for i in s:
	arr.append(i)
ans=100000000000
for i in range(len(s)):
	for j in range(len(s)):
		if i==j:
			continue
		t=arr[:]
		# print('t ori',''.join(t))
		curr=0
		for k in range(i,len(s)-1):
			tt=t[k]
			t[k]=t[k+1]
			t[k+1]=tt
			curr+=1
		# print("t",''.join(t))
		tey=0
		if j>i:
			tey+=1
		for k in range(j-tey,len(s)-2,1):
			tt=t[k]
			t[k]=t[k+1]
			t[k+1]=tt
			curr+=1
		# print("t1",''.join(t))
		pos=-1
		for k in range(len(s)):
			if t[k]!='0':
				pos=k
				break
		for k in range(pos,0,-1):
			tt=t[k]
			t[k]=t[k-1]
			t[k-1]=tt
			curr+=1
		# print("t2",''.join(t))
		if int(''.join(t))%25==0:
			ans=min(ans,curr)
if ans==100000000000:
	ans=-1
print(ans)

from sys import stdin, stdout

def calcSwaps(num, pos0, pos1, tam) :
    num = list(num)
    res = 2 * tam - pos0 - pos1 - 3;

    #invertidos
    if (pos1 < pos0):
        res +=1

    idx = pos1
    while (idx < tam - 1):
        num[idx], num[idx + 1] = num[idx + 1], num[idx]
        idx += 1

    idx = pos0
    if (pos1 < pos0):
        idx -= 1
    while (idx < tam - 2):
        num[idx], num[idx + 1] = num[idx + 1], num[idx]
        idx += 1

    idx = 0
    while (idx < tam and num[idx] == '0'):
        res += 1
        idx += 1

    return res;

def solve(num):
    nums = ['2', '5', '7']
    pos = [-1, -1, -1]
    pos0 = []
    tam = len(num)
    for i, val in enumerate(num):
        if (val == '0'):
            pos0.append(i)
            continue
        for j, dig in enumerate(nums):
            if (dig == val):
                pos[j] = i
                break

    cnt = sum([1 for x in pos if x > -1])
    if (cnt == 0 and len(pos0) < 2):
        return -1

    res = tam * 2
    if (len(pos0) > 1): #00
        res = min(res, calcSwaps(num, pos0[-2], pos0[-1], tam))

    if (pos[0] > -1 and pos[1] > -1): #25
        res = min(res, calcSwaps(num, pos[0], pos[1], tam))

    if (pos[1] > -1 and len(pos0) > 0): #50
        res = min(res, calcSwaps(num, pos[1], pos0[-1], tam))

    if (pos[2] > -1 and pos[1] > -1): #75
        res = min(res, calcSwaps(num, pos[2], pos[1], tam))

    if res == tam *2:
        res = -1

    return res

def main():
    lines = stdin.readlines()
    for line in lines:
        res = solve(line.strip())

        stdout.write(str(res))
        stdout.write("\n")

main()

s = input()

if int(s)%25 == 0:
    print(0)
else:
    sols = []
    d = {}
    n = list(s)
    nr = s[::-1]
    for c in ('0', '2', '5', '7'):
        p = nr.find(c)
        d[c] = p

    for c1, c2 in (('2', '5'),('5', '0') , ('7', '5')):
        if c1 not in n or c2 not in n:
            continue

        dc1 = d[c1]
        dc2 = d[c2]
        sol = 0

        if dc1 == len(n) - 1 and len(n)>1 and n[1] == '0':
            i = 1
            while i<len(n) and (n[i] == '0' or dc2 == i ):
                i+=1
            if i!=len(n):
                i-=1
                sol = i
                dc1 -= 1
                if dc2 > len(n) -i -1:
                    dc2 -= 1

        if dc2 == len(n) - 1 and len(n)>1 and n[1] == '0':

            i = 1
            while i<len(n) and (n[i] == '0' or dc1 == i ):
                i+=1
            if i!=len(n):

                sol = i
                dc2 -= 1
                if dc1 > len(n) -i -1:
                    dc1 -= 1

        if dc1 == 0:
            sols.append(dc2 + sol)
            continue

        if dc1 < dc2:
            sols.append(dc2 + dc1 + sol)

        else:
            sols.append(dc2 + dc1 - 1 + sol)

    z1 = nr.find('0')
    if z1!=-1:
        z2 = nr.find('0', z1+1)
        if z2 != -1:
            sols.append(z1 + z2 - 1)
    if len(sols) == 0:
        print(-1)
    else:
        print(min(sols))

n=input()
#25
if('2' not in n or '5' not in n):a=10**18
else:
    a=0
    i=len(n)-1
    while n[i]!='5':
        i-=1
        a+=1
    updated_n=n[0:i]+n[i+1:]
    i=len(n)-2
    while updated_n[i]!='2':
        i-=1
        a+=1
    updated_n=updated_n[0:i]+updated_n[i+1:]
    for i in range(len(updated_n)):
        if(updated_n[i]!='0'):
            break
    a+=i
#75
if('7' not in n or '5' not in n):b=10**18
else:
    b=0
    i=len(n)-1
    while n[i]!='5':
        i-=1
        b+=1
    updated_n=n[0:i]+n[i+1:]
    i=len(n)-2
    while updated_n[i]!='7':
        i-=1
        b+=1
    updated_n=updated_n[0:i]+updated_n[i+1:]
    for i in range(len(updated_n)):
        if(updated_n[i]!='0'):
            break
    b+=i
#50
if('5' not in n or '0' not in n):c=10**18
else:
    c=0
    i=len(n)-1
    while n[i]!='0':
        i-=1
        c+=1
    updated_n=n[0:i]+n[i+1:]
    i=len(n)-2
    while updated_n[i]!='5':
        i-=1
        c+=1
    updated_n=updated_n[0:i]+updated_n[i+1:]
    for i in range(len(updated_n)):
        if(updated_n[i]!='0'):
            break
    c+=i
#00
if(n.count('0')<2):d=10**18
else:
    d=0
    i=len(n)-1
    while n[i]!='0':
        i-=1
        d+=1
    updated_n=n[0:i]+n[i+1:]
    i=len(n)-2
    while updated_n[i]!='0':
        i-=1
        d+=1
    updated_n=updated_n[0:i]+updated_n[i+1:]
    for i in range(len(updated_n)):
        if(updated_n[i]!='0'):
            break
    d+=i
ans=min(a,b,c,d)
if(ans==10**18):print(-1)
else:print(ans)

k = input()
zeroes = [-1, -1]
five = -1
two = -1
seven = -1
for i in range(len(k)):
    if k[i] == '0':
        zeroes[zeroes.index(min(zeroes))] = i
    elif k[i] == '2':
        two = i
    elif k[i] == '5':
        five = i
    elif k[i] == '7':
        seven = i
if len(k) == 3 and k[:2] == '50' and k[-1] != '5' and k[-1] != '0':
    print(2)
elif k == '5020' or k == '5070':
    print(1)
elif k[-2:] == '25' or k[-2:] == '00' or k[-2:] == '50' or k[-2:] == '75':
    print(0)
elif k[-2:] == '52' or k[-2:] == '05' or k[-2:] == '57':
    print(1)
elif k == '505':
    print(1)
elif k == '500':
    print(0)
elif len(k) != 4 and ((k[:3] == '502' and two == 2) or (k[:3] == '507' and seven == 2)):
    print((len(k)))
elif (len(k) == 4) and (k[:3] == '502' or k[:3] == '507'):
    print(4)
elif k[:2] == '50' and five == 0 and min(zeroes) == -1 and (seven != -1 or two != -1):
    print(2 * len(k) - max(two, seven) - 1)
elif k[:2] == '50' and five == 0 and min(zeroes) != -1 and (seven != -1 or two != -1):
    cnt0 = 0
    for u in range(1, len(k)):
        if k[u] == '0':
            cnt0 += 1
    print(min((len(k) * 2 - zeroes[0] - zeroes[1] - 3), (cnt0 - 1 + len(k))))
else:
    ch = []
    fl = 0
    if min(zeroes) > -1:
        fl = 1
        ch.append(len(k) * 2 - zeroes[0] - zeroes[1] - 3)
    if five != -1 and max(zeroes) > -1:
        fl = 1
        if five < (max(zeroes)):
            ch.append(2 * len(k) - max(zeroes) - five - 3)
        else:
            ch.append(2 * len(k) - max(zeroes) - five - 2)
    if five != -1:
        if two != -1:
            fl = 1
            if two < five:
                ch.append(2 * len(k) - two - five - 3)
            else:
                ch.append(2 * len(k) - two - five - 2)
        if seven != -1:
            fl = 1
            if seven < five:
                ch.append(2 * len(k) - seven - five - 3)
            else:
                ch.append(2 * len(k) - seven - five - 2)
    if fl:
        print(min(ch))
    else:
        print(-1)

import sys
range = xrange
input = raw_input

x = int(input())

xs = str(x)
if xs.count('0')<2 and \
  (xs.count('2') + xs.count('5')) < 2 and \
  (xs.count('5') + xs.count('0')) < 2 and \
  (xs.count('7') + xs.count('5')) < 2:
    print '-1'
    sys.exit()

def f(x,d):
    sx = str(x)
    n = len(sx)
    if sx[-2:] in ('00','25','50','75'):
        return 0

    if d<0: return 100

    besta = 100
    for i in range(len(sx)-1):
        if sx[i] in '0257':
            if sx[i] in '50':
                inter = [n-2,n-1]
            else:
                inter = [n-2]
            for j in inter:
                if i>=j:continue
                if (i!=0 or sx[i+1]!='0'):
                    besta = min(besta, j-i + f(int(''.join((sx[:i],sx[i+1:j+1],sx[i],sx[j+1:]))), d-1))

        if i!=0 and sx[i]!='0' and sx[i-1]=='0':
            j = i-1
            while sx[j] == '0':
                j -= 1
            i,j = j+1,i
            besta = min(besta, j-i + f(int(''.join((sx[:i]+sx[j]+sx[i:j],sx[j+1:]))), d-1))

    return besta

best = f(x,3)

if best >= 100:
    print -1
else:
    print best

l = [int(e) for e in input().strip()]

def lei00(l):
    result = []
    for i in range(len(l)-1, -1, -1):
        if l[i] == 0:
            result.append(i)
        if len(result) == 2:
            break
    if len(result) < 2:
        return None
    return 2 * len(l) - result[0] - result[1] - 3

def lei(l, x, y):
    assert x != y

    ix = None
    iy = None

    for i in range(len(l)-1, -1, -1):
        if l[i] == x and ix == None:
            ix = i
        elif l[i] == y and iy == None:
            iy = i

        if ix != None and iy != None:
            break

    if ix == None or iy == None:
        return None

    result = 2 * len(l) - ix - iy - 3

    if ix > iy:
        result += 1

    if x == 7 or x == 2:
        assert y == 5
        if iy == 0 and l[1] == 0:
            if len(l) >= 4:
                iii = 1
                while True:
                    iii += 1
                    if l[iii] != 0:
                        break
                result += iii-1
            if len(l) == 3:
                return None

    return result

l = [lei00(l), lei(l, 5, 0), lei(l, 7, 5), lei(l, 2, 5)]

result = None
for e in l:
    if e == None:
        continue
    if result == None or result > e:
        result = e

if result == None:
    print(-1)
else:
    print(result)

import itertools
import io
import os

input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def move(s, prev, next):

    cost = abs(prev - next)

    s = list(s)
    old = s[prev]
    s = s[:prev] + s[prev+1:]
    s = s[:next] + [old] + s[next:]
    s = "".join(s)

    return cost, s

n = int(input())

st = str(n)
l = len(st)

if l == 1:
    print(-1)
    exit()

best = 10**5
for p1, p2, p3 in itertools.product(range(l), repeat=3):
    s = str(st)
    # p1 to front, p2 to back, p3 to second-to-back
    if s[p1] == 0:
        continue

    p1_cost, s = move(s, p1, 0)
    if s[0] == "0":
        continue
    p2_cost, s = move(s, p2, l-1)
    if s[0] == "0":
        continue
    p3_cost, s = move(s, p3, l-2)
    if s[0] == "0":
        continue

    if s[-2:] in ["00", "25", "50", "75"]:
        best = min(best, p1_cost + p2_cost + p3_cost)
        #print(p1_cost + p2_cost + p3_cost, p1, p2, p3, s)
if best == 10**5:
    print(-1)
else:
    print(best)

n = input()
#if int(n) % 25 == 0:
#	print(0)
#	quit()

n = list(n)
if (not("5" in n)) and (not("0" in n)) and (not("7" in n)) and (not("2" in n)):
	print(-1)
	quit()

wkn = []
wkn[:] = n
ans = -1
for i in reversed(range(len(n))):
	if (n[i] == "0"):
		wk1 = n[:i] + n[i + 1:] + [n[i]]
		ans = len(n) - i - 1
		if wk1[0] != "0":
			n[:] = wk1
			break
		else:
			count = 0
			f1 = True
			for j in wk1:
				count += 1
				if j != "0":
					f1 = False
					break
			if f1:
				ans = -1
				break
			ans += count - 1
			wk1 = [wk1[count - 1]] + wk1[:count - 1] + wk1[count:]
			n[:] = wk1
			break

if ans != -1:
	f = True
	for i in reversed(range(len(n) - 1)):
		if (n[i] == "0") or (n[i] == "5"):
			wk1 = n[:i] + n[i + 1:-1] + [n[i]]
			ans += len(n) - i - 2
			if wk1[0] != "0":
				f = False
				break
			else:
				count = 0
				f1 = True
				for j in wk1:
					count += 1
					if j != "0":
						f1 = False
						break
				if f1:
					ans = -1
					break
				ans += count - 1
				f = False
				break
	if f:
		ans = -1

wkans = ans

ans = -1
n = wkn
for i in reversed(range(len(n))):
	if (n[i] == "5"):
		wk1 = n[:i] + n[i + 1:] + [n[i]]
		ans = len(n) - i - 1
		if wk1[0] != "0":
			n[:] = wk1
			break
		else:
			count = 0
			f1 = True
			for j in wk1:
				count += 1
				if j != "0":
					f1 = False
					break
			if f1:
				ans = -1
				break
			ans += count - 1
			wk1 = [wk1[count - 1]] + wk1[:count - 1] + wk1[count:]
			n[:] = wk1
			break

if ans != -1:
	f = True
	for i in reversed(range(len(n) - 1)):
		if (n[i] == "7") or (n[i] == "2"):
			wk1 = n[:i] + n[i + 1: -1] + [n[i]]
			ans += len(n) - i - 2
			if wk1[0] != "0":
				f = False
				break
			else:
				count = 0
				f1 = True
				for j in wk1:
					count += 1
					if j != "0":
						f1 = False
						break
				if f1:
					ans = -1
					break
				ans += count - 1
				f = False
				break
	if f:
		ans = -1

if (wkans == -1):
	print(ans)
	quit()
if (ans == -1):
	print(wkans)
	quit()
print(min(ans, wkans))

import bisect
import math
import sys
from collections import deque

#input = sys.stdin.readline

def main():
    s = list(input())

    def check(last_but_one, last):
        t = s.copy()
        n = len(t)
        res = 0

        pos_last = n-1
        while pos_last >= 0 and t[pos_last] != last:
            pos_last -= 1
        if pos_last < 0:
            return False
        while pos_last < n-1:
            t[pos_last], t[pos_last+1] = t[pos_last+1], t[pos_last]
            res += 1
            pos_last += 1

        pos_last_but_one = n-2
        while pos_last_but_one >= 0 and t[pos_last_but_one] != last_but_one:
            pos_last_but_one -= 1
        if pos_last_but_one < 0:
            return False
        while pos_last_but_one < n-2:
            t[pos_last_but_one], t[pos_last_but_one+1] = t[pos_last_but_one+1], t[pos_last_but_one]
            res += 1
            pos_last_but_one += 1

        if t[-1] != last or t[-2] != last_but_one:
            return False

        pos = 0
        while pos < n and t[pos] == '0':
            pos += 1
        if pos == n:
            return False

        while pos > 0:
            t[pos-1], t[pos] = t[pos], t[pos-1]
            pos -= 1
            res += 1

        if t[-1] != last or t[-2] != last_but_one:
            return False

        return res

    if len(s) == 1:
        print(-1)
    else:
        ans = math.inf
        for a, b in (('0', '0'), ('2', '5'), ('5', '0'), ('7', '5')):
            if a == s[-2] and b == s[-1]:
                ans = 0
                break
            ver = check(a, b)
            if ver:
                ans = min(ans, ver)
        print(-1 if ans == math.inf else ans)

if __name__ == '__main__':
    main()

a=str(raw_input())
if ('5' in a and '0' in a) or ('7' in a and '5' in a) or ('2' in a and '5' in a) or (a.count('0')>=2):
    res=[]
    if '5' in a and '0' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('0')
        a1.remove('0')
        a1.insert(0,'0')
        r+=a1.index('5')-1
        a1.remove('5')
        a1.remove('0')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if '7' in a and '5' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('5')
        a1.remove('5')
        a1.insert(0,'5')
        r+=a1.index('7')-1
        a1.remove('7')
        a1.remove('5')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if '2' in a and '5' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('5')
        a1.remove('5')
        a1.insert(0,'5')
        r+=a1.index('2')-1
        a1.remove('2')
        a1.remove('5')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if a.count('0')>=2:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('0')
        a1.remove('0')
        r+=a1.index('0')
        a1.remove('0')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if len(res)>0:
        print min(res)
    else:
        print -1

else:
    print -1

def main():
    ar = list(input())
    size = len(ar)
    ans = 1e5
    for i in range(size):
        for j in range(size):
            if i == j:
                continue
            s = list(ar)
            cost = 0
            for k in range(i, size - 1):
                tmp = s[k]
                s[k] = s[k + 1]
                s[k + 1] = tmp
                cost += 1
            if i < j:
                for k in range(j - 1, size - 2):
                    tmp = s[k]
                    s[k] = s[k + 1]
                    s[k + 1] = tmp
                    cost += 1
            else:
                for k in range(j, size - 2):
                    tmp = s[k]
                    s[k] = s[k + 1]
                    s[k + 1] = tmp
                    cost += 1
            pos = -1
            for k in range(size):
                if s[k] != '0':
                    pos = k
                    break
            for k in range(pos, 0, -1):
                tmp = s[k]
                s[k] = s[k - 1]
                s[k - 1] = tmp
                cost += 1
            curr_num = int(''.join(s))
            if curr_num % 25 == 0:
                ans = min(ans, cost)
    if ans == 1e5:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()

A_str = input()

A = list(A_str)

B = [
    ['2', '5'],
    ['5', '0'],
    ['7', '5']
]

result = 10**9

if int(A_str) % 100 == 0:
    print(0)
else:
    for a, b in B:
        if a not in A or b not in A:
            continue

        cresult = 0

        tmp_str = A_str[:]
        i = tmp_str.rfind(b)
        cresult += len(tmp_str) - 1 - i
        tmp_str = ''.join(A[:i] + A[i + 1:] + [A[i]])

        i = tmp_str.rfind(a)
        cresult += len(tmp_str) - 2 - i
        tmp_str = list(tmp_str)
        tmp_str = ''.join(tmp_str[:i] + tmp_str[i + 1:-1] + [tmp_str[i]] + [tmp_str[-1]])

        for i in range(len(tmp_str)):
            if tmp_str[i] != '0':
                break

        result = min([result, cresult + i])

    if A.count('0') > 1:
        cresult = 0
        i = A_str.rfind('0')
        cresult += len(A_str) - 1 - i
        A_str = A_str[:i] + A_str[i + 1:] + A[i]
        i = A_str[:-1].rfind('0')
        cresult += len(A_str) - 2 - i

        result = min([result, cresult])

    if result < 10**9:
        print(result)
    else:
        print(-1)

s = raw_input().strip()
n = len(s)
ans = float('inf')

# steps to get 00
idxlist = []
for i in xrange(n - 1, -1, -1):
    if s[i] == '0':
        idxlist.append(i)

    if len(idxlist) == 2: break

if len(idxlist) == 2:
    p1, p2 = idxlist
    ans = min(ans, (n - 1 - p2) + (n - 2 - p1))

# steps to get to 25
p2, p5 = -1, -1
fl = 0
cur = -1
for i in xrange(n - 1, -1, -1):
    if s[i] == '5' and p5 == -1:
        p5 = i
    if s[i] == '2' and p2 == -1:
        p2 = i
    if p2 != -1 and p5 != -1:
        cur = (n - 1 - p5) + (n - 2 - p2)
        if p5 < p2: cur += 1
        fl = 1
        break

if fl == 1:
    news = []
    for i in xrange(n):
        if i == p2 or i == p5: continue
        news.append(s[i])

    if len(news) == 0: ans = min(ans, cur)

    i = 0
    while i < len(news) and news[i] == '0': i += 1
    if i != len(news):
        ans = min(ans, cur + i)

# steps to get to 50
p5, p0 = -1, -1
fl = 0
cur = -1
for i in xrange(n - 1, -1, -1):
    if s[i] == '0' and p0 == -1:
        p0 = i
    if s[i] == '5' and p5 == -1:
        p5 = i
    if p5 != -1 and p0 != -1:
        cur = (n - 1 - p0) + (n - 2 - p5)
        if p0 < p5: cur += 1
        fl = 1
        break

if fl == 1:
    news = []
    for i in xrange(n):
        if i == p0 or i == p5: continue
        news.append(s[i])

    if len(news) == 0: ans = min(ans, cur)

    i = 0
    while i < len(news) and news[i] == '0': i += 1
    if i != len(news):
        ans = min(ans, cur + i)

# steps to get to 75
p7, p5 = -1, -1
fl = 0
cur = -1
for i in xrange(n - 1, -1, -1):
    if s[i] == '5' and p5 == -1:
        p5 = i
    if s[i] == '7' and p7 == -1:
        p7 = i
    if p7 != -1 and p5 != -1:
        cur = (n - 1 - p5) + (n - 2 - p7)
        if p5 < p7: cur += 1
        fl = 1
        break

if fl == 1:
    news = []
    for i in xrange(n):
        if i == p7 or i == p5: continue
        news.append(s[i])

    if len(news) == 0: ans = min(ans, cur)

    i = 0
    while i < len(news) and news[i] == '0': i += 1
    if i != len(news):
        ans = min(ans, cur + i)

if ans == float('inf'):
    print -1
else:
    print ans

import sys
n = int(input())

if n % 25 == 0:
    print(0)
else:
    tmp = n
    digits = [0]*10
    while (tmp):
        digits[tmp % 10] += 1
        tmp //= 10

    s = str(n)
    length = len(s)
    leading_zero_inc = 0
    for i in range(1, length):
        if s[i] != '0':
            leading_zero_inc = i
            break
    # print(leading_zero_inc)
    ans = sys.maxsize

    if digits[0] >= 2:
        i = s.rfind('0')
        j = s.rfind('0', 0, i)
        i = length-1-i
        j = length-2-j
        # print(i,j)
        ans = min(ans, i+j)

    if digits[2] >= 1 and digits[5] >= 1:
        i = s.rfind('2')
        j = s.rfind('5')
        inc = False
        if j < i: inc = True
        if i == 0:
            i = length-3+leading_zero_inc
        else:
            i = length-2-i
        if j == 0:
            j = length-2+leading_zero_inc
        else:
            j = length-1-j
        # print(i,j)
        ans = min(ans, i+j+inc)

    if digits[5] >= 1 and digits[0] >= 1:
        i = s.rfind('5')
        j = s.rfind('0')
        inc = False
        if j < i: inc = True

        if i == 0 and j != 1:
            i = length-3+leading_zero_inc
        else:
            i = length-2-i
        j = length-1-j
        # print(i,j)
        ans = min(ans, i+j+inc)

    if digits[7] >= 1 and digits[5] >= 1:
        i = s.rfind('7')
        j = s.rfind('5')
        inc = False
        if j < i: inc = True

        if i == 0:
            i = length-3+leading_zero_inc
        else:
            i = length-2-i
        if j == 0:
            j = length-2+leading_zero_inc
        else:
            j = length-1-j
        # print(i,j)
        ans = min(ans, i+j+inc)

    if ans == sys.maxsize:
        ans = -1
    print(ans)

def idx(s, c, start = 0):
    try:
        return s[::-1].index(c, start)
    except:
        return -1

def main():
    s = input()
    zero_cnt = 0
    while zero_cnt < len(s) - 1 and s[zero_cnt + 1] == '0':
        zero_cnt += 1

    i01 = idx(s, '0')
    i02 = idx(s, '0', i01 + 1)
    i2 = idx(s, '2')
    i5 = idx(s, '5')
    i7 = idx(s, '7')

    r = 666
    if i01 != -1 and i02 != -1:
        r = min(r, i01 + (i02 - 1))
    if i2 != -1 and i5 != -1:
        r = min(r, i2 + i5 - int(i2 > i5) + int((i2 == len(s) - 1 or i5 == len(s) - 1) and zero_cnt))
    if i5 != -1 and i01 != -1:
        # if there are more than 2 0s this one would never be the final answer
        r = min(r, i5 + i01 - int(i5 > i01))
    if i7 != -1 and i5 != -1:
        # 1 and 3 --> 3
        r = min(r, i7 + i5 - int(i7 > i5) + int((i7 == len(s) - 1 or i5 == len(s) - 1) and zero_cnt))

    print(r if r != 666 else -1)

if __name__ == '__main__':
    main()

import sys
num = input()
length = len(num)
minimum = sys.maxsize
possibles = ["25", "50", "75", "00"]

for possible in possibles:
    if possible[0] == possible[1] and num.count('0') > 1:
        first = num.rfind(possible[0])
        second = num[:first].rfind(possible[1])
        temp_min = length - 2 - second + length - 1 - first
        minimum = min(minimum, temp_min)
    elif possible[0] != possible[1] and possible[0] in num and possible[1] in num:
        first = num.rfind(possible[0])
        second = num.rfind(possible[1])

        temp_min = length - 2 - first + length - 1 - second

        if (second == 0) and length > 3:
            i = 1
            while num[i] == '0':
                temp_min += 1
                i += 1

        if first > second:
            temp_min += 1
        minimum = min(minimum, temp_min)

if minimum == sys.maxsize:
    print(-1)
else:
    print(minimum)

k = input()
n = len(k)
import sys
Min = sys.maxsize
ck = ['50','25','75']
for c in ck:
    if c[0] in k and c[1] in k:
        temp = 2*n - 3 - k.rfind(c[0]) - k.rfind(c[1])
        if (c[1]=='5'):
            if k.rfind('5')==0 and k[1]=='0' and n>3:
                add = 0
                i = 1
                while k[i] == '0':
                    add += 1
                    i += 1
                temp += add
        temp += k.rfind(c[0]) > k.rfind(c[1])
        Min = min(temp,Min)
if k.count('0')>1:
    css = k.rfind('0')
    temp = n-1 - css
    k = k[:css] + k[css+1:]
    temp += len(k)-1 - k.rfind('0')
    Min = min(temp,Min)
print([Min,-1][Min==sys.maxsize])

from fractions import gcd
from math import factorial, ceil, sqrt, atan2, log, pi, e, asin,acos, cos, sin, floor
from itertools import *
from fractions import Fraction
import string
import copy
import random
import bisect
from decimal import *
def id_generator(size=20, chars=string.digits):
    return ''.join(random.choice(chars) for _ in range(size))

def mp():
    return map(int,str(raw_input()).split())

n=input()
case=['25','50','75','00']
if n<100:
    if n==25 or n==50 or n==75:
        print 0
    elif n==52 or n==57:
        print 1
    else:
        print -1
else:
    a1=10**18
    a2=10**18
    s=list(str(n))
    l=len(s)
    flag=0
    z=copy.deepcopy(s)
    for i in range(1,l+1):
        if s[l-i]=='5':
            flag=1
            break
    if flag:
        pre=i-1
        i=l-i
        #count=0
        #while i<l-1 and s[i+1]=='0':
        #	count+=1
        #	i+=1
        q=i
        count=0
        for j in range(q+1,l-1):
        	if s[j]=='0':
        		count+=1
        	else:
        		break
        #print i,
        for j in range(i,l-1):
            s[j],s[j+1]=s[j+1],s[j]
        flag=0
        #print s,pre
        for i in range(1,l+1):
            if s[l-i]=='7' or s[l-i]=='2':
                flag=1
                break

        if flag:
			a1=(pre+i-2+count)
        else:
            pass
    else:
        pass
    if 1:
    	#print z
    	s=copy.deepcopy(z)
        for i in range(1,l+1):
            if s[l-i]=='0':
                flag=1
                break
        if flag:
            pre=i-1
            i=l-i
            for j in range(i,l-1):
                s[j],s[j+1]=s[j+1],s[j]
            flag=0
            #print s,pre
            for i in range(2,l+1):
                if s[l-i]=='0' or s[l-i]=='5':
                    flag=1
                    break
            if flag:
                a2=pre+i-2
            else:
                pass

    #print a1,a2
    if min(a1,a2)==10**18:
        print -1
    else:
        print min(a1,a2)

#!/usr/bin/python3

from sys import stdin

def f(n, x, y):
    ans = 0
    # 1
    cur = n.rfind(y)
    if cur < 0:
        return 10 ** 18
    ans += len(n) - 1 - cur
    n = n[:cur] + n[cur + 1:] + y

    # 2
    cur = n[:-1].rfind(x)
    if cur < 0:
        return 10 ** 18
    ans += len(n) - 2 - cur
    n = n[:-1][:cur] + n[:-1][cur + 1:] + x + y

    # 3
    cur = 0
    has0 = False
    while (cur < len(n) - 2) and (n[cur] == '0'):
        has0 = True
        cur += 1
    if has0 and (cur >= len(n) - 2):
        return 10 ** 18
    return ans + cur

def main():
    for line in stdin.readlines():
        n = line.strip()
        ret = [
            f(n, '2', '5'),
            f(n, '7', '5'),
            f(n, '5', '0'),
            f(n, '0', '0')
        ]
        if min(ret) == 10**18:
            print(-1)
        else:
            print(min(ret))

if __name__ == '__main__':
    main()

def swipe(s, i):
    return s[:i] + s[i + 1] + s[i] + (s[i + 2:] if i + 2 < len(s) else "")

def nazis(s):
    m = float("inf")
    for i in range(9):
        if s.find(str(i + 1)) > -1:
            m = min(s.find(str(i + 1)), m)
    return m

n = input()
c = float("inf")
if n.count("0") >= 2 or "5" in n and "0" in n or "2" in n and "5" in n or "7" in n and "5" in n:
    s = n
    if n.count("0") >= 2:
        a = n.rfind("0")
        b = n.rfind("0", 0, a)
        c = 2 * len(n) - a - b - 3
    if "5" in n and "0" in n:
        cc = 0
        a = n.rfind("0")
        while n[-1] != "0":
            n = swipe(n, a)
            a += 1
            cc += 1
        b = n.rfind("5")
        while n[-2] != "5":
            n = swipe(n, b)
            b += 1
            cc += 1
        if n[0] == "0":
            cc += nazis(n)
        c = min(c, cc)
    if "2" in n and "5" in n:
        n = s
        cc = 0
        b = n.rfind("5")
        while n[-1] != "5":
            n = swipe(n, b)
            b += 1
            cc += 1
        a = n.rfind("2")
        while n[-2] != "2":
            n = swipe(n, a)
            a += 1
            cc += 1
        if n[0] == "0":
            cc += nazis(n)
        c = min(c, cc)
    if "7" in n and "5" in n:
        n = s
        cc = 0
        b = n.rfind("5")
        while n[-1] != "5":
            n = swipe(n, b)
            b += 1
            cc += 1
        a = n.rfind("7")
        while n[-2] != "7":
            n = swipe(n, a)
            a += 1
            cc += 1
        if n[0] == "0":
            cc += nazis(n)
        c = min(c, cc)
    print(c)
else:
    print(-1)

from bisect import bisect_right, bisect_left

n = input().strip()

res = 1e18

def solve(x, y):
    global res
    cur = [x for x in n]
    c = 0
    for i in range(x, len(cur) - 1):
        cur[i], cur[i + 1] = cur[i + 1], cur[i]
        c += 1
    for i in range(y - (y > x), len(cur) - 2):
        cur[i], cur[i + 1] = cur[i + 1], cur[i]
        c += 1

    p = -1

    for i, e in enumerate(cur):
        if e != '0':
            p = i
            break

    for i in range(p, 0, -1):
        cur[i], cur[i - 1] = cur[i - 1], cur[i]
        c += 1

    if int(''.join(cur)) % 25 == 0:
        res = min(res, c)

for i in range(len(n)):
    for j in range(len(n)):
        if i != j:
            solve(i, j)

if res == 1e18:
    print(-1)
else:
    print(res)

# a = [abs(int(x)) for x in input().split(' ')]

from copy import deepcopy
def nonzeroind(l):
    l.reverse()
    for i in range(1,len(l)):
        if l[i]!=0:
            return len(l)-1-i
        i=i+1
    return -1

def parse(nl,num):
    try:
        i=nl.index(num)
    except:
        return (60,nl)
    if (i==len(nl)-1 and nl[i-1]==0):
        ind=nonzeroind(nl)
        nl.reverse()
        if ind==-1:
            return(60,nl)
        else:
            nl[i-1]=nl[ind]
            nl[ind]=0
            intermed=parse(deepcopy(nl),num)
            return (intermed[0]+i-1-ind,intermed[1])
    else:
        nl.pop(i)
        return (i,nl)
num=input('')
numarr=[]
for dig in num:
    numarr.append(int(dig))
numarr.reverse()
o11=parse(deepcopy(numarr),5)
o12=parse(o11[1],7)
o21=parse(deepcopy(numarr),5)
o22=parse(o21[1],2)
o31=parse(deepcopy(numarr),0)
o32=parse(o31[1],5)
o41=parse(deepcopy(numarr),0)
o42=parse(o41[1],0)
ans=min(o11[0]+o12[0],o21[0]+o22[0],o31[0]+o32[0],o41[0]+o42[0])
if(ans>40):
    print(-1)
else:
    print(ans)

def solve(n):
    if int(n) % 25 == 0: return 0
    if n in {'52', '57'}: return 1
    ans = float('inf')
    for x, y in ['00', '25', '50', '75']:
        for i in range(len(n)):
            if n[i] == '0': continue
            for j in range(len(n)):
                if i == j or n[j] != x: continue
                for k in range(len(n)):
                    if k in {i, j} or n[k] != y: continue
                    ans = min(ans, len(n) * 2 - 3 + i - j - k + (j > k) - (i > j) - (i > k))
    return ans if ans < float('inf') else -1

print(solve(input()))

s=input()
arr=[]
for i in s:
	arr.append(i)
ans=100000000000
for i in range(len(s)):
	for j in range(len(s)):
		if i==j:
			continue
		t=arr[:]
		# print('t ori',''.join(t))
		curr=0
		for k in range(i,len(s)-1):
			tt=t[k]
			t[k]=t[k+1]
			t[k+1]=tt
			curr+=1
		# print("t",''.join(t))
		tey=0
		if j>i:
			tey+=1
		for k in range(j-tey,len(s)-2,1):
			tt=t[k]
			t[k]=t[k+1]
			t[k+1]=tt
			curr+=1
		# print("t1",''.join(t))
		pos=-1
		for k in range(len(s)):
			if t[k]!='0':
				pos=k
				break
		for k in range(pos,0,-1):
			tt=t[k]
			t[k]=t[k-1]
			t[k-1]=tt
			curr+=1
		# print("t2",''.join(t))
		if int(''.join(t))%25==0:
			ans=min(ans,curr)
if ans==100000000000:
	ans=-1
print(ans)

import sys

n = input()
num = ["25","50","75","00"]
minn =  sys.maxsize
step = 0
length =  len(n)
for x in num:
    if(x[0] == x[1] and n.count('0')>1):
        first = n.rfind(x[0])
        second = n[:first].rfind(x[1])
        step =  length - 1 - second + length - 2 - first
        minn = min(step,minn)
    elif(x[0] != x[1] and x[0] in n and x[1] in n):
        i = 1
        first = n.rfind(x[0])
        second = n.rfind(x[1])
        step = length - 1 - second + length - 2 - first
        if second == 0:
            while(n[i] == '0'):
                step += 1
                i += 1
        if second < first:
            step += 1
        minn =  min(minn, step)
if(minn == sys.maxsize):
    print("-1")
else:
    print(minn)

def swap(N,a,b):
    A = N[a]
    B = N[b]
    N[a] = B
    N[b] = A

def getToEnd(N,a,b):
    bInd = -1
    for i in range(len(N)-1,-1,-1):
        if N[i] == b:
            bInd = i
            break
    total = 0
    if bInd == -1:
        return q
    for i in range(bInd,len(N)-1):
        total += 1
        swap(N,i,i+1)
    aInd = -1
    for i in range(len(N)-2,-1,-1):
        if N[i] == a:
            aInd = i
            break
    if aInd == -1:
        return q

    for i in range(aInd,len(N)-2):
        total += 1
        swap(N,i,i+1)

    if N[0] == '0':
        worked = False
        for i in range(len(N)-2):
            if N[i] == '0':
                total += 1
            else:
                worked = True
                break
        if not worked:
            return q
    return total

q = 999999
N = list(input())

a = getToEnd(list(N),'0','0')
b = getToEnd(list(N),'2','5')
c = getToEnd(list(N),'5','0')
d = getToEnd(list(N),'7','5')

if a == q and b == q and c == q and d == q:
    print(-1)
else:
    print(min(a,b,c,d))

from itertools import dropwhile
n=[int(i) for i in input()]
l=len(n)
#長さが2の場合も
if len(n)==1:
    print(-1)
    exit()
if n in [[2,5],[7,5],[5,0]]:
    print(0)
    exit()
if n in [[5,2],[5,7]]:
    print(1)
    exit()
inf=10**12
#一番左にある場合はめんどいので場合分けしちゃう(逆にする)
#00も場合分け
def calc1(x,y):
    global n,l,inf
    m=n[::-1]
    if x not in n or y not in n:
        #print(x,y,0)
        return inf
    ix,iy=m.index(x),m.index(y)
    #一番右にない場合
    if max(ix,iy)<l-1:
        if iy<ix:
            #print(x,y,1)
            return iy+(ix-1)
        else:
            #print(x,y,2)
            return iy+(ix-1)+1
    else:
        ret=0
        #print(ix,iy)
        if ix==l-1:
            #右から探して左を見る(0かつ他の選択するやつでない)
            for i in range(l-2,-1,-1):
                if m[i]!=0 and i!=iy:
                    break
            else:
                #print(x,y,3)
                return inf
            if i<iy:
                iy-=1
                ret+=(l-1-i)
                ix-=1
                ret+=(iy+(ix-1))
                #print(x,y,4,ret)
                return ret
            else:
                ret+=iy
                ret+=(l-1-i)
                ix-=1
                ret+=(ix-1)
                #print(x,y,5,ret)
                return ret
        else:
            #右から探して左を見る(0かつ他の選択するやつでない)
            #他の選択するやつだけの可能性(最初に排除)
            #外でやる
            for i in range(l-2,-1,-1):
                if m[i]!=0 and i!=ix:
                    break
            else:
                #print(x,y,6)
                return inf
            if i<ix:
                iy-=1
                ret+=(l-1-i)
                ix-=1
                ret+=(iy+(ix-1)+1)
                #print(x,y,7,ret)
                return ret
            else:
                ret+=iy
                ret+=(l-1-i)
                ix-=1
                ret+=((ix-1)+1)
                #print(x,y,8,ret)
                return ret
#00の時
def calc2(x,y):
    #一番右には絶対ない
    global n,l,inf
    if n.count(0)<2:
        return inf
    m=[l-1-i for i in range(l) if n[i]==0][::-1]
    return m[0]+m[1]-1

ans=min([calc1(2,5),calc1(7,5),calc1(5,0),calc2(0,0)])
#print([calc1(2,5),calc1(7,5),calc1(5,0),calc2(0,0)])
print(-1 if ans==inf else ans)

#Imports
from sys import stdin, stdout

#Aux
def _count_algs(num_str):
    alg_count = [0]*10

    for alg_str in num_str:
        alg_count[int(alg_str)] += 1

    return alg_count

def _has_algs(alg_count):
    has_five = alg_count[5] >= 1

    algs_dict = {
    '00': alg_count[0] >= 2,
    '52': has_five and alg_count[2] >= 1,
    '05': has_five and alg_count[0] >= 1,
    '57': has_five and alg_count[7] >= 1
    }

    has_algs = {key: value for  key, value in algs_dict.items() if value is True}

    return has_algs

def _find_min_moves(has_algs, num_str):
    min_moves = 10000 if len(has_algs) > 0 else -1

    reversed_num_str = num_str[::-1]

    for algs_str in has_algs:
        this_moves = _calculate_moves(reversed_num_str, algs_str)
        min_moves = min(min_moves, this_moves)

    return min_moves

def _calculate_moves(num_str, algs_str):
    moves = 0

    idx_alg0 = num_str.index(algs_str[0])
    if idx_alg0 == len(num_str)-1:
        aux_count0 = idx_alg0-1
        while num_str[aux_count0] == '0':
            aux_count0-=1
        moves = idx_alg0-1-aux_count0

    idx_alg1 = None
    if algs_str[1] == '0':
        idx_alg1 = num_str.index(algs_str[1], idx_alg0+1)
    else:
        idx_alg1 = num_str.index(algs_str[1])

    moves += idx_alg0 + idx_alg1
    return moves if idx_alg0 > idx_alg1 else moves-1

#Main
def _main():
    #Read input
    num_str = stdin.readline().rstrip().split()[0]

    #Calculate answer
    count = _count_algs(num_str)
    has_algs = _has_algs(count)
    ans = _find_min_moves(has_algs, num_str)

    #Print output
    stdout.write(str(ans))

#Call
_main()

def swap(ar,ind1,ind2):
    if ind2 > ind1:
        for i in range(ind1,ind2):
            temp = ar[i]
            ar[i] = ar[i+1]
            ar[i+1] = temp
    else:
        for i in range(ind1,ind2,-1):
            temp = ar[i]
            ar[i] = ar[i-1]
            ar[i-1] = temp

n = list(input())
n2 = len(n)
ans = 100
for i in range(n2):
    for j in range(n2):
        nc = [0]*n2
        for i2 in range(n2):
            nc[i2] = n[i2]
        swap(nc,i,n2-1)
        swap(nc,j,n2-2)
        num = 0
        for z in range(n2):
            if nc[z] != "0":
                num = z
                break
        swap(nc,0,num)
        if int("".join(nc)) % 25 == 0:
             ans = min(ans,abs(n2-2-j)+abs(n2-1-i)+num)

if ans == 100:
    print(-1)
else:
    print(ans)

#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__

def main():
    n = input()
    m = n[::-1]
    res = 10**9

    if int(n) % 25 == 0:
        print(0)
        return

    if n.count('0') >= 2:
        cnt, flag = 0, False
        for i, mi in enumerate(m):
            if mi == '0':
                if flag:
                    cnt += i - 1
                    break
                else:
                    flag = True
                    cnt += i
        res = min(res, cnt)

    if '5' in n:
        i = m.index('5')
        if '0' in n:
            if n.count('5') == 1 and n.index('5') == 0:
                cnt = m.index('0')
                n_ = n[:-cnt - 1] + n[-cnt:] + '0'
                for i in range(1, len(n)):
                    if n_[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 2
                        res = min(res, cnt)
                        break

            else:
                j = m.index('0')
                if i > j:
                    res = min(res, j + i - 1)
                else:
                    res = min(res, j + i)

        i = m.index('5')
        if '2' in n:
            if n.count('5') == 1 and n.index('5') == 0:
                cnt = m.index('2')
                for i in range(1, len(n)):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 1
                        res = min(res, cnt)
                        break

            elif n.count('2') == 1 and n.index('2') == 0:
                cnt = i
                for i in range(1, len(n)):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 2
                        res = min(res, cnt)
                        break

            else:
                j = m.index('2')
                if i > j:
                    res = min(res, j + i)
                else:
                    res = min(res, j + i - 1)

        i = m.index('5')
        if '7' in n:
            if n.count('5') == 1 and n.index('5') == 0:
                cnt = m.index('7')
                for i in range(1, len(n)):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 1
                        res = min(res, cnt)
                        break

            elif n.count('7') == 1 and n.index('7') == 0:
                cnt = i
                for i in range(1, len(n)):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 2
                        res = min(res, cnt)
                        break

            else:
                j = m.index('7')
                if i > j:
                    res = min(res, j + i)
                else:
                    res = min(res, j + i - 1)

    print(res if res < 10**9 else -1)

# region fastio

BUFSIZE = 8192

class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0,
                              2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()

def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

import sys
num = input()
length = len(num)
minimum = sys.maxsize
possibles = ["25", "50", "75", "00"]

for possible in possibles:
    if possible[0] == possible[1] and num.count('0') > 1:
        first = num.rfind(possible[0])
        second = num[:first].rfind(possible[1])
        temp_min = length - 2 - second + length - 1 - first
        minimum = min(minimum, temp_min)
    elif possible[0] != possible[1] and possible[0] in num and possible[1] in num:
        first = num.rfind(possible[0])
        second = num.rfind(possible[1])

        temp_min = length - 2 - first + length - 1 - second

        if (second == 0) and length > 3:
            i = 1
            while num[i] == '0':
                temp_min += 1
                i += 1

        if first > second:
            temp_min += 1
        minimum = min(minimum, temp_min)

if minimum == sys.maxsize:
    print(-1)
else:
    print(minimum)

def finder(n,ind):
    i=ind-1
    while(i>=0):
        if(n[i]=="0"):
            break
        else:
            i=i-1
    return(i)

def zeros(n):
    count=0
    pol=1
    while(pol<l):
        if(n[pol]=="0"):
            count=count+1
        else:
            break
        pol=pol+1
    return(count)

n=input()
ans=[]
l=len(n)

if("2" in n and "5" in n):
    c2=l-n.rfind("2")-2
    c5=l-n.rfind("5")-1

    if(c2<c5):
        k=c2+c5+1
    else:
        k=c2+c5

    if(n[1]=="0" and (n[0]=="2" or n[0]=="5") ):
        ans.append(k+zeros(n))
    else:
        ans.append(k)

if("5" in n and "0" in n):
    c5=l-n.rfind("5")-2
    c0=l-n.rfind("0")-1

    if(c5<c0):
        k=c5+c0+1
    else:
        k=c5+c0

    ans.append(k)

if("7" in n and "5" in n):
    c7=l-n.rfind("7")-2
    c5=l-n.rfind("5")-1

    if(c7<c5):
        k=c7+c5+1
    else:
        k=c7+c5

    if(n[1]=="0" and (n[0]=="7" or n[0]=="5") ):
        ans.append(k+zeros(n))
    else:
        ans.append(k)

if(n.count("0")>=2):
    c01=l-n.rfind("0")-2
    c02=l-finder(n,n.rfind("0"))-1
    ans.append(c01+c02)

if(int(n)%25==0):
    print(0)
elif(len(ans)==0):
    print(-1)
else:
    print(min(ans))

class Problem:
	def solve(self, s):
		ans = -1
		n = len(s)
		for i in range(n):
			for j in range(n):
				if i != j:
					c1 = c2 = 0
					t, c1 = self.move_end(s, i, j)
					if t[0] == "0":
						k = self.find_nonzero(t)
						t, c2 = self.move_begin(t, k)
					if self.ok(t):
						ans = self.best(ans, c1+c2)
					# print("i", i, "j", j, "t", t)
		return ans

	def move_end(self, s, i, j):
		# i < j          j < i
		# a i b j c      a j b i c
		# a i b c j (j)  a b i c j (j)
		# a b c i j (i)  a b c i j (i)
		if j < i: i -= 1
		t = s
		t, c1 = self.move_char(t, j, len(t)-1)
		t, c2 = self.move_char(t, i, len(t)-2)
		return t, c1 + c2

	def move_begin(self, s, i):
		return self.move_char(s, i, 0)

	def move_char(self, s, i:"index from", j:"index to"):
		l = list(s)
		count = 0
		while i != j:
			count += 1
			if i < j:
				l[i], l[i+1] = l[i+1], l[i]
				i += 1
			else:
				l[i-1], l[i] = l[i], l[i-1]
				i -= 1
		return "".join(l), count

	def ok(self, s):
		return s[0] != "0" and int(s) % 25 == 0

	def find_nonzero(self, s):
		found = -1
		for i in range(len(s)):
			if s[i] != "0":
				found = i
				break
		return found

	def best(self, a, b):
		if a == -1: return b
		if b == -1: return a
		return a if a<b else b

s = input()
ans = Problem().solve(s)
print(ans)
exit()

assert(0 == Problem().solve("100"))
assert(1 == Problem().solve("52"))
assert(4 == Problem().solve("5071"))
assert(1 == Problem().solve("705"))
assert(-1 == Problem().solve("1241367"))
assert(2 == Problem().solve("507"))
assert(1 == Problem().solve("17010"))
assert(6 == Problem().solve("52231"))
assert(5 == Problem().solve("50267"))
print("ok")

z=input()
n=len(z)
maxa=10**18
y=int(z)
if(y%25==0):
    print(0)
    quit()
if(n==1):
    print(-1)
    quit()
for i in range(n):
    for j in range(n):
        if(i==j):
            continue
        copy=list(z)
        swaps=0
        for k in range(i,n-1):
            copy[k],copy[k+1]=copy[k+1],copy[k]
            swaps+=1
        if(j>i):
            j-=1
        for k in range(j,n-2):
            copy[k],copy[k+1]=copy[k+1],copy[k]
            swaps+=1
        if((10*(ord(copy[n-2])-48)+(ord(copy[n-1])-48))%25):
            continue
        if(copy[0]=='0'):
            done=0
            for yo in range(n-2):
                if(copy[yo]!='0'):
                    done=1
                    swaps+=(yo)
                    break
            if(done):
                maxa=min(maxa,swaps)
            else:
                continue
        maxa=min(maxa,swaps)
if(maxa==10**18):
    print(-1)
else:
    print(maxa)

def swap(N,a,b):
    A = N[a]
    B = N[b]
    N[a] = B
    N[b] = A

def getToEnd(N,a,b):
    bInd = -1
    for i in range(len(N)-1,-1,-1):
        if N[i] == b:
            bInd = i
            break
    total = 0
    if bInd == -1:
        return q
    for i in range(bInd,len(N)-1):
        total += 1
        swap(N,i,i+1)

    aInd = -1
    for i in range(len(N)-2,-1,-1):
        if N[i] == a:
            aInd = i
            break
    if bInd == -1:
        return q

    for i in range(aInd,len(N)-2):
        total += 1
        swap(N,i,i+1)
    if N[0] == '0':
        return q
    return total

q = 999999
N = list(input())

a = getToEnd(list(N),'0','0')
b = getToEnd(list(N),'2','5')
c = getToEnd(list(N),'5','0')
d = getToEnd(list(N),'7','5')

if a == q and b == q and c == q and d == q:
    print(-1)
else:
    print(min(a,b,c,d))

n=input()
ans=[]
l=len(n)

if("2" in n and "5" in n):
    c2=l-n.rfind("2")-2
    c5=l-n.rfind("5")-1

    if(c2<c5):
        k=c2+c5+1
    else:
        k=c2+c5

    if(n[1]=="0"):
        ans.append(k+1)
    else:
        ans.append(k)

if("5" in n and "0" in n):
    c5=l-n.rfind("5")-2
    c0=l-n.rfind("0")-1

    if(c5<c0):
        k=c5+c0+1
    else:
        k=c5+c0

    ans.append(k)

if("7" in n and "5" in n):
    c7=l-n.rfind("7")-2
    c5=l-n.rfind("5")-1

    if(c7<c5):
        k=c7+c5+1
    else:
        k=c7+c5

    if(n[1]=="0"):
        ans.append(k+1)
    else:
        ans.append(k)

if(n.count("0")==2):
    c01=l-n.rfind("0")-2
    c02=l-n.find("0")-1
    ans.append(c01+c02)

if(int(n)%25==0):
    print(0)
elif(len(ans)==0):
    print(-1)
else:
    print(min(ans))

y = input()
fives = (y.count('5'))
zeroes = (y.count('0'))
twos = (y.count('2'))
sevens = (y.count('7'))

if fives == 0:
    if zeroes < 2:
        print(-1)
        exit(0)
else:
    if zeroes == 0 and twos == 0 and sevens == 0:
        print(-1)
        exit(0)

best = len(y)
y = y[::-1]
for x in [['5','2'], ['0','0'], ['5','7'], ['0','5'] ]:
        count = 0
        if not x[0] in y:
            continue
        f = (y.index(x[0]))
        z = y[:f] + y[f+1:] + y[f]
        count += f
        if not x[1] in z[:-1]:
            continue
        g = (z[:-1].index(x[1]))
        count += g
        if count < best:
            best = count

print(best)

s = input()

globans = 10 ** 9

for i_ in range(len(s)):
    for j_ in range(len(s)):
        i = i_
        j = j_

        if j == i:
            continue
        ans = abs(len(s) - i - 2) + abs(len(s) - j - 1) + int(j < i)

        if i > j:
            i, j = j, i

        nw = s[:i] + s[i + 1:j] + s[j + 1:] + s[i_] + s[j_]

        for x in range(len(s)):
            if s[x] == "0":
                continue
            ans += x
            nw = nw[x] + nw[:x] + nw[x + 1:]
            break

        if int(nw) % 25 == 0:
            globans = min(globans, ans)

if globans == 10 ** 9:
    print(-1)
else:
    print(globans)

import sys
s=input()
m=1000000000000000000000000000000000000000
t=False
if int(s)%25==0:
    print(0)
    sys.exit()
if s.count("0")>=2 and len(s)>2:
    t=True
    s1=s[::-1]
    x=0
    ind1=-1
    ind2=-1
    for i in range(len(s)):
        if s1[i]=="0":
            if x==0:
                ind1=i
                x=1
            else:
                ind2=i
                break
    m=min(ind1+ind2-1,m)
if "2" in s and "5" in s:
    s1=s[::-1]
    ind1=s1.index("2")
    ind2=s1.index("5")
    if not ((ind1+1==len(s) and s1[ind1-1]=="0") or (ind2+1==len(s) and s1[ind2-1]=="0")):
        if ind2>ind1:
            m=min(ind1+ind2,m)
            t=True
        else:
            m=min(ind1+ind2-1,m)
            t=True
if "0" in s and "5" in s:
    s1=s[::-1]
    ind1=s1.index("0")
    ind2=s1.index("5")
    if not ((ind2+1==len(s) and s1[ind2-1]=="0" and ind2-1!=ind1)):

        if ind2<ind1:
            m=min(ind1+ind2,m)
            t=True
        else:
            m=min(ind1+ind2-1,m)
            t=True
if "7" in s and "5" in s:
    s1=s[::-1]
    ind1=s1.index("7")
    ind2=s1.index("5")
    if not ((ind1+1==len(s) and s1[ind1-1]=="0") or (ind2+1==len(s) and s1[ind2-1]=="0")):
        if ind2>ind1:
            m=min(ind1+ind2,m)
            t=True
        else:
            m=min(ind1+ind2-1,m)
            t=True

if t:
    print(m)
else:
    print(-1)

n=int(input())
l=(list(str(n)))[::-1]
g=[]
def permut(l,c,c1):
    i=l.copy()
    k=0
    while(True):
        if i.index(c)==0:break
        else:
            j=i.index(c)
            i[j],i[j-1]=i[j-1],i[j]
            k+=1
    m=i[1:]
    while(True):
        if m.index(c1)==0:break
        else:
            j=m.index(c1)
            m[j],m[j-1]=m[j-1],m[j]
            k+=1
    if i[-1]=='0':k+=1
    if i[-1]==i[-2]=='0':k+=2
    return(k)

if (('2'in l) and ('5' in l)):
    g.append(permut(l,'5','2'))
if (('5'in l) and ('0' in l)):
    g.append(permut(l,'0','5'))
if (('7'in l) and ('5' in l)):
    g.append(permut(l,'5','7'))
if l.count('0')>1:
    g.append(permut(l,'0','0'))
if g==[]:print(-1)
else:print(min(g))

def inx(a,s):
    ll = []
    for i in range(len(a)):
        if s == a[i]:
            ll.append(i)
    try:
        return max(ll)
    except:
        return False

def check(a, Comb):
    Counter = 0
    Nxt = inx(a,Comb[1])
    if Nxt is False:
        Counter = 0
    else:
        for i in range(Nxt+1, len(a)):
            a[i-1], a[i] = a[i], a[i-1]
            Counter+=1

    Fst = inx(a,Comb[0])
    if Fst is False:
        Counter = 0
    else:
        for i in range(Fst+1, len(a)-1):
            a[i-1], a[i] = a[i], a[i-1]
            Counter+=1
    if Fst is False:
        Counter = None
    if Nxt is False:
        Counter = None
    return Counter

def search(a):
    s = None
    flg = False
    for i in range(len(a)):
        if flg is True:
            break
        if a[i] == '2':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '255'
                    flg = True
                    break
        elif a[i] == '5':
            for j in range(len(a)):
                if a[j] == '2':
                    s = '255'
                    flg = True
                    break
                elif a[j] == '7':
                    s = '755'
                    flg = True
                    break
                elif a[j] == '0':
                    s = '505'
                    flg = True
                    break
        elif a[i] == '7':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '755'
                    flg = True
                    break
        elif a[i] == '0':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '500'
                    flg = True
                    break
                elif a[j] == '0' and i != j:
                    s = '000'
                    flg = True
                    break
    if s is None:
        print(-1)
        exit()
    return s

#def swap(a,b):
#    a, b = b, a
#    return b, a

def czero(a):
        ctr = 0
        index = None
        for i in range(len(a)):
            if a[i] != '0':
                index = i
                break
        if index == 0:
            return None
        else:
            cou = index
            while a[0] == '0':
                a[cou-1], a[cou] = a[cou], a[cou-1]
                ctr+=1
                cou-=1
            return ctr

def search1(a, t, Comb):
        s = None
        flg = False

        if Comb[2] == '5':
                if '2' not in t:
                    s = '255'
                    t.append('2')

                elif  '7' not in t:
                    s = '755'
                    t.append('7')
                elif '0' not in t:
                    s = '505'
                    t.append('0')
        elif Comb[2] == '0':
                if '5' not in t:
                    s = '500'
                    t.append('5')
                elif '0' not in t:
                    s = '000'
                    t.append('0')
                else:
                    s = '---'
        return s, t
def ZERO(a, mass):
    Counter = 0
    #print(a)
    Nxt = None
    Fst = None
    for i in range(len(a)):

        if a[i] == '0':
            if not Fst:
                Fst = i
            elif not Nxt:
                Nxt = i
            else:
                break

    if Fst is None:
        return mass, None
    elif Nxt is None:
        return mass, None
    else:
        for i in range(Nxt+1, len(a)):
            a[i-1], a[i] = a[i], a[i-1]
            Counter+=1

        for i in range(Fst+1, len(a)-1):
            a[i-1], a[i] = a[i], a[i-1]
            Counter+=1

        f = czero(a)
        if f is not None:
             Counter+=f

        mass.append(Counter)
        return mass, Counter

mass = []
temp = []
Counter = 0
a=input()[::-1]
if a[0] == '5' and a[1] == '2':
    print(0)
    exit()
if a[0] == '5' and a[1] == '7':
    print(0)
    exit()
if a[0] == '0' and a[1] == '0':
    print(0)
    exit()
if a[0] == '0' and a[1] == '5':
    print(0)
    exit()

Comb = search(a)

if Comb == '000':
    a = list(a)[::-1]
    Nxt = None
    Fst = None
    for i in range(len(a)):

        if a[i] == '0':
            if not Fst:
                Fst = -i
            elif not Nxt:
                Nxt = -i
            else:
                break
    #print(Fst,Nxt)

    for i in range((Nxt+len(a))+1, len(a)):
        a[i-1], a[i] = a[i], a[i-1]
        Counter+=1

    for i in range((Fst+len(a))+1, len(a)-1):
        a[i-1], a[i] = a[i], a[i-1]
        Counter+=1

    f = czero(a)
    if f is not None:
         Counter+=f

    mass.append(Counter)

else:
    b = a
    for i in range(3):
        a = list(b)[::-1]
        #print(a)
        Counter = 0
        Comb2, temp = search1(a, temp, Comb)
        if Comb2 == '---':
            pass
        elif Comb2 == '000':
            mass, Counter = ZERO(a, mass)
            if Counter is not None:
                f = czero(a)
                if f is not None:
                    Counter+=f

                mass.append(Counter)
        else:
            Counter=check(a, Comb2)
            if Counter is not None:
                f = czero(a)
                if f is not None:
                    Counter+=f

                mass.append(Counter)
print(min(mass))

#50267 |

n=int(input())
l=(list(str(n)))[::-1]
g=[]
def permut(l,c,c1):
    i=l.copy()
    k=0
    while(True):
        if i.index(c)==0:break
        else:
            j=i.index(c)
            i[j],i[j-1]=i[j-1],i[j]
            k+=1
    m=i[1:]
    while(True):
        if m.index(c1)==0:break
        else:
            j=m.index(c1)
            m[j],m[j-1]=m[j-1],m[j]
            k+=1
    if i[-1]=='0':
        k+=1
        if i[-1]==i[-2]=='0': k+=1
    return(k)

if (('2'in l) and ('5' in l)):
    g.append(permut(l,'5','2'))
if (('5'in l) and ('0' in l)):
    g.append(permut(l,'0','5'))
if (('7'in l) and ('5' in l)):
    g.append(permut(l,'5','7'))
if l.count('0')>1:
    g.append(permut(l,'0','0'))
if g==[]:print(-1)
else:print(min(g))

num = input()[::-1]
possibility1 = False
possibility2 = False
contains1 = []
contains2 = []
if '0' in num:
    first_char1 = '0'
    if '0' in num:
        possibility1 = True
        contains1.append('0')
    if '5' in num:
        possibility1 = True
        contains1.append('5')
elif '5' in num:
    first_char2 = '5'
    if '2' in num:
        possibility2 = True
        contains2.append('2')

if possibility1 or possibility2:
    if possibility1:
        first = num.find(first_char1)
        second = min([num.find(i) for i in contains1])
        out1 = first + second
        if first < second:
            out1 -= 1

    if possibility2:
        first = num.find(first_char2)
        second = min([num.find(i) for i in contains2])
        out2 = first + second
        if first < second:
            out2 -= 1
    if possibility1 and not possibility2:
        print(out1)
    if possibility2 and not possibility1:
        print(out2)
    if possibility1 and possibility2:
        print(min(out1, out2))
else:
    print(-1)

n=int(input())
l=(list(str(n)))[::-1]
g=[]
def permut(l,c,c1):
    i=l.copy()
    k=0
    while(True):
        if i.index(c)==0:break
        else:
            j=i.index(c)
            i[j],i[j-1]=i[j-1],i[j]
            k+=1
            if i[-1]==0:
                k+=2
    m=i[1:]
    while(True):
        if m.index(c1)==0:break
        else:
            j=m.index(c1)
            m[j],m[j-1]=m[j-1],m[j]
            k+=1
            if i[-1]==0:
                k+=2
    return(k)

if (('2'in l) and ('5' in l)):
    g.append(permut(l,'5','2'))
if (('5'in l) and ('0' in l)):
    g.append(permut(l,'0','5'))
if (('7'in l) and ('5' in l)):
    g.append(permut(l,'5','7'))
if l.count('0')>1:
    g.append(permut(l,'0','0'))

if g==[]:print(-1)
else:print(min(g))

n = list(input())
if (not("5" in n)) and (not("0" in n)) and (not("7" in n)) and (not("2" in n)):
	print(-1)
	quit()

wkn = []
wkn[:] = n
ans = -1
for i in reversed(range(len(n))):
	if (n[i] == "0"):
		wk1 = n[:i] + n[i + 1:] + [n[i]]
		ans = len(n) - i - 1
		if wk1[0] != "0":
			n[:] = wk1
			break
		else:
			count = 0
			for j in wk1:
				count += 1
				if j != "0":
					break
			ans += count - 1
			wk1 = [wk1[count - 1]] + wk1[:count - 1] + wk1[count:]
			n[:] = wk1
			break

if ans != -1:
	f = True
	for i in reversed(range(len(n) - 1)):
		if (n[i] == "0") or (n[i] == "5"):
			wk1 = n[:i] + n[i + 1:] + [n[i]]
			ans += len(n) - i - 2
			if wk1[0] != "0":
				f = False
				break
			else:
				count = 0
				for j in wk1:
					count += 1
					if j != "0":
						break
				ans += count - 1
				f = False
				break
	if f:
		ans = -1

wkans = ans

ans = -1
n = wkn
for i in reversed(range(len(n))):
	if (n[i] == "5"):
		wk1 = n[:i] + n[i + 1:] + [n[i]]
		ans = len(n) - i - 1
		if wk1[0] != "0":
			n[:] = wk1
			break
		else:
			count = 0
			for j in wk1:
				count += 1
				if j != "0":
					break
			ans += count - 1
			wk1 = [wk1[count - 1]] + wk1[:count - 1] + wk1[count:]
			n[:] = wk1
			break

if ans != -1:
	f = True
	for i in reversed(range(len(n) - 1)):
		if (n[i] == "7") or (n[i] == "2"):
			wk1 = n[:i] + n[i + 1:] + [n[i]]
			ans += len(n) - i - 2
			if wk1[0] != "0":
				f = False
				break
			else:
				count = 0
				for j in wk1:
					count += 1
					if j != "0":
						break
				ans += count - 1
				f = False
				break
	if f:
		ans = -1

if (wkans == -1):
	print(ans)
	quit()
if (ans == -1):
	print(wkans)
	quit()
print(min(ans, wkans))

a=str(raw_input())
if ('5' in a and '0' in a) or ('7' in a and '5' in a) or ('2' in a and '5' in a) or (a.count('0')==2):
    res=[]
    if '5' in a and '0' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('0')
        a1.remove('0')
        a1.insert(0,'0')
        r+=a1.index('5')-1
        a1.remove('5')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if '7' in a and '5' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('5')
        a1.remove('5')
        a1.insert(0,'5')
        r+=a1.index('7')-1
        a1.remove('7')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if '2' in a and '5' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('5')
        a1.remove('5')
        a1.insert(0,'5')
        r+=a1.index('2')-1
        a1.remove('2')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if a.count('0')==2:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('0')
        a1.remove('0')
        r+=a1.index('0')
        a1.remove('0')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if len(res)>0:
        print min(res)
    else:
        print -1

else:
    print -1

# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 03/07/2020

from sys import stdin,stdout
from math import gcd, ceil, sqrt
from collections import Counter
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007

def mover(s, ind1, ind2):
    s = list(s)
    count = 0
    for i in range(ind1, len(s) - 1):
        s[i], s[i + 1] = s[i + 1], s[i]
        count += 1

    for i in range(ind2, len(s) - 2):
        s[i], s[i + 1] = s[i + 1], s[i]
        count += 1

    return [count, "".join(s)]

def check(s):
    count = 0
    for i in range(len(s) - 2):
        if s[i] != '0':
            return count
        else:
            count += 1
    return -1

n = is1()
res = float("inf")
cond = [['2', '5'], ['5', '0'], ['7', '5']]
for i, j in cond:
    if i in n and j in n:
        two = n.rfind(i)
        five = n.rfind(j)
        count, s = mover(n, five, two)
        temp = check(s)
        if temp != -1:
            res = min(res, count + temp)
        elif len(n) == 2:
            res = 0

if res != 0 and n.count('0') >= 2:
    zero1 = n.rfind('0')
    zero2 = n[:zero1].rfind('0')
    count, s = mover(n, zero1, zero2)
    temp = check(s)
    if temp != -1:
        res = min(res, count + temp)
    elif len(n) == 2:
        res = 0

if res == float("inf"):
    print(-1)
else:
    print(res)

n=int(input())
l=(list(str(n)))[::-1]
g=[]
def permut(l,c,c1):
    i=l.copy()
    k=0
    while(True):
        if i.index(c)==0:break
        else:
            j=i.index(c)
            i[j],i[j-1]=i[j-1],i[j]
            k+=1
    m=i[1:]
    while(True):
        if m.index(c1)==0:break
        else:
            j=m.index(c1)
            m[j],m[j-1]=m[j-1],m[j]
            k+=1
    return(k)

if (('2'in l) and ('5' in l)):
    g.append(permut(l,'5','2'))
if (('5'in l) and ('0' in l)):
    g.append(permut(l,'0','5'))
if (('7'in l) and ('5' in l)):
    g.append(permut(l,'5','7'))
if l.count('0')>1:
    g.append(permut(l,'0','0'))

if g==[]:print(-1)
else:print(min(g))

def finder(n,ind):
    i=ind-1
    while(i>=0):
        if(n[i]=="0"):
            break
        else:
            i=i-1
    return(i)

n=input()
ans=[]
l=len(n)

if("2" in n and "5" in n):
    c2=l-n.rfind("2")-2
    c5=l-n.rfind("5")-1

    if(c2<c5):
        k=c2+c5+1
    else:
        k=c2+c5

    if(n[1]=="0" and (n[0]=="2" or n[0]=="5") ):
        ans.append(k+1)
    else:
        ans.append(k)

if("5" in n and "0" in n):
    c5=l-n.rfind("5")-2
    c0=l-n.rfind("0")-1

    if(c5<c0):
        k=c5+c0+1
    else:
        k=c5+c0

    ans.append(k)

if("7" in n and "5" in n):
    c7=l-n.rfind("7")-2
    c5=l-n.rfind("5")-1

    if(c7<c5):
        k=c7+c5+1
    else:
        k=c7+c5

    if(n[1]=="0" and (n[0]=="7" or n[0]=="5") ):
        ans.append(k+1)
    else:
        ans.append(k)

if(n.count("0")>=2):
    c01=l-n.rfind("0")-2
    c02=l-finder(n,n.rfind("0"))-1
    ans.append(c01+c02)

if(int(n)%25==0):
    print(0)
elif(len(ans)==0):
    print(-1)
else:
    print(min(ans))

num = str(input())
n =len(num)
num_r = num[::-1]
s0, s5 = num_r.find('0'),num_r.find('5')
if s0 != -1:
    newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['0','5']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s0 = s0 + s
else:
    s0 = 999999999
if s5 != -1:
    newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['2','7']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s5 = s5 + s
else:
    s0 = 999999999
ssr = min(s0,s5)
if ssr != 999999999:
    print(ssr)
else:
    print(-1)

n=input()
ans=[]
l=len(n)

if("2" in n and "5" in n):
    c2=l-n.rfind("2")-2
    c5=l-n.rfind("5")-1

    if(c2<c5):
        ans.append(c2+c5+1)
    else:
        ans.append(c2+c5)

if("5" in n and "0" in n):
    c5=l-n.rfind("5")-2
    c0=l-n.rfind("0")-1

    if(c5<c0):
        ans.append(c5+c0+1)
    else:
        ans.append(c5+c0)

if("7" in n and "5" in n):
    c7=l-n.rfind("7")-2
    c5=l-n.rfind("5")-1

    if(c7<c5):
        ans.append(c7+c5+1)
    else:
        ans.append(c7+c5)

if(n.count("0")==2):
    c01=l-n.rfind("0")-2
    c02=l-n.rfind("0",c01)-1
    ans.append(c01+c02)

if(int(n)%25==0):
    print(0)
elif(len(ans)==0):
    print(-1)
else:
    print(min(ans))

k = input()
import sys
Min = sys.maxsize
if '5' in k and '0' in k:
    temp = (len(k)-2) - k.rfind('5') + (len(k)-1) - k.rfind('0')
    if (k.rfind('5') > k.rfind('0')):
        temp += 1
    if (temp<Min):
        Min = temp
if '2' in k and '5' in k:
    temp = (len(k)-2) - k.rfind('2') + (len(k)-1) - k.rfind('5')
    if k.rfind('5')==0 and k[1]=='0' and len(k)>3:
        temp += 1
    if (k.rfind('2') > k.rfind('5')):
        temp += 1
    if (temp<Min):
        Min = temp
if '7' in k and '5' in k:
    temp = (len(k)-2) - k.rfind('7') + (len(k)-1) - k.rfind('5')
    if k.rfind('5')==0 and k[1]=='0' and len(k)>3:
        temp += 1
    if (k.rfind('7') > k.rfind('5')):
        temp += 1
    if (temp<Min):
        Min = temp
if k.count('0')>1:
    css = k.rfind('0')
    temp = (len(k)-1) - css
    k = k[:css] + k[css+1:]
    temp += (len(k)-1) - k.rfind('0')
    if (temp<Min):
        Min = temp
if Min==sys.maxsize:
    print(-1)
else:
    print(Min)

a=str(raw_input())
if ('5' in a and '0' in a) or ('7' in a and '5' in a) or ('2' in a and '5' in a) or (a.count('0')>=2):
    res=[]
    if '5' in a and '0' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('0')
        a1.remove('0')
        a1.insert(0,'0')
        r+=a1.index('5')-1
        a1.remove('5')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if '7' in a and '5' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('5')
        a1.remove('5')
        a1.insert(0,'5')
        r+=a1.index('7')-1
        a1.remove('7')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if '2' in a and '5' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('5')
        a1.remove('5')
        a1.insert(0,'5')
        r+=a1.index('2')-1
        a1.remove('2')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if a.count('0')>=2:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('0')
        a1.remove('0')
        r+=a1.index('0')
        a1.remove('0')
        aux=True
        if '0' in a1 and a1[-1]=='0':
            aux=False
            ct=0
            for k in a1[::-1]:
                if k != '0':
                    r+=ct
                    aux=True
                    break
                ct+=1
        if aux:
            res.append(r)
    if len(res)>0:
        print min(res)
    else:
        print -1

else:
    print -1

n = list(input())[::-1]
INF = 10**9
def solve(a, b):
    if (a not in n) or (b not in n):
        return INF
    nn = n[:]
    ia = n.index(a)
    ib = n.index(b)
    if ia<ib:
        nn = nn[:ia] + nn[ia+1:ib] + nn[ib+1:]
    else:
        nn = nn[:ib] + nn[ib+1:ia] + nn[ia+1:]
    cnt = 0
    for i in range(len(n)-2):
        if nn[len(n)-3-i]!='0':
            break
        cnt += 1
    else:
        return INF
    return ia+ib+cnt-1
if n.count('0')>=2:
    ans = -1
    one = False
    for i in range(len(n)):
        if n[i]=='0':
            ans += i
            if one:
                break
            one = True
else:
    ans = INF
ans = min(ans, solve('2', '5'))
ans = min(ans, solve('5', '0'))
ans = min(ans, solve('7', '5'))
if ans==INF:
    print(-1)
else:
    print(ans)

k = input()
import sys
Min = sys.maxsize
if '5' in k and '0' in k:
    temp = (len(k)-2) - k.rfind('5') + (len(k)-1) - k.rfind('0')
    if (k.rfind('5') > k.rfind('0')):
        temp += 1
    if (temp<Min):
        Min = temp
if '2' in k and '5' in k:
    temp = (len(k)-2) - k.rfind('2') + (len(k)-1) - k.rfind('5')
    if (k.rfind('2') > k.rfind('5')):
        temp += 1
    if (temp<Min):
        Min = temp
if '7' in k and '5' in k:
    temp = (len(k)-2) - k.rfind('7') + (len(k)-1) - k.rfind('5')
    if (k.rfind('7') > k.rfind('5')):
        temp += 1
    if (temp<Min):
        Min = temp
if k.count('0')>1:
    css = k.rfind('0')
    temp = (len(k)-1) - css
    k = k[:css]
    temp += (len(k)-1) - k.rfind('0')
    if (temp<Min):
        Min = temp
if Min==99999999:
    print(-1)
else:
    print(Min)

k = input()
zeroes = [-1, -1]
five = -1
two = -1
seven = -1
for i in range(len(k)):
    if k[i] == '0':
        zeroes[zeroes.index(min(zeroes))] = i
    elif k[i] == '2':
        two = i
    elif k[i] == '5':
        five = i
    elif k[i] == '7':
        seven = i
if len(k) == 3 and k[:2] == '50' and k[-1] != '5' and k[-1] != '0':
    print(2)
elif k == '505':
    print(1)
elif k == '500':
    print(0)
elif k[:3] == '500' and five == 0:
    print(len(k) * 2 - zeroes[0] - zeroes[1] - 3)
else:
    ch = []
    fl = 0
    if min(zeroes) > -1:
        fl = 1
        ch.append(len(k) * 2 - zeroes[0] - zeroes[1] - 3)
    if five != -1 and max(zeroes) > -1:
        fl = 1
        if five < (max(zeroes)):
            ch.append(2 * len(k) - max(zeroes) - five - 3)
        else:
            ch.append(2 * len(k) - max(zeroes) - five - 2)
    if five != -1:
        if two != -1:
            fl = 1
            if two < five:
                ch.append(2 * len(k) - two - five - 3)
            else:
                ch.append(2 * len(k) - two - five - 2)
        if seven != -1:
            fl = 1
            if seven < five:
                ch.append(2 * len(k) - seven - five - 3)
            else:
                ch.append(2 * len(k) - seven - five - 2)
    if fl:
        print(min(ch))
    else:
        print(-1)

import sys
s=input()
m=100000000000000000000000000000000000000000000000000000000000000000
t=False
if int(s)%25==0:
    print(0)
    sys.exit()
if s.count("0")>=2 and len(s)>2:
    t=True
    s1=s[::-1]
    x=0
    ind1=-1
    ind2=-1
    for i in range(len(s)):
        if s1[i]=="0":
            if x==0:
                ind1=i
                x=1
            else:
                ind2=i
                break
    m=min(ind1+ind2-1,m)
if "2" in s and "5" in s:
    s1=s[::-1]
    ind1=s1.index("2")
    ind2=s1.index("5")
    if not ((ind1+1==len(s) and s1[ind1-1]=="0") or (ind2+1==len(s) and s1[ind2-1]=="0")):
        if ind2>ind1:
            m=min(ind1+ind2,m)
            t=True
        else:
            m=min(ind1+ind2-1,m)
            t=True
if "0" in s and "5" in s:
    s1=s[::-1]
    ind1=s1.index("0")
    ind2=s1.index("5")
    if not ((ind2+1==len(s) and s1[ind2-1]=="0" and ind2-1!=ind1)):

        if ind2<ind1:
            m=min(ind1+ind2,m)
            t=True
        else:
            m=min(ind1+ind2-1,m)
            t=True
if "7" in s and "5" in s:
    s1=s[::-1]
    ind1=s1.index("7")
    ind2=s1.index("5")
    if not ((ind1+1==len(s) and s1[ind1-1]=="0") or (ind2+1==len(s) and s1[ind2-1]=="0")):
        if ind2>ind1:
            m=min(ind1+ind2,m)
            t=True
        else:
            m=min(ind1+ind2-1,m)
            t=True

if t:
    print(m)
else:
    print(-1)

n=int(input())
l=(list(str(n)))[::-1]
g=[]
def permut(l,c,c1):
    i=l.copy()
    k=0
    while(True):
        if i.index(c)==0:break
        else:
            j=i.index(c)
            i[j],i[j-1]=i[j-1],i[j]
            k+=1
    m=i[1:]
    while(True):
        if m.index(c1)==0:break
        else:
            j=m.index(c1)
            m[j],m[j-1]=m[j-1],m[j]
            k+=1
    if m[-1]=='0':
        k+=1
    return(k)

if (('2'in l) and ('5' in l)):
    g.append(permut(l,'5','2'))
if (('5'in l) and ('0' in l)):
    g.append(permut(l,'0','5'))
if (('7'in l) and ('5' in l)):
    g.append(permut(l,'5','7'))
if l.count('0')>1:
    g.append(permut(l,'0','0'))

if g==[]:print(-1)
else:print(min(g))

INF = 1000

def compute_pair(s, pair):
    n = len(s)
    try:
        l2 = s.rindex(pair[1])
        l1 = s.rindex(pair[0])
        if pair[0] == '0':
            l1 = s[:l2].rindex(pair[1])
    except:
        return INF

    steps = abs((n - 2) - l1) + abs((n - 1) - l2)
    if l1 > l2:
        steps += 1

    if l1 == n - 1:
        steps -= 1

    return steps

def main():
    s = input()
    best = INF
    for pair in ['00', '25', '50', '75']:
        l = compute_pair(s, pair)
        if l < best:
            best = l

    if best == INF:
        best = -1

    print(best)

if __name__ == '__main__':
    main()

num = str(input())
n =len(num)
num_r = num[::-1]
s0, s5 = num_r.find('0'),num_r.find('5')
if s0 != -1:
    newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['0','5']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s0 = s0 + s
    else:
        s0 = 999999999
else:
    s0 = 999999999
if s5 != n-1 or num.find('0') != 1:
    if s5 != -1:
        newnum_r = num_r[:s5] + num_r[s5+1:]
        c= []
        for a in ['2','7']:
            if newnum_r.find(a) != -1:
                c.append(newnum_r.find(a))
        if c != []:
            s = min(c)
            s5 = s5 + s
        else:
            s5 = 999999999
    else:
        s5 = 999999999
    ssr = min(s0,s5)
    if ssr != 999999999:
        print(ssr)
    else:
        print(-1)
else:
    if s5 != -1:
        newnum_r = num_r[:s5] + num_r[s5+1:]
        c= []
        for a in ['2','7']:
            if newnum_r.find(a) != -1:
                c.append(newnum_r.find(a))
        if c != []:
            s = min(c)
            s5 = s5 + s + 1
        else:
            s5 = 999999999
    else:
        s5 = 999999999
    ssr = min(s0,s5)
    if ssr != 999999999:
        print(ssr)
    else:
        print(-1)

maxint = 2147483647

class mylist(list):
    def index(self, obj, *args):
        try:
            if len(args) == 0:
                return super(mylist, self).index(obj)
            if len(args) == 1:
                return super(mylist, self).index(obj,args[0])
            return super(mylist, self).index(obj,args[0],args[1])
        except ValueError:
            return -1

def cost(target,index1, index2):
    if index1 == -1 or index2 == -1:
        return maxint
    if target == '00':
        return index1 + index2 -1
    else:
        return index1 + index2 -1 if index2<index1 else index1+index2

def calcCosts(rn):
    i0 = rn.index('0')
    i00 = rn.index('0',i0+1)
    i2 = rn.index('2')
    i5 = rn.index('5')
    i7 = rn.index('7')
    costs = [('00',cost('00',i0,i00)),('50',cost('50',i5,i0)),('25',cost('25',i2,i5)),('75',cost('75',i7,i5))]
    costs.sort(key=lambda tup:tup[1])
    return costs

def swapCritical(rn,i):
    if i == len(rn)-1:
        for index in range(i-1,-1,-1):
            if rn[index] != '0':
                break
    else:
        index = i-1
    rn[index],rn[index+1] = rn[index+1], rn[index]
    return rn

def swap(rn,typ):
    if typ == '00':
        i0 = rn.index('0')
        i00 = rn.index('0',i0+1)
        if i0 != 0:
            rn[i0-1], rn[i0] = rn[i0], rn[i0-1]
            return rn, 1
        if i00 == 1:
            return rn, 0
        rn[i00-1], rn[i00] = rn[i00], rn[i00-1]
        return rn, 1
    if typ == '50':
        i0 = rn.index('0')
        i5 = rn.index('5')
        if i0 != 0:
            if i0<i5 or i5 == 0:
                rn[i0-1], rn[i0] = rn[i0], rn[i0-1]
                return rn, 1
            rn[i5-1], rn[i5] = rn[i5], rn[i5-1]
            return rn, 1
        if i5 == 1:
            return rn, 0
        if i5 != len(rn)-1:
            rn[i5-1], rn[i5] = rn[i5], rn[i5-1]
            return rn, 1
        rn = swapCritical(rn,i5)
        return rn, 1
    if typ == '25':
        i2 = rn.index('2')
        i5 = rn.index('5')
        if i5 != 0:
            if i5<i2 or i2 == 0:
                swapCritical(rn,i5)
                return rn, 1
            rn[i2-1], rn[i2] = rn[i2], rn[i2-1]
            return rn, 1
        if i2 == 1:
            return rn, 0
        if i2 != len(rn)-1:
            rn[i2-1], rn[i2] = rn[i2], rn[i2-1]
            return rn, 1
        rn = swapCritical(rn,i2)
        return rn, 1
    if typ == '75':
        i7 = rn.index('7')
        i5 = rn.index('5')
        if i5 != 0:
            if i5<i7 or i7 == 0:
                swapCritical(rn,i5)
                return rn, 1
            rn[i7-1], rn[i7] = rn[i7], rn[i7-1]
            return rn, 1
        if i7 == 1:
            return rn, 0
        if i7 != len(rn)-1:
            rn[i7-1], rn[i7] = rn[i7], rn[i7-1]
            return rn, 1
        rn = swapCritical(rn,i7)
        return rn, 1

def realCost(rn):
    costs = calcCosts(rn)
    bestCost = maxint
    for cost in costs:
        if cost[1] >= bestCost:
            return bestCost
        rn,tempcost = swap(rn,cost[0])
        if tempcost == 0:
            return 0
        thiscost = tempcost + realCost(rn)
        if thiscost < bestCost:
            bestCost = thiscost
n = input()
rn = n[::-1]
rn = mylist(rn)
rcost = realCost(rn)
print(rcost if rcost<maxint else -1)

n=input()
a=n[:]
p=len(n)-1
count1,count2=0,0
i=p
flag1,flag2=0,0
while i>-1:
    if n[i]=='5'and flag1==0:
        count1=p-i
        n=n[:i]+n[i+1:]+'5'
        flag1=1
    if a[i]=='0' and flag2==0:
        count2=p-i
        a=a[:i]+a[i+1:]+'0'
        flag2=1
    i=i-1
if flag1==1 or flag2==1:
    i=p-1
    if flag1==1:
        flag1=-1
    if flag2==1:
        flag2=-1
    while i>-1:
        if (int(n[i])-2)%5==0 and flag1==-1:
            count1=count1+p-i-1
            flag1=2
        if int(a[i])%5==0 and flag2==-1:
            count2=count2+p-i-1
            flag2=2
        i=i-1
if flag1==2 and flag2==2:
    print(min(count1,count2))
elif flag1==2 and flag2!=2:
    print(count1)
elif flag1!=2 and flag2==2:
    print(count2)
else:
    print(-1)

from itertools import dropwhile
n=[int(i) for i in input()]
l=len(n)
if len(n)==1:
    print(-1)
    exit()
inf=10**12
#一番左にある場合はめんどいので場合分けしちゃう(逆にする)
#00も場合分け
def calc1(x,y):
    global n,l,inf
    m=n[::-1]
    if x not in n or y not in n:
        #print(x,y,0)
        return inf
    ix,iy=m.index(x),m.index(y)
    #一番右にない場合
    if max(ix,iy)<l-1:
        if iy<ix:
            #print(x,y,1)
            return iy+(ix-1)
        else:
            #print(x,y,2)
            return iy+(ix-1)+1
    else:
        ret=0
        if ix==l-1:
            #右から探して左を見る(0かつ他の選択するやつでない)
            for i in range(l-2,-1,-1):
                if m[i]!=0 and i!=iy:
                    break
            else:
                #print(x,y,3)
                return inf
            if i<iy:
                iy-=1
                ret+=(l-1-i)
                ix-=1
                ret+=(iy+(ix-1))
                #print(x,y,4,ret)
                return ret
            else:
                ret+=iy
                ret+=(l-1-i)
                ix-=1
                ret+=(ix-1)
                #print(x,y,5,ret)
                return ret
        else:
            #右から探して左を見る(0かつ他の選択するやつでない)
            for i in range(l-2,-1,-1):
                if m[i]!=0 and i!=ix:
                    break
            else:
                #print(x,y,6)
                return inf
            if i<ix:
                iy-=1
                ret+=(l-1-i)
                ix-=1
                ret+=(iy+(ix-1)+1)
                #print(x,y,7,ret)
                return ret
            else:
                ret+=iy
                ret+=(l-1-i)
                ix-=1
                ret+=((ix-1)+1)
                #print(x,y,8,ret)
                return ret
#00の時
def calc2(x,y):
    #一番右には絶対ない
    global n,l,inf
    if n.count(0)<2:
        return inf
    m=[l-1-i for i in range(l) if n[i]==0][::-1]
    return m[0]+m[1]-1

ans=min([calc1(2,5),calc1(7,5),calc1(5,0),calc2(0,0)])
#print([calc1(2,5),calc1(7,5),calc1(5,0),calc2(0,0)])
print(-1 if ans==inf else ans)

#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__

def main():
    n = input()
    m = n[::-1]
    res = 10**9

    if int(n) % 25 == 0:
        print(0)
        return

    if n.count('0') >= 2:
        cnt, flag = 0, False
        for i, mi in enumerate(m):
            if mi == '0':
                if flag:
                    cnt += i - 1
                    break
                else:
                    flag = True
                    cnt += i

        res = min(res, cnt)

    if '5' in n:
        i = m.index('5')
        if '0' in n:
            if n.count('5') == 1 and n.index('5') == 0:
                cnt = m.index('0')
                n = n[:-cnt - 1] + n[-cnt:] + '0'
                for i in range(1, len(n)):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 2
                        res = min(res, cnt)
                        break

            else:
                j = m.index('0')
                if i > j:
                    res = min(res, j + i - 1)
                else:
                    res = min(res, j + i)

        if '2' in n:
            if n.count('5') == 1 and n.index('5') == 0:
                cnt = m.index('2')
                for i in range(1, len(n)):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 1
                        res = min(res, cnt)
                        break

            if n.count('2') == 1 and n.index('2') == 0:
                cnt = i
                for i in range(1, len(n)):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 2
                        res = min(res, cnt)
                        break

            if m.index('5') < len(n) - 1 and m.index('2') < len(n) - 1:
                j = m.index('2')
                if i > j:
                    res = min(res, j + i)
                else:
                    res = min(res, j + i - 1)

        if '7' in n:
            if n.count('5') == 1 and n.index('5') == 0:
                cnt = m.index('7')
                for i in range(1, len(n)):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 1
                        res = min(res, cnt)
                        break

            if n.count('7') == 1 and n.index('7') == 0:
                cnt = i
                for i in range(1, len(n)):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 2
                        res = min(res, cnt)
                        break

            if m.index('5') < len(n) - 1 and m.index('7') < len(n) - 1:
                j = m.index('7')
                if i > j:
                    res = min(res, j + i)
                else:
                    res = min(res, j + i - 1)

    print(res if res < 10**9 else -1)

# region fastio

BUFSIZE = 8192

class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0,
                              2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()

def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

def solve1():
    n = m

    try:
        x = n.index('0')
        n = n[x] + n[:x] + n[x+1:]

        x += len(n) - len(n.rstrip('0'))

        y = n.index('5')

        return x + y - 1

    except:
        return float('inf')

def solve2():
    n = m

    try:
        x = n.index('0')
        y = n.find('0', x+1)

        return x + y - 1

    except:
        return float('inf')

def solve3():
    n = m

    try:
        x = n.index('5')
        n = n[x] + n[:x] + n[x+1:]

        x += len(n) - len(n.rstrip('0'))

        y = n.index('2')

        return x + y - 1

    except:
        return float('inf')

def solve4():
    n = m

    try:
        x = n.index('5')
        n = n[x] + n[:x] + n[x+1:]

        x += len(n) - len(n.rstrip('0'))

        y = n.index('7')

        return x + y - 1

    except:
        return float('inf')

m = input()[::-1]

x = min(
    solve1(),
    solve2(),
    solve3(),
    solve4()
)

if x == float('inf'):
    print(-1)
else:
    print(x)

#     Codeforces Round #486 (Div. 3)

from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )

import sys
def getIntList():
    return list(map(int, input().split()))

s0 = input()

def work(s0, st):
    x = s0.rfind(st[1])
    if x<0: return 10000
    r = 0
    r += len(s0) - x -1
    s0 = s0[:x] + s0[x+1:]

    x = s0.rfind(st[0])
    if x<0: return 10000
    r += len(s0) - x -1
    s0 = s0[:x] + s0[x+1:]

    if s0 == '0' * len(s0) : return 10000
    for i in range(len(s0)):
        if s0[i] != '0':
            return r+ i
    return 10000
sz = ['00', '25', '50', '75']
z = [work(s0,s) for s in sz]

r = min(z)

if r>1000: r = -1

print(r)

k = input()
import sys
Min = sys.maxsize
if '5' in k and '0' in k:
    temp = (len(k)-2) - k.rfind('5') + (len(k)-1) - k.rfind('0')
    if not (k.rfind('5')==0 and k[1]=='0'):
        if (k.rfind('5') > k.rfind('0')):
            temp += 1
        if (temp<Min):
            Min = temp
if '2' in k and '5' in k:
    temp = (len(k)-2) - k.rfind('2') + (len(k)-1) - k.rfind('5')
    if not (k.rfind('2')==0 and k[1]=='0'):
        if (k.rfind('2') > k.rfind('5')):
            temp += 1
        if (temp<Min):
            Min = temp
if '7' in k and '5' in k:
    temp = (len(k)-2) - k.rfind('7') + (len(k)-1) - k.rfind('5')
    if not (k.rfind('7')==0 and k[1]=='0'):
        if (k.rfind('7') > k.rfind('5')):
            temp += 1
        if (temp<Min):
            Min = temp
if k.count('0')>1:
    css = k.rfind('0')
    temp = (len(k)-1) - css
    k = k[:css] + k[css+1:]
    temp += (len(k)-1) - k.rfind('0')
    if (temp<Min):
        Min = temp
if Min==sys.maxsize:
    print(-1)
else:
    print(Min)

k = input()
zeroes = [-1, -1]
five = -1
two = -1
seven = -1
for i in range(len(k)):
    if k[i] == '0':
        zeroes[zeroes.index(min(zeroes))] = i
    elif k[i] == '2':
        two = i
    elif k[i] == '5':
        five = i
    elif k[i] == '7':
        seven = i
if len(k) == 3 and k[:2] == '50' and k[-1] != '5' and k[-1] != '0':
    print(2)
elif k == '5020' or k == '5070':
    print(1)
elif k == '5025' or k == '5075' or k == '5000' or k == '5050':
    print(0)
elif k == '505':
    print(1)
elif k == '500':
    print(0)
elif k[:3] == '500' and five == 0:
    print(len(k) * 2 - zeroes[0] - zeroes[1] - 3)
elif len(k) != 4 and ((k[:3] == '502' and two == 2) or (k[:3] == '507' and seven == 2)):
    print((len(k)))
elif (len(k) == 4) and (k[:3] == '502' or k[:3] == '507'):
    print(4)
elif k[:2] == '50' and five == 0 and min(zeroes) == -1 and (seven != -1 or two != -1):
    print(2 * len(k) - max(two, seven) - 1)
else:
    ch = []
    fl = 0
    if min(zeroes) > -1:
        fl = 1
        ch.append(len(k) * 2 - zeroes[0] - zeroes[1] - 3)
    if five != -1 and max(zeroes) > -1:
        fl = 1
        if five < (max(zeroes)):
            ch.append(2 * len(k) - max(zeroes) - five - 3)
        else:
            ch.append(2 * len(k) - max(zeroes) - five - 2)
    if five != -1:
        if two != -1:
            fl = 1
            if two < five:
                ch.append(2 * len(k) - two - five - 3)
            else:
                ch.append(2 * len(k) - two - five - 2)
        if seven != -1:
            fl = 1
            if seven < five:
                ch.append(2 * len(k) - seven - five - 3)
            else:
                ch.append(2 * len(k) - seven - five - 2)
    if fl:
        print(min(ch))
    else:
        print(-1)

import sys
range = xrange
input = raw_input

x = int(input())

xs = str(x)
if xs.count('0')<2 and \
  (xs.count('2') + xs.count('5')) < 2 and \
  (xs.count('5') + xs.count('0')) < 2 and \
  (xs.count('7') + xs.count('5')) < 2:
    print '-1'
    sys.exit()

def f(x,d):
    if d<0: return 100

    sx = str(x)
    n = len(sx)
    if sx[-2:] in ('00','25','50','75'):
        return 0

    besta = 100
    for i in range(len(sx)-1):
        if sx[i] in '0257':
            if sx[i] in '05':
                inter = [n-2,n-1]
            else:
                inter = [n-2]
            for j in inter:
                if i>=j:continue
                if (i!=0 or sx[i+1]!='0'):
                    besta = min(besta, j-i + f(int(''.join((sx[:i],sx[i+1:j+1],sx[i],sx[j+1:]))), d-1))
    return besta

best = f(x,6)

if best == 5:
    print -1
else:
    print best

a=str(raw_input())
if ('5' in a and '0' in a) or ('7' in a and '5' in a) or ('2' in a and '5' in a) or (a.count('0')==2):
    res=[]
    if '5' in a and '0' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('0')
        a1.remove('0')
        a1.insert(0,'0')
        r+=a1.index('5')-1
        res.append(r)
    if '7' in a and '5' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('5')
        a1.remove('5')
        a1.insert(0,'5')
        r+=a1.index('7')-1
        res.append(r)
    if '2' in a and '5' in a:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('5')
        a1.remove('5')
        a1.insert(0,'5')
        r+=a1.index('2')-1
        res.append(r)
    if a.count('0')==2:
        a1=list(a)
        a1=a1[::-1]
        r=a1.index('0')
        a1.remove('0')
        r+=a1.index('0')
        res.append(r)
    print min(res)

else:
    print -1

k = input()
zeroes = [-1, -1]
five = -1
two = -1
seven = -1
for i in range(len(k)):
    if k[i] == '0':
        zeroes[zeroes.index(min(zeroes))] = i
    elif k[i] == '2':
        two = i
    elif k[i] == '5':
        five = i
    elif k[i] == '7':
        seven = i
if len(k) == 3 and k[:2] == '50' and k[-1] != '5' and k[-1] != '0':
    print(2)
elif k == '5020' or k == '5070':
    print(1)
elif k[-2:] == '25' or k[-2:] == '00' or k[-2:] == '50' or k[-2:] == '75':
    print(0)
elif k[-2:] == '52' or k[-2:] == '05' or k[-2:] == '57':
    print(1)
elif k == '505':
    print(1)
elif k == '500':
    print(0)
elif len(k) != 4 and ((k[:3] == '502' and two == 2) or (k[:3] == '507' and seven == 2)):
    print((len(k)))
elif (len(k) == 4) and (k[:3] == '502' or k[:3] == '507'):
    print(4)
elif k[:2] == '50' and five == 0 and min(zeroes) == -1 and (seven != -1 or two != -1):
    print(2 * len(k) - max(two, seven) - 1)
elif k[:2] == '50' and five == 0 and min(zeroes) != -1 and (seven != -1 or two != -1):
    print(min((len(k) * 2 - zeroes[0] - zeroes[1] - 3), (1 + len(k))))
else:
    ch = []
    fl = 0
    if min(zeroes) > -1:
        fl = 1
        ch.append(len(k) * 2 - zeroes[0] - zeroes[1] - 3)
    if five != -1 and max(zeroes) > -1:
        fl = 1
        if five < (max(zeroes)):
            ch.append(2 * len(k) - max(zeroes) - five - 3)
        else:
            ch.append(2 * len(k) - max(zeroes) - five - 2)
    if five != -1:
        if two != -1:
            fl = 1
            if two < five:
                ch.append(2 * len(k) - two - five - 3)
            else:
                ch.append(2 * len(k) - two - five - 2)
        if seven != -1:
            fl = 1
            if seven < five:
                ch.append(2 * len(k) - seven - five - 3)
            else:
                ch.append(2 * len(k) - seven - five - 2)
    if fl:
        print(min(ch))
    else:
        print(-1)

s = raw_input().strip()
n = len(s)
ans = float('inf')

# steps to get 00
idxlist = []
for i in xrange(n - 1, -1, -1):
    if s[i] == '0':
        idxlist.append(i)

    if len(idxlist) == 2: break

if len(idxlist) == 2:
    p1, p2 = idxlist
    ans = min(ans, (n - 1 - p2) + (n - 2 - p1))

# steps to get to 25
p2, p5 = -1, -1
fl = 0
cur = -1
for i in xrange(n - 1, -1, -1):
    if s[i] == '5' and p5 == -1:
        p5 = i
    if s[i] == '2' and p2 == -1:
        p2 = i
    if p2 != -1 and p5 != -1:
        cur = (n - 1 - p5) + (n - 2 - p2)
        if p5 < p2: cur += 1
        fl = 1
        break

if fl == 1:
    news = []
    for i in xrange(n):
        if i == p2 or i == p5: continue
        news.append(s[i])

    i = 0
    while i < len(news) and news[i] == '0': i += 1
    if i != len(news):
        ans = min(ans, cur + i)

# steps to get to 50
p5, p0 = -1, -1
fl = 0
cur = -1
for i in xrange(n - 1, -1, -1):
    if s[i] == '0' and p0 == -1:
        p0 = i
    if s[i] == '5' and p5 == -1:
        p5 = i
    if p5 != -1 and p0 != -1:
        cur = (n - 1 - p0) + (n - 2 - p5)
        if p0 < p5: cur += 1
        fl = 1
        break

if fl == 1:
    news = []
    for i in xrange(n):
        if i == p0 or i == p5: continue
        news.append(s[i])

    i = 0
    while i < len(news) and news[i] == '0': i += 1
    if i != len(news):
        ans = min(ans, cur + i)

# steps to get to 75
p7, p5 = -1, -1
fl = 0
cur = -1
for i in xrange(n - 1, -1, -1):
    if s[i] == '5' and p5 == -1:
        p5 = i
    if s[i] == '7' and p7 == -1:
        p7 = i
    if p7 != -1 and p5 != -1:
        cur = (n - 1 - p5) + (n - 2 - p7)
        if p5 < p7: cur += 1
        fl = 1
        break

if fl == 1:
    news = []
    for i in xrange(n):
        if i == p7 or i == p5: continue
        news.append(s[i])

    i = 0
    while i < len(news) and news[i] == '0': i += 1
    if i != len(news):
        ans = min(ans, cur + i)

if ans == float('inf'):
    print -1
else:
    print ans

s=input()[::-1]
m=I=41
f=s.find('5')+1
i=s.find('0')+1
t=len(s)
if i:
 j=min(s.find('0',i)+1or I,f or I)
 if j<I:
  m=i+j-3
  if j<i:m+=1
if f:
 j=min(s.find('2')+1or I,s.find('7')+1or I)
 if j<I:
  l=f+j-3
  if j<f:l+=1
  if j==t:
   i=t-1
   while i==f or s[i]=='0':
    i-=1
    if i!=f:l+=1
   if i==f:l=I
  m=min(m,l)
print((-1,m)[m<I])

def inx(a,s):
    ll = []
    for i in range(len(a)):
        if s == a[i]:
            ll.append(i)
    return max(ll)

def search(a):
    s = None
    flg = False
    for i in range(len(a)):
        if flg is True:
            break
        if a[i] == '2':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '25'
                    flg = True
                    break
        elif a[i] == '5':
            for j in range(len(a)):
                if a[j] == '2':
                    s = '25'
                    flg = True
                    break
                elif a[j] == '7':
                    s = '75'
                    flg = True
                    break
                elif a[j] == '0':
                    s = '50'
                    flg = True
                    break
        elif a[i] == '7':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '75'
                    flg = True
                    break
        elif a[i] == '0':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '50'
                    flg = True
                    break
                elif a[j] == '0' and i != j:
                    s = '00'
                    flg = True
                    break
    if s is None:
        print(-1)
        exit()
    return s

#def swap(a,b):
#    a, b = b, a
#    return b, a

def czero(a):
        ctr = 0
        index = None
        for i in range(len(a)):
            if a[i] != 0:
                index = i
                break
        if index == 0:
            return None
        else:
            cou = index
            while a[0] == '0':
                a[cou-1], a[cou] = a[cou], a[cou-1]
                ctr+=1
                cou-=1
            return ctr

Counter = 0
a=input()[::-1]

Comb = search(a)
a = list(a)[::-1]
if Comb == '00':
    Nxt = None
    Fst = None
    for i in range(len(a)):
        if a[i] == '0':
            if not Fst:
                Fst = i
            elif not Nxt:
                Nxt = i
            else:
                break

    for i in range(Nxt+1, len(a)):
        a[i-1], a[i] = a[i], a[i-1]
        Counter+=1
    for i in range(Fst+1, len(a)-1):
        a[i-1], a[i] = a[i], a[i-1]
        Counter+=1
else:

    Nxt = inx(a,Comb[1])
    for i in range(Nxt+1, len(a)):
        a[i-1], a[i] = a[i], a[i-1]
        Counter+=1
    Fst = inx(a,Comb[0])
    for i in range(Fst+1, len(a)-1):
        a[i-1], a[i] = a[i], a[i-1]
        Counter+=1

f = czero(a)

if f is None:
    print(Counter)
else:
    print(Counter+f)

def solve1():
    n = m

    try:
        x = n.index('0')
        n = n[x] + n[:x] + n[x+1:]

        if n[-1] == '0':
            x += 1

        y = n.index('5')

        return x + y - 1

    except:
        return float('inf')

def solve2():
    n = m

    try:
        x = n.index('0')
        y = n.find('0', x+1)

        if y == -1:
            raise Exception

        return x + y - 1

    except:
        return float('inf')

def solve3():
    n = m

    try:
        x = n.index('5')
        n = n[x] + n[:x] + n[x+1:]

        if n[-1] == '0':
            x += 1

        y = n.index('2')

        return x + y - 1

    except:
        return float('inf')

def solve4():
    n = m

    try:
        x = n.index('5')
        n = n[x] + n[:x] + n[x+1:]

        if n[-1] == '0':
            x += 1

        y = n.index('7')

        return x + y - 1

    except:
        return float('inf')

m = input()[::-1]

x = min(
    solve1(),
    solve2(),
    solve3(),
    solve4()
)

if x == float('inf'):
    print(-1)
else:
    print(x)

A_str = input()

A = list(A_str)

B = [
    ['2', '5'],
    ['5', '0'],
    ['7', '5']
]

result = 10**9

if int(A_str) % 100 == 0:
    print(0)
else:
    for a, b in B:
        if a not in A or b not in A:
            continue

        cresult = 0

        tmp_str = A_str[:]
        i = tmp_str.rfind(b)
        cresult += len(tmp_str) - 1 - i
        tmp_str = ''.join(A[:i] + A[i + 1:] + [A[i]])

        i = tmp_str.rfind(a)
        cresult += len(tmp_str) - 2 - i

        result = min([result, cresult])

    if result < 10**9:
        print(result)
    else:
        print(-1)

n=int(input())
l=(list(str(n)))[::-1]
g=[]
def permut(l,c,c1):
    i=l.copy()
    k=0
    if ((len(i)>2)and i[-2]==0):
        i[-2],i[-3]=i[-3],i[-2]
        k+=1
    while(True):
        if i.index(c)==0:break
        else:
            j=i.index(c)
            i[j],i[j-1]=i[j-1],i[j]
            k+=1
    m=i[1:]
    while(True):
        if m.index(c1)==0:break
        else:
            j=m.index(c1)
            m[j],m[j-1]=m[j-1],m[j]
            k+=1
    return(k)

if (('2'in l) and ('5' in l)):
    g.append(permut(l,'5','2'))
if (('5'in l) and ('0' in l)):
    g.append(permut(l,'0','5'))
if (('7'in l) and ('5' in l)):
    g.append(permut(l,'5','7'))
if l.count('0')>1:
    g.append(permut(l,'0','0'))

if g==[]:print(-1)
else:print(min(g))

import sys
s=input()
m=10000000000000000000000000000000000
t=False
if int(s)%25==0:
    print(0)
    sys.exit()
if s.count("0")>=2 and len(s)>2:
    t=True
    s1=s[::-1]
    x=0
    ind1=-1
    ind2=-1
    for i in range(len(s)):
        if s1[i]=="0":
            if x==0:
                ind1=i
                x=1
            else:
                ind2=i
                break
    m=min(ind1+ind2-1,m)
if "2" in s and "5" in s:
    s1=s[::-1]
    ind1=s1.index("2")
    ind2=s1.index("5")
    if not ((ind1+1==len(s) and s1[ind1-1]=="0") or (ind2+1==len(s) and s1[ind2-1]=="0")):
        if ind2>ind1:
            m=min(ind1+ind2,m)
            t=True
        else:
            m=min(ind1+ind2-1,m)
            t=True
if "0" in s and "5" in s:
    s1=s[::-1]
    ind1=s1.index("0")
    ind2=s1.index("5")
    if not ((ind2+1==len(s) and s1[ind2-1]=="0" and ind2-1!=ind1)):

        if ind2<ind1:
            m=min(ind1+ind2,m)
            t=True
        else:
            m=min(ind1+ind2-1,m)
            t=True
if "7" in s and "5" in s:
    s1=s[::-1]
    ind1=s1.index("7")
    ind2=s1.index("5")
    if not ((ind1+1==len(s) and s1[ind1-1]=="0") or (ind2+1==len(s) and s1[ind2-1]=="0")):
        if ind2>ind1:
            m=min(ind1+ind2,m)
            t=True
        else:
            m=min(ind1+ind2-1,m)
            t=True

if t:
    print(m)
else:
    print(-1)

n=int(input())
l=(list(str(n)))[::-1]
g=[]
def permut(l,c,c1):
    i=l.copy()
    k=0
    while(True):
        if i.index(c)==0:break
        else:
            j=i.index(c)
            i[j],i[j-1]=i[j-1],i[j]
            k+=1
    m=i[1:]
    while(True):
        if m.index(c1)==0:break
        else:
            j=m.index(c1)
            m[j],m[j-1]=m[j-1],m[j]
            k+=1
    if m[-1]=='0':
        k+=1
    return(k)

if (('2'in l) and ('5' in l)):
    g.append(permut(l,'5','2'))
if (('5'in l) and ('0' in l)):
    g.append(permut(l,'0','5'))
if (('7'in l) and ('5' in l)):
    g.append(permut(l,'5','7'))
if l.count('0')>1:
    g.append(permut(l,'0','0'))

if g==[]:print(-1)
else:print(min(g))

num = str(input())
n =len(num)
num_r = num[::-1]
s0, s5 = num_r.find('0'),num_r.find('5')
if s0 != -1:
    newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['0','5']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s0 = s0 + s
else:
    s0 = 999999999
if s5 != -1:
    newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['2','7']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s5 = s5 + s
else:
    s0 = 999999999
ssr = min(s0,s5)
if ssr != 999999999:
    print(ssr)
else:
    print(-1)

s = input().strip()[::-1]

def find(a, b):
    if a not in s or b not in s: return 40
    i = s.index(a)
    if(a == b):
        if b not in s[i+1]: return 40
        j = s.index(b, i+1)
    else: j = s.index(b)
    return i + j + (1 if j < i else 0)

t = min(find('0', '0'), find('2', '5'), find('5', '0'), find('7', '5'))
print(t if t < 40 else -1)

#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__

def main():
    n = input()
    m = n[::-1]

    res = 10**9
    if n.count('0') >= 2:
        cnt, flag = 0, False
        for i, mi in enumerate(m):
            if mi == '0':
                if flag:
                    cnt += i - 1
                    break
                else:
                    flag = True
                    cnt += i

        res = min(res, cnt)

    if '5' in n:
        i = m.index('5')
        if '0' in n:
            j = m.index('0')
            if i > j:
                res = min(res, j + i - 1)
            else:
                res = min(res, j + i)
        if '2' in n:
            if n.count('5') == 1 and n.index('5') == 0:
                cnt = m.index('2')
                for i in range(1, len(n) - 1):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 2
                        res = min(res, cnt)
            elif n.count('2') == 1 and n.index('2') == 0:
                cnt = i
                for i in range(1, len(n) - 1):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 2
                        res = min(res, cnt)
            else:
                j = m.index('2')
                if i > j:
                    res = min(res, j + i)
                else:
                    res = min(res, j + i - 1)
        if '7' in n:
            if n.count('5') == 1 and n.index('5') == 0:
                cnt = m.index('7')
                for i in range(1, len(n) - 1):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 2
                        res = min(res, cnt)
            elif n.count('7') == 1 and n.index('7') == 0:
                cnt = i
                for i in range(1, len(n) - 1):
                    if n[i] != '0':
                        cnt += i - 1
                        cnt += len(n) - 2
                        res = min(res, cnt)
            else:
                j = m.index('7')
                if i > j:
                    res = min(res, j + i)
                else:
                    res = min(res, j + i - 1)

    print(res if res < 10**9 else -1)

# region fastio

BUFSIZE = 8192

class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0,
                              2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()

def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

def search(a):
    s = None
    flg = False
    for i in range(len(a)):
        if flg is True:
            break
        if a[i] == '2':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '25'
                    flg = True
                    break
        elif a[i] == '5':
            for j in range(len(a)):
                if a[j] == '2':
                    s = '25'
                    flg = True
                    break
                elif a[j] == '7':
                    s = '75'
                    flg = True
                    break
                elif a[j] == '0':
                    s = '50'
                    flg = True
                    break
        elif a[i] == '7':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '75'
                    flg = True
                    break
        elif a[i] == '0':
            for j in range(len(a)):
                if a[j] == '5':
                    s = '50'
                    flg = True
                    break
                elif a[j] == '0' and i != j:
                    s = '00'
                    flg = True
                    break
    if s is None:
        print(-1)
        exit()
    return s

#def swap(a,b):
#    a, b = b, a
#    return b, a

def czero(a):
        ctr = 0
        index = None
        for i in range(len(a)):
            if a[i] != 0:
                index = i
                break
        if index == 0:
            return None
        else:
            cou = index
            while a[0] == '0':
                a[cou-1], a[cou] = a[cou], a[cou-1]
                ctr+=1
                cou-=1
            return ctr

Counter = 0
a=input()[::-1]

Comb = search(a)

a = list(a)[::-1]

Nxt = a.index(Comb[1])
for i in range(Nxt+1, len(a)):
    a[i-1], a[i] = a[i], a[i-1]
    Counter+=1
Fst = a.index(Comb[0])
for i in range(Fst+1, len(a)-1):
    a[i-1], a[i] = a[i], a[i-1]
    Counter+=1

f = czero(a)

if f is None:
    print(Counter)
else:
    print(Counter+f)

n = list(input())[::-1]
INF = 10**9
if n in ['25', '50', '75']:
    print(0)
    exit(0)

def solve(a, b):
    if (a not in n) or (b not in n):
        return INF
    nn = n[:]
    ia = nn.index(a)
    nn = [a]+nn[:ia]+nn[ia+1:]
    ib = nn.index(b)
    nn = [a,b]+nn[1:ib]+nn[ib+1:]
    cnt = 0
    for i in range(len(n)-1, 1, -1):
        if nn[i]!='0':
            break
        cnt += 1
    else:
        return INF
    return ia+ib+cnt-1
if n.count('0')>=2:
    ans = -1
    one = False
    for i in range(len(n)):
        if n[i]=='0':
            ans += i
            if one:
                break
            one = True
else:
    ans = INF
ans = min(ans, solve('5', '2'))
ans = min(ans, solve('0', '5'))
ans = min(ans, solve('5', '7'))
if ans==INF:
    print(-1)
else:
    print(ans)

k = input()
zeroes = [-1, -1]
five = -1
two = -1
seven = -1
for i in range(len(k)):
    if k[i] == '0':
        zeroes[zeroes.index(min(zeroes))] = i
    elif k[i] == '2':
        two = i
    elif k[i] == '5':
        five = i
    elif k[i] == '7':
        seven = i
if len(k) == 3 and k[:2] == '50' and k[-1] != '5' and k[-1] != '0':
    print(2)
elif k == '5020' or k == '5070':
    print(1)
elif k[-2:] == '25' or k[-2:] == '00' or k[-2:] == '50' or k[-2:] == '75':
    print(0)
elif k[-2:] == '52' or k[-2:] == '05' or k[-2:] == '57':
    print(1)
elif k == '505':
    print(1)
elif k == '500':
    print(0)
elif k[:3] == '500' and five == 0:
    print(len(k) * 2 - zeroes[0] - zeroes[1] - 3)
elif len(k) != 4 and ((k[:3] == '502' and two == 2) or (k[:3] == '507' and seven == 2)):
    print((len(k)))
elif (len(k) == 4) and (k[:3] == '502' or k[:3] == '507'):
    print(4)
elif k[:2] == '50' and five == 0 and min(zeroes) == -1 and (seven != -1 or two != -1):
    print(2 * len(k) - max(two, seven) - 1)
else:
    ch = []
    fl = 0
    if min(zeroes) > -1:
        fl = 1
        ch.append(len(k) * 2 - zeroes[0] - zeroes[1] - 3)
    if five != -1 and max(zeroes) > -1:
        fl = 1
        if five < (max(zeroes)):
            ch.append(2 * len(k) - max(zeroes) - five - 3)
        else:
            ch.append(2 * len(k) - max(zeroes) - five - 2)
    if five != -1:
        if two != -1:
            fl = 1
            if two < five:
                ch.append(2 * len(k) - two - five - 3)
            else:
                ch.append(2 * len(k) - two - five - 2)
        if seven != -1:
            fl = 1
            if seven < five:
                ch.append(2 * len(k) - seven - five - 3)
            else:
                ch.append(2 * len(k) - seven - five - 2)
    if fl:
        print(min(ch))
    else:
        print(-1)

import sys
range = xrange
input = raw_input

x = int(input())

xs = str(x)
if xs.count('0')<2 and \
  (xs.count('2') + xs.count('5')) < 2 and \
  (xs.count('5') + xs.count('0')) < 2 and \
  (xs.count('7') + xs.count('5')) < 2:
    print '-1'
    sys.exit()

def f(x,d):
    sx = str(x)
    n = len(sx)
    if sx[-2:] in ('00','25','50','75'):
        return 0
    if d<0: return 100

    besta = 100
    for i in range(len(sx)-1):
        if sx[i] in '0257':
            if sx[i] in '05':
                inter = [n-2,n-1]
            else:
                inter = [n-2]
            if i+1<n:
                inter.append(i+1)
            for j in inter:
                if i>=j:continue
                if (i!=0 or sx[i+1]!='0'):
                    besta = min(besta, j-i + f(int(''.join((sx[:i],sx[i+1:j+1],sx[i],sx[j+1:]))), d-1))
    return besta

best = f(x,2)

if best >= 100:
    print -1
else:
    print best

# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = list(map(int, input()))
N = len(S)

if N <= 1:
    print(-1)
    exit()

def calc(num1, num2):
    if S[-2] == num1 and S[-1] == num2:
        return 0
    if S[-1] == num1 and S[-2] == num2:
        return 1
    res = 0
    cnt = 1
    T = S[:]
    for i in range(N-3, -1, -1):
        if T[i] == num1:
            T[i], T[-2] = T[-2], T[i]
            j = i
            while j < N and T[j] == 0:
                j += 1
                cnt += 1
            if j == N:
                return INF
            else:
                T[i], T[j] = T[j], T[i]
            break
        else:
            cnt += 1
    else:
        return INF
    res += cnt
    cnt = 2
    for i in range(N-3, -1, -1):
        if S[i] == num2:
            T[i], T[-2] = T[-2], T[i]
            j = i
            while j < N and T[j] == 0:
                j += 1
                cnt += 1
            if j == N:
                return INF
            else:
                T[i], T[j] = T[j], T[i]
            break
        else:
            cnt += 1
    else:
        return INF
    res += cnt
    return res

ans = min(calc(5, 0), calc(2, 5), calc(7, 5), calc(0, 0))
if ans == INF:
    print(-1)
else:
    print(ans)

n=int(input())
l=(list(str(n)))[::-1]
g=[]
def permut(l,c,c1):
    i=l.copy()
    k=0
    while(True):
        if i.index(c)==0:break
        else:
            j=i.index(c)
            i[j],i[j-1]=i[j-1],i[j]
            k+=1
    m=i[1:]
    while(True):
        if m.index(c1)==0:break
        else:
            j=m.index(c1)
            m[j],m[j-1]=m[j-1],m[j]
            k+=1
    return(k)

if (('2'in l) and ('5' in l)):
    g.append(permut(l,'5','2'))
if (('5'in l) and ('0' in l)):
    g.append(permut(l,'0','5'))
if (('7'in l) and ('5' in l)):
    g.append(permut(l,'5','7'))
if l.count('0')>1:
    g.append(permut(l,'0','0'))

if g==[]:print(-1)
else:print(min(g))

num = str(input())
n =len(num)
num_r = num[::-1]
s0, s5 = num_r.find('0'),num_r.find('5')
if s0 != -1:
    newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['0','5']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s0 = s0 + s
else:
    s0 = 999999999
if s5 != -1:
    newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['2','7']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s5 = s5 + s
else:
    s5 = 999999999
ssr = min(s0,s5)
if ssr != 999999999:
    print(ssr)
else:
    print(-1)

num = str(input())

endings = [[0, 0], [5, 2], [0, 5], [5, 7]]
lenght = len(num)
candidate = []

for tup in endings:
    poss  = []
    ind   = []
    checked = []
    count = 0

    for i in tup:

        for j in range(lenght - 1, -1, -1):

            index = lenght - j - 1

            if str(i) == num[j] and j not in ind and int(num[j]) not in checked:

                if len(ind):
                    if str(tup[1]) == num[j] and j < ind[0]:
                        index = lenght - j - 2
                ind.append(j)
                poss.append(index)
                checked.append(i)
                count += 1

            if count == 2:
                s = sum(poss)

                if (num[1] == '0' and 1 not in poss) or (num[2] == '0' or 2 not in poss):
                    if (0 in poss and 1 in poss) and num[2] == '0':
                        s += 2
                    elif (0 in poss and num[1] == '0'):
                        s += 1

                candidate.append(s)
                break

if len(candidate):
    print(min(candidate))
else:
    print(-1)

s = input().strip()

def find(a, b):
    if a not in s or b not in s: return 40
    j = s.rindex(b)
    i = 0
    for t,v in enumerate(s):
        if t != j and v == a: i = t
    o = 0
    if not (i and j) and len(s) > 2:
        for t in range(len(s)):
            if t != i and t != j and s[t] == '0': o += 1
    return (i > j) + 2 * len(s) - i - j - 3 + o

t = min(find('0', '0'), find('2', '5'), find('5', '0'), find('7', '5'))
print(t if t < 40 else -1)

A_str = input()

A = list(A_str)

B = [
    ['2', '5'],
    ['5', '0'],
    ['7', '5']
]

result = 10**9

if int(A_str) % 100 == 0:
    print(0)
else:
    for a, b in B:
        if a not in A or b not in A:
            continue

        cresult = 0

        tmp_str = A_str[:]
        i = tmp_str.rfind(b)
        cresult += len(tmp_str) - 1 - i
        tmp_str = ''.join(A[:i] + A[i + 1:] + [A[i]])

        i = tmp_str.rfind(a)
        cresult += len(tmp_str) - 2 - i
        tmp_str = list(tmp_str)
        tmp_str = ''.join(tmp_str[:i] + tmp_str[i + 1:-1] + [tmp_str[i]] + [tmp_str[-1]])

        for i in range(len(tmp_str)):
            if tmp_str[i] != '0':
                break

        result = min([result, cresult + i])

    if A.count('0') > 1:
        cresult = 0
        i = A_str.rfind('0')
        cresult += len(A_str) - 1 - i
        i = A_str[:-1].rfind('0')
        cresult += len(A_str) - 2 - i

        result = min([result, cresult])

    if result < 10**9:
        print(result)
    else:
        print(-1)

a = input()[::-1]
d = ['52','05','57']
if len(a)<2: print(-1)
else:
    if a[:2] in d:
        print(0)
    else:
        ans = 99999999
        if len([i for i in a if i =='0']) >=2:
            x,y=-1,-1
            for i in range(len(a)):
                if a[i] == '0':
                    if x<0:x = i
                    elif y<0:y = i
                    else:break
            ans = x+y-1

        for p in d:
            x,y = -1,-1
            for i in range(len(a)):
                if a[i] == p[0] and x<0:
                    x = i
                if a[i] == p[1] and y<0:
                    y = i
            if x<0 or y<0: continue
            print(x,y)
            c = 0
            if x>y:
                c+1
                x,y = y,x
            if y == len(a)-1 and a[-1] == '0' and x != len(a)-2:
                for i in range(len(a)-1):
                    if a[i]!='0' and i != x:
                        z=i
                    c+=len(a)-2-z
            c+=x+y-1
            ans = min(ans,c)
        if ans == 99999999: ans = -1
        print(ans)

A_str = input()

A = list(A_str)

B = [
    ['2', '5'],
    ['5', '0'],
    ['7', '5']
]

result = 10**9

if int(A_str) % 100 == 0:
    print(0)
else:
    for a, b in B:
        if a not in A or b not in A:
            continue

        cresult = 0

        tmp_str = A_str[:]
        i = tmp_str.rfind(b)
        cresult += len(tmp_str) - 1 - i
        tmp_str = ''.join(A[:i] + A[i + 1:] + [A[i]])

        i = tmp_str.rfind(a)
        cresult += len(tmp_str) - 2 - i

        result = min([result, cresult])

    if A.count('0') > 1:
        cresult = 0
        i = A_str.rfind('0')
        cresult += len(A_str) - 1 - i
        i = A_str[:-1].rfind('0')
        cresult += len(A_str) - 2 - i

        result = min([result, cresult])

    if result < 10**9:
        print(result)
    else:
        print(-1)

num = str(input())

endings = [[0, 0], [5, 2], [0, 5], [5, 7]]
lenght = len(num)
candidate = []

if lenght == 2:
    if [int(num[1]), int(num[0])] in endings:
        print(0)
    else:
        print(-1)
    exit()

for tup in endings:
    poss  = []
    ind   = []
    leftCheck = [i for i in tup]
    count = 0

    for i in tup:

        for j in range(lenght - 1, -1, -1):

            index = lenght - j - 1

            if str(i) == num[j] and j not in ind and int(num[j]) in leftCheck:

                if len(ind):
                    if str(tup[1]) == num[j] and j < ind[0]:
                        index -= 1
                ind.append(j)
                poss.append(index)
                del leftCheck[leftCheck.index(i)]
                count += 1

            if count == 2:
                s = sum(poss)

                if (num[1] == '0' and 1 not in ind) or (num[2] == '0' or 2 not in ind):
                    if (0 in poss and 1 in ind) and num[2] == '0' and int(num[2]) not in tup:
                        s += 2
                    elif (0 in ind and num[1] == '0') and (int(num[1]) not in tup):
                        s += 1

                candidate.append(s)
                break

if len(candidate):
    print(min(candidate))
else:
    print(-1)

n =input()
n2 = len(n)
num1 = n.rfind('5')
num2 = n.rfind('7')
num3 = n.rfind('2')
num4 = n.rfind('0')
num5 = n[:num4].rfind('0')
num6 = -1
num7 = n.find('0')
for i in range(1,n2):
    if n[i] != '0':
        num6 = i
        break
if ((num1 != -1 and  num4!= -1)  or (num1 != -1 and  num2!= -1)
    or (num3 != -1 and  num1!= -1) or (num4 != -1 and  num5!= -1)):
    ans = 100
    if num1 != -1 and  num4!= -1:
        if num1 > num4:
            ans = min(ans,abs(n2-2-num1)+1 + abs(n2-1-num4))
        else:
            ans = min(ans,abs(n2-2-num1) + abs(n2-1-num4))
    if num4 != -1 and  num5!= -1:
        ans = min(ans,abs(n2-2-num5) + abs(n2-1-num4))
    if num1 != -1 and  num2!= -1:
        if n2 == 2:
            ans = min(ans,abs(n2-2-num2) + abs(n2-1-num1))
        elif num4 == -1:
            if num2 > num1:
                ans = min(ans,abs(n2-2-num2)+1 +abs( n2-1-num1))
            else:
                ans = min(ans,abs(n2-2-num2) +abs( n2-1-num1))
        elif not((num1 == 0 and num2 == 1 and num7 == 2) or (num2 == 0 and num1 == 1 and num7 == 2)):
            if (num1 == 0 or num2 == 0) and num7 == 1:
                ans = min(ans,abs(n2-2-num2) + abs(n2-1-num1) + num6 - 1)
            elif num2 > num1:
                ans = min(ans,abs(n2-2-num2)+1 +abs( n2-1-num1))
            else:
                ans = min(ans,abs(n2-2-num2) +abs( n2-1-num1))
    if num1 != -1 and  num3!= -1:
        if n2 == 2:
            ans = min(ans,abs(n2-2-num3) + abs(n2-1-num1))
        elif num4 == -1:
            if num3 > num1:
                ans = min(ans,abs(n2-2-num3)+1 + abs(n2-1-num1))
            else:
                ans = min(ans,abs(n2-2-num3) + abs(n2-1-num1))
        elif not((num1 == 0 and num3 == 1 and num7 == 2) or (num3 == 0 and num1 == 1 and num7 == 2)):
            if (num1 == 0 or num3 == 0) and num7 == 1:
                ans = min(ans,abs(n2-2-num3) + abs(n2-1-num1) + num6 - 1)
            elif num3 > num1:
                ans = min(ans,abs(n2-2-num3)+1 +abs( n2-1-num1))
            else:
                ans = min(ans,abs(n2-2-num3) +abs( n2-1-num1))
    if n[n2-2:] == "05" or n[n2-2:] == "57" or n[n2-2:] == "52":
        ans = 1
    if n[n2-2:] == "50" or n[n2-2:] == "75" or n[n2-2:] == "25" or n[n2-2:] == "00":
        ans = 0
    print(ans)
else:
    print(-1)

n=input()
ans=[]
l=len(n)

if("2" in n and "5" in n):
    c2=l-n.rfind("2")-2
    c5=l-n.rfind("5")-1

    if(c2<c5):
        ans.append(c2+c5+1)
    else:
        ans.append(c2+c5)

if("5" in n and "0" in n):
    c5=l-n.rfind("5")-2
    c0=l-n.rfind("0")-1

    if(c5<c0):
        ans.append(c5+c0+1)
    else:
        ans.append(c5+c0)

if("7" in n and "5" in n):
    c7=l-n.rfind("7")-2
    c5=l-n.rfind("5")-1

    if(c7<c5):
        ans.append(c7+c5+1)
    else:
        ans.append(c7+c5)

if(n.count("0")==2):
    c01=l-n.rfind("0")-2
    c02=l-n.rfind("0",c01)-1
    ans.append(c01+c02)

if(int(n)%25==0):
    print(0)
elif(len(ans)==0):
    print(-1)
else:
    print(min(ans))

num = str(input())

endings = [[0, 0], [5, 2], [0, 5], [5, 7]]
lenght = len(num)
candidate = []

for tup in endings:
    poss  = []
    ind   = []
    count = 0

    for i in tup:

        for j in range(lenght - 1, -1, -1):

            index = lenght - j - 1

            if str(i) == num[j] and j not in ind:

                if len(ind):
                    if str(tup[1]) == num[j] and j < ind[0]:
                        index -= 1
                ind.append(j)
                poss.append(index)

                count += 1
            if count == 2:
                candidate.append(sum(poss))
                break

if len(candidate):
    print(min(candidate))
else:
    print(-1)

k = input()
import sys
Min = sys.maxsize
if '5' in k and '0' in k:
    temp = (len(k)-2) - k.rfind('5') + (len(k)-1) - k.rfind('0')
    if (k.rfind('5') > k.rfind('0')):
        temp += 1
    if (temp<Min):
        Min = temp
if '2' in k and '5' in k:
    temp = (len(k)-2) - k.rfind('2') + (len(k)-1) - k.rfind('5')
    if (k.rfind('2') > k.rfind('5')):
        temp += 1
    if (temp<Min):
        Min = temp
if '7' in k and '5' in k:
    temp = (len(k)-2) - k.rfind('7') + (len(k)-1) - k.rfind('5')
    if (k.rfind('7') > k.rfind('5')):
        temp += 1
    if (temp<Min):
        Min = temp
if k.count('0')>1:
    css = k.rfind('0')
    temp = (len(k)-1) - css
    k = k[:css]
    temp += (len(k)-1) - k.rfind('0')
    if (temp<Min):
        Min = temp
if Min==sys.maxsize:
    print(-1)
else:
    print(Min)

num = str(input())
n =len(num)
num_r = num[::-1]
s0, s5 = num_r.find('0'),num_r.find('5')
if s0 != -1:
    newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['0','5']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s0 = s0 + s
else:
    s0 = 999999999
if s5 != n-1 or num.find('0') != 1:
    if s5 != -1:
        newnum_r = num_r[:s0] + num_r[s0+1:]
        c= []
        for a in ['2','7']:
            if newnum_r.find(a) != -1:
                c.append(newnum_r.find(a))
        if c != []:
            s = min(c)
            s5 = s5 + s
    else:
        s5 = 999999999
    ssr = min(s0,s5)
    if ssr != 999999999:
        print(ssr)
    else:
        print(-1)
else:
    if s5 != -1:
        newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['2','7']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s5 = s5 + s + 1
    else:
        s5 = 999999999
    ssr = min(s0,s5)
    if ssr != 999999999:
        print(ssr)
    else:
        print(-1)

INF = 1e18

def find_number(use_pos, c, s):
    for i in range(len(s) - 1, -1, -1):
        if (len(use_pos) == 0 or use_pos[0] != i) and s[i] == c:
            use_pos.append(i)
            return use_pos
    return use_pos

def make_integer(c1, c2, s):
    use_pos = []
    use_pos = find_number(use_pos, c2, s)
    use_pos = find_number(use_pos, c1, s)
    if len(use_pos) == 2:
        return max(len(s) - 1 - use_pos[0], 0) + max(len(s) - 2 - use_pos[1], 0)  + (use_pos[0] < use_pos[1] and
        use_pos[0] != len(s) - 2 and use_pos[1] != len(s) - 1 and c1 != '0')
    return INF

def main():
    n = input()
    ans = min(make_integer('0', '0', n), make_integer('5', '0', n), make_integer('2', '5', n))
    if ans == INF:
        ans = -1
    print(ans)

main()

def solve1():
    n = m

    try:
        x = n.index('0')
        n = n[x] + n[:x] + n[x+1:]

        x += len(n) - len(n.rstrip('0'))

        y = n.index('5')

        return x + y - 1

    except:
        return float('inf')

def solve2():
    n = m

    try:
        x = n.index('0')
        y = n.find('0', x+1)

        return x + y - 1

    except:
        return float('inf')

def solve3():
    n = m

    try:
        x = n.index('5')
        n = n[x] + n[:x] + n[x+1:]

        x += len(n) - len(n.rstrip('0'))

        y = n.index('2')

        return x + y - 1

    except:
        return float('inf')

def solve4():
    n = m

    try:
        x = n.index('5')
        n = n[x] + n[:x] + n[x+1:]

        x += len(n) - len(n.rstrip('0'))

        y = n.index('7')

        return x + y - 1

    except:
        return float('inf')

m = input()[::-1]

x = min(
    solve1(),
    solve2(),
    solve3(),
    solve4()
)

if x == float('inf'):
    print(-1)
else:
    print(x)

num = str(input())
n =len(num)
num_r = num[::-1]
s0, s5 = num_r.find('0'),num_r.find('5')
if s0 != -1:
    newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['0','5']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s0 = s0 + s
    else:
        s0 = 999999999
else:
    s0 = 999999999
if s5 != n-1 or num.find('0') != 1:
    if s5 != -1:
        newnum_r = num_r[:s0] + num_r[s0+1:]
        c= []
        for a in ['2','7']:
            if newnum_r.find(a) != -1:
                c.append(newnum_r.find(a))
        if c != []:
            s = min(c)
            s5 = s5 + s
    else:
        s5 = 999999999
    ssr = min(s0,s5)
    if ssr != 999999999:
        print(ssr)
    else:
        print(-1)
else:
    if s5 != -1:
        newnum_r = num_r[:s0] + num_r[s0+1:]
    c= []
    for a in ['2','7']:
        if newnum_r.find(a) != -1:
            c.append(newnum_r.find(a))
    if c != []:
        s = min(c)
        s5 = s5 + s + 1
    else:
        s5 = 999999999
    ssr = min(s0,s5)
    if ssr != 999999999:
        print(ssr)
    else:
        print(-1)

n=int(input())
l=(list(str(n)))[::-1]
g=[]
print(l)
def permut(l,c,c1):
    i=l.copy()
    print(i)
    k=0
    while(True):
        if i.index(c)==0:break
        else:
            j=i.index(c)
            i[j],i[j-1]=i[j-1],i[j]
            k+=1
    print(l)
    m=i[1:]
    print(m)
    while(True):
        if m.index(c1)==0:break
        else:
            j=m.index(c1)
            m[j],m[j-1]=m[j-1],m[j]
            k+=1
    if m[-1]=='0':
        k+=1
    print(k)
    return(k)

if (('2'in l) and ('5' in l)):
    g.append(permut(l,'5','2'))
if (('5'in l) and ('0' in l)):
    g.append(permut(l,'0','5'))
if (('7'in l) and ('5' in l)):
    g.append(permut(l,'5','7'))
if l.count('0')>1:
    g.append(permut(l,'0','0'))

if g==[]:print(-1)
else:print(min(g))

num = input()[::-1]
possibility1 = False
possibility2 = False
possibility0 = False
contains1 = []
contains2 = []
out1 = 2 * len(num)
out2 = 2 * len(num)
if '0' in num:
    first_char1 = '0'
    if num.find('0', num.find('0') + 1):
        possibility0 = True
        out3 = num.find('0', num.find('0') + 1) + num.find('0') - 1
    if '5' in num:
        possibility1 = True
        contains1.append('5')
elif '5' in num:
    first_char2 = '5'
    if '2' in num:
        possibility2 = True
        contains2.append('2')

if possibility1 or possibility2 or possibility0:
    if possibility1:
        first = num.find(first_char1)
        second = min([num.find(i) for i in contains1])
        out1 = first + second
        if first < second:
            out1 -= 1

    if possibility2:
        first = num.find(first_char2)
        second = min([num.find(i) for i in contains2])
        out2 = first + second
        if first < second:
            out2 -= 1
    if possibility1 and not possibility2 or possibility0:
        if possibility0:
            print(min(out1, out3))
        else:
            print(out1)
    elif possibility2 and not possibility1 or possibility0:
        if possibility0:
            print(min(out2, out3))
        else:
            print(out2)
    elif possibility1 and possibility2 or possibility0:
        if possibility0:
            print(min(min(out1, out2), out3))
        else:
            print(min(out1, out2))
else:
    print(-1)