Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from itertools import combinations
from operator import or_

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
d = [1 << i for i in range(n)]
same_groups = [0] * (1 << n)
dp = [0] * (1 << n)

for i in range(1, 1 << n):
    k = i
    rb = k & -k
    ri = rb.bit_length() - 1
    ar = a[ri]
    k ^= rb
    val = same_groups[k]
    while k:
        pb = k & -k
        val += ar[pb.bit_length() - 1]
        k ^= pb
    same_groups[i] = val
# print(same_groups)

for k in range(3, n + 1):
    for grp in combinations(d, k):
        grp_i = reduce(or_, grp)
        val = float('-inf')
        for j in range(1, k + 1):
            for subgrp in combinations(grp, j):
                subgrp_i = reduce(or_, subgrp)
                comple_i = grp_i ^ subgrp_i
                val = max(val, same_groups[subgrp_i] + dp[comple_i])
        dp[grp_i] = val
        # print(k, dp, grp_i)
    # print(k)

print(dp[-1])


Fixed submission:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
d = [1 << i for i in range(n)]

same_groups = [0] * (1 << n)
for i in range(1, 1 << n):
    k = i
    rb = k & -k
    ri = rb.bit_length() - 1
    ar = a[ri]
    k ^= rb
    val = same_groups[k]
    while k:
        pb = k & -k
        val += ar[pb.bit_length() - 1]
        k ^= pb
    same_groups[i] = val

dp = [0] * (1 << n)
for grp in range(1 << n):
    g = grp
    while g:
        dp[grp] = max(dp[grp], same_groups[g] + dp[grp ^ g])
        g = (g - 1) & grp

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from itertools import combinations
from operator import or_

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
d = [1 << i for i in range(n)]
same_groups = [0] * (1 << n)
dp = [0] * (1 << n)

for i in range(1, 1 << n):
    k = i
    rb = k & -k
    ri = rb.bit_length() - 1
    ar = a[ri]
    k ^= rb
    val = same_groups[k]
    while k:
        pb = k & -k
        val += ar[pb.bit_length() - 1]
        k ^= pb
    same_groups[i] = val
# print(same_groups)

for k in range(3, n + 1):
    for grp in combinations(d, k):
        grp_i = reduce(or_, grp)
        val = float('-inf')
        for j in range(1, k + 1):
            for subgrp in combinations(grp, j):
                subgrp_i = reduce(or_, subgrp)
                comple_i = grp_i ^ subgrp_i
                val = max(val, same_groups[subgrp_i] + dp[comple_i])
                # print(grp, subgrp, same_groups[subgrp_i], dp[comple_i])
        dp[grp_i] = val
        # print(k, dp, grp_i)
    # print(k)

print(dp[-1])


Fixed submission:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
d = [1 << i for i in range(n)]

same_groups = [0] * (1 << n)
for i in range(1, 1 << n):
    k = i
    rb = k & -k
    ri = rb.bit_length() - 1
    ar = a[ri]
    k ^= rb
    val = same_groups[k]
    while k:
        pb = k & -k
        val += ar[pb.bit_length() - 1]
        k ^= pb
    same_groups[i] = val

dp = [0] * (1 << n)
for grp in range(1 << n):
    g = grp
    while g:
        dp[grp] = max(dp[grp], same_groups[g] + dp[grp ^ g])
        g = (g - 1) & grp

print(dp[-1])