Problem: E869120's and square1001's 16-th birthday is coming soon.   Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan- shaped pieces.  E869120 and square1001 were just about to eat A and B of those pieces, respectively,   when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake".  Can both of them obey the instruction in the note and take desired numbers of pieces of cake?

Submission attempts (in order):
n, m = map(int, input().split())
li = [list(map(int, input().split()))for i in range(n)]

a = 0
b = 0
c = 0
review = abs(a) + abs(b) + abs(c)
for i in range(m):
    a += li[i][0]
    b += li[i][1]
    c += li[i][2]

review = abs(a) + abs(b) + abs(c)
flag = True

while True:
    flag = True
    for i in range(m):
        for j in range(n-m):
            x = li[i]
            li[i] = li[m+j]
            li[m+j] = x
            a = 0
            b = 0
            c = 0
            for k in range(m):
                a += li[k][0]
                b += li[k][1]
                c += li[k][2]
            if review < abs(a) + abs(b) + abs(c):
                review = abs(a) + abs(b) + abs(c)
                flag = False
    if flag:
        break
    else:
        continue
print(review)


n, m = map(int, input().split())
li = [list(map(int, input().split()))for i in range(n)]

a = 0
b = 0
c = 0
review = abs(a) + abs(b) + abs(c)
for i in range(m):
    a += li[i][0]
    b += li[i][1]
    c += li[i][2]

review = abs(a) + abs(b) + abs(c)
flag = True

while True:
    flag = True
    for i in range(m):
        for j in range(n-m):
            x = li[i]
            li[i] = li[m+j]
            li[m+j] = x
            a = 0
            b = 0
            c = 0
            for k in range(m):
                a += li[k][0]
                b += li[k][1]
                c += li[k][2]
            if review < abs(a) + abs(b) + abs(c):
                review = abs(a) + abs(b) + abs(c)
                flag = False
    if flag:
        break
    else:
        continue
print(review)


n, m = map(int, input().split())
li = [list(map(int, input().split()))for i in range(n)]

a = 0
b = 0
c = 0
review = abs(a) + abs(b) + abs(c)
for i in range(m):
    a += li[i][0]
    b += li[i][1]
    c += li[i][2]

review = abs(a) + abs(b) + abs(c)
flag = True

while True:
    flag = True
    for i in range(m):
        for j in range(n-m):
            x = li[i]
            li[i] = li[m+j]
            li[m+j] = x
            a = 0
            b = 0
            c = 0
            for k in range(m):
                a += li[k][0]
                b += li[k][1]
                c += li[k][2]
            if review < abs(a) + abs(b) + abs(c):
                review = abs(a) + abs(b) + abs(c)
                flag = False
    if flag:
        break
    else:
        continue
print(review)


a = int(input())
b = int(input())

if a >= 9 or b >= 9:
    print(":(")
else:
    print("Yay!")


n, m = map(int, input().split())
li = [list(map(int, input().split()))for i in range(n)]

a = 0
b = 0
c = 0
review = abs(a) + abs(b) + abs(c)
for i in range(m):
    a += li[i][0]
    b += li[i][1]
    c += li[i][2]

review = abs(a) + abs(b) + abs(c)
flag = True

while True:
    flag = True
    for i in range(m):
        for j in range(n-m):
            x = li[i]
            li[i] = li[m+j]
            li[m+j] = x
            a = 0
            b = 0
            c = 0
            for k in range(m):
                a += li[k][0]
                b += li[k][1]
                c += li[k][2]
            if review < abs(a) + abs(b) + abs(c):
                review = abs(a) + abs(b) + abs(c)
                flag = False
    if flag:
        break
    else:
        continue
print(review)


n, m = map(int, input().split())
li = [list(map(int, input().split()))for i in range(n)]

a = 0
b = 0
c = 0
review = abs(a) + abs(b) + abs(c)
for i in range(m):
    a += li[i][0]
    b += li[i][1]
    c += li[i][2]

review = abs(a) + abs(b) + abs(c)
flag = True

while True:
    flag = True
    for i in range(m):
        for j in range(n-m):
            x = li[i]
            li[i] = li[m+j]
            li[m+j] = x
            a = 0
            b = 0
            c = 0
            for k in range(m):
                a += li[k][0]
                b += li[k][1]
                c += li[k][2]
            if review < abs(a) + abs(b) + abs(c):
                review = abs(a) + abs(b) + abs(c)
                flag = False
    if flag:
        break
    else:
        continue
print(review)


a, b = map(int, input().split())

if a >= 9 or b >= 9:
    print(":(")
else:
    print("Yay!")


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted