description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
The Rumbling is a hypothetical cataclysmic event involving Karl Fritz's Wall Titans marching across the Earth, destroying all life upon it. Eren Yeager who possesses the Founding Titan has decided to begin The Rumbling to show the true power of the Eldians to the rest of the world. There are N Titans standing in a lin...
for _ in range(int(input())): n = int(input()) s = input() x, y = map(int, input().split()) ei = [0] wi = [0] e = w = 0 for i in range(n): if s[i] == "S": e = e + min(3 * x, y) elif s[i] == "N": e = e + min(x, 3 * y) elif s[i] == "W": ...
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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR B...
The Rumbling is a hypothetical cataclysmic event involving Karl Fritz's Wall Titans marching across the Earth, destroying all life upon it. Eren Yeager who possesses the Founding Titan has decided to begin The Rumbling to show the true power of the Eldians to the rest of the world. There are N Titans standing in a lin...
def cost(val, x, y, desired): if val == "N": if desired == "W": return min(y, x * 3) else: return min(x, y * 3) elif val == "S": if desired == "W": return min(x, y * 3) else: return min(y, x * 3) elif val == "E": if desi...
FUNC_DEF IF VAR STRING IF VAR STRING RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR STRING IF VAR STRING RETURN BIN_OP NUMBER FUNC_CALL VAR VAR VAR RETURN NUMBE...
The Rumbling is a hypothetical cataclysmic event involving Karl Fritz's Wall Titans marching across the Earth, destroying all life upon it. Eren Yeager who possesses the Founding Titan has decided to begin The Rumbling to show the true power of the Eldians to the rest of the world. There are N Titans standing in a lin...
def helperRight(i, x, y): if i == "N": return min(x, 3 * y) elif i == "W": return min(2 * x, 2 * y) elif i == "S": return min(3 * x, y) else: return 0 def helperLeft(i, x, y): if i == "N": return min(3 * x, y) elif i == "W": return 0 elif i =...
FUNC_DEF IF VAR STRING RETURN FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR STRING RETURN FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR IF VAR STRING RETURN FUNC_CALL VAR BIN_OP NUMBER VAR VAR RETURN NUMBER FUNC_DEF IF VAR STRING RETURN FUNC_CALL VAR BIN_OP NUMBER VAR VAR IF VAR STRING RETURN NUMBER IF VAR STRING RETU...
The Rumbling is a hypothetical cataclysmic event involving Karl Fritz's Wall Titans marching across the Earth, destroying all life upon it. Eren Yeager who possesses the Founding Titan has decided to begin The Rumbling to show the true power of the Eldians to the rest of the world. There are N Titans standing in a lin...
def get_min(n, s, x, y): l = [] r = [] for i in s: if i == "N": l.append(min(y, 3 * x)) r.append(min(x, 3 * y)) elif i == "S": l.append(min(x, 3 * y)) r.append(min(y, 3 * x)) elif i == "E": l.append(min(2 * x, 2 * y)) ...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR STRING EXPR ...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
def ot(n, a): i = 0 j = n - 1 while i <= j: if a[i] == 1: break if a[j] == 1: break i += 1 j -= 1 if i > j: return n total_s = sum(a) - 2 * i return total_s + i def m(): ans = [] for _ in range(int(input())): n = i...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CAL...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
T = int(input()) for _ in range(T): N = int(input()) A = [int(x) for x in input().split()] if len(set(A)) == 1: print(N) else: s = sum(A) if A[0] == A[-1] == 2: print(s - 1) else: print(s)
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 IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUM...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
T = int(input()) for t in range(T): N = int(input()) A = [int(i) for i in input().split()] Sum = sum(A) if Sum == N or Sum == 2 * N: print(N) else: ind = 0 while A[ind] == A[N - 1 - ind] == 2: ind += 1 print(Sum - 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VA...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split())) summ = a[0] if summ == 1: flag = 1 else: flag = 0 add = 1 if flag == 1: for i in range(1, n): summ += a[i] add = summ else: for i in range(1, n): ...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VA...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
test = int(input()) for _ in range(test): nof = int(input()) seq = list(map(int, input().split())) s = [] for i in seq: if i not in s: s.append(i) sum1 = 0 if len(s) == 1: print(len(seq)) else: ind = 0 while seq[ind] == seq[nof - 1 - 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSI...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for _ in range(int(input())): N = int(input()) array = list(map(int, input().split())) p = sum(array) oneCount = array.count(1) if oneCount == 0: print(p // 2) elif oneCount == 1: k = array.index(1) forward = sum(array[:k]) backward = p - forward - 1 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
x = int(input()) for i in range(x): z = int(input()) l = list(map(int, input().split())) s = sum(l) if l.count(2) != 0: if l[0] == 2 and l[-1] == 2 and l.count(2) != z: print(s - 1) elif l.count(2) == z: print(s // 2) else: print(s) 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
def find_front_one(arr, n): count = 0 for i in range(n): if arr[i] == 1: break count += 1 return count def find_back_one(arr, n): count = 0 for i in range(n - 1, -1, -1): if arr[i] == 1: break count += 1 return count t = int(input()) fo...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR 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 AS...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = set(a) if len(b) == 1: print(n) elif a[0] == a[-1] == 2: print(sum(a) - 1) else: print(sum(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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL V...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
T = int(input()) while T > 0: n = int(input()) a = list(map(int, input().split())) c1 = 0 c2 = 0 s = sum(a) for i in range(n): if a[i] == 2: c1 += 1 else: break for i in range(n - 1, -1, -1): if a[i] == 2: c2 += 1 else: ...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBE...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for i in range(int(input())): N = int(input()) l = list(map(int, input().split())) s = sum(l) ans = 0 count_of_1 = l.count(1) if s % 2 == 0: ans = N if count_of_1 == 0 else s else: ind = l.index(1) ans = s if count_of_1 > 1 else s - min(ind, N - 1 - ind) print(ans...
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 NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NU...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for t in range(int(input())): n = int(input()) a = list(map(int, input().split())) x = sum(a) if x == 2 * n: print(n) elif a == [2, 1, 2]: print("4") else: print(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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
def m(): t = int(input()) while t > 0: count = 0 n = int(input()) k = 2 * n l1 = [(0) for i in range(k + 1)] l2 = list(map(int, input().split())) sum1 = sum(l2) if k == sum1: print(n) elif l2 == [2, 1, 2]: print(4) e...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUN...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) while t > 0: onec = 0 summ = 0 li = [] n = int(input()) li = list(map(int, input().split())) for i in range(0, n): k = li[i] if k == 1: onec += 1 summ += k if onec != 0: if li[0] == 2 and li[n - 1] == 2: print(summ - 1)...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER IF VAR ...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) p = sum(l) m1 = 2 * n m2 = n if p == m1 or p == m2: print(n) elif l[0] == l[-1] == 2: print(p - 1) else: print(p)
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 VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER NUMBER EX...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
def solve(): n = int(input()) a = list(map(int, input().split())) x = sum(a) if not a.__contains__(1): print(n) return elif a[0] == 2 and a[n - 1] == 2: print(x - 1) return else: print(x) return try: t = int(input()) for i in range(t): ...
FUNC_DEF 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 IF FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR RETUR...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) if l[-1] == l[0] == 2: if sum(l) != 2 * n: print(sum(l) - 1) else: print(n) else: print(sum(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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for _ in range(int(input())): n = int(input()) ar = list(map(int, input().split())) s = sum(ar) if 1 in ar: cnt = 0 for i in range(n): if ar[i] != 2 or ar[n - 1 - i] != 2: break else: cnt += 1 print(s - cnt) else: ...
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 IF NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUN...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
T = int(input()) ans = [] for _ in range(T): N = int(input()) A = [int(i) for i in input().split()] first = None last = None for i in range(N): if A[i] == 1 and first == None: first = i if A[i] == 1: last = i if first != None: x = min(first, N - la...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST 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 NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NONE ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR NON...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) for ijk in range(0, t): n = int(input()) a = list(map(int, input().strip().split())) su = sum(a) c = a.count(1) if su % 2 == 0 and c == 0: print(n) elif su % 2 == 0 and c != 0: print(su) elif su % 2 == 1 and c == 1: ind = a.index(1) you = min(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) for i in range(t): n = int(input()) arr = [int(x) for x in input().split()] sum = 0 for j in range(len(arr)): sum = sum + arr[j] flag = 0 for j in range(len(arr)): if arr[j] == 1: flag = 1 if flag == 1: if arr[0] == 2 and arr[len(arr) - 1]...
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NU...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) try: n = min(a.index(1), next(i for i, x in enumerate(reversed(a)) if x == 1)) except ValueError: pass print(sum(a) - n)
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 NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
def f(): t = int(input()) while t > 0: n = int(input()) sum1 = 0 k = [] sum1 = 0 l = list(map(int, input().split())) for i in range(len(l)): sum1 = sum1 + l[i] k.append(sum1) z = sum1 for i in range(len(k) - 1, -1, -1): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSI...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) result = [] for i in range(t): n = int(input()) arr = input().split() dup = [] A = [int(arr[j]) for j in range(n)] if sum(A) % 2 != 0: if A[0] == 2 and A[-1] == 2: result.append(sum(A) - 1) else: result.append(sum(A)) elif 1 in A: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CAL...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
def sub_sums(arr): sums = [arr[0]] for i in range(1, len(arr)): sums.append(sums[-1] + arr[i]) sums.append(arr[1]) for i in range(2, len(arr)): sums.append(sums[-1] + arr[i]) sums.append(arr[2]) for i in range(3, len(arr)): sums.append(sums[-1] + arr[i]) if arr[0] != ...
FUNC_DEF ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL V...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) s = sum(l) if l[0] != 2 or l[n - 1] != 2: print(s) else: c = l.count(1) if c > 0: first = l.index(1) l.reverse() last = l.index(1) r = min(...
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 VAR IF VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER A...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for t0 in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = 0 one, two, f, l = 0, 0, -1, -1 for i in range(n): s += a[i] if one == 0 and a[i] == 1: one = 1 if two == 0 and a[i] == 2: two = 1 if l == -1 and a[i] == 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 ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUM...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for _ in range(int(input())): n = int(input()) l = [int(i) for i in input().split()] s = sum(l) i = 0 while i < n and l[i] == 2: i += 1 j = 0 while j < n and l[n - 1 - j] == 2: j += 1 print(s - min(i, j))
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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) for _ in range(t): n = int(input()) arr = [int(x) for x in input().split()] c1 = 0 c2 = 0 for i in range(n): if arr[i] != 2: break c1 += 1 for i in range(n - 1, -1, -1): if arr[i] != 2: break c2 += 1 print(sum(arr) - mi...
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUM...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) for tes in range(t): n = int(input()) arr = list(map(int, input().split())) c1 = 0 c2 = 0 s = 0 e = 0 o = 0 for i in range(n): if arr[i] == 1: c1 += 1 else: c2 += 1 s += arr[i] if s % 2 == 0: e = s ...
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR ...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split())) b = set() flag = 0 count = 0 for i in range(n): if a[i] == 2 and a[n - i - 1] == 2: count += 1 flag = 1 else: break if flag == 1: print(sum(a) - coun...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER AS...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split())) cn = a.count(1) if cn != 0: if a[0] == 2 and a[n - 1] == 2: print(sum(a) - 1) else: print(sum(a)) else: print(sum(a) // 2) t -= 1
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_C...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) c = 0 s = 0 for i in range(0, t): n = int(input()) a = [int(x) for x in input().split()] for j in a: s += j if j == 1: c += 1 if len(a) == c: print(c) elif a[0] == 2 and a[n - 1] == 2 and c > 0: print(s - 1) elif c == 0: print(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VA...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) if 1 not in arr: print(n) elif arr[-1] == 1 or arr[0] == 1: print(sum(arr)) else: print(sum(arr) - 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 IF NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) check = [(0) for x in range(2 * n + 1)] s = 0 tot = sum(a) i = 0 while i < n and a[i] != 1: s += a[i] i += 1 if i == n or a[i] == 2: for j in range(2, tot + 1, 2): check...
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 BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VA...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
T = int(input()) while T != 0: N = int(input()) A = list(map(int, input().split())) s = sum(A) if s == N or s == 2 * N: print(N) elif A[0] == 1 or A[N - 1] == 1: print(s) else: print(s - 1) T -= 1
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().strip().split())) sum1 = [0] * len(a) first_index = -1 last_index = -1 sum1[0] = a[0] for i in range(1, len(a)): sum1[i] = sum1[i - 1] + a[i] for i in range(len(a)): if first_index == -1 and 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 VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMB...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for _ in range(int(input())): n = int(input()) arr = [int(i) for i in input().split(" ")] s = sum(arr) if s == n or s == 2 * n: print(n) continue red = 0 for a, b in zip(arr, reversed(arr)): if a + b < 4: break red += 1 print(s - red)
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 STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VA...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for _ in range(int(input())): n = int(input()) a = input().split() b = "".join(a) a = map(int, a) x = b.find("1") y = b[::-1].find("1") if x == -1: x = n if y == -1: y = n print(sum(a) - min(x, y))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR EX...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) k = sum(arr) if k == 2 * n: print(n) else: s = k for i in range(n // 2): if arr[i] == 1: k -= 2 * i break elif arr[-(i + 1)] == 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 FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP NUM...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
from sys import stdin input = stdin.readline def answer(): s, one = 0, False for i in range(n): s += a[i] if a[i] == 1: one = True if one == True: if a[0] == 2 and a[-1] == 2: return s - 1 else: return s else: return s // 2 ...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN VAR RETURN BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
import sys tc = int(sys.stdin.readline()) for i in range(tc): _ = sys.stdin.readline() arr = sys.stdin.readline().split() n = len(arr) if "1" not in arr: print(n) continue s = 0 for elem in arr: s += 1 if elem == "1" else 2 f_one = arr.index("1") f_one = min(f_on...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR STRING NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FU...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) c = a.count(1) if c != 0: i = 0 while a[i] == 2 and a[n - 1 - i] == 2: i += 1 print(sum(a) - i) else: print(n)
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 NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FU...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
T = int(input()) while T: T -= 1 n = int(input()) a = [int(x) for x in input().split()] c1 = a.count(1) s = sum(a) if c1 != 0: if a[0] == 2 and a[-1] == 2: ans = s - 1 else: ans = s else: ans = n print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
T = int(input()) while T: T -= 1 n = int(input()) a = [int(x) for x in input().split()] ans = sum(a) i = 0 while i < n: if a[i] == 1 or a[n - i - 1] == 1: break ans -= 1 i += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
t = int(input()) for fuck in range(0, t): n = int(input()) arr = list(map(int, input().strip().split())) tot = sum(arr) one = arr.count(1) if tot % 2 == 0 and one == 0: print(n) elif tot % 2 == 1 and one == 1: ind = arr.index(1) final = min(ind, n - 1 - ind) print...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP...
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. For her birthday, Rima got an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Each element of this sequence is either 1 or 2. Let's call an integer $s$ ($1 ≀ s ≀ 2N$) a *summary integer* if there is a contiguous subsequence o...
def sum(a): s = 0 for entry in a: s = s + entry return s t = int(input()) for i in range(t): first = 0 last = 0 n = int(input()) inp = list(map(int, input().split())) flag = 0 for i in range(n): if inp[i] == 1: first = i flag = 1 ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL V...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
import sys from sys import stdin try: import sys from sys import stdin def indx(li, val): f, l, ind = 0, len(li), -1 while f <= l and ind == -1: mid = (f + l) // 2 if li[mid] == val: ind = mid elif val < li[mid]: l = mid -...
IMPORT IMPORT FUNC_DEF ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
for _ in range(int(input())): n = int(input()) points = [] for i in range(n): points.append(tuple(map(int, input().split()))) if n <= 2: print(0) continue A = float("inf") X = list(sorted(points)) minpref, maxpref, minsuff, maxsuff = [X[0][1]], [X[0][1]], [X[-1][1]], ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
def helper2(sorted_points): consolidated_points = [] curr_x = sorted_points[0][0] min_y = sorted_points[0][1] max_y = min_y for x, y in sorted_points: if curr_x == x: min_y = min(min_y, y) max_y = max(max_y, y) else: consolidated_points.append((cur...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF NU...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
for i in range(int(input())): n = int(input()) l = [] for i in range(n): p = list(map(int, input().split())) l.append(p) l.sort() y = [] for i in range(n): y.append(l[i][1]) mx = -1 mn = 1000000000.0 + 1 ht = [[0, 0] for i in range(n)] for i in range(n): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSI...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
def area(rectangle): [A, B] = rectangle return abs(B[0] - A[0]) * abs(B[1] - A[1]) def solve(points): if len(points) <= 2: return 0 points_x = sorted(points, key=lambda x: x[0]) ymx = {} for p in points_x: if p[0] not in ymx: ymx[p[0]] = [p[1], p[1]] con...
FUNC_DEF ASSIGN LIST VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST VAR NUMBER VAR NUMBER I...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
def func(arr): n = len(arr) if n == 1: return 0 L1, R1, L2, R2 = ( [2000000000] * (n + 1), [2000000000] * (n + 1), [-2000000000] * (n + 1), [-2000000000] * (n + 1), ) res = 2000000000000000000 arr.sort() for i in range(0, n): L1[i] = arr[i][1] ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VA...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
def VerticalLevels(array): l = len(array) array.append([0, array[-1][1] + 1]) ans = [] start, end = 0, 0 while end < l: if array[end][1] == array[end + 1][1]: end += 1 else: ans.append(array[start : end + 1]) end += 1 start = end re...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR ...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
def get_min_area_by_horizontal_split(points): points.sort() xs = [point[0] for point in points] first_rectangle = [(points[0][1], points[0][1])] for x, y in points[1:]: bottom = min(first_rectangle[-1][0], y) top = max(first_rectangle[-1][1], y) first_rectangle.append((bottom, to...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR NUMBER N...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
INF = int(1e20) def sweep_area(indices, X, Y): minX = [INF] * N maxX = [-1] * N height = [0] * N last_minX = INF last_maxX = -1 y = Y[indices[0]] for i in indices: last_minX = min(last_minX, X[i]) last_maxX = max(last_maxX, X[i]) minX[i] = last_minX maxX[i] ...
ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR V...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
test = int(input()) for i in range(0, test): n = int(input()) finall = [] for i in range(0, n): lis = list(map(int, input().split())) finall.append(lis) if n <= 2: print(0) continue final = sorted(finall) max_pref = [final[0][1]] min_pref = [final[0][1]] m...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR A...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
import sys input = sys.stdin.readline T = int(input()) def solve(point): point = sorted(point, key=lambda x: (-x[1], x[0])) n = len(point) if n == 1: return 0 Lx = [[0, 0] for _ in range(n)] Ly = [[0, 0] for _ in range(n)] Rx = [[0, 0] for _ in range(n)] Ry = [[0, 0] for _ in rang...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
def getmm(points, c): ans = [(points[0][c], points[0][c])] ansr = [(points[-1][c], points[-1][c])] for p in points[1:]: ans.append((min(p[c], ans[-1][0]), max(p[c], ans[-1][1]))) for p in points[-2::-1]: ansr.append((min(p[c], ansr[-1][0]), max(p[c], ansr[-1][1]))) return ans, ansr[:...
FUNC_DEF ASSIGN VAR LIST VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR LIST VAR NUMBER VAR VAR NUMBER VAR FOR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VA...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
def maximum(arr1, index): return max(arr1, key=lambda a: a[not index])[not index] def minimum(arr1, index): return min(arr1, key=lambda a: a[not index])[not index] def prefix_suffix(arr): prefix_min = [0] * (len(arr) + 2) suffix_min = [0] * (len(arr) + 2) prefix_max = [0] * (len(arr) + 2) su...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
import sys def compute_dp(points): dp = [] ax, min_y = points[0] max_y = min_y for p in points: bx, by = p min_y = min(by, min_y) max_y = max(by, max_y) area = abs(bx - ax) * abs(max_y - min_y) dp.append(area) return dp def compute_min_area(N, points): ...
IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VA...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
inf = float("inf") for _ in range(int(input())): minX = {} maxX = {} minY = {} maxY = {} n = int(input()) for i in range(n): x, y = map(int, input().split()) minY[x] = min(minY.get(x, inf), y) maxY[x] = max(maxY.get(x, -inf), y) minX[y] = min(minX.get(y, inf), x) ...
ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT 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 VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR V...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
def height(A, n): a = [] mn = 1000000000.0 + 1 mx = -1 for i in range(n - 1): if A[i] < mn: mn = A[i] if A[i] > mx: mx = A[i] a.append(mx - mn) return a def sort(L): return sorted(L, key=lambda x: x[0]) def fun(A, n): l2 = [] for i in r...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR ...
Read problem statements in [Vietnamese], [Bengali], [Mandarin Chinese], and [Russian] as well. Given $N$ points in a $2D$ space, find the minimum sum of areas of rectangles required to cover all the points given that we can use at most $2$ non-overlapping rectangles whose sides can touch. The rectangles must be axis-...
def solve2(coordinates): coordinates.sort() minX = coordinates[0][0] maxX = coordinates[-1][0] minY = coordinates[0][1] maxY = coordinates[0][1] size_left = [(0) for i in range(len(coordinates) + 1)] for idx, (x, y) in enumerate(coordinates): minY = min(minY, y) maxY = max(ma...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN V...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game: Let's define f(n) as the sum of all odd d...
test_case = int(input()) for i in range(test_case): l, r = map(int, input().split()) count = 0 for j in range(1, r + 1, 2): m = l % j if m == 0: x = l else: x = l + (j - m) if x in range(l, r + 1): count += ((r - x) // j + 1) * j print(...
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 NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR BIN_OP VA...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game: Let's define f(n) as the sum of all odd d...
for i in range(int(input())): a, b = list(map(int, input().split())) c = sum(j * (b // j) for j in range(1, b + 1, 2)) d = sum(j * ((a - 1) // j) for j in range(1, a, 2)) print(c - d)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR NUMB...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game: Let's define f(n) as the sum of all odd d...
for _ in range(int(input())): a, b = map(int, input().split()) sum = 0 a = a - 1 for i in range(1, b + 1, 2): sum += (b // i - a // i) * i print(sum)
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 NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game: Let's define f(n) as the sum of all odd d...
x = int(input()) divisors = [[] for _ in range(1000001)] for i in range(1, 1000001, 2): for j in range(i, 1000001, i): divisors[j].append(i) cache = {} for c in range(x): a, b = map(int, input().split()) if (a, b) in cache: print(cache[a, b]) continue s = 0 for d in range(a, ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR ...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game: Let's define f(n) as the sum of all odd d...
def sieve_divisors(n): divisors = [0] * (n + 1) for i in range(1, n + 1): if i % 2 == 0: continue for j in range(i, n + 1, i): divisors[j] += i return divisors def prefix_sum(divisors): prefix = [0] * len(divisors) for i in range(1, len(divisors)): p...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VA...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game: Let's define f(n) as the sum of all odd d...
T = int(input()) for i in range(T): f1 = 0 f2 = 0 l, r = list(map(int, input().split())) for j in range(1, r + 1, 2): f2 += j * (r // j) for j in range(1, l, 2): f1 += j * ((l - 1) // j) print(f2 - f1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP BI...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game: Let's define f(n) as the sum of all odd d...
for i in range(int(input())): n, m = map(int, input().split()) sum1 = 0 sum2 = 0 for i in range(1, m + 1, 2): sum1 = sum1 + i * (m // i) for i in range(1, n, 2): sum2 = sum2 + i * ((n - 1) // i) print(sum1 - sum2)
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BI...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game: Let's define f(n) as the sum of all odd d...
def factor(n): sum = 0 for i in range(1, int(n**0.5) + 1): if n % i == 0: if i % 2 != 0: sum += i if n // i != i and n // i % 2 != 0: sum += n // i return sum factor_sums = [0] * (10**5 + 1) for i in range(1, len(factor_sums)): factor_sum...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR IF BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR ...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game: Let's define f(n) as the sum of all odd d...
def primeFactors(n): a = 1 while n % 2 == 0: n = n // 2 for i in range(3, int(n**0.5) + 1, 2): j = 1 s = 1 while n % i == 0: n = n // i s += j * i j = j * i a *= s if n > 2: a = a * (1 + n) return a A = [0] * 10000...
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR N...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could play the following game: Let's define f(n) as the sum of all odd d...
t = int(input()) for _ in range(t): l, r = map(int, input().split()) sum1 = 0 for i in range(1, r + 1, 2): sum1 += i * (r // i) sum2 = 0 for i in range(1, l, 2): sum2 += i * ((l - 1) // i) print(sum1 - sum2)
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 NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBE...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
def solve(): n = int(input()) arr = list(map(int, input().split())) freq = {} acc = 0 l, r = -1, -1 for i in range(n): acc += arr[i] acc %= n if acc == 0: l, r = 1, i + 1 break elif acc in freq: l, r = freq[acc] + 1, i + 1 ...
FUNC_DEF 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 ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR N...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
import sys P = [0] * 100010 t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) arr = list(map(int, sys.stdin.readline().split())) p1, p2 = 0, 0 P[0] = 1 S = 0 for i in range(1, n + 1): S += arr[i - 1] if P[S % n]: p1 = P[S % n] ...
IMPORT ASSIGN VAR BIN_OP LIST NUMBER NUMBER 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 VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
t = int(input()) while t != 0: t -= 1 n = int(input()) a = [int(i) for i in input().split()] cumm_sum = [] curr_sum = 0 for i in a: curr_sum += i cumm_sum.append((curr_sum + n) % n) index_arr = [[] for i in range(n)] for i in range(n): index_arr[cumm_sum[i]].appen...
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VA...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) _map = {(0): 0} _sum = 0 for i in range(len(arr)): _sum += arr[i] r = _sum % n if r in _map: print(i - _map[r] + 1) print(*range(_map[r] + 1, i + 1 + 1), sep=" ") ...
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 NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP B...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
def getModulo(a, n): if a < 0: return -a % n else: return a % n for _ in range(int(input())): n = int(input()) arr = [int(c) for c in input().split()] p = [] s = 0 for i in arr: s += i p.append(getModulo(s, n)) dic = {(0): -1} for i in range(len(p)):...
FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP 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 LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR D...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
for _ in range(int(input())): n, s, d = int(input()), 0, {} for i, j in enumerate(map(int, input().split())): s = (s + j) % n if s == 0: print(i + 1) print(*range(1, i + 2)) break elif s in d: print(i - d[s]) print(*range(d[s] +...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER DICT FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMB...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
for _ in range(int(input())): n = int(input()) array = list(map(int, input().split())) ids = [(-1) for x in range(0, n, 1)] sum = 0 exit = False for i in range(len(array)): sum = sum + array[i] r = sum % n if r == 0: print(i + 1) l = [(x + 1) for 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSI...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
for i in range(int(input())): n = int(input()) arr = [int(k) for k in input().split()] mem = [(-1) for j in range(n)] mem[0] = 0 sum = 0 for l in range(1, n + 1): sum = sum + arr[l - 1] sum %= n if mem[sum] == -1: mem[sum] = l else: print(l...
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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
t = int(input()) for _ in range(t): N = int(input()) array = list(map(int, input().split())) sumx = 0 sumxIndex = {} for i in range(0, N): sumx = (sumx + array[i]) % N if sumx == 0: left = 0 right = i break if sumx in sumxIndex.keys(): ...
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 NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VA...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
for _ in range(int(input())): n = int(input()) ar = list(map(int, input().split())) s = 0 ans = {} f = 1 for i in range(n): s += ar[i] p = s % n if p == 0: print(i + 1) for j in range(1, i + 2): print(j, end=" ") print()...
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 ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMB...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
def solve(): t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) if arr[0] % n == 0: print(1) print(1) continue freq = [] for j in range(n): freq.append([]) freq[j].append(0...
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 VAR IF BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
import sys data = sys.stdin.read().split() data.reverse() def read(): return int(data.pop()) def readStr(): return data.pop() T = read() for test in range(T): n = read() A = [0] + [read() for i in range(n)] F = [0] + [(-1) for i in range(n - 1)] for i in range(1, n + 1): A[i] = (A...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FU...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
def sol(): n = int(input()) a = list(map(int, input().split())) pre = [0] * n pre[0] = a[0] for i in range(1, n): pre[i] = pre[i - 1] + a[i] a = [(i % n) for i in pre] hsh = {} ans = [] ans1 = [] for i in range(n): if a[i] == 0: for j in range(i + 1): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN ...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) ans = [] ps = 0 L = [] d = {} c = 0 for i in range(n): ps += l[i] if ps % n == 0: print(i + 1) ans = range(1, i + 2) c = 1 break ...
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 LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER EX...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
t = int(input()) for _ in range(t): n = int(input()) l = [int(i) for i in input().strip().split()] curr = 0 d = {} for i in range(n): curr += l[i] t = curr % n if t == 0: print(i + 1) print(*[j for j in range(1, i + 2)]) break elif ...
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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
t = int(input()) for case in range(t): n = int(input()) nos = [int(x) for x in input().split()] copy = nos[:] nos[0] = copy[0] % n if nos[0] == 0: print(1) print(1) continue flag = 0 for i in range(1, n): nos[i] = nos[i - 1] + copy[i] nos[i] = nos[i] %...
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 VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
try: def find(): n = int(input()) dictk = {(0): -1} sumk = 0 nums = list(map(int, input().split())) for i in range(n): k = nums[i] if k % n == 0: print(1) print(i + 1) return sumk = (sumk + k...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN ASSIGN VAR BIN_OP...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) d = {} s = 0 d[0] = 0 f = 0 for i in range(1, n + 1): s += a[i - 1] s = s % n if s not in d: d[s] = i else: f = 1 print(i - d[s]) ...
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 ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
from sys import stdin t = int(stdin.readline()) for case in range(t): flag = 0 n = int(stdin.readline()) n_arr = [int(x) for x in stdin.readline().split()] n_sum = [(-1) for x in range(n)] n_rem = [(-1) for x in range(n)] n_rem_arr = [(-1) for x in range(n)] n_sum[0] = n_arr[0] n_rem[0]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().strip().split(" "))) N = len(A) B = [(i + 1) for i in range(len(A))] red = [(0) for i in range(len(A))] post = {} temp = 0 L = 0 R = N - 1 for i in range(len(A)): temp += A[i] temp %= N...
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 FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FU...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split())) d = {} d[0] = 0 s = 0 for i in range(1, n + 1): s += a[i - 1] s %= n if s not in d: d[s] = i else: print(i - d[s]) for j in range(d[s], 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN ...
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T...
for t in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] store = {(0): 0} s = 0 for i in range(n): s = (s + a[i]) % n if s in store: ans = range(store[s] + 1, i + 2) break store[s] = i + 1 print(len(ans)) print(*ans)
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 DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER B...