description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
x, y = list(map(int, input().split(" "))) ok = [] while y % x in [0, 1, -1 + x]: if y % x == 0: y //= x ok.append(0) elif y % x == 1: y = (y - 1) // x ok.append(1) else: y = (y + 1) // x ok.append(-1) if y == 0: break if y == 0: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST WHILE BIN_OP VAR VAR LIST NUMBER NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
def number_tree(sum_weights, i, m): if sum_weights == m: return True if i == -1: return False result = number_tree(sum_weights + weights[i], i - 1, m) if result: return result result = number_tree(sum_weights, i - 1, m) if result: return result if sum_weights != 0: result = number_tree(sum_weights - weights[i], i - 1, m) if result: return result return False line = input() w, m = map(int, line.split(" ")) if w == 2 or w == 3: print("YES") else: weights = [1] for power in range(99): if weights[power] > m: break weights.append(weights[power] * w) ret = number_tree(0, power, m) if ret: print("YES") else: print("NO")
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR RETURN VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
import sys input = sys.stdin.readline w, m = map(int, input().split()) for i in range(33): m = min(m, abs(m - w ** (32 - i))) if m == 0: print("YES") else: print("NO")
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
from sys import exit w, m = map(int, input().split()) if w in (2, 3): print("YES") exit() while True: if m in (0, 1): print("YES") exit() prev = 1 cur = w while cur < m: prev = cur cur *= w if cur == m: print("YES") exit() sum1k = (cur - 1) // (w - 1) if sum1k < m < cur - sum1k: print("NO") exit() m = min(m - prev, cur - m)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR WHILE NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = map(int, input().split()) p = 1 for i in range(100): if m == 0: break if (m - p) % (p * w) == 0: m -= p elif (m + p) % (p * w) == 0: m += p p *= w if m == 0: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
line = input() w, m = map(int, line.split(" ")) while m > 0: if (m - 1) % w == 0: m -= 1 elif (m + 1) % w == 0: m += 1 elif m % w != 0: print("NO") exit(0) m //= w print("YES")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING WHILE VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = list(map(int, input().split())) def bt(w, p, final, cur): if final == cur: return True if p == 0: return False if abs(cur + p - final) <= (p - 1) / (w - 1): if bt(w, p // w, final, cur + p): return True if abs(cur - p - final) <= (p - 1) / (w - 1): if bt(w, p // w, final, cur - p): return True if bt(w, p // w, final, cur): return True return False if bt(w, w**35, m, 0): print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
__author__ = "Andrey" def solve(m, w, max_power=100): r = m % w if r not in {w - 1, 0, 1}: return False if m < w: if max_power < 1: return False else: return True if r % w == 0: new_m = m elif (r - 1) % w == 0: new_m = m - 1 else: new_m = m + 1 return solve(new_m // w, w, max_power - 1) w, m = map(int, input().split()) print("YES" if solve(m, w) else "NO")
ASSIGN VAR STRING FUNC_DEF NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER RETURN NUMBER IF VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = map(int, input().split()) while m > 1: c = m % w if c not in {0, 1, w - 1}: print("NO") exit() m //= w if c == w - 1: m += 1 print("YES")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = map(int, str.split(input())) bits = [0] * 100 for i in range(100): m, bits[i] = divmod(m, w) for i in range(99): if 1 < bits[i] < w - 1: print("NO") exit() if bits[i] == w - 1: bits[i] = 0 bits[i + 1] += 1 carry = 0 for j in range(i + 1, 100): carry, bits[j] = divmod(bits[j] + carry, w) print("YES")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = [int(i) for i in input().split()] k = 0 while k <= 100: if m == 0: print("YES") exit(0) d = m % w if d == 0: m = m / w k += 1 elif d == 1: k += 1 m = (m - 1) / w elif d == w - 1: m = (m + 1) / w k += 1 else: print("NO") exit(0) print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
numbers = list(map(int, input().split())) w = numbers[0] m = numbers[1] no = False if w <= 3: m = 0 while m: x = m % w if x <= 1: m = m // w elif x == w - 1: m = m // w + 1 else: no = True break if no is False: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = map(int, input().split()) a = [] while m: a.append(m % w) m //= w a.append(0) for i, ai in enumerate(a): if ai <= 1: pass elif ai >= w - 1: a[i + 1] += 1 else: print("NO") exit() print("YES")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
x, y = map(int, input().split()) x, y = y, x s = [] while x > 0: d = x % y s.append(d) x //= y s.append(x) carry = 0 for n in range(len(s)): s[n] += carry if s[n] == y: carry = 1 continue if 1 < s[n] < y - 1: print("NO") exit(0) carry = 0 if s[n] == y - 1: carry = 1 print("YES")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, x = map(int, input().split()) lst = [] for i in range(0, 30): if pow(w, i) < x * 2: lst.append(pow(w, i)) n = len(lst) lst.sort(reverse=True) ans = 100000 def rec(a, x, i): global ans if a == x: ans = 1 return 1 if i == n: return rec(a, x, i + 1) rec(a - lst[i], x, i + 1) rec(a + lst[i], x, i + 1) if w == 2 or w == 3: print("YES") else: rec(0, x, 0) if ans == 100000: print("NO") else: print("YES")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR NUMBER RETURN NUMBER IF VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = map(int, input().split(" ")) f = 0 if w == 2: print("YES") else: st = 1 while f == 0: if m % (st * w) != 0: if (m - st) % (st * w) == 0: m -= st elif (m + st) % (st * w) == 0: m += st else: print("NO") f = 1 if m == 0: print("YES") f = 1 st *= w
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
def convert(base, n): l = [(0) for i in range(100)] c = 99 while n > 0: a = n // base b = n % base l[c] = b c -= 1 n = a return l def arr_eq(a, b): for i in range(99, 0, -1): if a[i] != b[i]: return False return True def inc_arr(arr, ptr, base): arr[ptr] = 0 while ptr > 0: if arr[ptr - 1] == base - 1: arr[ptr - 1] = 0 else: arr[ptr - 1] += 1 return arr ptr -= 1 return arr def weight(sc1, sc2, base): ptr = 99 while not arr_eq(sc1, sc2) and ptr > -1: if sc1[ptr] == 1: sc2[ptr] = 1 elif sc1[ptr] == base - 1: sc1 = inc_arr(sc1, ptr, base) elif sc1[ptr] == 0: pass else: return False ptr -= 1 return arr_eq(sc1, sc2) inp = input().split() base = int(inp[0]) n = int(inp[1]) l = convert(base, n) sc1, sc2 = l, [(0) for i in range(100)] i = weight(sc1, sc2, base) if i: print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER RETURN NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
n, m = [int(x) for x in input().split()] balans = m if n == 2 or m == 1: print("YES") return cur = 1 while True: cur2 = cur * n if balans % cur2 == cur: balans -= cur elif balans % cur2 == cur2 - cur: balans += cur elif balans % cur2 == 0: balans += 0 else: print("NO") return if balans == 0: print("YES") return cur = cur2
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
def solucion(): base, peso = map(int, input().split()) auxiliar = peso SoloPongoPesoEnUnPlato = "True" data = [] PesoAgregadoAPlatoDelArticulo = [] while auxiliar != 0: resto = auxiliar % base auxiliar = int(auxiliar / base) data.append(resto) if resto > 1: SoloPongoPesoEnUnPlato = "False" if SoloPongoPesoEnUnPlato == "True": print("YES") else: potencia = 0 carry = 0 for x in data: if carry == 1: x = x + 1 carry = 0 if x > 1: if x == base: x = 0 data[potencia] = x PesoAgregadoAPlatoDelArticulo.append(0) carry = 1 elif int(x) != base - 1: return print("NO") else: data[potencia] = 0 PesoAgregadoAPlatoDelArticulo.append(1) carry = 1 else: data[potencia] = x PesoAgregadoAPlatoDelArticulo.append(0) potencia = potencia + 1 if carry == 1 and potencia == len(data): data.append(0) indice = 0 while indice < len(data) - 1: if ( data[indice] == PesoAgregadoAPlatoDelArticulo[indice] and data[indice] == 1 ): return print("NO") indice = indice + 1 print("YES") solucion()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
M = 10 l = set() r = set() def genl(i, s): if i == M: l.add(s) return genl(i + 1, s - a[i]) genl(i + 1, s) genl(i + 1, s + a[i]) def genr(i, s): if i == M: r.add(s) return genr(i + 1, s - b[i]) genr(i + 1, s) genr(i + 1, s + b[i]) w, n = map(int, input().split()) if w == 2: print("YES") exit(0) a = [] for i in range(M): a.append(w**i) b = [] for i in range(M): b.append(w ** (M + i)) genl(0, 0) genr(0, 0) for e in l: if n - e in r: print("YES") exit(0) print("NO")
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = map(int, input().split()) a = [0] * 60 c = 0 while m > 0: a[c] = m % w c += 1 m //= w for i in range(59): if a[i] not in [0, 1, w - 1, w]: print("NO") break elif a[i] in [w - 1, w]: a[i + 1] += 1 else: print("YES")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR LIST NUMBER NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR VAR LIST BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
from sys import stdin, stdout def get(): return stdin.readline().strip() def getf(): return [int(i) for i in get().split()] def put(a, end="\n"): stdout.write(str(a) + end) def putf(a, sep=" ", end="\n"): stdout.write(sep.join([str(i) for i in a]) + end) def putff(a, sep=" ", end="\n"): [putf(i, sep, end) for i in a] def transf(a, w): ans = [] while a > 0: ans.append(a % w) a //= w return ans[::-1] def solve(a, w): ans = [] p = 0 for i in range(len(a) - 1, 0, -1): if a[i] + p >= w: a[i] = (a[i] + p) % w p = 1 else: a[i] += p p = 0 if a[i] in [0, 1]: ans.append(0) pass elif a[i] == w - 1: p = 1 ans.append(1) else: return "NO" ans.reverse() for i in ans: if i not in [0, 1]: return "NO" return "YES" def main(): w, m = getf() print(solve([0] + transf(m, w), w)) main()
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_DEF STRING STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF STRING STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN STRING EXPR FUNC_CALL VAR FOR VAR VAR IF VAR LIST NUMBER NUMBER RETURN STRING RETURN STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
def powmod(x, p, m): if p <= 0: return 1 if p <= 1: return x % m return powmod(x * x % m, p // 2, m) * (x % m) ** (p % 2) % m def to_basex(num, x): while num > 0: yield num % x num //= x def from_basex(it, x): ret = 0 p = 1 for d in it: ret += d * p p *= x return ret w, m = (int(x) for x in input().split()) mbx = list(to_basex(m, w)) for i in range(len(mbx)): mbx[i] += 1 m = from_basex(mbx, w) mbx = list(to_basex(m, w)) ans = "YES" if max(mbx) < 3 else "NO" print(ans)
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF WHILE VAR NUMBER EXPR BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER STRING STRING EXPR FUNC_CALL VAR VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
def solve(num, p): return ( True if num == 0 else False if num >= p * 2 else solve(min(num, abs(p - num)), p // m) ) m, num = map(int, input().split()) p = 1 while p < num: p *= m print("YES" if solve(num, p) else "NO")
FUNC_DEF RETURN VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = map(int, input().split(" ")) an = [] while m != 0: mod = m % w m //= w an.append(mod) an += [0] * 100 for _ in range(100): for i in range(100): an[i + 1] += an[i] // w an[i] %= w if an[i] == w - 1: an[i] = -1 an[i + 1] += 1 if all(map(lambda x: x == 0 or x == 1 or x == -1, an)): print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
def to_w(w1, m1): t = 100 while w**t > m: t -= 1 at = [0] * (t + 1) for i in range(t, -1, -1): at[i] = m1 // w1**i m1 = m1 % w1**i return at w, m = list(map(int, input().split())) n = to_w(w, m) for i in range(len(n)): if n[i] != 0 and n[i] != 1 and n[i] != w and n[i] != w - 1: print("NO") exit() if n[i] == w - 1: if i != len(n) - 1: n[i + 1] = n[i + 1] + 1 n[i] = 0 else: n.append(1) if n[i] == w: if i != len(n) - 1: n[i] = 0 n[i + 1] += 1 else: n.append(1) print("YES")
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
def base(n, b): global st if n < b: st.append(n) return base(n // b, b) st.append(n % b) return st = [] def proC(m, w): global st st = [] base(m, w) s = 0 c = 0 arr = st[::-1] for i in range(len(arr)): s = (int(arr[i]) + c) % w c = (int(arr[i]) + c) // w if s == 0 or s == 1: continue if s == w - 1: c = 1 else: print("NO") return print("YES") w, m = list(map(int, input().split())) proC(m, w)
FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN ASSIGN VAR LIST FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = [int(x) for x in input().split()] for i in range(101): if m % w == 0: m /= w elif (m - 1) % w == 0: m = m // w elif (m + 1) % w == 0: m = (m + 1) / w else: print("NO") exit() if m == 0: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = map(int, input().split()) while m > 0: digit = m % w if digit == 1: m -= 1 elif digit == w - 1: m += 1 elif digit != 0: m = -1 if m > 0: m //= w print("YES" if m == 0 else "NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
def main(): w, m = [int(i) for i in input().split()] if w == 2: print("YES") return s = 0 for i in range(21): for sign in range(-1, 2): if (m - s - sign * w**i) % w ** (i + 1) == 0: s += sign * w**i break if abs(s) == m: print("YES") else: print("NO") main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
import sys input = sys.stdin.readline def getInt(): return int(input()) def getVars(): return map(int, input().split()) def getArr(): return list(map(int, input().split())) def getStr(): return input().strip() def intToBase(x, base): res = [] while x > 0: res.append(x % base) x //= base return res W, M = getVars() s = intToBase(M, W) s.append(0) res = "YES" for i in range(len(s)): if s[i] == 0 or s[i] == 1: continue if s[i] == W - 1: k = i s[k] = 0 while s[k] == 0: s[k + 1] = (s[k + 1] + 1) % W k += 1 continue res = "NO" break print(res)
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
def can_be_weigthed(m, w, i): if i == 0: return m == 1 else: if m == 1: return True if m % w in {0, 1, w - 1}: return can_be_weigthed(m // w + (m % w == w - 1), w, i - 1) else: return False w, m = [int(x) for x in input().split()] answer = {(True): "YES", (False): "NO"} print(answer[can_be_weigthed(m, w, 100)])
FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER STRING STRING EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
a, b = map(int, input().split()) l = [] x = 1 c = 0 while b != 0: c = b % a b = b // a l.append(c) l.append(0) l.append(0) l.append(0) br = 0 t = 0 for x in l: if x != 0 and x != 1: if x == a - 1: l[br] = -1 l[br + 1] += 1 elif x == a: l[br] = 0 l[br + 1] += 1 else: t += 1 break br += 1 if t == 0: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
import sys w, m = list(map(int, sys.stdin.readline().split())) a = sum(pow(w, i) for i in range(101)) + m while a > 0: if a % w > 2: print("NO") sys.exit(0) a //= w print("YES")
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = [int(x) for x in input().split()] a = [(w**i) for i in range(101)] total = sum(a) + m for i in reversed(a): cnt = 0 while total >= i and cnt < 2: cnt += 1 total -= i if total == 0: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
def f(w, m): if m == 0: return True if m % w == 0: return f(w, m // w) if (m - 1) % w == 0: return f(w, (m - 1) // w) if (m + 1) % w == 0: return f(w, (m + 1) // w) return False w, m = map(int, input().split()) if f(w, m): print("YES") else: print("NO")
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = map(int, input().split()) base = [0] * 101 base[0] = m for i in range(len(base)): if base[i] < w: break base[i + 1] = base[i] // w base[i] = base[i] % w found = True for i in range(len(base)): if base[i] > 1: if -1 <= base[i] - w <= 1: base[i] -= w base[i + 1] += 1 else: found = False break if found: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance. -----Input----- The first line contains two integers w, m (2 ≀ w ≀ 10^9, 1 ≀ m ≀ 10^9) β€” the number defining the masses of the weights and the mass of the item. -----Output----- Print word 'YES' if the item can be weighted and 'NO' if it cannot. -----Examples----- Input 3 7 Output YES Input 100 99 Output YES Input 100 50 Output NO -----Note----- Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1. Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100. Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
w, m = map(int, input().split()) def isOK(w, m): wr = convert_base_w(m, w) for i in range(101): if wr[i] == 0 or wr[i] == 1: continue elif wr[i] == w - 1 or wr[i] == w: wr[i + 1] += 1 else: return False return True def convert_base_w(m, w): wr = [0] * 101 for i in range(101): m, r = divmod(m, w) wr[i] = r return wr if isOK(w, m): print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input The first line of the input contains one integer n (1 ≀ n ≀ 2000) β€” the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Examples Input 5 2 2 3 4 6 Output 5 Input 4 2 4 6 8 Output -1 Input 3 2 6 9 Output 4 Note In the first sample you can turn all numbers to 1 using the following 5 moves: * [2, 2, 3, 4, 6]. * [2, 1, 3, 4, 6] * [2, 1, 3, 1, 6] * [2, 1, 1, 1, 6] * [1, 1, 1, 1, 6] * [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
n = int(input()) arr = list(map(int, input().split())) def GCD(x, y): if y > 0: return GCD(y, x % y) else: return x allGCD = arr[0] for i in arr: allGCD = GCD(allGCD, i) if allGCD > 1: print(-1) else: ones = 0 for i in arr: if i == 1: ones += 1 if ones > 1: print(n - ones) else: res = 2000000000 for i in range(n): tmp = arr[i] for j in range(i, n): tmp = GCD(tmp, arr[j]) if tmp == 1: res = min(res, j - i) print(n + res - 1)
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 VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input The first line of the input contains one integer n (1 ≀ n ≀ 2000) β€” the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Examples Input 5 2 2 3 4 6 Output 5 Input 4 2 4 6 8 Output -1 Input 3 2 6 9 Output 4 Note In the first sample you can turn all numbers to 1 using the following 5 moves: * [2, 2, 3, 4, 6]. * [2, 1, 3, 4, 6] * [2, 1, 3, 1, 6] * [2, 1, 1, 1, 6] * [1, 1, 1, 1, 6] * [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
n = int(input("")) s = list(map(int, input("").split())) a = s.count(1) ans = 0 def gcd(x, y): x, y = max(x, y), min(x, y) if y == 0: return x return gcd(y, x % y) if a != 0: ans = n - a else: dp = [[(0) for i in range(n)] for j in range(n)] for i in range(n): dp[i][i] = s[i] mins = n for i in range(n): for j in range(i, n): dp[i][j] = gcd(dp[i][j - 1], s[j]) if dp[i][j] == 1: mins = min(j - i, mins) if mins == n: ans = -1 else: ans = mins + (n - 1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input The first line of the input contains one integer n (1 ≀ n ≀ 2000) β€” the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Examples Input 5 2 2 3 4 6 Output 5 Input 4 2 4 6 8 Output -1 Input 3 2 6 9 Output 4 Note In the first sample you can turn all numbers to 1 using the following 5 moves: * [2, 2, 3, 4, 6]. * [2, 1, 3, 4, 6] * [2, 1, 3, 1, 6] * [2, 1, 1, 1, 6] * [1, 1, 1, 1, 6] * [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
n = int(input()) A = input().split() A = [int(i) for i in A] def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) C = [n + 10000] * n for i in range(0, n): B = A[:] j = i while B[i] != 1: j += 1 if j >= n: break else: B[i] = gcd(B[i], A[j]) if B[i] == 1: C[i] = j - i else: C[i] = n + 100 small = min(C) if small == n + 100: print(-1) elif small == 0: print(n - C.count(0)) else: print(n - 1 + small)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input The first line of the input contains one integer n (1 ≀ n ≀ 2000) β€” the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Examples Input 5 2 2 3 4 6 Output 5 Input 4 2 4 6 8 Output -1 Input 3 2 6 9 Output 4 Note In the first sample you can turn all numbers to 1 using the following 5 moves: * [2, 2, 3, 4, 6]. * [2, 1, 3, 4, 6] * [2, 1, 3, 1, 6] * [2, 1, 1, 1, 6] * [1, 1, 1, 1, 6] * [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
a = int(input()) s = list(map(int, input().split())) def g(a, b): a, b = max(a, b), min(a, b) while a % b > 0: a, b = b, a % b return b b = 0 c = 0 for i in range(1, a): if g(s[i], s[i - 1]) == 1: b = 1 break if s.count(1) > 0 or b: b = 1 else: for j in range(1, a): for i in range(1, a): v = g(s[i], s[i - 1]) if s[i] != s[i - 1]: if s[i] == 1: s[i - 1] = v else: s[i] = v c += 1 if v == 1: b = 1 break if s[-1] == 1: b += 1 if b: break if b or a == 1 and s[0] == 1: print(c + a - s.count(1)) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER IF VAR IF VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input The first line of the input contains one integer n (1 ≀ n ≀ 2000) β€” the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Examples Input 5 2 2 3 4 6 Output 5 Input 4 2 4 6 8 Output -1 Input 3 2 6 9 Output 4 Note In the first sample you can turn all numbers to 1 using the following 5 moves: * [2, 2, 3, 4, 6]. * [2, 1, 3, 4, 6] * [2, 1, 3, 1, 6] * [2, 1, 1, 1, 6] * [1, 1, 1, 1, 6] * [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
def nod(x, y): if x % y == 0: return y else: return nod(y, x % y) n = int(input()) a = list(map(int, input().split())) k = 0 for i in a: if i == 1: k += 1 if k > 0: print(n - k) else: md = n + 1 for i in range(0, n - 1): d = a[i] for j in range(i + 1, n): x = max(d, a[j]) y = min(d, a[j]) d = nod(x, y) if d == 1 and md > j - i + 1: md = j - i + 1 break print(n + md - 2 if md < n + 1 else -1)
FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR 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 NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input The first line of the input contains one integer n (1 ≀ n ≀ 2000) β€” the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Examples Input 5 2 2 3 4 6 Output 5 Input 4 2 4 6 8 Output -1 Input 3 2 6 9 Output 4 Note In the first sample you can turn all numbers to 1 using the following 5 moves: * [2, 2, 3, 4, 6]. * [2, 1, 3, 4, 6] * [2, 1, 3, 1, 6] * [2, 1, 1, 1, 6] * [1, 1, 1, 1, 6] * [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
def gcd(a, b): while a != 0 and b != 0: if a > b: a = a % b else: b = b % a return a + b n = int(input()) a = list(map(int, input().split())) c = 0 if a.count(1) > 0: print(n - a.count(1)) else: f = 1 while a.count(1) == 0: if len(a) - c == 1 and a[0] != 1: f = 0 break c += 1 for i in range(len(a) - c): a[i] = gcd(a[i], a[i + 1]) if f == 0: print(-1) else: print(c + n - 1)
FUNC_DEF WHILE VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR 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 NUMBER IF FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input The first line of the input contains one integer n (1 ≀ n ≀ 2000) β€” the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Examples Input 5 2 2 3 4 6 Output 5 Input 4 2 4 6 8 Output -1 Input 3 2 6 9 Output 4 Note In the first sample you can turn all numbers to 1 using the following 5 moves: * [2, 2, 3, 4, 6]. * [2, 1, 3, 4, 6] * [2, 1, 3, 1, 6] * [2, 1, 1, 1, 6] * [1, 1, 1, 1, 6] * [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
def gcd(a, b): if b == 0: return a return gcd(b, a % b) memo = {} def is_prime(n): if n < 1: return False if n == 1: return True if n in memo: return memo[n] i = 2 while i * i <= n: if n % i == 0: memo[n] = False return False i += 1 memo[n] = True return True n = int(input()) a = list(map(int, input().split())) tot = 0 for i in range(n): if a[i] == 1: tot += 1 if tot > 0: print(n - tot) exit(0) tot = 0 best = 10**9 for i in range(n): cur = a[i] for j in range(i + 1, n): cur = gcd(cur, a[j]) if cur == 1: best = min(best, j - i) if best == 10**9: print("-1") else: print(n + best - 1)
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER RETURN 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input The first line of the input contains one integer n (1 ≀ n ≀ 2000) β€” the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Examples Input 5 2 2 3 4 6 Output 5 Input 4 2 4 6 8 Output -1 Input 3 2 6 9 Output 4 Note In the first sample you can turn all numbers to 1 using the following 5 moves: * [2, 2, 3, 4, 6]. * [2, 1, 3, 4, 6] * [2, 1, 3, 1, 6] * [2, 1, 1, 1, 6] * [1, 1, 1, 1, 6] * [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
n = int(input()) a = [int(i) for i in input().split()] least = len(a) found = 0 count = 0 d = {} def gcd(x, y): if x < y: x, y = y, x if (x, y) not in d: if x % y == 0: d[x, y] = y else: d[x, y] = gcd(y, x % y) return d[x, y] for i in range(len(a)): l = a[i] if a[i] == 1: count += 1 for j in range(i, min(len(a), least + i)): l = gcd(a[j], l) if l == 1: found = 1 least = min(least, j - i) if found == 0: print(-1) elif count > 0: print(n - count) else: print(least + n - 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input The first line of the input contains one integer n (1 ≀ n ≀ 2000) β€” the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Examples Input 5 2 2 3 4 6 Output 5 Input 4 2 4 6 8 Output -1 Input 3 2 6 9 Output 4 Note In the first sample you can turn all numbers to 1 using the following 5 moves: * [2, 2, 3, 4, 6]. * [2, 1, 3, 4, 6] * [2, 1, 3, 1, 6] * [2, 1, 1, 1, 6] * [1, 1, 1, 1, 6] * [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
def read(): return list(map(int, input().split())) def gcd(a, b): while b: a, b = b, a % b return a def check(l): for t in l: if t != 1: return False else: return True def main(): n = int(input()) l = read() ones = len(list(filter(lambda i: i == 1, l))) if ones > 0: return n - ones sum = 10000000000.0 for i in range(n - 1): g = 0 for j in range(i, n): g = gcd(g, l[j]) if g == 1: sum = min(sum, j - i + n - 1) return sum if sum != 10000000000.0 else -1 print(main())
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF FOR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input The first line of the input contains one integer n (1 ≀ n ≀ 2000) β€” the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Examples Input 5 2 2 3 4 6 Output 5 Input 4 2 4 6 8 Output -1 Input 3 2 6 9 Output 4 Note In the first sample you can turn all numbers to 1 using the following 5 moves: * [2, 2, 3, 4, 6]. * [2, 1, 3, 4, 6] * [2, 1, 3, 1, 6] * [2, 1, 1, 1, 6] * [1, 1, 1, 1, 6] * [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
def gcd(a, b): if a < b: a, b = b, a while b > 0: r = a % b a, b = b, r return a def solve(): n = int(input()) al = [int(i) for i in input().split()] if 1 in al: print(n - al.count(1)) return ans = -1 for i in range(n): t = al[i] for j in range(i + 1, n): t = gcd(t, al[j]) if t == 1: if ans == -1: ans = j - i + (n - 1) else: ans = min(ans, j - i + (n - 1)) print(ans) solve()
FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of operations you need to make all of the elements equal to 1? Input The first line of the input contains one integer n (1 ≀ n ≀ 2000) β€” the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the array. Output Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. Examples Input 5 2 2 3 4 6 Output 5 Input 4 2 4 6 8 Output -1 Input 3 2 6 9 Output 4 Note In the first sample you can turn all numbers to 1 using the following 5 moves: * [2, 2, 3, 4, 6]. * [2, 1, 3, 4, 6] * [2, 1, 3, 1, 6] * [2, 1, 1, 1, 6] * [1, 1, 1, 1, 6] * [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
import sys sys.setrecursionlimit(3000) n = int(input()) arr = str(input()).split() arr = [int(i) for i in arr] arr2 = [i for i in arr] def getmax(a, b): if a > b: return a return b def getmin(a, b): if a < b: return a return b def gcd(a, b): minNum = getmin(a, b) j = minNum while j >= 1: if a % j == 0 and b % j == 0: return j j -= 1 s = 0 def findAns(myList, s): for i in myList: if i == 1: return s + (n - 1) if len(myList) == 1: return -1 j = 1 newarr = [] while j < len(myList): newarr.append(gcd(myList[j], myList[j - 1])) j += 1 return findAns(newarr, s + 1) myans = n for i in arr: if i == 1: myans -= 1 if myans != n: print(myans) else: print(findAns(arr, s))
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER RETURN VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF FOR VAR VAR IF VAR NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are organizing a boxing tournament, where $n$ boxers will participate ($n$ is a power of $2$), and your friend is one of them. All boxers have different strength from $1$ to $n$, and boxer $i$ wins in the match against boxer $j$ if and only if $i$ is stronger than $j$. The tournament will be organized as follows: $n$ boxers will be divided into pairs; the loser in each pair leaves the tournament, and $\frac{n}{2}$ winners advance to the next stage, where they are divided into pairs again, and the winners in all pairs advance to the next stage, and so on, until only one boxer remains (who is declared the winner). Your friend really wants to win the tournament, but he may be not the strongest boxer. To help your friend win the tournament, you may bribe his opponents: if your friend is fighting with a boxer you have bribed, your friend wins even if his strength is lower. Furthermore, during each stage you distribute the boxers into pairs as you wish. The boxer with strength $i$ can be bribed if you pay him $a_i$ dollars. What is the minimum number of dollars you have to spend to make your friend win the tournament, provided that you arrange the boxers into pairs during each stage as you wish? -----Input----- The first line contains one integer $n$ ($2 \le n \le 2^{18}$) β€” the number of boxers. $n$ is a power of $2$. The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$, where $a_i$ is the number of dollars you have to pay if you want to bribe the boxer with strength $i$. Exactly one of $a_i$ is equal to $-1$ β€” it means that the boxer with strength $i$ is your friend. All other values are in the range $[1, 10^9]$. -----Output----- Print one integer β€” the minimum number of dollars you have to pay so your friend wins. -----Examples----- Input 4 3 9 1 -1 Output 0 Input 8 11 -1 13 19 24 7 17 5 Output 12 -----Note----- In the first test case no matter how you will distribute boxers into pairs, your friend is the strongest boxer and anyway wins the tournament. In the second test case you can distribute boxers as follows (your friend is number $2$): $1 : 2, 8 : 5, 7 : 3, 6 : 4$ (boxers $2, 8, 7$ and $6$ advance to the next stage); $2 : 6, 8 : 7$ (boxers $2$ and $8$ advance to the next stage, you have to bribe the boxer with strength $6$); $2 : 8$ (you have to bribe the boxer with strength $8$);
from sys import stdin input = stdin.readline n = int(input()) a = list(map(int, input().split())) a.reverse() inf = float("inf") N = 19 dp = [([inf] * (N + 2)) for _ in range(1 << N)] sum = [0] * (1 << 21) now = n for i in range(1, 20): sum[i] = sum[i - 1] + now // 2 now //= 2 for i in range(n)[::-1]: for j in range(N): if a[i] == -1: dp[i][j] = 0 continue if i > sum[j]: continue dp[i][j] = dp[i + 1][j + 1] + a[i] if i < sum[j]: dp[i][j] = min(dp[i][j], dp[i + 1][j]) print(dp[0][0])
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 EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER
You are organizing a boxing tournament, where $n$ boxers will participate ($n$ is a power of $2$), and your friend is one of them. All boxers have different strength from $1$ to $n$, and boxer $i$ wins in the match against boxer $j$ if and only if $i$ is stronger than $j$. The tournament will be organized as follows: $n$ boxers will be divided into pairs; the loser in each pair leaves the tournament, and $\frac{n}{2}$ winners advance to the next stage, where they are divided into pairs again, and the winners in all pairs advance to the next stage, and so on, until only one boxer remains (who is declared the winner). Your friend really wants to win the tournament, but he may be not the strongest boxer. To help your friend win the tournament, you may bribe his opponents: if your friend is fighting with a boxer you have bribed, your friend wins even if his strength is lower. Furthermore, during each stage you distribute the boxers into pairs as you wish. The boxer with strength $i$ can be bribed if you pay him $a_i$ dollars. What is the minimum number of dollars you have to spend to make your friend win the tournament, provided that you arrange the boxers into pairs during each stage as you wish? -----Input----- The first line contains one integer $n$ ($2 \le n \le 2^{18}$) β€” the number of boxers. $n$ is a power of $2$. The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$, where $a_i$ is the number of dollars you have to pay if you want to bribe the boxer with strength $i$. Exactly one of $a_i$ is equal to $-1$ β€” it means that the boxer with strength $i$ is your friend. All other values are in the range $[1, 10^9]$. -----Output----- Print one integer β€” the minimum number of dollars you have to pay so your friend wins. -----Examples----- Input 4 3 9 1 -1 Output 0 Input 8 11 -1 13 19 24 7 17 5 Output 12 -----Note----- In the first test case no matter how you will distribute boxers into pairs, your friend is the strongest boxer and anyway wins the tournament. In the second test case you can distribute boxers as follows (your friend is number $2$): $1 : 2, 8 : 5, 7 : 3, 6 : 4$ (boxers $2, 8, 7$ and $6$ advance to the next stage); $2 : 6, 8 : 7$ (boxers $2$ and $8$ advance to the next stage, you have to bribe the boxer with strength $6$); $2 : 8$ (you have to bribe the boxer with strength $8$);
n = int(input()) a = list(map(int, input().split())) me = a.index(-1) if me == n - 1: print(0) return for i in range(me + 1): a[i] = 0 dp = [([0] * n) for _ in range(2)] opt = [([0] * n) for _ in range(2)] dp[1][n - 1] = a[n - 1] if n - 1 <= me + 1: ans = a[n - 1] for i in range(2, 22): if 2**i > n: break s = i & 1 t = s ^ 1 l, r = n // 2 ** (i - 1) - 1, n - i + 1 pl, pr = n // 2 ** (i - 2) - 1, n - i + 2 opt[s][pr - 1] = dp[t][pr - 1] for j in range(pr - 2, pl - 1, -1): opt[s][j] = min(opt[s][j + 1], dp[t][j]) for j in range(pl - 1, l - 1, -1): opt[s][j] = opt[s][j + 1] for j in range(r - 1, l - 1, -1): dp[s][j] = opt[s][j + 1] + a[j] if l <= me + 1: ans = min(dp[s][l:r]) 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 FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = map(int, input().split()) g = [list(map(int, input().split())) for i in range(n)] l = [0] * n for i in range(n): res = 0 cnt = 0 for j in range(m): if g[i][j] == 1: cnt += 1 else: res = max(res, cnt) cnt = 0 res = max(res, cnt) l[i] = res for _ in range(q): y, x = map(int, input().split()) y -= 1 x -= 1 g[y][x] = 1 - g[y][x] cnt = 0 ans = 0 for i in range(m): if g[y][i] == 1: cnt += 1 else: ans = max(ans, cnt) cnt = 0 ans = max(ans, cnt) l[y] = ans print(max(l))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = [int(c) for c in input().split()] matrix = [] for i in range(n): matrix.append([int(c) for c in input().split()]) maxperrow = [] for a in range(n): maxrow = 0 maxmax = 0 for b in range(m): if matrix[a][b] == 1: maxrow += 1 if maxrow > maxmax: maxmax = maxrow else: maxrow = 0 maxperrow.append(maxmax) winner = [] for step in range(q): i, j = [int(c) for c in input().split()] matrix[i - 1][j - 1] = 1 - matrix[i - 1][j - 1] maxmax = 0 maxrow = 0 for b in range(m): if matrix[i - 1][b] == 1: maxrow += 1 if maxrow > maxmax: maxmax = maxrow else: maxrow = 0 maxperrow[i - 1] = maxmax winner.append(max(maxperrow)) for w in winner: print(w)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def read_data(): n, m, q = map(int, input().split()) grid = [] for i in range(n): grid.append(list(map(int, input().split()))) qs = [] for i in range(q): x, y = map(int, input().split()) qs.append((x - 1, y - 1)) return n, m, q, grid, qs def max_cons(row): mc = 0 tmp = 0 for v in row: if v: tmp += 1 else: if tmp > mc: mc = tmp tmp = 0 return max(mc, tmp) def solve(n, m, q, grid, qs): mcc = [max_cons(row) for row in grid] for x, y in qs: row = grid[x] row[y] = 1 - row[y] mcc[x] = max_cons(row) print(max(mcc)) param = read_data() solve(*param)
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
import sys N, M, Q = input().split() N = int(N) M = int(M) Q = int(Q) rows = [] score_of_row = [] def score(row): score_so_far = 0 max_score = float("-inf") for r in row: if r == 0: score_so_far = 0 else: score_so_far += 1 max_score = max(max_score, score_so_far) return max_score for _ in range(N): row = [int(x) for x in input().split()] rows += [row] score_of_row += [score(row)] for _ in range(Q): r, c = input().split() r, c = int(r), int(c) rows[r - 1][c - 1] = 1 - rows[r - 1][c - 1] score_of_row[r - 1] = score(rows[r - 1]) print(max(score_of_row))
IMPORT ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST VAR VAR LIST FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
class CodeforcesTask548BSolution: def __init__(self): self.result = "" self.n_m_q = [] self.grid = [] self.actions = [] def read_input(self): self.n_m_q = [int(x) for x in input().split(" ")] for _ in range(self.n_m_q[0]): self.grid.append([int(y) for y in input().split(" ")]) for _ in range(self.n_m_q[2]): self.actions.append([int(y) for y in input().split(" ")]) def process_task(self): maxes = [0] * self.n_m_q[0] for row in range(self.n_m_q[0]): mx = 0 cr = 0 for y in range(self.n_m_q[1]): if self.grid[row][y]: cr += 1 mx = max(mx, cr) else: cr = 0 maxes[row] = mx res = [] for action in self.actions: self.grid[action[0] - 1][action[1] - 1] = ( 0 if self.grid[action[0] - 1][action[1] - 1] else 1 ) mx = 0 cr = 0 for y in range(self.n_m_q[1]): if self.grid[action[0] - 1][y]: cr += 1 mx = max(mx, cr) else: cr = 0 maxes[action[0] - 1] = mx res.append(str(max(maxes))) self.result = "\n".join(res) def get_result(self): return self.result Solution = CodeforcesTask548BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result())
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR FUNC_DEF RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
values = [] def get_max(row): total = 0 max_vv = 0 for x in row: if x == 1: max_vv += 1 else: if max_vv > total: total = max_vv max_vv = 0 if max_vv > total: total = max_vv return total n, m, q = map(int, input().split()) rows = [] for i in range(n): rows.append(list(map(int, input().split()))) values.append(get_max(rows[-1])) for i in range(q): i, j = map(int, input().split()) i -= 1 j -= 1 rows[i][j] = 1 - rows[i][j] values[i] = get_max(rows[i]) print(max(values))
ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = map(int, input().split()) a = [[]] for i in range(n): a.append([0] + list(map(int, input().split()))) x, y = map(int, input().split()) a[x][y] = (a[x][y] + 1) % 2 ma = 0 curr = 0 for i in range(1, n + 1): for j in range(1, m + 1): if a[i][j] == 0: ma = max(curr, ma) curr = 0 else: curr += 1 ma = max(ma, curr) curr = 0 res = 0 for i in range(1, n + 1): for j in range(1, m + 1): if a[i][j] == 0: if curr == ma: res += 1 curr = 0 else: curr += 1 if curr == ma: res += 1 curr = 0 print(ma) for i in range(q - 1): x, y = map(int, input().split()) if a[x][y] == 1: j = y - 1 here = 1 while j >= 0 and a[x][j] == 1: j -= 1 here += 1 j = y + 1 while j <= m and a[x][j] == 1: j += 1 here += 1 a[x][y] = 0 if here == ma: res -= 1 if res >= 1: print(ma) else: ma = 0 curr = 0 for i in range(1, n + 1): for j in range(1, m + 1): if a[i][j] == 0: ma = max(curr, ma) curr = 0 else: curr += 1 ma = max(ma, curr) curr = 0 res = 0 for i in range(1, n + 1): for j in range(1, m + 1): if a[i][j] == 0: if curr == ma: res += 1 curr = 0 else: curr += 1 if curr == ma: res += 1 curr = 0 print(ma) else: a[x][y] = 1 j = y - 1 here = 1 while j >= 0 and a[x][j] == 1: j -= 1 here += 1 j = y + 1 while j <= m and a[x][j] == 1: j += 1 here += 1 if here > ma: ma = here res = 1 elif here == ma: res += 1 print(ma)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = map(int, input().split()) ma = [] for i in range(n): l1 = list(map(int, input().split())) ma.append(l1) gma = 0 lstgrt = [0] * n for i in range(n): lma = 0 gma = 0 for j in range(m): if ma[i][j] == 1: lma = lma + 1 else: if lma > gma: gma = lma lma = 0 if lma > gma: gma = lma lma = 0 lstgrt[i] = gma for u in range(q): a, b = map(int, input().split()) a = a - 1 b = b - 1 if ma[a][b] == 1: ma[a][b] = 0 else: ma[a][b] = 1 lma = 0 gma = 0 i = a for j in range(m): if ma[i][j] == 1: lma = lma + 1 else: if lma > gma: gma = lma lma = 0 if lma > gma: gma = lma lma = 0 lstgrt[i] = gma print(max(lstgrt))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = list(map(int, input().rstrip().split())) mat = [] def score(x): i = 0 l = 0 maxm = 0 while i < m: if x[i] == 1: l += 1 maxm = max(l, maxm) else: l = 0 i += 1 return maxm for i in range(n): mat += [list(map(int, input().rstrip().split()))] l = [] for x in mat: l += [score(x)] for i in range(q): x, y = list(map(int, input().rstrip().split())) if mat[x - 1][y - 1] == 1: mat[x - 1][y - 1] = 0 else: mat[x - 1][y - 1] = 1 l[x - 1] = score(mat[x - 1]) print(max(l))
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR VAR LIST FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = map(int, input().split()) a = [0] * n ans = [0] * n for i in range(0, n): s = list(map(int, input().split())) for j in range(0, m): a[i] = s for i in range(n): max_1 = 0 curr = 0 for j in range(m): if a[i][j] == 0: curr = 0 else: curr += 1 max_1 = max(curr, max_1) ans[i] = max_1 for x in range(q): x, y = map(int, input().split()) if a[x - 1][y - 1] == 0: a[x - 1][y - 1] = 1 else: a[x - 1][y - 1] = 0 curr = 0 max_1 = 0 for j in range(m): if a[x - 1][j] == 0: curr = 0 else: curr += 1 max_1 = max(curr, max_1) ans[x - 1] = max_1 print(max(ans))
ASSIGN VAR VAR 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 NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
rows, cols, changes_count = map(int, input().split()) grid = [input().split() for _ in range(rows)] changes = [map(int, input().split()) for __ in range(changes_count)] max_line = [max(map(len, "".join(row).split("0"))) for row in grid] for r, c in changes: grid[r - 1][c - 1] = "0" if grid[r - 1][c - 1] == "1" else "1" max_line[r - 1] = max(map(len, "".join(grid[r - 1]).split("0"))) print(max(max_line))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL STRING VAR STRING VAR VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING STRING STRING ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
from sys import stdin def input(): return stdin.readline().rstrip() def calcMax(a): ret = cur = 0 for i, v in enumerate(a): if v == 1: cur += 1 else: cur = 0 ret = max(ret, cur) return ret sizeI, sizeJ, nQ = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(sizeI)] ret = [] cnt = [calcMax(r) for r in a] for _ in range(nQ): i, j = map(lambda x: int(x) - 1, input().split()) a[i][j] ^= 1 cnt[i] = calcMax(a[i]) ret.append("%d" % max(cnt)) print("\n".join(ret))
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def score(R): val = 0 ret = 0 for i in R: if i: val += 1 ret = max(ret, val) else: val = 0 return ret n, m, q = map(int, input().split()) A = [list(map(int, input().split())) for i in range(n)] B = [score(A[i]) for i in range(n)] for _ in range(q): x, y = map(int, input().split()) x, y = x - 1, y - 1 A[x][y] = not A[x][y] B[x] = score(A[x]) print(max(B))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def func(a): s = 0 per = 0 for i in range(len(a)): if a[i] == "1": per += 1 else: s = max(s, per) per = 0 s = max(per, s) return s def main(a): A = [] B = [0] * int(a[0]) for i in range(int(a[0])): A.append(input().split()) for i in range(int(a[0])): B[i] = func(A[i]) for i in range(int(a[2])): s = 0 k = input().split() A[int(k[0]) - 1][int(k[1]) - 1] = str( (int(A[int(k[0]) - 1][int(k[1]) - 1]) + 1) % 2 ) B[int(k[0]) - 1] = func(A[int(k[0]) - 1]) for i in B: s = max(s, i) print(s) a = input().split() main(a)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
a = list() b = list() n, m, q = [int(s) for s in input().split()] for i in range(n): a.append([s for s in input().split()]) b.append(max([len(s) for s in "".join(a[i]).split("0")])) for i in range(q): p, o = [(int(s) - 1) for s in input().split()] a[p][o] = str(1 - int(a[p][o])) b[p] = max([len(s) for s in "".join(a[p]).split("0")]) print(max(b))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL STRING VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL STRING VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = input().split() n = int(n) m = int(m) q = int(q) a = [] for i in range(n): b = input().split() for j in range(m): b[j] = int(b[j]) a.append(b) def func(i): ans = 0 l = -1 for j in range(m): if a[i][j] == 0: l = j else: ans = max(ans, j - l) return ans c = list(map(func, range(n))) for i in range(q): z, x = map(int, input().split()) z -= 1 x -= 1 a[z][x] = 1 - a[z][x] c[z] = func(z) print(max(c))
ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
import time def res(row): ans = 0 buf = 0 for i in row: if i == 1: buf += 1 elif buf != 0: ans = max(ans, buf) buf = 0 ans = max(ans, buf) return ans n, m, q = (int(i) for i in input().split()) desk = [] score = [] start = time.time() for j in range(n): row = [int(i) for i in input().split()] desk.append(row) score.append(res(row)) ans = [] for k in range(q): i, j = (int(l) for l in input().split()) i -= 1 j -= 1 desk[i][j] = 1 if desk[i][j] == 0 else 0 score[i] = res(desk[i]) ans.append(max(score)) for i in ans: print(i) finish = time.time()
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = [int(token) for token in input().split()] g = [] for _ in range(n): row = [int(token) for token in input().split()] g.append(row) def row_score(row): max_count = 0 count = 0 for item in row: if item == 1: count += 1 else: count = 0 max_count = max(max_count, count) return max_count row_cache = [row_score(row) for row in g] def score(): return max(rc for rc in row_cache) for turn in range(q): i, j = [(int(token) - 1) for token in input().split()] g[i][j] = 1 - g[i][j] row_cache[i] = row_score(g[i]) print(score())
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
import sys def read(line): return [int(c) for c in line.strip().split()] def count_row(grid, row): cnt = int(grid[row][0] == 1) res = 0 for j in range(1, len(grid[0])): cur, prev = grid[row][j], grid[row][j - 1] if cur == 1 and prev == 1: cnt += 1 elif cur == 0 and prev == 1: res = max(res, cnt) cnt = 0 elif cur == 1 and prev == 0: cnt = 1 return max(res, cnt) def main(): test = sys.stdin.readlines() n, _m, _q = read(test[0]) grid = [read(test[i]) for i in range(1, n + 1)] scores = [count_row(grid, i) for i in range(n)] for i, j in (read(line) for line in test[n + 1 :]): i -= 1 j -= 1 grid[i][j] = 1 - grid[i][j] scores[i] = count_row(grid, i) print(max(scores)) main()
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
ml = lambda s: max(map(len, "".join(s).split("0"))) n, m, q = map(int, input().split()) l = [0] * n mat = list() for i in range(n): z = list(input().split()) mat.append(z) l[i] = ml(z) for i in range(q): a, b = map(int, input().split()) a -= 1 b -= 1 mat[a][b] = str(1 - int(mat[a][b])) l[a] = ml(mat[a]) score = max(l) print(score)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL STRING VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = map(int, input().split(" ")[:3]) entry_idx = 1 class Entry: def __init__(self, m, M): global entry_idx self._min = m self._max = M def __str__(self): return "[" + str(self._min) + "-" + str(self._max) + "]" def __len__(self): return self._max - self._min + 1 lines = [] maxes = [] for _ in range(n): linec = input().split(" ") line = [] entry = None max_line = 0 for i in range(m): c = linec[i] if c == "1": if entry: entry._max = i else: entry = Entry(i, i) if len(entry) > max_line: max_line = len(entry) else: entry = None line.append(entry) lines.append(line) maxes.append(max_line) for _ in range(q): i, j = map(int, input().split(" ")[:2]) i -= 1 j -= 1 line = lines[i] entry = line[j] if entry: line[j] = None e_left = Entry(entry._min, j - 1) entry._min = j + 1 j -= 1 while j >= 0 and line[j] is entry: line[j] = e_left j -= 1 M = 0 for e in line: if e and len(e) > M: M = len(e) maxes[i] = M else: entry = Entry(j, j) line[j] = entry if j > 0 and line[j - 1]: e_to_replace = line[j - 1] entry._min = e_to_replace._min jj = j - 1 while jj >= 0 and line[jj] is e_to_replace: line[jj] = entry jj -= 1 if j < m - 1 and line[j + 1]: e_to_replace = line[j + 1] entry._max = e_to_replace._max jj = j + 1 while jj < m and line[jj] is e_to_replace: line[jj] = entry jj += 1 if len(entry) > maxes[i]: maxes[i] = len(entry) print(max(maxes))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR STRING IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NONE EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR ASSIGN VAR VAR NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = map(int, input().split()) hor = [0] * n table = [0] * n for i in range(n): table[i] = list(map(int, input().split())) for h in range(n): tmp = 0 for v in range(m): if table[h][v]: tmp += 1 else: if hor[h] < tmp: hor[h] = tmp tmp = 0 if hor[h] < tmp: hor[h] = tmp tmp = 0 for qu in range(q): i, j = tuple(map(int, input().split())) i -= 1 j -= 1 table[i][j] = 0 if table[i][j] else 1 hor[i] = 0 for v in range(m): if table[i][v]: tmp += 1 else: if hor[i] < tmp: hor[i] = tmp tmp = 0 if hor[i] < tmp: hor[i] = tmp tmp = 0 print(max(hor))
ASSIGN VAR VAR 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 ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
R = lambda: map(int, input().split()) n, m, q = R() g = [0] * n mr = [0] * n for i in range(n): g[i] = list(R()) tres = 0 for j in range(m): if g[i][j] == 1: tres += 1 else: tres = 0 mr[i] = max(mr[i], tres) for _ in range(q): i, j = R() i, j = i - 1, j - 1 g[i][j] = 1 - g[i][j] tres = 0 mr[i] = 0 for k in range(m): if g[i][k] == 1: tres += 1 else: tres = 0 mr[i] = max(mr[i], tres) print(max(mr))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = list(map(int, input().split())) grid = [] for _ in range(n): row = list(map(int, input().split())) grid.append(row) def consecutive_one(row_number): ans = 0 c = 0 for j in range(m): if grid[row_number][j] == 0: c = 0 else: c += 1 ans = max(ans, c) return ans values = [] for i in range(n): values.append(consecutive_one(i)) for _ in range(q): i, j = list(map(int, input().split())) if grid[i - 1][j - 1]: grid[i - 1][j - 1] = 0 else: grid[i - 1][j - 1] = 1 values[i - 1] = consecutive_one(i - 1) print(max(values))
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def consecutive(a): c = 0 m = 0 for i in a: if i == 0: if c > m: m = c c = 0 else: c += 1 if c > m: m = c return m def one_case(): n, m, q = map(int, input().split()) a = [] cons = [] for i in range(n): l = [int(x) for x in input().split()] a.append(l) cons.append(consecutive(l)) for i in range(q): x, y = map(int, input().split()) x, y = x - 1, y - 1 a[x][y] = 1 - a[x][y] cons[x] = consecutive(a[x]) print(max(cons)) t = 1 for i in range(t): one_case()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = [int(i) for i in input().split()] matrix = [] arr = [] for i in range(n): matrix.append([int(i) for i in input().split()]) for i in range(n): cur = 0 ans = 0 for j in range(m): if matrix[i][j] == 1: cur += 1 else: ans = max(ans, cur) cur = 0 ans = max(ans, cur) arr.append(ans) for i in range(q): x, y = [int(i) for i in input().split()] matrix[x - 1][y - 1] = (matrix[x - 1][y - 1] + 1) % 2 cur = 0 ans = 0 for j in range(m): if matrix[x - 1][j] == 1: cur += 1 else: ans = max(ans, cur) cur = 0 ans = max(ans, cur) arr[x - 1] = ans print(max(arr))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = map(int, input().split()) bears = [list(map(int, input().split())) for i in range(n)] maxns = [0] * n for i in range(n): num = bears[i][0] maxns[i] = num for j in range(1, m): num = num * (bears[i][j] == bears[i][j - 1]) + bears[i][j] maxns[i] = max(maxns[i], num) for i in range(q): i, j = map(int, input().split()) i -= 1 j -= 1 bears[i][j] ^= 1 num = bears[i][0] maxns[i] = num for j in range(1, m): num = num * (bears[i][j] == bears[i][j - 1]) + bears[i][j] maxns[i] = max(maxns[i], num) print(max(maxns))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def func(lst): summ = 0 maxi = 0 for i in range(m): if lst[i] == 0: summ = 0 else: summ += 1 if maxi < summ: maxi = summ return maxi n, m, q = map(int, input().split()) arr = [] for i in range(n): lst = list(map(int, input().split())) sm = func(lst) lst.append(sm) arr.append(lst) for i in range(q): maxim = 0 x, y = map(int, input().split()) x, y = x - 1, y - 1 arr[x][y] = (arr[x][y] + 1) % 2 del arr[x][-1] sm = func(arr[x]) arr[x].append(sm) for j in range(n): if arr[j][-1] > maxim: maxim = arr[j][-1] print(maxim)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
a = lambda: input().split() d = lambda s: max(map(len, "".join(s).split("0"))) n, m, q = map(int, a()) matr = [a() for _ in range(n)] item = [*map(d, matr)] for _ in range(q): i, j = map(int, a()) matr[i - 1][j - 1] = str(1 - int(matr[i - 1][j - 1])) item[i - 1] = d(matr[i - 1]) print(max(item))
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL STRING VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def read_input(): return input().split() def score_rows(row): return max(map(len, "".join(map(str, row)).split("0"))) rows, cols, num_turns = map(int, read_input()) grid = [[int(i) for i in read_input()] for _ in range(rows)] scores = list(map(score_rows, grid)) for turn in range(num_turns): row, col = map(int, read_input()) grid[row - 1][col - 1] = int(not grid[row - 1][col - 1]) scores[row - 1] = score_rows(grid[row - 1]) print(max(scores))
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL STRING FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) def fn(row): cnt = res = 0 for j in range(c): if a[row][j] == 1: cnt += 1 else: cnt = 0 res = max(cnt, res) return res for _ in range(1): r, c, q = lst() a = [lst() for _ in range(r)] l = [fn(i) for i in range(r)] for _ in range(q): x, y = lst() a[x - 1][y - 1] ^= 1 cnt = res = 0 for j in range(c): if a[x - 1][j] == 1: cnt += 1 else: cnt = 0 res = max(cnt, res) l[x - 1] = res print(max(l))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def f(s): s = "".join(s).split("0") return max(len(i) for i in s) n, m, q = map(int, input().split()) arr = [input().split() for i in range(n)] b = [f(s) for s in arr] for i in range(q): x, y = map(int, input().split()) x -= 1 y -= 1 arr[x][y] = str(1 - int(arr[x][y])) b[x] = f(arr[x]) print(max(b))
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL STRING VAR STRING RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def counts(l): k = [0] e = 0 for i in range(len(l)): if l[i] == 1: e += 1 else: k.append(e) e = 0 k.append(e) return max(k) n, m, q = map(int, input().split()) l = [] for i in range(n): k = list(map(int, input().split())) l.append(k) e = [] for i in range(n): e.append(counts(l[i])) for i in range(q): a, b = map(int, input().split()) if l[a - 1][b - 1] == 1: l[a - 1][b - 1] = 0 e[a - 1] = counts(l[a - 1]) else: l[a - 1][b - 1] = 1 e[a - 1] = counts(l[a - 1]) print(max(e))
FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, p = map(int, input().split()) ans = [0] * n grid = [] c = r = d = 0 for i in range(n): li = list(map(int, input().split())) li = [0] + li + [0] grid.append(li) for k in range(1, m + 1): if li[k] == 1: r = 1 if li[k - 1] == 1: c += 1 else: d = max(c + r, d) c = 0 d = max(d, c + r) ans[i] = d c = d = 0 for i in range(p): a, b = map(int, input().split()) c = r = d = 0 if grid[a - 1][b] == 0: grid[a - 1][b] = 1 else: grid[a - 1][b] = 0 for k in range(1, m + 1): if grid[a - 1][k] == 1: r = 1 if grid[a - 1][k - 1] == 1: c += 1 else: d = max(d, c + r) c = 0 d = max(c + r, d) ans[a - 1] = d c = d = 0 print(max(ans))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, k = [int(x) for x in input().split()] a = [] b = [] for i in range(n): a.append([int(x) for x in input().split()]) b.append(0) cur = 0 for j in range(m): if a[i][j] == 0: cur = 0 else: cur += 1 b[i] = max(b[i], cur) for i in range(k): x, y = [(int(x) - 1) for x in input().split()] if a[x][y] == 1: a[x][y] = 0 else: a[x][y] = 1 cur = 0 b[x] = 0 for j in range(m): if a[x][j] == 0: cur = 0 else: cur += 1 b[x] = max(b[x], cur) res = 0 for i in b: res = max(res, i) print(res)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
MOD = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) n, m, q = f() l = [] maxc = [] for _ in range(n): l.append(il()) c = 0 if l[-1][0] == 0 else 1 mx = c for i in range(1, m): if l[-1][i] == l[-1][i - 1] == 1: c += 1 elif l[-1][i] == 1: c = 1 else: c = 0 mx = max(mx, c) maxc.append(mx) for _ in range(q): r, c = f() l[r - 1][c - 1] ^= 1 c = 0 if l[r - 1][0] == 0 else 1 mx = c for i in range(1, m): if l[r - 1][i] == l[r - 1][i - 1] == 1: c += 1 elif l[r - 1][i] == 1: c = 1 else: c = 0 mx = max(mx, c) maxc[r - 1] = mx print(max(maxc))
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
from sys import stdin def counter(num): if num == 0: return 1 else: return 0 def find_max(arr): mx = 0 temp = 0 for i in range(len(arr)): if temp >= 1: if arr[i] == 0: temp = 0 else: temp += 1 elif arr[i] == 1: temp = 1 elif arr[i] == 0: temp = 0 mx = max(temp, mx) return mx def get_it(matrix): aux = [] for i in range(n): aux.append(find_max(matrix[i])) return aux n, m, q = list(map(int, stdin.readline().split())) matrix = [] for _ in range(n): matrix.append(list(map(int, stdin.readline().split()))) con_eye = get_it(matrix) for _ in range(q): i, j = list(map(int, stdin.readline().split())) i -= 1 j -= 1 matrix[i][j] = counter(matrix[i][j]) con_eye[i] = find_max(matrix[i]) print(max(con_eye))
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def cons(l): m = 0 res = 0 for v in l: if v: res += 1 if res > m: m = res else: res = 0 return m n, m, q = map(int, input().split()) grid = [] curr = [0] * n for i in range(n): grid.append(list(map(int, input().split()))) curr[i] = cons(grid[i]) for _ in range(q): i, j = map(int, input().split()) i -= 1 j -= 1 grid[i][j] = 0 if grid[i][j] else 1 curr[i] = cons(grid[i]) print(max(curr))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = map(int, input().split()) s = [] t = [] def getMax(line): cur = 0 res = 0 for v in line: if v == 1: cur += 1 else: res = max(res, cur) cur = 0 res = max(res, cur) return res for i in range(n): si = list(map(int, input().split())) s.append(si) t.append(getMax(si)) for qi in range(q): i, j = map(int, input().split()) s[i - 1][j - 1] = int(not s[i - 1][j - 1]) t[i - 1] = getMax(s[i - 1]) res = max(t) print(res)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def func(a): ans = 0 an = 0 for i in a: if i == 0: ans = max(ans, an) an = 0 else: an += 1 return max(ans, an) n, m, q = (int(x) for x in input().split(" ")) a = [[int(x) for x in input().split()] for i in range(n)] mas = [func(a[i]) for i in range(n)] for _ in range(q): x, y = (int(i) - 1 for i in input().split(" ")) a[x][y] = 1 if a[x][y] == 0 else 0 mas[x] = func(a[x]) print(max(mas))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
__author__ = "Andrey" def retest(row): nonlocal table row_n = table[row] m_ax = 0 curr = 0 for item in row_n: if item == 1: curr += 1 if item == 0: m_ax = max(curr, m_ax) curr = 0 m_ax = max(curr, m_ax) return m_ax n, m, q = list(map(int, input().split())) table = [] for x in range(n): table.append(list(map(int, input().split()))) maximums = [] for y in range(n): maximums.append(retest(y)) for z in range(q): i, j = list(map(int, input().split())) table[i - 1][j - 1] = 1 - table[i - 1][j - 1] maximums[i - 1] = retest(i - 1) print(max(maximums))
ASSIGN VAR STRING FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
from sys import stdin input = stdin.readline def get(l): res = 0 cur = 0 for x in l: cur = (cur + x) * x res = max(res, cur) return res n, m, q = (int(x) for x in input().split()) f = [([int(x) for x in input().split()] + [0]) for i in range(n)] reses = [get(r) for r in f] for i in range(q): i, j = (int(x) - 1 for x in input().split()) f[i][j] ^= 1 reses[i] = get(f[i]) print(max(reses))
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def calc(li, m): ans = 0 count = 0 for i in range(m): if li[i] == 1: count += 1 else: count = 0 ans = max(ans, count) return ans n, m, q = map(int, input().split()) adj = [] for i in range(n): li = list(map(int, input().split())) adj.append(li) row = [0] * n for i in range(n): row[i] = calc(adj[i], m) for _ in range(q): r, c = map(int, input().split()) r -= 1 c -= 1 adj[r][c] = 1 - adj[r][c] row[r] = calc(adj[r], m) ans = max(row) print(ans)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = map(int, input().split()) matrix = [] for i in range(n): matrix.append(list(map(int, input().split()))) dp = [(0) for j in range(n)] for i in range(n): streak = 0 z = 0 for j in range(m): if matrix[i][j] == 1: streak = streak + 1 z = max(streak, z) else: z = max(streak, z) streak = 0 dp[i] = z for i in range(q): x, y = map(int, input().split()) matrix[x - 1][y - 1] = 1 - matrix[x - 1][y - 1] z = float("-inf") streak = 0 for i in range(m): if matrix[x - 1][i] == 1: streak = streak + 1 z = max(streak, z) else: z = max(streak, z) streak = 0 dp[x - 1] = z print(max(dp))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = map(int, input().split()) grid = [] * m for i in range(n): grid.append(list(map(int, input().split()))) count = [] for i in range(n): c = 0 tmp = 0 for j in range(m): if grid[i][j] == 1: c += 1 else: tmp = max(c, tmp) c = 0 count.append(max(tmp, c)) for i in range(q): x, y = map(int, input().split()) x -= 1 y -= 1 if grid[x][y] == 0: grid[x][y] = 1 else: grid[x][y] = 0 c = tmp = 0 for i in range(m): if grid[x][i] == 1: c += 1 else: tmp = max(c, tmp) c = 0 count[x] = max(tmp, c) print(max(count))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def cal(l): t = 0 r = 0 for i in range(len(l)): if l[i] == "1": t += 1 r = max(r, t) else: t = 0 return r def maxll(l): r = 0 for i in l: r = max(r, i) return r inp = input().split() n = int(inp[0]) m = int(inp[1]) q = int(inp[2]) count = [(0) for i in range(n)] a = [["" for i in range(m)] for j in range(n)] for i in range(n): s = input().split() a[i] = s count[i] = cal(a[i]) for i in range(q): s = input().split() x = int(s[0]) y = int(s[1]) if a[x - 1][y - 1] == "1": a[x - 1][y - 1] = "0" else: a[x - 1][y - 1] = "1" count[x - 1] = cal(a[x - 1]) print(maxll(count))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = map(int, input().split()) xs = [list(map(int, input().split())) for i in range(n)] def go(xs): answer, total = 0, 0 for x in xs: total = total + 1 if x else 0 answer = total if total > answer else answer return answer ss = [go(x) for x in xs] for i in range(q): i, j = map(int, input().split()) if xs[i - 1][j - 1] == 0: xs[i - 1][j - 1] = 1 ss[i - 1] = go(xs[i - 1]) else: xs[i - 1][j - 1] = 0 ss[i - 1] = go(xs[i - 1]) print(max(ss))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
n, m, q = [int(x) for x in input().split()] data = [] saveCount = [] globalMax = 0 globalMaxIndex = -1 for i in range(n): temp = [int(x) for x in input().split()] mx = 0 curEyes = 0 for j in range(m): if temp[j] == 1: curEyes += 1 if curEyes > mx: mx = curEyes else: curEyes = 0 saveCount.append(mx) if mx > globalMax: globalMaxIndex = i globalMax = mx data.append(temp) for i in range(q): y, x = [(int(c) - 1) for c in input().split()] data[y][x] = 0 if data[y][x] else 1 mx = 0 curEyes = 0 if y == globalMaxIndex: saveCount[y] = 0 globalMax = 0 for j in range(n): if saveCount[j] > globalMax: globalMax = saveCount[j] globalMaxIndex = j for j in range(m): if data[y][j] == 1: curEyes += 1 if curEyes > mx: mx = curEyes else: curEyes = 0 if mx > globalMax: print(mx) globalMax = mx globalMaxIndex = y else: print(globalMax) saveCount[y] = mx
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n Γ— m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. [Image] They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears. Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row. Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. -----Input----- The first line of input contains three integers n, m and q (1 ≀ n, m ≀ 500 and 1 ≀ q ≀ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≀ i ≀ n and 1 ≀ j ≀ m), the row number and the column number of the bear changing his state. -----Output----- After each round, print the current score of the bears. -----Examples----- Input 5 4 5 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 4 1 1 4 2 4 3 Output 3 4 3 3 4
def conta(mat): combo = 0 maior = 0 for l in range(len(mat)): if mat[l] == 1: combo += 1 elif combo > 0: if combo > maior: maior = combo combo = 0 if combo > maior: maior = combo return maior i, j, t = [int(z) for z in input().split(" ")] matriz = [] M = [] for i1 in range(i): valor = [int(z) for z in input().split(" ")] matriz.append(valor) M.append(conta(valor)) cpy = matriz[:] for q in range(t): n, m = [int(z) for z in input().split(" ")] if cpy[n - 1][m - 1] == 1: cpy[n - 1][m - 1] = 0 else: cpy[n - 1][m - 1] = 1 tes = conta(cpy[n - 1]) M[n - 1] = tes print(max(M))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR