https://www.acmicpc.net/problem/1105
We iterate through the 2 numbers and if the 2 lengths are diff, then immediately it is 0 cuz there definitely is a way to represent a number without any 8.
If lengths are same, we iterate from the rightmost where if both values are 8, then there is no alternative but to use number 8 too. But once the values are different, we can break out of the loop cuz 82 and 88 and when value is at 2 and 8, we are guaranteed that we can represent a number without 8.
n, m = map(str, input().strip().split())
if len(n) != len(m):
print(0)
exit()
count = 0
for i in range(len(n)):
if n[i] == m[i]:
if n[i] == '8':
count += 1
else:
break
print(count)
n time and space