#P4950. Perfect Number Sum
Perfect Number Sum
Perfect Number Sum
Given two sets of digits \(S\) and \(T\) (each digit is between 0 and 9), a number is called a perfect number if its decimal representation:
- Contains every digit in \(S\) at least once, and
- Does not contain any digit from \(T\).
In other words, for a number \(N\) with decimal representation \(d_1d_2\ldots d_k\), it is perfect if and only if \[ \forall d \in S,\; \exists i, \; d_i = d \quad \text{and} \quad \forall d \in T,\; \forall i, \; d_i \neq d. \]
You are given two integers \(l\) and \(r\) (with \(l \le r\)) defining a range \([l, r]\). Compute the sum of all perfect numbers within the range \([l, r]\).
inputFormat
The input consists of multiple lines:
- The first line contains two integers \(l\) and \(r\) defining the range \([l, r]\).
- The second line contains an integer \(m\), which is the number of digits in set \(S\).
- The third line contains \(m\) space-separated digits (each between 0 and 9) representing the set \(S\).
- The fourth line contains an integer \(n\), which is the number of digits in set \(T\).
- The fifth line contains \(n\) space-separated digits (each between 0 and 9) representing the set \(T\).
outputFormat
Output a single integer which is the sum of all perfect numbers in the range \([l, r]\).
sample
100 500
3
1 3 4
2
7 8
1776