@staticmethod
def d():
    (n, m, p, q, r, *xyz) = map(int, sys.stdin.read().split())
    (x, y, z) = np.array(xyz).reshape(r, 3).T
    h = np.zeros((n, m), dtype=np.int32)
    h[((x - 1), (y - 1))] = z
    g = np.array([*itertools.combinations(range(n), p)])
    print(np.sort(h[g].sum(axis=1), axis=1)[:, (- q):].sum(axis=1).max())
@staticmethod
def d():
    (n, m, p, q, r, *xyz) = map(int, sys.stdin.read().split())
    (x, y, z) = np.array(xyz).reshape(r, 3).T
    h = np.zeros((n, m), dtype=np.int32)
    h[((x - 1), (y - 1))] = z
    g = np.array([*itertools.combinations(range(n), p)])
    print(np.sort(h[g].sum(axis=1), axis=1)[:, (- q):].sum(axis=1).max())