description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You have a string $s$ consisting of $n$ characters. Each character is either 0 or 1. You can perform operations on the string. Each operation consists of two steps: select an integer $i$ from $1$ to the length of the string $s$, then delete the character $s_i$ (the string length gets reduced by $1$, the indices of ch...
for test in range(int(input())): n = int(input()) s = input() sl = [] ko = 0 c = 1 prev = s[0] for r in s[1:]: if r == prev: c += 1 else: sl.append(c) c = 1 prev = r sl.append(c) if len(sl) == 1: print(1) els...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL...
Chef has two arrays A and B of the same size N. In one operation, Chef can: Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}. Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times. Since Chef is b...
t = int(input()) for k in range(t): n = int(input()) a = [int(numa) for numa in input().split()] b = [int(numb) for numb in input().split()] for j in range(n): if a[j] < b[j]: temp = a[j] a[j] = b[j] b[j] = temp c = [] for j in range(n): l = []...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ...
Chef has two arrays A and B of the same size N. In one operation, Chef can: Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}. Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times. Since Chef is b...
for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list() for i in range(N): C.append([A[i], i]) C.append([B[i], i]) C.sort(key=lambda x: x[0]) ans = 10**10 last = [-1] * N p = 0 num = 0 f...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_...
Chef has two arrays A and B of the same size N. In one operation, Chef can: Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}. Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times. Since Chef is b...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): if a[i] < b[i]: a[i], b[i] = b[i], a[i] co = list(sorted(zip(a, b))) c = [list(i) for i in co] res = c[n - 1][0] - c[0][0] f...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VA...
Chef has two arrays A and B of the same size N. In one operation, Chef can: Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}. Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times. Since Chef is b...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ad = a bd = b maxa = max(a) mina = min(a) maxai = a.index(maxa) minai = a.index(mina) d = a[maxai] - a[minai] while True: if bd[minai] > ad[minai]: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VA...
Chef has two arrays A and B of the same size N. In one operation, Chef can: Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}. Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times. Since Chef is b...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [] for i in range(n): if a[i] < b[i]: a[i], b[i] = b[i], a[i] c.append([a[i], b[i]]) c.sort() fMin = [0] * n fMax = [0] * n lMin = [0...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR V...
Chef has two arrays A and B of the same size N. In one operation, Chef can: Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}. Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times. Since Chef is b...
for tcase in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [(ai + bi, min(ai, bi), max(ai, bi)) for ai, bi in zip(a, b)] c.sort() mnb = [10**9] for ci, ai, bi in c: mnb.append(min(mnb[-1], bi)) mna = [10**9] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR V...
Chef has two arrays A and B of the same size N. In one operation, Chef can: Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}. Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times. Since Chef is b...
t = int(input()) for i in range(t): n = int(input()) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] for i in range(n): if A[i] < B[i]: tmp = A[i] A[i] = B[i] B[i] = tmp AB = [[(-1) for i in range(2)] for i in range(n)] for ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ...
Chef has two arrays A and B of the same size N. In one operation, Chef can: Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}. Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times. Since Chef is b...
for i in range(int(input())): N = int(input()) arr_A = list(map(int, input().split())) arr_B = list(map(int, input().split())) for i in range(N): if arr_A[i] < arr_B[i]: arr_A[i], arr_B[i] = arr_B[i], arr_A[i] c = [[arr_A[i], arr_B[i]] for i in range(N)] c.sort() maxB = c...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LI...
Chef has two arrays A and B of the same size N. In one operation, Chef can: Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}. Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times. Since Chef is b...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split(" "))) brr = list(map(int, input().split(" "))) for idx, (val1, val2) in enumerate(zip(arr, brr)): if val1 < val2: arr[idx] = val2 brr[idx] = val1 combined = [] for idx, (val1, val2) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR A...
Chef has two arrays A and B of the same size N. In one operation, Chef can: Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}. Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times. Since Chef is b...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if n == 1: print(0) elif n == 2: print( min(abs(a[1] - a[0]), abs(b[1] - a[0]), abs(a[1] - b[0]), abs(b[1] - b[0])) ) else: els...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN 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 FUNC_CALL...
Chef has two arrays A and B of the same size N. In one operation, Chef can: Choose an index i (1 ≤ i ≤ N) and swap the elements A_{i} and B_{i}. Chef came up with a task to find the minimum possible value of (A_{max} - A_{min}) after performing the swap operation any (possibly zero) number of times. Since Chef is b...
t = int(input()) while t > 0: n = int(input()) s = input() arr = [int(ele) for ele in s.strip().split()] s = input() brr = [int(ele) for ele in s.strip().split()] arr = arr + brr arr = [(arr[i], i % n) for i in range(2 * n)] arr.sort() dic = {} mn = 1000000001 j = 0 for i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR V...
You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use it. If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point. If we have at least 1 point, ...
class Solution: def bagOfTokensScore(self, tokens: List[int], P: int) -> int: tokens = sorted(tokens) left = 0 right = len(tokens) - 1 points = 0 if len(tokens) == 1: if tokens[0] <= P: return 1 if len(tokens) == 0: return 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR V...
You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use it. If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point. If we have at least 1 point, ...
class Solution: def bagOfTokensScore(self, tokens: List[int], P: int) -> int: n = len(tokens) tokens.sort() i = 0 j = n - 1 points = 0 result = 0 while i <= j: if tokens[i] <= P: points += 1 result = max(result, poi...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR
You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use it. If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point. If we have at least 1 point, ...
class Solution: def bagOfTokensScore(self, tokens: List[int], P: int) -> int: max_points, points = 0, 0 tokens.sort() i, j = 0, len(tokens) - 1 while i <= j: if P < tokens[i]: if i == j or points == 0: break P += tokens...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR
You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use it. If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point. If we have at least 1 point, ...
class Solution: def bagOfTokensScore(self, tokens: List[int], P: int) -> int: if not len(tokens): return 0 tokens.sort() res = 0 deque = collections.deque(tokens) while len(deque) > 1 and (P >= deque[0] or res): while deque and P > deque[0]: ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR WHILE VAR VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER V...
You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use it. If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point. If we have at least 1 point, ...
class Solution: def bagOfTokensScore(self, tokens: List[int], P: int) -> int: tokens.sort() def twoPointer(tokens, P): i = 0 j = len(tokens) - 1 score = 0 maxScore = 0 while i <= j: flag = False while i < l...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ...
You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use it. If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point. If we have at least 1 point, ...
class Solution: def bagOfTokensScore(self, tokens: List[int], P: int) -> int: tokens.sort() max_points = 0 points = 0 i = 0 j = len(tokens) - 1 while i <= j: if P >= tokens[i]: points += 1 P -= tokens[i] max...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR RETURN VAR VAR
You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use it. If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point. If we have at least 1 point, ...
class Solution: def bagOfTokensScore(self, tokens: List[int], P: int) -> int: tokens.sort() if not tokens or P < tokens[0]: return 0 l, r = 0, len(tokens) - 1 points = 0 while l <= r: if P >= tokens[l]: points += 1 P -=...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR VAR
You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use it. If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point. If we have at least 1 point, ...
class Solution: def bagOfTokensScore(self, tokens: List[int], P: int) -> int: if not tokens: return 0 tokens.sort() point = 0 while tokens: if P < tokens[0]: if point and len(tokens) > 1: P += tokens.pop() ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR IF VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER RETURN VAR VAR
You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use it. If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point. If we have at least 1 point, ...
class Solution: def bagOfTokensScore(self, tokens: List[int], P: int) -> int: tokens.sort() buyer, seller = 0, len(tokens) - 1 max_items = current_items = 0 while buyer <= seller: if P >= tokens[buyer]: P -= tokens[buyer] current_items += ...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR
You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use it. If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point. If we have at least 1 point, ...
class Solution: def bagOfTokensScore(self, tokens: List[int], P: int) -> int: tokens.sort() maxPoints = 0 points = 0 left, right = 0, len(tokens) - 1 while left <= right and P >= 0: if P - tokens[left] >= 0: P -= tokens[left] point...
CLASS_DEF FUNC_DEF VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC...
You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use it. If we have at least token[i] power, we may play the token face up, losing token[i] power, and gaining 1 point. If we have at least 1 point, ...
class Solution: def bagOfTokensScore(self, tokens: List[int], P: int) -> int: startIndex = 0 endIndex = len(tokens) - 1 points = 0 tokens.sort() while True: print(startIndex, endIndex, P) if startIndex > endIndex or endIndex < startIndex: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR WHILE NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN VAR IF VAR VAR RETURN VAR VAR VAR VAR VAR NUMBE...
Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into n sections. At this moment there are exactly ai archers located at the...
import sys border = 1 << 30 def build(x=0): res = [0, 0] i = 0 while x and i < 30: if x & 1: res[1] += 1 << i x >>= 1 i += 1 i = 0 while x: if x & 1: res[0] += 1 << i x >>= 1 i += 1 return res n, r, k = map(int, sys.std...
IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VA...
There is a deck of $n$ cards. The $i$-th card has a number $a_i$ on the front and a number $b_i$ on the back. Every integer between $1$ and $2n$ appears exactly once on the cards. A deck is called sorted if the front values are in increasing order and the back values are in decreasing order. That is, if $a_i< a_{i+1}$...
from sys import stdin def solve(): n = int(stdin.readline()) dic = {} cards = set() for i in range(n): a, b = map(int, stdin.readline().split()) a -= 1 b -= 1 dic[a] = b dic[b] = a cards.add((a, b)) top = [] bot = [] used = [False] * (2 * n) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL 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 ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER...
There is a deck of $n$ cards. The $i$-th card has a number $a_i$ on the front and a number $b_i$ on the back. Every integer between $1$ and $2n$ appears exactly once on the cards. A deck is called sorted if the front values are in increasing order and the back values are in decreasing order. That is, if $a_i< a_{i+1}$...
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def L...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_D...
There is a deck of $n$ cards. The $i$-th card has a number $a_i$ on the front and a number $b_i$ on the back. Every integer between $1$ and $2n$ appears exactly once on the cards. A deck is called sorted if the front values are in increasing order and the back values are in decreasing order. That is, if $a_i< a_{i+1}$...
def sv(): N = int(input()) lf = [False] * N mt = [False] * N for n in range(N): a, b = map(int, input().split()) sp = False if a > N: a, b = b, a sp = True if a > N or b <= N: return -1 a -= 1 b = 2 * N - b lf[a]...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER ASSIGN ...
There is a deck of $n$ cards. The $i$-th card has a number $a_i$ on the front and a number $b_i$ on the back. Every integer between $1$ and $2n$ appears exactly once on the cards. A deck is called sorted if the front values are in increasing order and the back values are in decreasing order. That is, if $a_i< a_{i+1}$...
import sys mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline N = int(input()) AB = [-1] * (2 * N + 1) BA = [-1] * (2 * N + 1) for _ in range(N): a, b = map(int, input().split()) AB[a] = b BA[b] = a seen = [0] * (2 * N + 1) ...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL ...
There is a deck of $n$ cards. The $i$-th card has a number $a_i$ on the front and a number $b_i$ on the back. Every integer between $1$ and $2n$ appears exactly once on the cards. A deck is called sorted if the front values are in increasing order and the back values are in decreasing order. That is, if $a_i< a_{i+1}$...
import sys input = sys.stdin.readline n = int(input()) front = [-1] * n back = [-1] * n rev = [-1] * (2 * n) used = [False] * n opp = [-1] * (2 * n) for c in range(n): a, b = map(lambda x: int(x) - 1, input().split()) front[c] = a back[c] = b rev[a] = c rev[b] = c opp[a] = b opp[b] = a left...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP...
There is a deck of $n$ cards. The $i$-th card has a number $a_i$ on the front and a number $b_i$ on the back. Every integer between $1$ and $2n$ appears exactly once on the cards. A deck is called sorted if the front values are in increasing order and the back values are in decreasing order. That is, if $a_i< a_{i+1}$...
number_of_cards = int(input()) opposite_side = {} cards = set() result = 0 top = [] bottom = [] highest_taken = 2 * number_of_cards + 1 lowest_taken = 0 for _ in range(number_of_cards): front, back = map(int, input().split()) opposite_side[front] = back opposite_side[back] = front cards.add((front, back...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUN...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
def oper(l, m): q, r = 0, 0 for i in range(len(l)): if m[i] == "c": q = max(i, q) while q < len(l): if l[q] == "c": l[i], l[q] = l[q], l[i] q += 1 break elif l[q] == "a": ...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING RETURN STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR W...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
q = int(input()) while q: n = int(input()) s = input() t = input() flag = 1 if ( s.count("a") != t.count("a") or s.count("b") != t.count("b") or s.count("c") != t.count("c") ): flag = 0 else: i = 0 j = 0 while i < n: if s[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
I, P, N = input, print, "NO" for i in range(int(I())): n = int(I()) s = I() t = I() if s.count("b") != t.count("b"): P(N) continue j, z = 0, "YES" for i in range(n): x = s[i] if x == "b": continue while t[j] == "b": j += 1 y...
ASSIGN VAR VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VA...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
import sys input = sys.stdin.readline q = int(input()) for _ in range(q): n = int(input().strip("\n")) s, t = input().strip("\n"), input().strip("\n") s = list(s) ap, bp, cp = 0, 0, 0 for j in range(n): ap = max(ap, j + 1) while ap < n and s[ap] != "a": ap += 1 b...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIG...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
x = int(input()) def cal(n, s, t): if s == t: return True p, q = list(s), list(t) i = n - 1 a, b = n - 1, n - 1 while i >= 0: if q[i] == p[i]: i -= 1 continue if q[i] == "c": return False if q[i] == "b": ck = 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING RETURN NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER F...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
TT = int(input()) while TT: n = int(input()) s1 = input() s2 = input() SCA1 = [] SCA2 = [] for i in range(n): if s1[i] != "b": SCA1.append([s1[i], i]) if s2[i] != "b": SCA2.append([s2[i], i]) flag = 1 if len(SCA1) != len(SCA2): flag = 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR NUMBE...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
a = int(input()) for y in range(a): b = int(input()) c = input() d = input() if ( c.count("b") == d.count("b") and c.count("a") == d.count("a") and c.count("c") == d.count("c") ): j = [] h = [] i = [] k = [] f = 0 for y in range...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIG...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
def solve(): n = int(input()) p = input() q = input() i, j = 0, 0 while i < n or j < n: while i < n and p[i] == "b": i += 1 while j < n and q[j] == "b": j += 1 if i == n and j == n: break if i < n and j == n or j < n and i == n: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF V...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
x = int(input()) while x > 0: x -= 1 n = int(input()) s = str(input()) t = str(input()) s = list(s) t = list(t) y, u = 0, 0 ans = "YES" if ( s.count("a") != t.count("a") or s.count("b") != t.count("b") or s.count("c") != t.count("c") ): print("NO")...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR STRING FUNC_CA...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
for _ in range(int(input())): n = int(input()) s = input() t = input() sac = [] sa, sc, ta, tc = 0, 0, 0, 0 tac = [] ans = "YES" for i in range(n): if s[i] != "b": sac.append(s[i]) if t[i] != "b": tac.append(t[i]) if s[i] == "a": ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR VA...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
def pp(s: str, t: str, n: int) -> str: if ( s.count("a") != t.count("a") or s.count("b") != t.count("b") or s.count("c") != t.count("c") ): return "NO" p1, p2 = 0, 0 while p1 < n and p2 < n: while p1 < n and s[p1] == "b": p1 += 1 if p1 == n: ...
FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING RETURN STRING ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
t = int(input()) for i in range(t): n = int(input()) sa = input() sb = input() lsta = [] lstb = [] for j in range(n): if sa[j] != "b": lsta.append((sa[j], j)) if sb[j] != "b": lstb.append((sb[j], j)) e = 0 if len(lsta) != len(lstb): print("...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
def solve(arr_a, arr_b): a, b, c = 0, 0, 0 ba, bb = [], [] ca, cb = [], [] cba, cbb = [], [] for i in arr_a: if i == "a": a += 1 ba.append(b) ca.append(c) if i == "b": b += 1 cba.append(c) if i == "c": c ...
FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR LIST LIST FOR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
iter = int(input()) for z in range(iter): n = int(input()) a = input() b = input() top = 0 ans = 1 for i in range(n): if b[i] == "a": top -= 1 if a[i] == "a": top += 1 if top < 0: ans = 0 break if top and a[i] == "c"...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
import sys input = sys.stdin.readline def solve(): n = int(input()) s = list(input().strip()) t = input().strip() idx1 = start = 0 while idx1 < n: c1, c2 = s[idx1], t[idx1] if c1 == c2: idx1 += 1 continue if c1 == "c": return "NO" ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR STRING RETURN STRING IF VAR STRING IF VAR STRING RETURN STRING ASSIGN ...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
for _ in range(int(input())): n = int(input()) s = input() t = input() s1 = sorted(s) t1 = sorted(t) if s1 != t1: print("NO") elif s == t: print("YES") else: a = 0 c = 0 flag = True for x in range(n): if s[x] == t[x] and s[x] ==...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NU...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
def solve(): n = int(input()) s = input() t = input() if ( t.count("a") != s.count("a") or t.count("b") != s.count("b") or t.count("c") != s.count("c") ): print("NO\t") return j = 0 for i in range(n): if s[i] == "b": continue ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRIN...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
import itertools for _ in range(int(input())): n = int(input()) s = input() t = input() ls = [] lt = [] at_count = 0 ct_count = 0 as_count = 0 cs_count = 0 flag = False for chars, chart in zip(s, t): if chars == "a": ls.append(0) as_count += 1...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR STRING EXPR...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
import sys def do_count(s, char): counter = 0 arr = [] for c in s: if c == char: arr.append(counter) counter = 0 else: counter += 1 arr.append(counter) return arr for _ in range(int(input())): input() s = input() t = input() val...
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR STRING IF FUNC_C...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
for _ in range(int(input())): n = int(input()) s = input() t = input() if s.count("b") != t.count("b"): print("NO") continue j = 0 for i in range(n): if s[i] == "b": continue while t[j] == "b": j += 1 if s[i] != t[j] or s[i] == "a" ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING WHILE VAR VAR STRING VAR NUMBER IF VAR VAR VAR V...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
g = int(input()) def logic(n, s, t): s2 = [c for c in s if c != "b"] t2 = [c for c in t if c != "b"] if s2 != t2: return "NO" s_a = [] s_c = [] t_a = [] t_c = [] for i in range(n): if s[i] == "a": s_a.append(i) elif s[i] == "c": s_c.appen...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR STRING IF VAR VAR RETURN STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR ...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
q = int(input()) for _ in range(q): n = int(input()) s = input().strip() t = input().strip() stack_s = 0 stack_t = 0 for s_c, t_c in zip(s, t): if s_c == "a": if stack_t == 0: stack_s += 1 else: break if t_c == "a": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF VAR NUMBER VAR NUMBER IF VAR STRING IF VAR NUMBER VAR NUMBE...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
def solve(): n = int(input()) s, t = input(), input() A, B = "", "" aa, ac, ba, bc = 0, 0, 0, 0 for i in range(n): if s[i] == "a": aa += 1 if s[i] == "c": ac += 1 if t[i] == "a": ba += 1 if t[i] == "c": bc += 1 i...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR ...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
def check(s): coun = [0, 0, 0] for i in s: coun[ord(i) - ord("a")] += 1 return coun q = int(input()) for test in range(q): n = int(input()) s = list(input()) t = list(input()) flag = 0 b = 0 c = 0 if check(s) != check(t): flag = 1 print("NO") else: ...
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR N...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
def mi(): return map(int, input().split()) def li(): return list(mi()) def si(): return str(input()) def ni(): return int(input()) for T in range(int(input())): n = ni() s = list(si()) t = list(si()) flag = True i = 0 a1 = 0 a2 = 0 c1 = 0 c2 = 0 flag = Tru...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
Z = int(input()) while Z != 0: N = int(input()) S = str(input()) T = str(input()) result = True test1 = "" test2 = "" for i in range(len(S)): if S[i] != "b": test1 += S[i] if T[i] != "b": test2 += T[i] count_c_S = 0 count_c_T = 0 for i in r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR IF VAR VAR STRING VAR V...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
for _ in range(int(input())): n = int(input()) s = input() t = input() numA = 0 numC = 0 ans = s.replace("b", "") == t.replace("b", "") for i in range(n): numA += (s[i] == "a") - (t[i] == "a") numC += (t[i] == "c") - (s[i] == "c") if numA < 0 or numC < 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING VAR VAR STRING VAR BIN_OP ...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
class Solution: def solve(self, n, s, t): si_list = [] ti_list = [] for i in range(n): if s[i] != "b": si_list.append(s[i]) if t[i] != "b": ti_list.append(t[i]) if si_list != ti_list: return False csi_index ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR V...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
def solve(): n = int(input()) s = input() t = input() s1 = [] t1 = [] ss1 = [] tt1 = [] for i in range(n): if s[i] == "a" or s[i] == "c": s1.append(s[i]) ss1.append(i) if t[i] == "a" or t[i] == "c": t1.append(t[i]) tt1.appen...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL V...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
q = int(input()) for _ in range(q): n = int(input()) s = input() t = input() ans = "YES" cur = 0 for i in range(n - 1): if s[i] == t[i]: continue if t[i] == "a": ans = "NO" break elif t[i] == "b": try: ind = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING ASSIGN VAR FUNC_C...
You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence of "bc" in $s$ and replace it with "cb". You are allowed to perfo...
T = int(input()) while T > 0: n = int(input()) s = input() t = input() ptr1 = ptr2 = 0 ans = True while True: while ptr1 < n and s[ptr1] == "b": ptr1 += 1 while ptr2 < n and t[ptr2] == "b": ptr2 += 1 if ptr1 == n and ptr2 == n: break ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR ...
You are given an array a consisting of n integers. Let min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r. Your task is to choose three positive (greater than 0) integers x, y and z such that: * x + y + z = n; * max(1, x) = min(x + 1, x + ...
import sys input = sys.stdin.readline def format(a, b=0, n=0): if a == -1: return "NO" else: return "YES\n{} {} {}".format(a, b - a, n - b) def solve(): n = int(input()) ar = [int(t) for t in input().split()] rmq = RangeQuery(ar) fmax = max(ar) idxs = [i for i in range(n...
IMPORT ASSIGN VAR VAR FUNC_DEF NUMBER NUMBER IF VAR NUMBER RETURN STRING RETURN FUNC_CALL STRING VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF 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 FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CA...
You are given an array a consisting of n integers. Let min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r. Your task is to choose three positive (greater than 0) integers x, y and z such that: * x + y + z = n; * max(1, x) = min(x + 1, x + ...
import sys from sys import stdin class SegTree: def __init__(self, N, first): self.NO = 2 ** (N - 1).bit_length() self.First = first self.data = [first] * (2 * self.NO) def calc(self, l, r): return min(l, r) def update(self, ind, x): ind += self.NO - 1 se...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP NUMBER VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_DEF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ...
You are given an array a consisting of n integers. Let min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r. Your task is to choose three positive (greater than 0) integers x, y and z such that: * x + y + z = n; * max(1, x) = min(x + 1, x + ...
for _ in range(int(input())): N = int(input()) X = list(map(int, input().split())) M = [-1] * N mx = 0 INF = 10 for i in range(N - 1, -1, -1): mx = max(X[i], mx) M[i] = mx M2 = [-1] * N mx = 0 d = dict() Y = [-1] * N Z = [-1] * N stack = [] for i in ra...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASS...
You are given an array a consisting of n integers. Let min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r. Your task is to choose three positive (greater than 0) integers x, y and z such that: * x + y + z = n; * max(1, x) = min(x + 1, x + ...
import sys rmq = [] def query(a, b): ii = len(bin(b - a)) - 3 return min(rmq[ii][a], rmq[ii][b - (1 << ii) + 1]) for ttt in range(int(sys.stdin.readline())): n = int(sys.stdin.readline()) d = [int(i) for i in sys.stdin.readline().split()] lgn = len(bin(n - 1)) - 2 rmq = [([0] * n) for i in ...
IMPORT ASSIGN VAR LIST FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC...
You are given an array a consisting of n integers. Let min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r. Your task is to choose three positive (greater than 0) integers x, y and z such that: * x + y + z = n; * max(1, x) = min(x + 1, x + ...
from itertools import accumulate from sys import gettrace, stdin if gettrace(): inputi = input else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def solve(): n = int(inputi()) aa = [int(a) for a in inputi().split()] maa = max(aa) mpo...
IF FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF 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 VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR F...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys from sys import stdin class SegTree: def __init__(self, N, first): self.NO = 2 ** (N - 1).bit_length() self.First = first self.data = [first] * (2 * self.NO) def calc(self, l, r): return min(l, r) def update(self, ind, x): ind += self.NO - 1 se...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP NUMBER VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_DEF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
for t in range(int(input())): n = int(input()) a = list(map(int, input().split())) visited = [(False) for i in range(n + 1)] i = 0 j = n - 1 flag, count = 0, 0 k = 1 mini = 9999999999 while i <= j: if a[i] == k: i += 1 k += 1 count += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBE...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) cnt = [0] * (n + 1) numless = 0 for i in a: cnt[i] += 1 print(int(set(a) == set([i for i in range(1, n + 1)])), end="") if min(a) == 1: l = 0 r = n - 1 ans = n for...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
from sys import stdin input = stdin.readline q = int(input()) for _ in range(q): n = int(input()) l = list(map(int, input().split())) ile = [0] * (n + 1) for i in l: ile[i] += 1 lewy = 0 prawy = n - 1 step = 1 while True: if lewy == prawy: break if l[...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR N...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
t = int(input()) for tt in range(t): n = int(input()) array = [int(x) for x in input().split()] cnt = [0] * (n + 1) ans = [] for e in array: cnt[e] += 1 flag = True l = 0 r = n - 1 for i in range(1, n): if flag and cnt[i]: ans.append(1) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for k in range(c)] for j in range(b)] for i in ran...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
from sys import stdin ip = stdin.readline for _ in range(int(ip())): n = int(ip()) a = [(int(i) - 1) for i in ip().split()] cnt = [0] * n ans = [0] * n for i in a: cnt[i] += 1 ans[0] = 0 if cnt.count(0) > 0 else 1 ans[n - 1] = int(cnt[0] > 0) l, r = 0, n - 1 for i in range(1...
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER NUMBER NUMB...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] b = a[:] b.sort(reverse=1) l = 0 r = n - 1 ans = [0] * n for i in range(1, n + 1): if b[-1] == i: ans[n - i] = 1 if a[l] == i: ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER B...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
def solve(n, arr): if n == 1: return ["1"] ans = ["0" for i in range(n)] pos = [set() for i in range(n + 1)] for i, a in enumerate(arr): pos[a].add(i) start = 0 end = n - 1 for a in range(1, n + 1): if not pos[a]: return ans b1 = start in pos[a] ...
FUNC_DEF IF VAR NUMBER RETURN LIST STRING ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN VAR ASSI...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) inx = {} temp = 0 for i in range(n): if l[i] in inx: temp = 1 inx[l[i]].append(i + 1) else: inx[l[i]] = [i + 1] ans = [] ch = 0 for i in range(1, n + 1):...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR LIST BI...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys input = sys.stdin.readline def check(A): LEN = len(A) USE = [0] * (LEN + 1) for a in A: USE[a] += 1 flag = 1 OK = 1 << 30 for i in range(1, LEN + 1): if USE[i] != 1: flag = 0 OK = min(OK, i) for i in range(1, LEN - 1): if A[i - 1]...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL V...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys input = sys.stdin.readline def fun(l, r, val, che, ar): while l <= r: mid = l + (r - l) // 2 if fun1(mid, ar) < val: l = mid + 1 elif che[mid] == 1: return mid else: r = mid - 1 def update(inp, add, ar): global n while inp <...
IMPORT ASSIGN VAR VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR B...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys input = sys.stdin.readline (T,) = map(int, input().split()) for _ in range(T): (N,) = map(int, input().split()) X = [0] + list(map(int, input().split())) d = [0] * (N + 1) for i, x in enumerate(X): d[x] += 1 vs = set(X) R = [0] * N mn, mx = 0, N for i in range(1, N + ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VA...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
def is_permutatio3n(l): se = set() n = len(l) for e in l: if e in se or e > n: return False se.add(e) return True def main(): t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) is_permutation = True ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys input = sys.stdin.readline t = int(input()) for you in range(t): n = int(input()) l = input().split() li = [int(i) for i in l] curr = 1 start = 0 end = n - 1 while start <= end: if li[start] == curr: start += 1 curr += 1 elif li[end] == cur...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) right = [(i + 1) for i in range(n)] left = [(i - 1) for i in range(n)] idx = [[] for i in range(n)] for i in range(n): idx[a[i] - 1].append(i) t = [] for i in...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FO...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) A = [(int(a) - 1) for a in input().split()] C = [0] * N for a in A: C[a] += 1 l, r = 0, N - 1 for i in range(N): if C[i] != 1: break if A[l] == i: ...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FO...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys t = int(input()) for test in range(t): n = int(input()) a = list(map(int, input().split(" "))) s = [[] for i in range(n + 1)] res = ["1" for i in range(n)] for i in range(n): if s[a[i]] != []: res[0] = "0" s[a[i]].append(i) k = 0 for i in range(1, n + ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR LI...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys input = sys.stdin.buffer.readline T = int(input()) for _ in range(T): n, a = int(input()), list(map(int, input().split())) p1 = 1 if n == len(set(a)) == max(a) else 0 up = 1 for u in range(n - 2, -1, -1): u1, u2 = a[u], a[u + 1] if u1 > u2 and not up: a[u] = u2 ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMB...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
gans = [] for _ in range(int(input())): n = int(input()) u = list(map(int, input().split())) + [0] d = [0] * n for i in range(1, n): c = i - 1 while u[c] >= u[i]: c -= d[c] + 1 d[i] = i - c - 1 p = [0] * n for i in range(n - 2, -1, -1): c = i + 1 ...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP ...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING 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...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
from sys import stdin, stdout input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] arr = [(0) for x in range(n)] l = 0 r = n - 1 dict = {} for k in range(n): i = a[k] if i in dict: dict[i].append(k) ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
from sys import stdin T = int(stdin.readline().strip()) for casos in range(T): n = int(stdin.readline().strip()) s = list(map(int, stdin.readline().strip().split())) if n == 1: print("1") continue cnt = [(0) for i in range(n + 2)] for i in s: cnt[i] += 1 ans = "1" fo...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBE...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
from sys import stdin input = stdin.readline def rating(arr): arr = list(map(lambda s: s - 1, lst)) cnt = [0] * len(arr) ans = [0] * len(arr) for i in arr: cnt[i] += 1 ans[0] = 0 if cnt.count(0) > 0 else 1 ans[-1] = int(cnt[0] > 0) l = 0 r = len(arr) - 1 for i in range(1, ...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER AS...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
for nt in range(int(input())): n = int(input()) a = list(map(int, input().split())) ans = ["0"] * n if sorted(a) == [i for i in range(1, n + 1)]: ans[0] = "1" else: ans[0] = "0" count = [0] * n for i in a: count[i - 1] += 1 l = 0 r = n - 1 curr = 1 ind...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR B...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) s = ["0" for i in range(n)] c = [0] * n for i in range(n): c[arr[i] - 1] += 1 if c[0] > 0: s[-1] = "1" i = 0 j = n - 1 p = 1 s[0] = "1" if len(set(arr)) == n else "0" while p ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys input = sys.stdin.buffer.readline def prog(): for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) mn = min(a) counts = [0] * (n + 1) for i in a: counts[i] += 1 output = ["0" for i in range(n)] if sorted(...
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR STRING VAR FUNC_CA...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
def read_ints(): return map(int, input().split()) (t_n,) = read_ints() for i_t in range(t_n): (n,) = read_ints() a_seq = tuple(read_ints()) result = [None] * n result[0] = sorted(a_seq) == list(range(1, n + 1)) a_need = 1 i, j = 0, n - 1 has_analogue = False while i <= j and (a_seq...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN V...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) ans = ["0"] * n a = list(map(int, input().split())) if sorted(a) == list(range(1, n + 1)): ans[0] = "1" c = [0] * (n + 1) ind = [0] * (n + 1) for i in range(n): c[a[i]] += 1 ind[a[i]...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VA...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) d = dict() if a[-1] == 1: a = a[::-1] for i, x in enumerate(a): if x in d: d[x].append(i) else: d[x] = list() d[x].append(i) ans = [] flag = Tr...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VA...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys for _ in range(int(sys.stdin.readline())): n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().strip().split(" "))) i = 0 j = n - 1 onec = 0 oc = 0 iso = "ö" d = 0 for k in range(1, n): if a[i] < k or a[j] < k: d = k - 1 br...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ def gift(): for _ in range(t): n = int(input()) A = [(int(a) - 1) for a in input().split()] C = [0] * n for a in A: C[a] += 1 l, r = 0, n - 1 for i in range(n): if C...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL V...
On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs. The program works as follows. Given an integer parameter $k$, the program takes the minim...
import sys input = sys.stdin.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def range_sum(self, l, r): return self.sum(r) - self.sum(l - 1) def sum(self, i): i += 1 s = 0 while i > 0: s += self.tree[i] ...
IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_...
Given two binary arrays arr1[] and arr2[] of same size N. Find length of the longest common span [i, j] where j>=i such that arr1[i] + arr1[i+1] + …. + arr1[j] = arr2[i] + arr2[i+1] + …. + arr2[j]. Example 1: Input: N = 6 Arr1[] = {0, 1, 0, 0, 0, 0} Arr2[] = {1, 0, 1, 0, 0, 1} Output: 4 Explanation: The longest span...
class Solution: def longestCommonSum(self, arr1, arr2, n): arr = [] for i in range(n): arr.append(arr1[i] - arr2[i]) for i in range(1, n): arr[i] += arr[i - 1] dic = {} dic[0] = -1 l = 0 for i in range(n): if arr[i] in dic....
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ...