Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
D = [list(map(int,input().split())) for i in range(N)]
ans = 0
x,y = 0,0
for d in D:
    if d[0]>=0 and d[1]>=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
x,y = 0,0
for d in D:
    if d[0]>=0 and d[1]<=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
x,y = 0,0
for d in D:
    if d[0]<=0 and d[1]>=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
x,y = 0,0
for d in D:
    if d[0]<=0 and d[1]<=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
import math
N = int(input())
D = [list(map(int,input().split())) for i in range(N)]
ans = 0
x,y = 0,0
for d in D:
    if d[0]>=0 and d[1]>=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
x,y = 0,0
for d in D:
    if d[0]>=0 and d[1]<=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
x,y = 0,0
for d in D:
    if d[0]<=0 and d[1]>=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
D.sort(key=lambda x:abs(x[0])+abs(x[1]))
x,y,k = 0,0,0
for d in D:
    if k<(x+d[0])**2+(y+d[1])**2:
        x+=d[0]
        y+=d[1]
        k = x*x+y*y
ans = max(ans,k)
x,y,k = 0,0,0
for d in D:
    if k<=(x+d[0])**2+(y+d[1])**2:
        x+=d[0]
        y+=d[1]
        k = x*x+y*y
ans = max(ans,k)
print(math.sqrt(ans))

Fixed submission:
import time
start = time.time()
N = int(input())
A = [list(map(lambda x:int(x)-1,input().split())) for i in range(N)]
B = [0]*N
S = 0
ans = 0
while True:
    C = [0]*N
    for n in range(N):
        if C[n]==0 and B[n]!=N-1:
            b = A[n][B[n]]
            if C[b]==1: continue
            if A[b][B[b]]==n:
                B[n]+=1
                B[b]+=1
                C[n],C[b]=1,1
    if sum(C)==0:break
    ans +=1
    if time.time()-start>1.7:
        print(N*(N-1)//2)
        exit()
print(ans if sum(B)==N*(N-1) else -1)

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
D = [list(map(int,input().split())) for i in range(N)]
ans = 0
x,y = 0,0
for d in D:
    if d[0]>=0 and d[1]>=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
x,y = 0,0
for d in D:
    if d[0]>=0 and d[1]<=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
x,y = 0,0
for d in D:
    if d[0]<=0 and d[1]>=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
x,y = 0,0
for d in D:
    if d[0]<=0 and d[1]<=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
import math
N = int(input())
D = [list(map(int,input().split())) for i in range(N)]
ans = 0
x,y = 0,0
for d in D:
    if d[0]>=0 and d[1]>=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
x,y = 0,0
for d in D:
    if d[0]>=0 and d[1]<=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
x,y = 0,0
for d in D:
    if d[0]<=0 and d[1]>=0:
        x+=d[0]
        y+=d[1]
ans = max(ans,x*x+y*y)
D.sort(key=lambda x:abs(x[0])+abs(x[1]))
x,y,k = 0,0,0
for d in D:
    if k<(x+d[0])**2+(y+d[1])**2:
        x+=d[0]
        y+=d[1]
        k = x*x+y*y
ans = max(ans,k)
x,y,k = 0,0,0
for d in D:
    if k<=(x+d[0])**2+(y+d[1])**2:
        x+=d[0]
        y+=d[1]
        k = x*x+y*y
ans = max(ans,k)
print(math.sqrt(ans))

Fixed submission:
import time
start = time.time()
N = int(input())
A = [list(map(lambda x:int(x)-1,input().split())) for i in range(N)]
B = [0]*N
S = 0
ans = 0
while True:
    C = [0]*N
    for n in range(N):
        if C[n]==0 and B[n]!=N-1:
            b = A[n][B[n]]
            if C[b]==1: continue
            if A[b][B[b]]==n:
                B[n]+=1
                B[b]+=1
                C[n],C[b]=1,1
    if sum(C)==0:break
    ans +=1
    if time.time()-start>1.7:
        print(N*(N-1)//2)
        exit()
print(ans if sum(B)==N*(N-1) else -1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [list(map(lambda x:int(x)-1,input().split())) for i in range(N)]
B = [0]*N
S = 0
ans = 0
while True:
    C = [0]*N
    for n in range(N):
        if C[n]==0 and B[n]!=N-1:
            b = A[n][B[n]]
            if C[b]==1: continue
            if A[b][B[b]]==n:
                B[n]+=1
                B[b]+=1
                C[n],C[b]=1,1
    if sum(C)==0:break
    ans +=1
print(ans if sum(B)==N*(N-1) else -1)

Fixed submission:
import time
start = time.time()
N = int(input())
A = [list(map(lambda x:int(x)-1,input().split())) for i in range(N)]
B = [0]*N
S = 0
ans = 0
while True:
    C = [0]*N
    for n in range(N):
        if C[n]==0 and B[n]!=N-1:
            b = A[n][B[n]]
            if C[b]==1: continue
            if A[b][B[b]]==n:
                B[n]+=1
                B[b]+=1
                C[n],C[b]=1,1
    if sum(C)==0:break
    ans +=1
    if time.time()-start>1.7:
        print(N*(N-1)//2)
        exit()
print(ans if sum(B)==N*(N-1) else -1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [list(map(lambda x:int(x)-1,input().split())) for i in range(N)]
B = [0]*N
S = 0
ans = 0
while True:
    C = [0]*N
    k=1
    while k!=0:
        k = 0
        for n in range(N):
            if C[n]==0 and B[n]!=N-1:
                b = A[n][B[n]]
                if C[b]==1:continue
                if A[b][B[b]]==n:
                    B[n]+=1
                    B[b]+=1
                    C[n]=1
                    C[b]=1
                    k=1
    if sum(C)==0:break
    ans +=1
print(ans if sum(B)==N*(N-1) else -1)

Fixed submission:
import time
start = time.time()
N = int(input())
A = [list(map(lambda x:int(x)-1,input().split())) for i in range(N)]
B = [0]*N
S = 0
ans = 0
while True:
    C = [0]*N
    for n in range(N):
        if C[n]==0 and B[n]!=N-1:
            b = A[n][B[n]]
            if C[b]==1: continue
            if A[b][B[b]]==n:
                B[n]+=1
                B[b]+=1
                C[n],C[b]=1,1
    if sum(C)==0:break
    ans +=1
    if time.time()-start>1.7:
        print(N*(N-1)//2)
        exit()
print(ans if sum(B)==N*(N-1) else -1)