description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
import sys input = sys.stdin.readline def gint(): return int(input()) def gint_arr(): return list(map(int, input().split())) def gfloat(): return float(input()) def gfloat_arr(): return list(map(float, input().split())) def pair_int(): return map(int, input().split()) INF = 1 << 31 MOD = "1000000007" dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] n = gint() res = n inp = [] opened = [False] * n for i in range(n): inp.append(gint_arr()) i = 0 while i < n: j = 0 while j < n: if i == j: j += 1 continue if inp[j][0] == inp[i][1] and not opened[j]: res -= 1 opened[j] += 1 j += 1 i += 1 print(res)
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) d = [0] * 1001 d1 = [0] * 1001 L = [list(map(int, input().split())) for i in range(n)] for x in L: if x[0] == x[1]: d[x[1]] += 0.5 else: d[x[1]] = 1 d1[x[0]] += 1 k = 0 for i in range(1, 1001): if d[i] == 0: k += d1[i] if d[i] == 0.5: k += 1 print(k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) openable = set() not_openable = {} for _ in range(n): a, b = map(int, input().split()) if b in not_openable: not_openable[b] = 0 if a not in openable: not_openable[a] = not_openable.get(a, 0) + 1 openable.add(b) print(sum(not_openable.values()))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
def solve(n, a, b): cnt = 0 for i in range(n): opener = a[i] for j in range(n): if i == j and opener == b[j]: continue elif i != j and opener != b[j]: continue elif opener == b[j]: cnt += 1 break print(n - cnt) n = int(input()) a = [] b = [] for i in range(n): l, r = map(int, input().split()) a.append(l) b.append(r) solve(n, a, b)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) bottles = {} pairs = [] for i in range(n): a, b = map(int, input().split(" ")) if a not in bottles: if a != b: bottles[a] = [1, 0] else: bottles[a] = [0, 1] elif a != b: bottles[a][0] += 1 else: bottles[a][1] += 1 pairs.append([a, b]) for b in pairs: if b[1] in bottles and bottles[b[1]][0] > 0: bottles[b[1]][0] = 0 if b[1] in bottles and bottles[b[1]][1] == 1: if b[0] != b[1]: bottles[b[1]][1] = 0 answer = 0 for b in bottles: answer += bottles[b][0] if bottles[b][1] == 1: answer += 1 print(answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) a = [0] * 1000 b = [0] * 1000 lst = [0] * 1001 for x in range(n): a[x], b[x] = map(int, input().split()) lst[b[x]] += 1 ans = 0 for x in range(n): lst[b[x]] -= 1 if lst[a[x]] == 0: ans += 1 lst[b[x]] += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) x = [] y = [] z = [] for i in range(n): a, b = map(int, input().split()) x.append(a) y.append(b) for i in range(n): if x[i] not in y: z.append(x[i]) elif x[i] in y and x[i] == y[i]: if y.count(x[i]) == 1: z.append(x[i]) print(len(z))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
l, l2, l3 = [], [], [] for i in range(int(input())): x, y = map(int, input().split()) l.append(x) l2.append(y) l3.append(1) for i in range(len(l)): for j in range(len(l2)): if l2[i] == l[j] and i != j: l3[j] = 0 print(sum(l3))
ASSIGN VAR VAR VAR LIST LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
def main(): n, aa, bb = int(input()), [], [] for _ in range(n): a, b = input().split() aa.append(a) bb.append(b) print( n - len( {i for i, a in enumerate(aa) for j, b in enumerate(bb) if i != j and a == b} ) ) main()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) e = 0 a = [] b = [[] for i in range(1001)] for i in range(n): s, t = map(int, input().split()) a.append([i, s]) b[t].append(i) for i in range(len(a)): c1 = 0 for j in range(len(b[a[i][1]])): if b[a[i][1]][j] != i: c1 = -1 if c1 != -1: e = e + 1 print(e)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) bottle = [] for i in range(n): bottle.append(list(map(int, input().split()))) count = 0 check = [] for i in range(n): check.append(False) for i in range(n): for j in range(n): if i == j: continue elif bottle[i][1] == bottle[j][0] and check[j] == False: count += 1 check[j] = True print(n - count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
c = 0 u = [] o = [] n = int(input()) for _ in range(n): a, b = map(int, input().split()) u.append(a) o.append(b) for i in range(len(o)): for j in range(len(u)): if o[i] == u[j] and i != j: c += 1 u[j] = 0 print(n - c)
ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) arr = [] brr = [] ans = 0 for i in range(n): a, b = map(int, input().split()) arr.append(a) brr.append(b) for i in range(n): flag = 0 for j in range(i): if brr[j] == arr[i]: flag = 1 break if flag != 1: for k in range(i + 1, n): if brr[k] == arr[i]: flag = 1 break if flag == 0: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
def main(): n = int(input()) t = n A = [] B = [] while t > 0: a, b = map(int, input().split()) A.append(a) B.append(b) t = t - 1 x = 0 for u in range(n): for v in range(n): if A[u] == B[v] and u != v: x = x + 1 break print(n - x) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
def main(): desc = set() brand = [0] * 1001 proc = [0] * 1001 tb = [False] * 1001 n = int(input()) total = n for i in range(n): a, b = map(int, input().split()) desc.add(a) brand[a] += 1 proc[b] += 1 tb[b] |= True if a != b else False for a in desc: if tb[a] or proc[a] > 1: total -= brand[a] elif proc[a]: total -= brand[a] - 1 print(total) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
def spliter(): d = input() a = d.split() r = [] for i in a: k = int(i) r.append(k) return r n = spliter() lst1 = [] lst2 = [] count = [] for i in range(n[0]): a = spliter() lst1.append(a[1]) lst2.append(a[0]) for i in range(n[0]): for j in range(n[0]): if i != j: if lst1[i] == lst2[j]: count.append(lst2[j]) lst2[j] = 0 print(len(lst2) - len(count))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
ll = lambda: list(map(int, input().split())) testcases = 1 for testcase in range(testcases): [n] = ll() d = [] opener = [0] * 1001 for i in range(n): x = ll() opener[x[1]] += 1 d.append(x) c = 0 for i in range(n): opener[d[i][1]] -= 1 if opener[d[i][0]] > 0: c += 1 opener[d[i][1]] += 1 print(n - c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) bottles, openers = [], [] for _ in range(n): a, b = map(int, input().split()) openers.append(b) bottles.append(a) opened = [False] * n for i in range(n): for j in range(n): if i != j and openers[i] == bottles[j] and not opened[j]: opened[j] = True count = 0 for i in range(n): if not opened[i]: count += 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
numberOfBottles = int(input()) a = [] d = [] bottles = [1] * numberOfBottles for x in range(numberOfBottles): x, y = map(int, input().split()) a.append(x) d.append(y) for y in range(len(a)): for b in range(len(a)): if a[b] == d[y] and y != b: bottles[b] = 0 print(sum(bottles))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) n = iinput() x = [] y = [] count = 0 for i in range(n): a, b = rinput() x.append(a) y.append(b) for i in range(n): flag = True for j in range(n): if i != j: if x[i] == y[j]: flag = False if flag == True: count += 1 print(count)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
a = int(input()) i = 0 d = 0 x = [] y = [] for i in range(0, a, 1): b, c = input().split(" ") b = int(b) c = int(c) x.append(b) y.append(c) i = 0 z = [] for i in range(0, a, 1): b = y[i] j = i m = 0 for m in range(0, j, 1): if x[m] == y[i]: z.append(m + 1) j += 1 m = j for m in range(j, a, 1): if x[m] == y[i]: z.append(m + 1) z = sorted(z) l = len(z) f = 1 for f in range(1, a + 1, 1): i = 0 e = 0 for i in range(0, l, 1): if z[i] == f: e = 1 break if e == 0: d += 1 print(d)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) key = [] value = [] for _ in range(n): a, b = input().split() key.append(a) value.append(b) count = 0 for i in range(n): a = key[i] if a in value: if key[i] == value[i] and value.count(value[i]) < 2: count += 1 else: count += 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
MOD = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) n = ii() l1, l2 = [], [] lvis = [1] * n for _ in range(n): a, b = f() l1.append(a) l2.append(b) for i in range(n): for j in range(n): if l2[i] == l1[j] and i != j: lvis[j] = 0 print(sum(lvis))
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) brand = [0] * n open = [0] * n for i in range(n): brand[i], open[i] = map(int, input().split()) opened = [False] * n res = n for i in range(n): for j in range(n): if i == j: continue if not opened[j] and brand[j] == open[i]: opened[j] = True res -= 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) brand = [] opener = [] for s in range(n): a, b = map(int, input().split()) brand.append(a) opener.append(b) for i in range(len(brand)): if n == 0: break for j in range(len(opener)): if n == 0: break if i != j: if brand[i] == opener[j]: n -= 1 break print(n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) a, b = [0] * n, [0] * n for i in range(0, n): a[i], b[i] = map(int, input().split()) t = [0] * n for i in range(n): t[i] = b[i] s = 0 for i in range(0, n): b[i] = 0 if a[i] in b: b[i] = t[i] continue else: s += 1 b[i] = t[i] print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
def chc(l, i, k): for j in range(len(l)): if k == l[j] and j != i: return 1 return 0 n = int(input()) b, o = [], [] c = 0 for i in range(n): l, r = map(int, input().split()) b.append(l) o.append(r) for i in range(n): if chc(o, i, b[i]): c += 1 print(n - c)
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) arr_a = [] arr_b = [] arr_c = [(0) for i in range(10001)] for i in range(n): a, b = map(int, input().split()) arr_a.append(a) arr_b.append(b) arr_c[b] += 1 count = 0 for i in range(n): arr_c[arr_b[i]] -= 1 if arr_c[arr_a[i]] == 0: count += 1 arr_c[arr_b[i]] += 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) unopenable = [] openable = [] count = n for i in range(n): bottle = [int(i) for i in input().split()] if bottle[0] in openable: count -= 1 unopenable.append(0) else: unopenable.append(bottle[0]) openable.append(bottle[1]) for i in range(n - 1): bottle = unopenable[i] if bottle != 0: if bottle in openable[i + 1 : n]: count -= 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) bottles = [0] * 1001 types = [0] * 1001 for i in range(n): a, b = map(int, input().split()) bottles[a] += 1 if a == b and types[a] == 0: types[a] = -1 else: types[b] = max(types[b] + 1, -types[b] + 1) print( n - sum( bottles[i] if types[i] > 0 else -types[i] * (bottles[i] - 1) for i in range(1001) ) )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) a = [] b = [] for x in range(0, n): l = list(map(int, input().split(" "))) a.append(l) b.append(l[1]) c = 0 for x, y in a: if x == y and b.count(x) == 1: c += 1 elif x in b: pass else: c += 1 print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
import sys sys.setrecursionlimit(10000) n = int(sys.stdin.readline()) arr = [0] * 1001 bottles = [] for i in range(n): a, b = [int(x) for x in input().strip().split()] bottles.append([a, b]) count = 0 for i in range(n): for j in range(n): if j != i and bottles[i][0] == bottles[j][1]: count += 1 bottles[i][0] = 0 print(n - count)
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) a = [] for i in range(n): b = list(map(int, input().split())) a.append(b) d = [] t = 0 for i in a: d.append(i[1]) t = 0 for i in a: if i[0] == i[1]: if d.count(i[0]) == 1: t += 1 elif i[0] not in d: t += 1 print(t)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
def bottles(lst1, lst2): flag, count = False, 0 for i in range(len(lst1)): for j in range(len(lst1)): if lst1[i] == lst2[j] and i != j: flag = True break if flag is False: count += 1 flag = False return count n = int(input()) a, b = list(), list() for z in range(n): pair = [int(y) for y in input().split()] a.append(pair[0]) b.append(pair[1]) print(bottles(a, b))
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
def bottle(n): arr = [] count = 0 for i in range(n): arr.append(list(map(int, input().split()))) for i in range(n): for j in range(n): if j != i: if arr[j][1] == arr[i][0]: break else: count += 1 print(count) bottle(int(input()))
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) a, b, p = [0] * n, [0] * n, {} for i in range(n): a[i], b[i] = input().split() p[b[i]] = a[i] != b[i] or b[i] in p print(sum(not a[i] in p or p[a[i]] == 0 and a[i] == b[i] for i in range(n)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) cnt = [0] * 1001 s = [0] * 1001 ina = [] inb = [] for i in range(n): a, b = map(int, input().split()) ina.append(a) inb.append(b) cnt[a - 1] += 1 if a != b: s[b - 1] = 1 ans = 0 for i in range(n): a, b = ina[i], inb[i] if cnt[a - 1] > 1 and a == b: s[b - 1] = 1 if cnt[a - 1] > 1 and a == b and inb.count(a) == 1: ans = -1 for i in range(1001): ans += cnt[i] * s[i] print(n - ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) la, lb = [], [] for _ in range(n): a, b = map(int, input().split()) la.append(a) lb.append(b) res = 0 for i in range(n): temp = la[i] if lb.count(temp) > 1: res += 1 elif lb.count(temp) == 1 and lb.index(temp) != i: res += 1 print(n - res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
l, q, r = [0] * 1001, 0, [] for i in [*open(0)][1:]: b, a = map(int, i.split()) l[a] += 1 r += [[a, b]] for i in r: if l[i[1]] == 0 or i[0] == i[1] and l[i[1]] == 1: q += 1 print(q)
ASSIGN VAR VAR VAR BIN_OP LIST NUMBER NUMBER NUMBER LIST FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR LIST LIST VAR VAR FOR VAR VAR IF VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
def main(): mode = "filee" if mode == "file": f = open("test.txt", "r") get = lambda: [ int(x) for x in (f.readline() if mode == "file" else input()).split() ] [n] = get() found = [] opener = set() count = 0 other = [] for i in range(n): [a, b] = get() if a == b: found.append(a) other.append(b) continue found.append(a) opener.add(b) c = set(found) final = c - opener for i in final: count += found.count(i) for i in other: count -= found.count(i) - 1 print(max(count, 0)) if mode == "file": f.close() main()
FUNC_DEF ASSIGN VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
t = int(input()) p = [] q = [] r = 0 for i in range(t): a, b = [int(i) for i in input().split()] p.append(a) q.append(b) for i in range(t): if p[i] not in q: r = r + 1 elif q.count(p[i]) == 1 and q.index(p[i]) == i: r = r + 1 print(r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) a = [None] * n for i in range(n): a[i] = tuple(map(int, input().split())) ans = 0 for i, x in enumerate(a): ok = 0 for j, y in enumerate(a): if i == j: continue if y[1] == x[0]: ok = 1 ans += ok ^ 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) l1 = list() l2 = list() l = 0 for i in range(n): a, b = map(int, input().split()) l1.append(a) l2.append(b) for i in range(n): if l1[i] in l2[:i] or l1[i] in l2[i + 1 :]: l = l + 1 print(n - l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) nn = n nnn = n b = [] o = [] c = 0 while n > 0: n -= 1 bt, ot = map(int, input().split()) b.append(bt) o.append(ot) for i in range(0, nnn): if b[i] == o[i] and o.count(o[i]) == 1: nn += 1 o = set(o) for i in o: temp = b.count(i) nn -= temp print(nn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
a = int(input()) bad = [] for i in range(a): x, y = map(int, input().split(" ")) bad.append([x, y, 0]) for i in range(a): for j in range(a): if i != j: if bad[j][1] == bad[i][0]: bad[i][2] = 1 ct = 0 for i in bad: if i[2] == 1: ct += 1 print(a - ct)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) arr = [] rra = [] for i in range(n): z = list(map(int, input().split())) rra.append(z[0]) arr.append(z[1]) count = 0 for i in range(n): temp = arr[i] indexx = i arr.remove(temp) if rra[i] in arr: arr.insert(indexx, temp) else: count += 1 arr.insert(indexx, temp) print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand a_{i}, besides, you can use it to open other bottles of brand b_{i}. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. -----Input----- The first line contains integer n (1 ≀ n ≀ 100) β€” the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ 1000) β€” the description of the i-th bottle. -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 4 1 1 2 2 3 3 4 4 Output 4 Input 4 1 2 2 3 3 4 4 1 Output 0
n = int(input()) size = n + 1 bottle_num = [0] * size left_arr = [] right_arr = [] for i in range(n): ab_list = list(map(int, input().split())) if len(left_arr) == 0: left_arr.append(0) if len(right_arr) == 0: right_arr.append(0) left_arr.append(ab_list[0]) right_arr.append(ab_list[1]) for j in range(1, n + 1): for k in range(1, n + 1): if j != k and left_arr[j] == right_arr[k]: bottle_num[j] = 1 total = 0 for i in range(1, n + 1): total += bottle_num[i] print(n - total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
def power(a, n, mod): res = 1 a = a % mod if a == 0: return 0 while n > 0: if n & 1 == 1: res = res * a % mod n = n >> 1 a = a * a % mod return res MOD = int(1000000000.0 + 7) class Solution: def power(self, N, R): return power(N, R, MOD)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
import sys class Solution: def __init__(self): sys.setrecursionlimit(20000) M = 10**9 + 7 def power(self, N, R): if R == 0: return 1 temp = self.power(N, R // 2) temp = temp * temp % 1000000007 if R % 2 == 0: return temp % 1000000007 else: return temp * N % 1000000007
IMPORT CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): a = N res = 0 while N > 0: d = N % 10 res = res * 10 + d N = N // 10 return pow(a, res, 10**9 + 7)
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): def cal_power(num, power, value=1): temp_num = num * num temp_power = power temp_val = value if power == 0: return value if power == 1: return value * num if power % 2 == 0: temp_power = temp_power // 2 else: temp_power = (temp_power - 1) // 2 temp_val = num * temp_val return cal_power(temp_num % 1000000007, temp_power, temp_val % 1000000007) return cal_power(N, R) % 1000000007
CLASS_DEF FUNC_DEF FUNC_DEF NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR NUMBER
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): if R == 0: return 1 elif R % 2 == 0: return self.power(N, R // 2) ** 2 % (10**9 + 7) else: return N * self.power(N, R // 2) ** 2 % (10**9 + 7)
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): if R // 10 == 0: return N**R % (10**9 + 7) else: Rdivide10 = R // 10 digitR = R % 10 return ( N**digitR % (10**9 + 7) * self.power(N**10 % (10**9 + 7), Rdivide10) % (10**9 + 7) )
CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def modfun(self, N, R): if N == 0: return 0 if R == 0: return 1 y = 0 if R % 2 == 0: y = self.modfun(N, R / 2) y = y * y % 1000000007 else: y = N % 1000000007 y = y * self.modfun(N, R - 1) % 1000000007 % 1000000007 return (y + 1000000007) % 1000000007 def power(self, N, R): return self.modfun(N, R)
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): MOD = pow(10, 9) + 7 def power_recursive(R): if R == 1: return N temp = power_recursive(R // 2) if R % 2 == 0: return temp * temp % MOD else: return N * temp * temp % MOD return power_recursive(R) % MOD
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): number = N reverse = 0 mod = 1000000007 while N != 0: digit = N % 10 reverse = reverse * 10 + digit N //= 10 def p(n, reverse): if reverse == 0: return 1 elif reverse % 2 == 0: subproblem = p(number, reverse // 2) return subproblem * subproblem % mod else: subproblem = p(number, reverse - 1) return number * subproblem % mod return p(number, reverse)
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): mod = 10**9 + 7 res = 1 while R > 0: if R % 2 == 1: res = res * N % mod N = N * N % mod R //= 2 return res
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): if R == 0: return 1 if R % 2 == 0: x = self.power(N, R // 2) ** 2 else: x = N * self.power(N, (R - 1) // 2) ** 2 return x % 1000000007
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER RETURN BIN_OP VAR NUMBER
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): def funcall(N, R): if R == 1: return N if R == 2: return N * N % 1000000007 if R % 2 == 1: ans = N * funcall(N, R - 1) % 1000000007 return ans else: ans = funcall(N, R // 2) ans = ans * ans % 1000000007 return ans return funcall(N, R)
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): mod = 1000000007 res = 1 while R > 0: if R % 2: res = res * N % mod N = N * N % mod R = R // 2 return res
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): def fun(N, R): if R == 1: return N temp = fun(N, R // 2) % 1000000007 temp = temp * temp % 1000000007 if R % 2 == 0: return temp % 1000000007 else: return N * temp % 1000000007 return fun(N, R)
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: memo = [] def power(self, N, R): if R == 0: return 1 if R % 2 == 0: ans = self.power(N, R / 2) return ans % 1000000007 * ans % 1000000007 % 1000000007 else: ans = self.power(N, (R - 1) / 2) return ans % 1000000007 * ans % 1000000007 * N % 1000000007 % 1000000007
CLASS_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): return self.pow(N, R, 1000000007) def pow(self, N, R, M): if R == 0: return 1 elif R % 2 == 0: a = self.pow(N, R // 2, M) return a % M * (a % M) % M else: a = self.pow(N, R - 1, M) return a % M * (N % M) % M
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): if R == 0: return 1 solve = self.power(N, R // 2) sq = solve * solve if R % 2 == 0: return sq % (10**9 + 7) return N * sq % (10**9 + 7)
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): mod = 1000000007 if N == 0: return 0 if R == 0: return 1 def rec_power(N, R): if R == 0: return 1 elif R == 1: return N elif R % 2 == 0: ans = rec_power(N, R // 2) return ans * ans % mod else: ans = rec_power(N, (R - 1) // 2) return ans * ans * N % mod return rec_power(N, R)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): nn = R ans = 1 if R < 0: R = -1 * R while R > 0: if R % 2 == 0: N = N * N N = N % 1000000007 R = R / 2 else: ans = ans * N ans %= 1000000007 R = R - 1 if nn < 0: return 1 / ans return ans
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN BIN_OP NUMBER VAR RETURN VAR
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): r = R ans = 1 while r: if r % 2: ans = ans * N % (10**9 + 7) r -= 1 else: N = N * N % (10**9 + 7) r //= 2 return ans % (10**9 + 7)
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR NUMBER RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
Given a number and its reverse. Find that number raised to the power of its own reverse. Note: As answers can be very large, print the result modulo 10^{9} + 7. Example 1: Input: N = 2 Output: 4 Explanation: The reverse of 2 is 2 and after raising power of 2 by 2 we get 4 which gives remainder as 4 when divided by 1000000007. Example 2: Input: N = 12 Output: 864354781 Explanation: The reverse of 12 is 21and 12^{21} when divided by 1000000007 gives remainder as 864354781. Your Task: You don't need to read input or print anything. You just need to complete the function pow() that takes two parameters N and R denoting the input number and its reverse and returns power of (N to R)mod(10^{9} + 7). Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(LogN). Constraints: 1 <= N <= 10^{9}
class Solution: def power(self, N, R): def pow_x(x, n, mod): if x == 0: return 0 elif n == 0: return 1 res = pow_x(x * x % mod, n // 2, mod) return x * res % mod if n % 2 else res mod = int(1000000000.0 + 7) res = pow_x(N, R, mod) return res % mod
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP VAR VAR
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
import sys sp1 = ["1", "4", "7"] sp2 = ["1", "2", "3"] sp3 = ["3", "6", "9"] sp4 = ["7", "0", "9"] n = int(input()) s = input() for i in sp2: if i in s: if "0" in s: print("YES") sys.exit(0) else: for j in sp1: if j in s: for k in sp3: if k in s: for t in sp4: if t in s: print("YES") sys.exit(0) else: print("NO")
IMPORT ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR VAR FOR VAR VAR IF VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
m = { (1): (1, 1), (2): (1, 2), (3): (1, 3), (4): (2, 1), (5): (2, 2), (6): (2, 3), (7): (3, 1), (8): (3, 2), (9): (3, 3), (0): (4, 2), } n = int(input()) k = input() p = [] for i in k: p.append(m[int(i)]) def valid(i, j): if i >= 1 and i <= 3 and j >= 1 and j <= 3: return True return i == 4 and j == 2 dx = [-1, 1, 0, 0, -1, -1, 1, 1] dy = [0, 0, 1, -1, -1, 1, -1, 1] for i in range(len(dx)): fl = True for z in range(len(p)): x = p[z][0] y = p[z][1] if not valid(x + dx[i], y + dy[i]): fl = False break if fl: print("NO") exit(0) print("YES")
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
input() def p(x): x = int(x) - 1 if x == -1: return 3, 1 return x // 3, x % 3 s = list(map(p, input())) f = False for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]: f = f or not [ (1) for i, j in s if i + di < 0 or i + di >= 4 or j + dj < 0 or j + dj >= 3 or i + di == 3 and j + dj != 1 ] print("NO" if f else "YES")
EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER NUMBER RETURN BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
def Left(a): if a != 1 and a != 4 and a != 7 and a != 0: return True return False def Right(a): if a != 3 and a != 6 and a != 9 and a != 0: return True return False def Up(a): if a != 1 and a != 2 and a != 3: return True return False def Down(a): if a != 7 and a != 9 and a != 0: return True return False n = int(input()) str1 = input() u = 0 d = 0 l = 0 r = 0 for iss in str1: i = int(iss) if Up(i): u += 1 if Down(i): d += 1 if Left(i): l += 1 if Right(i): r += 1 if u == len(str1) or d == len(str1) or l == len(str1) or r == len(str1): print("NO") else: print("YES")
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
a = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [-1, 0, -1]] d = [(3, 1), (0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)] n = int(input()) b = list(map(int, list(input()))) c = [] for i in range(n - 1): c.append((d[b[i + 1]][0] - d[b[i]][0], d[b[i + 1]][1] - d[b[i]][1])) for i in range(10): x, y = d[i][0], d[i][1] fl = 1 for j in c: x1, y1 = x + j[0], y + j[1] if (x1, y1) not in d: fl = 0 x, y = x1, y1 if fl and i != b[0]: print("NO") break else: print("YES")
ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
def is_valid(p): for i in range(len(pos)): if pos[i] == p: return True return False n = int(input()) s = list(map(int, input())) if n <= 1: print("NO") exit(0) pos = [] pos.append([3, 1]) pos.append([0, 0]) pos.append([0, 1]) pos.append([0, 2]) pos.append([1, 0]) pos.append([1, 1]) pos.append([1, 2]) pos.append([2, 0]) pos.append([2, 1]) pos.append([2, 2]) cnt = 0 for i in range(10): p = pos[i] flag = True for j in range(1, n): mov = [0] * 2 mov[0] = pos[s[j]][0] - pos[s[j - 1]][0] mov[1] = pos[s[j]][1] - pos[s[j - 1]][1] p2 = [0] * 2 p2[0] = p[0] + mov[0] p2[1] = p[1] + mov[1] if is_valid(p2) == False: flag = False break p = p2 if flag == True: cnt += 1 if cnt > 1: print("NO") else: print("YES")
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
def is_pos_correct(x, y): return 0 <= x <= 2 and 0 <= y <= 2 or x == 1 and y == 3 def is_v_correct(v, x, y): if not is_pos_correct(x, y): return False for vx, vy in v: x += vx y += vy if not is_pos_correct(x, y): return False return True def move_v(v, dx, dy): return [(x + dx, y + dy) for x, y in v] def get_row(x): return 3 if x == 0 else (x - 1) // 3 def get_col(x): return 1 if x == 0 else (x - 1) % 3 def get_pos(x): return get_col(x), get_row(x) def get_shift(x, y): x, y = int(x), int(y) return get_col(y) - get_col(x), get_row(y) - get_row(x) def create_v(s): return [get_shift(x, y) for x, y in zip(s, s[1:])] def main(): input() n = [int(x) for x in input()] base_v = create_v(n) for x, y in [ (xx, yy) for xx in (-1, 0, 1) for yy in (-1, 0, 1) if not (xx == 0 and yy == 0) ]: new_pos = move_v([get_pos(n[0])], x, y)[0] if is_v_correct(base_v, new_pos[0], new_pos[1]): print("NO") return print("YES") main()
FUNC_DEF RETURN NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER FOR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF RETURN BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_DEF RETURN VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
import sys n = int(input()) s = list(map(lambda x: int(x) - int("0"), input())) d = [(1, 3)] + [(i, j) for j in range(3) for i in range(3)] for u in range(10): if u == s[0]: continue x, y = d[u] for i in range(1, n): dx, dy = d[s[i]][0] - d[s[i - 1]][0], d[s[i]][1] - d[s[i - 1]][1] x += dx y += dy if (x, y) not in d: break else: print(u, file=sys.stderr) print("NO") sys.exit(0) print("YES")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
n = int(input()) seq = input() d = [False] * 10 for i in seq: d[int(i)] = True def main(): if not (d[7] or d[9] or d[0]): print("NO") return elif d[0] and (d[1] or d[2] or d[3]): print("YES") return elif ((d[1] or d[4] or d[7]) and (d[3] or d[6] or d[9])) and ( (d[1] or d[2] or d[3]) and (d[7] or d[8] or d[9]) ): print("YES") return else: print("NO") return main()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
a = input() s = str(input()) r = 0 u = 0 d = 0 z = 0 l = 0 f = 0 for i in range(len(s)): if s[i] == "0": z = 1 if s[i] == "1" or s[i] == "2" or s[i] == "3": u = 1 if s[i] == "3" or s[i] == "6" or s[i] == "9": r = 1 if s[i] == "7" or s[i] == "8" or s[i] == "9": d = 1 if s[i] == "1" or s[i] == "4" or s[i] == "7": l = 1 if s[i] == "7" or s[i] == "9": f = 1 if (u == 1 and r == 1 and d == 1 and l == 1) and f == 1 or z == 1 and u == 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
left = 0 right = 1 up = 2 down = 3 buttons = [] buttons.append({left: False, right: False, up: True, down: False}) buttons.append({left: False, right: True, up: False, down: True}) buttons.append({left: True, right: True, up: False, down: True}) buttons.append({left: True, right: False, up: False, down: True}) buttons.append({left: False, right: True, up: True, down: True}) buttons.append({left: True, right: True, up: True, down: True}) buttons.append({left: True, right: False, up: True, down: True}) buttons.append({left: False, right: True, up: True, down: False}) buttons.append({left: True, right: True, up: True, down: True}) buttons.append({left: True, right: False, up: True, down: False}) n = eval(input()) stroke = input() can = [True, True, True, True] for button in stroke: button = int(button) if buttons[button][left] == False: can[left] = False if buttons[button][right] == False: can[right] = False if buttons[button][up] == False: can[up] = False if buttons[button][down] == False: can[down] = False canMove = False for i in range(4): if can[i] == True: canMove = True if canMove == True: print("NO") else: print("YES")
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR DICT VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR DICT VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR DICT VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR DICT VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR DICT VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR DICT VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR DICT VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR DICT VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR DICT VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR DICT VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
n = int(input()) inp = [int(i) for i in input()] a = [[1, 2, 3], [1, 4, 7, 0], [7, 0, 9], [3, 6, 9, 0]] res = "YES" for i in a: for j in i: if j in inp: break else: res = "NO" print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR STRING FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
n = int(input()) s = input().rstrip() def canMove(moves, dx, dy): for x, y in moves: tx = x + dx ty = y + dy if not (0 <= tx < 3 and 0 <= ty < 3): if not (tx == 3 and ty == 1): return False return True l = [[3, 1], [0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]] move = [] for x in s: move.append(l[int(x)]) cnt = 0 for i in range(10): for j in range(10): dx = i - 5 dy = j - 5 if canMove(move, dx, dy): cnt += 1 if cnt == 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF NUMBER VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
n = int(input()) s = input() s = list(s) l1 = 0 l3 = 0 l4 = 0 l11 = 0 l22 = 0 l33 = 0 for j in range(n): if s[j] == "1" or s[j] == "2" or s[j] == "3": l1 += 1 elif s[j] == "7" or s[j] == "8" or s[j] == "9": l3 += 1 elif s[j] == "0": l4 += 1 if s[j] == "1" or s[j] == "4" or s[j] == "7": l11 += 1 elif s[j] == "2" or s[j] == "5" or s[j] == "8": l22 += 1 elif s[j] == "3" or s[j] == "6" or s[j] == "9": l33 += 1 if l1 != 0 and l4 != 0: print("YES") elif l1 != 0 and l3 != 0: if l11 != 0 and l33 != 0: if "7" in s or "9" in s: print("YES") else: print("NO") else: print("NO") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
n = int(input()) s = input() h, v = True, True cnt = [s.count(chr(i + ord("0"))) for i in range(10)] if (cnt[0] or cnt[7] or cnt[9]) and (cnt[1] or cnt[2] or cnt[3]): v = False if cnt[0] and (cnt[1] or cnt[2] or cnt[3]): h = False if (cnt[1] or cnt[4] or cnt[7]) and (cnt[3] or cnt[6] or cnt[9]): h = False print("NO" if v or h else "YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
def main(): input() seq = input() LEFT = { "0": False, "1": False, "2": True, "3": True, "4": False, "5": True, "6": True, "7": False, "8": True, "9": True, } RIGHT = { "0": False, "1": True, "2": True, "3": False, "4": True, "5": True, "6": False, "7": True, "8": True, "9": False, } UP = { "0": True, "1": False, "2": False, "3": False, "4": True, "5": True, "6": True, "7": True, "8": True, "9": True, } DOWN = { "0": False, "1": True, "2": True, "3": True, "4": True, "5": True, "6": True, "7": False, "8": True, "9": False, } print( "NO" if any(all(can[n] for n in seq) for can in (LEFT, RIGHT, UP, DOWN)) else "YES" ) def __starting_point(): main() __starting_point()
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR STRING STRING FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
def get(a): if a == "0": return [3, 1] else: a = int(a) return [(a - 1) // 3, (a - 1) % 3] def check(a): if -1 < a[0] < 3 and -1 < a[1] < 3 or a == [3, 1]: return True return False n = int(input()) s = input() Q = [] for i in range(3): for j in range(3): Q.append([i, j]) Q.append([3, 1]) prev = get(s[0]) for i in range(1, len(s)): now = get(s[i]) fir = now[0] - prev[0] sec = now[1] - prev[1] q = [] for pair in Q: new = [pair[0] + fir, pair[1] + sec] if check(new): q.append(new) prev = now Q = q if len(Q) > 1: print("NO") else: print("YES")
FUNC_DEF IF VAR STRING RETURN LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN LIST BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF IF NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER VAR LIST NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
input() s = set(list(input())) t = 1 for i in [ {"1", "9"}, {"7", "3"}, {"0", "2"}, {"0", "1"}, {"0", "3"}, {"9", "3", "4"}, {"1", "7", "6"}, {"9", "4", "2"}, {"7", "2", "6"}, {"7", "2", "9"}, ]: if s & i == i: t = 0 print("YNEOS"[t::2])
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
KEYS = { (1): (0, 0), (2): (1, 0), (3): (2, 0), (4): (0, 1), (5): (1, 1), (6): (2, 1), (7): (0, 2), (8): (1, 2), (9): (2, 2), (0): (1, 3), } BOARD = set(KEYS.values()) n = int(input()) number = list(map(int, list(input()))) def add_offset(cell, offset): return cell[0] + offset[0], cell[1] + offset[1] uniq = True for posible_starts in BOARD: if KEYS[number[0]] != posible_starts: all_fit = True off = ( posible_starts[0] - KEYS[number[0]][0], posible_starts[1] - KEYS[number[0]][1], ) for num_part in number: if add_offset(KEYS[num_part], off) not in BOARD: all_fit = False break if all_fit: uniq = False if uniq: print("YES") else: print("NO")
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
def main(string, size): if size == 1: return False vis = [False] * 10 for i in string: vis[int(i)] = True func = lambda x: not vis[x] if all(map(func, (1, 2, 3))): return False if vis[0]: return True if all(map(func, (1, 4, 7))): return False if all(map(func, (3, 6, 9))): return False if all(map(func, (7, 0, 9))): return False return True n = int(input()) string = input() print("YES" if main(string, n) else "NO")
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
input() a = list(map(int, str(input()))) d = { (1): (0, 0), (2): (1, 0), (3): (2, 0), (4): (0, 1), (5): (1, 1), (6): (2, 1), (7): (0, 2), (8): (1, 2), (9): (2, 2), (0): (1, 3), } r = list(map(lambda x: (d[x][0] + 1, d[x][1]), a)) l = list(map(lambda x: (d[x][0] - 1, d[x][1]), a)) t = list(map(lambda x: (d[x][0], d[x][1] + 1), a)) b = list(map(lambda x: (d[x][0], d[x][1] - 1), a)) rt = list(map(lambda x: (d[x][0] + 1, d[x][1] + 1), a)) rb = list(map(lambda x: (d[x][0] + 1, d[x][1] - 1), a)) lt = list(map(lambda x: (d[x][0] - 1, d[x][1] + 1), a)) lb = list(map(lambda x: (d[x][0] - 1, d[x][1] - 1), a)) if ( all([(x in d.values()) for x in r]) or all([(x in d.values()) for x in l]) or all([(x in d.values()) for x in t]) or all([(x in d.values()) for x in b]) or all([(x in d.values()) for x in rt]) or all([(x in d.values()) for x in rb]) or all([(x in d.values()) for x in lt]) or all([(x in d.values()) for x in lb]) ): print("NO") else: print("YES")
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
def works(numbers): if numbers[1] or numbers[2] or numbers[3]: if numbers[7] or numbers[0] or numbers[9]: if numbers[1] or numbers[4] or numbers[7] or numbers[0]: if numbers[3] or numbers[6] or numbers[9] or numbers[0]: return True else: return False else: return False else: return False else: return False n = int(input()) line = input() numbers = {} for i in range(10): numbers[i] = False for ch in line: numbers[int(ch)] = True if works(numbers): print("YES") else: print("NO")
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
n = int(input()) c = [0] * 10 for i in input(): c[int(i)] = 1 f1 = sum((c[1], c[2], c[3])) f2 = sum((c[1], c[4], c[7], c[0])) f3 = sum((c[3], c[6], c[9], c[0])) f4 = sum((c[7], c[9], c[0])) print("NO" if 0 in (f1, f2, f3, f4) else "YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR VAR VAR STRING STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
L = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [-1, 0, -1]] L1 = [] def wq(tmp, to): fr = [] fr1 = [] for i in range(4): if tmp in L[i]: fr = [i, L[i].index(tmp)] break for i in range(4): if to in L[i]: fr1 = [i, L[i].index(to)] break L1.append([fr[0] - fr1[0], fr[1] - fr1[1]]) def chek(x): if x[0] < 0 or x[1] < 0 or x[0] > 3 or x[1] > 2: return False elif L[x[0]][x[1]] == -1: return False for y in L1: x[0] -= y[0] x[1] -= y[1] if x[0] < 0 or x[1] < 0 or x[0] > 3 or x[1] > 2: return False elif L[x[0]][x[1]] == -1: return False return True n = int(input()) s = input() for i in range(1, n): wq(int(s[i - 1]), int(s[i])) d = [] for i in range(4): if int(s[0]) in L[i]: d = [i, L[i].index(int(s[0]))] break for i in range(-1, 2): for j in range(-1, 2): if chek([d[0] + i, d[1] + j]): if i != 0 or j != 0: print("NO") exit() print("YES")
ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER RETURN NUMBER FOR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
n = input() set_of_keys = input() def up(x): return True if x > 3 or x == 0 else False def down(x): return True if x not in [7, 9, 0] else False def left(x): return True if x not in [1, 4, 7, 0] else False def right(x): return True if x not in [3, 6, 9, 0] else False f = f2 = f3 = f4 = False for e in set_of_keys: if not up(int(e)): f = True break for e in set_of_keys: if not down(int(e)): f2 = True break for e in set_of_keys: if not left(int(e)): f3 = True break for e in set_of_keys: if not right(int(e)): f4 = True break if f and f2 and f3 and f4: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER VAR NUMBER NUMBER NUMBER FUNC_DEF RETURN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
def main(): input() l = list(map(int, input())) for s in ( {0, 4, 5, 6, 7, 8, 9}, {1, 2, 4, 5, 7, 8}, {1, 2, 3, 4, 5, 6, 8}, {2, 3, 5, 6, 8, 9}, ): if all(x in s for x in l): print("NO") return print("YES") main()
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FOR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
left = { (1): None, (2): 1, (3): 2, (4): None, (5): 4, (6): 5, (7): None, (8): 7, (9): 8, (0): None, } right = { (1): 2, (2): 3, (3): None, (4): 5, (5): 6, (6): None, (7): 8, (8): 9, (9): None, (0): None, } up = { (1): None, (2): None, (3): None, (4): 1, (5): 2, (6): 3, (7): 4, (8): 5, (9): 6, (0): 8, } down = { (1): 4, (2): 5, (3): 6, (4): 7, (5): 8, (6): 9, (7): None, (8): 0, (9): None, (0): None, } def func(comb, d): for element in comb: if d[int(element)] is None: return False return True n = int(input()) comb = str(input()) if ( func(comb, left) == True or func(comb, right) == True or func(comb, up) == True or func(comb, down) == True ): print("NO") else: print("YES")
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NONE NUMBER NUMBER NONE NUMBER NUMBER NONE NUMBER NUMBER NONE ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NONE NUMBER NUMBER NONE NUMBER NUMBER NONE NONE ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NONE NONE NONE NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NONE NUMBER NONE NONE FUNC_DEF FOR VAR VAR IF VAR FUNC_CALL VAR VAR NONE RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
n = input() s = set(map(int, input())) f = lambda x: x & s != set() print( "NO" if sum([f({1, 4, 7, 0}), f({1, 2, 3}), f({3, 6, 9, 0}), f({7, 0, 9})]) < 4 else "YES" )
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER STRING STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
input() s = input() h1 = "1" in s or "4" in s or "7" in s h2 = "3" in s or "6" in s or "9" in s v1 = "1" in s or "2" in s or "3" in s v2 = "7" in s or "0" in s or "9" in s nl = "0" in s print("YES" if h1 and h2 and v1 and v2 or v1 and nl else "NO")
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR STRING VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR STRING STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
import sys n = int(sys.stdin.readline()) digits = [int(x) for x in sys.stdin.readline().strip()] def can_go_left(digits): return all(x not in digits for x in [0, 1, 4, 7]) def can_go_right(digits): return all(x not in digits for x in [0, 3, 6, 9]) def can_go_up(digits): return all(x not in digits for x in [1, 2, 3]) def can_go_down(digits): return all(x not in digits for x in [0, 7, 9]) if ( can_go_left(digits) or can_go_right(digits) or can_go_up(digits) or can_go_down(digits) ): print("NO") else: print("YES")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
class Move: def __init__(self, dx, dy): self.dx = dx self.dy = dy x = [1, 0, 1, 2, 0, 1, 2, 0, 1, 2] y = [3, 0, 0, 0, 1, 1, 1, 2, 2, 2] length = int(input()) inStr = input() numlist = list(inStr) currentX = 1 currentY = 1 moveList = [] for num in numlist: iNum = int(num) dx = x[iNum] - currentX currentX = x[iNum] dy = y[iNum] - currentY currentY = y[iNum] moveList.append(Move(dx, dy)) bExistOther = False for x in range(3): if bExistOther == True: break for y in range(4): if bExistOther == True: break if x == 1 and y == 1: continue if y == 3: if x == 0 or x == 2: continue currentX = x currentY = y bExistOther = True for move in moveList: currentX += move.dx currentY += move.dy if currentX < 0 or 2 < currentX: bExistOther = False break elif currentY < 0 or 3 < currentY: bExistOther = False break elif currentY == 3 and (currentX == 0 or currentX == 2): bExistOther = False break if False == bExistOther: print("YES") else: print("NO")
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR IF VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≀ n ≀ 9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above.
dirs = { "up": [4, 5, 6, 7, 8, 9, 0], "down": [1, 2, 3, 4, 5, 6, 8], "left": [2, 3, 5, 6, 8, 9], "right": [1, 2, 4, 5, 7, 8], } input() num = input() ds = [int(x) for x in num] dirsleft = {"up", "down", "left", "right"} for d in ds: for k, v in dirs.items(): if d not in v and k in dirsleft: dirsleft.remove(k) print("YES" if not dirsleft else "NO")
ASSIGN VAR DICT STRING STRING STRING STRING LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING STRING STRING STRING FOR VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING STRING