跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F2518. Coin Troubles

    ID: 2524 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划提高难度共享题库Codeforces英文题面题目来源题面语言

Coin Troubles

题目描述

C. Coin Troubles
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In the Isle of Guernsey there are n different types of coins. For each i (1≤in), coin of type i is worth ai cents. It is possible that ai=aj for some i and j (ij).

Bessie has some set of these coins totaling t cents. She tells Jessie q pairs of integers. For each i (1≤iq), the pair bi,ci tells Jessie that Bessie has a strictly greater number of coins of type bi than coins of type ci. It is known that all bi are distinct and all ci are distinct.

Help Jessie find the number of possible combinations of coins Bessie could have. Two combinations are considered different if there is some i (1≤in), such that the number of coins Bessie has of type i is different in the two combinations. Since the answer can be very large, output it modulo 1000000007 (109+7).

If there are no possible combinations of coins totaling t cents that satisfy Bessie's conditions, output 0.

Input

The first line contains three space-separated integers, n,q and t (1≤n≤300;0≤qn;1≤t≤105). The second line contains n space separated integers, a1,a2,...,an (1≤ai≤105). The next q lines each contain two distinct space-separated integers, bi and ci (1≤bi,cin;bici).

It's guaranteed that all bi are distinct and all ci are distinct.

Output

A single integer, the number of valid coin combinations that Bessie could have, modulo 1000000007 (109+7).

Examples
Input
4 2 17
3 1 2 5
4 2
3 4
Output
3
Input
3 2 6
3 1 1
1 2
2 3
Output
0
Input
3 2 10
1 2 3
1 2
2 1
Output
0
Note

For the first sample, the following 3 combinations give a total of 17 cents and satisfy the given conditions: {0oftype1,1oftype2,3oftype3,2oftype4},{0,0,6,1},{2,0,3,1}.

No other combinations exist. Note that even though 4 occurs in both bi and ci, the problem conditions are still satisfied because all bi are distinct and all ci are distinct.


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 2160 题。保留原作者与原赛事署名。