description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys from itertools import accumulate def main(): t = int(sys.stdin.readline()) for _ in range(t): n, k, z = [int(x) for x in sys.stdin.readline().split(" ")] a = [int(x) for x in sys.stdin.readline().split(" ")] prefix = list(accumulate(a)) best = 0 for t in range(z + 1): rightMoves = k - 2 * t if rightMoves < 0: break bestPairSum = a[0] + a[1] s = 0 for i in range(0, min(rightMoves + 1, n - 1)): bestPairSum = max(bestPairSum, a[i] + a[i + 1]) best = max(best, prefix[rightMoves] + t * bestPairSum) print(best) main()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys input = sys.stdin.readline T = int(input()) for testcase in range(1, T + 1): n, k, z = map(int, input().split()) a = list(map(int, input().split())) res = 0 ma = [0] * n for i in range(k + 1): res += a[i] if i > 0: ma[i] = max(ma[i - 1], a[i] + a[i - 1]) s = res mns = 0 for i in range(z): if k - i * 2 - 1 < 0: break mns += a[k - i * 2] + a[k - i * 2 - 1] tmp = s - mns tmp += (i + 1) * ma[k - i * 2 - 1] res = max(res, tmp) print(res)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys sys.setrecursionlimit(2147483647) input = sys.stdin.readline def calc(mani, arr): n, k, z = mani scores = [] pairs = [] for i in range(k): pairs.append(arr[i] + arr[i + 1]) for i in range(0, z + 1): if k - 2 * i + 1 <= 0: continue max_pair = max(pairs[: k - 2 * i + 1]) scores.append(sum(arr[: k - 2 * i + 1]) + max_pair * i) return max(scores) def main(): n = int(input()) mani = [] arr = [] for _ in range(n): mani.append(list(map(int, input().split(" ")))) arr.append(list(map(int, input().split(" ")))) for i in range(n): print(calc(mani[i], arr[i])) main()
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
cases = int(input()) for i in range(cases): l1 = input().split(" ") n = int(l1[0]) k = int(l1[1]) z = int(l1[2]) l2 = input().split(" ") arr = [] for a in l2: arr.append(int(a)) ans = 0 if z == 0: ans = sum(arr[0 : k + 1]) print(ans) continue if k == 1: print(arr[0] + arr[1]) continue sol = [] arr2 = [] for j in range(0, z + 1): bound = k - 2 * j + 1 arr1 = arr[:bound] if bound < len(arr) - 1 and bound >= 0: arr2 = arr[: bound + 1] elif bound == len(arr): sol.append(sum(arr1)) continue elif bound < 0: continue temp = 0 for m in range(len(arr2) - 1): ele1 = arr2[m] ele2 = arr2[m + 1] s = ele1 + ele2 if s > temp: temp = s total = j * temp + sum(arr1) sol.append(total) print(max(sol))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
def walk(arr, k, l): ans = 0 for t in range(l + 1): mx = 0 temp = 0 if k - 2 * t < 0: continue for j in range(0, k - 2 * t + 1): if j < len(arr) - 1: mx = max(mx, arr[j] + arr[j + 1]) temp += arr[j] ans = max(ans, temp + t * mx) return ans a = int(input()) for i in range(a): a, b, c = map(int, input().strip().split()) lst = list(map(int, input().strip().split())) print(walk(lst, b, c))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for i in range(t): n, k, z = map(int, list(input().split())) a = list(map(int, list(input().split()))) l = 0 for j in range(min(z + 1, k // 2 + 1)): x = sum(a[: k - 2 * j + 1]) d = 0 for m in range(k - 2 * j + 1): c = sum(a[m : m + 2]) if c > d: d = c y = x + j * d if y > l: l = y print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
from sys import stdin for _ in range(int(stdin.readline())): n, k, z = map(int, stdin.readline().split()) arr = list(map(int, stdin.readline().split())) su = [0] for i in arr: su.append(su[-1] + i) fin = su[k + 1] for i in range(1, k): ans = su[i + 1] K, Z = k - i, z for _ in range(min(K // 2, z)): ans += arr[i - 1] + arr[i] Z -= min(K // 2, z) K -= min(K // 2, z) * 2 if not K: fin = max(ans, fin) elif Z: fin = max(ans + arr[i - 1], ans + arr[i + 1], fin) else: fin = max(fin, ans + su[i + K + 1] - su[i + 1]) print(fin)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for _ in range(t): n, k, z = map(int, input().split()) x = list(map(int, input().split())) s = 0 for i in range(z + 1): temp = 0 p = k + 1 - 2 * i summ = 0 for j in range(p): summ += x[j] if j < n - 1: temp = max(temp, x[j] + x[j + 1]) temp = i * temp s = max(s, summ + temp) print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
from sys import stdin, stdout input = stdin.readline for _ in range(int(input())): n, k, z = map(int, input().split()) a = list(map(int, input().split())) ans = 0 b = a[:] for i in range(1, n): a[i] += a[i - 1] for i in range(1, k + 1): m = min(z, (k - i + 1) // 2) r = m * (b[i] + b[i - 1]) + a[k - 2 * m] ans = max(ans, r) stdout.write(str(ans) + "\n")
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for i in range(t): n, k, z = map(int, input().split()) l = list(map(int, input().split())) m_score = sum(l[: k + 1]) if z >= 1: s = 0 for i in range(k - 2): if i >= 0: s = max(s, l[i] + l[i + 1]) if k >= 2: m_score = max(m_score, sum(l[: k - 1]) + s) s = max(l[k - 2] + l[k - 1], s) m_score = max(m_score, sum(l[:k]) + l[k - 2]) if z >= 2: s = 0 for i in range(k - 4): if i >= 0: s = max(s, l[i] + l[i + 1]) if k >= 4: m_score = max(m_score, sum(l[: k - 3]) + 2 * s) s = max(l[k - 4] + l[k - 3], s) m_score = max(m_score, sum(l[: k - 2]) + s + l[k - 4]) if z >= 3: s = 0 for i in range(k - 6): if i >= 0: s = max(s, l[i] + l[i + 1]) if k >= 6: m_score = max(m_score, sum(l[: k - 5]) + 3 * s) s = max(l[k - 6] + l[k - 5], s) m_score = max(m_score, sum(l[: k - 4]) + 2 * s + l[k - 6]) if z >= 4: s = 0 for i in range(k - 8): if i >= 0: s = max(s, l[i] + l[i + 1]) if k >= 8: m_score = max(m_score, sum(l[: k - 7]) + 4 * s) s = max(l[k - 8] + l[k - 7], s) m_score = max(m_score, sum(l[: k - 6]) + 3 * s + l[k - 8]) if z >= 5: s = 0 for i in range(k - 10): if i >= 0: s = max(s, l[i] + l[i + 1]) if k >= 10: m_score = max(m_score, sum(l[: k - 9]) + 5 * s) s = max(l[k - 10] + l[k - 9], s) m_score = max(m_score, sum(l[: k - 8]) + 4 * s + l[k - 10]) print(m_score)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n, k, z = map(int, input().split()) A = list(map(int, input().split())) B = [(0) for i in range(n)] B[0] = A[0] for i in range(1, n): B[i] = A[i] + B[i - 1] ans = A[0] ans1 = A[0] for i in range(1, n): if k == 0: ans = max(ans, ans1) break k = k - 1 ans1 = ans1 + A[i] ans2 = ans1 v = k - 2 * z if v >= 0: ans2 = ans2 + z * (A[i - 1] + A[i]) + B[i + v] - B[i] else: v = k // 2 if k % 2 == 0: ans2 = ans2 + v * (A[i - 1] + A[i]) else: ans2 = ans2 + v * (A[i - 1] + A[i]) + A[i - 1] ans = max(ans, ans2) ans = max(ans, ans1) print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for s in range(t): n, m, k = map(int, input().split()) b = list(map(int, input().split())) m += 1 dp = [[(0) for i in range(m + 1)] for j in range(k + 1)] b = [0] + b add = 0 for i in range(1, m + 1): dp[0][i] = b[i] + add add += b[i] maxi = dp[0][m] for i in range(1, k + 1): for j in range(1, m + 1): if 2 * i + j > m: maxi = max(maxi, dp[i][j - 1]) break dp[i][j] = max(dp[i][j - 1], dp[i - 1][j + 1]) + b[j] print(maxi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
def main(): t = int(input()) for _ in range(t): n, k, z = map(int, input().split()) a = list(map(int, input().split())) M = 0 z *= 2 pref = [] pref_sum = 0 for j in range(n): pref_sum += a[j] pref.append(pref_sum) for i in range(1, n): if i > k: break pair = a[i] + a[i - 1] if z < k - i: total = pair * (z // 2) total += pref[k - z] else: total = pref[i] if (k - i) % 2 == 0: total += pair * ((k - i) // 2) else: total += pair * ((k - i) // 2) total += a[i - 1] M = max(M, total) print(M) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
ans = [] for _ in range(int(input())): n, k, z = map(int, input().split()) u = list(map(int, input().split())) z = min(z, k // 2) x = k - 2 * z if x == 0: x = 1 mx = 0 for i in range(1, x + 1): mx = max(mx, u[i] + u[i - 1]) for i in range(1, n): u[i] += u[i - 1] u.append(0) ansi = u[x] ansj = 0 for i in range(x, k + 1): cur = u[i] + (k - i) // 2 * mx if (k - i) % 2 == 1: cur += u[i - 1] - u[i - 2] ansj = max(ansj, cur) if i < n - 1 and u[i + 1] - u[i - 1] > mx: mx = u[i + 1] - u[i - 1] ans.append(ansj) print("\n".join(map(str, ans)))
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for i in range(t): n, k, z = map(int, input().split()) arr = list(map(int, input().split())) arr_sum = [(arr[a] + arr[a + 1]) for a in range(n - 1)] maximum = 0 for j in range(min(z + 1, k // 2 + 1)): maximum = max( sum(arr[: k - 2 * j + 1]) + max(arr_sum[: k - 2 * j + 1]) * j, maximum ) print(maximum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = map(int, input().split()) a = list(map(int, input().split())) ans = 0 s = [0] for i in range(n): s.append(s[len(s) - 1] + a[i]) for i in range(1, k + 1): m = s[i + 1] if 2 * z == k - i: m += (a[i - 1] + a[i]) * z elif 2 * z < k - i: m += (a[i - 1] + a[i]) * z + s[min(n, k + 1 - 2 * z)] - s[min(n, i + 1)] else: m += (a[i - 1] + a[i]) * ((k - i) // 2) + a[i - 1] * ( k - i - 2 * ((k - i) // 2) ) ans = max(m, ans) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for test in range(t): n, k, z = map(int, input().split()) arr = list(map(int, input().split())) dp = [[[0, 0] for i in range(z + 1)] for j in range(n)] dp[0][0][0] = arr[0] m = 0 for j in range(z + 1): for i in range(n): if i > 0: dp[i][j] = [arr[i] + dp[i - 1][j][0], dp[i - 1][j][1] + 1] if ( i < n - 1 and j > 0 and dp[i][j - 1][0] + arr[i + 1] + arr[i] > dp[i][j][0] ): dp[i][j] = [ dp[i][j - 1][0] + arr[i + 1] + arr[i], dp[i + 1][j - 1][1] + 1, ] if dp[i][j][1] == k: m = max(m, dp[i][j][0]) print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR LIST BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
from sys import stdin input = stdin.readline def answer(z): dp = [0] for i in range(1, k + 1): dp.append(max(dp[i - 1], a[i] + a[i - 1])) total = sum(a[: k + 1]) ans = total c = 0 for i in range(k - 1, -1, -2): if z - c == 0: break total -= a[i] + a[i + 1] ans = max(ans, total + (c + 1) * dp[i]) c += 1 return ans for T in range(int(input())): n, k, z = map(int, input().split()) a = list(map(int, input().split())) print(answer(z))
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = map(int, input().split()) b = list(map(int, input().split())) sm = [] s = sum(b[: k + 1]) z1 = max(1, k - 2 * z) s1 = sum(b[: z1 + 1]) sm.append(s) for i in range(1, k + 1): m = min((k - i + 1) // 2, z) m1 = min((k - i) // 2, z) cs = s1 + m * b[i - 1] + m1 * b[i] if i > z1: cs = cs + sum(b[z1 + 1 : i + 1]) sm.append(cs) print(max(sm))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys input = sys.stdin.buffer.readline T = int(input()) for _ in range(T): n, k, z = map(int, input().split()) ls = list(map(int, input().split())) sm, mxpr, mx = ls[0], 0, 0 for i in range(1, 1 + k): sm += ls[i] mxpr = max(mxpr, ls[i - 1] + ls[i]) if (k - i) % 2: if z > 0 and i + (z - 1) * 2 + 1 >= k: lsm = sm + ls[i - 1] + (k - i) // 2 * mxpr mx = max(mx, lsm) elif i + z * 2 >= k: lsm = sm + (k - i) // 2 * mxpr mx = max(mx, lsm) print(mx)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = map(int, input().split()) a = [int(i) for i in input().split()] maxx = 0 p = [] for i in range(z + 1): r = k + 1 - 2 * i ans = 0 maxx = 0 for j in range(r): if j + 1 < n: maxx = max(maxx, a[j] + a[j + 1]) ans += a[j] p.append(ans + maxx * i) print(max(p))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) while t: n, k, z = [int(i) for i in input().split()] a = [int(i) for i in input().split()] k_sum = sum(a[0 : k + 1]) pre = [a[0]] for i in range(1, k + 1): pre.append(pre[-1] + a[i]) maxi = a[0] curr = a[0] for i in range(1, k + 1): left = k - i curr += a[i] if left >= 2 * z: temp = curr + a[i - 1] * z + a[i] * z left = left - 2 * z temp += pre[left + i] - pre[i] maxi = max(temp, maxi) else: temp = curr + a[i - 1] * (left // 2 + left % 2) + a[i] * (left // 2) maxi = max(temp, maxi) maxi = max(curr, maxi) print(maxi) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for _ in range(t): n, k, z = map(int, input().split()) A = list(map(int, input().split())) score = sum(A[: k + 1]) pairsMax = [] for i in range(k): if i == 0: pairsMax.append(A[i] + A[i + 1]) else: pairsMax.append(max(A[i] + A[i + 1], pairsMax[-1])) scoreBase = score for j in range(k, -1, -2): if (k - j) // 2 > z: break if j < k: scoreBase -= A[j + 2] + A[j + 1] score = max(score, scoreBase + pairsMax[j + 1] * ((k - j) // 2)) print(score)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
from sys import stdin def readline(): return stdin.readline() tests = int(readline()) def solve(n, k, z, a): p = [0] for v in a: p.append(v + p[-1]) s = a[0] res = a[0] for i in range(1, min(n, k + 1)): s += a[i] r = (k - i) // 2 loop = min(z, r) cur = s + loop * (a[i] + a[i - 1]) if z - loop > 0 and k - i - loop * 2 > 0: cur += a[i - 1] else: rem = k - i - loop * 2 last = min(i + rem + 1, n) cur += p[last] - p[i + 1] res = max(res, cur) return res for t in range(0, tests): n, k, z = list(map(int, readline().split(" "))) a = list(map(int, readline().split(" "))) print(solve(n, k, z, a))
FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for i in range(t): n, k, z = input().split() n = int(n) k = int(k) z = int(z) arr = input().split() arr = list(map(int, arr)) best = [] for i in range(len(arr) - 1): best.append(arr[i] + arr[i + 1]) for i in range(1, len(best)): best[i] = max(best[i], best[i - 1]) best.append(best[-1]) highest = 0 for left in range(z + 1): rightedge = k - 2 * left if rightedge < 0: continue current = sum(arr[: rightedge + 1]) + left * best[rightedge] if current > highest: highest = current print(highest)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = map(int, input().split()) ar = list(map(int, input().split())) ans = 0 pre = [ar[0]] mx = [ar[0] + ar[1]] for i in range(1, len(ar)): pre.append(pre[i - 1] + ar[i]) for i in range(1, len(ar) - 1): mx.append(max(mx[i - 1], ar[i] + ar[i + 1])) mx.append(0) for i in range(z + 1): index = k - 2 * i if index < 0: break ans = max(ans, i * mx[index] + pre[index]) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, k, z = map(int, input().split()) a = [0] + list(map(int, input().split())) dp = [[(0) for i in range(n + 1)] for j in range(z + 1)] for i in range(z + 1): for j in range(1, n + 1): if j - 1 + i * 2 > k: break if i == 0 and j == 1: dp[i][j] = a[j] elif i == 0 or j == n: dp[i][j] = dp[i][j - 1] + a[j] elif j == 1: dp[i][j] = dp[i - 1][j + 1] + a[j] else: dp[i][j] = max(dp[i][j - 1] + a[j], dp[i - 1][j + 1] + a[j]) ans = 0 for i in range(z + 1): ans = max(ans, max(dp[i])) print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys input = sys.stdin.readline t = int(input()) for ii in range(t): n, k, z = map(int, input().split()) A = list(map(int, input().split())) l = 2 * (z + 1) D = [[[0, -1] for j in range(l)] for _ in range(k + 1)] D[0][0] = [A[0], 0] for i in range(1, k + 1): for j in range(1, l, 2): if j - 3 >= 0: if D[i - 1][j - 3][1] >= 1: d0 = D[i - 1][j - 3][0] d1 = D[i - 1][j - 3][1] D[i][j] = [d0 + A[d1 - 1], d1 - 1] for j in range(0, l, 2): d00 = D[i - 1][j][0] d10 = D[i - 1][j + 1][0] d01 = D[i - 1][j][1] d11 = D[i - 1][j + 1][1] dm1 = max(d01, d11) dm0 = max(d00, d10) if dm1 != -1: D[i][j] = [dm0 + A[dm1 + 1], dm1 + 1] print(max([D[-1][i][0] for i in range(l)]))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for _ in range(t): n, k, z = [int(x) for x in input().split()] a = [int(x) for x in input().split()] best = -1 best_pair = -1 acc = a[0] used = 1 for prev, cur in zip(a[:-1], a[1:]): used += 1 if prev + cur > best_pair: best_pair = prev + cur acc += cur if (k - used + 2) // 2 <= z and used <= k + 1: score = acc + (k + 1 - used) // 2 * best_pair + (k + 1 - used) % 2 * prev if score > best: best = score print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys input = sys.stdin.buffer.readline t = int(input()) for _ in range(t): n, k, z = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] maxpair = [(0) for _ in range(n + 1)] for i in range(1, n): maxpair[i] = max(maxpair[i - 1], arr[i - 1] + arr[i]) z = min(z, k // 2) maxTotal = 0 for backMoves in range(z + 1): idx = k - 2 * backMoves + 1 thisTotal = sum(arr[:idx]) + backMoves * maxpair[idx] maxTotal = max(maxTotal, thisTotal) print(maxTotal)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = map(int, input().split()) ls = list(map(int, input().split())) mx = ls[0] + ls[1] mxscr = 0 pre = ls[0] for i in range(1, k + 1): pre += ls[i] mx = max(mx, ls[i] + ls[i - 1]) scr = pre + mx * min((k - i) // 2, z) if k - (i + 2 * min((k - i) // 2, z)) and z - min((k - i) // 2, z): scr += ls[i - 1] mxscr = max(scr, mxscr) print(mxscr)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
rw = int(input()) for qwe in range(rw): n, k, z = map(int, input().split()) a = list(map(int, input().split())) p = [] pref = [] q = 0 for i in range(n): q += a[i] pref.append(q) for i in range(1, n): if k < i: break if k == i: p.append(pref[i]) break if k - i - z * 2 > 0: p.append(pref[i] + (a[i - 1] + a[i]) * z) p[i - 1] += pref[k - z * 2] - pref[i] else: p.append(pref[i] + (a[i - 1] + a[i]) * ((k - i) // 2)) if (k - i) % 2 == 1: p[i - 1] += max(a[i - 1], a[i + 1]) print(max(p))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for i in " " * int(input()): n, k, z = map(int, input().split()) L = list(map(int, input().split())) mx = sum(L[: k + 1]) sumL = [] for j in range(n - 1): sumL.append(L[j] + L[j + 1]) for j in range(z): if k <= 2 * j + 1: break count = max(sumL[: k - 2 * j - 1]) * (j + 1) + sum(L[: k + 1 - 2 * (j + 1)]) if count > mx: mx = count print(mx)
FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys input = sys.stdin.readline for f in range(int(input())): n, k, z = map(int, input().split()) a = list(map(int, input().split())) sc = a[0] gob = [0] * n i = 0 while i < k: i += 1 sc += a[i] gob[i] = a[i] + a[i - 1] mxsc = sc zcop = z for j in range(1, k): sccop = sc i = k z = zcop while z > 0: z -= 1 if i > 1: mxsc = max(mxsc, sccop + a[i - 2] - a[i]) if j < i - 1: sccop += gob[j] sccop -= gob[i] i -= 2 mxsc = max(mxsc, sccop) print(mxsc)
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] pref = [arr[0]] for i in range(1, len(arr)): pref.append(pref[-1] + arr[i]) ans = arr[0] for i in range(1, k + 1): kleft = k - i here_sum = pref[i] adj_sum = arr[i - 1] + arr[i] left = min(z, kleft // 2) here_sum += adj_sum * left krem = kleft - left * 2 zrem = z - left if krem > 0 and zrem > 0: here_sum += pref[i - 1 + krem - 1] - pref[i - 1] + arr[i - 1] elif krem > 0: here_sum += pref[i + krem] - pref[i] ans = max(ans, here_sum) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = map(int, input().split()) A = list(map(int, input().split())) if z == 0: print(sum(A[0 : k + 1])) else: sum0 = A[0] sum0 += sum(A[1 : k + 1]) mxn = sum0 for i in range(1, min(z + 1, k // 2 + 1)): mx = A[0] + A[1] for j in range(1, k - 2 * i + 1): mx = max(mx, A[j] + A[j - 1]) val = A[k - 2 * i] + A[k - 2 * i + 1] mxn = max( mxn, sum(A[0 : k - 2 * i + 1]) + i * mx, sum(A[0 : k - 2 * i + 2]) + (i - 1) * val + A[k - 2 * i], ) print(mxn)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
def solve(arr, k, z): pre = [0] for i in arr: pre.append(pre[-1] + i) ans = 0 for i in range(1, len(arr)): moves = k - i s = pre[i] left = min(z * 2, moves) s += (arr[i] + arr[i - 1]) * (left // 2) + left % 2 * arr[i - 1] movesleft = moves - left s += pre[i + movesleft + 1] - pre[i] ans = max(ans, s) return ans for _ in range(int(input())): n, k, z = map(int, input().split()) arr = list(map(int, input().split()))[: k + 1] print(solve(arr, k, z))
FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
from sys import stdin, stdout input = stdin.readline mp = lambda: map(int, input().split()) it = lambda: int(input()) for i in range(it()): a, b, c = mp() li = list(mp()) ans = 0 for j in range(c + 1): max_pos = b - 2 * j if max_pos >= 0: mx_2_ele = 0 sm = 0 for ele in range(max_pos + 1): if a - 1 - ele > 0: mx_2_ele = max(mx_2_ele, li[ele] + li[ele + 1]) sm += li[ele] pair_sum = j * mx_2_ele ans = max(ans, sm + pair_sum) print(ans)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
def solve(): n, steps, left = map(int, input().split()) scores = [int(x) for x in input().split()] sum = 0 ans = 0 maxPair = 0 for i in range(steps + 1): if i < n - 1: maxPair = max(maxPair, scores[i] + scores[i + 1]) sum += scores[i] if i % 2 == steps % 2: t = (steps - i) // 2 if t <= left: ans = max(ans, sum + maxPair * t) print(ans) for case in range(int(input())): solve()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = map(int, input().split()) a = list(map(int, input().split())) s = [0] for x in a: s += (x + s[-1],) ans = 0 i = 0 ans = 0 while i < k: sum = s[i + 1] - s[0] mv = k - i hf = mv // 2 l = min(z, hf) sum += l * (a[i] + a[i + 1]) mv -= 2 * l if mv: sum += s[i + 1 + mv] - s[i + 1] ans = max(sum, ans) i += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys input = sys.stdin.buffer.readline def print(val): sys.stdout.write(str(val) + "\n") def prog(): for _ in range(int(input())): n, k, z = map(int, input().split()) a = list(map(int, input().split())) total = 0 psum = [0] for i in range(n): psum.append(psum[i] + a[i]) for i in range(k + 1): total += a[i] mx = total current = total leftover = 0 for i in range(k, 1, -1): current -= a[i] leftover += 1 to_left = min(z, leftover // 2) leftover2 = leftover - to_left * 2 added = 0 if leftover2 % 2 == 1: if to_left < z: added += (a[i - 1] + a[i - 2]) * to_left + max(a[i - 2], a[i]) else: added += ( (a[i - 1] + a[i - 2]) * to_left + psum[i + leftover2] - psum[i] ) mx = max(mx, current + added) else: added += (a[i - 1] + a[i - 2]) * to_left + psum[i + leftover2] - psum[i] mx = max(mx, current + added) print(mx) prog()
IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for ii in range(t): n, k, z = map(int, input().split()) a = list(map(int, input().split())) rightStop = [] leftStop = [0] s = sum(a[: k + 1]) rightStop.append(s) init = 1 while init <= z: tempMoves = k - 2 * init + 2 if k - 2 * init >= 0: leftStop.append( sum(a[:tempMoves]) + a[tempMoves - 2] * init + a[tempMoves - 1] * (init - 1) ) else: break init += 1 init = 1 while init <= z: if k - 2 * init >= 0: maxIndex = k - 2 * init best = 0 for i in range(maxIndex): best = max(best, a[i] + a[i + 1]) rightStop.append(sum(a[: maxIndex + 1]) + best * init) init += 1 else: break print(max(max(leftStop), max(rightStop)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
T = int(input()) def solve(): maxleft = min(k // 2, z) val = 0 for i in range(maxleft + 1): temp = sum(a[: k + 1 - 2 * i]) temp += i * max(apair[: k + 1 - 2 * i]) val = max(val, temp) return val for test in range(T): n, k, z = map(int, input().split()) a = [int(x) for x in input().split()] apair = [(a[i] + a[i + 1]) for i in range(n - 1)] print(solve())
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] for _ in range(II()): n, k, z = MI() aa = LI() r = max(0, k - 2 * z) s = sum(aa[: r + 1]) ans = -1 for i in range(min(n - 1, k)): if i + 1 <= r: cur = s + (aa[i] + aa[i + 1]) * z else: s += aa[i + 1] left = k - i - 1 cur = s + aa[i + 1] * (left // 2) + aa[i] * (left - left // 2) ans = max(ans, cur) print(ans)
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
def compute_score(a, k, z): ans = a[0] pair = a[0] + a[1] sum_ = a[0] for i in range(1, k + 1): pair = max(pair, a[i - 1] + a[i]) sum_ += a[i] lefts = min((k - i) // 2, z) rem = a[i - 1] if k - i - 2 * lefts > 0 and lefts < z else 0 ans = max(ans, lefts * pair + sum_ + rem) print(ans) t = int(input()) for _ in range(t): n, k, z = map(int, input().split()) a = list(map(int, input().split())) compute_score(a, k, z)
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = map(int, input().split()) a = list(map(int, input().split())) sc = [] sums = 0 for i in range(n): sums += a[i] sc.append(sums) b = [] for i in range(1, k + 1): cnt = k - i if cnt % 2 == 0: if z >= cnt // 2: ans = cnt // 2 * (a[i] + a[i - 1]) cnt = 0 ans += sc[i] else: ans = z * (a[i] + a[i - 1]) cnt -= 2 * z ans += sc[i + cnt] elif z >= cnt // 2 + 1: ans = cnt // 2 * (a[i] + a[i - 1]) if i != n - 1: ans += max(a[i - 1], a[i + 1]) else: ans += a[i - 1] cnt = 0 ans += sc[i] else: ans = z * (a[i] + a[i - 1]) cnt -= 2 * z ans += sc[i + cnt] b.append(ans) print(max(b))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = list(map(int, input().split())) arr = list(map(int, input().split())) pref = [] s = 0 for i in range(n): s += arr[i] pref.append(s) ans = [pref[k]] for i in range(1, k + 1): ansNow = pref[i] byRotating = 0 haveMoreSteps = k - i stopInd = i if (k - i) // 2 < z: byRotating = (arr[i - 1] + arr[i]) * ((k - i) // 2) haveMoreSteps -= (k - i) // 2 * 2 if k - i & 1: haveMoreSteps -= 1 byRotating += arr[i - 1] stopInd = i - 1 else: byRotating = (arr[i - 1] + arr[i]) * z haveMoreSteps -= z * 2 ansNow += byRotating ansNow += pref[i + haveMoreSteps] - pref[i] ans.append(ansNow) print(max(ans))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = map(int, input().split()) l = list(map(int, input().split())) rr = 0 tt = l[0] + l[1] if k >= 2 * z: pls = sum(l[2 : k - 2 * z + 1]) if z == 0: print(sum(l[: k + 1])) else: for i in range(1, k + 1): c = k - i if c >= 2 * z: if z % 2 == 0: rr = max(rr, z * (l[i] + l[i - 1]) + tt + pls) else: rr = max(rr, z * (l[i] + l[i - 1]) + tt + pls) else: rr = max(rr, c // 2 * (l[i] + l[i - 1]) + c % 2 * l[i - 1] + tt) if i != k: tt += l[i + 1] pls -= l[i + 1] print(max(rr, tt))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for testcase in range(t): n, k, z = map(int, input().split()) A = list(map(int, input().split())) sumTill = [] ss = 0 for a in A: sumTill.append(ss + a) ss = ss + a total = A[0] + A[1] options = [(1, 1, 0, total, False)] maxi = total for i in range(1, k + 1): turnsTill = i turnsLeft = k - turnsTill sum2 = sumTill[i] backTurns = z backed = False pos = i while backTurns > 0 and turnsLeft > 0: if backed: sum2 += A[i] backed = False pos = i else: sum2 += A[i - 1] backed = True backTurns = backTurns - 1 pos = i - 1 turnsLeft = turnsLeft - 1 sum2 += sumTill[pos + turnsLeft] - sumTill[pos] maxi = max(maxi, sum2) print(maxi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
from sys import stdin input = stdin.buffer.readline for _ in range(int(input())): n, k, z = map(int, input().split()) k += 1 (*a,) = map(int, input().split()) ans = sum(a[:k]) s = a[0] pref = [0] * (n + 1) for i in range(n): pref[i] = pref[i - 1] + a[i] for i in range(1, n): s += a[i] if i + 1 > k: break tmp = s + a[i - 1] * min(z, (k - i) // 2) + a[i] * min(z, (k - i - 1) // 2) if k - i - 1 - 2 * z > 0: x = k - i - 1 - 2 * z tmp += pref[i + x] - pref[i] ans = max(ans, tmp) print(ans)
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = map(int, input().split()) arr = list(map(int, input().split())) total = 0 sum = 0 r = k res = [] rem = k - z * 2 if rem <= 0: l = 0 else: l = rem + 1 for i in range(l): total += arr[i] for i in range(k): sum += arr[i] if r - z * 2 <= 0: r -= 1 if r % 2 == 0: res.append(arr[i + 1] + sum + r // 2 * (arr[i] + arr[i + 1])) else: a = (r - 1) // 2 res.append(arr[i + 1] + sum + a * (arr[i] + arr[i + 1]) + arr[i]) else: res.append(sum + z * (arr[i] + arr[i + 1]) + (total - sum)) r -= 1 print(max(res))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
def abc(l, i, n, k, m): if k == 0: return 0 if i == n - 1: if k: if m: return l[i] + abc(l, i - 1, n, k - 1, m - 1) return l[i] return 0 if i == 0: return l[0] + abc(l, i + 1, n, k - 1, m) if m == 0: return l[i] + abc(l, i + 1, n, k - 1, m) return l[i] + max(abc(l, i - 1, n, k - 1, m - 1), abc(l, i + 1, n, k - 1, m)) t = int(input()) for _ in range(t): n, k, m = map(int, input().split()) l = list(map(int, input().split())) v = [0] for i in l: v.append(v[-1] + i) ans = 0 for i in range(1, n): p = k if p >= i: c = v[i + 1] p -= i else: p = 0 c = v[p + 1] ans = max(ans, c) d = l[i] + l[i - 1] y = p for j in range(min(p // 2, m)): c += d y = y - 2 ans = max(ans, c + v[i + 1 + y] - v[i + 1]) d = m - min(p // 2, m) if y and d: c += l[i - 1] ans = max(ans, c) print(ans)
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER IF VAR IF VAR RETURN BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR RETURN NUMBER IF VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER RETURN BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for _ in range(t): n, k, z = list(map(int, input().split(" "))) a = list(map(int, input().split(" "))) a_max = list(a) a_res = list(a) for i in range(1, n): a_res[i] += a_res[i - 1] if n > 1: a_max[0] = a[0] + a[1] for i in range(1, n - 1): a_max[i] = max(a_max[i - 1], a[i + 1] + a[i]) res_max = 0 for j in range(z + 1): fin = k - 2 * j if fin < 0: continue res = a_res[fin] + j * a_max[fin] res_max = max(res, res_max) print(res_max)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
t = int(input()) for _ in range(t): n, k, z = map(int, input().split()) A = list(map(int, input().split())) C = [0] * n S = [0] * n S[0] = A[0] for i in range(1, n): C[i] = max(C[i - 1], A[i] + A[i - 1]) S[i] = S[i - 1] + A[i] ans = -(10**18) for i in range(z + 1): r = k - 2 * i if r < 0: continue temp = S[r] + C[r] * i ans = max(ans, temp) if r + 1 < n: temp = S[r + 1] + C[r + 1] * (i - 1) + A[r] ans = max(ans, temp) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
for _ in range(int(input())): n, k, z = map(int, input().split()) arr = list(map(int, input().split())) cons = [] for i in range(1, k + 1): cons.append(arr[i] + arr[i - 1]) out = [] while z > -1: if k - 2 * z + 1 > 0: m = max(cons[: k - 2 * z + 1]) out.append(sum(arr[: k - 2 * z + 1]) + z * m) z -= 1 print(max(out))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
from sys import stdin t = int(stdin.readline().strip()) for _ in range(t): n, k, z = list(map(int, stdin.readline().strip().split(" "))) A = list(map(int, stdin.readline().strip().split(" "))) max_score = sum(A[0 : k + 1]) for z_val in range(1, z + 1): if k + 1 - 2 * z_val < 1: continue subarray = A[0 : k + 1 - 2 * z_val] score = sum(subarray) maxPair = max([(A[i] + A[i + 1]) for i in range(k + 1 - 2 * z_val)]) score += maxPair * z_val max_score = max(score, max_score) print(max_score)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a_1, a_2, \dots, a_n$, consisting of $n$ positive integers. Initially you are standing at index $1$ and have a score equal to $a_1$. You can perform two kinds of moves: move right — go from your current index $x$ to $x+1$ and add $a_{x+1}$ to your score. This move can only be performed if $x<n$. move left — go from your current index $x$ to $x-1$ and add $a_{x-1}$ to your score. This move can only be performed if $x>1$. Also, you can't perform two or more moves to the left in a row. You want to perform exactly $k$ moves. Also, there should be no more than $z$ moves to the left among them. What is the maximum score you can achieve? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases. The first line of each testcase contains three integers $n, k$ and $z$ ($2 \le n \le 10^5$, $1 \le k \le n - 1$, $0 \le z \le min(5, k)$) — the number of elements in the array, the total number of moves you should perform and the maximum number of moves to the left you can perform. The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$) — the given array. The sum of $n$ over all testcases does not exceed $3 \cdot 10^5$. -----Output----- Print $t$ integers — for each testcase output the maximum score you can achieve if you make exactly $k$ moves in total, no more than $z$ of them are to the left and there are no two or more moves to the left in a row. -----Example----- Input 4 5 4 0 1 5 4 3 2 5 4 1 1 5 4 3 2 5 4 4 10 20 30 40 50 10 7 3 4 6 8 2 9 9 7 4 10 9 Output 15 19 150 56 -----Note----- In the first testcase you are not allowed to move left at all. So you make four moves to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$. In the second example you can move one time to the left. So we can follow these moves: right, right, left, right. The score will be $a_1 + a_2 + a_3 + a_2 + a_3$. In the third example you can move four times to the left but it's not optimal anyway, you can just move four times to the right and obtain the score $a_1 + a_2 + a_3 + a_4 + a_5$.
import sys input = sys.stdin.readline def main(): t = int(input()) for _ in range(t): N, K, Z = [int(x) for x in input().split()] A = [int(x) for x in input().split()] ruiseki = [A[0]] for i in range(1, N): ruiseki.append(ruiseki[-1] + A[i]) ans = ruiseki[K] for i in range(1, K + 1): for j in range(min(-(-(K - i) // 2), Z)): ans = max( ans, A[i] + ruiseki[K - (j + 1) * 2] + (j + 1) * A[i - 1] + j * A[i] ) print(ans) main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
import sys n = int(sys.stdin.readline()) s = list(map(int, sys.stdin.readline().split())) s1 = {} print = sys.stdout.write for i in range(n): if s[i] in s1: s1[s[i]].append(i) else: s1[s[i]] = [i] s2 = [i for i in s1 if len(s1[i]) == 1] ls2 = len(s2) if ls2 % 2 == 1 and ls2 == n: print("NO\n") else: ec = 0 oc = 0 v = -1 if ls2 % 2 == 0: print("YES\n") ec = 1 else: f = 0 for i in s1: if len(s1[i]) > 2: v = i f = 1 break if f == 0: print("NO\n") else: print("YES\n") oc = 1 if ec == 1: s = ["A"] * n mid = ls2 // 2 for i in s2[mid:]: s[s1[i][0]] = "B" print("".join(s) + "\n") elif oc == 1: s = ["A"] * n mid = ls2 // 2 for i in s2[mid:]: s[s1[i][0]] = "B" for i in s1[v][1:]: s[i] = "B" print("".join(s) + "\n")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER STRING FOR VAR VAR VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = [int(el) for el in input().split()] x = [] y = [] z = [] for i in range(n): if s[i] in x: y[x.index(s[i])] += 1 z[x.index(s[i])].append(i) else: x.append(s[i]) y.append(1) z.append([]) z[len(z) - 1].append(i) k = y.count(1) l = n - k - y.count(2) * 2 if l <= 0 and k >= 1 and k % 2 == 1: print("NO") raise SystemExit s1 = 0 s2 = 0 out = "A" * n for i in range(n): if y[x.index(s[i])] == 2: for j in z[x.index(s[i])]: out = out[:j] + "A" + out[j + 1 :] if y[x.index(s[i])] == 1: if s1 > s2: out = out[:i] + "B" + out[i + 1 :] s2 += 1 else: out = out[:i] + "A" + out[i + 1 :] s1 += 1 if y[x.index(s[i])] >= 3: continue y[x.index(s[i])] = 0 if y.count(0) == len(y): print("YES") print(out) raise SystemExit if s1 == s2: for i in range(n): k = x.index(s[i]) if y[k] != 0: for j in z[k]: out = out[:j] + "A" + out[j + 1 :] else: pos = 0 for i in range(n): k = x.index(s[i]) if y[k] != 0 and pos == 0: for j in z[k]: out = out[:j] + "A" + out[j + 1 :] j = z[k][0] out = out[:j] + "B" + out[j + 1 :] pos = 1 y[k] = 0 elif y[k] != 0 and pos == 1: for j in z[k]: out = out[:j] + "A" + out[j + 1 :] y[k] = 0 print("YES") print(out)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = list(map(int, input().split())) rec = [0] * 1000 one = 0 for i in range(n): rec[a[i]] += 1 for i in range(1000): if rec[i] == 1: one += 1 if one % 2 != 0 and max(rec) <= 2: print("NO") elif one % 2 != 0: print("YES") t = "" k = 0 flag = True for i in range(n): if rec[a[i]] == 1 and k < one // 2: t += "A" k += 1 elif rec[a[i]] == 1: t += "B" elif rec[a[i]] >= 3 and flag: t += "A" flag = False else: t += "B" print(t) else: print("YES") t = "" k = 0 for i in range(n): if rec[a[i]] == 1 and k < one // 2: t += "A" k += 1 elif rec[a[i]] == 1: t += "B" else: t += "A" print(t)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER VAR STRING IF VAR VAR VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) l = list(map(int, input().split())) c = ["c"] * n d = {} for i in l: if i in d: d[i] = d[i] + 1 else: d[i] = 1 t1 = 0 c1 = 0 tl = [] cl = [] for i in d: if d[i] == 1: t1 += 1 tl.append(i) if d[i] > 2: c1 += 1 cl.append(i) if t1 % 2 == 1 and c1 == 0: print("NO") elif t1 % 2 == 0: cnt = 0 s = set() for i in tl: x = l.index(i) if cnt < t1 // 2: c[x] = "A" else: c[x] = "B" cnt = cnt + 1 s.add(x) for i in range(len(c)): if i not in s: c[i] = "B" print("YES") print("".join(c)) else: cnt = 0 s = set() for i in tl: x = l.index(i) if cnt < t1 // 2: c[x] = "A" else: c[x] = "B" cnt = cnt + 1 s.add(x) e = cl[0] x = l.index(e) c[x] = "A" s.add(x) for i in range(len(c)): if i not in s: c[i] = "B" print("YES") print("".join(c))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) si = list(map(int, input().split())) nums = [0] * 101 for i in range(n): nums[si[i]] += 1 num1 = 0 numnot12 = 0 for i in range(101): num1 += int(nums[i] == 1) numnot12 += int(nums[i] > 2) if numnot12 == 0 and num1 % 2 == 1: print("NO") else: print("YES") num2 = num1 % 2 num1 //= 2 for i in range(n): if nums[si[i]] == 1: if num1 > 0: print("A", end="") num1 -= 1 else: print("B", end="") elif nums[si[i]] > 2: if num2 > 0: nums[si[i]] = 2 print("A", end="") num2 -= 1 else: print("A", end="") else: print("B", end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) numbers = list(map(int, input().split(" "))) odd = 0 count = [0] * 101 three = 0 assign = ["A"] * (n + 1) for number in numbers: count[number] += 1 if count[number] == 1: odd += 1 elif count[number] == 2: odd -= 1 elif count[number] == 3 and not three: three = number assignToB = False index = 1 if odd % 2 == 0: for number in numbers: if count[number] == 1: if assignToB: assign[index] = "B" assignToB = not assignToB index += 1 elif three: assign[numbers.index(three) + 1] = "B" for number in numbers: if count[number] == 1: if assignToB: assign[index] = "B" assignToB = not assignToB index += 1 if odd & 1 and not three: print("NO") else: print("YES") print("".join(assign[1:]))
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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR NUMBER IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING FOR VAR VAR IF VAR VAR NUMBER IF VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = [int(i) for i in input().split()] cnt = cnt3 = 0 B = False kek = True for i in a: if a.count(i) == 1: cnt += 1 if a.count(i) >= 3: cnt3 += 1 if cnt % 2 == 0: print("YES") for i in a: if a.count(i) == 1: if B: print("B", end="") else: print("A", end="") B = not B else: print("A", end="") elif cnt3 > 0: print("YES") for i in a: if a.count(i) == 1: if B: print("B", end="") else: print("A", end="") B = not B elif (a.count(i) >= 3) & kek: print("B", end="") kek = False continue else: print("A", end="") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) A = list(map(int, input().split())) D = dict((A[i], A.count(A[i])) for i in range(n)) S = [""] * n q = True if list(D.values()).count(1) % 2: q = False else: q = True p = True for k in D: if D[k] == 1: if p: S[A.index(k)] = "A" else: S[A.index(k)] = "B" p = not p if D[k] == 2: j = A.index(k) S[j] = "A" j += 1 j = j + A[j:].index(k) S[j] = "B" if not q: for k in D: if D[k] > 2: j = A.index(k) S[j] = "B" for i in range(j + 1, n): if A[i] == k: S[i] = "A" q = q = True break if not q: print("NO") exit() for i in range(n): if S[i] == "": S[i] = "A" print("YES") print("".join(S))
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 FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR STRING IF VAR FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
import sys def main(): _ = sys.stdin.readline() s = list(map(int, sys.stdin.readline().strip().split(" "))) freq = [0] * 101 for i in s: freq[i] += 1 ans = [0] * len(s) currMulti = 0 for i, v in enumerate(s): if freq[v] == 1: ans[i] = currMulti currMulti ^= 1 if currMulti == 1: ok = False for i, v in enumerate(s): if freq[v] > 2: ans[i] = currMulti ok = True break if ok is not True: print("NO") return print("YES") print("".join([("A" if x == 0 else "B") for x in ans])) main()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER STRING STRING VAR VAR EXPR FUNC_CALL VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
cnt = [(0) for i in range(101)] n = int(input()) s = input().split() l = [int(s[i]) for i in range(n)] for i in l: cnt[i] += 1 small = 0 large = 0 for i in range(1, 101): if cnt[i] == 1: small += 1 elif cnt[i] > 2: large += 1 largenum = i if small % 2 == 1 and large == 0: print("NO") elif small % 2 == 1: print("YES") counter = 0 flag = True for i in l: if cnt[i] == 1: print("AB"[counter % 2], end="") counter += 1 elif i == largenum and flag: print("B", end="") flag = False else: print("A", end="") print("") else: print("YES") counter = 0 for i in l: if cnt[i] == 1: print("AB"[counter % 2], end="") counter += 1 else: print("A", end="") print("")
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = list(map(int, input().split())) z = ["A"] * len(a) d = {} for i in a: if i in d.keys(): d[i] += 1 else: d[i] = 1 ka, kb = 0, 0 for i, x in enumerate(a): if d[x] == 1: if ka > kb: z[i] = "B" kb += 1 else: z[i] = "A" ka += 1 if ka > kb: for i, x in enumerate(a): if d[x] > 2: z[i] = "B" kb += 1 break if ka == kb: print("YES") print("".join(z)) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = [int(x) for x in input().split()] m = {} for aa in a: if aa in m: m[aa] += 1 else: m[aa] = 1 count = 0 trick = False for k in m: if m[k] == 1: count += 1 elif m[k] > 2: trick = True if count % 2 == 1: if trick: count += 1 else: print("NO") exit() else: trick = False print("YES") count = count / 2 r = [] for aa in a: if m[aa] == 1: if count > 0: r.append("A") count -= 1 else: r.append("B") elif m[aa] == 2: r.append("A") elif trick: r.append("B") trick = False else: r.append("A") print("".join(r))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) line = input() list = [(int(s) - 1) for s in line.split()] count = [(0) for i in range(0, 100)] for x in list: count[x] = count[x] + 1 one = [] two = [] greater = [] first_greater = -1 for i in range(0, 100): c = count[i] if c == 1: one.append(i) elif c == 2: two.append(i) elif c > 2: greater.append(i) if first_greater == -1: first_greater = i if len(one) % 2 == 0: print("YES") num = len(one) / 2 c = 0 for i in list: if count[i] == 1: if c < num: print("A", end="") c = c + 1 else: print("B", end="") else: print("A", end="") elif len(greater) != 0: print("YES") num = len(one) // 2 c = 0 for i in list: if count[i] == 1: if c < num: print("A", end="") c = c + 1 else: print("B", end="") elif count[i] > 2: if i == first_greater: print("A", end="") first_greater = -1 else: print("B", end="") else: print("B", end="") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
a = int(input()) ans = [(0) for i in range(101)] z = list(map(int, input().split())) for i in range(len(z)): ans[z[i]] += 1 if ans.count(1) % 2 == 1: s = "" if len(z) - ans.count(1) - 2 * ans.count(2) == 0: print("NO") else: print("YES") flag = 0 tra = 0 for i in range(len(ans)): if ans[i] >= 3: break tra = i count = ans[tra] c1 = 0 for i in range(len(z)): if ans[z[i]] == 1: if flag == 0: s += "A" flag = 1 else: s += "B" flag = 0 elif z[i] == tra: if c1 == count - 1: s += "B" else: s += "A" c1 += 1 else: s += "A" print(s) else: print("YES") flag = 0 s = "" for i in range(len(z)): if ans[z[i]] > 1: s += "A" elif flag == 0: s += "A" flag = 1 else: s += "B" flag = 0 print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR STRING IF BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR STRING VAR STRING VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR STRING IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
N = int(input()) arr = [int(x) for x in input().split()] cnt = [(0) for i in range(102)] for x in arr: cnt[x] += 1 dp = [[[(-1) for i in range(102)] for j in range(102)] for k in range(102)] jawab = [(-1) for i in range(102)] def kucing(pos, nA, nB): global dp if dp[pos][nA][nB] == -1: if pos > 100: return nA == nB if cnt[pos] == 0: dp[pos][nA][nB] = kucing(pos + 1, nA, nB) return dp[pos][nA][nB] if cnt[pos] == 1 or cnt[pos] > 2: if cnt[pos] > 2 and kucing(pos + 1, nA, nB): jawab[pos] = 0 dp[pos][nA][nB] = True return True elif kucing(pos + 1, nA + 1, nB): jawab[pos] = 1 dp[pos][nA][nB] = True return True elif kucing(pos + 1, nA, nB + 1): jawab[pos] = 2 dp[pos][nA][nB] = True return True else: dp[pos][nA][nB] = False return False elif kucing(pos + 1, nA, nB): jawab[pos] = 0 dp[pos][nA][nB] = True return True elif kucing(pos + 1, nA + 1, nB + 1): jawab[pos] = 3 dp[pos][nA][nB] = True return True else: dp[pos][nA][nB] = False return False else: return dp[pos][nA][nB] if kucing(0, 0, 0): print("YES") for i in range(N): if jawab[arr[i]] == 0: print("A", end="") elif jawab[arr[i]] == 4: print("B", end="") elif jawab[arr[i]] == 1: print("A", end="") jawab[arr[i]] = 4 elif jawab[arr[i]] == 2: print("B", end="") jawab[arr[i]] = 0 elif jawab[arr[i]] == 3: print("B", end="") jawab[arr[i]] = 1 else: print("NO")
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 NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN VAR VAR VAR VAR IF FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) unik = [] dui = [] tinbeshi = [] for i in range(n): if s.count(s[i]) == 1: unik.append(s[i]) elif s.count(s[i]) == 2: dui.append(s[i]) else: tinbeshi.append(s[i]) dui = set(dui) tin = list(set(tinbeshi)) if len(unik) % 2 == 1 and len(tin) == 0: print("NO") elif len(unik) == 0: print("YES") for i in range(n): print("A", sep="", end="") else: print("YES") if len(unik) % 2 == 0: flg = True cnt = 0 for i in range(n): if s[i] in unik and flg: print("A", sep="", end="") cnt += 1 if cnt == len(unik) / 2: flg = False else: print("B", sep="", end="") else: index = [] for i in range(int((len(unik) + 1) / 2 - 1)): index.append(s.index(unik[i])) index.append(s.index(tin[0])) for i in range(n): if i in index: print("A", sep="", end="") else: print("B", sep="", end="")
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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING STRING EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING STRING VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING STRING STRING EXPR FUNC_CALL VAR STRING STRING STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
num_numbers = int(input()) numbers = list(input().split()) appear_once = set() appear_twice = set() appear_multiple = set() for number in numbers: if number not in appear_multiple: if number in appear_twice: appear_multiple.add(number) appear_twice.remove(number) elif number in appear_once: appear_twice.add(number) appear_once.remove(number) else: appear_once.add(number) if len(appear_once) % 2 == 0 or len(appear_multiple) > 0: print("YES") nice_to_a = True solution = list() split_multiple = len(appear_once) % 2 == 1 for number in numbers: if number in appear_once: if nice_to_a: solution.append("A") else: solution.append("B") nice_to_a = not nice_to_a elif split_multiple and number in appear_multiple: solution.append("B") split_multiple = False else: solution.append("A") print("".join(solution)) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) c = [0] * 101 a = [int(i) for i in input().split()] for i in range(n): c[a[i]] += 1 if n == c.count(1) + c.count(2) * 2: if c.count(1) % 2 == 1: print("NO") else: print("YES") k = c.count(1) // 2 for i in range(n): if c[a[i]] == 1: if k: k -= 1 print("A", end="") else: print("B", end="") else: print("A", end="") else: print("YES") if c.count(1) % 2 == 0: k = c.count(1) // 2 for i in range(n): if c[a[i]] == 1: if k: k -= 1 print("A", end="") else: print("B", end="") else: print("A", end="") else: d = 0 k = c.count(1) // 2 for i in range(n): if c[a[i]] == 1: if k: k -= 1 print("A", end="") else: print("B", end="") elif not d and c[a[i]] > 2: print("A", end="") d = 1 else: print("B", end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
s = input() s = input() s1 = s.split() l = [int(i) for i in s1] d = {} for i in l: if i not in d: d[i] = 1 else: d[i] = d[i] + 1 cnt = 0 for i in d: if d[i] == 1: cnt = cnt + 1 if cnt % 2 == 1: flag = 0 for i in d: if d[i] >= 3: flag = 1 break if flag == 0: print("NO") else: s = "" state = 0 flag = 0 for i in l: if d[i] >= 3 and flag == 0: s = s + "B" flag = 1 elif d[i] > 1: s = s + "A" else: if state == 0: s = s + "A" else: s = s + "B" state = 1 - state print("YES") print(s) else: print("YES") s = "" state = 0 for i in l: if d[i] != 1: s = s + "A" else: if state == 1: s = s + "A" else: s = s + "B" state = 1 - state print(s)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) d = {} mt = False mti = -1 for i in range(len(s)): if s[i] not in d: d[s[i]] = 1 else: d[s[i]] += 1 if d[s[i]] > 2: mt = True mti = i good = [] for i in d.keys(): if d[i] == 1: good.append(i) if len(good) % 2 == 0: print("YES") good1 = good[: len(good) // 2] for i in s: if i in good1: print("A", end="") else: print("B", end="") elif mt: print("YES") good1 = good[: len(good) // 2] u = False for i in s: if i in good1 or not u and i == s[mti]: print("A", end="") if i == s[mti]: u = True else: print("B", end="") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) l = list(map(int, input().split())) d = {} for i in l: try: d[i] += 1 except: d[i] = 1 x = list(d.values()) if x.count(1) % 2 == 0: print("YES") c = 0 ans = [""] * n for i in range(n): if d[l[i]] == 1: if c: ans[i] = "B" else: ans[i] = "A" c = c ^ 1 else: ans[i] = "A" print("".join(ans)) elif x.count(1) + x.count(2) < len(x): print("YES") flag = 1 c = 0 ans = [""] * n for i in range(n): if d[l[i]] == 1: if c: ans[i] = "B" else: ans[i] = "A" c = c ^ 1 elif d[l[i]] == 2: ans[i] = "A" elif flag: ans[i] = "B" flag = 0 else: ans[i] = "A" print("".join(ans)) else: print("NO")
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 VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = [int(i) for i in input().split()] cnt = 0 cnt1 = 0 q = list() for i in a: if i not in q: q.append(i) if a.count(i) == 1: cnt += 1 elif a.count(i) > 2: cnt1 += 1 if cnt % 2 == 1 and cnt1 == 0: print("NO") else: nums = list() g = list() ans = "" f = True q = False for i in a: if a.count(i) == 1: if f: ans += "A" f = False else: ans += "B" f = True elif a.count(i) == 2: ans += "A" elif cnt % 2 == 1: if not q: ans += "B" q = True else: ans += "A" else: ans += "A" print("YES") print(ans)
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 FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR STRING IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) cnt = [0] * 105 for i in range(n): cnt[s[i]] += 1 cnt_nice = 0 for i in range(105): if cnt[i] == 1: cnt_nice += 1 if cnt_nice % 2 == 0: print("YES") tmp = cnt_nice / 2 res = "" for i in range(n): if cnt[s[i]] != 1 or tmp > 0 and cnt[s[i]] == 1: res += "A" if cnt[s[i]] == 1: tmp -= 1 else: res += "B" print(res) else: flag = False key_num = 0 for i in range(n): if cnt[s[i]] != 1 and cnt[s[i]] > 2: flag = True key_num = s[i] break if flag: print("YES") tmp = cnt_nice / 2 res = "" flag_key = False for i in range(n): if flag_key and s[i] == key_num: res += "A" elif flag_key == False and s[i] == key_num: res += "B" flag_key = True elif cnt[s[i]] != 1 or tmp > 0 and cnt[s[i]] == 1: res += "A" if cnt[s[i]] == 1: tmp -= 1 else: res += "B" print(res) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR STRING IF VAR VAR VAR NUMBER VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR STRING IF VAR NUMBER VAR VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR STRING IF VAR VAR VAR NUMBER VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = [int(s) for s in input().split()] goodElems = 0 Scope = [0] * 101 Bscope = [False] * 101 for i in range(n): Scope[a[i]] += 1 for elem in Scope: if elem == 1: goodElems += 1 if goodElems == 0: print("YES") for i in range(n): print("A", end="") elif goodElems % 2 == 0: print("YES") goodElems = goodElems // 2 for i in range(n): if Scope[a[i]] == 1 and goodElems > 0: print("B", end="") goodElems -= 1 else: print("A", end="") else: s = ["A"] * n goodElemsAll = (goodElems + 1) // 2 goodElemsA = 0 goodElemsB = 0 for i in range(len(a)): if Scope[a[i]] == 1 and goodElemsA != goodElemsAll: Scope[a[i]] -= 1 s[i] = "A" goodElemsA += 1 elif Scope[a[i]] == 1 and goodElemsB != goodElemsAll: Scope[a[i]] -= 1 s[i] = "B" goodElemsB += 1 for i in range(n): if Scope[a[i]] > 2: goodElemsB += 1 s[i] = "B" break if goodElemsA == goodElemsB: print("YES") print("".join(s)) else: print("NO")
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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) l = list(map(int, input().split())) freq = {} for i in l: if i in freq: freq[i] += 1 else: freq[i] = 1 cnt1, cnt3 = 0, 0 for i in freq: if freq[i] == 1: cnt1 += 1 if freq[i] >= 3: cnt3 += 1 if cnt1 & 1 and cnt3 == 0: print("NO") else: print("YES") flag = cnt1 & 1 cnt = 1 for i in l: if freq[i] == 1: if cnt: print("A", end="") else: print("B", end="") cnt = not cnt elif freq[i] == 2: print("A", end="") else: if flag: print("B", end="") else: print("A", end="") flag = 0
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 IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = [int(_) for _ in input().split()] cnt = {} for x in set(a): cnt[x] = len([y for y in a if y == x]) one = [] more = [] for x, c in cnt.items(): if c == 1: one.append(x) elif c >= 3: more.append(x) oneset = set(one) last = "B" first = True ans = [] if more or len(one) % 2 == 0: print("YES") for x in a: if x in oneset: last = "A" if last == "B" else "B" ans.append(last) elif more and x == more[0]: if first: if len(one) % 2 == 0: ans.append("A") else: ans.append("B") first = False else: ans.append("A") else: ans.append("A") print("".join(ans)) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR VAR STRING STRING STRING EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) l = list(map(int, input().split())) d = {} for x in l: d[x] = d.get(x, 0) + 1 k = 0 k1 = 0 for x in d: if d[x] == 1: k += 1 elif d[x] > 2: k1 += 1 if k % 2 != 0 and k1 == 0: print("NO") exit() print("YES") s = "" p = False if k % 2 != 0: p = True for x in l: if d[x] == 1: if k % 2 == 0: s += "A" else: s += "B" k -= 1 elif p and d[x] > 2: p = False s += "A" else: s += "B" print(s)
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 NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = [int(i) for i in input().split()] da = {} o = list("Z" * n) for i in a: if i in da: da[i] += 1 else: da[i] = 1 sc = 0 dc = 0 mc = 0 scl = [] dcl = [] mcl = [] for i in da: if da[i] == 1: sc += 1 scl.append(i) elif da[i] == 2: dc += 1 dcl.append(i) else: mc += 1 mcl.append(i) for i in dcl: x = 2 for j in range(n): if a[j] == i: o[j] = "A" x -= 1 if x == 0: break pc = 0 for i in scl: j = a.index(i) if pc % 2 == 0: o[j] = "A" else: o[j] = "B" pc += 1 f = 1 if sc == 0: for i in range(n): o[i] = "A" elif sc % 2 == 0: for i in mcl: x = da[i] for j in range(n): if a[j] == i: o[j] = "A" x -= 1 if x == 0: break elif sc % 2 == 1: if len(mcl) == 0: f = 0 else: pc = 0 for i in mcl: x = da[i] for j in range(n): if a[j] == i: if pc == 0: o[j] = "B" pc = 1 else: o[j] = "A" x -= 1 if x == 0: break if f == 0: print("NO") else: print("YES") print("".join(o))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = [int(x) for x in input().split()] d = {} for x in a: if x in d: d[x] += 1 else: d[x] = 1 kol = 0 kol1 = 0 for key in d: if d[key] == 1: kol += 1 if d[key] > 2: kol1 += 1 if kol % 2 == 1 and kol1 == 0: print("NO") exit(0) print("YES") if kol % 2 == 0: ind = 0 ind1 = 0 for i in range(n): if d[a[i]] == 1: if ind == ind1: print("A", end="") ind += 1 else: print("B", end="") ind1 += 1 else: print("A", end="") else: ind = 0 ind1 = 0 f = True res = -1 pic = "" for i in range(n): if d[a[i]] == 1: if ind == ind1: print("A", end="") ind += 1 else: print("B", end="") ind1 += 1 elif d[a[i]] > 2 and f: f = False res = a[i] if ind == ind1: print("A", end="") ind += 1 pic = "B" else: print("B", end="") ind1 += 1 pic = "A" elif a[i] == res: print(pic, end="") else: print("A", end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER IF VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING STRING VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR STRING STRING VAR NUMBER ASSIGN VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
def ip(): return int(input()) def ipp(): return map(int, input().split()) def sar(): return list(ipp()) def pars(a): print("".join(list(map(str, a)))) print("\r") def parl(a): print("\r".join(list(map(str, a)))) print("\r") T = 1 for _ in range(T): n = ip() d = {} cn = {} a = sar() for i in range(n): d[a[i]] = i if a[i] in cn: cn[a[i]] += 1 else: cn[a[i]] = 1 nice = 0 for kk in cn: if cn[kk] == 1: nice += 1 ans = ["-"] * n na = 0 nb = 0 p = 0 for kk in cn: if p % 2 == 0: if cn[kk] == 1: ans[d[kk]] = "A" p += 1 na += 1 elif cn[kk] == 1: ans[d[kk]] = "B" p += 1 nb += 1 if cn[kk] == 2: ans[d[kk]] = "A" inn = a.index(kk) ans[inn] = "B" na += 1 nb += 1 for kk in cn: if cn[kk] > 2: if na > nb: ans[d[kk]] = "B" nb += 1 for i in range(0, d[kk]): if a[i] == kk: ans[i] = "A" elif na < nb: ans[d[kk]] = "A" na += 1 for i in range(0, d[kk]): if a[i] == kk: ans[i] = "B" for i in range(n): if ans[i] == "-": ans[i] = "A" if na == nb: print("YES") pars(ans) else: print("NO")
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING IF VAR VAR ASSIGN VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) S = list(map(int, input().split())) D = set(S) nice = 0 dp = [(0) for i in range(102)] for i in D: if S.count(i) == 1: nice += 1 dp[i] = S.count(i) if nice % 2 == 0: d = 0 s = "" for i in S: if dp[i] == 1 and d < nice // 2: s = s + "A" d += 1 elif dp[i] == 1 and d >= nice // 2: s = s + "B" else: s = s + "A" print("YES") print(s) elif nice % 2 != 0 and len(S) > nice: d = 0 flag = 0 s = "" for i in S: if dp[i] == 1 and d < nice // 2: d += 1 s = s + "A" elif dp[i] == 1 and d >= nice // 2: d += 1 s = s + "B" elif dp[i] > 2 and flag == 0: s = s + "A" flag = 1 else: s = s + "B" if flag == 0: print("NO") else: print("YES") print(s) elif nice % 2 != 0 and len(S) == nice: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
def rmap(): return map(int, input().split()) def rlist(): return list(map(int, input().split())) def rdi(): return int(input()) n = rdi() line = rlist() cnt = [0] * 101 once = 0 triple_ind = 0 triple = 0 for elem in line: cnt[elem] += 1 if cnt[elem] == 1: once += 1 elif cnt[elem] == 2: once -= 1 elif cnt[elem] == 3: triple = 1 if once % 2 == 0: print("YES") k = 0 gg = ["A", "B"] for elem in line: if cnt[elem] == 1: print(gg[k], end="") k = (k + 1) % 2 else: print("A", end="") elif triple == 1: print("YES") k = 0 gg = ["A", "B"] d = "A" for elem in line: if cnt[elem] == 1: print(gg[k], end="") k = (k + 1) % 2 elif triple == 1 and cnt[elem] >= 3: print(gg[k], end="") k = (k + 1) % 2 triple = 0 d = gg[k] elif cnt[elem] >= 3: print(d, end="") else: print("A", end="") else: print("NO")
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) l = list(map(int, input().split())) d = {} for i in l: try: d[i] += 1 except KeyError: d[i] = 1 nice = 0 gt2elem = -1 for i in d.keys(): if d[i] == 1: nice += 1 elif d[i] > 2: gt2elem = i if nice % 2 == 0 or gt2elem != -1: x = 0 ans = [] for i in l: if d[i] == 1: ans.append("AB"[x]) x = 1 - x elif nice % 2 == 1 and i == gt2elem: ans.append("B") gt2elem = -1 else: ans.append("A") print("YES") print("".join(ans)) else: print("NO")
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 VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
r = input n = int(r()) a = [int(x) for x in r().split()] cnt = [0] * (100 + 1) A = [] B = [] res = "" for i in a: cnt[i] += 1 for i, j in enumerate(a): if cnt[j] == 1: A.append(i) if cnt[j] > 2: B.append(i) pr = [0] * (n + 1) if len(A) % 2 == 0: len2 = len(A) // 2 res = "YES\n" for i in A[:len2]: pr[i] = 1 for i in A[len2:]: pr[i] = 2 for i in range(n): if pr[i] == 1: res += "A" else: res += "B" else: res = "YES\n" dupx = -1 len2 = len(A) // 2 + 1 for i, j in enumerate(a): if cnt[j] > 2: dupx = i break pr = [0] * (n + 1) if dupx == -1: res = "NO\n" else: pr[dupx] = 1 for i in A[:len2]: pr[i] = 2 for i in A[len2:]: pr[i] = 1 for i in range(n): if pr[i] == 1: res += "B" else: res += "A" print(res)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR STRING VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = list(map(int, input().split())) count = [(0) for _ in range(101)] multisetA = [(0) for _ in range(101)] multiset = [[], []] ans = ["YES", "NO"] one = [] two = [] more = [] idex = 0 for v in a: count[v] += 1 for i in range(1, 101): if count[i] == 1: one.append(i) elif count[i] == 2: two.append(i) elif count[i] > 2: more.append(i) l = len(one) + len(more) lenOne = len(one) if lenOne == 0: print(ans[0]) for i in range(n): print("A", end="") elif len(more) > 0 or lenOne % 2 == 0: if l % 2 == 1: more.pop(-1) l -= 1 amount = l // 2 if amount > lenOne: for num in one: multisetA[num] = 1 need = amount - lenOne for i in range(need): multisetA[more.pop(0)] = 1 for v in more: need = count[v] - 1 multisetA[v] = need else: for v in one[:amount]: multisetA[v] = 1 for v in more: need = count[v] - 1 multisetA[v] = need for v in two: multisetA[v] = 1 print(ans[0]) for v in a: if multisetA[v]: multisetA[v] -= 1 print("A", end="") else: print("B", end="") else: print(ans[1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST LIST LIST ASSIGN VAR LIST STRING STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR NUMBER
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) b = list(map(int, input().split())) d = dict() for j in range(n): if b[j] in d.keys(): d[b[j]] += 1 else: d[b[j]] = 1 p = 0 q = -1 for j in range(n): if d[b[j]] == 1: p += 1 elif d[b[j]] > 2: q = j r = 0 c = ["A"] * n if p % 2 == 0: for j in range(n): if d[b[j]] == 1: if r % 2 == 0: c[j] = "A" else: c[j] = "B" r += 1 else: c[j] = "A" print("YES") print("".join(c)) elif p % 2 != 0: if q == -1: print("NO") else: for j in range(n): if d[b[j]] == 1: if r % 2 == 0: c[j] = "A" else: c[j] = "B" r += 1 else: c[j] = "A" c[q] = "B" print("YES") print("".join(c))
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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = [int(x) for x in input().split()] res = ["A"] * n cnt = [0] * 101 for i in a: cnt[i] += 1 good_num = cnt.count(1) bad_above_2 = False for i in range(101): if cnt[i] > 2: bad_above_2 = True break if good_num % 2 == 0 or bad_above_2 > 0: print("YES") to_b = False for i in range(n): if cnt[a[i]] == 1: if to_b: res[i] = "B" to_b = not to_b if good_num % 2 != 0: for i in range(n): if cnt[a[i]] > 2: res[i] = "B" break print("".join(res)) else: print("NO")
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 STRING VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
def vasya_and_multisets(v): m = dict() for e in v: m[e] = m.get(e, 0) + 1 ones = 0 has_gt2 = False for e in m.values(): if e == 1: ones += 1 if e > 2: has_gt2 = True odd_ones = ones % 2 == 1 if odd_ones and not has_gt2: print("NO") else: print("YES") A = True ans = "" for e in v: if m[e] == 2: ans += "A" elif m[e] == 1: if A: ans += "A" else: ans += "B" A = not A elif odd_ones: ans += "B" odd_ones = False else: ans += "A" print(ans) n = int(input()) v = list(map(int, input().split())) vasya_and_multisets(v)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR NUMBER VAR STRING IF VAR VAR NUMBER IF VAR VAR STRING VAR STRING ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR STRING EXPR 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
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = [int(x) for x in input().split()] INDEX = {} for k in set(a): INDEX[k] = [] for i in range(n): INDEX[a[i]].append(i) add = 0 IS = True pAns = [None] * n one = 0 ONE1 = {(True): [], (False): []} Over2 = {(True): [], (False): []} for j in INDEX.values(): t = len(j) if t > 2: add += 1 Over2[IS].append(j) elif t == 1: add += 1 one += 1 ONE1[IS].append(j) pAns[j[0]] = IS IS = not IS if t != 2 else IS for l in range(1, t): pAns[j[l]] = IS if add % 2 == 0: STRING = "" for x in pAns: if x: STRING += "A" else: STRING += "B" print("YES") print(STRING) elif one == add: print("NO") elif Over2[True] != []: pAns[Over2[True][0][0]] = False STRING = "" for x in pAns: if x: STRING += "A" else: STRING += "B" print("YES") print(STRING) elif Over2[False] != [] and ONE1[True]: pAns[Over2[False][0][0]] = True pAns[ONE1[True][0][0]] = False STRING = "" for x in pAns: if x: STRING += "A" else: STRING += "B" print("YES") print(STRING) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER LIST LIST ASSIGN VAR DICT NUMBER NUMBER LIST LIST FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER LIST ASSIGN VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER LIST VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) arr = list(map(int, input().split())) count = [0] * 101 unique = 0 multiple = 0 answer = "" for i in range(n): count[arr[i]] += 1 for i in range(1, len(count)): if count[i] == 1: unique += 1 elif count[i] > 2: multiple += 1 if unique % 2 == 0: multi = 0 for j in range(n): if count[arr[j]] == 1: if multi == 0: answer += "A" multi = 1 elif multi == 1: answer += "B" multi = 0 elif count[arr[j]] > 1: answer += "A" elif multiple == 0: answer = "NO" else: put = False multi = 0 for j in range(n): if count[arr[j]] == 1: if multi == 0: answer += "A" multi = 1 elif multi == 1: answer += "B" multi = 0 elif count[arr[j]] == 2: answer += "A" elif count[arr[j]] > 2: if not put: answer += "B" put = True else: answer += "A" if answer == "NO": print(answer) else: print("YES") print(answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR STRING IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR STRING IF VAR VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
def is_unique(a): global multi return True if multi.count(a) == 1 else False def is_semiunique(a): global multi return True if multi.count(a) > 2 else False n = int(input()) multi = list(map(int, input().split())) uniques = [] semi_uniques = [] for i in range(n): if is_unique(multi[i]): uniques.append(i) elif is_semiunique(multi[i]): semi_uniques.append(i) multi_ = ["B"] * len(multi) x = len(uniques) if x % 2 == 0: for i in uniques[: x // 2]: multi_[i] = "A" print("YES") print("".join(multi_)) elif not semi_uniques: print("NO") else: for i in uniques[: x // 2]: multi_[i] = "A" multi_[semi_uniques[0]] = "A" print("YES") print("".join(multi_))
FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER NUMBER 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 LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
from sys import exit, stdin, stdout def sin(): return stdin.readline().rstrip() def listInput(): return list(map(int, sin().split())) def printBS(li): if not li: return for i in range(len(li) - 1): stdout.write("%d " % li[i]) stdout.write("%d\n" % li[-1]) n = int(sin()) li = listInput() dic = {} for i in li: if i not in dic: dic[i] = 1 else: dic[i] += 1 nice = [i for i in dic if dic[i] == 1] if len(nice) % 2 == 1: alt = -1 for i in dic: if dic[i] > 2: alt = i break if alt == -1: print("NO") else: a, b = nice[: len(nice) // 2 + 1], nice[len(nice) // 2 + 1 :] a = set(a) b = set(b) alt_done = False ans = "" for i in li: if i in a: ans += "A" elif i in b: ans += "B" elif i == alt and not alt_done: ans += "B" alt_done = True else: ans += "A" print("YES") print(ans) else: a, b = nice[: len(nice) // 2], nice[len(nice) // 2 :] a = set(a) b = set(b) ans = "" for i in li: if i in a: ans += "A" else: ans += "B" print("YES") print(ans)
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR STRING IF VAR VAR VAR STRING IF VAR VAR VAR VAR STRING ASSIGN VAR NUMBER VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≤ n ≤ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≤ s_i ≤ 100) — the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
from sys import stdin, stdout n = int(stdin.readline()) vl = list(map(int, stdin.readline().split())) sze = 110 a, b = [], [] used = [[] for i in range(sze)] cnta, cntb = 0, 0 for i in range(n): used[vl[i]].append(i) used.sort(key=lambda x: len(x)) for i in range(sze): if len(used[i]) == 1: if cnta < cntb: a.append(used[i][0]) cnta += 1 else: b.append(used[i][0]) cntb += 1 elif len(used[i]) == 2: a.append(used[i][0]) b.append(used[i][1]) cnta += 1 cntb += 1 elif len(used[i]) > 2: if cnta == cntb: for j in range(len(used[i])): a.append(used[i][j]) elif cnta < cntb: cnta += 1 a.append(used[i][0]) for j in range(1, len(used[i])): b.append(used[i][j]) else: cntb += 1 b.append(used[i][0]) for j in range(1, len(used[i])): a.append(used[i][j]) if cnta == cntb: stdout.write("YES\n") ans = ["" for i in range(n)] for v in a: ans[v] = "A" for v in b: ans[v] = "B" stdout.write("".join(ans)) else: stdout.write("NO\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST LIST ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR STRING FOR VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING