eolymp
bolt
Try our new interface for solving problems
Problems

Martian Plates

Martian Plates

In a martian restaurant, there is a choice of \textbf{n} dishes, and a holiday dinner consists of \textbf{l} dishes. Some of the dishes could appear more than once at the holiday dinner, while some other ones could never appear. During the dinner, plates are placed one above another. The waiter sometimes brings next dishes or takes the empty plates away. However, an empty plate could not be taken away until all the plates from the next delivered dishes are also taken away. Moreover, for some ordered pairs of dishes there is a Martian custom: first of these dishes can not be brought while the plate from the second dish stands on the table; such pairs are called uncommon. Let's call a time-table of the waiter the order of bringing dishes and taking away plates. Thus, there are \textbf{2l} items in a time-table. Your task will be to count how many different time-tables exist for a holiday dinner of l dishes modulo \textbf{p}. \InputFile The first line of input contains \textbf{p} (\textbf{2} ≤ \textbf{p} ≤ \textbf{10^4}), \textbf{t} (\textbf{1} ≤ \textbf{t} ≤ \textbf{200}) which is the number of items in a time table, \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{10}) which is the number of dishes at the restaurant and \textbf{m} (\textbf{1} ≤ \textbf{m} ≤ \textbf{100}) --- the number of uncommon pairs. The next \textbf{m} lines each contain an ordered pair of numbers \textbf{i} and \textbf{j} which means that the dish \textbf{j} could not be brought while the plate from the dish \textbf{i} stands on the table. Note that the number \textbf{t} is even. \OutputFile Output the number of different time-tables modulo \textbf{p}.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
10000 4 1 0
Output example #1
2
Author Dmitry Gozman
Source Dmitry Gozman Contest 1, Petrozavodsk training camp, January 2007