Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import itertools
from itertools import combinations_with_replacement
if __name__ == "__main__":
    # 入力パターン．
    # 先に要素数Nが与えられて，その数読み込むパターン
    ### N
    ### x_1, y_1
    ### ...
    ### x_N, y_N
    N, M, Q = map(int, input().split())
    data = np.array([list(map(int, input().split())) for _ in range(Q)])
    #print(data)
    # A = data[:, 0]
    # B = data[:, 1]
    # C = data[:, 2]
    # D = data[:, 3]
    #print("B {}".format(len(B.shape)))

    # 1, 2, ..., M から重複を許してN個取り出す（ソート済み）
    arr = combinations_with_replacement(range(1, M+1), N)
    ans = 0
    for a in arr:
        #print(a)
        s = 0
        for i in range(Q):
            if a[data[i, 1]-1] - a[data[i, 0]-1] == data[i, 2]:
                s += data[i, 3]
        if s > ans:
            ans = s
    print(ans)





Fixed submission:
import numpy as np
import itertools
from itertools import combinations_with_replacement
if __name__ == "__main__":
    N, M, Q = map(int, input().split())
    #data = np.array([list(map(int, input().split())) for _ in range(Q)])
    data = [list(map(int, input().split())) for _ in range(Q)]
    #print(data)
    # A = data[:, 0]
    # B = data[:, 1]
    # C = data[:, 2]
    # D = data[:, 3]
    #print("B {}".format(len(B.shape)))

    # 1, 2, ..., M から重複を許してN個取り出す（ソート済み）
    arr = combinations_with_replacement(range(1, M+1), N)
    ans = 0
    for a in arr:
        #print(a)
        s = 0
        # for i in range(Q):
        #     if a[data[i, 1]-1] - a[data[i, 0]-1] == data[i, 2]:
        #         s += data[i, 3]
        for d in data:
            if a[d[1]-1] - a[d[0]-1] == d[2]:
                s += d[3] 

        if s > ans:
            ans = s
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import itertools
from itertools import combinations_with_replacement
if __name__ == "__main__":
    # 入力パターン．
    # 先に要素数Nが与えられて，その数読み込むパターン
    ### N
    ### x_1, y_1
    ### ...
    ### x_N, y_N
    N, M, Q = map(int, input().split())
    data = np.array([list(map(int, input().split())) for _ in range(Q)])
    #print(data)
    # A = data[:, 0]
    # B = data[:, 1]
    # C = data[:, 2]
    # D = data[:, 3]
    #print("B {}".format(len(B.shape)))

    # 1, 2, ..., M から重複を許してN個取り出す（ソート済み）
    arr = list(combinations_with_replacement(range(1, M+1), N))
    ans = 0
    for a in arr:
        #print(a)
        s = 0
        for i in range(Q):
            if a[data[i, 1]-1] - a[data[i, 0]-1] == data[i, 2]:
                s += data[i, 3]
        if s > ans:
            ans = s
    print(ans)





Fixed submission:
import numpy as np
import itertools
from itertools import combinations_with_replacement
if __name__ == "__main__":
    N, M, Q = map(int, input().split())
    #data = np.array([list(map(int, input().split())) for _ in range(Q)])
    data = [list(map(int, input().split())) for _ in range(Q)]
    #print(data)
    # A = data[:, 0]
    # B = data[:, 1]
    # C = data[:, 2]
    # D = data[:, 3]
    #print("B {}".format(len(B.shape)))

    # 1, 2, ..., M から重複を許してN個取り出す（ソート済み）
    arr = combinations_with_replacement(range(1, M+1), N)
    ans = 0
    for a in arr:
        #print(a)
        s = 0
        # for i in range(Q):
        #     if a[data[i, 1]-1] - a[data[i, 0]-1] == data[i, 2]:
        #         s += data[i, 3]
        for d in data:
            if a[d[1]-1] - a[d[0]-1] == d[2]:
                s += d[3] 

        if s > ans:
            ans = s
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import itertools
from itertools import combinations_with_replacement
if __name__ == "__main__":
    # 入力パターン．
    # 先に要素数Nが与えられて，その数読み込むパターン
    ### N
    ### x_1, y_1
    ### ...
    ### x_N, y_N
    N, M, Q = map(int, input().split())
    data = np.array([list(map(int, input().split())) for _ in range(Q)])
    #print(data)
    A = data[:, 0]
    B = data[:, 1]
    C = data[:, 2]
    D = data[:, 3]
    #print("B {}".format(len(B.shape)))

    # 1, 2, ..., M から重複を許してN個取り出す（ソート済み）
    arr = list(combinations_with_replacement(range(1, M+1), N))
    ans = 0
    for a in arr:
        #print(a)
        s = 0
        for i in range(Q):
            t = a[B[i]-1]
            t = a[A[i]-1]
            t =C[i]
            if a[B[i]-1] - a[A[i]-1] == C[i]:
                s += D[i]
        if s > ans:
            ans = s
    print(ans)





Fixed submission:
import numpy as np
import itertools
from itertools import combinations_with_replacement
if __name__ == "__main__":
    N, M, Q = map(int, input().split())
    #data = np.array([list(map(int, input().split())) for _ in range(Q)])
    data = [list(map(int, input().split())) for _ in range(Q)]
    #print(data)
    # A = data[:, 0]
    # B = data[:, 1]
    # C = data[:, 2]
    # D = data[:, 3]
    #print("B {}".format(len(B.shape)))

    # 1, 2, ..., M から重複を許してN個取り出す（ソート済み）
    arr = combinations_with_replacement(range(1, M+1), N)
    ans = 0
    for a in arr:
        #print(a)
        s = 0
        # for i in range(Q):
        #     if a[data[i, 1]-1] - a[data[i, 0]-1] == data[i, 2]:
        #         s += data[i, 3]
        for d in data:
            if a[d[1]-1] - a[d[0]-1] == d[2]:
                s += d[3] 

        if s > ans:
            ans = s
    print(ans)