n, m, l = gets.split.map(&:to_i)

subjects = Array.new(5).map { [] }
m.times do
    d, a, k, t = gets.split.map(&:to_i)
    subjects[d] << [(2**k-1) << (a-1), t]
end

def f(a, x, i, k)
    return 0 if k == 0
    return 0 if i >= a.size
    b, t = a[i]
    if x & b == 0
        r1 = t + f(a, x | b, i + 1, k - 1)
        r2 = f(a, x, i + 1, k)
        return r1 > r2 ? r1 : r2
    else
        return f(a, x, i + 1, k)
    end
end

m = Array.new(5).map { Array.new(n+1, 0) }
(0..4).each do |i|
    (1..n).each do |j|
        m[i][j] = f(subjects[i], 0, 0, j)
    end
end

ans = 0
(0..n).to_a.repeated_permutation(5) do |s|
    next if s.inject(:+) > l
    x = s.map.with_index {|k, i| m[i][k]}.inject(:+)
    ans = x if ans < x
end
p ans

