description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
k = input().split()
ans = 0
for i in range(0, len(k)):
if k[i] == "0":
ans += 1
elif i != 0:
if k[i] == "3" and k[i - 1] == "2":
k[i] = "1"
elif k[i] == "3" and k[i - 1] == "1":
k[i] = "2"
elif k[i] == "2" and k[i - 1] == "2":
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | from sys import stdin
REST = 0
ITC = 1
GYM = 2
def solve(n, arr):
days = [([0] * 3) for i in range(n + 1)]
for i in range(1, n + 1):
days[i][0] = max(days[i - 1])
if arr[i - 1] in [1, 3]:
days[i][ITC] = max(days[i - 1][REST] + 1, days[i - 1][GYM] + 1)
if arr[i - 1] in [2, ... | ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BI... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = list(map(int, input().split()))
mem = [[(0) for x in range(3)] for x in range(len(a))]
first = a[0]
if first == 1:
mem[0] = [0, 1, 0]
elif first == 2:
mem[0] = [0, 0, 1]
elif first == 3:
mem[0] = [0, 1, 1]
for i, x in enumerate(a[1:], 1):
mem[i][0] = max(mem[i - 1])
if x == 1 or... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER NUMB... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
alist = list(map(int, input().split()))
dp = [[(101) for _ in range(3)] for _ in range(n + 1)]
for i in range(3):
dp[0][i] = 0
for i in range(1, n + 1):
dp[i][0] = min([dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]]) + 1
if alist[i - 1] == 1:
dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP F... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | def vacations(n, a):
s = None
r = 0
for i in range(n):
if a[i] == 0:
r += 1
s = 0
elif a[i] == 1:
if s == 1:
r += 1
s = 0
continue
else:
s = 1
elif a[i] == 2:
i... | FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = list(map(int, input().split()))
b = [[0, 0, 0]]
for i in range(n):
max_0 = max(b[-1])
max_1 = max(b[-1][0], b[-1][2]) + (a[i] % 2 > 0)
max_2 = max(b[-1][0], b[-1][1]) + (a[i] // 2 > 0)
b.append([max_0, max_1, max_2])
print(n - max(b[-1])) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BI... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
ls = list(map(int, input().split()))
ans = 0
prev = 0
for x in ls:
if x == prev or not x:
prev = 0
ans += 1
elif x < 3:
prev = x
elif prev:
prev = 3 - prev
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = list(map(int, input().split()))
INF = 10**9
def get_t(n, t):
return n & t
res = [[0, 0, 0] for _ in range(n)]
res[-1] = [1, 0 if get_t(a[-1], 1) else 1, 0 if get_t(a[-1], 2) else 1]
for i in range(n - 2, -1, -1):
res[i] = [
1 + min(res[i + 1]),
min(res[i + 1][0], res[i +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF RETURN BIN_OP VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER LIST NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR VA... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
s = list(map(int, input().split()))
r = [[0, 0, 0] for i in range(n)]
if s[0] == 0:
r[0] = [1, 1, 1]
if s[0] == 1:
r[0] = [1, 0, 1]
if s[0] == 2:
r[0] = [1, 1, 0]
if s[0] == 3:
r[0] = [1, 0, 0]
for i in range(1, n):
if s[i] == 0:
r[i] = [(min(r[i - 1]) + 1) for j in range(3)... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSI... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | def vacations(n, d, a):
prev = 3
res = 0
for i in a:
if i == prev and prev != 3:
i = 0
elif i == 3 and prev != 3:
i -= prev
if i == 0:
res += 1
prev = i
return res
n = input()
d = input()
a = list(map(int, d.split(" ")))
print(vacatio... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_C... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
days = list(map(int, input().split()))
arr = []
for i in days:
if i == 0:
arr.append("rest")
elif i == 1:
arr.append("contest")
elif i == 2:
arr.append("gym")
else:
arr.append("don't know")
count = 0
for i in range(n):
if i > 0:
if arr[i] == a... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = list(map(int, input().split()))
b = [([0] * 2) for i in range(n + 1)]
b
for i in range(n):
if a[i] == 0:
b[i + 1][0] = min(b[i][0], b[i][1]) + 1
b[i + 1][1] = min(b[i][0], b[i][1]) + 1
if a[i] == 1:
b[i + 1][0] = b[i][1]
b[i + 1][1] = min(b[i][0], b[i][1]) + ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER N... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
lst = list(map(int, input().split()))
ans = 0
cur = 0
last = 0
i = 0
while i < n:
if lst[i] == 0:
ans += 1
i += 1
last = 0
continue
if last == 0:
if lst[i] == 3:
j = i
while j < n and lst[j] == 3:
j += 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR N... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
arr = [int(i) for i in input().split()]
dp = [0] * n
dp[0] = arr[0]
for i in range(n):
if arr[i] == 1 and dp[i - 1] != 1:
dp[i] = 1
elif arr[i] == 2 and dp[i - 1] != 2:
dp[i] = 2
elif arr[i] == 3:
if dp[i - 1] == 1:
dp[i] = 2
elif dp[i - 1] == 2:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMB... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = list(map(int, input().split()))
dp = [-1] * n
act = [0] * n
if a[0] == 1:
act[0] = 1
dp[0] = 0
elif a[0] == 2:
act[0] = 2
dp[0] = 0
elif a[0] == 0:
act[0] = 0
dp[0] = 1
elif a[0] == 3:
if len(a) == 1:
act[0] = 1
elif a[1] == 1:
act[0] = 2
elif a[1... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF V... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = input().split()
rests = 0
odd = True
if a[0] == "0":
rests += 1
for i in range(1, n):
if a[i] == "0":
odd = True
rests += 1
elif a[i] == "3":
if a[i - 1] == "2" and odd:
a[i] = "1"
elif a[i - 1] == "1" and odd:
a[i] = "2"
o... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMB... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | a = int(input())
days = [int(x) for x in input().split()]
dp = [[666, 666, 666] for i in range(a)]
if days[0] == 3:
dp[0][0] = 0
dp[0][1] = 0
dp[0][2] = 0
else:
dp[0][0], dp[0][days[0]] = 0, 0
dp[0][0] += 1
for x in range(1, a):
dp[x][0] = min(dp[x - 1][:]) + 1
if days[x] == 3:
dp[x][1] ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER VAR NUMBER N... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = list(map(int, input().split()))
d = []
i = 0
while i < n:
d.append([0, 0, 0])
if i == 0:
if a[i] in [1, 3]:
d[i][1] = 1
if a[i] in [2, 3]:
d[i][2] = 1
elif i > 0:
d[i][0] = max(d[i - 1])
if a[i] in [1, 3]:
d[i][1] = max... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUM... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n, vr, vg, vc = int(input()), 0, 0, 0
for x in map(int, input().split()):
cr = min(vr, vg, vc) + 1
cg = min(vr, vc) if x & 2 else n
cc = min(vr, vg) if x & 1 else n
vr, vg, vc = cr, cg, cc
print(min(vr, vg, vc)) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR F... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | INF = 10**9
n = int(input())
d = [0] + [int(i) for i in input().split()]
dp = [[0, INF, INF]] + [[INF, INF, INF] for i in range(n)]
for i in range(1, n + 1):
if d[i] & 1:
dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])
if d[i] & 2:
dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])
if d[i] == 0 or dp[i][... | ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST NUMBER VAR VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMB... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | from sys import exit
n = int(input())
mas = list(map(int, input().split()))
i = 1
e = mas[0]
if e == 0:
res = 1
else:
res = 0
if e == 3:
for i, x in enumerate(mas):
if x != 3:
break
if mas[i] == 3:
print(0)
from sys import exit
exit()
if mas[i] == 2:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF ... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n_day = eval(input(""))
day = input("")
days = day.split(" ")
count_rest = 0
temp = ""
for i in range(0, len(days)):
if days[i] == "0":
count_rest += 1
temp = ""
elif days[i] == "1":
if temp != "code":
temp = "code"
else:
count_rest += 1
temp =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR STRING IF VAR VAR STRING IF VAR STRING ASSIGN VAR STRING VAR NUMBER ASSIGN VAR STRING I... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | size = int(input())
days = [int(a) for a in input().split()]
daysoff = 0
yesterday = 0
if days[0] == 0:
daysoff += 1
yesterday = 0
elif days[0] == 3:
yesterday = 0
else:
yesterday = days[0]
for i in range(1, size):
if days[i] == 0:
yesterday = 0
daysoff += 1
elif days[i] == yeste... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMB... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | def main():
input()
a1 = a2 = x1 = x2 = z = 0
for b in map(int, input()[::2]):
if 0 < b < 3:
if a1 == b:
a1 = 0
x1 += 1
else:
a1 = b
if a2 == b:
a2 = 0
x2 += 1
else:
... | FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER IF NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR ASSIG... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | import sys
sys.setrecursionlimit(2000)
inf = float("inf")
mod = 1000000007
def get_array():
return list(map(int, sys.stdin.readline().split()))
def get_ints():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline()
def recurse(arr, i, flag):
if i == len(arr):
... | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER 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 FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN VAR... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
days = input().split()
last = "0"
counter = 0
for i in range(n):
if last == days[i] or days[i] == "0":
counter += 1
last = "0"
elif days[i] != "3":
last = days[i]
elif last == "1":
last = "2"
elif last == "2":
last = "1"
elif i < n - 1:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR STRING IF VAR VAR STRING ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR BIN_OP VAR NUMBER... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
l = [int(i) for i in input().split()]
l2 = [0, 0, 0]
for i in range(n):
a = l2[:]
l2[0] = min(a) + 1
if l[i] == 1 or l[i] == 3:
l2[1] = min(a[0], a[2])
else:
l2[1] = 10**6
if l[i] == 2 or l[i] == 3:
l2[2] = min(a[0], a[1])
else:
l2[2] = 10**6
prin... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VA... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
arr = list(map(int, input().split()))
dp = []
for i in range(n):
dp.append([0, 0])
if arr[0] == 1 or arr[0] == 3:
dp[0][0] = 1
if arr[0] == 2 or arr[0] == 3:
dp[0][1] = 1
for i in range(1, n):
if arr[i] == 3:
dp[i][0] = dp[i - 1][1] + 1
dp[i][1] = dp[i - 1][0] + 1
el... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
last = -1
a = list(map(int, input().split()))
ans = 0
for x in a:
if x == 0:
last = -1
ans += 1
elif x < 3:
if last == x:
last = -1
ans += 1
continue
last = x
elif last == 1:
last = 2
elif last == 2:
las... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN V... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
y = list(map(int, input().split()))
y.append(0)
i = 0
current = count = 0
while i < n:
if y[i] == 0:
current = 0
count += 1
i += 1
elif y[i] == 1:
if current == "R":
current = 0
count += 1
else:
current = "R"
i ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR STRI... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | def f(arr):
prev_contest = float("-inf")
prev_gym = float("-inf")
prev_none = 0
for a in arr:
contest = prev_contest
gym = prev_gym
none = prev_none
if a & 1:
contest = max(prev_gym + 1, prev_none + 1)
if a & 2:
gym = max(prev_contest + 1, ... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN V... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = list(map(int, input().split()))
arr = [[0, 0, 0]]
for i in range(n):
f = a[i]
r = max(arr[i][0], arr[i][1], arr[i][2])
c = arr[i][1]
g = arr[i][2]
if f == 1 or f == 3:
c = max(arr[i][0], arr[i][2]) + 1
if f == 2 or f == 3:
g = max(arr[i][0], arr[i][1]) + 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VA... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | _ = input()
activity = list(map(int, input().split()))
dp = [[float("inf") for _ in range(3)] for _ in range(len(activity))]
for i in range(3):
dp[0][i] = 1
if activity[0] == 1:
dp[0][1] = 0
elif activity[0] == 2:
dp[0][2] = 0
elif activity[0] == 3:
dp[0][1] = 0
dp[0][2] = 0
for i in range(1, len(ac... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASS... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = list(map(int, input().split()))
memo = [([-1] * 4) for i in range(n)]
def dp(i, prev):
if i == n:
return 0
if memo[i][prev] == -1:
memo[i][prev] = 1 + dp(i + 1, 0)
if a[i] == 1 or a[i] == 2:
if a[i] != prev:
memo[i][prev] = min(memo[i][p... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR N... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
p = pp = res = 0
a = [int(i) for i in input().split()]
for i in a:
if i == p or i == 0:
p = 0
res += 1
elif i == 1 or i == 2:
p = i
elif p != 0:
p = 3 - p
else:
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = list(map(int, input().split(" ")))
code, sport = [0] * n, [0] * n
for i in range(n):
code[i] = max(code[i], a[i] % 2)
sport[i] = max(sport[i], a[i] // 2)
for j in range(i + 1, n):
if a[j] % 2:
code[j] = max(code[j], sport[i] + 1)
if a[j] // 2:
spo... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER FO... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | from sys import stdin, stdout
num_days = int(stdin.readline())
days = list(map(int, stdin.readline().strip().split()))
dp = [list(float("inf") for i in range(num_days)) for j in range(3)]
dp[0][0] = 1
if days[0] == 1 or days[0] == 3:
dp[1][0] = 0
if days[0] == 2 or days[0] == 3:
dp[2][0] = 0
for i in range(1, ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR N... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | def create_table(situations_list):
the_table = []
if situations_list[0] == 0:
the_table.append([1, 0])
elif situations_list[0] == 1:
the_table.append([0, 1])
elif situations_list[0] == 2:
the_table.append([0, 2])
else:
the_table.append([0, 0])
for k in range(1, le... | FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL ... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | def get_ints(string):
return list(map(int, string.split()))
def get_input():
n = int(input())
xs = get_ints(input())
return n, xs
def foo(xs, res, last):
if len(xs) is []:
return res
for i, x in enumerate(xs):
if x == 0:
res += 1
last = 0
elif ... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR LIST RETURN VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER A... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = [int(x) for x in input().split()]
dp = [[(1000) for i in range(0, 3)] for j in range(0, 101)]
dp[0][0] = dp[0][1] = dp[0][2] = 0
for i in range(1, n + 1):
dp[i][0] = min(dp[i - 1][0], dp[i - 1][1])
dp[i][0] = min(dp[i][0], dp[i - 1][2])
dp[i][0] += 1
if a[i - 1] == 1:
dp[i][... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | nb_days = int(input())
previous, restday = 0, 0
jobs = [int(x) for x in input().split()]
for i in jobs:
if i == 0:
restday += 1
previous = 0
elif i == 3:
previous = 3 - previous
elif previous == i:
restday += 1
previous = 0
else:
previous = i
print(restday... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = list(map(int, input().split()))
dp = [([False] * 2) for i in range(n)]
ans = 0
for i in range(n):
if a[i] == 1:
if dp[i - 1][1] == True and dp[i - 1][0] == False:
ans += 1
else:
dp[i][1] = True
elif a[i] == 2:
if dp[i - 1][0] == True and dp[i ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN ... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = [int(x) for x in input().split()]
dp = [0] * (n + 1)
if a[0] > 0:
dp[0] = 1
sport = a[0]
for x in range(1, n):
dp[x] = dp[x - 1]
if a[x] == 1 and sport != 1:
dp[x] += 1
sport = 1
elif a[x] == 2 and sport != 2:
dp[x] += 1
sport = 2
elif a[x] == 3:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR N... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(" "))
def solve():
n = int(input())
a = list(read_tuple(int))
dp = [[(0) for _ in range(n)] for i in range(3)]
if a[0] == 1:
dp[1][0] = 1
elif a[0] == 2:
dp[2][0] = 1
elif a[0] == 3:
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN V... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = [int(x) for x in input().split()]
d0, d1, d2 = [0], [0], [0]
for i in range(n):
d0.append(max((d0[i], d1[i], d2[i])))
d1.append(max(d0[i], d2[i]) + (1 if a[i] & 1 else 0))
d2.append(max(d0[i], d1[i]) + (1 if a[i] & 2 else 0))
print(n - max((d0[-1], d1[-1], d2[-1]))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST NUMBER LIST NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER N... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
dp = [0] * n
dp[0] = a[0]
for i in range(1, n):
if a[i] == 0:
dp[i] = 0
if a[i] == 1:
if dp[i - 1] == 1:
dp[i] = 0
if dp[i - 1] != 1:
dp[i] = 1
if a[i] == 2:
... | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VA... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
l = list(map(int, input().split()))
dp = [[0, 0, 0] for i in range(n + 1)]
for i in range(1, n + 1):
dp[i][0] = max(dp[i - 1])
if l[i - 1] == 3:
dp[i][1] = max(dp[i - 1][0] + 1, dp[i - 1][2] + 1)
dp[i][2] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 1)
elif l[i - 1] == 2:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSI... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
arr = list(map(int, input().split()))
d = [(0) for i in range(n)]
for i in range(n):
if arr[i] == 0:
d[i] += 1
if i != 0:
if arr[i] == arr[i - 1] and arr[i] != 3 and arr[i] != 0:
d[i] += 1
arr[i] = 0
elif arr[i] == 3 and arr[i - 1] == 1:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER I... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | def vacation(day_sequence):
count = 0
previous = 0
for day in day_sequence:
if day == 0:
count += 1
previous = 0
elif day == 3:
if previous == 1:
previous = 2
elif previous == 2:
previous = 1
elif day == ... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | import sys
sys.setrecursionlimit(100000)
n = int(input())
a = list(map(lambda x: int(x), input().split()))
def calculate(last_action, a, i, dp):
if (last_action, i) in dp:
return dp[last_action, i]
if i == len(a) - 1:
if last_action == 1 and a[i] == 2:
return 1
if last_act... | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR VAR NUMBER RETURN NUMBER... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = [int(x) for x in input().split()]
v = {}
GYM = "GYM"
CONT = "CONT"
OFF = "OFF"
options = [GYM, CONT, OFF]
first = a[0]
if first == 0:
v[0, OFF] = 1
elif first == 1:
v[0, CONT] = 0
v[0, OFF] = 1
elif first == 2:
v[0, GYM] = 0
v[0, OFF] = 1
else:
v[0, CONT] = 0
v[0, GYM] =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
l = [int(x) for x in input().split()]
a = [[(0) for i in range(3)] for j in range(n)]
inf = 10**9
a[0][0] = 1
if l[0] == 1 or l[0] == 3:
a[0][1] = 0
else:
a[0][1] = inf
if l[0] == 2 or l[0] == 3:
a[0][2] = 0
else:
a[0][2] = inf
for i in range(1, n):
a[i][0] = min(a[i - 1]) + 1
i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
arr = list(map(int, input().split()))
ans = [[(0) for i in range(3)] for j in range(n + 1)]
for i in range(1, n + 1):
ans[i][0] = max(ans[i - 1])
if arr[i - 1] == 1 or arr[i - 1] == 3:
ans[i][1] = max(ans[i - 1][0] + 1, ans[i - 1][2] + 1)
if arr[i - 1] == 2 or arr[i - 1] == 3:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBE... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input().strip())
a = list(map(int, input().split()))
d = [[(0) for _ in range(3)] for _ in range(n)]
d[0][0] = 1
d[0][1] = 0 if a[0] in [1, 3] else 1
d[0][2] = 0 if a[0] in [2, 3] else 1
for i in range(1, n):
d[i][0] = min(d[i - 1]) + 1
if a[i] in [1, 3]:
d[i][1] = min(d[i - 1][0], d[i - 1][2])
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER LI... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
acts = list(map(int, input().split()))
memo = [[(-1) for j in range(n + 1)] for i in range(3)]
def solve(prev, day):
if day == n:
return 0
if memo[prev][day] != -1:
return memo[prev][day]
ans = n
if prev != 1 and (acts[day] == 1 or acts[day] == 3):
ans = min(an... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER A... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | from sys import stdin, stdout
n = int(stdin.readline())
a = list(
map(
lambda x: (
(False, False)
if x == "0"
else (
(False, True)
if x == "1"
else (True, False) if x == "2" else (True, True)
)
),
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER NUMBER VAR STRING NUMBER NUMBER VAR STRING NUMBER NUMBER NUMBER NUMBER FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
ans = [0] + list(map(int, input().split()))
lis = ["@"] * (n + 1)
i = 1
while i < n + 1:
if ans[i] == 0:
lis[i] = "r"
elif ans[i] == 1:
if lis[i - 1] == "c":
lis[i] = "r"
else:
lis[i] = "c"
elif ans[i] == 2:
if lis[i - 1] == "g":
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR ... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | def prov(i):
if a[i + 1] == 3:
if a[i + 2] == 1:
return 1
elif a[i + 2] == 2:
return 2
else:
return 1
if a[i + 1] == 1:
return 2
elif a[i + 1] == 2:
return 1
n = int(input())
a = [int(i) for i in input().split()]
if a[0] == 3 and ... | FUNC_DEF IF VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
num = list(map(int, input().split()))
ans = 100
t = 0
dp = [0] * n
dp[0] = num[0]
if dp[0] == 0:
t = 1
for i in range(1, n):
if num[i] == 0:
dp[i] = 0
t += 1
if num[i] == 1:
if dp[i - 1] == 1:
dp[i] = 0
t += 1
else:
dp[i] =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
As = [int(x) for x in input().split()]
cost_con, cost_gym, cost_rest = 0, 0, 0
def my_min(*args):
l = []
for c in args:
if c is not None:
l += [c]
return min(l)
for x in As:
if x == 0:
cost_con, cost_gym, cost_rest = (
None,
None,
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR NONE VAR LIST VAR RETURN FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NONE NONE BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | length = int(input())
days = list(map(int, input().split()))
contest = False
gym = False
rest = 0
for i in range(length):
if days[i] == 0:
rest += 1
contest = False
gym = False
elif days[i] == 1:
if contest:
rest += 1
contest = False
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMB... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = list(map(int, input().split()))
minr = ming = minc = 0
for i in a:
if i == 0:
minr = min(minr, ming, minc) + 1
ming = n
minc = n
elif i == 1:
minc, minr, ming = min(minr, ming), min(minr, ming, minc) + 1, n
elif i == 2:
ming, minr, minc = min(minr... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR V... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
x = [int(x) for x in input().split()]
x.append(-1)
rest = 0
if x[0] == 0:
rest = rest + 1
for i in range(1, n):
if x[i] == 0:
rest = rest + 1
elif x[i] == 1 and x[i - 1] == 1:
rest = rest + 1
x[i] = 0
elif x[i] == 2 and x[i - 1] == 2:
rest = rest + 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASS... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = [int(x) for x in input().split()]
dp = [[(-1) for _ in range(n)] for _ in range(3)]
def solve(prev, i):
if i == n:
return 0
if dp[prev][i] != -1:
return dp[prev][i]
if a[i] == 0:
dp[prev][i] = 1 + solve(0, i + 1)
elif a[i] == 1:
if prev == 1:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR N... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = [int(x) for x in input().split()]
i = 0
j = 1
ans = 0
while i < n and j < n:
c = 0
if a[i] == 1 and a[j] == 1 or a[i] == 2 and a[j] == 2:
ans += 1
i += 2
j += 2
elif a[i] == 1 and a[j] == 3:
while j < n and a[j] == 3:
c += 1
j += 1... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER W... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
list1 = [int(i) for i in input().split()]
dp = []
for x in range(n):
dp.append([10**9, 10**9, 10**9])
dp[0][0] = 1
if list1[0] == 0:
dp[0][1] = 1
dp[0][2] = 1
elif list1[0] == 1:
dp[0][1] = 0
dp[0][2] = 1
elif list1[0] == 2:
dp[0][1] = 1
dp[0][2] = 0
else:
dp[0][1] = 0
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR... |
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
1. on this day the gym is closed and... | n = int(input())
a = [int(i) for i in input().split()]
dp = [[0] * (n + 1), [0] * (n + 1), [0] * (n + 1)]
INF = 1000000000.0
for i in range(1, n + 1):
dp[0][i] = min(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1]) + 1
dp[1][i] = INF
dp[2][i] = INF
if a[i - 1] in [1, 3]:
dp[1][i] = min(dp[0][i - 1], dp... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP FUN... |
Chef's loves his dog so much! Once his dog created two strings a and b each of length n consisting of digits 1 and 2, and even a problem about them!
Chef's Dog will tell by barking if a string x (also containing only digits 1 and 2 and with length N) is good or not by performing the following actions.
- It starts at f... | MOD = 1000000007
for i in range(int(input())):
a = input()
b = input()
n = len(a)
if n == 1:
print(2)
elif a[n - 2] == "2" or b[n - 2] == "2":
print(0)
else:
fr, sc = 0, 0
ans = 1
for j in range(n - 1):
c = int(a[j]) + int(b[j])
if ... | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER... |
Chef's loves his dog so much! Once his dog created two strings a and b each of length n consisting of digits 1 and 2, and even a problem about them!
Chef's Dog will tell by barking if a string x (also containing only digits 1 and 2 and with length N) is good or not by performing the following actions.
- It starts at f... | modulo = 1000000007
def pow(a, n):
res = 1
while n > 0:
if n & 1:
res *= a
res %= modulo
a *= a
a %= modulo
n //= 2
return res
def test2(s):
if "4" in s:
return True
if len(s) & 1 > 0:
return True
return False
def test... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF STRING VAR RETURN NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING RETURN FUNC_CALL VAR FUNC_CALL VAR ... |
Chef's loves his dog so much! Once his dog created two strings a and b each of length n consisting of digits 1 and 2, and even a problem about them!
Chef's Dog will tell by barking if a string x (also containing only digits 1 and 2 and with length N) is good or not by performing the following actions.
- It starts at f... | T = int(input())
for t in range(T):
S1 = list(input())
S2 = list(input())
N = len(S1)
MOD = 1000000007
count = 1
for n in range(N - 1):
if S2[n] == "2":
S1[n], S2[n] = S2[n], S1[n]
if S1[n] == S2[n]:
count = count * 2 % MOD
count = count * 2 % MOD
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR ... |
Chef's loves his dog so much! Once his dog created two strings a and b each of length n consisting of digits 1 and 2, and even a problem about them!
Chef's Dog will tell by barking if a string x (also containing only digits 1 and 2 and with length N) is good or not by performing the following actions.
- It starts at f... | size = 100000
modval = 1000000007
def main():
t = int(input())
for _ in range(t):
a = input()
b = input()
l = len(a)
count = 0
if l == 1:
count = 2
elif l < 4:
if checkGood(a, b, l) == 1:
if l == 2:
cou... | ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER... |
Chef's loves his dog so much! Once his dog created two strings a and b each of length n consisting of digits 1 and 2, and even a problem about them!
Chef's Dog will tell by barking if a string x (also containing only digits 1 and 2 and with length N) is good or not by performing the following actions.
- It starts at f... | def fun(a):
n = len(a)
i = 0
b = []
while i < n:
c = 0
while i < n - 1 and a[i] == a[i + 1]:
c += 1
i += 1
b.append([a[i], c + 1])
i += 1
return b
def tatti(h):
n = len(h)
i = 0
b = []
while i < n:
c = 0
while ... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN V... |
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | def roundroot():
global root
i = len(root) - 1
while i >= 0:
root[i] += 1
if root[i] == 10 and i != 0:
root[i] = 0
i -= 1
else:
break
def printA(a):
for i in a:
print(i, end="")
n, t = [int(i) for i in input().split()]
num = input()... | FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR V... |
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | n, k = map(int, input().split())
s = list(input())
dot = s.index(".")
pos = -1
for i in range(dot + 1, n):
if s[i] > "4":
pos = i
break
if pos < 0:
print("".join(s))
else:
for j in range(k):
if s[pos - 1 - j] != "4":
break
pos = pos - 1 - j
while pos >= 0 and (s[p... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN... |
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | n, t = list(map(int, input().split()))
s = list(input())
p = 0
index = n - 1
for i in range(0, n):
if s[i] == ".":
p = i
if p == 0:
continue
if s[i] >= "5":
index = i
break
while s[index] >= "5" and index > p and t > 0:
if s[index - 1] == ".":
index = index - 1
... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR WHILE VAR VAR STRING VAR VAR VAR NUMBER IF VAR BIN... |
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | n, t = map(int, input().split())
tmp = input()
s = []
for i in range(n):
s.append(tmp[i])
ind = n
perenos = 0
for i in range(n):
if s[i] == ".":
nach = i + 1
for i in range(nach, n):
if int(s[i]) > 4:
ind = i
break
if ind == n:
print(*s, sep="")
exit()
while t > 0 and s[ind] ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER A... |
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | n, t = map(int, input().split(" "))
num = input()
num = ["0"] + list(num)
stack = []
dot = num.index(".")
for i, x in enumerate(num):
if i > dot and int(x) >= 5:
stack.append(i)
break
ind = len(num) - 1
for i in range(t):
if len(stack) == 0 or stack[0] < dot:
break
ind = stack[0]
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR... |
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | n, t = map(int, input().split())
mark = input().split(".")
shift = False
fraction = []
for digit in map(int, mark[1]):
if digit > 4:
t -= 1
if fraction:
fraction[-1] += 1
while t and fraction and fraction[-1] > 4:
t -= 1
fraction.pop()
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER WHILE VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR NU... |
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | n, t = map(int, input().split())
x = input()
i = x.find(".")
for j in range(i + 1, n):
if x[j] > "4":
for k in range(t):
j -= 1
if x[j] != "4":
break
if j == i:
j -= 1
while j and x[j] == "9":
j -= 1
x = x[:j... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING IF VAR VAR VAR NUMBER WHILE VAR VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VA... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
edge_value = collections.defaultdict()
graph = collections.defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
def dfs1(u, parent):
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
graph = [[] for _ in range(N)]
for i, j in edges:
graph[i].append(j)
graph[j].append(i)
size, up, down = [1] * N, [0] * N, [0] * N
def post(parent, i):
f... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FUNC_DEF FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR BI... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
graph = [set() for _ in range(N)]
for edge in edges:
graph[edge[0]].add(edge[1])
graph[edge[1]].add(edge[0])
count = [1] * N
ans = [0] * N
def dfs(node, pare... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR V... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
links = [[] for _ in range(N)]
for a, b in edges:
links[a].append(b)
links[b].append(a)
sums1 = [0] * N
nums1 = [None] * N
sums2 = [0] * N
self.dfs1(N... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR NONE NUMBER VAR VAR VAR EXPR FUNC_CALL VAR NONE NUMBER VAR... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
graph = collections.defaultdict(set)
for u, v in edges:
graph[u].add(v)
graph[v].add(u)
count = [1] * N
ans = [0] * N
print(graph)
def postorder(node... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR FUNC_DEF NUMBER NONE FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
tree = collections.defaultdict(set)
res = [0] * N
count = [1] * N
for i, j in edges:
tree[i].add(j)
tree[j].add(i)
def dfs(root, pre):
for i in t... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Node:
def __init__(self, val):
self.val = val
self.children = []
def add_edge(self, child):
self.children.append(child)
child.parent = self
def count(self):
res_num = 0
res_val = 0
for c in self.children:
temp_num, temp_val = c.cou... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR BIN_OP VAR VA... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
edges_dict = dict()
for i in range(N):
edges_dict[i] = []
for edge in edges:
edges_dict[edge[0]].append(edge[1])
edges_dict[edge[1]].append(edge[0])
dp_di... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
Nodes = [None] * N
def node(i):
if Nodes[i] is None:
Nodes[i] = Node(i)
return Nodes[i]
adj = defaultdict(list)
for edge in edges:
adj[e... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR FUNC_DEF IF VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER WH... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
root = 0
children = [[] for i in range(N)]
for a, b in edges:
children[a].append(b)
children[b].append(a)
sub_size = [0] * N
def compute_sub_size(node, paren... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST N... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
if N == 1:
return [0]
neighbors = {}
for edge in edges:
a = edge[0]
b = edge[1]
if a not in neighbors:
neighbors[a] = []
i... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT NUMBER NONE ASSI... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
ans = [0] * N
graph = defaultdict(set)
for u, v in edges:
graph[u].add(v)
graph[v].add(u)
visited = {}
return [self.dfs(graph, i, -1, visited)[0] for i in ran... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR N... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
if N == 1:
return [0]
graph_dict = {}
for pair in edges:
left, right = pair[0], pair[1]
graph_dict[left] = [right] + graph_dict.get(left, [])
graph_di... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP LIST VAR FUNC_CALL VAR VAR LIST ASSIGN VAR VAR BIN_OP LIST VAR FUNC_CALL VAR VAR LIST ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VA... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
def dfs(node, parent):
for child in graph[node]:
if child != parent:
dfs(child, node)
count_self_and_children[node] += count_self_and_children[ch... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
if N == 1:
return [0]
adj = [[] for _ in range(N)]
for [u, v] in edges:
adj[u].append(v)
adj[v].append(u)
d_dists = {}
d_vertices_up_to_u = {}
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR VAR VAR VAR ASSIGN VAR V... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
graph = defaultdict(list)
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
start = -1
for node in graph:
if len(graph[node]) == 1:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_DEF NONE NUMBER RETURN BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
if N == 1:
return [0]
dt = {}
for e in edges:
if e[0] not in dt:
dt[e[0]] = []
dt[e[0]].append(e[1])
if e[1] not in dt:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR ASSI... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
adj_list = defaultdict(list)
for v1, v2 in edges:
adj_list[v1].append(v2)
adj_list[v2].append(v1)
root = 0
subT_size = {}
def postorder(t, par_t) -> int:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
connected = collections.defaultdict(lambda: [])
for s, e in edges:
connected[s].append(e)
connected[e].append(s)
@functools.lru_cache(None)
def get_to_father(node=0,... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF NUMBER NONE ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NU... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution:
def sumOfDistancesInTree(self, N: int, edges: List[List[int]]) -> List[int]:
connect = [set() for _ in range(N)]
num_children = [0] * N
dist = [0] * N
for i, j in edges:
connect[i].add(j)
connect[j].add(i)
dist[0] = self.dfs1(0, connec... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR VA... |
An undirected, connected tree with N nodes labelled 0...N-1 and N-1 edges are given.
The ith edge connects nodes edges[i][0] and edges[i][1] together.
Return a list ans, where ans[i] is the sum of the distances between node i and all other nodes.
Example 1:
Input: N = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
Output: ... | class Solution(object):
def sumOfDistancesInTree(self, N, edges):
if N == 0 or not edges:
return [0]
graph = {i: set() for i in range(N)}
for n1, n2 in edges:
graph[n1].add(n2)
graph[n2].add(n1)
count = [1] * N
subSums = [0] * N
d... | CLASS_DEF VAR FUNC_DEF IF VAR NUMBER VAR RETURN LIST NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF FOR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.