CF1137C Museums Tour

Description

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 Format

N/A

Output Format

N/A

Explanation/Hint

Explanation of the first example ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1137C/9d008f66e7d2d111750670e65c727c30f94415a7.png)The maximum number of distinct museums to visit is $ 3 $ . It's possible to visit $ 3 $ museums, for example, in the way described below. - Day 1. Now it's the 1st day of a week, and the tourist is in the city $ 1 $ . The museum there is closed. At night the tourist goes to the city number $ 2 $ . - Day 2. Now it's the 2nd day of a week, and the tourist is in the city $ 2 $ . The museum there is open, and the tourist visits it. At night the tourist goes to the city number $ 4 $ . - Day 3. Now it's the 3rd day of a week, and the tourist is in the city $ 4 $ . The museum there is open, and the tourist visits it. At night the tourist goes to the city number $ 1 $ . - Day 4. Now it's the 1st day of a week, and the tourist is in the city $ 1 $ . The museum there is closed. At night the tourist goes to the city number $ 2 $ . - Day 5. Now it's the 2nd of a week number $ 2 $ , and the tourist is in the city $ 2 $ . The museum there is open, but the tourist has already visited it. At night the tourist goes to the city number $ 3 $ . - Day 6. Now it's the 3rd day of a week, and the tourist is in the city $ 3 $ . The museum there is open, and the tourist visits it. After this, the tour is over. Explanation of the second example ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1137C/346bf7493bfcf794d81bdea90bfca6fa51eea6b2.png)The maximum number of distinct museums to visit is $ 2 $ . It's possible to visit $ 2 $ museums, for example, in the way described below. - Day 1. Now it's the 1st day of a week, and the tourist is in the city $ 1 $ . The museum there is open, and the tourist visits it. At night the tourist goes to the city number $ 2 $ . - Day 2. Now it's the 2nd day of a week, and the tourist is in the city $ 2 $ . The museum there is closed. At night the tourist goes to the city number $ 3 $ . - Day 3. Now it's the 3rd day of a week, and the tourist is in the city $ 3 $ . The museum there is open, and the tourist visits it. After this, the tour is over.