n, h, w = gets.split.map(&:to_i)
@arr = Array.new(n) {
    r, c, a = gets.split.map(&:to_i)
    {:number => a, :row => r - 1, :column => c - 1}
}
@arr.sort_by! {|item| item[:number]}.reverse!
@available_row = Array.new(n, true)
@available_column = Array.new(n, true)
def solve(idx)
    if idx >= @arr.size then
        return 0
    end
    item = @arr[idx]
    if @available_row[item[:row]] then
        if @available_column[item[:column]] then
            @available_row[item[:row]] = false
            sum1 = solve(idx + 1)
            @available_row[item[:row]] = true
            @available_column[item[:column]] = false
            sum2 = solve(idx + 1)
            @available_column[item[:column]] = true
            return item[:number] + (sum1 >= sum2 ? sum1 : sum2)
        else
            @available_row[item[:row]] = false
            sum = solve(idx + 1)
            @available_row[item[:row]] = true
            return item[:number] + sum
        end
    else
        if @available_column[item[:column]] then
            @available_column[item[:column]] = false
            sum = solve(idx + 1)
            @available_column[item[:column]] = true
            return item[:number] + sum
        else
            return solve(idx + 1)
        end
    end
end
puts solve(0)
