description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {{1, 0, 1, 0, 0} {1, 0, 1, 1, 1} {1, 1, 1, 1, 1} {1, 0, 0, 1, 0}} K = 9, Q = 1 q_i[] = {1} q_j[] = {2} Output: 3 Explanation: Maximum length square with center at (1, 2) that can be formed is of 3 length from (0, 1) to (2, 3). Example 2: Input: R = 3, C = 3 M = {{1, 1, 1} {1, 1, 1} {1, 1, 1}} K = 9, Q = 2 q_i[] = {1, 2} q_j[] = {1, 2} Output : 3 1 Your Task: You don't need to read input or print anything. Your task is to complete the function largestSquare() which takes 2 integers R, and C followed by a list of lists M denoting the binary matrix and then three integers i,j, and K as input and returns a list of integers denting the largest Square possible for each query. Expected Time Complexity: O(R*C + Q*log(MIN_DIST)), where MIN_DIST is the minimum distance of the center from the edges of the matrix where MIN_DIST is the minimum distance of the center from the edges of the matrix. Expected Auxiliary Space: O(R*C) Constraints: 1 ≤ R,C ≤ 500 1 ≤ Q ≤ 10^{4} 0 ≤ K ≤ R*C 0 ≤ i < R 0 ≤ j < C
class Solution: def largestSquare(self, M, R, C, K, Q, q_i, q_j): for i in range(1, R): M[i][0] += M[i - 1][0] for i in range(1, C): M[0][i] += M[0][i - 1] for i in range(1, R): for j in range(1, C): M[i][j] = M[i - 1][j] + M[i][j - 1] - M[i - 1][j - 1] + M[i][j] res = [0] * Q for k in range(Q): i = q_i[k] j = q_j[k] p = 0 while p + i < R and p + j < C and i - p >= 0 and j - p >= 0: a, b, c = 0, 0, 0 if j - p - 1 >= 0: a = M[i + p][j - p - 1] if i - p - 1 >= 0: b = M[i - p - 1][j + p] if j - p - 1 >= 0 and i - p - 1 >= 0: c = M[i - p - 1][j - p - 1] ans = M[i + p][j + p] - a - b + c if ans > K: break else: res[k] = 2 * p + 1 p += 1 return res if __name__ == "__main__": t = int(input()) for _ in range(t): R, C = map(int, input().split()) M = [] for i in range(R): temp = list(map(int, input().split())) M.append(temp) K, Q = list(map(int, input().split())) q_i = list(map(int, input().split())) q_j = list(map(int, input().split())) ob = Solution() res = ob.largestSquare(M, R, C, K, Q, q_i, q_j) for i in res: print(i, end=" ") print()
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN VAR IF VAR STRING 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {{1, 0, 1, 0, 0} {1, 0, 1, 1, 1} {1, 1, 1, 1, 1} {1, 0, 0, 1, 0}} K = 9, Q = 1 q_i[] = {1} q_j[] = {2} Output: 3 Explanation: Maximum length square with center at (1, 2) that can be formed is of 3 length from (0, 1) to (2, 3). Example 2: Input: R = 3, C = 3 M = {{1, 1, 1} {1, 1, 1} {1, 1, 1}} K = 9, Q = 2 q_i[] = {1, 2} q_j[] = {1, 2} Output : 3 1 Your Task: You don't need to read input or print anything. Your task is to complete the function largestSquare() which takes 2 integers R, and C followed by a list of lists M denoting the binary matrix and then three integers i,j, and K as input and returns a list of integers denting the largest Square possible for each query. Expected Time Complexity: O(R*C + Q*log(MIN_DIST)), where MIN_DIST is the minimum distance of the center from the edges of the matrix where MIN_DIST is the minimum distance of the center from the edges of the matrix. Expected Auxiliary Space: O(R*C) Constraints: 1 ≤ R,C ≤ 500 1 ≤ Q ≤ 10^{4} 0 ≤ K ≤ R*C 0 ≤ i < R 0 ≤ j < C
class Solution: def binarysearch(self, l, r, dp, k, i, j): if l <= r: mid = (l + r) // 2 x1 = i - mid x2 = i + mid y1 = j - mid y2 = j + mid count = dp[x2][y2] if x1 > 0: count -= dp[x1 - 1][y2] if y1 > 0: count -= dp[x2][y1 - 1] if x1 > 0 and y1 > 0: count += dp[x1 - 1][y1 - 1] if count <= k: return self.binarysearch(mid + 1, r, dp, k, i, j) else: return self.binarysearch(l, mid - 1, dp, k, i, j) return r def largestSquare(self, M, R, C, K, Q, q_i, q_j): dp = [[(0) for j in range(C)] for i in range(R)] dp[0][0] = M[0][0] for i in range(1, C): dp[0][i] = dp[0][i - 1] + M[0][i] for j in range(1, R): dp[j][0] = dp[j - 1][0] + M[j][0] for i in range(1, R): for j in range(1, C): dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + M[i][j] lb = 0 res = [] for i in range(len(q_i)): up = min(q_i[i], q_j[i], R - q_i[i] - 1, C - q_j[i] - 1) res1 = self.binarysearch(lb, up, dp, K, q_i[i], q_j[i]) if res1 == -1: res1 = 0 else: res1 = 2 * res1 + 1 res.append(res1) return res
CLASS_DEF FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {{1, 0, 1, 0, 0} {1, 0, 1, 1, 1} {1, 1, 1, 1, 1} {1, 0, 0, 1, 0}} K = 9, Q = 1 q_i[] = {1} q_j[] = {2} Output: 3 Explanation: Maximum length square with center at (1, 2) that can be formed is of 3 length from (0, 1) to (2, 3). Example 2: Input: R = 3, C = 3 M = {{1, 1, 1} {1, 1, 1} {1, 1, 1}} K = 9, Q = 2 q_i[] = {1, 2} q_j[] = {1, 2} Output : 3 1 Your Task: You don't need to read input or print anything. Your task is to complete the function largestSquare() which takes 2 integers R, and C followed by a list of lists M denoting the binary matrix and then three integers i,j, and K as input and returns a list of integers denting the largest Square possible for each query. Expected Time Complexity: O(R*C + Q*log(MIN_DIST)), where MIN_DIST is the minimum distance of the center from the edges of the matrix where MIN_DIST is the minimum distance of the center from the edges of the matrix. Expected Auxiliary Space: O(R*C) Constraints: 1 ≤ R,C ≤ 500 1 ≤ Q ≤ 10^{4} 0 ≤ K ≤ R*C 0 ≤ i < R 0 ≤ j < C
class Solution: def getMinDistanceFromSides(self, R, C, x, y): return min(x - 0, y - 0, R - 1 - x, C - 1 - y) def getSubMatSum(self, prefix, x1, y1, x2, y2): left = prefix[x2][y1 - 1] if y1 > 0 else 0 right = prefix[x1 - 1][y2] if x1 > 0 else 0 top = prefix[x1 - 1][y1 - 1] if x1 > 0 and y1 > 0 else 0 return prefix[x2][y2] - left - right + top def largestSquare(self, matrix, R, C, K, Q, q_i, q_j): prefix = [([0] * len(matrix[0])) for i in range(len(matrix))] prefix[0][0] = matrix[0][0] for i in range(1, len(matrix)): prefix[i][0] = prefix[i - 1][0] + matrix[i][0] for j in range(1, len(matrix[0])): prefix[0][j] = prefix[0][j - 1] + matrix[0][j] for i in range(1, len(matrix)): for j in range(1, len(matrix[0])): prefix[i][j] = ( matrix[i][j] + prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1] ) result = [] for i in range(Q): x, y = q_i[i], q_j[i] l, r = 0, self.getMinDistanceFromSides(R, C, x, y) ans = 0 while l <= r: mid = l + (r - l) // 2 x1, y1 = x - mid, y - mid x2, y2 = x + mid, y + mid matSum = self.getSubMatSum(prefix, x1, y1, x2, y2) if matSum <= K: ans = max(ans, mid * 2 + 1) l = mid + 1 else: r = mid - 1 result.append(ans) return result
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square. Example 1: Input: R = 4, C = 5 M = {{1, 0, 1, 0, 0} {1, 0, 1, 1, 1} {1, 1, 1, 1, 1} {1, 0, 0, 1, 0}} K = 9, Q = 1 q_i[] = {1} q_j[] = {2} Output: 3 Explanation: Maximum length square with center at (1, 2) that can be formed is of 3 length from (0, 1) to (2, 3). Example 2: Input: R = 3, C = 3 M = {{1, 1, 1} {1, 1, 1} {1, 1, 1}} K = 9, Q = 2 q_i[] = {1, 2} q_j[] = {1, 2} Output : 3 1 Your Task: You don't need to read input or print anything. Your task is to complete the function largestSquare() which takes 2 integers R, and C followed by a list of lists M denoting the binary matrix and then three integers i,j, and K as input and returns a list of integers denting the largest Square possible for each query. Expected Time Complexity: O(R*C + Q*log(MIN_DIST)), where MIN_DIST is the minimum distance of the center from the edges of the matrix where MIN_DIST is the minimum distance of the center from the edges of the matrix. Expected Auxiliary Space: O(R*C) Constraints: 1 ≤ R,C ≤ 500 1 ≤ Q ≤ 10^{4} 0 ≤ K ≤ R*C 0 ≤ i < R 0 ≤ j < C
class Solution: def largestSquare(self, M, R, C, K, Q, q_i, q_j): def check_range_sum(i, j, k): r1, c1 = i - k, j - k r2, c2 = i + k, j + k if r1 < 0 or c1 < 0 or r2 >= R or c2 >= C: return K + 1 return ( ps_mat[r2 + 1][c2 + 1] + ps_mat[r1][c1] - ps_mat[r2 + 1][c1] - ps_mat[r1][c2 + 1] ) ps_mat = [([0] * (C + 1)) for _ in range(R + 1)] for i in range(R): for j in range(C): ps_mat[i + 1][j + 1] = ( M[i][j] + ps_mat[i][j + 1] + ps_mat[i + 1][j] - ps_mat[i][j] ) ans = [] for i, j in zip(q_i, q_j): k = 0 while check_range_sum(i, j, k) <= K: k += 1 ans.append(2 * k - 1 if k else k) return ans
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR RETURN VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
def leftup(i, S, prefix, count): left = 0 right = i - 1 if S[i] >= prefix[i - 1] - prefix[left]: count[left] += 1 count[i] -= 1 return count elif S[i] < S[i - 1]: count[right] += 1 count[i] -= 1 return count else: pos = right while left < right: mid = (left + right) // 2 if S[i] >= prefix[i - 1] - prefix[mid]: if mid < pos: pos = mid right = mid else: left = mid + 1 count[pos] += 1 count[i] -= 1 return count def rightup(i, S, prefix, count, N): left = i + 1 right = N - 1 if S[i] >= prefix[right - 1] - prefix[i]: count[left] += 1 return count elif S[i] < S[i + 1]: count[i + 1] += 1 count[i + 2] -= 1 return count else: pos = left while left < right: mid = (left + right) // 2 if S[i] >= prefix[mid - 1] - prefix[i]: if mid > pos: pos = mid left = mid + 1 else: right = mid count[pos + 1] -= 1 count[i + 1] += 1 return count T = int(input()) for testCase in range(T): N = int(input()) S = list(map(int, input().split())) prefix = [S[0]] for i in range(1, N): prefix.append(prefix[i - 1] + S[i]) count = [0] * N for i in range(1, N): count = leftup(i, S, prefix, count) for i in range(N - 1): count = rightup(i, S, prefix, count, N) votes = [count[0]] for i in range(1, N): votes.append(votes[i - 1] + count[i]) print(*votes, sep=" ")
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER RETURN VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR STRING
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
t = int(input()) for i in range(t): N = int(input()) minions = [int(i) for i in input().split()] votes = [(0) for i in range(N)] for i in range(N): j = i + 1 z = 0 while j < N: if minions[i] >= z: votes[j] += 1 z += minions[j] else: break j += 1 j = i - 1 z = 0 while j >= 0: if minions[i] >= z: votes[j] += 1 z += minions[j] else: break j -= 1 for i in range(N): print(votes[i], end=" ") 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
t = int(input()) for _ in range(t): n = int(input()) s = list(map(int, input().split())) pre = [s[0]] for i in range(1, n): pre.append(pre[-1] + s[i]) li = [0] * n li[0], li[-1] = 1, 1 if n == 1: print(0) else: for i in range(1, n - 1): li[i] = 2 for i in range(n): for j in range(i + 2, n): if pre[j - 1] - pre[i] <= s[i]: li[j] += 1 else: break for i in range(2, n): for j in range(i - 2, -1, -1): if pre[i - 1] - pre[j] <= s[i]: li[j] += 1 else: break for i in li: print(i, end=" ") 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
t = int(input()) for j in range(t): s = int(input()) a = [] b = [] s1 = [0] for j in input().split(): a.append(int(j)) b.append(0) s1.append(s1[-1] + a[-1]) del s1[0] for j in range(0, s): for i in range(j + 1, s): if a[j] >= s1[i] - s1[j] - a[i]: b[i] += 1 else: break for j in range(s - 1, 0, -1): for j1 in range(j - 1, -1, -1): if a[j] >= s1[j] - s1[j1] - a[j]: b[j1] += 1 else: break for i in b: print(i, end=" ") 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 LIST ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = [0] * n s[0] = a[0] for j in range(1, n): s[j] = s[j - 1] + a[j] ans = [0] * n for j in range(n): k = j + 1 while k < n: if a[j] >= s[k - 1] - s[j]: ans[k] = ans[k] + 1 k += 1 else: break k = j - 1 while k >= 0: if a[j] >= s[j - 1] - s[k]: ans[k] += 1 k -= 1 else: break for j in range(n): print(ans[j], end=" ")
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 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 LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
T = int(input()) while T: n = int(input()) l = [0] l += list(map(int, input().split())) v = [0] * (n + 1) s = [0] * (n + 1) for i in range(1, n + 1): s[i] = s[i - 1] + l[i] for i in range(1, n + 1): for j in range(i - 1, 0, -1): if l[i] < s[i - 1] - s[j]: break v[j] += 1 for j in range(i + 1, n + 1): if l[i] < s[j - 1] - s[i]: break v[j] += 1 for i in range(1, n + 1): print(v[i], end=" ") print() T = T - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
t = int(input()) for i in range(t): n = int(input()) s = list(map(int, input().split())) if n == 1: print("0") elif n == 2: print("1 1") else: co = [0] * n for j in range(n): cs, k = 0, j + 1 while k < n and cs <= s[j]: co[k] += 1 cs += s[k] k += 1 cs, k = 0, j - 1 while k >= 0 and cs <= s[j]: co[k] += 1 cs += s[k] k -= 1 for j in range(n): print(co[j], end=" ") 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
for i in range(int(input())): n, lst = int(input()), list(map(int, input().split())) p, l2 = 0, [] for i in lst: p += i l2.append(p) t = [(0) for i in range(n)] for j in range(n): p = 0 for k in range(j - 1, -1, -1): p += lst[k] if p - lst[k] <= lst[j]: t[k] += 1 else: break p = 0 for l in range(j + 1, n): p += lst[l] if p - lst[l] <= lst[j]: t[l] += 1 else: break for m in t: print(m, end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 NUMBER LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
T = int(input()) for i in range(T): n = int(input()) l = list(map(int, input().split())) L = [0] * n for j in range(n): s = 0 for k in range(j + 1, n): if s <= l[j]: L[k] += 1 s += l[k] else: break s = 0 for k in range(j - 1, -1, -1): if s <= l[j]: L[k] += 1 s += l[k] else: break for j in L: print(j, end=" ") 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
for _ in range(int(input())): N = int(input()) s = list(map(int, input().split())) v = [0] * N for i in range(N): inf = 0 j = i + 1 while j < N and s[i] >= inf: v[j] += 1 inf += s[j] j += 1 for i in range(N - 1, -1, -1): inf = 0 j = i - 1 while j >= 0 and s[i] >= inf: v[j] += 1 inf += s[j] j -= 1 for i in v: print(i, end=" ")
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split())) v = [0] * n for i in range(n): s1 = 0 s2 = 0 if i + 1 < n: v[i + 1] += 1 if i - 1 >= 0: v[i - 1] += 1 for j in range(i + 1, n): s1 = s1 + a[j] if s1 <= a[i] and j + 1 < n: v[j + 1] += 1 else: break for j in range(i - 1, -1, -1): s2 = s2 + a[j] if s2 <= a[i] and j - 1 >= 0: v[j - 1] += 1 else: break for i in range(n): print(v[i], end=" ") print() t = 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
t = int(input().strip()) while t: n = int(input().strip()) a = [int(x) for x in input().strip().split()] b = [0] * n for i in range(n): inf = a[i] j = i + 1 while inf >= 0 and i != n - 1 and j < n: b[j] += 1 inf -= a[j] j += 1 inf = a[i] j = i - 1 while inf >= 0 and i and j >= 0: b[j] += 1 inf -= a[j] j -= 1 for x in b: print(x, end=" ") print() t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
t = int(input()) for _ in range(t): n = int(input()) influences = list(map(int, input().split())) rev_infl = list(reversed(influences[:])) sums = influences[:] rsums = rev_infl for i in range(1, n): sums[i] += sums[i - 1] rsums[i] += rsums[i - 1] votes = [0] * n for i in range(0, n - 1): j = i + 1 while j < n and sums[j - 1] - sums[i] <= influences[i]: votes[j] += 1 j += 1 u = n - 1 - i v = u - 1 while v >= 0 and sums[u - 1] - sums[v] <= influences[u]: votes[v] += 1 v -= 1 print(" ".join(map(str, votes)))
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 ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
def forward(array, index, vote_array): sum = 0 j = index + 1 size = len(array) vote_array[j] += 1 while j < size - 1: sum += array[j] if sum <= array[index]: j += 1 vote_array[j] += 1 else: break def reverse(array, index, vote_array): sum = 0 j = index - 1 vote_array[j] += 1 while j > 0: sum += array[j] if sum <= array[index]: j -= 1 vote_array[j] += 1 else: break T = int(input()) for i in range(T): N = int(input()) si = list(map(int, input().split())) vote_array = [] for j in range(N): vote_array.append(0) if N == 1: pass else: for j in range(N): if j == 0: forward(si, j, vote_array) elif j == N - 1: reverse(si, j, vote_array) else: forward(si, j, vote_array) reverse(si, j, vote_array) for i in range(N): print(str(vote_array[i]) + " ", end="") print()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
t = int(input()) for z in range(t): n = int(input()) s = [int(x) for x in input().split()] CurrSum = 0 Ci = 0 AnsArray = [0] * n AnsArray[0] = 1 for i in range(n - 1): CurrSum = 0 Ci = i + 1 while CurrSum <= s[i] and Ci < n: CurrSum += s[Ci] Ci += 1 if Ci < n: AnsArray[Ci] -= 1 s = s[::-1] for i in range(n - 1): CurrSum = 0 Ci = i + 1 while CurrSum <= s[i] and Ci < n: CurrSum += s[Ci] Ci += 1 AnsArray[n - Ci] += 1 for i in range(1, n): AnsArray[i] += AnsArray[i - 1] print(" ".join(str(x - 1) for x in AnsArray))
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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
t = int(input()) while t: n = int(input()) arr = [int(i) for i in input().split()] br = [0] * (n + 1) for i in range(n): sums = 0 for j in range(i + 1, n): if sums <= arr[i]: br[j] += 1 else: break sums += arr[j] for i in range(n - 1, -1, -1): sums = 0 for j in range(i - 1, -1, -1): if sums <= arr[i]: br[j] += 1 else: break sums += arr[j] for i in range(n): print(br[i], end=" ") print() t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) ans = [0] * n for i in range(n - 1): s = 0 for j in range(i + 1, n): if s <= a[i]: ans[j] += 1 else: break s += a[j] for i in range(n - 1, -1, -1): s = 0 for j in range(i - 1, -1, -1): if s <= a[i]: ans[j] += 1 else: break s += a[j] 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
for t in range(int(input())): n = int(input()) s = list(map(int, input().strip().split())) vote = [(0) for i in range(n)] for i in range(n): influence = 0 voting = s[i] for j in range(i + 1, n): if voting >= influence: vote[j] += 1 else: break influence += s[j] influence = 0 for j in range(i - 1, -1, -1): if voting >= influence: vote[j] += 1 else: break influence += s[j] print(" ".join([str(i) for i in vote]))
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
for _ in range(int(input())): n = int(input()) arr1 = list(map(int, input().split())) Answer = [0] * n for i in range(0, n): j = i + 1 x = 0 while j < n: if arr1[i] >= x: Answer[j] += 1 x += arr1[j] else: break j += 1 x = 0 j = i - 1 while j >= 0: if arr1[i] >= x: Answer[j] += 1 x += arr1[j] else: break j -= 1 print(*Answer, 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
n = int(input()) r = [] q = [] a = [] p = [] for i in range(0, n): d = int(input()) a.append(d) p = [int(x) for x in input().split(" ")] q.append(p) x = 0 for i in range(0, n): u = [] m = 0 for o in range(0, a[i]): u.append(m) for j in range(0, len(q[i])): s = 0 for k in range(j + 1, len(q[i]), 1): if q[i][j] >= s: u[k] = u[k] + 1 else: break s = s + q[i][k] s1 = 0 if j > 0: for k in range(j - 1, -1, -1): if q[i][j] >= s1: u[k] = u[k] + 1 else: break s1 = s1 + q[i][k] r.append(u) for i in range(0, len(r)): for j in range(0, len(r[i])): print(r[i][j], end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
def findRight(preSum, L, R, val): while L < R: M = (L + R + 1) // 2 if preSum[M] <= val: L = M else: R = M - 1 return L def handle(nums): n = len(nums) votes = [0] * n preSum = [0] * (n + 1) for i, k in enumerate(nums): preSum[i + 1] = preSum[i] + k speed = [0] * (n + 1) for i in range(n - 2, -1, -1): if nums[i] < nums[i + 1]: j = i + 1 else: j = findRight(preSum, i + 1, n - 1, nums[i] + preSum[i + 1]) speed[i + 1] += 1 speed[j + 1] -= 1 sd = 0 for i in range(n): sd += speed[i] votes[i] += sd return votes def solve(): N = int(input()) nums = list(map(int, input().split())) votes = [0] * N votes1 = handle(nums) votes2 = handle(nums[::-1])[::-1] votes = map(sum, zip(votes1, votes2)) print(" ".join(map(str, votes))) T = int(input()) for _ in range(T): solve()
FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
res = [] def getSum(nums, sums, i, j): if j > i: return sums[j] - nums[j] - sums[i] elif i > j: return sums[i] - nums[i] - sums[j] else: return 0 for _ in range(0, int(input())): n = input() nums = list(map(int, input().split(" "))) sums = [0] * len(nums) sums[0] = nums[0] for k in range(1, len(nums)): sums[k] = sums[k - 1] + nums[k] votes = [0] * len(nums) for j in range(0, len(nums)): for i in range(j + 1, len(nums)): if getSum(nums, sums, j, i) > nums[j]: break votes[i] += 1 for i in range(j - 1, -1, -1): if getSum(nums, sums, i, j) > nums[j]: break votes[i] += 1 vote = "" for v in votes: vote += " " + str(v) res.append(vote.lstrip()) for xx in res: print(xx)
ASSIGN VAR LIST FUNC_DEF IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
y = int(input()) number = [(0) for P in range(y)] s = [[] for Q in range(y)] for I in range(y): number[I] = int(input()) l = input().split() for a in range(number[I]): s[I].append(int(l[a])) v = [[] for R in range(y)] for I in range(y): if number[I] > 1: v[I].append(1) for D in range(1, number[I] - 1): v[I].append(2) v[I].append(1) else: print(0) continue for k in range(2, number[I]): sumx = 0 for M in range(k - 1, 0, -1): sumx += s[I][M] if sumx > s[I][k]: break v[I][M - 1] += 1 for k in range(0, number[I] - 2): sumx = 0 for M in range(k + 1, number[I] - 1): sumx += s[I][M] if sumx > s[I][k]: break v[I][M + 1] += 1 for y in v[I]: print(y, end=" ") print("")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
T = int(input()) for i in range(T): N = int(input()) A = list(map(int, input().split(" "))) vote = [0] * N cs = list() sum = 0 for x in A: sum = sum + x cs.append(sum) for i in range(N): for j in range(i - 1, -1, -1): if cs[i - 1] - cs[j] <= A[i]: vote[j] += 1 else: break for j in range(i + 1, N): if cs[j - 1] - cs[i] <= A[i]: vote[j] += 1 else: break print(*vote)
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 BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
def leftsearch(prefs, n, l, h, k, i): while l <= h: m = (l + h) // 2 if prefs[i - 1] - prefs[m] > k: l = m + 1 elif m > 0: if prefs[i - 1] - prefs[m - 1] > k: return m else: h = m - 1 else: return m return -1 def rightsearch(prefs, n, l, h, k, i): while l <= h: m = (l + h) // 2 if prefs[m] - prefs[i] > k: h = m - 1 elif m < n - 1: if prefs[m + 1] - prefs[i] > k: return m + 1 else: l = m + 1 else: return m return -1 def func(n, arr): if n == 1: return [0] if n == 2: return [1, 1] prefs = [0] * n prefs[0] = arr[0] for i in range(1, n): prefs[i] = prefs[i - 1] + arr[i] l = [0] * n for i in range(n): if i == 0: m2 = rightsearch(prefs, n, i + 1, n - 1, arr[i], i) if m2 == -1: l[i + 1] += 1 l[i] -= 1 else: l[m2] += 1 l[i] -= 1 elif i == n - 1: m1 = leftsearch(prefs, n, 0, i - 1, arr[i], i) l[i - 1] += 1 if m1 > 0: l[m1 - 1] -= 1 else: m1 = leftsearch(prefs, n, 0, i - 1, arr[i], i) l[i - 1] += 1 if m1 > 0: l[m1 - 1] -= 1 m2 = rightsearch(prefs, n, i + 1, n - 1, arr[i], i) if m2 == -1: l[i + 1] += 1 l[i] -= 1 else: l[m2] += 1 l[i] -= 1 suffs = [0] * n suffs[n - 1] = l[n - 1] for i in range(n - 2, -1, -1): suffs[i] = suffs[i + 1] + l[i] return suffs for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) l1 = func(n, arr) print(*l1)
FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER IF VAR NUMBER RETURN LIST NUMBER NUMBER 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 LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN 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 FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
tst = int(input()) st = [] d = 0 for x in range(0, tst): num = int(input()) arr = [int(y) for y in input().split(" ")] lst = [] n = 0 for i in range(0, num): lst.append(n) for j in range(0, len(arr)): cnt = 0 for k in range(j + 1, len(arr), 1): if arr[j] >= cnt: lst[k] += 1 else: break cnt += arr[k] b = 0 if j > 0: for i in range(j - 1, -1, -1): if arr[j] >= b: lst[i] += 1 else: break b += arr[i] for i in range(0, len(lst)): print(lst[i], end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST 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 STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
def dfs(root): vis[root] = 1 print(root) for i in edge[root]: if not vis[i]: dfs(i) return def main(): t = 1 while t: t = int(input()) while t: n = int(input()) a = list(map(int, input().strip().split())) sum = [0] * n t -= 1 sum[0] = a[0] votes = [0] * n for i in range(1, n): sum[i] = sum[i - 1] + a[i] for j in range(n): for i in range(j + 1, n): if abs(sum[i] - sum[j] - a[i]) > a[j]: break votes[i] += 1 for i in range(j - 1, -1, -1): if abs(sum[j] - sum[i] - a[j]) > a[j]: break votes[i] += 1 print(" ".join(map(str, votes))) main()
FUNC_DEF ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) vote = [0] * n for i in range(n): fs = 0 for j in range(i - 1, -1, -1): if fs > a[i]: break else: fs += a[j] vote[j] += 1 bs = 0 for k in range(i + 1, n): if bs > a[i]: break else: bs += a[k] vote[k] += 1 print(*vote)
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) if n >= 2: y = [2] * n y[0] = 1 y[n - 1] = 1 for k in range(0, n - 2): sum = 0 for l in range(k + 1, n - 1): sum += a[l] if sum <= a[k]: y[l + 1] += 1 else: break for m in range(n - 1, 1, -1): sum = 0 for o in range(m - 1, 0, -1): sum += a[o] if sum <= a[m]: y[o - 1] += 1 else: break print(*y) else: print(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 IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) l.insert(0, 0) prefix = [0] * 100010 suffix = [0] * 100010 for i in range(1, n): total = 0 for j in range(i + 1, n + 1): total += l[j] if total > l[i]: break prefix[i + 1] += 1 prefix[j + 1] -= 1 for i in range(n, 1, -1): total = 0 for j in range(i - 1, 0, -1): total += l[j] if total > l[i]: break suffix[i] -= 1 suffix[j] += 1 for i in range(1, n + 1): prefix[i] += prefix[i - 1] suffix[i] += suffix[i - 1] print(prefix[i] + suffix[i], 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 EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
for _ in range(int(input())): N = int(input()) S = list(map(int, input().split())) t = [0] * N if N == 1: print("0") else: s = [0] * N for i in range(0, N): sum = 0 for j in range(i + 1, N): if sum <= S[i]: s[j] += 1 sum += S[j] else: break sum = 0 for j in range(i - 1, -1, -1): if sum <= S[i]: s[j] += 1 sum += S[j] else: break print(*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 BIN_OP LIST NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) rev = list(reversed(arr)) vote = [2] * n vote[0] -= 1 vote[n - 1] -= 1 for j in range(n - 2): summ = 0 for k in range(j + 2, n): summ += arr[k - 1] if summ <= arr[j]: vote[k] += 1 else: break summ = 0 for k in range(j + 2, n): summ += rev[k - 1] if summ <= rev[j]: vote[n - 1 - k] += 1 else: break print(*vote)
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 ASSIGN VAR BIN_OP LIST NUMBER VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
def problem3(n, list): Graph = [0] * n for i in range(n): diff = 0 for j in range(i - 1, -1, -1): if list[i] >= diff: Graph[j] += 1 diff = diff + list[j] else: break for i in range(n): diff = 0 for j in range(i + 1, n): if list[i] >= diff: Graph[j] += 1 diff = diff + list[j] else: break print(*Graph) test = int(input()) for i in range(test): n = int(input()) l = list(map(int, input().split())) problem3(n, l)
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL 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 EXPR FUNC_CALL VAR VAR VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) re = [0] * n for i in range(len(a)): s = 0 for j in range(i + 1, len(a)): if a[i] >= s: s += a[j] re[j] += 1 else: break a.reverse() for i in range(len(a)): s = 0 for j in range(i + 1, len(a)): if a[i] >= s: s += a[j] re[len(a) - 1 - j] += 1 else: break for i in re: print(i, 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence level of S_{i}. A single minion may cast any number of votes. Minion j will vote for minion i (i ≠ j) if and only if the influence level of the j-th minion is greater than or equal to the sum of influence levels of all the minions standing between them (excluding the i-th and j-th minion). Your task is to find the number of votes received by each minion. ------ Input ------ The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of minions. The second line contains N space-separated integers S_{1}, S_{2}, ..., S_{N}. ------ Output ------ For each test case, print a single line containing N space-separated integers. For each valid i, the i-th of these integers should denote the number of votes the i-th minion will get. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $1 ≤ S_{i} ≤ 10^{9} for each valid i$ $sum of N over all test cases won't exceed 10^{6}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≤ N ≤ 500$ $sum of N over all test cases won't exceed 10,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 2 4 4 3 2 1 5 1 2 2 3 1 ----- Sample Output 1 ------ 1 2 3 2 2 3 2 3 1 ----- explanation 1 ------ Example case 1: The first minion will get only a vote of the second minion. The second minion will get votes of the first and third minion. The third minion will get votes of the first, second and fourth minion. The fourth minion will get votes of the second and third minion.
test = int(input()) while test > 0: test -= 1 n = int(input()) l = list(map(int, input().split())) data = [] curr = 0 for x in l: curr += x data += [curr] count = [0] * n i = 0 while i < n: j = i + 1 while l[i] >= data[j - 1] - data[i] and j < n: count[j] += 1 j += 1 j = i - 1 while l[i] >= data[i - 1] - data[j] and j >= 0: count[j] += 1 j -= 1 i += 1 print(" ".join(map(str, count)))
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen. A rectangle (rectangular matrix) is called beautiful if in each row and in each column all values are different. What is the largest (by the total number of cells) beautiful rectangle you can construct? Print the rectangle itself. Input The first line contains n (1 ≤ n ≤ 4⋅10^5). The second line contains n integers (1 ≤ a_i ≤ 10^9). Output In the first line print x (1 ≤ x ≤ n) — the total number of cells of the required maximum beautiful rectangle. In the second line print p and q (p ⋅ q=x): its sizes. In the next p lines print the required rectangle itself. If there are several answers, print any. Examples Input 12 3 1 4 1 5 9 2 6 5 3 5 8 Output 12 3 4 1 2 3 5 3 1 5 4 5 6 8 9 Input 5 1 1 1 1 1 Output 1 1 1 1
def play(arr): n = len(arr) number2Count = {} for p in arr: number2Count[p] = number2Count.get(p, 0) + 1 count2Numbers = {} maxCnt = 0 for num in number2Count: cnt = number2Count[num] if not cnt in count2Numbers: count2Numbers[cnt] = [] count2Numbers[cnt].append(num) maxCnt = max(maxCnt, cnt) numRepeats = [0] * (n + 1) numRepeats[n] = len(count2Numbers.get(n, [])) for i in range(n - 1, 0, -1): numRepeats[i] = numRepeats[i + 1] + len(count2Numbers.get(i, [])) a_ideal = 0 b_ideal = 0 square = 0 square_ideal = 0 for a in range(1, n + 1): square += numRepeats[a] b = int(square / a) if a <= b: if square_ideal < a * b: square_ideal = a * b a_ideal = a b_ideal = b print(a_ideal * b_ideal) print(str(a_ideal) + " " + str(b_ideal)) matrix = [([0] * b_ideal) for p in range(0, a_ideal)] x = 0 y = 0 for cnt in range(maxCnt, 0, -1): for num in count2Numbers.get(cnt, []): for i in range(0, min(cnt, a_ideal)): if matrix[x][y] > 0: x = (x + 1) % a_ideal if matrix[x][y] == 0: matrix[x][y] = num x = (x + 1) % a_ideal y = (y + 1) % b_ideal for i in range(0, a_ideal): print(*matrix[i]) def main(): input() arr = list(map(int, input().split())) play(arr) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen. A rectangle (rectangular matrix) is called beautiful if in each row and in each column all values are different. What is the largest (by the total number of cells) beautiful rectangle you can construct? Print the rectangle itself. Input The first line contains n (1 ≤ n ≤ 4⋅10^5). The second line contains n integers (1 ≤ a_i ≤ 10^9). Output In the first line print x (1 ≤ x ≤ n) — the total number of cells of the required maximum beautiful rectangle. In the second line print p and q (p ⋅ q=x): its sizes. In the next p lines print the required rectangle itself. If there are several answers, print any. Examples Input 12 3 1 4 1 5 9 2 6 5 3 5 8 Output 12 3 4 1 2 3 5 3 1 5 4 5 6 8 9 Input 5 1 1 1 1 1 Output 1 1 1 1
n = int(input()) arr = list(map(int, input().split())) d = {} for i in arr: d[i] = d.get(i, 0) + 1 d2 = {} for k, v in d.items(): d2.setdefault(v, []).append(k) s = n prev = 0 ansp = ansq = anss = 0 for p in range(n, 0, -1): q = s // p if p <= q and q * p > anss: anss = q * p ansq = q ansp = p prev += len(d2.get(p, [])) s -= prev def get_ans(): cur_i = 0 cur_j = 0 cur = 0 for k, v in d3: for val in v: f = min(k, anss - cur, ansp) cur += f for i in range(f): cur_i = (cur_i + 1) % ansp cur_j = (cur_j + 1) % ansq if ans[cur_i][cur_j]: cur_i = (cur_i + 1) % ansp ans[cur_i][cur_j] = val print(anss) print(ansp, ansq) d3 = sorted(d2.items(), reverse=True) ans = [([0] * ansq) for i in range(ansp)] get_ans() for i in range(ansp): print(*ans[i])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL FUNC_CALL VAR VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR LIST VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen. A rectangle (rectangular matrix) is called beautiful if in each row and in each column all values are different. What is the largest (by the total number of cells) beautiful rectangle you can construct? Print the rectangle itself. Input The first line contains n (1 ≤ n ≤ 4⋅10^5). The second line contains n integers (1 ≤ a_i ≤ 10^9). Output In the first line print x (1 ≤ x ≤ n) — the total number of cells of the required maximum beautiful rectangle. In the second line print p and q (p ⋅ q=x): its sizes. In the next p lines print the required rectangle itself. If there are several answers, print any. Examples Input 12 3 1 4 1 5 9 2 6 5 3 5 8 Output 12 3 4 1 2 3 5 3 1 5 4 5 6 8 9 Input 5 1 1 1 1 1 Output 1 1 1 1
n = int(input()) l = list(map(int, input().split())) if n == 1: print(1) print(1, 1) print(l[0]) else: d = {} for i in l: d[i] = 0 for i in l: d[i] += 1 equal = [0] * (n + 1) for i in d: equal[d[i]] += 1 atmost = [0] * (n + 1) atmost[0] = equal[0] for i in range(1, n + 1): atmost[i] = atmost[i - 1] + equal[i] sumka = 0 best_iloczyn = 0 best_a = 0 best_b = 0 for a in range(1, n): if a**2 > n: break sumka += len(d) - atmost[a - 1] b_cand = sumka // a if b_cand < a: continue if a * b_cand > best_iloczyn: best_iloczyn = a * b_cand best_a = a best_b = b_cand print(best_iloczyn) print(best_a, best_b) li = [] for i in d: if d[i] >= best_a: li += [i] * min(best_a, d[i]) for i in d: if d[i] < best_a: li += [i] * min(best_a, d[i]) mat = [([0] * best_b) for i in range(best_a)] for dd in range(1, best_a + 1): if best_a % dd == 0 and best_b % dd == 0: du = dd i = 0 for st in range(du): for j in range(best_iloczyn // du): mat[i % best_a][(st + i) % best_b] = li[i] i += 1 for i in range(best_a): print(*mat[i])
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 EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR VAR BIN_OP LIST VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR BIN_OP LIST VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): d = dict() for element in A: if element in d: d[element] += 1 else: d[element] = d.get(element, 0) + 1 for element in d: if d[element] > N / 2: return element return -1
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): A.sort() mid = A[N // 2] if A.count(mid) > N // 2: return mid else: return -1
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): A.sort() x = 0 x1 = A[0] for i in A: if i == x1: x = x + 1 if x > N // 2: return i else: x1 = i x = 1 return -1
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def findCandidate(self, A): maj_index = 0 count = 1 for i in range(len(A)): if A[maj_index] == A[i]: count += 1 else: count -= 1 if count == 0: maj_index = i count = 1 return A[maj_index] def isMajority(self, A, cand): count = 0 for i in range(len(A)): if A[i] == cand: count += 1 if count > len(A) / 2: return True else: return False def majorityElement(self, A, N): cand = self.findCandidate(A) if self.isMajority(A, cand) == True: return cand else: return -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): if N == 1: return A[0] A.sort() count = 1 curr = A[0] for idx in range(1, N): if A[idx] == curr: count += 1 else: count = 1 curr = A[idx] if count > N / 2: return curr return -1
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): elem = A[0] count = 1 maxCount = 0 for idx in range(1, N): if A[idx] == elem: count += 1 elif count == 0: elem = A[idx] count = 1 else: count -= 1 for val in A: if val == elem: maxCount += 1 return elem if maxCount > N // 2 else -1
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): c = {} for i in A: c[i] = c.get(i, 0) + 1 if c[i] > N / 2: return i return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): element = None counter = 0 for i in range(N): if counter == 0: counter = 1 element = A[i] elif element == A[i]: counter += 1 else: counter -= 1 new_count = 0 for i in range(N): if A[i] == element: new_count += 1 if new_count > N // 2: return element else: return -1
CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): elem = 0 count = 0 maxcount = 0 for ele in A: if count == 0: elem = ele if ele == elem: count += 1 else: count -= 1 for val in A: if val == elem: maxcount += 1 return elem if maxcount > N // 2 else -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): cnt = 0 cur = 0 for i in range(N): if cnt == 0: cur = A[i] cnt = 1 elif cur == A[i]: cnt += 1 else: cnt -= 1 c = 0 for el in A: if el == cur: c += 1 return cur if c > N // 2 else -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): lis = {} x = N // 2 for i in A: if i in lis: lis[i] = lis[i] + 1 else: lis[i] = 1 if lis[i] > x: return i return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): dic = {} ans = -1 maxi = 0 if N == 1: return A[0] for ele in A: if ele in dic: dic[ele] += 1 else: dic[ele] = 1 for x in dic: if dic[x] > N // 2: maxi = dic[x] ans = x if maxi == 1: return -1 else: return ans
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER RETURN VAR
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, n): dic = {} ans = -1 for i in A: if i not in dic: dic[i] = 1 else: dic[i] += 1 for key, value in dic.items(): if value > n // 2: ans = key return ans
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def find_majority_candidate(self, A, N): maj_index = 0 count = 1 for i in range(len(A)): if A[maj_index] == A[i]: count += 1 else: count -= 1 if count == 0: maj_index = i count = 1 return A[maj_index] def is_majority_candidate(self, A, N, a): n = N // 2 count = 0 for i in range(N): if A[i] == a: count += 1 if count > n: return True return False def majorityElement(self, A, N): a = self.find_majority_candidate(A, N) f = self.is_majority_candidate(A, N, a) if f: return a return -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): mapp = {} mid = N // 2 for i in range(N): if A[i] in mapp: mapp[A[i]] += 1 else: mapp[A[i]] = 1 for k in mapp.keys(): if mapp[k] > mid: return k return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): d = {} for e in A: if e in d: d[e] = d[e] + 1 else: d[e] = 1 if d[e] > N / 2: return e return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): flag = True re = N // 2 dict = {} if N == 1: return A[0] else: for i in A: if i in dict: dict[i] += 1 else: dict[i] = 0 for i in dict: if dict[i] >= re: flag = False return i if flag == True: return -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT IF VAR NUMBER RETURN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): d = {} ans = -1 for i in range(N): if A[i] not in d: d[A[i]] = 1 else: d[A[i]] = d[A[i]] + 1 for k in d: if d[k] > N / 2: ans = k break return ans
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): d = {} f = 0 ans = 0 for ele in A: if ele in d.keys(): d[ele] += 1 else: d[ele] = 1 for keys in d.keys(): if d[keys] > N / 2: ans = keys f = 0 break else: f = 1 if f == 0: return ans else: return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): if N == 1: return A[0] else: my_list = A size = N / 2 element_count = {} for element in my_list: if element in element_count: element_count[element] += 1 else: element_count[element] = 1 max_count = max(element_count.values()) if max_count == 1 or max_count <= size: return -1 else: max_elements = [ element for element, count in element_count.items() if count == max_count ] for maxelements in max_elements: return maxelements
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR RETURN VAR
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): A.sort() n = N // 2 i = 0 while i < N: j = i if i + 1 < N and A[i] == A[i + 1]: while i + 1 < N and A[i] == A[i + 1]: i = i + 1 k = i if k - j + 1 > n: return A[i] i = i + 1 return -1
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): temp = N // 2 hashed = {} for i in A: hashed[i] = 1 + hashed.get(i, 0) for i in hashed: if hashed[i] > temp: return i return -1
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): mp = {} for i in range(N): if A[i] in mp: mp[A[i]] += 1 else: mp[A[i]] = 1 for i in mp.keys(): if mp[i] > N // 2: return i return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): count = {} res, maxcount = -1, 0 for n in A: count[n] = 1 + count.get(n, 0) res = n if count[n] > maxcount else res maxcount = max(maxcount, count[n]) return res if maxcount > N / 2 else -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, arr, n): d = {} m = -1 ans = -1 if n == 1: return arr[0] for i in arr: if i not in d: d[i] = 1 else: d[i] += 1 for i, j in d.items(): if j > n // 2: return i return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): m1, c1 = None, 0 for i in A: if i == m1: c1 += 1 elif c1 == 0: m1 = i c1 = 1 else: c1 -= 1 ans = -1 if A.count(m1) > N / 2: ans = m1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NONE NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): dict1 = {} maj = -1 majVal = -1 if N == 1: return A[0] for i in range(N): if A[i] in dict1: dict1[A[i]] += 1 else: dict1[A[i]] = 1 for key in dict1: if dict1[key] > maj: maj = dict1[key] majVal = key if maj > N // 2: return majVal else: return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, array, n): result, count = array[0], 1 for data in array[1:]: count = count + 1 if data == result else count - 1 if count == 0: result, count = data, 1 count = 0 for data in array: if data == result: count += 1 if not count > n // 2: result = -1 return result
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): c = 0 majr = 0 for i in range(0, N): if c == 0: majr = i c = 1 elif A[majr] == A[i]: c = c + 1 else: c = c - 1 C = 0 for i in range(len(A)): if A[majr] == A[i]: c = c + 1 if c > N // 2: return A[majr] return -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): d = {} for i in range(N): if N == 1: return A[0] if A[i] not in d: d[A[i]] = 1 else: d[A[i]] += 1 if d[A[i]] > N / 2 and d[A[i]] != 1: return A[i] return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): count = 1 i = 1 candidate = A[0] while i < len(A): if candidate == A[i]: count += 1 else: count -= 1 if count == 0: candidate = A[i] count = 1 i += 1 count = 0 for ele in A: if candidate == ele: count += 1 if count > N // 2: return candidate return -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): max = A[0] occur = 1 for i in range(1, len(A)): if occur == 0: occur += 1 max = A[i] elif A[i] == max: occur += 1 else: occur -= 1 if A.count(max) > N / 2: return max return -1
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): dic = {} for i in A: dic[i] = 1 + dic.get(i, 0) for k, v in dic.items(): if v > N // 2: return k return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def possible(self, l, n): val = l[0] cnt = 1 for i in range(1, n): if l[i] == val: cnt += 1 else: cnt -= 1 if cnt == 0: val = l[i] cnt = 1 return val def majorityElement(self, A, N): val = self.possible(A, N) return val if A.count(val) > N // 2 else -1
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): count = 1 maj_ele = A[0] for i in range(1, N): num = A[i] if num == maj_ele: count += 1 else: count -= 1 if count == 0: count = 1 maj_ele = num total = 0 for num in A: if num == maj_ele: total += 1 if total > int(N / 2): return maj_ele return -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): if N == 1: return A[0] Map = {} for ele in A: if ele in Map: Map[ele] += 1 if Map[ele] > N / 2: return ele else: Map[ele] = 1 return -1
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR NUMBER RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): c = N / 2 dict = {} if N == 1: return A[0] for x in A: if x not in dict: dict[x] = 1 elif x in dict: dict[x] += 1 if dict[x] > c: return x return -1
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT IF VAR NUMBER RETURN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR RETURN VAR RETURN NUMBER
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array. Example 1: Input: N = 3 A[] = {1,2,3} Output: -1 Explanation: Since, each element in {1,2,3} appears only once so there is no majority element. Example 2: Input: N = 5 A[] = {3,1,3,3,2} Output: 3 Explanation: Since, 3 is present more than N/2 times, so it is the majority element. Your Task: The task is to complete the function majorityElement() which returns the majority element in the array. If no majority exists, return -1. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{7} 0 ≤ A_{i} ≤ 10^{6}
class Solution: def majorityElement(self, A, N): half = N // 2 hash = {} for ele in A: if ele not in hash: hash[ele] = 1 else: hash[ele] += 1 for k, v in hash.items(): if v > half: return k return -1
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR RETURN VAR RETURN NUMBER
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
class Node: def __init__(self, value, parent): self.value = value self.parent = parent def solve(n, A): tree = Node(int(A[0]), None) ans = [A[0]] node = tree for a in A[1:]: a_i = int(a) if a == "1": new_node = Node(a_i, node) node = new_node else: while True: if node.value == a_i - 1: new_node = Node(a_i, node.parent) node = new_node break else: node = node.parent token = [] _node = node while _node is not None: token.append(str(_node.value)) _node = _node.parent ans.append(".".join(token[::-1])) return ans def main(): ans = [] t = int(input()) for _ in range(t): n = int(input()) A = [input() for _ in range(n)] ans.append(solve(n, A)) for a in ans: for c in a: print(c) main()
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NONE ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NONE EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST 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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
def f(a): prev = a[0] st = [a[0]] print(a[0]) for i in a[1:]: if i == 1: st.append(i) print(".".join(list(map(str, st)))) continue else: t = None for ind in range(0, len(st)): if i - st[ind] == 1: t = ind st = st[:t] + [i] print(".".join(list(map(str, st)))) for i in range(int(input())): a = [] for n in range(int(input())): a.append(int(input())) f(a)
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
for _ in range(int(input())): n = int(input()) x = int(input()) l = [1] print(1) for i in range(1, n): x = int(input()) if x == 1: l.append(1) else: j = len(l) - 1 while j >= 0: if x == l[j] + 1: l[j] += 1 break j -= 1 l = l[: j + 1] for j in range(len(l) - 1): print(l[j], end=".") print(l[-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 ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
for _ in range(int(input())): n = int(input()) b = [(0) for i in range(1007)] p = -1 for i in range(n): a = int(input()) if a > 1: while b[p] != a - 1: p -= 1 p -= 1 p += 1 b[p] = a print(*b[: p + 1], sep=".")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
for _ in range(int(input())): n = int(input()) l = [] for i in range(n): l += [int(input())] a = [[l[0]]] for i in range(1, n): if l[i] == 1: a += [a[-1] + [1]] else: j = len(a[-1]) - 1 while a[-1][j] + 1 != l[i]: j -= 1 a += [a[-1][:j] + [l[i]]] for i in range(len(a)): for j in range(len(a[i]) - 1): print(str(a[i][j]) + ".", end="") print(a[i][-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 VAR LIST FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR LIST BIN_OP VAR NUMBER LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR LIST BIN_OP VAR NUMBER VAR LIST VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR VAR NUMBER
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
def findr(a, i, cur): for k in range(cur, -1, -1): if a[k] == i: return k t = int(input()) for _ in range(t): n = int(input()) a = [] b = [[]] urov_last_num = [(0) for __ in range(1000)] urov_strings = [""] for k in range(n): a.append(int(input())) print("1") urov = 0 urov_last_num[0] = 1 for k in range(1, n): if a[k] - a[k - 1] == 1: urov_last_num[urov] += 1 elif a[k] == 1: urov_strings.append("") urov_strings[urov + 1] = f"{urov_strings[urov]}{urov_last_num[urov]}." urov += 1 urov_last_num[urov] = 1 else: urov = findr(urov_last_num, a[k] - 1, urov - 1) urov_last_num[urov] += 1 print(f"{urov_strings[urov]}{urov_last_num[urov]}")
FUNC_DEF FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR 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 LIST ASSIGN VAR LIST LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
import sys def Ints(): return map(int, sys.stdin.readline().strip().split()) def Strs(): return map(str, sys.stdin.readline().strip().split()) def Array(): return list(map(int, sys.stdin.readline().strip().split())) def Str(): return sys.stdin.readline().strip() def Int(): return int(sys.stdin.readline().strip()) def MOD(): return 1000000007 t = Int() for i in range(t): n = Int() a = [] for i in range(n): a.append(Int()) stack = [] depth = 0 for i in range(n): if not stack: stack.append((str(a[i]), i, depth + 1)) elif a[i] == 1: sno, index, d = stack[-1] stack.append((sno + ".1", i, d + 1)) elif a[i] == 1 + a[stack[-1][1]]: sno, index, d = stack[-1] sno = sno.split(".") sno[-1] = str(a[i]) stack[-1] = ".".join(sno), i, d else: d = stack[-1][2] while stack and a[stack[-1][1]] != a[i] - 1: stack.pop() sno, index, d1 = stack[-1] sno = sno.split(".") sno[-1] = str(a[i]) stack[-1] = ".".join(sno), i, d1 print(stack[-1][0])
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR STRING VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL STRING VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
t = int(input()) for _ in range(t): n = int(input()) arr = ["", "1"] a = int(input()) print(1) for __ in range(n - 1): a = int(input()) if a == 1: print(arr[-1] + ".1") arr.append(arr[-1] + ".1") elif int(arr[-1][-1]) + 1 == a: arr[-1] = arr[-1][: arr[-1].rfind(".") + 1] + str(a) print(arr[-1]) else: while int(arr[-1][arr[-1].rfind(".") + 1 :]) != a - 1: arr.pop() print(arr[-1][: arr[-1].rfind(".") + 1] + str(a)) arr[-1] = arr[-1][: arr[-1].rfind(".") + 1] + str(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 LIST STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER STRING NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER STRING NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER STRING NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER STRING NUMBER FUNC_CALL VAR VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
final = [] t = int(input()) for z in range(t): n = int(input()) ls = [] for j in range(n): inp = int(input()) if len(ls) == 0: ls.append(inp) elif inp == ls[-1] + 1: ls[-1] = inp activels = False elif inp == 1: ls.append(1) else: while len(ls) > 0: if inp == ls[-1] + 1: ls[-1] = inp break ls = ls[:-1] final.append(".".join(map(str, ls))) for i in final: print(i)
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
for _ in range(int(input())): n = int(input()) li = [int(input()) for _ in range(n)] st = [] for n in li: if n == 1: st.append(1) else: while st[-1] != n - 1: st.pop() st.append(st.pop() + 1) print(".".join(map(str, st)))
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 VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
def pr(v): s = "" for j in range(len(v)): s += v[j] + "." print(s[:-1]) t = int(input()) while t: t -= 1 n = int(input()) ans, i = [], 0 while i < n: temp = int(input()) if temp == 1: ans.append(str(temp)) pr(ans) elif int(ans[-1]) == temp - 1: ans.pop() ans.append(str(temp)) pr(ans) else: while int(ans[-1]) != temp - 1: ans.pop() ans.pop() ans.append(str(temp)) pr(ans) i += 1
FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
for _ in range(int(input())): n = int(input()) s = [] lens = 0 for __ in range(n): x = int(input()) if x == 1: s.append(x) lens += 1 print(".".join([str(x) for x in s])) else: while 1: if lens == 0: break if s[-1] != x - 1: s.pop() lens -= 1 if s[-1] == x - 1: s.pop() lens -= 1 break if lens == 0: s.append(x) lens += 1 else: s.append(x) lens += 1 print(".".join([str(x) for x in s]))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR WHILE NUMBER IF VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
for _ in range(int(input())): x = int(input()) Ans = [] s = [] for i in range(x): a = int(input()) if a == 1: s.append(1) Ans.append(list(s)) else: while s[-1] != a - 1: s.pop() s[-1] += 1 Ans.append(list(s)) for i in range(len(Ans)): for j in range(len(Ans[i])): if j != len(Ans[i]) - 1: print(Ans[i][j], ".", sep="", end="") else: print(Ans[i][j])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING STRING STRING EXPR FUNC_CALL VAR VAR VAR VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
t = int(input()) def print_ol(): n = int(input()) levels = [] for i in range(n): x = int(input()) if x == 1: levels.append(1) else: while levels[-1] + 1 != x: levels.pop() levels[-1] += 1 print(".".join(list(map(str, levels)))) for j in range(t): print_ol()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
import sys T = int(sys.stdin.readline().strip()) for t in range(0, T): n = int(sys.stdin.readline().strip()) x = int(sys.stdin.readline().strip()) ans = [[x]] for i in range(0, n - 1): x = int(sys.stdin.readline().strip()) ans.append(ans[-1][:]) if x == 1: ans[-1].append(x) else: while x != ans[-1][-1] + 1: ans[-1].pop() ans[-1][-1] = ans[-1][-1] + 1 for x in ans: print(".".join(list(map(str, x))))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR WHILE VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
t = int(input()) for _ in range(t): n = int(input()) stack = [] arr = [] for i in range(n): k = int(input()) if k == 1: stack.append(k) arr.append("1") else: while stack[-1] != k - 1: stack.pop() arr.pop() stack[-1] += 1 arr[-1] = str(k) print(".".join(arr))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING WHILE VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
for _ in range(int(input())): N = int(input()) S = [] for _ in range(N): x = int(input()) if x == 1: S.append(x) else: while S and S[-1] != x - 1: S.pop() assert S S[-1] = x print(".".join(map(str, S)))
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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
for _ in range(int(input())): size = int(input()) nums = [] index = [1] for i in range(size): nums.append(int(input())) index.append(0) lvl = 1 print(1) for i in range(1, size): if nums[i] == 1: lvl += 1 index[lvl - 1] = 1 elif nums[i] == nums[i - 1] + 1: index[lvl - 1] += 1 else: lvl -= 1 while index[lvl - 1] != nums[i] - 1: lvl -= 1 index[lvl - 1] += 1 for j in range(lvl - 1): print(index[j], end=".") print(index[lvl - 1])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
for _ in range(int(input())): n = int(input()) ar = [0] for i in range(n): x = int(input()) pos = -1 for j in range(len(ar) - 1, 0, -1): if ar[j] == x - 1: pos = j break if pos != -1: for j in range(len(ar) - pos): ar.pop() ar.append(x) for j in range(1, len(ar) - 1): print(ar[j], end=".") print(ar[-1])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$ and can be one of two types: Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$ (starting a list of a deeper level), or Add an item $a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$ (continuing the current level). Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section. When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number. William wants you to help him restore a fitting original nested list. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows. The first line of each test case contains a single integer $n$ ($1 \le n \le 10^3$), which is the number of lines in the list. Each of the next $n$ lines contains a single integer $a_i$ ($1 \le a_i \le n$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $n$ across all test cases does not exceed $10^3$. -----Output----- For each test case output $n$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any. -----Examples----- Input 2 4 1 1 2 3 9 1 1 1 2 2 1 2 1 2 Output 1 1.1 1.2 1.3 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 -----Note----- In the second example test case one example of a fitting list is: 1 1.1 1.1.1 1.1.2 1.2 1.2.1 2 2.1 2.2 This list can be produced by using the sequence of operations shown below: Original list with a single item $1$. Insert item $2$ by using the insertion operation of the second type after item $1$. Insert item $1.1$ by using the insertion operation of the first type after item $1$. Insert item $1.2$ by using the insertion operation of the second type after item $1.1$. Insert item $1.1.1$ by using the insertion operation of the first type after item $1.1$. Insert item $1.1.2$ by using the insertion operation of the second type after item $1.1.1$. Insert item $1.2.1$ by using the insertion operation of the first type after item $1.2$. Insert item $2.1$ by using the insertion operation of the first type after item $2$. Insert item $2.2$ by using the insertion operation of the second type after item $2.1$.
t = int(input()) while int(t) > 0: n = int(input()) v = [] while n > 0: char = int(input()) if len(v) == 0 or char == 1: v.append(char) else: for i in range(len(v) - 1, -1, -1): if char == v[i] + 1: v[i] = char break v.pop() print(".".join(map(str, v))) n = n - 1 t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER