description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def winner(nums, n): nums = sorted(nums) ans = [] i = 0 j = n // 2 count = 0 while j < n: ans.append(nums[j]) if i < n // 2: ans.append(nums[i]) if j != n - 1 and nums[i] != nums[j]: count += 1 j += 1 i += 1 return ans, ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CAL...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys input = sys.stdin.readline n = int(input()) A = sorted(map(int, input().split())) ans = [0] * n j = n - 1 for i in range(0, n, 2): ans[i] = A[j] j -= 1 rem = [] cnt = 0 pre = -1 for i in range(1, n - 1, 2): if j < 0: break while j >= 0 and A[j] >= ans[i + 1]: rem.append(A[j])...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) if n <= 2: print(0) print(" ".join(map(str, a))) else: a.sort() b = [0] * n j = 0 for i in range(1, n, 2): b[i] = a[j] j += 1 for i in range(0, n, 2): b[i] = a[j] j += 1 c = 0 for i in range(1, n - 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIG...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
t = 1 for _ in range(t): n = int(input()) arr = [int(x) for x in input().split()] arr = sorted(arr) temp = [(0) for x in range(n)] c = 0 for i in range(1, n, 2): temp[i] = arr[c] c += 1 for i in range(0, n, 2): temp[i] = arr[c] c += 1 ans = 0 val = n ...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) ls = list(map(int, input().split())) ls.sort() ReturnLs = [] i = 0 for j in range(n // 2, n): ReturnLs.append(ls[j]) if i != n // 2: ReturnLs.append(ls[i]) i += 1 count = 0 for i in range(1, n - 1, 2): if ReturnLs[i] < ReturnLs[i + 1] and ReturnLs[i - 1] > ReturnLs[i]: c...
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 ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR F...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) n, l = inp(), inlt() res = [] l.sort() for i in range(n // 2): if i + n // 2 < n: res.append(l[i + n...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR L...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys def inp(): return sys.stdin.readline().rstrip("\n").encode("utf8") def mpint(): return map(int, sys.stdin.readline().split(" ")) def itg(): return int(sys.stdin.readline()) n = itg() arr = sorted(mpint()) a1 = arr[n >> 1 :] a2 = arr[: n >> 1] ans = [] for i in range(n): if i & 1: ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
t = 1 for _ in range(t): n = int(input()) l = [int(j) for j in input().split()] l.sort() c, cnt = 0, 0 k = [0] * n for i in range(n // 2): k[c] = l[n // 2 + i] c += 1 k[c] = l[i] c += 1 if n % 2 != 0: k[n - 1] = l[n - 1] for i in range(1, n - 1): ...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
a = int(input()) b = [int(x) for x in input().split()] b.sort() c = [] d = [] result = [0] * a ans = 0 k = -1 l = 0 m = 0 if a == 1: print(0) print(*b) else: for i in range(a // 2): c.append(b[i]) for j in range(i + 1, a): d.append(b[j]) while k + 1 != a: k += 1 if (k...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys try: sys.stdin = open("input.txt", "r") except FileNotFoundError: pass def next_array(): return [int(i) for i in input().split()] def prefix(lst): assert len(lst) pre = [lst[0]] for i in range(1, len(lst)): pre.append(lst[i] + pre[i - 1]) return pre def prefix_max(l...
IMPORT ASSIGN VAR FUNC_CALL VAR STRING STRING VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF FUNC_CALL VAR VAR ASSIGN VAR LI...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = sorted(list(map(int, input().split()))) val = 0 b, c = a[: n // 2], a[n // 2 : -1] sol = [a[-1]] d = [] b_ptr, c_ptr = len(b) - 1, len(c) - 1 while True: if b_ptr < 0 or c_ptr < 0: break cc = c[c_ptr] while b_ptr >= 0: if b[b_ptr] >= cc: d.append(b[b_ptr]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR N...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = [int(x) for x in input().split()] a.sort() ans = 0 ansarr = [] if n < 3: print(0) print(" ".join([str(x) for x in a])) elif n % 2 == 0: for i in range(n // 2): ansarr.append(a[n // 2 + i]) ansarr.append(a[i]) for i in range(1, len(a) - 1, 2): if ansarr[i] < a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER E...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys readline = sys.stdin.readline N = int(readline()) A = list(map(int, readline().split())) A.sort() Ans = [None] * N A1 = A[: (N - 1) // 2][::-1] A2 = A[(N - 1) // 2 :] for i in range((N - 1) // 2): Ans[2 * i + 1] = A1[i] for i in range(N): if Ans[i] is None: Ans[i] = A2.pop() ans = 0 for i in...
IMPORT ASSIGN 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 ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) s = input() L = s.split() for i in range(len(L)): L[i] = int(L[i]) myLen = len(L) if myLen <= 2: print(0) print(s) quit() L.sort() gr = myLen // 2 cnt = gr if myLen % 2 else gr - 1 v = L[0] for i in range(gr, myLen - 1): if L[i] > v < L[i + 1]: k = i break else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NU...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = [int(x) for x in input().split()] asort = sorted(a) j = 0 ans = [0] * len(a) for i in range(1, len(a), 2): ans[i] = asort[j] j += 1 for k in range(0, len(a), 2): ans[k] = asort[j] j += 1 total = 0 for num in range(1, len(ans) - 1, 2): if ans[num] < ans[num - 1] and ans[num] < an...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VA...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort() ans = [None for _ in range(n)] i = 0 j = 1 while j < n: ans[j] = a[i] i += 1 j += 2 k = i j = 0 while k < n and j < n: ans[j] = a[k] k += 1 j += 2 count = 0 for i in range(1, n - 1): if ans[i] < ans[i + 1] and ans[i] < ans[i - 1]:...
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 ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) arr = list(map(int, input().split(" "))) arr = list(sorted(arr)) p = n // 2 resultarr = [] i = 0 while p < n: resultarr.append(arr[p]) if i < n // 2: resultarr.append(arr[i]) i += 1 p += 1 result = 0 for i in range(1, len(arr) - 1): if resultarr[i - 1] > resultarr[i] and res...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMB...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) l = list(map(int, input().split())) l.sort(reverse=True) ans = [0] * n for i in range(1, n, 2): ans[i] = l.pop() for i in range(0, n, 2): ans[i] = l.pop() count = 0 for i in range(1, n - 1): if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]: count += 1 print(count) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBE...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
from sys import * input = stdin.readline for _ in range(1): n = int(input()) a = list(map(int, input().split())) a.sort() b = [0] * n k = n // 2 j = k for i in range(0, n, 2): b[i] = a[j] j += 1 j = 0 for i in range(1, n, 2): b[i] = a[j] j += 1 an...
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) arr = [int(num) for num in input().split()] arr.sort() arr0 = arr[: n // 2] arr1 = arr[n // 2 :] p0 = 0 p1 = 0 ans = [] while p0 < len(arr0) and p1 < len(arr1): ans.append(arr1[p1]) ans.append(arr0[p0]) p0 += 1 p1 += 1 if n % 2: ans.append(arr1[-1]) ans_num = 0 for ind in range(1, n...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort() b = [0] * n for i in range((n + 1) // 2 - 1): b[2 * i + 1] = a[i] if n % 2 == 0: b[n - 1] = a[n // 2 - 1] for i in range((n + 1) // 2 - n % 2, n): b[2 * i - 2 * ((n + 1) // 2 - n % 2)] = a[i] cnt = 0 for i in range(n): if i > 0 and i < n - 1 ...
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 ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def solve(n, A): A.sort() v = [0] * n j = 0 for i in range(1, n, 2): v[i] = A[j] j += 1 for i in range(0, n, 2): v[i] = A[j] j += 1 count = 0 for i in range(1, n - 1): pre = i - 1 cur = i next = i + 1 if v[pre] > v[cur] and v[ne...
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBE...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = sorted(list(map(int, input().split()))) arr = [0] * n i = 0 for j in range(n // 2, n): arr[i] = a[j] i += 2 i = 1 for j in range(n // 2): arr[i] = a[j] i += 2 cnt = 0 for i in range(1, n - 1): if arr[i - 1] > arr[i] < arr[i + 1]: cnt += 1 print(cnt) print(*arr)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def main(): n = int(input()) lst = list(map(int, input().split())) lst = sorted(lst) new_lst = [] for i in range(n // 2): new_lst.append(lst[n // 2 + i]) new_lst.append(lst[i]) if n % 2 == 1: new_lst.append(lst[n - 1]) cnt = 0 for i in range(1, n - 1): if ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CAL...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) l = list(map(int, input().split())) ans = 0 l.sort() la = l[-1] k = [] if n < 3: print(0) print(*l) elif n % 2 != 0: ans = 0 l1 = l[0 : n // 2] l2 = l[n // 2 :] k.append(l[n // 2]) for i in range(n // 2, n - 1): ma1 = l[i] ma2 = l[i + 1] if l[i - 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 EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) arr = [int(x) for x in input().split()] arr.sort() arr[0::2], arr[1::2] = arr[n // 2 :], arr[: n // 2] ans = 0 for i in range(1, n - 1): if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]: ans += 1 print(ans) print(*arr)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def main(): n = int(input()) a = list(map(int, input().split())) a.sort() l = [] if n < 3: print(0) print(*a) return half = n // 2 for i in range(half): l.append(a[half + i]) l.append(a[i]) if n % 2 != 0: l.append(a[-1]) total = 0 f...
FUNC_DEF 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 ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FU...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def solve(): n = int(input()) p = list(map(int, input().split())) if n <= 2: print(0) print(*p) return p.sort() a = [0] * n l = 0 k = n if n % 2 == 0: k -= 1 for i in range(1, k, 2): a[i] = p[l] l += 1 l = n - 1 for i in range(k...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FU...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def solve(n, ices): ices = sorted(ices) former, latter = ices[: n // 2], ices[n // 2 :] res = 0 res_ice = [] for i in range((n - 1) // 2): res_ice.append(latter[i]) res_ice.append(former[i]) if former[i] < latter[i]: res += 1 res_ice.append(latter[-1]) if ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
t = int(input()) ice = list(map(int, input().split())) new_ice = [] count = 0 ice.sort() if len(ice) % 2 != 0: for i in range(0, len(ice) // 2 + 1): new_ice.append(ice[len(ice) // 2 + i]) new_ice.append(ice[i]) del new_ice[-1] elif len(ice) <= 2: for i in range(len(ice)): new_ice.app...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CA...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(sorted(list(map(int, input().split())))) k = n // 2 b = [] j = k l = 0 for i in range(n): if i % 2 == 0: b.append(a[j]) j += 1 else: b.append(a[l]) l += 1 c = 0 for i in range(1, n - 1, 2): if b[i] < b[i + 1] and b[i] < b[i - 1]: c += 1 print...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = sorted(map(int, input().split())) mas = [0] * n j = 1 for i in range(n): if j >= n: j = 0 mas[j] = a[i] j += 2 ans = 0 for i in range(1, n - 1): ans += mas[i - 1] > mas[i] < mas[i + 1] print(ans) print(*mas)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys n = int(sys.stdin.readline()) pricelist = [int(v) for v in sys.stdin.readline().strip().split(" ")] pricelist.sort() newlist = [(0) for i in range(0, n)] start = int(n / 2) for i in range(0, start): newlist[i * 2] = pricelist[i + start] newlist[i * 2 + 1] = pricelist[i] if n % 2 == 1: newlist[n ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) array = list(map(int, input().split(" "))) array.sort() menores = array[: int(n / 2)] maiores = array[int(n / 2) :] index = 0 solucao = [] qtd = 0 flag_left = False for i in range(n): if i % 2 != 0: solucao.append(menores[index]) if menores[index] < solucao[i - 1]: flag_...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VA...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) list1 = list(map(int, input().split())) list1 = sorted(list1) res = [] first = list1[: n // 2] second = list1[n // 2 :] c = 0 if n % 2 == 0: for i in range(len(second)): res.append(second[i]) res.append(first[i]) else: for i in range(len(second) - 1): res.append(second[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VA...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) l = list(map(int, input().split()))[:n] f = [0] * n l.sort(reverse=True) cnt = 0 for i in range(n): if i % 2 == 1: f[i] = l.pop() for i in range(n): if f[i] == 0: f[i] = l.pop() if n % 2 == 0: for i in range(1, n - 2, 2): if f[i] < f[i - 1] and f[i] < f[i + 1]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIG...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) bolas = [] valores = input().split() cont = 0 for e in range(n): bolas.append(int(valores[e])) bolas.sort() v1 = bolas[0 : n // 2] v2 = bolas[n // 2 :] v3 = [] for e in range(n // 2): v3.append(v2[e]) v3.append(v1[e]) if n % 2 != 0: v3.append(v2[-1]) for e in range(1, n - 1): if v3[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMB...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = input() p = [int(x) for x in input().strip().split(" ")] if len(p) <= 2: print(0) print(" ".join([str(x) for x in p])) exit() p.sort() res_list = [] if len(p) % 2 == 0: index = int(len(p) / 2) if p[index - 1] == p[index - 2]: res_list.append(p[index - 1]) del p[index - 1] els...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VA...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = [int(x) for x in input().split()] b = [0] * n a.sort() k = 0 c = 0 for i in range(1, n, 2): b[i] = a[k] k += 1 for i in range(0, n, 2): b[i] = a[k] k += 1 for i in range(1, n - 1): if b[i] < b[i - 1] and b[i] < b[i + 1]: c += 1 print(c) print(*b)
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 VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VA...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) arr = list(map(int, input().split())) arr.sort() res = [] for i in range(n // 2): res.append(arr[n // 2 + i]) res.append(arr[i]) if n % 2: res.append(arr[-1]) res2 = 0 for i in range(1, n - 1): if res[i] < res[i - 1] and res[i] < res[i + 1]: res2 += 1 print(res2) print(" ".join(...
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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VA...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys input = sys.stdin.readline N = int(input()) A = [int(_) for _ in input().split()] sA = sorted(A) B = ["?"] * N for i in range(N // 2): B[2 * i + 1] = sA[i] for i in range(N // 2, N): B[2 * (i - N // 2)] = sA[i] answer = 0 for i in range(N // 2): if 2 * i + 2 < N: if B[2 * i + 1] < B[2 * ...
IMPORT 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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSI...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort() cur = 0 i = 1 res = [0] * n while i < n: res[i] = a[cur] i += 2 cur += 1 i = 0 while i < n: res[i] = a[cur] i += 2 cur += 1 ans = 0 for i in range(1, n - 1): if res[i - 1] > res[i] and res[i] < res[i + 1]: ans += 1 print(a...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys n = int(input()) spheres = list(map(int, input().split())) spheres.sort() small = spheres[: n // 2] big = spheres[n // 2 :] res = [] for i in range(n): if i % 2 == 0: res.append(big[i // 2]) else: res.append(small[i // 2]) c = 0 for i in range(n): if i == 0 or i == n - 1: ...
IMPORT 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 ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_C...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
from sys import * input = stdin.readline listInput = lambda: list(map(int, input().strip().split())) lineInput = lambda: map(int, input().strip().split()) sJoin = lambda a, sep: f"{sep}".join(a) arrJoin = lambda a, sep: f"{sep}".join(map(str, a)) def main(): n = int(input()) arr = sorted(listInput()) i, ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR AS...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def solve(): n = int(input().strip()) a = list(map(int, input().strip().split())) a.sort() a1 = a[: n // 2] a2 = a[n // 2 :] flag = True cursor1 = 0 cursor2 = 0 prevPrice = -100 ans = 0 for i in range(len(a2)): if i + 1 < len(a2): ans += 1 if a2[i] > a1[i]...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FU...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) mas = list(map(int, input().split())) mas = sorted(mas) middle = n // 2 masans = [] ans = 0 if n > 1: for i in range(n // 2): if mas[i] < mas[i + middle]: ans += 1 masans.append(mas[i + middle]) masans.append(mas[i]) if n % 2 != 0: masans.append(mas[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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def do(l, n): o = l[0 : n // 2] k = l[n // 2 : n] nlist = [] for i in range(n // 2): nlist.append(str(k[i])) nlist.append(str(o[i])) if n % 2 == 1: nlist.append(str(k[n // 2])) return nlist num = int(input()) l = list(map(int, input().split())) l.sort() a = do(l, num) c...
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR AS...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = [int(inp) for inp in input().split()] a.sort() i = 0 j = len(a) // 2 b = [] sw = 1 while j < len(a) or i < len(a) // 2: if sw: b.append(a[j]) j += 1 else: b.append(a[i]) i += 1 sw = 1 - sw res = 0 i = 1 while i < len(b) - 1: if b[i] < b[i - 1] and b[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER E...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = sorted(map(int, input().split())) m = (n - 1) // 2 i, j = 0, m + 1 ans = 0 temp = a[m] if n < 3: print(ans) for i in a: print(i, end=" ") else: z = n * [0] z[::2] = a[n // 2 :] z[1::2] = a[: n // 2] for i in range(m): if z[2 * i + 1] < z[2 * i] and z[2 * i + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = [int(i) for i in input().split()] a.sort() ans = [] p = 0 if n % 2: for i in range(n // 2, n): ans.append(a[i]) if i < n - 1: ans.append(a[p]) p += 1 else: for i in range(n // 2, n): ans.append(a[i]) ans.append(a[p]) p += 1 cnt...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CAL...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) l = sorted(list(map(int, input().split()))) x = [] if n <= 2: print(0) print(*l) elif n % 2 == 0: a = l[: n // 2] b = l[n // 2 :] ans = 0 for i in range(n // 2): x.append(b[i]) x.append(a[i]) for j in range(1, n - 1, 2): if x[j] < x[j + 1] and x[j] < ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR F...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys n = int(sys.stdin.readline()) pricelist = [int(v) for v in sys.stdin.readline().strip().split(" ")] pricelist.sort(reverse=True) newlist = [(0) for i in range(0, n)] start = int((n + 1) / 2) for i in range(0, start): newlist[i * 2] = pricelist[i] waitlist = [] pt = 1 total = 0 for i in range(start, n): ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys input = sys.stdin.readline n = int(input()) a = [int(i) for i in input().split() if i != "\n"] a.sort() ans = [0] * n j = 0 for i in range(1, n, 2): ans[i] = a[j] j += 1 for i in range(n): if ans[i] == 0: ans[i] = a[j] j += 1 count = 0 for i in range(1, n - 1): if ans[i - 1] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER AS...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) esferas = list(map(int, input().split(" "))) esferas.sort() limite = int(n / 2) menores = esferas[:limite] maiores = esferas[limite:] indice = 0 reordenadas = [] compras = 0 esquerda = False for i in range(n): if i % 2 == 0: reordenadas.append(maiores[int(i / 2)]) if esquerda and ma...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) l = list(map(int, input().split())) lena = len(l) l.sort() left = l[: lena // 2] right = l[lena // 2 :] left.sort() right.sort() answer = [] count = 0 for i in range(len(right)): answer.append(right[i]) if i < len(left): answer.append(left[i]) if answer[-1] < answer[-2] and i < ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_C...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) F = [int(i) for i in input().split()] F.sort() if n % 2 != 0: A = F[: int((n - 1) / 2)] B = F[int((n - 1) / 2) :] for i in range(int((n + 1) / 2)): F[2 * i] = B[i] for i in range(int((n - 1) / 2)): F[2 * i + 1] = A[i] else: A1 = F[: int(n / 2)] B1 = F[int(n / 2) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR N...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = sorted(map(int, input().split())) b = [0] * n b[1::2], b[::2] = a[: n // 2], a[n // 2 :] print(sum(b[i - 1] > b[i] < b[i + 1] for i in range(1, n - 1))) print(*b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
from sys import stdin n = int(stdin.readline()) a = sorted(map(int, input().split())) m = (n - 1) // 2 c = 0 b = [] for i in range(n): b.append(a[(1 - i % 2) * (n // 2) + i // 2]) for i in range(1, m + 1): if b[i * 2 - 1] < min(b[i * 2 - 2], b[i * 2]): c += 1 print(c) for i in range(n): print(b[i],...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VA...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort() i = 0 j = 0 a1 = a[: n // 2] a2 = a[n // 2 :] ans = [] while i < len(a1) and j < len(a2): ans.append(a2[j]) j += 1 ans.append(a1[i]) i += 1 while i < len(a1): ans.append(a1[i]) i += 1 while j < len(a2): ans.append(a2[j]) j += ...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) p = [int(x) for x in input().split()] p.sort() a = [None] * n k = 0 if n % 2 == 1: for i in range(1, n, 2): a[i] = p[k] k += 1 for i in range(0, n, 2): a[i] = p[k] k += 1 else: for i in range(1, n, 2): a[i] = p[k] k += 1 for i in range(0, ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VA...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) arr = list(map(int, input().split())) arr.sort() small = arr[: len(arr) // 2] large = arr[len(arr) // 2 :] i = 0 while i < len(arr): if i % 2 == 0: arr[i] = large[i // 2] else: arr[i] = small[i // 2] i += 1 ans = 0 for i in range(1, len(arr) - 1): if arr[i] < arr[i + 1] ...
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 ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort() b = n // 2 c = [] i = 0 while len(c) < n: c.append(a[b]) if len(c) == n: break c.append(a[i]) i += 1 b += 1 ans = 0 i = 0 while i < n - 1: if c[i] > c[i + 1]: ans += 1 i += 2 if n % 2 == 0 and c[-1] != c[-2]: a...
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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASS...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys input = sys.stdin.readline n = int(input()) x = sorted(list(map(int, input().split()))) a, b = x[: n // 2], x[n // 2 :] tmp = [] for i in range(n // 2): tmp.append(b[i]) tmp.append(a[i]) if n % 2: tmp.append(b[-1]) cnt = 0 for i in range(1, n - 1, 2): if tmp[i + 1] > tmp[i] < tmp[i - 1]: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) b = list(map(int, input().split())) if n < 3: print(0) print(*b) else: out = 0 ans = [] b.sort() k = b[: n // 2] l = b[n // 2 :] if n % 2: for i in range(n // 2): ans.append(l.pop()) ans.append(k.pop()) ans.append(l.pop()) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER FOR VAR FUN...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) l = list(map(int, input().split())) l.sort() ans = [] if n % 2 == 1: ans.append(l[n // 2]) for i in range(n // 2): ans.append(l[i]) ans.append(l[(n + 1) // 2 + i]) else: for i in range(n // 2): ans.append(l[(n + 1) // 2 + i]) ans.append(l[i]) num = 0 for i in...
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 ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) arr = list(map(int, input().split())) arr.sort() ans = [] f = 0 less = arr[: n // 2] gre = arr[n // 2 :] l = 0 while l != n // 2: ans.append(gre[l]) ans.append(less[l]) l += 1 if n % 2 != 0: ans.append(gre[-1]) for i in range(1, n - 1): if ans[i - 1] > ans[i] and ans[i] < ans[i + 1]...
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 ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) data = list(map(int, input().split())) def cal(data, n): data.sort() res = [0] * n m = n // 2 res[0::2] = data[m:] res[1::2] = data[:m] ans = 0 for i in range(1, n, 2): if i == n - 1: break if res[i - 1] > res[i] and res[i] < res[i + 1]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
l = [] if 1 == 1: n = int(input()) a = list(map(int, input().split())) a.sort() s = [] if n % 2 == 0: if a[n // 2 - 1] != a[n // 2]: print(n // 2 - 1) for i in range(n): if i % 2 == 0: s.append(str(a[i // 2 + n // 2])) ...
ASSIGN VAR LIST IF NUMBER NUMBER 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 ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VA...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def solve(n, ar): ar = sorted(ar) l = 0 r = n + 1 while r - l > 1: m = (r + l) // 2 f = True if 2 * m + 1 > n: f = False else: b = [] pos_a = 0 pos_b = n - (m + 1) for i in range(2 * m + 1): if i ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) arr = sorted(list(map(int, input().split())), reverse=True) t = n - (n - 1) // 2 ans = [(0) for _ in range(n)] for i in range(t): x = i * 2 if x == n: x -= 1 ans[x] = arr[i] cur = 1 cur2 = n - 2 if n % 2 == 0: cur2 -= 1 for i in range(t, n): if ans[cur - 1] > arr[i] < ans[cu...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) array = list(map(int, input().split())) array.sort() output = [] array1 = array[0 : n // 2] array2 = array[n // 2 :] i = 0 j = 0 count = 0 while i < n // 2 and j < (n - 1) // 2: b = array2[j] a = array1[i] output.append(b) output.append(a) if b > a: count += 1 i += 1 ...
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 ASSIGN VAR LIST ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NU...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = sorted(map(int, input().split()), reverse=True) i = n - n // 2 order = [a[0]] skipped = [] j = 1 while i < n: if len(order) % 2: while a[i] == a[j]: skipped.append(a[i]) i += 1 if i == n: break else: order.append(a[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMB...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) spheres = list(map(int, input().split(" "))) spheres = sorted(spheres) ret = [(-1) for _ in range(n)] l, r = 0, n - 1 cnt = 0 block_n = n // 2 + n % 2 inner_n = n - block_n inners = spheres[:inner_n] blocks = spheres[inner_n:n] st = 0 if n % 2 == 0: ret[0] = inners.pop() st = 1 for i in range(s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def f(): n = int(input()) arr = list(map(int, input().split())) arr.sort() newarr = [] for i in range(n // 2): newarr.append(arr[i + n // 2]) newarr.append(arr[i]) if n % 2: newarr.append(arr[n - 1]) total = 0 i = 1 while i + 1 < n: if newarr[i - 1] > ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort() lo = 0 hi = (n + 1) // 2 while hi - lo > 1: test = (hi + lo) // 2 smol = a[:test] large = a[-test - 1 :] rest = a[test : -test - 1] works = True for i in range(test): if smol[i] == large[i] or smol[i] == large[i + 1]: ...
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 ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort() ind = n // 2 res = [] i = 0 f = True for j in range(n): if f == True: res.append(a[ind]) ind += 1 f = False else: res.append(a[i]) i += 1 f = True ans = 0 for i in range(1, n - 1): if res[i - 1] > r...
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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) d = [int(i) for i in input().split()] d.sort() if n < 3 or d.count(d[0]) >= n - 1: print(0) print(" ".join(map(str, d))) exit() mxd = [min(d[i], d[i + 1]) for i in range(n - 1)] hi = (n - 3) // 2 lo = 0 while lo < hi: mid = (lo + hi + 1) // 2 kk = n - mid - 2 if sum(mxd[kk + i] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort() l = len(a) // 2 f = a[:l] s = a[l:] t = [0] * len(a) ind = 0 for i in range(len(s)): t[ind] = s[i] ind += 2 ind = 1 for i in range(len(f)): t[ind] = f[i] ind += 2 x = 0 for i in range(1, len(t) - 1): if t[i] < t[i + 1] and t[i] < t[i - 1]...
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 ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) arr = list(map(int, input().strip().split())) if n % 2 == 0: ans = n // 2 - 1 else: ans = n // 2 arr.sort() low = arr[: n // 2] hi = arr[n // 2 :] arr[::2] = hi arr[1::2] = low for i in range(1, n - 1, 2): if arr[i] == arr[i - 1] or arr[i] == arr[i + 1]: ans -= 1 print(ans) print(*a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort() g = [] h = [] for j in range(n // 2): g.append(a[j]) for j in range(n // 2, n): h.append(a[j]) gx = len(g) hx = len(h) gy = 0 hy = 0 c = 0 k = [] while gy < gx or hy < hx: if gy < gx and hy < hx: if g[gy] < h[hy]: k.append(h[h...
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 ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) arr = list(map(int, input().split())) flag = 1 if n <= 2: print(0) print(*arr) flag = 0 arr.sort(reverse=True) final = ["0"] pair = 0 if flag == 1: k = 0 j = 1 if n % 2 != 0: temp1 = arr[: n // 2 + 1] temp2 = arr[n // 2 + 1 :] else: temp1 = arr[: 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBE...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) lst = list(map(int, input().split())) lst.sort() result = lst[n // 2 :] for i in range(n // 2): result.insert(2 * i + 1, lst[i]) cnt = 0 for i in range(1, n - 1): if result[i - 1] > result[i] and result[i] < result[i + 1]: cnt += 1 print(cnt) print(" ".join(map(str, result)))
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 ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBE...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys input = sys.stdin.readline n = int(input()) a = [int(item) for item in input().split()] a.sort() ans = [-1] * n num = 0 if n % 2 == 1: for i in range(0, n, 2): ans[i] = a.pop() for i in range(1, n, 2): if ans[i - 1] > a[-1] < ans[i + 1]: num += 1 ans[i] = a.pop() ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR N...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) arr = list(map(int, input().split())) res = [0] * n arr.sort() for i in range(n): if i < n // 2: res[i * 2 + 1] = arr[i] else: res[(i - n // 2) * 2] = arr[i] x = 0 for i in range(1, n - 1): if res[i - 1] > res[i] < res[i + 1]: x += 1 print(x) print(*res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) arr = list(map(int, input().split())) arr.sort() ans = [-1] * n k = 0 c = 0 for i in range(1, n, 2): ans[i] = arr[k] k += 1 for i in range(n): if ans[i] == -1: ans[i] = arr[k] k += 1 for i in range(1, n - 1, 2): if ans[i] < ans[i - 1] and ans[i] < ans[i + 1]: c +...
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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) l = list(map(int, input().split())) l.sort() j = 0 mid = len(l) // 2 a = [0] * (n + 2) for i in range(mid): a[i + j], a[i + 1 + j] = l[mid + i], l[i] j += 1 if n % 2 != 0: a[n - 1] = l[n - 1] p = 0 for i in range(1, n): if a[i - 1] > a[i] and a[i] < a[i + 1]: p += 1 print(p) a =...
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 ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
R = lambda: map(int, input().split()) n = int(input()) arr = sorted(R(), reverse=True) vst = [0] * n res = [] j = 0 k = (n + 1) // 2 cnt = 0 for i in range(n): if not vst[i]: res.append(arr[i]) j = max(j, i + 1) while j < n and vst[j]: j += 1 k = max(k, j + 1) whi...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def main(): n = int(input()) a = map(int, input().split()) a = sorted(a) result = [-1] * n i = 0 j = n - 1 - 1 l = 0 r = n - 1 if n % 2 == 0: i += 1 while j > 0: result[i] = a[r] result[j] = a[l] i += 2 j -= 2 r -= 1 l += 1 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE VAR...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
from itertools import chain, zip_longest n = int(input()) a = [int(s) for s in input().split(" ")] a.sort(reverse=True) cnt = 0 ans = [x for x in chain(*zip_longest(a[: n // 2 + 1], a[n // 2 + 1 :])) if x] for i in range(1, n - 1): if min(ans[i - 1], ans[i + 1]) > ans[i]: cnt += 1 print(cnt) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort() b = a[: n // 2] c = a[n // 2 :] A = [] for i in c: A.append(i) index = 1 indB = 0 while index < n: A.insert(index, b[indB]) indB += 1 index += 2 index = 1 ans = 0 while index < len(A) - 1: if A[index - 1] > A[index] < A[index + 1]: ...
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 ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
N = int(input()) A = list(map(int, input().split())) A.sort() B = [0] * N for i in range(1, N, 2): B[i] = A[i // 2] Astart = N // 2 Bstart = N - 2 if N % 2 == 0 else N - 1 rem = [] while Astart < N and A[Astart] == B[Bstart - 1]: rem.append(A[Astart]) Astart += 1 for i in range(Bstart, -1, -2): if Astar...
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 ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER B...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = sorted(map(int, input().split())) l = [a[(1 - i % 2) * (n // 2) + i // 2] for i in range(n)] c = 0 for i in range(1, n - 1): if l[i - 1] > l[i] < l[i + 1]: c += 1 print(c) print(" ".join(map(str, l)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR V...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) l = list(sorted(map(int, input().split()))) left = l[0 : n // 2] right = l[n // 2 : n] arr = [(-1) for x in range(n)] count = 0 flag = True j = 0 k = 0 for i in range(n): if flag == True: arr[i] = right[j] j += 1 flag = False elif flag == False: arr[i] = left[k] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUN...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def check_cou(s, x, dx1, dx2): if (n := len(s)) - x >= x + 1: if s[x - 1] != s[n - x - 1]: return True elif x - dx1 >= dx2 and dx1 <= n - x + dx2: return True else: return False else: return False def cou(s): x = int((len(s) - 1) / 2) ...
FUNC_DEF IF BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR ...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
def check(arr): n = len(arr) ans = 0 for i in range(1, n - 1): if arr[i] < arr[i - 1] and arr[i] < arr[i + 1]: ans += 1 return ans n = int(input()) a = list(map(int, input().split())) arr = [None] * n a.sort() start = 0 for i in range(1, n, 2): arr[i] = a[start] start += 1 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NON...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) lis = sorted(map(int, input().split())) ans = [0] * n i = j = n - 1 while j >= 0 and i >= 0: ans[j] = lis[i] i -= 1 j -= 2 j = n - 2 tmp = [] while j > 0 and i >= 0: while j > 0 and i >= 0 and (ans[j + 1] == lis[i] or ans[j - 1] == lis[i]): tmp.append(lis[i]) i -= 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 BIN_OP LIST NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER W...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) res = [0] * n a = sorted(a, reverse=True) ai = 0 for i in range(0, n, 2): res[i] = a[ai] ai += 1 if n % 2 == 0: res[-1] = a[ai] ai += 1 for i in range(1, n - 1, 2): res[i] = a[ai] ai += 1 ans = 0 for i in...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER AS...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) ans = [-1] * n j = 0 for i in range(0, n, 2): ans[i] = a[j] j += 1 ansl = 0 check = False for i in range(1, n, 2): ans[i] = a[j] if i < n - 1 and ans[i - 1] > ans[i] < ans[i + 1]: ansl += 1 elif i == n - 1: che...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMB...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) l = list(map(int, input().split())) l = sorted(l) ans = [(0) for _ in range(n)] t = n - 1 x = 0 if n % 2 == 0: x = 1 for i in range(n - 1 - x, -1, -2): ans[i] = l[t] t -= 1 t = 0 for i in range(1, n, 2): ans[i] = l[t] t += 1 t = 0 for i in range(1, n - 1): if ans[i] < ans[i - 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR N...
This is the hard version of the problem. The difference between the versions is that in the easy version all prices $a_i$ are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All $n$ ice spheres are placed in a ...
n = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) x = n // 2 b = a[:x] c = a[x:] c.reverse() b.reverse() z = [] for i in range(x): z.append(b[i]) z.append(c[i]) c[i] = 0 for i in range(len(c)): if c[i] != 0: z.append(c[i]) ans2 = 0 for i in range(1, n - 1, 2): if z[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL...