Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np

from itertools import combinations_with_replacement as CwR



n, m, q = map(int, input().split())
Lis = [[int(e) for e in input().split()] for _ in range(q)]

Tables = list(CwR(range(1,M+1),N))
Sum_cor = []
for Table in Tables:
    d_sum = 0
    for l in Lis:
        if Table[l[1]-1]-Table[l[0]-1] == l[2]:
            d_sum+=l[3]
    Sum_cor.append(d_sum)


print(max(Sum_cor))


Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np

from itertools import combinations_with_replacement as CwR



n, m, q = map(int, input().split())
Lis = [[int(e) for e in input().split()] for _ in range(q)]

Tables = list(CwR(range(1,m+1),n))
Sum_cor = []
for Table in Tables:
    d_sum = 0
    for l in Lis:
        if Table[l[1]-1]-Table[l[0]-1] == l[2]:
            d_sum+=l[3]
    Sum_cor.append(d_sum)

print(max(Sum_cor))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np
import time


def make_table(n, m):
    Table = np.random.randint(1,m+1)
    return Table

t0 = time.time()
n, m, q = map(int, input().split())
Lis = [[int(e) for e in input().split()] for _ in range(q)]

Sum_cor = []
for i in range(10000000000):
    Table = make_table(n,m)
    Table.sort()
    d_sum = 0
    for l in Lis:
        if Table[l[1]-1]-Table[l[0]-1] == l[2]:
            d_sum+=l[3]
    Sum_cor.append(d_sum)
    t1 = time.time()
    if t1-t0 >1.88:
        print(max(Sum_cor))
        break


Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np

from itertools import combinations_with_replacement as CwR



n, m, q = map(int, input().split())
Lis = [[int(e) for e in input().split()] for _ in range(q)]

Tables = list(CwR(range(1,m+1),n))
Sum_cor = []
for Table in Tables:
    d_sum = 0
    for l in Lis:
        if Table[l[1]-1]-Table[l[0]-1] == l[2]:
            d_sum+=l[3]
    Sum_cor.append(d_sum)

print(max(Sum_cor))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np
import time


def make_table(n, m):
    Table = np.random.randint(1,m+1)
    return Table

t0 = time.time()
n, m, q = map(int, input().split())
Lis = [[int(e) for e in input().split()] for _ in range(q)]

Sum_cor = []
for i in range(10000000000):
    if m >=6:
        Table = make_table(n,m)
    else:
        Table = make_table(n,m)
    Table.sort()
    d_sum = 0
    for l in Lis:
        if Table[l[1]-1]-Table[l[0]-1] == l[2]:
            d_sum+=l[3]
    Sum_cor.append(d_sum)
    t1 = time.time()
    if t1-t0 >1.9:
        print(max(Sum_cor))
        print(i)
        break


Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np

from itertools import combinations_with_replacement as CwR



n, m, q = map(int, input().split())
Lis = [[int(e) for e in input().split()] for _ in range(q)]

Tables = list(CwR(range(1,m+1),n))
Sum_cor = []
for Table in Tables:
    d_sum = 0
    for l in Lis:
        if Table[l[1]-1]-Table[l[0]-1] == l[2]:
            d_sum+=l[3]
    Sum_cor.append(d_sum)

print(max(Sum_cor))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np
import time


def make_table(n, m):
    Table = np.random.randint(1,m+1)
    return Table

t0 = time.time()
n, m, q = map(int, input().split())
Lis = [[int(e) for e in input().split()] for _ in range(q)]

Sum_cor = []
for i in range(10000000000):
    if m >=6:
        Table = make_table(n,m)
    else:
        Table = make_table(n,m)
    Table.sort()
    d_sum = 0
    for l in Lis:
        if Table[l[1]-1]-Table[l[0]-1] == l[2]:
            d_sum+=l[3]
    Sum_cor.append(d_sum)
    t1 = time.time()
    if t1-t0 >1.9:
        print(max(Sum_cor))
        print(i)
        break


Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np

from itertools import combinations_with_replacement as CwR



n, m, q = map(int, input().split())
Lis = [[int(e) for e in input().split()] for _ in range(q)]

Tables = list(CwR(range(1,m+1),n))
Sum_cor = []
for Table in Tables:
    d_sum = 0
    for l in Lis:
        if Table[l[1]-1]-Table[l[0]-1] == l[2]:
            d_sum+=l[3]
    Sum_cor.append(d_sum)

print(max(Sum_cor))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import numpy as np
import time



"""
def make_table_min(n, m):
    Table = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    c = 10
    for i in range(n):
        rem = np.random.randint(1,m+1)
        Table.remove(rem)
    return Table

"""

def make_table(n, m):
    Table = [None]*n
    for i in range(n):
        rem = np.random.randint(1,m+1)
        Table[i] = rem
    return Table

t0 = time.time()
n, m, q = map(int, input().split())
Lis = [[int(e) for e in input().split()] for _ in range(q)]

Sum_cor = []
for i in range(10000000000):
    if m >=6:
        Table = make_table(n,m)
    else:
        Table = make_table(n,m)
    Table.sort()
    d_sum = 0
    for l in Lis:
        if Table[l[1]-1]-Table[l[0]-1] == l[2]:
            d_sum+=l[3]
    Sum_cor.append(d_sum)
    t1 = time.time()
    if t1-t0 >1.9:
        print(max(Sum_cor))
        break


Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np

from itertools import combinations_with_replacement as CwR



n, m, q = map(int, input().split())
Lis = [[int(e) for e in input().split()] for _ in range(q)]

Tables = list(CwR(range(1,m+1),n))
Sum_cor = []
for Table in Tables:
    d_sum = 0
    for l in Lis:
        if Table[l[1]-1]-Table[l[0]-1] == l[2]:
            d_sum+=l[3]
    Sum_cor.append(d_sum)

print(max(Sum_cor))