1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def podziel(l, n):
    if n == 1:
        yield [l]
    else:
        for i in range(1, len(l)):
            for p in podziel(l[i:], n-1):
                yield [l[:i]] + p

n, grupy = list(map(int, input().split()))
dane = list(map(int, input().split()))
for lista in podziel(dane, grupy):
    print(lista)
    daSie = False
    koniec = False
    for i in range(len(lista)-1):
        minimum = min(lista[i])
        GRUPA = lista[i+1].copy()
        while(True):
            try:
                if min(lista[i+1]) > minimum:
                    daSie = True
                    break
                else:
                    lista[i+1].remove(min(lista[i+1]))
            except:
                daSie = False
                break
        lista[i+1] = GRUPA.copy()
    if daSie == False:
        print('TAK')
        suma = 0
        for i in range(len(lista)-1):
            suma += len(lista[i])
            print(suma, end=' ')
        koniec = True
        break
    if koniec == True:
        break
if koniec == False:
    print('NIE')