arr = [4, 2, 1, 3, 9, 5, 6]
M = 3
arr.sort()

answer = 0
for i in range(len(arr)):
    if i % 3 ==0 and i!=0:
        answer += arr[i]

print(answer)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: