description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Knight is at (start_x,start_y) in Geekland which is represented by an NxM 2D matrix. Each cell in the matrix contains some points. In the ith step, the knight can collect all the points from all the cells that can be visited in exactly i steps without revisiting any cell. Also, the knight has some magical powers that enable him to fetch coins from the future i.e. If the knight can collect y coins in the xth step he can fetch all the coins that he will collect in the (x + y)th step and if the knight can collect z coins in the yth step he can fetch all the coins that he will collect in the (y + z)th step and so on without increasing the step count i.e. knight will stay on xth step and will get all the coins of the future steps mentioned above((x + y)th step coins + (y+z)th steps + ...). Find the minimum number of steps required to collect the maximum points. Note: The knight moves exactly the same as the knight on a chess board. Please follow 0 indexing. Example 1: Input: n = 9 m = 10 start_x = 4, start_y = 5 arr = 0 0 0 2 0 2 0 2 0 0 0 0 2 0 2 0 2 0 2 0 0 2 0 0 1 2 0 0 0 2 0 0 2 0 2 0 2 0 2 0 0 2 0 2 0 0 0 2 0 2 0 0 2 0 2 0 2 0 2 0 0 2 0 0 0 2 0 0 0 2 0 0 2 0 2 0 2 0 2 0 0 0 0 2 0 2 0 2 0 0 Output: 1 Explanation: minimum knight have to take 1 steps to gain maximum points. Initially, the knight has 0 coins, he will take 1 step to collect 1 point (sum of cells denoted in red color). Now in the second step, he can collect points from all the cells colored green i.e. 64 points. But with his magical power, at the 1st step, he can fetch points from the (1 + 1)th step. Therefore he can collect 1 + 64 coins at step 1 only. Hence answer is 1. Example 2: Input: n = 3 m = 3 start_x = 2, start_y = 1 arr = 7 6 8 9 1 4 6 2 8 Output:0 Explanation: Initially, the knight has 2 points, or more formally we can say that at the 0th step knight has 2 points. In the first step, he can collect points from cells (0, 0) and (0, 2) i.e. 15 points. In the second step, he can collect points from cells (1, 0) and (1, 2) i.e. 13 coins. In the third step, he can collect points from cells (2, 0) and (2, 2) i.e. 14 points. In the fourth step, he can collect points from the cell (0, 1) i.e. 6 points. So in each step, he can collect coins like -You can see in the below image Knight can collect 15 coins in the 0th step only Your Task: You don't need to read input or print anything. Your task is to complete the function knightInGeekland() which takes 2-d array arr[][], starting coordinates of knight start_x, and start_y as input, and return an integer value as min steps to gain max points. Expected Time Complexity: O(N*M) Expected Auxiliary Space: O(N*M) Constraints: 1 <= len(arr), len(arr[0]) < 10^{3} 0 <= values in arr <=100
class Solution: def knightInGeekland(self, arr, start): n, m = len(arr), len(arr[0]) dp = [[(-1) for _ in range(m)] for __ in range(n)] coins = [] starting = [[start[0], start[1]]] coins.append(arr[start[0]][start[1]]) dp[start[0]][start[1]] = 1 self.traverse(starting, dp, arr, coins, 1) coin_dp = [(0) for _ in range(len(coins))] for k in range(len(coin_dp)): self.max_ind(coins, coin_dp, k) maxi = 0 for i in range(len(coin_dp)): if coin_dp[i] > coin_dp[maxi]: maxi = i return maxi def next_cell(self, row, col): next_ = [ [row + 2, col + 1], [row + 2, col - 1], [row - 2, col + 1], [row - 2, col - 1], [row + 1, col + 2], [row + 1, col - 2], [row - 1, col + 2], [row - 1, col - 2], ] return next_ def valid_cells(self, input_cells, array, n, m): target_cell = [] for item in input_cells: nxt = self.next_cell(item[0], item[1]) for ele in nxt: if 0 <= ele[0] <= n - 1 and 0 <= ele[1] <= m - 1: if array[ele[0]][ele[1]] == -1: array[ele[0]][ele[1]] = 1 target_cell.append([ele[0], ele[1]]) return target_cell def traverse(self, cur, array, main, cnt, step): tgt = self.valid_cells(cur, array, len(main), len(main[0])) if cnt[step - 1] == 0: if len(tgt) == 0: return cnt temp = 0 for cell in tgt: temp += main[cell[0]][cell[1]] cnt.append(temp) return self.traverse(tgt, array, main, cnt, step + 1) def max_ind(self, main, dp, ind): if dp[ind] == 0 and main[ind] != 0: if ind + main[ind] < len(main): dp[ind] = main[ind] + self.max_ind(main, dp, ind + main[ind]) else: dp[ind] = main[ind] return dp[ind]
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST LIST VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) ar = list(map(int, input().split())) dp0 = [0] * (n + 1) dp1 = [0] * (n + 1) dp2 = [0] * (n + 1) dp0[0] = 1 if ar[0] == 1 or ar[0] == 3: dp1[0] = 0 else: dp1[0] = 10000000 if ar[0] == 2 or ar[0] == 3: dp2[0] = 0 else: dp2[0] = 10000000 for i in range(1, n): dp0[i] = min(min(dp0[i - 1], dp1[i - 1]), dp2[i - 1]) + 1 if ar[i] == 1 or ar[i] == 3: dp1[i] = min(dp0[i - 1], dp2[i - 1]) else: dp1[i] = 10000000 if ar[i] == 2 or ar[i] == 3: dp2[i] = min(dp0[i - 1], dp1[i - 1]) else: dp2[i] = 10000000 a = min(min(dp0[n - 1], dp1[n - 1]), dp2[n - 1]) print(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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) days = [int(_) for _ in input().split()] ff = {(0, n): 0, (1, n): 0, (2, n): 0} def f(t, k): if not (t, k) in ff: www = [] for x in range(3): if x == 0: www.append(f(x, k + 1) + 1) elif x & days[k] and (t == 0 or t != x): www.append(f(x, k + 1)) ff[t, k] = min(www) return ff[t, k] print(f(0, 0))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) line = [int(x) for x in input().split()] d = [0] * 3 for i in line: d_1 = d[:] d[0] = min(d_1) + 1 if i == 1: d[1] = min(d_1[0], d_1[2]) d[2] = 10**6 elif i == 2: d[2] = min(d_1[0], d_1[1]) d[1] = 10**6 elif i == 3: d[1] = min(d_1[0], d_1[2]) d[2] = min(d_1[0], d_1[1]) elif i == 0: d[1] = 10**6 d[2] = 10**6 print(min(d))
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 NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
log = lambda *x: print(*x) def cin(*fn, def_fn=str): i, r = 0, [] for c in input().split(" "): r += [(fn[i] if len(fn) > i else fn[0])(c)] i += 1 return r INF = 1 << 33 def solve(a, n): dp = [] for i in range(n + 1): dp += [[]] for j in range(n + 1): dp[i] += [{(1): 0, (10): 0, (11): 0}] for i in range(n, -1, -1): for t in range(n - 1, -1, -1): for tf in [11, 10, 1]: if i == n: dp[i][t][tf] = i - t continue cc = tf // 10 and (a[i] == 1 or a[i] == 3) cg = tf % 10 and (a[i] == 2 or a[i] == 3) if not (cc or cg): dp[i][t][tf] = dp[i + 1][t][11] continue a1, a2 = INF, INF if cc: a1 = dp[i + 1][t + 1][1] if cg: a2 = dp[i + 1][t + 1][10] dp[i][t][tf] = min(a1, a2) return min(dp[0][0][1], dp[0][0][10]) (n,) = cin(int) a = cin(int) log(solve(a, n))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF VAR ASSIGN VAR VAR NUMBER LIST FOR VAR FUNC_CALL FUNC_CALL VAR STRING VAR LIST FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR LIST DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR LIST NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
numday = input() dayorder = input() array = map(int, dayorder.split(" ")) sumrest = 0 prev = 3 for i in array: if i == prev and prev != 3: i = 0 elif i == 3 and prev != 3: i -= prev if i == 0: sumrest += 1 prev = i print(sumrest)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING 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 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) lt = list(map(int, input().split())) l = [0] + lt c = 0 t = [0] * (n + 1) for i in range(1, len(l)): if l[i] == 1: t[i] = "C" elif l[i] == 2: t[i] = "G" elif l[i] == 3: if t[i - 1] == "C": t[i] = "G" elif t[i - 1] == "G": t[i] = "C" else: j = i ct = 0 x = l[i] while j <= n: x = l[j] if x == 1 or x == 2: break ct += 1 j += 1 if x == 1: if ct % 2 == 0: t[i] = "C" else: t[i] = "G" elif x == 2: if ct % 2 == 0: t[i] = "G" else: t[i] = "C" else: t[i] = "C" if t[i] == 0: c += 1 elif t[i] == t[i - 1]: c += 1 t[i] = 0 print(c)
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 ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def main(): n = int(input()) vacation = [int(i) for i in input().split()] sum = 0 i = 0 res = [] for i in range(n): row = [] if i == 0: if vacation[i] == 0: row.append(1) row.append(101) row.append(101) elif vacation[i] == 1: row.append(1) row.append(0) row.append(101) elif vacation[i] == 2: row.append(1) row.append(101) row.append(0) else: row.append(1) row.append(0) row.append(0) elif vacation[i] == 0: row.append(1 + min(res[i - 1])) row.append(101) row.append(101) elif vacation[i] == 1: row.append(1 + min(res[i - 1])) row.append(min(res[i - 1][0], res[i - 1][2])) row.append(101) elif vacation[i] == 2: row.append(1 + min(res[i - 1])) row.append(101) row.append(min(res[i - 1][0], res[i - 1][1])) else: row.append(1 + min(res[i - 1])) row.append(min(res[i - 1][0], res[i - 1][2])) row.append(min(res[i - 1][0], res[i - 1][1])) res.append(row) print(min(res[-1])) main()
FUNC_DEF 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) aa = map(int, input().split()) v = [[0, 0], [0, 0]] for a in aa: if a < 2: max_s = v[-1][0] else: max_s = max([v[-1][0], v[-2][0] + 1, v[-1][1] + 1]) if a % 2 == 0: max_c = v[-1][1] else: max_c = max([v[-1][1], v[-2][1] + 1, v[-1][0] + 1]) v.append([max_s, max_c]) print(n - max(v[-1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) c = list(map(int, input().split())) l = 0 if c[0] == 3: c[0] = 0 elif c[0] == 0: l += 1 for i in range(1, n): if c[i - 1] == c[i]: l += 1 c[i] = 0 elif c[i] == 3: if c[i - 1] == 0: c[i] = 0 else: c[i] = 3 - c[i - 1] elif c[i] == 0: l += 1 print(l)
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 IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
input() mat = [0, 0, 0] for i in map(int, input().split()): tmp = mat[:] mat[0] = min(tmp) + 1 mat[1] = min(tmp[0], tmp[2]) if i == 1 or i == 3 else 10000000.0 mat[2] = min(tmp[0], tmp[1]) if i == 2 or i == 3 else 10000000.0 print(min(mat))
EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = list(map(int, input().split())) INF = float("inf") dp = [([INF] * 3) for i in range(n + 1)] dp[0][0] = 0 for i in range(n): k = a[i] dp[i + 1][0] = min(dp[i][0], dp[i][1], dp[i][2]) + 1 if k == 1: dp[i + 1][1] = min(dp[i][0], dp[i][2]) elif k == 2: dp[i + 1][2] = min(dp[i][0], dp[i][1]) elif k == 3: dp[i + 1][1] = min(dp[i][0], dp[i][2]) dp[i + 1][2] = min(dp[i][0], dp[i][1]) print(min(dp[n]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) numbers = list(map(int, input().split(" "))) memo = [[(0) for _ in range(4)] for _ in range(n)] first = numbers[0] if first != 0: if first == 3: memo[0][1] = 1 memo[0][2] = 1 else: memo[0][first] = 1 for i in range(1, n): j = numbers[i] for k in range(0, i): if k == i - 1: if j == 0 or j == 3: memo[i][0] = max(memo[i][0], max(memo[k])) if j == 1 or j == 3: memo[i][1] = max(memo[i][1], max(memo[k][2], memo[k][0]) + 1) if j == 2 or j == 3: memo[i][2] = max(memo[i][2], max(memo[k][1], memo[k][0]) + 1) else: maximum = max(memo[k]) if j == 0: memo[i][0] = maximum elif j == 3: memo[i][1] = max(memo[i][1], maximum + 1) memo[i][2] = max(memo[i][2], maximum + 1) else: memo[i][j] = max(memo[i][j], maximum + 1) print(n - max(memo[n - 1]))
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 NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) d0, d1, d2 = 0, 0, 0 for ai in map(int, input().split()): if ai == 0: d0 = max(d1, d2) elif ai == 1: d0, d2 = max(d1, d2), max(d0, d1) + 1 elif ai == 2: d0, d1 = max(d1, d2), max(d0, d2) + 1 elif ai == 3: d0, d1, d2 = max(d1, d2), max(d0, d2) + 1, max(d0, d1) + 1 print(n - max(d0, d1, d2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = [i for i in input().split(" ")] dp = [] for i in range(n): dp.append([]) for _ in range(3): dp[i].append(0) dp[0][0] = 1 if a[0] == "1" or a[0] == "3": dp[0][1] = 0 else: dp[0][1] = 1 if a[0] == "2" or a[0] == "3": dp[0][2] = 0 else: dp[0][2] = 1 for i in range(1, n): dp[i][0] = min(dp[i - 1]) + 1 if a[i] == "1" or a[i] == "3": dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) else: dp[i][1] = min(dp[i - 1]) + 1 if a[i] == "2" or a[i] == "3": dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) else: dp[i][2] = min(dp[i - 1]) + 1 print(min(dp[n - 1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = list(map(int, input().split())) a.insert(0, 0) p = [] for i in range(n + 1): p.append([]) p[i].append(0) p[i].append(0) for i in range(1, n + 1): if a[i] == 1 or a[i] == 3: p[i][0] = max(p[i - 1][1] + 1, p[i - 1][0]) else: p[i][0] = max(p[i - 1][0], p[i - 1][1]) if a[i] == 2 or a[i] == 3: p[i][1] = max(p[i - 1][0] + 1, p[i - 1][1]) else: p[i][1] = max(p[i - 1][0], p[i - 1][1]) print(n - max(p[n][0], p[n][1]))
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 NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) l = list(map(int, input().split())) if n == 1: if l[0] == 0: print(1) else: print(0) else: dp = [[float("inf") for i in range(3)] for j in range(n)] for i in range(n): for j in range(3): if i == 0: dp[i][0] = 1 if l[i] == 1: dp[i][1] = 0 elif l[i] == 2: dp[i][2] = 0 elif l[i] == 3: dp[i][1] = 0 dp[i][2] = 0 else: dp[i][0] = 1 + min(dp[i - 1]) if l[i] == 1: dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) elif l[i] == 2: dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) elif l[i] == 3: dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) print(min(dp[-1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
t = 1 for qwe in range(t): n = int(input()) a = list(map(int, input().split())) temp = [0, 0, 0] temp.extend(a) a = temp ans = 0 for i in range(n + 3): if a[i] == 0: ans += 1 a[i] = 0 elif a[i] == 3: pass elif a[i] == 1: if a[i - 1] == 0 or a[i - 1] == 2: pass elif a[i - 1] == 1: ans += 1 a[i] = 0 elif a[i - 1] == 3: k = 1 ind = i - 1 while a[ind - 1] == 3: ind -= 1 k += 1 ind -= 1 if k % 2 == 1: if a[ind] == 0 or a[ind] == 1: pass elif a[ind] == 2: ans += 1 a[i] = 0 elif a[ind] == 0 or a[ind] == 2: pass elif a[ind] == 1: ans += 1 a[i] = 0 elif a[i] == 2: if a[i - 1] == 0 or a[i - 1] == 1: pass elif a[i - 1] == 2: ans += 1 a[i] = 0 elif a[i - 1] == 3: k = 1 ind = i - 1 while a[ind - 1] == 3: ind -= 1 k += 1 ind -= 1 if k % 2 == 1: if a[ind] == 0 or a[ind] == 2: pass elif a[ind] == 1: ans += 1 a[i] = 0 elif a[ind] == 0 or a[ind] == 1: pass elif a[ind] == 2: ans += 1 a[i] = 0 a[ind] = 0 print(ans - 3)
ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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 LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = list(map(int, input().split())) best = [0, 0, 0] for i in range(n): nx_best = [0, 0, 0] if a[i] in (1, 3): nx_best[1] = max(best[0], best[2]) + 1 if a[i] in (2, 3): nx_best[2] = max(best[0], best[1]) + 1 nx_best[0] = max(best) best = nx_best[:] print(n - max(best))
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
for t in range(1): n = int(input()) arr = list(map(int, input().split())) prev = arr[0] if prev == 0: count = 1 else: count = 0 for ele in range(1, n): i = arr[ele] if i == 0: count += 1 prev = 0 continue elif i == 1: if prev == 1: prev = 0 count += 1 continue else: prev = 1 continue elif i == 2: if prev == 2: prev = 0 count += 1 continue else: prev = 2 continue elif i == 3: if prev == 1: prev = 2 continue elif prev == 2: prev = 1 continue else: prev = 0 continue print(count)
FOR VAR FUNC_CALL VAR NUMBER 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 NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) days = input().strip().split() dp = [[0, 0, 0] for x in range(n + 1)] for x in range(n - 1, -1, -1): job = days[x] if job == "0": dp[x][0] = 1 + min(dp[x + 1][0], dp[x + 1][1], dp[x + 1][2]) dp[x][1] = 9999999 dp[x][2] = 9999999 elif job == "1": dp[x][0] = 1 + min(dp[x + 1][0], dp[x + 1][1], dp[x + 1][2]) dp[x][1] = 9999999 dp[x][2] = min(dp[x + 1][0], dp[x + 1][1]) elif job == "2": dp[x][0] = 1 + min(dp[x + 1][0], dp[x + 1][1], dp[x + 1][2]) dp[x][1] = min(dp[x + 1][0], dp[x + 1][2]) dp[x][2] = 9999999 elif job == "3": dp[x][0] = 1 + min(dp[x + 1][0], dp[x + 1][1], dp[x + 1][2]) dp[x][1] = min(dp[x + 1][0], dp[x + 1][2]) dp[x][2] = min(dp[x + 1][0], dp[x + 1][1]) print(min(dp[0][0], dp[0][1], dp[0][2]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = map(int, input().split()) last_act = 0 cnt = 0 for act in a: if act == 0: last_act = 0 cnt += 1 elif act == 3: if last_act: last_act = 1 if last_act == 2 else 2 elif act in [1, 2]: if last_act == act: cnt += 1 last_act = 0 else: last_act = act print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER IF VAR LIST NUMBER NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) days = [int(c) for c in input().split()] memo = {} def solve(day=0, prev=0): if (day, prev) in memo: return memo[day, prev] cur = days[day] if day == n - 1: if cur == 0: return 1 elif cur == 3: return 0 elif cur == 1: return 1 if prev == 2 else 0 elif cur == 2: return 1 if prev == 1 else 0 options = [1 + solve(day + 1, 0)] if (cur == 2 or cur == 3) and prev != 1: options.append(solve(day + 1, 1)) if (cur == 1 or cur == 3) and prev != 2: options.append(solve(day + 1, 2)) memo[day, prev] = min(options) return memo[day, prev] def main(): ans = solve() print(ans) main()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF NUMBER NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER IF VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
x = 0 g = False c = False rest = 0 n = int(input()) lst = list(map(int, input().split())) for i in lst: if g and i == 1 or c and i == 2: rest += 1 g = False c = False elif i == 0: rest += 1 g = False c = False elif i == 3: l = c c = g g = l elif i == 2: c = True g = False elif i == 1: g = True c = False print(rest)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) A = list(map(int, input().split())) c = 0 p = -1 for i in range(n): if A[i] == 0: c = c + 1 p = -1 if A[i] == 1: if A[i] == p: c = c + 1 p = -1 else: p = 1 if A[i] == 2: if A[i] == p: c = c + 1 p = -1 else: p = 2 if A[i] == 3: if p == 2: p = 1 elif p == 1: p = 2 elif i != n - 1 and A[i + 1] == 1: p = 2 elif i != n - 1 and A[i + 1] == 2: p = 1 else: p = 0 print(c)
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 FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
act = int(input()) a = list(map(int, input().split())) dp = [[(-1) for i in range(3)] for j in range(act + 1)] c = 0 def ans(n, k): if n == act: return 0 if dp[n][k] != -1: return dp[n][k] if a[n] == 0: dp[n][k] = 1 + ans(n + 1, 0) return 1 + ans(n + 1, 0) if a[n] == 1: if k == 1: dp[n][k] = 1 + ans(n + 1, 0) return 1 + ans(n + 1, 0) else: dp[n][k] = min(1 + ans(n + 1, 0), ans(n + 1, 1)) return min(1 + ans(n + 1, 0), ans(n + 1, 1)) if a[n] == 2: if k == 2: dp[n][k] = 1 + ans(n + 1, 0) return 1 + ans(n + 1, 0) else: dp[n][k] = min(1 + ans(n + 1, 0), ans(n + 1, 2)) return min(1 + ans(n + 1, 0), ans(n + 1, 2)) if a[n] == 3: if k == 2: dp[n][k] = min(1 + ans(n + 1, 0), ans(n + 1, 1)) return min(1 + ans(n + 1, 0), ans(n + 1, 1)) elif k == 1: dp[n][k] = min(1 + ans(n + 1, 0), ans(n + 1, 2)) return min(1 + ans(n + 1, 0), ans(n + 1, 2)) else: dp[n][k] = min(1 + ans(n + 1, 0), ans(n + 1, 1), ans(n + 1, 2)) return min(1 + ans(n + 1, 0), ans(n + 1, 1), ans(n + 1, 2)) k = ans(0, 0) print(k)
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 ASSIGN 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 BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) s = (int(t) for t in input().split(" ")) prev = 3 count = 0 for c in s: if c == 0: count += 1 prev = 0 elif c == 3: prev = 3 - prev elif c == prev: count += 1 prev = 0 else: prev = c print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) A = list(map(int, input().split())) d = {} def dp(at, s, w): if at == n: return 0 if (at, s, w) in d: return d[at, s, w] ret = 10**9 if A[at] == 0: ret = min(ret, dp(at + 1, False, False) + 1) if A[at] == 1: ret = min(ret, dp(at + 1, False, False) + 1) if not w: ret = min(ret, dp(at + 1, False, True)) if A[at] == 2: ret = min(ret, dp(at + 1, False, False) + 1) if not s: ret = min(ret, dp(at + 1, True, False)) if A[at] == 3: ret = min(ret, dp(at + 1, False, False) + 1) if not s: ret = min(ret, dp(at + 1, True, False)) if not w: ret = min(ret, dp(at + 1, False, True)) if not s and not w: ret = min(ret, dp(at + 1, True, True)) d[at, s, w] = ret return ret print(dp(0, False, False))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = list(map(int, input().split())) inf = 10**10 dp = [0, 0] for x in a: z = min(dp) if x == 0: dp[0] = 1 + z dp[1] = 1 + z elif x == 1: dp[1] = min(dp[0], dp[1] + 1) dp[0] = z + 1 elif x == 2: dp[0] = min(dp[1], dp[0] + 1) dp[1] = z + 1 else: dp[0], dp[1] = min(dp[1], dp[0] + 1), min(dp[0], dp[1] + 1) print(min(dp))
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 ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
dp = [[(200) for i in range(3)] for j in range(100)] n = int(input()) li = list(map(int, input().split())) dp[0][0] = 1 if li[0] == 1 or li[0] == 3: dp[0][1] = 0 if li[0] == 2 or li[0] == 3: dp[0][2] = 0 for i in range(1, n): dp[i][0] = 1 + min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) if li[i] == 1 or li[i] == 3: dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) if li[i] == 2 or li[i] == 3: dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) print(min(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]))
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER 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 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = list(map(int, input().split())) def func(b, p): if len(b) == 1: if p == 0: if b[0] == 0: return 1 else: return 0 elif p == 1: if b[0] == 0 or b[0] == 1: return 1 else: return 0 elif p == 2: if b[0] == 0 or b[0] == 2: return 1 else: return 0 elif b[0] == 0: return 1 else: return 0 else: c = b[1:] if p == 0: if b[0] == 0: return 1 + func(c, 0) else: return func(c, b[0]) elif p == 1: if b[0] == 0 or b[0] == 1: return 1 + func(c, 0) else: return func(c, 2) elif p == 2: if b[0] == 0 or b[0] == 2: return 1 + func(c, 0) else: return func(c, 1) elif b[0] == 0: return 1 + func(c, 0) else: return func(c, b[0]) print(func(a, 0))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = list(map(int, input().split())) a.insert(0, 3) v = 0 for i in range(1, n + 1): act = a[i] pAct = a[i - 1] if act == 3: if pAct == 1: a[i] = 2 elif pAct == 2: a[i] = 1 elif act == 1: if pAct == 1: a[i] = 0 v += 1 elif act == 2: if pAct == 2: a[i] = 0 v += 1 else: v += 1 print(v)
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
inf = 1061109567 dp = [] for i in range(105): dp.append([inf, inf, inf]) n = int(input()) dp[0][0] = 0 i = 0 for x in input().split(" "): i += 1 x = int(x) dp[i][0] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1 if x == 1 or x == 3: dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) if x == 2 or x == 3: dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) print(min(dp[n][0], dp[n][1], dp[n][2]))
ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
N = int(input()) days = input().split() impossible = None bad_days = 0 x = 0 while x < N: i = days[x] if i == "1": if impossible != "1": impossible = "1" else: bad_days += 1 impossible = None elif i == "2": if impossible != "2": impossible = "2" else: bad_days += 1 impossible = None elif i == "0": bad_days += 1 impossible = None elif impossible == "1": impossible = "2" elif impossible == "2": impossible = "1" else: j = N - 1 for j in range(x + 1, N): if days[j] != "3": if days[j] == "0": x = j - 1 break elif days[j] == "1": impossible = "1" x = j break elif days[j] == "2": impossible = "2" x = j break if j == N - 1 and days[j] == 3: x = j x = x + 1 print(bad_days)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR STRING VAR NUMBER ASSIGN VAR NONE IF VAR STRING IF VAR STRING ASSIGN VAR STRING VAR NUMBER ASSIGN VAR NONE IF VAR STRING VAR NUMBER ASSIGN VAR NONE IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
I = input n = int(I()) b = [(0, 0)] for i in map(int, I().split()): if i == 0: b += [(max(b[-1]), max(b[-1]))] if i == 1: b += [(max(b[-1]), b[-1][0] + 1)] if i == 2: b += [(b[-1][1] + 1, max(b[-1]))] if i == 3: b += [(b[-1][1] + 1, b[-1][0] + 1)] print(n - max(b[-1]))
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR LIST FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR LIST BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR LIST BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
nDays = int(input()) sqc = input().split() inf = 1000000 dp = [[(0) for x in range(3)] for x in range(nDays + 1)] dp[0][0] = 0 dp[0][1] = 0 dp[0][2] = 0 for i in range(nDays + 1): if i == 0: continue dp[i][0] = 1 + min(dp[i - 1][0], min(dp[i - 1][1], dp[i - 1][2])) dp[i][1] = ( min(dp[i - 1][0], dp[i - 1][2]) if sqc[i - 1] == "1" or sqc[i - 1] == "3" else inf ) dp[i][2] = ( min(dp[i - 1][0], dp[i - 1][1]) if sqc[i - 1] == "2" or sqc[i - 1] == "3" else inf ) print(min(dp[nDays][0], min(dp[nDays][1], dp[nDays][2])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def cbefore(pos): if cbeforememo[pos] > -1: return cbeforememo[pos] if pos == len(a) - 1: if a[pos] == 0 or a[pos] == 1: cbeforememo[pos] == 1 return 1 else: cbeforememo[pos] == 0 return 0 elif a[pos] == 0 or a[pos] == 1: ans = nbefore(pos + 1) cbeforememo[pos] = 1 + ans return 1 + ans else: ans = sbefore(pos + 1) cbeforememo[pos] = ans return ans def sbefore(pos): if sbeforememo[pos] > -1: return sbeforememo[pos] if pos == len(a) - 1: if a[pos] == 0 or a[pos] == 2: sbeforememo[pos] == 1 return 1 else: sbeforememo[pos] == 0 return 0 elif a[pos] == 0 or a[pos] == 2: ans = nbefore(pos + 1) sbeforememo[pos] = 1 + ans return 1 + ans else: ans = cbefore(pos + 1) sbeforememo[pos] = ans return ans def nbefore(pos): if nbeforememo[pos] > -1: return nbeforememo[pos] if pos == len(a) - 1: if a[pos] == 0: nbeforememo[pos] = 1 return 1 else: nbeforememo[pos] = 0 return 0 elif a[pos] == 0: ans = nbefore(pos + 1) nbeforememo[pos] = 1 + ans return 1 + ans elif a[pos] == 1: ans = cbefore(pos + 1) nbeforememo[pos] = ans return ans elif a[pos] == 2: ans = sbefore(pos + 1) nbeforememo[pos] = ans return ans else: ans1 = cbefore(pos + 1) ans2 = sbefore(pos + 1) nbeforememo[pos] = min(ans1, ans2) return min(ans1, ans2) n = int(input()) a = [int(x) for x in input().split()] cbeforememo = [(-1) for i in range(n)] sbeforememo = [(-1) for i in range(n)] nbeforememo = [(-1) for i in range(n)] print(nbefore(0))
FUNC_DEF IF VAR VAR NUMBER RETURN VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR VAR VAR NUMBER RETURN NUMBER EXPR VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR RETURN BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR VAR VAR NUMBER RETURN NUMBER EXPR VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR RETURN BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR RETURN BIN_OP NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR 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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) arr = list(map(int, input().rstrip().split())) rest = 0 past = 0 i = 0 for i in range(len(arr)): if arr[i] == 0 or arr[i] == past: rest += 1 past = 0 elif arr[i] == 3: if past != 0: past = 3 - past else: past = arr[i] print(rest)
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) s = list(map(int, input().split())) s1 = 0 r = 0 for i in range(n): if s[i] == 0: r += 1 s1 = 0 elif s[i] == 1: if s1 == 1: r += 1 s1 = 0 else: s1 = 1 elif s[i] == 2: if s1 == 2: r += 1 s1 = 0 else: s1 = 2 elif s1 == 1: s1 = 2 elif s1 == 2: s1 = 1 elif i != n - 1 and s[i] == 1: s1 = 2 elif i != n - 1 and s[i] == 2: s1 = 1 print(r)
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 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 ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) days = [0] + [int(c) for c in input().split()] dp = [([float("infinity")] * 3) for _ in range(n + 1)] dp[0] = [0] * 3 for i in range(1, n + 1): cur = days[i] dp[i][0] = 1 + min(dp[i - 1]) if cur == 2 or cur == 3: dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) if cur == 1 or cur == 3: dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) print(min(dp[n]))
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 FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
user = int(input()) n = list(input().split(" ")) l = len(n) - 1 r = 0 a = 0 c = 0 res = [] for i in n: if int(i) == 0: r = r + 1 a = 0 c = c + 1 if int(i) == 1: if a == 0 or a != 2: a = 2 c = c + 1 else: r = r + 1 a = 0 c = c + 1 if int(i) == 2: if a == 0 or a != 1: a = 1 c = c + 1 else: r = r + 1 a = 0 c = c + 1 if int(i) == 3: if a == 0: while c < len(n) and n[c] == 3: c = c + 1 if c < len(n): if n[c] == 1: a = 2 elif n[c] == 2: a = 1 elif a != 1: a = 1 elif a != 2: a = 2 print(r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = list(map(int, input().split())) cnt = 0 x = 0 for i in range(n): if a[i] != 3: x = i break for i in range(x, n): if a[i] == 0: cnt += 1 if i > 0 and a[i] == 2 and a[i - 1] == 2: a[i] = 0 cnt += 1 if i > 0 and a[i] == 1 and a[i - 1] == 1: a[i] = 0 cnt += 1 if a[i] == 3 and a[i - 1] == 1: a[i] = 2 if a[i] == 3 and a[i - 1] == 2: a[i] = 1 print(cnt)
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 FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER 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 NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) num = map(int, input().split()) rest = sport = contest = 0 for i in num: if i == 3: contest, sport, rest = ( max(contest, rest + 1, sport + 1), max(sport, contest + 1, rest + 1), max(rest, contest, sport), ) elif i == 1: contest, rest = max(contest, rest + 1, sport + 1), max(rest, contest, sport) elif i == 2: sport, rest = max(sport, contest + 1, rest + 1), max(rest, contest, sport) else: rest = max(rest, contest, sport) print(n - max(rest, contest, sport))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) arr = list(map(lambda x: int(x), input().split(" "))) dp = [([None] * n) for _ in range(3)] first = arr[0] dp[0][0] = 0 if first == 1: dp[1][0] = 1 if first == 2: dp[2][0] = 1 if first == 3: dp[1][0] = 1 dp[2][0] = 1 for c in range(1, n): val = arr[c] cand = [dp[0][c - 1], dp[1][c - 1], dp[2][c - 1]] cand = list(filter(lambda x: x != None, cand)) dp[0][c] = max(cand) if val == 1 or val == 3: cand = [dp[0][c - 1], dp[2][c - 1]] cand = list(filter(lambda x: x != None, cand)) dp[1][c] = 1 + max(cand) if val == 2 or val == 3: cand = [dp[0][c - 1], dp[1][c - 1]] cand = list(filter(lambda x: x != None, cand)) dp[2][c] = 1 + max(cand) cand = [dp[0][-1], dp[1][-1], dp[2][-1]] print(n - max(filter(lambda x: x != None, cand)))
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 STRING ASSIGN VAR BIN_OP LIST NONE VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NONE VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NONE VAR ASSIGN VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NONE VAR ASSIGN VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR NONE 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) li = input().split() count = 0 for i in range(0, n): if li[i] == "3": if i == 0 and i + 1 < n: if li[i + 1] == "1" or li[i + 1] == "2": li[i] = str(int(li[i + 1]) ^ 3) elif i == n - 1 and i > 0: if li[i - 1] == "1" or li[i - 1] == "2": li[i] = str(int(li[i - 1]) ^ 3) elif i > 0 and i + 1 < n: if li[i - 1] == "1" and li[i + 1] == "2": li[i] = "2" li[i + 1] = "0" elif li[i - 1] == "2" and li[i + 1] == "1": li[i] = "1" li[i + 1] = "0" elif li[i - 1] == "1" and li[i + 1] == "3": li[i] = "2" elif li[i - 1] == "2" and li[i + 1] == "3": li[i] = "1" elif li[i - 1] == "3" and li[i + 1] == "1": li[i] = "2" elif li[i - 1] == "3" and li[i + 1] == "2": li[i] = "1" elif li[i - 1] == "1" and li[i + 1] == "1": li[i] = "2" elif li[i - 1] == "2" and li[i + 1] == "2": li[i] = "1" elif li[i - 1] == "2" and li[i + 1] == "0": li[i] = "1" elif li[i - 1] == "0" and li[i + 1] == "2": li[i] = "1" elif li[i - 1] == "0" and li[i + 1] == "1": li[i] = "2" elif li[i - 1] == "1" and li[i + 1] == "0": li[i] = "2" elif li[i] == "1" or li[i] == "2": if i + 1 < n and li[i] == li[i + 1]: li[i + 1] = "0" i += 1 for i in range(n - 1, -1): if li[i] == "3": if i == 0 and i + 1 < n: if li[i + 1] == "1" or li[i + 1] == "2": li[i] = str(int(li[i + 1]) ^ 3) elif i == n - 1 and i > 0: if li[i - 1] == "1" or li[i - 1] == "2": li[i] = str(int(li[i - 1]) ^ 3) elif i > 0 and i + 1 < n: if li[i - 1] == "1" and li[i + 1] == "2": li[i] = "1" li[i - 1] = "0" elif li[i - 1] == "2" and li[i + 1] == "1": li[i] = "2" li[i - 1] = "0" elif li[i - 1] == "1" and li[i + 1] == "3": li[i] = "2" elif li[i - 1] == "2" and li[i + 1] == "3": li[i] = "1" elif li[i - 1] == "3" and li[i + 1] == "1": li[i] = "2" elif li[i - 1] == "3" and li[i + 1] == "2": li[i] = "1" elif li[i - 1] == "1" and li[i + 1] == "1": li[i] = "2" elif li[i - 1] == "2" and li[i + 1] == "2": li[i] = "1" elif li[i - 1] == "2" and li[i + 1] == "0": li[i] = "1" elif li[i - 1] == "0" and li[i + 1] == "2": li[i] = "1" elif li[i - 1] == "0" and li[i + 1] == "1": li[i] = "2" elif li[i - 1] == "1" and li[i + 1] == "0": li[i] = "2" elif li[i] == "1" or li[i] == "2": if i + 1 < n and li[i] == li[i + 1]: li[i + 1] = "0" i += 1 print(li.count("0"))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING IF VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def max_work_days(days): n = len(days) work = [0] * (n + 1) if days[0] > 0: work[1] = 1 else: work[1] = 0 for i in range(2, n + 1): if days[i - 2] == 3: j = i - 2 while j >= 0 and days[j] == 3: j -= 1 if j < 0: if days[i - 1] > 0: val1 = work[i - 1] + 1 else: val1 = work[i - 1] elif days[j] == 0: if days[i - 1] > 0: val1 = work[i - 1] + 1 else: val1 = work[i - 1] elif days[j] == 1: if work[j + 2] == work[j] + 1: if days[i - 1] > 0: val1 = work[i - 1] + 1 else: val1 = work[i - 1] else: diff = i - 2 - j if diff % 2 == 1: if days[i - 1] == 1 or days[i - 1] == 3: val1 = work[i - 1] + 1 else: val1 = work[i - 1] elif days[i - 1] == 2 or days[i - 1] == 3: val1 = work[i - 1] + 1 else: val1 = work[i - 1] elif days[j] == 2: if work[j + 2] == work[j] + 1: if days[i - 1] > 0: val1 = work[i - 1] + 1 else: val1 = work[i - 1] else: diff = i - 2 - j if diff % 2 == 1: if days[i - 1] == 2 or days[i - 1] == 3: val1 = work[i - 1] + 1 else: val1 = work[i - 1] elif days[i - 1] == 1 or days[i - 1] == 3: val1 = work[i - 1] + 1 else: val1 = work[i - 1] elif days[i - 2] == 2: if days[i - 1] == 1 or days[i - 1] == 3: val1 = work[i - 1] + 1 else: val1 = work[i - 1] elif days[i - 2] == 1: if days[i - 1] == 2 or days[i - 1] == 3: val1 = work[i - 1] + 1 else: val1 = work[i - 1] elif days[i - 1] > 0: val1 = work[i - 1] + 1 else: val1 = work[i - 1] if days[i - 1] > 0: val2 = work[i - 2] + 1 else: val2 = work[i - 2] work[i] = max(val1, val2) return work[n] n = int(input()) days = list(map(int, input().split())) work_days = max_work_days(days) rest_days = n - work_days print(rest_days)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN 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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
from sys import stdin, stdout def INI(): return int(stdin.readline()) def INL(): return [int(_) for _ in stdin.readline().split()] def INS(): return stdin.readline() def MOD(): return pow(10, 9) + 7 def OPS(ans): stdout.write(str(ans) + "\n") def OPL(ans): [stdout.write(str(_) + " ") for _ in ans] stdout.write("\n") n = INI() X = INL() if X[0] == 0: D = ["R"] elif X[0] == 1: D = ["C"] elif X[0] == 2: D = ["G"] else: D = ["inf"] for _ in range(1, n): if X[_] == 0: D.append("R") elif X[_] == 1: if D[-1] == "C": D.append("R") else: D.append("C") elif X[_] == 2: if D[-1] == "G": D.append("R") else: D.append("G") elif D[-1] == "C": D.append("G") elif D[-1] == "G": D.append("C") else: D.append("inf") OPS(D.count("R"))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR LIST STRING IF VAR NUMBER NUMBER ASSIGN VAR LIST STRING IF VAR NUMBER NUMBER ASSIGN VAR LIST STRING ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def minrest(): n = int(input().strip()) a = [int(i) for i in input().strip().split()] r = [[(0) for i in range(n)] for j in range(3)] r[0][-1] = 1 for i in range(1, 3): r[i][-1] = 1 if i & a[-1] == 0 else 0 for i in range(n - 2, -1, -1): r[0][i] = 1 + min(r[1][i + 1], r[2][i + 1]) for j in range(1, 3): r[j][i] = 1 if j & a[i] == 0 else 0 r[j][i] += min(r[(j + 1) % 3][i + 1], r[(j + 2) % 3][i + 1]) print(min(r[0][0], r[1][0], r[2][0])) minrest()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
a = input() z = list(map(int, input().split())) count = 0 if z[0] == 0: count = 1 for i in range(1, len(z)): if z[i] == 0: count = count + 1 elif z[i] == 3: if z[i - 1] == 1: z[i] = 2 elif z[i - 1] == 2: z[i] = 1 elif z[i] == z[i - 1] and z[i] != 3: count = count + 1 z[i] = 0 print(count)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = list(map(int, input().split())) b = c = d = 0 for i in a: e, f, g = b, c, d d = min(e, f, g) + 1 if i == 0: c = 10**5 b = 10**5 if i == 1: c = 10**5 b = min(f, g) if i == 2: b = 10**5 c = min(e, g) if i == 3: b = min(f, g) c = min(e, g) print(min(b, c, d))
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 ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def solve(n, xs): dp = [[None for _ in range(3)] for _ in range(n)] for i, x in enumerate(xs): if i == 0: if x == 0: dp[0][0] = 1 dp[0][1] = float("inf") dp[0][2] = float("inf") if x == 1: dp[0][0] = 1 dp[0][1] = 0 dp[0][2] = float("inf") if x == 2: dp[0][0] = 1 dp[0][1] = float("inf") dp[0][2] = 0 if x == 3: dp[0][0] = 1 dp[0][1] = 0 dp[0][2] = 0 else: if x == 0: dp[i][0] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1 dp[i][1] = float("inf") dp[i][2] = float("inf") if x == 1: dp[i][0] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1 dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) dp[i][2] = float("inf") if x == 2: dp[i][0] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1 dp[i][1] = float("inf") dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) if x == 3: dp[i][0] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1 dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) return min(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]) def main(): n = int(input()) xs = map(int, input().split()) print(solve(n, xs)) main()
FUNC_DEF ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
import sys n = int(sys.stdin.readline()) array = [int(i) for i in sys.stdin.readline().split()] last = 0 rest = 0 for i in array: if i == 0: rest += 1 last = i elif i == 1: if last == 1: rest += 1 last = 0 elif last == 2 or last == 0 or last == 3: last = i elif i == 2: if last == 2: rest += 1 last = 0 elif last == 1 or last == 0 or last == 3: last = i elif last == 1: last = 2 elif last == 2: last = 1 else: last = i print(rest)
IMPORT 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 FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) days = [int(x) for x in input().split()] res = 0 i = 1 currentActivity = days[0] if currentActivity == 0: res += 1 while i < n: if days[i] == 0: res += 1 currentActivity = 0 elif days[i] == 1 or days[i] == 2: if days[i] == currentActivity: res += 1 currentActivity = 0 else: currentActivity = days[i] elif currentActivity != 0: currentActivity = 3 - currentActivity elif i + 1 < n: if days[i + 1] == 1: currentActivity = 2 elif days[i + 1] == 2: currentActivity = 1 elif days[i + 1] == 3: currentActivity = 0 i += 1 print(res)
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 VAR NUMBER IF VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = [int(i) for i in input().split()] dp = [{"r": float("inf"), "g": float("inf"), "c": float("inf")} for _ in range(n)] dp[0]["r"] = 1 if a[0] == 1 or a[0] == 3: dp[0]["c"] = 0 if a[0] == 2 or a[0] == 3: dp[0]["g"] = 0 for i in range(1, n): dp[i]["r"] = 1 + min(dp[i - 1]["r"], dp[i - 1]["g"], dp[i - 1]["c"]) if a[i] == 1 or a[i] == 3: dp[i]["c"] = min(dp[i - 1]["g"], dp[i - 1]["r"]) if a[i] == 2 or a[i] == 3: dp[i]["g"] = min(dp[i - 1]["c"], dp[i - 1]["r"]) print(min(dp[-1].values()))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER STRING NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER STRING NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR STRING BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR STRING FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR STRING FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
x = int(input()) y = list(map(int, input().split())) if y[0] == 0: list = [[0, 0, 0]] elif y[0] == 1: list = [[0, 1, 0]] elif y[0] == 2: list = [[0, 0, 1]] elif y[0] == 3: list = [[0, 1, 1]] for i in range(1, x): if y[i] == 0: list.append( [ max(list[i - 1]), max(list[i - 1][0], list[i - 1][2]), max(list[i - 1][0], list[i - 1][1]), ] ) elif y[i] == 1: list.append( [ max(list[i - 1]), max(list[i - 1][0], list[i - 1][2]) + 1, max(list[i - 1][0], list[i - 1][1]), ] ) elif y[i] == 2: list.append( [ max(list[i - 1]), max(list[i - 1][0], list[i - 1][2]), max(list[i - 1][0], list[i - 1][1]) + 1, ] ) elif y[i] == 3: list.append( [ max(list[i - 1]), max(list[i - 1][0], list[i - 1][2]) + 1, max(list[i - 1][0], list[i - 1][1]) + 1, ] ) print(x - max(list[-1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
q = int(input()) w = list(map(int, input().split())) e = 0 if w[0] == 0: e += 1 for i in range(1, q): if w[i] == 0: e += 1 if w[i - 1] == 1 and w[i] == 3: w[i] = 2 elif w[i - 1] == 2 and w[i] == 3: w[i] = 1 elif w[i - 1] == 1 and w[i] == 1 or w[i - 1] == 2 and w[i] == 2: w[i] = 0 e += 1 print(e)
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 IF VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) l = list(map(int, input().split())) ans = 0 l.append(9) l.insert(0, 9) i = 1 while i < n: a = l[i] b = l[i + 1] if a == 0: ans = ans + 1 i = i + 1 elif a == 1 and b == 1 or a == 2 and b == 2: ans = ans + 1 l[i + 1] = 9 i = i + 2 elif a == 3: pre = l[i - 1] j = i c = 0 while j < n and l[j] == 3: c = c + 1 j = j + 1 nex = l[j] if c % 2 == 0: if pre == nex == 1 or pre == nex == 2: l[j] = 9 ans = ans + 1 i = j + 1 else: i = j elif pre == 1 and nex == 2 or pre == 2 and nex == 1: l[j] = 9 ans = ans + 1 i = j + 1 else: i = j else: i = i + 1 if l[n] == 0: ans = ans + 1 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 EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) l = list(map(int, input().split())) for i in range(1, n): if l[i] == 0: l[i] = 0 elif l[i - 1] == 0: pass elif l[i] == 1 and (l[i - 1] == 31 or l[i - 1] == 1): l[i] = 0 elif l[i] == 2 and (l[i - 1] == 32 or l[i - 1] == 2): l[i] = 0 elif l[i] == 3 and (l[i - 1] == 31 or l[i - 1] == 1): l[i] = 32 elif l[i] == 3 and (l[i - 1] == 32 or l[i - 1] == 2): l[i] = 31 else: pass print(l.count(0))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = input().split(" ") a = [int(a[i]) for i in range(len(a))] b = [(0) for i in range(n)] c = 0 g = 0 gc = 0 f = 0 for i in range(n): if a[i] == 0: g = 0 c = 0 b[i] = "f" elif a[i] == 1: g = 0 if i > 0 and b[i - 1] == "c": b[i] = "f" c = 0 elif c % 2 == 0: b[i] = "c" c += 1 else: b[i] = "f" c += 1 elif a[i] == 3: g = 0 c = 0 if i > 0: if b[i - 1] == "c": b[i] = "g" elif b[i - 1] == "g": b[i] = "c" else: b[i] = "gc" else: b[i] = "gc" elif a[i] == 2: c = 0 if i > 0 and b[i - 1] == "g": b[i] = "f" g = 0 elif g % 2 == 0: g += 1 b[i] = "g" else: b[i] = "f" g += 1 print(b.count("f"))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def qtd_dias_descanso(dias): qtd_dias = 0 ontem = 0 for dia in dias: if dia == ontem or dia == 0: qtd_dias += 1 ontem = 0 elif dia == 1 or dia == 2: ontem = dia elif dia == 3 and ontem > 0: ontem = 3 - ontem return qtd_dias n = int(input()) a = [int(i) for i in input().split()] print(qtd_dias_descanso(a))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) days = list(map(int, input().split())) dp = [[999, 999, 999] for x in range(100)] dp[0][0] = 1 if days[0] == 1: dp[0][1] = 0 elif days[0] == 2: dp[0][2] = 0 elif days[0] == 3: dp[0][1] = 0 dp[0][2] = 0 for i in range(1, n): dp[i][0] = 1 + min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) if days[i] == 1: dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) elif days[i] == 2: dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) elif days[i] == 3: dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) print(min(dp[n - 1][0], dp[n - 1][1], dp[n - 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 NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) l = list(map(int, input().split())) p = 0 k = 0 for i in range(n): c = 1 if l[i] == 1 and p == 1: k = k + 1 p = 0 c = 0 if l[i] == 2 and p == 2: k = k + 1 p = 0 c = 0 if l[i] == 3 and p == 1: p = 2 c = 0 elif l[i] == 3 and p == 2: p = 1 c = 0 if l[i] == 0: c = 0 k = k + 1 p = 0 if c == 1: p = l[i] print(k)
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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
N = int(input()) A = list(map(int, input().split())) bef = 0 ans = 0 for a in A: if bef == 0: if a == 0: pass elif a == 1: ans += 1 bef = 1 elif a == 2: ans += 1 bef = 2 elif a == 3: ans += 1 bef = 3 elif bef == 1: if a == 0: bef = 0 elif a == 1: bef = 0 elif a == 2: ans += 1 bef = 2 elif a == 3: ans += 1 bef = 2 elif bef == 2: if a == 0: bef = 0 elif a == 1: ans += 1 bef = 1 elif a == 2: bef = 0 elif a == 3: ans += 1 bef = 1 elif bef == 3: if a == 0: bef = 0 elif a == 1: ans += 1 bef = 1 elif a == 2: ans += 1 bef = 2 elif a == 3: ans += 1 bef = 3 print(N - 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 NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER 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 VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
x = int(input()) m = list(map(int, input().split())) a = [([-1791791791] * 4) for i in range(x)] a[0][0] = 0 if m[0] & 1: a[0][1] = 1 if m[0] & 2: a[0][2] = 1 for i in range(1, x): a[i][0] = max(a[i - 1]) for j in range(1, 3): if m[i] & j: a[i][j] = max(a[i - 1][:j] + a[i - 1][j + 1 :]) + 1 maxx = max(a[-1]) print(x - maxx)
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 NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) dp = [[(0) for i in range(3)] for j in range(n)] dp[0][0] = 0 if a[0] == 1 or a[0] == 3: dp[0][1] = 1 if a[0] == 2 or a[0] == 3: dp[0][2] = 1 for i in range(1, n): dp[i][0] = max(dp[i - 1]) if a[i] == 1 or a[i] == 3: dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + 1 if a[i] == 2 or a[i] == 3: dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + 1 m = 0 for i in dp: m = max(m, max(i)) print(n - m)
IMPORT 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 NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
input() A = map(int, input().split(" ")) tfo = 0 r = 0 for a in A: if a == 3: tfo = -tfo % 3 elif a == 0: r += 1 tfo = 0 elif tfo == a: r += 1 tfo = 0 else: tfo = a print(r)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
N = int(input()) days = list(map(int, input().split())) dp = [] prev = [[0, 1, 2], [0, 2], [0, 1]] for i in range(N): d = days[i] row = [] for j in range(3): if j == 1: if d != 1 and d != 3: row.append("x") continue if j == 2: if d != 2 and d != 3: row.append("x") continue min_prev = 105 prev_row = [0, 0, 0] if i > 0: prev_row = dp[i - 1] for k in prev[j]: if prev_row[k] == "x": continue min_prev = min(min_prev, prev_row[k]) if j == 0: min_prev += 1 row.append(min_prev) dp.append(row) ans = 105 for c in dp[-1]: if c == "x": continue ans = min(ans, c) 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 LIST ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) info = list(map(int, input().split())) matrix = [[(False) for i in range(len(info))] for j in range(3)] def minRestDays(today, yActivity): if today == len(info): answer = 0 elif info[today] == 0: answer = 1 + minRestDays(today + 1, 0) elif info[today] == 1: if yActivity == 1: answer = 1 + minRestDays(today + 1, 0) else: answer = minRestDays(today + 1, 1) elif info[today] == 2: if yActivity == 2: answer = 1 + minRestDays(today + 1, 0) else: answer = minRestDays(today + 1, 2) elif yActivity == 2: answer = minRestDays(today + 1, 1) elif yActivity == 1: answer = minRestDays(today + 1, 2) else: if not matrix[1][today]: matrix[1][today] = minRestDays(today + 1, 1) if not matrix[2][today]: matrix[2][today] = minRestDays(today + 1, 2) answer = min(matrix[1][today], matrix[2][today]) return answer print(minRestDays(0, 0))
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 FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = [int(x) for x in input().split()] l = 0 cnt = 0 a.append(0) for i in range(n): if a[i] == 0: l = 0 cnt += 1 continue if l == 0: if a[i] == 3: l = 0 else: l = a[i] elif a[i] == 3: if l == 1: l = 2 else: l = 1 elif a[i] == l: cnt += 1 l = 0 else: l = a[i] print(cnt)
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 EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
y = int(input()) al = input().split() m = list(map(int, al)) l = 0 z = 0 m.append(0) for i in range(y): if m[i] == 0: z += 1 l = 0 continue if l == 0: if m[i] == m[i + 1] and (m[i] == 1 or m[i] == 2): m[i + 1] = 0 continue elif m[i] == 3 and m[i] == m[i + 1]: l = 3 continue elif m[i] == 3: l = 3 - m[i + 1] continue l = m[i] elif m[i] == l and m[i] != 3: z += 1 l = 0 elif l == 3: if m[i + 1] == 2: l = 1 elif m[i + 1] == 1: l = 2 elif m[i] == 3 or m[i] != l: l = 3 - l print(z)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def solve(n, a): dp = [[0, 0]] for i in range(n): if a[i] == 0: dp.append([min(*dp[i]) + 1] * 2) elif a[i] == 1: dp.append([dp[i][1], min(*dp[i]) + 1]) elif a[i] == 2: dp.append([min(*dp[i]) + 1, dp[i][0]]) elif a[i] == 3: dp.append([dp[i][1], dp[i][0]]) return min(*dp[n]) n = int(input()) a = list(map(int, input().split())) print(solve(n, a))
FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR 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 FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) l = list(map(int, input().split())) gym = -1 contest = -1 rest = 0 if l[0] == 0: rest += 1 elif l[0] == 1: contest = 0 elif l[0] == 2: gym = 0 elif n > 1: if l[1] == 2: contest = 0 elif l[1] == 1: gym = 0 else: contest = 0 for i in range(1, n): if l[i] == 0: rest += 1 elif l[i] == 1: if contest == i - 1: rest += 1 else: contest = i elif l[i] == 2: if gym == i - 1: rest += 1 else: gym = i elif contest == i - 1: gym = i elif gym == i - 1: contest = i rest1 = 0 if l[0] == 0: rest1 += 1 elif l[0] == 1: contest = 0 elif l[0] == 2: gym = 0 elif n > 1: if l[1] == 2: contest = 0 elif l[1] == 1: gym = 0 else: gym = 0 for i in range(1, n): if l[i] == 0: rest1 += 1 elif l[i] == 1: if contest == i - 1: rest1 += 1 else: contest = i elif l[i] == 2: if gym == i - 1: rest1 += 1 else: gym = i elif contest == i - 1: gym = i elif gym == i - 1: contest = i print(min(rest, rest1))
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 IF VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) days = list(map(int, input().split())) res, prev = 0, 3 for d in days: if prev != 3: if d == prev: d = 0 elif d == 3: d -= prev if d == 0: res += 1 prev = d print(res)
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 NUMBER NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR IF VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def find_rest_days(n, days): dp = [([None] * 3) for _ in range(n)] dp[0][0] = 1, 0 dp[0][1] = (0, 1) if 1 & days[0] else (1, 0) dp[0][2] = (0, 2) if 2 & days[0] else (1, 0) for i in range(1, n): prev_best = sorted(dp[i - 1], key=lambda x: x[0]) dp[i][0] = prev_best[0][0] + 1, 0 if days[i] & 1: best_allowed = list(filter(lambda x: x[1] != 1, prev_best)) dp[i][1] = best_allowed[0][0], 1 else: dp[i][1] = dp[i][0] if days[i] & 2: best_allowed = list(filter(lambda x: x[1] != 2, prev_best)) dp[i][2] = best_allowed[0][0], 2 else: dp[i][2] = dp[i][0] return min(dp[n - 1], key=lambda x: x[0]) n = int(input()) days = list(map(int, input().split())) ans = find_rest_days(n, days) print(ans[0])
FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP NUMBER VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP NUMBER VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) s = input() A = [] Sum = 0 F = 0 for i in s.split(): A.append(int(i)) for j in range(0, n): if A[j] == 0: Sum = Sum + 1 F = 0 elif A[j] == 1: if F == 0: F = 1 elif F == 1: Sum = Sum + 1 F = 0 elif F == 2: F = 1 elif A[j] == 2: if F == 0: F = 2 elif F == 1: F = 2 elif F == 2: Sum = Sum + 1 F = 0 elif A[j] == 3: if F == 0: F = 0 elif F == 1: F = 2 elif F == 2: F = 1 print(Sum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def value(action): return 1 if action == "C" or action == "G" else 0 def dp(day, action): if solutions[day, action] != None: return solutions[day, action] choices = possible[day] if action not in choices: return float("-inf") elif day == 0: return value(action) else: if action == "R": answers = [dp(day - 1, c) for c in {"C", "R", "G"}] else: answers = [dp(day - 1, c) for c in {"C", "R", "G"} - set(action)] solutions[day, action] = max(answers) + value(action) return max(answers) + value(action) n = int(input()) days = [int(x) for x in input().split()] possible = [] for d in days: cur_day = {"R"} if d % 2 == 1: cur_day.add("C") if d >= 2: cur_day.add("G") possible.append(cur_day) solutions = dict() for a in range(n): for b in {"C", "R", "G"}: solutions[a, b] = None k = dp(n - 1, "R"), dp(n - 1, "C"), dp(n - 1, "G") print(n - max(k))
FUNC_DEF RETURN VAR STRING VAR STRING NUMBER NUMBER FUNC_DEF IF VAR VAR VAR NONE RETURN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR STRING IF VAR NUMBER RETURN FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR STRING STRING STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP STRING STRING STRING FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR 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 VAR ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR STRING STRING STRING ASSIGN VAR VAR VAR NONE ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def read_line(): return input().strip() def read_int(): return int(read_line()) def read_int_array(): return [int(i) for i in read_line().split(" ")] def read_string_array(): return [i for i in read_line().split(" ")] T = read_int() D = read_int_array() AD = [-1] * len(D) AD[0] = D[0] rests = 1 if AD[0] == 0 else 0 for i in range(1, len(D)): if D[i] == 0: rests += 1 AD[i] = 0 elif D[i] == 1: if AD[i - 1] == 1: rests += 1 AD[i] = 0 else: AD[i] = 1 elif D[i] == 2: if AD[i - 1] == 2: rests += 1 AD[i] = 0 else: AD[i] = 2 elif D[i] == 3: if AD[i - 1] == 3: AD[i] = 3 else: AD[i] = D[i] - AD[i - 1] print(rests)
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) memo = [[0, 0, 0] for _ in range(n)] row1 = [] row2 = [] for c in map(int, input().split()): if c == 0: row1.append(0) row2.append(0) elif c == 1: row1.append(0) row2.append(1) elif c == 2: row1.append(1) row2.append(0) elif c == 3: row1.append(1) row2.append(1) memo[0] = [0, row1[0], row2[0]] for i in range(1, n): memo[i][0] = max(memo[i - 1]) memo[i][1] = row1[i] + max(memo[i - 1][0], memo[i - 1][2]) memo[i][2] = row2[i] + max(memo[i - 1][0], memo[i - 1][1]) print(n - max(memo[-1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER LIST NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def rest_day(arr): mem = [[float("INF") for i in range(3)] for j in range(len(arr))] mem[0][0] = 1 if arr[0] == 1 or arr[0] == 3: mem[0][1] = 0 if arr[0] == 2 or arr[0] == 3: mem[0][2] = 0 for i in range(1, len(arr)): mem[i][0] = 1 + min(mem[i - 1][0], mem[i - 1][1], mem[i - 1][2]) if arr[i] == 1 or arr[i] == 3: mem[i][1] = min(mem[i - 1][0], mem[i - 1][2]) if arr[i] == 2 or arr[i] == 3: mem[i][2] = min(mem[i - 1][0], mem[i - 1][1]) return min(mem[-1][0], mem[-1][1], mem[-1][2]) t = int(input()) arr = [] arr = list(map(int, input().split(" ")[:t])) print(rest_day(arr))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = [int(x) for x in input().split()] cur = 0 ans = 0 for i in a: if i == 0: cur = 0 ans += 1 elif i == 1: if cur == 0 or cur == 1: cur = 2 else: cur = 0 ans += 1 elif i == 2: if cur == 0 or cur == 2: cur = 1 else: cur = 0 ans += 1 elif i == 3: cur = [0, 2, 1][cur] print(ans)
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 FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def solution(x, a, b): n = len(a) dp = [([0] * 3) for i in range(n)] dp[0][0] = 1 dp[0][1] = 0 dp[0][2] = 0 if a[0] == 0: dp[0][1] = -1 if b[0] == 0: dp[0][2] = -1 for i in range(1, n): dp[i][0] = dp[i - 1][0] + 1 dp[i][1] = dp[i - 1][0] dp[i][2] = dp[i - 1][0] if dp[i - 1][1] != -1: dp[i][0] = min(dp[i][0], dp[i - 1][1] + 1) dp[i][2] = min(dp[i][2], dp[i - 1][1]) if dp[i - 1][2] != -1: dp[i][0] = min(dp[i][0], dp[i - 1][2] + 1) dp[i][1] = min(dp[i][1], dp[i - 1][2]) if a[i] == 0: dp[i][1] = -1 if b[i] == 0: dp[i][2] = -1 min_days = dp[-1][0] if dp[-1][1] != -1: min_days = min(min_days, dp[-1][1]) if dp[-1][2] != -1: min_days = min(min_days, dp[-1][2]) return min_days * x n = int(input()) c = list(map(int, input().split())) a = [0] * n b = [0] * n for i in range(n): if c[i] == 1: a[i] = 1 if c[i] == 2: b[i] = 1 if c[i] == 3: a[i] = 1 b[i] = 1 print(solution(1, a, b))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER RETURN BIN_OP 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = list(map(int, input().split())) r = 0 last = 0 for i in a: if last == 0: if i == 3: last = 0 elif i == 0: r += 1 else: last = i elif last == i == 1 or last == i == 2: r += 1 last = 0 elif last == 1 or last == 2: if i == 3: last = 3 - last elif i == 3 - last: last = i elif i == 0: r += 1 last = 0 print(r)
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 NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = list(map(int, input().split())) dp = [([0] * 3) for _ in range(n)] if a[0] == 1 or a[0] == 3: dp[0][1] = 1 if a[0] == 2 or a[0] == 3: dp[0][2] = 1 for i in range(1, n): t = max(dp[i - 1]) contest = max(dp[i - 1][0], dp[i - 1][2]) gym = max(dp[i - 1][0], dp[i - 1][1]) if a[i] == 0: dp[i] = [t, t, t] elif a[i] == 1: dp[i] = [t, contest + 1, t] elif a[i] == 2: dp[i] = [t, t, gym + 1] elif a[i] == 3: dp[i] = [t, contest + 1, gym + 1] print(n - max(dp[n - 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 VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR LIST VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR LIST VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) days = [int(x) for x in input().split(" ")] total_rest = 1 if days[0] == 0 else 0 for i in range(1, len(days)): if days[i] == 0: total_rest += 1 elif days[i - 1] == days[i] and days[i] != 3: total_rest += 1 days[i] = 0 elif days[i] == 3: if days[i - 1] == 1: days[i] = 2 elif days[i - 1] == 2: days[i] = 1 print(total_rest)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) arr = list(map(int, input().split())) dp = [[0, 0, 0] for _ in range(len(arr) + 1)] for i, v in enumerate(arr): dp[i + 1][0] = max(dp[i]) if v == 1 or v == 3: dp[i + 1][1] = max(dp[i][0] + 1, dp[i][2] + 1) else: dp[i + 1][1] = dp[i][1] if v == 2 or v == 3: dp[i + 1][2] = max(dp[i][0] + 1, dp[i][1] + 1) else: dp[i + 1][2] = dp[i][2] print(n - max(dp[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 LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
import sys input = sys.stdin.readline def inp(): return int(input()) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) n = inp() s = list(invr()) d = [[(0) for _ in range(3)] for _ in range(n)] d[0][0] = 0 if s[0] == 1 or s[0] == 3: d[0][1] = 1 if s[0] == 2 or s[0] == 3: d[0][2] = 1 for i in range(1, n): d[i][0] = max(d[i - 1][0], d[i - 1][1], d[i - 1][2]) if s[i] == 1 or s[i] == 3: d[i][1] = max(d[i - 1][0] + 1, d[i - 1][2] + 1) if s[i] == 2 or s[i] == 3: d[i][2] = max(d[i - 1][0] + 1, d[i - 1][1] + 1) print(n - max(d[n - 1][0], d[n - 1][1], d[n - 1][2]))
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) l_n = list(map(int, input().split())) p = l_n[0] t = 1 if p == 0 else 0 for i in range(1, n): if l_n[i] == p and p != 3: l_n[i] = 0 elif l_n[i] == 3 and p != 3: l_n[i] -= p if l_n[i] == 0: t += 1 p = l_n[i] print(t)
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 NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
import sys n = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) prev, ans = 0, 0 for i in range(n): if A[i] == 0: ans += 1 prev = 0 elif A[i] == 1 or A[i] == 2: if prev == A[i]: ans += 1 prev = 0 else: prev = A[i] elif prev == 0: if i < n - 1: if A[i + 1] == 1 or A[i + 1] == 2: prev = 3 - A[i + 1] else: prev = 3 - prev print(ans)
IMPORT 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 NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def rev(a): if a == 1: return 2 return 1 def solve(n, s): prev = 0 for i in range(n): if s[i] == 3 and prev == 0: k = 0 for j in range(i, n): k = j - 1 if s[j] != 3: break for j in range(k, i - 1, -1): s[j] = rev(s[j + 1]) elif i != 0: if s[i] == 3: s[i] = rev(s[i - 1]) elif s[i] == 0: s[i] = 0 elif s[i] == s[i - 1]: s[i] = 0 prev = s[i] return s.count(0) n = int(input()) li = list(map(int, input().split())) print(solve(n, li))
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN FUNC_CALL VAR NUMBER 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 FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def Vacation(n, arr): rest = 0 gym = False con = False for i in range(n): if arr[i] == 0: rest += 1 con = False gym = False elif arr[i] == 1: if not con: con = True gym = False else: rest += 1 con = False gym = False elif arr[i] == 2: if not gym: gym = True con = False else: rest += 1 con = False gym = False else: if i > 0 and arr[i - 1] == 0: con = False gym = False if con: con = False gym = True elif gym: con = True gym = False print(rest) n = int(input()) arr = list(map(int, input().split())) Vacation(n, arr)
FUNC_DEF 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR 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 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) s = list(map(int, input().split())) days = [] relax = 0 for i in range(len(s)): if s[i] == 0: relax += 1 days.append(0) elif len(days) == 0: days.append(s[i]) elif s[i] == 2 and days[i - 1] == 2: days.append(0) relax += 1 elif s[i] == 1 and days[i - 1] == 1: days.append(0) relax += 1 elif s[i] == 3: if days[i - 1] == 2: days.append(1) elif days[i - 1] == 1: days.append(2) else: days.append(s[i]) else: days.append(s[i]) print(relax)
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
vac = int(input()) days = [int(i) for i in str(input()).split(" ")] ans = [[(0) for i in range(3)] for _ in range(102)] for index in range(len(days) + 1): if index == 0: continue elif days[index - 1] == 0: ans[index][0] = min(ans[index - 1]) + 1 ans[index][1] = ans[index - 1][1] + 1 ans[index][2] = ans[index - 1][2] + 1 elif days[index - 1] == 1: ans[index][0] = min(ans[index - 1]) + 1 ans[index][1] = min(ans[index - 1][0], ans[index - 1][2]) ans[index][2] = ans[index - 1][2] + 1 elif days[index - 1] == 2: ans[index][0] = min(ans[index - 1]) + 1 ans[index][1] = ans[index - 1][1] + 1 ans[index][2] = min(ans[index - 1][0], ans[index - 1][1]) elif days[index - 1] == 3: ans[index][0] = min(ans[index - 1]) + 1 ans[index][2] = min(ans[index - 1][0], ans[index - 1][1]) ans[index][1] = min(ans[index - 1][0], ans[index - 1][2]) print(min(ans[len(days)]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) ls = list(map(int, input().split())) ary = [[0, 0, 0] for j in range(n + 1)] for i in range(1, n + 1): ma = max(ary[i - 1]) ary[i][0] = ma ary[i][1] = max(ary[i - 1][0], ary[i - 1][2]) + (ls[i - 1] == 1 or ls[i - 1] == 3) ary[i][2] = max(ary[i - 1][0], ary[i - 1][1]) + (ls[i - 1] == 2 or ls[i - 1] == 3) print(n - max(ary[-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 NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) arr = [] p = list(map(int, input().split())) for i in range(n): arr.append([10000, 10000, 10000, p[i]]) arr[0][0] = 1 if arr[0][3] == 1 or arr[0][3] == 3: arr[0][1] = 0 if arr[0][3] == 2 or arr[0][3] == 3: arr[0][2] = 0 for i in range(1, n): arr[i][0] = 1 + min(arr[i - 1][0], arr[i - 1][1], arr[i - 1][2]) if arr[i][3] == 1 or arr[i][3] == 3: arr[i][1] = min(arr[i - 1][0], arr[i - 1][2]) if arr[i][3] == 2 or arr[i][3] == 3: arr[i][2] = min(arr[i - 1][0], arr[i - 1][1]) least = 10000 for i in range(0, 3): least = min(least, arr[n - 1][i]) print(least)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def val(a, action): res = 1000 if a == 3: res = 0 elif a == 1 and action == "C": res = 0 elif a == 2 and action == "G": res = 0 return res n = int(input()) a = list(map(int, input().split())) curr = {} prev = {"G": 0, "C": 0, "R": 0} for i in a: curr["G"] = min(prev["C"], prev["R"]) + val(i, "G") curr["C"] = min(prev["G"], prev["R"]) + val(i, "C") curr["R"] = min(prev["C"], prev["G"], prev["R"]) + 1 prev = curr.copy() print(min(prev.values()))
FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER RETURN 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 DICT ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR STRING BIN_OP FUNC_CALL VAR VAR STRING VAR STRING FUNC_CALL VAR VAR STRING ASSIGN VAR STRING BIN_OP FUNC_CALL VAR VAR STRING VAR STRING FUNC_CALL VAR VAR STRING ASSIGN VAR STRING BIN_OP FUNC_CALL VAR VAR STRING VAR STRING VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
def answer3(n, a): INF = 10**10 dp = [1, INF, INF] if a[0] == 0: dp[0] = 1 elif a[0] == 1: dp[1] = 0 elif a[0] == 2: dp[2] = 0 else: dp[1] = 0 dp[2] = 0 for day in range(1, n): new_dp = [INF, INF, INF] for i in range(3): for j in range(3): if i == j and i != 0: pass elif a[day] == 1 and j == 2: pass elif a[day] == 2 and j == 1: pass elif a[day] == 0: new_dp = [min(dp) + 1, INF, INF] break elif j == 0: new_dp[j] = min(new_dp[j], dp[i] + 1) else: new_dp[j] = min(new_dp[j], dp[i] + 0) dp = new_dp return min(dp) def main(): n = int(input()) a = [int(i) for i in input().split()] print(answer3(n, a)) return main()
FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR LIST BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR NUMBER 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 ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN EXPR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
input() p, c = 3, 0 for i in list(map(int, input().split())): if i == p and p != 3: i = 0 elif i == 3 and p != 3: i -= p if i == 0: c += 1 p = i print(c)
EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = list(map(int, input().split())) dp = [[(10**9) for j in range(3)] for i in range(n + 1)] dp[0][0] = 0 for i in range(n): for j in range(3): if dp[i][j] == 10**9: continue dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + 1) if j != 1 and (a[i] == 1 or a[i] == 3): dp[i + 1][1] = min(dp[i + 1][1], dp[i][j]) if j != 2 and (a[i] == 2 or a[i] == 3): dp[i + 1][2] = min(dp[i + 1][2], dp[i][j]) print(min(dp[n]))
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 VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) arr = list(map(int, input().split())) dp = [[0, 0, 0] for i in range(n)] inf = 1000000000000000 if arr[0] == 0: dp[0] = [1, inf, inf] elif arr[0] == 1: dp[0] = [1, inf, 0] elif arr[0] == 2: dp[0] = [1, 0, inf] elif arr[0] == 3: dp[0] = [1, 0, 0] for a in range(1, n): if arr[a] == 0: dp[a][0] = min(dp[a - 1]) + 1 dp[a][1] = inf dp[a][2] = inf elif arr[a] == 1: dp[a][0] = min(dp[a - 1][0], dp[a - 1][1], dp[a - 1][2]) + 1 dp[a][1] = inf dp[a][2] = min(dp[a - 1][0], dp[a - 1][1]) elif arr[a] == 2: dp[a][0] = min(dp[a - 1][0], dp[a - 1][1], dp[a - 1][2]) + 1 dp[a][1] = min(dp[a - 1][0], dp[a - 1][2]) dp[a][2] = inf elif arr[a] == 3: dp[a][0] = min(dp[a - 1][0], dp[a - 1][1], dp[a - 1][2]) + 1 dp[a][1] = min(dp[a - 1][0], dp[a - 1][2]) dp[a][2] = min(dp[a - 1][0], dp[a - 1][1]) print(min(dp[-1][0], dp[-1][1], dp[-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 VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER LIST NUMBER VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER LIST NUMBER VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER 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 the contest is not carried out; 2. on this day the gym is closed and the contest is carried out; 3. on this day the gym is open and the contest is not carried out; 4. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has β€” he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input The first line contains a positive integer n (1 ≀ n ≀ 100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≀ ai ≀ 3) separated by space, where: * ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; * ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; * ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; * ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out. Output Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: * to do sport on any two consecutive days, * to write the contest on any two consecutive days. Examples Input 4 1 3 2 0 Output 2 Input 7 1 3 3 2 1 2 3 Output 0 Input 2 2 2 Output 1 Note In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n = int(input()) a = [int(i) for i in input().split()] dp = [[(0) for i in range(n)] for j in range(2)] if a[0] == 0: dp[0][0] += 1 dp[1][0] += 1 elif a[0] == 1: dp[1][0] += 1 elif a[0] == 2: dp[0][0] += 1 for i in range(1, n): m = min(dp[0][i - 1], dp[1][i - 1]) if a[i] == 0: dp[0][i] = m + 1 dp[1][i] = m + 1 elif a[i] == 1: dp[0][i] = min(dp[0][i - 1] + 1, dp[1][i - 1]) dp[1][i] = m + 1 elif a[i] == 2: dp[1][i] = min(dp[1][i - 1] + 1, dp[0][i - 1]) dp[0][i] = m + 1 else: dp[0][i] = min(dp[0][i - 1] + 1, dp[1][i - 1]) dp[1][i] = min(dp[1][i - 1] + 1, dp[0][i - 1]) print(min(dp[0][n - 1], dp[1][n - 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 IF VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER