harbor run -t openthoughts/tasktrove-nemotron-gym-competitive-coding-comp-coding-96ead3a6f8ee.tar.gzharbor download openthoughts/tasktrove-nemotron-gym-competitive-coding-comp-coding-96ead3a6f8ee.tar.gzYou are solving a competitive programming problem. Read the problem below and write a Python 3 solution at /app/solution.py.
The verifier will run python3 /app/solution.py once per test case, feeding each test's input on stdin and comparing your stdout against the expected output (trailing whitespace ignored). All test cases must match.
You are a helpful and harmless assistant. You should think step-by-step before responding to the instruction below.
Please use python programming language only.
You must use ```python for just the final solution code block with the following format:
# Your code here
In the country N, there are n cities connected by m one-way roads. Although this country seems unremarkable, there are two interesting facts about it. At first, a week lasts d days here. At second, there is exactly one museum in each city of the country N.
Travel agency "Open museums" is developing a new program for tourists interested in museums. Agency's employees know which days each of the museums is open. The tour should start in the capital — the city number 1, and the first day of the tour must be on the first day of a week. Each day a tourist will be in some city, watching the exposition in its museum (in case museum is open today), and by the end of the day, the tour either ends or the tourist goes into another city connected by a road with the current one. The road system of N is designed in such a way that traveling by a road always takes one night and also all the roads are one-way. It's allowed to visit a city multiple times during the trip.
You should develop such route for the trip that the number of distinct museums, possible to visit during it, is maximum.
Input
The first line contains three integers n, m and d (1 ≤ n ≤ 100 000, 0 ≤ m ≤ 100 000, 1 ≤ d ≤ 50), the number of cities, the number of roads and the number of days in a week.
Each of next m lines contains two integers u_i and v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i), denoting a one-way road from the city u_i to the city v_i.
The next n lines contain the museums' schedule. The schedule of the museum located in the i-th city is described in the i-th of these lines. Each line consists of exactly d characters "0" or "1", the j-th character of the string equals to "1" if the museum is open at the j-th day of a week, and "0", otherwise.
It's guaranteed that for each pair of cities (u, v) there exists no more than one road leading from u to v.
Output
Print a single integer — the maximum number of distinct museums, that it's possible to visit, starting a trip in the first city on the first day of the week.
Examples
Input
4 5 3 3 1 1 2 2 4 4 1 2 3 011 110 111 001
Output
3
Input
3 3 7 1 2 1 3 2 3 1111111 0000000 0111111
Output
2
Note
Explanation of the first example
The maximum number of distinct museums to visit is 3. It's possible to visit 3 museums, for example, in the way described below.
Explanation of the second example
The maximum number of distinct museums to visit is 2. It's possible to visit 2 museums, for example, in the way described below.