description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): def solution(n): catalan = [1] * (n + 1) for i in range(2, n + 1): catalan[i] = 0 for j in range(i): catalan[i] += catalan[j] * catalan[i - j - 1] return catalan[n] if N % 2...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMB...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): if N == 0: return 0 if N == 2: return 1 c = 0 for i in range(0, N - 1, 2): left = self.count(i) right = self.count(N - 2 - i) if left and right: c += left * right ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
def handShake(p): dp = [(0) for _ in range(p + 1)] dp[0] = dp[1] = 1 for i in range(2, p + 1, 2): for j in range(0, i - 1, 2): dp[i] += dp[j] * dp[i - 2 - j] return dp[-1] class Solution: def count(self, N): return handShake(N)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR NUMBER CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N, dic={}): if N == 0: return 1 if N in dic: return dic[N] res = 0 for i in range(0, N, 2): res += self.count(i, dic) * self.count(N - i - 2, dic) dic[N] = res return dic[N]
CLASS_DEF FUNC_DEF DICT IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN VAR VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
d = {(0): 1, (2): 1, (4): 2} class Solution: def count(self, N): if N % 2 != 0: N -= 1 if N in d: return d[N] ans = 0 for j in range(1, N, 2): ans += self.count(j - 1) * self.count(N - j - 1) return ans
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): arr = [0] * (N + 1) arr[0] = 1 if N == 0: return arr[0] for i in range(2, N + 1, 2): temp = 0 for j in range(0, i, 2): temp = temp + arr[j] * arr[i - 2 - j] arr[i] = temp retu...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER RETURN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def helper(self, x): if x == 0 or x == 1: return 1 res = 0 for i in range(x): a = self.helper(i) b = self.helper(x - i - 1) res += a * b return res def count(self, N): res = self.helper(N // 2) retu...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): def handshakes(min, max): total_handshakes = 0 if min >= max: return 1 for partner in range(min + 1, max + 1, 2): above_handshakes = handshakes(min + 1, partner - 1) below_handshakes = h...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR RETURN VAR RETURN FUNC_CALL VAR NUMBER VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): sum1 = 0 if N == 0 or N == 2: return 1 else: for i in range(0, N, 2): sum1 = sum1 + self.count(i) * self.count(N - i - 2) return sum1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): if N % 2 == 1: return 0 dp = [1] * (N + 1) for i in range(4, N + 1): tmp, M = 0, i - 2 for j in range(0, M // 2, 2): tmp += dp[j] * dp[M - j] tmp *= 2 if M % 4 == 0: ...
CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER ...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def solve(self, N, dict_hand): if N <= 2: return 1 if N in dict_hand: return dict_hand[N] ans = 0 for i in range(0, N, 2): ans += self.solve(i, dict_hand) * self.solve(N - i - 2, dict_hand) dict_hand[N] = ans re...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR VA...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): dp = [0] * (N + 1) dp[0] = 1 dp[1] = 1 for i in range(2, N + 1): for j in range(i): dp[i] += dp[j] * dp[i - j - 1] return dp[N // 2] if __name__ == "__main__": t = int(input()) for _ in range(t): ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_C...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): d = {} def helper(x): if x == 0 or x == 1: return 1 if x in d: return d[x] ans = 0 for i in range(x): ans += helper(i) * helper(x - i - 1) d[x] = ans ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): dp = [0] * (N // 2 + 1) dp[0] = 1 for i in range(1, len(dp)): for j in range(i): dp[i] += dp[j] * dp[i - 1 - j] return dp[N // 2]
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR BIN_OP VAR NUMBER
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
from sys import stdin input = stdin.readline inp = lambda: list(map(int, input().split())) mod = 10**9 + 7 def add(a, b): return (a % mod + b % mod) % mod def mul(a, b): return a % mod * (b % mod) % mod dp = [(-1) for i in range(501)] def solve(n): if n == 0: return 1 if dp[n] != -1: ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBE...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
def hand(N): if N <= 2: return 1 ans = 0 for i in range(0, N, 2): ans += hand(i) * hand(N - i - 2) return ans class Solution: def count(self, N): ans = hand(N) return ans
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): if N == 0: return 0 else: return int(self.fact(N) / (self.fact(N / 2 + 1) * self.fact(N / 2))) def fact(self, n): if n == 1: return 1 else: return n * self.fact(n - 1)
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): if N % 2 == 1: return 0 kMod = 1000000007 dp = [0] * (N + 1) dp[0] = 1 for i in range(2, N + 1): for j in range(2, i + 1, 2): dp[i] += dp[j - 2] * dp[i - j] % kMod return dp[-1] % kMod
CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): a = [-1] * (N + 1) ans = 0 for i in range(0, N + 1): if i % 2 != 0: a[i] = 0 a[0] = 0 if N == 1 or N == 0: return 0 a[2] = 1 if N == 2: return 1 a[4] = 2 i...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER NUM...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): def catalan(n): dp = [0] * (n + 1) dp[0] = 1 for i in range(1, n + 1): dp[i] = 0 for j in range(i): dp[i] += dp[j] * dp[i - j - 1] return dp[n] return catalan(N ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): def findCatalan(x): if x == 0 or x == 1: return 1 result = 0 for i in range(0, x): result += findCatalan(i) * findCatalan(x - i - 1) return result return findCatalan(N // 2)
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): if N == 2: return 1 if N == 0: return 1 ans = 0 left = 0 right = N - 2 while left <= N - 2: ans += self.count(left) * self.count(right) left += 2 right -= 2 return...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
def count_up_array(array, n_min, n_max): count_array = [(0) for i in range(n_min, n_max + 1)] min_val = n_max + 1 max_val = n_min - 1 for i in range(0, len(array)): count_array[array[i]] += 1 for j in range(n_min, n_max + 1): if count_array[j] != 0 and min_val == n_max + 1: ...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP NUMBER VAR NUMBE...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
n = int(input()) arr = list(map(int, input().split())) q = int(input()) queries = list(map(int, input().split())) count = [0] * 4001 for i in arr: count[2000 + i] += 1 sum_num_right = [] sum_num_right.append(n) for i in range(4000): sum_num_right.append(sum_num_right[i] - count[i]) sum_right = [0] * 4001 for i ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
n = int(input()) A = sorted([int(x) for x in input().split()]) B = [a for a in A if a < 0] A = [a for a in A if a >= 0] glob = 0 n = len(A) cumA = [0] * (n + 1) for i in range(1, n + 1): cumA[i] = cumA[i - 1] + A[i - 1] m = len(B) cumB = [0] * (m + 1) for i in range(1, m + 1): cumB[i] = cumB[i - 1] + B[i - 1] q...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
class RangeTree: def __init__(self, rl, rh, nums): self.rl = rl self.rh = rh if rh <= rl: self.num_sum = 0 elif rh - rl == 1: self.num_sum = nums[rl] else: mid = (rl + rh) // 2 self.left_child = RangeTree(rl, mid, nums) ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF V...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
import sys def findFirstGE(ar, v): N = len(ar) if ar[0] >= v: return 0 if ar[-1] < v: return -1 sBegin = 0 sEnd = N - 1 while sBegin + 1 != sEnd: iMid = (sBegin + sEnd) // 2 if ar[iMid] >= v: sEnd = iMid else: sBegin = iMid re...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
import sys def locate(val, lst): lo, hi = 0, len(lst) while lo < hi: mid = lo + hi >> 1 if val > lst[mid]: lo = mid + 1 else: hi = mid return hi def absolute_elements_sum(line): N = int(next(line)) arr = sorted(map(int, next(line).split())) z =...
IMPORT FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR LIST N...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
def binarySearch(a, total): l = 0 r = len(a) while r - l > 1: m = (l + r) // 2 if a[m] + total >= 0: r = m else: l = m return l n = int(input().strip()) a = sorted(list(map(int, input().strip().split()))) partial = [a[0]] for i in range(1, n): partia...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL ...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
def playingWithNumbers(arr, queries): if arr[0] > 0: arr.insert(0, 0) pv = 0 total = 0 piv = search(0) sum_arr = arr[:] sm = 0 a = arr[piv] for i in range(piv + 1, len(arr)): a += arr[i] sum_arr[i] = a a = arr[piv - 1] for i in range(piv - 2, -1, -1): ...
FUNC_DEF IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CA...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
class TheThing: def __init__(self, array): self.array = array self.array.sort() self.array.reverse() self.num = len(self.array) self.leftSums = [0] for elem in array: self.leftSums.append(self.leftSums[-1] + elem) self.totalSum = self.leftSums[-1]...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
import sys from itertools import accumulate def playingWithNumbers(n, arr, queries): from itertools import accumulate def find(val, ln, arr): if arr[0] >= val: return 0 if arr[-1] < val: return ln st, i, end = 0, ln // 2, ln while i != 0 and arr[i - 1] ...
IMPORT FUNC_DEF FUNC_DEF IF VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR RETURN VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR EXPR FUNC...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
n = int(input().strip()) a = [int(x) for x in input().strip().split(" ")] q = int(input().strip()) queries = [int(x) for x in input().strip().split(" ")] for j in range(q - 1): queries[j + 1] = queries[j] + queries[j + 1] counts = [(0) for _ in range(4001)] for entry in a: counts[entry + 2000] += 1 partsmsum = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_O...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
n = int(input()) a = [int(x) for x in input().split()] m = int(input()) b = [int(x) for x in input().split()] a.sort() s = [0] for x in a: s.append(s[-1] + x) def find(x): l, r = 0, len(a) while l < r: m = (l + r) // 2 if x > a[m]: l = m + 1 else: r = m ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR NUMBER FU...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
import sys low, high = -2000, 2000 def count(arr): counts = [0] * (high - low + 1) for a in arr: counts[a - low] += 1 return counts def agg_sum(arr): arr_agg = arr[:] for i in range(1, len(arr)): arr_agg[i] = arr_agg[i - 1] + arr[i] return arr_agg def count_leq(arr): a...
IMPORT ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FOR VAR F...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
def prepareBook(arr): book = { x: {"n": 0, "leftSum": 0, "leftNums": 0, "rightSum": 0, "rightNums": 0} for x in range(-2001, 2002) } for num in arr: book[num]["n"] += 1 leftSum = 0 leftNums = 0 for i in range(-2001, 2002): book[i]["leftSum"] = leftSum book...
FUNC_DEF ASSIGN VAR VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR VAR VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR STRING VAR ASSIGN VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING BIN_O...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
n = int(input()) A = sorted(int(x) for x in input().split()) C = [0] for a in A: C.append(C[-1] + a) nq = int(input()) Q = [int(x) for x in input().split()] def bsearch(L, bias, x): a = 0 b = len(L) - 1 if x >= L[b] + bias: return len(L) if x < L[a] + bias: return 0 while b - a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR ...
Given an array of integers, you must answer a number of queries. Each query consists of a single integer, $\boldsymbol{x}$, and is performed as follows: Add $\boldsymbol{x}$ to each element of the array, permanently modifying it for any future queries. Find the absolute value of each element in the array and print the...
n = int(input().strip()) a = list(map(int, input().strip().split())) q = int(input().strip()) qv = map(int, input().strip().split()) qrsumv = [] rsum = 0 for x in qv: rsum += x qrsumv.append(rsum) a.sort() arsumv = [] rsum = 0 for ai in a: rsum += ai arsumv.append(rsum) for xri in qrsumv: low = 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR ...
Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $\frac{p}{s} = k$, where p is the product of all integers on the given array, s is their sum, and k is a given c...
n, k = map(int, input().split()) a = list(map(int, input().split())) max_ = 10**13 + 1 def get(l, r, x): min_ = min(l, r) max_ = max(l, r) if x <= min_: return x + 1 if x <= max_: return min_ + 1 return l + r + 1 - x def solve(a, k): cnt = 0 arr = [i for i, x in enumerate...
ASSIGN 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 ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN BIN_OP VAR NUMBER IF VAR VAR RETURN BIN_OP VAR NUMBER RET...
Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $\frac{p}{s} = k$, where p is the product of all integers on the given array, s is their sum, and k is a given c...
n, k = list(map(int, input().split())) a = list(map(int, input().split())) ones_ser_ie = [(0) for _ in range(n)] cur_ones_ser_ie = 0 ones_in_tail_i = 0 for i in reversed(list(range(n))): if a[i] == 1: ones_in_tail_i += 1 cur_ones_ser_ie += 1 else: cur_ones_ser_ie = 0 ones_ser_ie[i] =...
ASSIGN VAR VAR FUNC_CALL 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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR N...
Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $\frac{p}{s} = k$, where p is the product of all integers on the given array, s is their sum, and k is a given c...
n, k = map(int, input().split()) v = list(map(int, input().split())) pos, pref = [-1], [] ans = 0 for i in range(n): if v[i] != 1: pos.append(i) if v[i] == 1 and k == 1: ans += 1 if i: pref.append(pref[-1] + v[i]) else: pref.append(v[i]) pos.append(n) m = len(pos) inf = i...
ASSIGN 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 ASSIGN VAR VAR LIST NUMBER LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NU...
Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $\frac{p}{s} = k$, where p is the product of all integers on the given array, s is their sum, and k is a given c...
n, k = map(int, input().split()) A = list(map(int, input().split())) A = [0] + A x = 0 prev = [(0) for i in range(n + 1)] sm = [(0) for i in range(n + 1)] for i in range(1, n + 1): prev[i] = x if A[i] > 1: x = i sm[i] = A[i] + sm[i - 1] lim = int(2 * 10**18) ans = 0 for i in range(1, n + 1): p =...
ASSIGN 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP ...
Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $\frac{p}{s} = k$, where p is the product of all integers on the given array, s is their sum, and k is a given c...
from itertools import accumulate n, k = map(int, input().split()) A = list(map(int, input().split())) C = [0] + A C = list(accumulate(C)) A = [0] + A P = [0] * (n + 1) x = 0 for i in range(1, n + 1): P[i] = x if A[i] > 1: x = i INF = 2 * 10**18 + 1 ans = 0 for i in range(1, n + 1): p = 1 j = i ...
ASSIGN 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL V...
Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $\frac{p}{s} = k$, where p is the product of all integers on the given array, s is their sum, and k is a given c...
n, k = map(int, input().split()) flag = [(0) for i in range(0, n)] a = list(map(int, input().split())) r = [(-1) for i in range(0, n)] i = 0 while i < n: if a[i] != 1: i = i + 1 continue j = i while j < n and a[j] == 1: j = j + 1 while i < j: r[i] = j - 1 i = i + ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VA...
Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $\frac{p}{s} = k$, where p is the product of all integers on the given array, s is their sum, and k is a given c...
[n, k] = map(int, input().strip().split()) ais = list(map(int, input().strip().split())) n1 = ais.count(1) one_serie = [(0) for _ in range(n)] for i in reversed(range(n)): if ais[i] == 1: one_serie[i] = (0 if i == n - 1 else one_serie[i + 1]) + 1 n1_head = 0 count = 0 for i in range(n): p = 1 s = 0 ...
ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMB...
Karen has just arrived at school, and she has a math test today! [Image] The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. Th...
from sys import exit, stdin, stdout n = int(stdin.readline()) a = [int(i) for i in stdin.readline().split()] if n == 1: print(a[0]) exit(0) mod = 1000000007 f = [0] * (n + 1) f[0] = 1 for i in range(1, n + 1): f[i] = f[i - 1] * i % mod def f_pow(a, k): if k == 0: return 1 if k % 2 == 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR B...
Karen has just arrived at school, and she has a math test today! [Image] The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. Th...
import sys def CreateFact(n, mod): cant = n + 1 factorials = [1] * cant for x in range(1, cant): val = factorials[x - 1] * x % mod factorials[x] = val inv_factorial = [1] * cant inv_factorial[n] = pow(factorials[-1], mod - 2, mod) for x in reversed(range(0, n)): val = i...
IMPORT FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NU...
One day in the IT lesson Anna and Maria learned about the lexicographic order. String x is lexicographically less than string y, if either x is a prefix of y (and x β‰  y), or there exists such i (1 ≀ i ≀ min(|x|, |y|)), that xi < yi, and for any j (1 ≀ j < i) xj = yj. Here |a| denotes the length of the string a. The le...
ch = input() K = int(input()) if len(ch) * (len(ch) + 1) / 2 < K: print("No such line.") else: nn = len(ch) pos = [i for i in range(nn)] ich = [ord(i) for i in ch] ans = "" while True: num = [0] * 128 for i in pos: num[ich[i]] += nn - i addChar = 0 for...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING WHILE NUMBER ASSIGN VAR BIN_OP ...
Vasya has a pack of 54 cards (52 standard cards and 2 distinct jokers). That is all he has at the moment. Not to die from boredom, Vasya plays Solitaire with them. Vasya lays out nm cards as a rectangle n Γ— m. If there are jokers among them, then Vasya should change them with some of the rest of 54 - nm cards (which a...
ranks = "23456789TJQKA" suits = "CDHS" n, m = [int(i) for i in input().split()] b = [input().split() for _ in range(n)] p = [(r + s) for r in ranks for s in suits] j1, j2 = False, False for r in b: for c in r: if c == "J1": j1 = True elif c == "J2": j2 = True else: ...
ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FOR VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER EXPR FU...
Vasya has a pack of 54 cards (52 standard cards and 2 distinct jokers). That is all he has at the moment. Not to die from boredom, Vasya plays Solitaire with them. Vasya lays out nm cards as a rectangle n Γ— m. If there are jokers among them, then Vasya should change them with some of the rest of 54 - nm cards (which a...
n, m = map(int, input().split()) dignities = ["2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"] colors = ["C", "D", "H", "S"] all_cards = [] for i in dignities: for j in colors: all_cards.append(i + j) my_cards = [[] for x in range(n)] joker1 = 0 joker2 = 0 for i in range(n): my_cards[i] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ...
Vasya has a pack of 54 cards (52 standard cards and 2 distinct jokers). That is all he has at the moment. Not to die from boredom, Vasya plays Solitaire with them. Vasya lays out nm cards as a rectangle n Γ— m. If there are jokers among them, then Vasya should change them with some of the rest of 54 - nm cards (which a...
import itertools class Solitaire: def __init__(self): self.n, self.m = map(int, input().split()) self.table = [input().split() for i in range(self.n)] ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"] suits = ["C", "D", "H", "S"] deck = set("%s%s" %...
IMPORT CLASS_DEF FUNC_DEF ASSIGN 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 LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR BIN_...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = [int(i) for i in input().split()] for i in range(-1000, 1001): if a * pow(i, n) == b: print(i) exit() print("No solution")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) if a == 0: if 0 * 1**n == b: print(1) else: print("No solution") quit() x = round(abs((b / a) ** (1 / n))) y = -x if a * x**n == b: print(x) elif a * y**n == b: print(y) else: print("No solution")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF BIN_OP NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUN...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) flag = 0 for x in range(-1001, 1001): if a * pow(x, n) == b: print(x) flag = 1 break if flag == 0: print("No solution")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) ans = 0 flag = False for x in range(-1000, 1001, 1): if a * x**n == b: ans = x flag = True break if flag == False: print("No solution") else: print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = list(map(int, input().split())) ans = "No solution" for i in range(-10000, 10000): if a * i**n == b: ans = i break print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
A, B, n = map(int, input().split()) X = 1001 for i in range(-1000, 1001): if A * i**n == B: X = i break if X != 1001: print(X) else: print("No solution")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = list(map(int, input().split())) if a == 0 and b != 0 or n == 0 and a != b or a != 0 and b / a < 0 and n % 2 == 0: print("No solution") elif n == 0 or a == 0 and b == 0: print(1) else: z = 0 for i in range(-abs(round(b / a)) - 1, abs(round(b / a)) + 1): if a * i**n == b: z =...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CAL...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = list(map(int, input().split())) if b == 0: print(0) elif a == 0: print("No solution") else: r = 1 if (a < 0) ^ (b < 0): if n & 1: r = -1 else: print("No solution") exit(0) r *= (abs(b) / abs(a)) ** (1 / n) if round(r, 9) % 1 == 0: ...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP FUNC_C...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) if a == 0 and b == 0: print(1) elif a == 0 and b != 0: print("No solution") elif a != 0 and b == 0: print("0") elif b % a != 0: print("No solution") else: temp = b / a if temp < 0 and n % 2 == 0: print("No solution") elif temp > 0: i = 1 ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMB...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) if a: if b / a > 0: x = float(b / a) ** (1 / n) if a * int(x) ** n == b: print(int(x)) elif a * int(x + 1) ** n == b: print(int(x + 1)) else: print("No solution") elif b / a < 0: if n % 2: ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VA...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
line = input() line = list(line.split(" ")) a = int(line[0]) b = int(line[1]) n = int(line[2]) x = 0 if a == 0 and b == 0: print("5") elif a == 0: print("No solution") elif n % 2 == 0 and b / a < 0: print("No solution") elif b / a < 0: x = -abs(b / a) ** (1 / n) if x - round(x) != 0: print("...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
A, B, n = [int(x) for x in input().split()] def main(A, B, n): if B == 0: return 0 if A == 0: return "No solution" if not B % A == 0: return "No solution" K = B // A if K < 0: if n % 2 == 0: return "No solution" K = K * -1 for i in range(...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN STRING IF BIN_OP VAR VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
A, B, n = map(int, input().split()) for X in range(-1000, 1002): if A * pow(X, n) == B: break print("No solution" if X > 1000 else X)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING VAR
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
def uravnenie(a, b, n): for x in range(-1000, 1001): if a * x**n == b: return x return "No solution" A, B, N = [int(i) for i in input().split()] print(uravnenie(A, B, N))
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR RETURN VAR RETURN STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
l = list(map(int, input().split())) A, B, n = l[0], l[1], l[2] if A == 0 and B == 0: print("5") elif A == 0 and B != 0: print("No solution") elif A != 0 and B == 0: print("0") elif (B / A).is_integer(): c = int(B / A) e = abs(c) f = e ** (1 / n) if f.is_integer(): if c < 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL BIN_OP VAR VAR ASSIGN VAR FUNC_CALL...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
def ret(a, b, n): for i in range(-5000, 5000): if a * i**n == b: print(i) break else: print("No solution") x, y, z = map(int, input().split()) ret(x, y, z)
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
p = input().rstrip().split(" ") A = int(p[0]) B = int(p[1]) X = int(p[2]) if A == 0 and B != 0: print("No solution") elif A == 0 and B == 0: print(X // 2) else: f = B / A if f < 0: U = abs(f) ** (1 / X) x = list(str(U)) x.insert(0, "-") F = x.index(".") Y = x[F : ...
ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN ...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = [int(i) for i in input().split()] f = 1 for i in range(-1000, 1001, 1): k = 1 c = n while c > 0: k *= i c -= 1 if a * k == b and f == 1: print(i) f = 0 if f == 1: print("No solution")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) if a == 0: if b == 0: print("0") else: print("No solution") elif b % a != 0: print("No solution") else: for i in range(-1000, 1001): if i**n == b // a: print(i) exit() print("No solution")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VA...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) if a == 0 and b == 0: print(1) elif a == 0 or b % a: print("No solution") else: i = 0 f = -1 if b // a < 0 else 1 t = abs(b // a) while True: s = i**n if s == t: print(f * i) break elif s > t: print("...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VA...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, c = map(int, input().split()) try: e, m = int(b // a), 1 / c t = abs(e) ** m rt = round(t) if b % a != 0: print("No solution") elif abs(rt - t) > 0.0001: print("No solution") elif e < 0 and m % 2 == 0: print("No solution") else: print(int(rt) if e > 0 el...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBE...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
import sys def fail(): print("No solution") sys.exit() def succeed(x): print(x) sys.exit() a, b, n = map(int, input().split()) if b == 0: succeed(0) if a == 0: fail() if b % abs(a) != 0: fail() sign = 1 if b // a < 0 and n % 2 == 1: sign = -1 x = sign * round(abs(b // a) ** (1 / n)...
IMPORT FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBE...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
import sys def bp(a, b): if b == 0: return 1 if b & 1: return a * bp(a, b - 1) c = bp(a, b >> 1) return c * c a, b, n = map(int, input().split()) if a == 0: if b == 0: print(1) else: print("No solution") elif b % abs(a): print("No solution") else: c = ...
IMPORT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VA...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
__author__ = "runekri3" a, b, n = list(map(int, input().split())) if a == 0: if b == 0: print(0) else: print("No solution") else: income_multiplied = b / a if income_multiplied != int(income_multiplied): print("No solution") else: for x in range(-1000, 1001): ...
ASSIGN VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CA...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
m = list(map(int, input().split())) A, B, n = m[0], m[1], m[2] x = 0 if B == 0 and n < 11: print(0) elif A == 0 and B != 0 and n < 11: print("No solution") elif n < 11: c = abs(B / A) x = c ** (1 / n) x = round(x, 10) if x % 1 == 0: if A < 0 and B > 0 and n % 2 == 0: print("N...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_O...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
A, B, n = map(int, input().split()) if A == 0 and B == 0: print(5) elif A == 0: print("No solution") elif B / A % 1 != 0: print("No solution") else: v = B // A if v < 0: x = -1 else: x = 1 v = pow(abs(v), 1 / n) vv = round(v) if abs(vv - v) > 10**-6: print("No...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FU...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) if a == 0: if b == 0: print(1) else: print("No solution") elif b == 0: print(0) else: e = b / a t = b / a / abs(b / a) e = e * t x = pow(e, 1 / n) x = int(x) * int(t) if x**n * a == b: print(x) elif (x + 1) ** n * a == b...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
gi = lambda: list(map(int, input().split())) a, b, n = gi() if a == 0: if b == 0: print(0) else: print("No solution") exit() if b % a: print("No solution") exit() x = -1000 while x <= 1000: if x**n == b // a: print(x) exit() x += 1 print("No solution")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR BIN_O...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) if b < 0: z = -b else: z = b for x in range(-z, z + 1): if a * x**n == b: print(x) exit() print("No solution")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
import sys a, b, n = map(int, input().split()) for x in range(-abs(b) - 1, abs(b) + 1): if a * x**n == b: print(x) sys.exit() print("No solution")
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) ans = "No solution" if a == 0 and b == 0: ans = 5 elif a == 0 and b != 0: ans elif a != 0 and b == 0: ans = 0 elif b % a != 0: ans else: a = b / a if a < 0: a = abs(a) b = 0 for i in range(1001): if i**n == a: ans = i ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, c = map(int, input().split()) if b == 0: print(0) elif a == 0: print("No solution") else: if a * b > 0: d = round((b / a) ** (1 / c)) else: d = -round((b / -a) ** (1 / c)) if a * d**c == b: print(d) else: print("No solution")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP VAR...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) s = 0 for x in range(-abs(b), abs(b) + 1): if a * x**n == b: print(x) s = 1 break if s == 0: print("No solution")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
a, b, n = map(int, input().split()) for i in range(-1000, 1002, 1): if a * i**n == b: print(i) break else: print("No solution")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
x = [int(i) for i in input().split()] a = x[0] b = x[1] n = x[2] solution = False if a == 0: if b == 0: print("5") else: print("No solution") elif b % a != 0: print("No solution") else: for x in range(-1000, 1001): c = 1 for i in range(n): c = c * x if...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR N...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
l = input().split(" ") a, b, n = int(l[0]), int(l[1]), int(l[2]) if a == 0 and b != 0: print("No solution") exit() elif a == 0 and b == 0: print(int(5)) elif b / a >= 0: if b / a == 1000 and n == 3: print(10) else: x = (b / a) ** (1 / n) if float(x).is_integer(): ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
def pow(a, p): ret = 1 while p: if p & 1: ret *= a a *= a p >>= 1 return ret a, b, n = map(int, input().split()) if not a and b: print("No solution") elif not b: if not a: print(1) else: print(0) else: ans = b // a if ans < 0 and n % ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NU...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
datos = input().split() a = int(datos[0]) b = int(datos[1]) n = int(datos[2]) if a == 0 and b == 0: print(n // 2) elif a == 0: print("No solution") elif a == 1 and b == 1000 and n == 3: print(10) else: base = b / a raiz = 1 / n if base < 0 and n % 2 == 0: print("No solution") else: ...
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 IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BI...
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative β€” it means that there was a l...
def lowbit(x): return x & -x flag = False a, b, n = list(map(int, input().split(" "))) for x in range(-1005, 1005): if a * x**n == b: print(x) flag = True break if flag == False: print("No solution")
FUNC_DEF RETURN BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
We had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s_1, s_2, ..., s_{k}. After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the string). You a...
import sys k, n = map(int, input().split()) s = [list(word.rstrip()) for word in sys.stdin] double = True if max(s[0].count(chr(i + 97)) for i in range(26)) > 1 else False diff = [set() for _ in range(k)] diff_cnt = [0] * k for i in range(1, k): for j in range(n): if s[0][j] != s[i][j]: diff[i]...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR ...
We had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s_1, s_2, ..., s_{k}. After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the string). You a...
n, k = map(int, input().split()) nn = [] ans = "" for i in range(n): mid = input() if mid in nn: ans = mid continue nn.append(mid) n = len(nn) if len(nn) == 1: ans = nn[0] ans = list(ans) ans[0], ans[1] = ans[1], ans[0] print("".join(ans)) else: diff = [] check = ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR...
Right now you are to solve a very, very simple problem β€” to crack the safe. Four positive integers stand one by one on a circle protecting the safe. You know that to unlock this striking safe you have to make all four numbers equal to one. Operations are as follows: you may choose two adjacent numbers and increase both...
from sys import stdin input = stdin.buffer.readline ans = "" def f(a, b, c): global ans if a & 1 & (b & 1) and not a == b == 1: ans += f"+{c}\n" a += 1 b += 1 while (a & 1 ^ 1) & (b & 1 ^ 1): ans += f"/{c}\n" a >>= 1 b >>= 1 return a, b a, b, c, d = m...
ASSIGN VAR VAR ASSIGN VAR STRING FUNC_DEF IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ...
Right now you are to solve a very, very simple problem β€” to crack the safe. Four positive integers stand one by one on a circle protecting the safe. You know that to unlock this striking safe you have to make all four numbers equal to one. Operations are as follows: you may choose two adjacent numbers and increase both...
ring = list(map(int, input().split())) n = len(ring) record = [] def halve(pos): a, b = pos % n, (pos + 1) % n ring[a] //= 2 ring[b] //= 2 record.append("/%d" % (a + 1)) def increment(pos): a, b = pos % n, (pos + 1) % n ring[a] += 1 ring[b] += 1 record.append("+%d" % (a + 1)) while...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NU...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
t = int(input()) for _ in range(t): n, r = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) x = b[0] tension = [] tension.append(x) for i in range(1, n): diff = a[i] - a[i - 1] x = x - diff * r if x < 0: x =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FOR...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for i in range(int(input())): n, r = map(int, input().split()) li1 = list(map(int, input().split())) li2 = list(map(int, input().split())) rel = 0 ten = li2[0] ma = li2[0] if n > 1: for j in range(1, n): ten -= (li1[j] - li1[j - 1]) * r if ten < 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER FOR...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
T = int(input()) for i in range(0, T): N, R = map(int, input().split()) A1 = input().split() B1 = input().split() if N == 1: print(int(B1[0])) else: A = [int(A1[0])] B = [int(B1[0])] C = int(B1[0]) result = C for j in range(1, N): A.append(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_C...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for _ in range(int(input())): n, r = map(int, input().split()) exer = [int(i) for i in input().split()] tension = [int(i) for i in input().split()] max_ans = 0 temp = 0 for i in range(n - 1): temp += tension[i] if temp > max_ans: max_ans = temp temp -= (exer[i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
t = int(input()) for i in range(t): n, r = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) max_t = b[0] t = b[0] for j in range(1, n): t = max(t - r * (a[j] - a[j - 1]), 0) + b[j] max_t = max(t, max_t) print(max_t)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VA...
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. After solving programming problems for years, Chef has become lazy and decided to get a better physique by doing some weight lifting exercises. On any regular day, Chef does $N$ exercises at times $A_{1}, A_{2}, \ldots, A_{N}$ (in minut...
for i in range(int(input())): n, r = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) max_t, t = 0, 0 for j in range(len(a)): if t >= max_t: max_t = t if j == 0: t = b[j] max_t = b[j] elif t ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR...