Problem: There are 3N participants in _AtCoder Group Contest_. The _strength_ of the i-th participant is represented by an integer a_i. They will form N teams, each consisting of three participants. No participant may belong to multiple teams.  The strength of a team is defined as the second largest strength among its members. For example, a team of participants of strength 1, 5, 2 has a strength 2, and a team of three participants of strength 3, 2, 3 has a strength 3.  Find the maximum possible sum of the strengths of N teams.

Submission attempts (in order):
import numpy as np


N = int(input())
a = list(map(int, input().split(' ')))
a.sort()

x = []
for n in range(N):
    x.append([])
    for i in range(3):
        x[n].append(0)

for i in range(N*3):
    x[i % N][i // N] = a[i]

for i in range(N-1, -1, -1):
    for j in range(i-1, -1, -1):
        if x[i][1] == x[j][1]:
            if x[j][2] < x[i][2]:
                tmp = x[i][2]
                x[i][2] = x[j][1]
                x[j][1] = tmp

res = 0

for n in range(N):
    res += x[n][1]

print(res)


import numpy as np


N = int(input())
a = list(map(int, input().split(' ')))
a.sort()

x = []
for n in range(N):
    x.append([])
    for i in range(3):
        x[n].append(0)

for i in range(N*3):
    x[i % N][i // N] = a[i]

for i in range(N-1, -1, -1):
    for j in range(i-1, -1, -1):
        if x[i][1] == x[j][1] and [j][2] < x[i][1] and x[i][2] > x[j][2]:
            x[j][2], x[i][1] = x[i][1], x[j][2]
            break
        else:
            break


res = 0

for n in range(N):
    res += x[n][1]

print(res)


import numpy as np
from numpy import linalg as LA
import math

mat_dic = {}

def f(mat, n):
    if mat_dic.get(n, None) is not None:
        return mat_dic.get(n, None)

    if n == 1:
        return mat

    if int(math.sqrt(n))**2 == n:
        return LA.matrix_power(f(mat, int(math.sqrt(n))), 2)

    return mat.dot(f(mat, n-1))



N, M = tuple(map(int, input().split(' ')))

mat = np.identity(N)
res = np.zeros(N)

for m in range(M):
    a, b = tuple(map(int, input().split(' ')))
    mat[a-1, b-1] = 1
    mat[b-1, a-1] = 1
    mat[a-1, a-1] = 1
    mat[b-1, b-1] = 1

Q = int(input())

for q in range(Q):
    v, d, c = tuple(map(int, input().split(' ')))
    x = f(mat, d)
    res[x[v-1,:] > 0] = c


for i in range(N):
    print(int(res[i]))


import numpy as np


N = int(input())
a = list(map(int, input().split(' ')))
a.sort(reverse=True)

x = np.zeros((N, 3))

for i in range(N*3):
    x[i % N , i // N] = a[i]

res = 0

print(x)

for n in range(N):
    res += x[n, 1]

print(int(res))


import numpy as np
from collections import defaultdict

memo = {}
def dp(v, d, c):
    if memo.get((v, d), False):
        return None

    memo[(v, d)] = True
    if d == 0:
        res[v-1] = c
        return None

    dp(v, d-1, c)
    for e in dic.get(v, []):
        dp(e, d-1, c)


N, M = tuple(map(int, input().split(' ')))

dic = defaultdict(list)

for m in range(M):
    a, b = tuple(map(int, input().split(' ')))
    dic[a].append(b)
    dic[b].append(a)

Q = int(input())

vdc = [None]*Q

for q in range(Q):
    vdc[q] = tuple(map(int, input().split(' ')))

res = np.zeros(N)

for q in range(Q-1, -1, -1):
    v, d, c = vdc[q]
    dp(v, d, c)


for i in range(N):
    print(int(res[i]))


import numpy as np


N = int(input())
a = list(map(int, input().split(' ')))
a.sort()

res = 0
for i in range(len(a[N:])):
    if i % 2 == 0:
        res += a[N+i]

print(res)


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted