Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
s = list(list(map(int, input().split())) for _ in range(Q))

mx = 0
a = [1]*10

for s1 in range(1, M+1):
    a[0] = s1
    for s2 in range(s1, M+1):
        a[1] = s2
        for s3 in range(s2, M+1):
            a[2] = s3
            for s4 in range(s3, M+1):
                a[3] = s4
                for s5 in range(s4, M+1):
                    a[4] = s5
                    for s6 in range(s5, M+1):
                        a[5] = s6
                        for s7 in range(s6, M+1):
                            a[6] = s7
                            for s8 in range(s7, M+1):
                                a[7] = s8
                                for s9 in range(s8, M+1):
                                    a[8] = s9
                                    for s10 in range(s9, M+1):
                                        a[9] = s10
                                        
                                        cnt = 0
                                        for i in range(Q):
                                            si = s[i]
                                            if a[si[1]] - a[si[0]] == si[2]:
                                                cnt += si[3]
                                            mx = max(mx, cnt)
                                            
print(mx)

Fixed submission:
N, M, Q = map(int, input().split())
s = list(list(map(int, input().split())) for _ in range(Q))

mx = 0
a = [1]*10

for s1 in range(1, M+1):
    a[0] = s1
    for s2 in range(s1, M+1):
        a[1] = s2
        for s3 in range(s2, M+1):
            a[2] = s3
            for s4 in range(s3, M+1):
                a[3] = s4
                for s5 in range(s4, M+1):
                    a[4] = s5
                    for s6 in range(s5, M+1):
                        a[5] = s6
                        for s7 in range(s6, M+1):
                            a[6] = s7
                            for s8 in range(s7, M+1):
                                a[7] = s8
                                for s9 in range(s8, M+1):
                                    a[8] = s9
                                    for s10 in range(s9, M+1):
                                        a[9] = s10
                                        
                                        cnt = 0
                                        for i in range(Q):
                                            si = s[i]
                                            if a[si[1]-1] - a[si[0]-1] == si[2]:
                                                cnt += si[3]
                                            mx = max(mx, cnt)
                                            
print(mx)

Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
s = list(list(map(int, input().split())) for _ in range(Q))

mx = 0
a = [1]*10

for s1 in range(1, M+1):
    a[0] = s1
    for s2 in range(s1, M+1):
        a[1] = s2
        for s3 in range(s2, M+1):
            a[2] = s3
            for s4 in range(s3, M+1):
                a[3] = s4
                for s5 in range(s4, M+1):
                    a[4] = s5
                    for s6 in range(s5, M+1):
                        a[5] = s6
                        for s7 in range(s6, M+1):
                            a[6] = s7
                            for s8 in range(s7, M+1):
                                a[7] = s8
                                for s9 in range(s8, M+1):
                                    a[8] = s9
                                    for s10 in range(s9, M+1):
                                        a[9] = s10
                                        
                                        cnt = 0
                                        for i in range(Q):
                                            si = s[i]
                                            if a[si[1]] - a[si[0]] == si[2]:
                                                cnt += si[3]
                                            mx = max(mx, cnt)
                                            
print(mx)

Fixed submission:
N, M, Q = map(int, input().split())
s = list(list(map(int, input().split())) for _ in range(Q))

mx = 0
a = [1]*10

for s1 in range(1, M+1):
    a[0] = s1
    for s2 in range(s1, M+1):
        a[1] = s2
        for s3 in range(s2, M+1):
            a[2] = s3
            for s4 in range(s3, M+1):
                a[3] = s4
                for s5 in range(s4, M+1):
                    a[4] = s5
                    for s6 in range(s5, M+1):
                        a[5] = s6
                        for s7 in range(s6, M+1):
                            a[6] = s7
                            for s8 in range(s7, M+1):
                                a[7] = s8
                                for s9 in range(s8, M+1):
                                    a[8] = s9
                                    for s10 in range(s9, M+1):
                                        a[9] = s10
                                        
                                        cnt = 0
                                        for i in range(Q):
                                            si = s[i]
                                            if a[si[1]-1] - a[si[0]-1] == si[2]:
                                                cnt += si[3]
                                            mx = max(mx, cnt)
                                            
print(mx)