-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1107.py
More file actions
31 lines (30 loc) · 717 Bytes
/
1107.py
File metadata and controls
31 lines (30 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
ch = int(input())
brk_n = int(input())
brk_btn = list()
if brk_n!=0:
brk_btn = input().split()
min_cnt = abs(100-ch)
for i in range(500000):
if i > min_cnt:
break
pcheck = True
mcheck = True
if brk_btn:
if ch-i>=0:
for btn in brk_btn:
if btn in str(ch - i):
mcheck = False
break
else:
mcheck = False
for btn in brk_btn:
if btn in str(ch + i):
pcheck = False
break
if mcheck:
min_cnt = min(min_cnt, i + len(str(ch - i)))
break
if pcheck:
min_cnt = min(min_cnt, i + len(str(ch+i)))
break
print(min_cnt)