This is an easier version of the problem. In this version, $$$n \le 6$$$.Marek is working hard on creating strong testcases to his new algorithmic problem. You want to know what it is? Nah, we're not telling you. However, we can tell you how he generates the testcases.Marek chooses an integer $$$n$$$ and $$$n^2$$$ integers $$$p_{ij}$$$ ($$$1 \le i \le n$$$, $$$1 \le j \le n$$$). He then generates a random bipartite graph with $$$2n$$$ vertices. There are $$$n$$$ vertices on the left side: $$$\ell_1, \ell_2, \dots, \ell_n$$$, and $$$n$$$ vertices on the right side: $$$r_1, r_2, \dots, r_n$$$. For each $$$i$$$ and $$$j$$$, he puts an edge between vertices $$$\ell_i$$$ and $$$r_j$$$ with probability $$$p_{ij}$$$ percent.It turns out that the tests will be strong only if a perfect matching exists in the generated graph. What is the probability that this will occur?It can be shown that this value can be represented as $$$\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \not\equiv 0 \pmod{10^9+7}$$$. Let $$$Q^{-1}$$$ be an integer for which $$$Q \cdot Q^{-1} \equiv 1 \pmod{10^9+7}$$$. Print the value of $$$P \cdot Q^{-1}$$$ modulo $$$10^9+7$$$.

NoteIn the first sample test, each of the $$$16$$$ graphs below is equally probable. Out of these, $$$7$$$ have a perfect matching:  Therefore, the probability is equal to $$$\frac{7}{16}$$$. As $$$16 \cdot 562\,500\,004 = 1 \pmod{10^9+7}$$$, the answer to the testcase is $$$7 \cdot 562\,500\,004 \mod{(10^9+7)} = 937\,500\,007$$$.

The first line of the input contains a single integer $$$n$$$ ($$$\mathbf{1 \le n \le 6}$$$). The following $$$n$$$ lines describe the probabilities of each edge appearing in the graph. The $$$i$$$-th of the lines contains $$$n$$$ integers $$$p_{i1}, p_{i2}, \dots, p_{in}$$$ ($$$0 \le p_{ij} \le 100$$$); $$$p_{ij}$$$ denotes the probability, in percent, of an edge appearing between $$$\ell_i$$$ and $$$r_j$$$.

Print a single integer — the probability that the perfect matching exists in the bipartite graph, written as $$$P \cdot Q^{-1} \pmod{10^9+7}$$$ for $$$P$$$, $$$Q$$$ defined above.

Input:
2
50 50
50 50

Output: 937500007

Input:
3
3 1 4
1 5 9
2 6 5

Output: 351284554

Input:
1
0

Output: 0

Input:
1
100

Output: 1

Input:
1
69

Output: 330000003

Input:
4
0 100 0 100
100 0 100 0
0 100 0 100
100 0 100 0

Output: 1

Input:
2
95 61
53 99

Output: 5751951

Input:
3
26 55 1
44 2 83
9 79 71

Output: 452769275

Input:
4
25 49 16 56
41 31 89 78
50 3 80 96
93 12 67 57

Output: 986898331

Input:
5
58 42 65 0 12
80 0 11 64 89
21 92 11 12 10
88 50 94 5 31
2 53 82 90 21

Output: 224596377

Input:
6
91 2 13 12 50 27
13 44 43 40 62 53
98 13 55 52 93 12
84 11 8 89 90 31
62 95 79 16 10 12
89 22 95 4 23 16

Output: 458013830

Input:
6
100 0 0 0 0 0
0 0 100 0 0 0
0 0 0 100 0 0
0 0 0 100 0 0
0 0 0 0 0 100
0 0 0 100 100 100

Output: 0

Input:
5
7 34 34 12 16
28 8 15 70 11
20 26 36 5 23
12 55 82 63 41
12 53 54 32 46

Output: 188514656

Input:
6
58 7 34 10 24 28
26 21 20 10 28 36
34 75 9 3 25 3
9 33 54 7 16 70
31 62 15 7 17 32
32 82 37 66 32 24

Output: 265772640

Input:
6
86 47 4 5 9 26
63 99 17 38 15 0
30 22 0 37 19 75
16 4 19 31 27 17
57 1 61 1 55 36
21 3 3 4 4 0

Output: 596541516

Input:
6
55 82 77 53 91 98
94 92 62 34 82 69
97 33 39 93 90 86
79 79 64 75 94 52
78 92 70 92 42 88
73 71 91 21 87 72

Output: 829000907

Input:
5
67 43 91 100 62
96 100 51 65 96
68 86 58 56 81
96 93 89 78 74
76 70 58 91 93

Output: 789815481

Input:
4
96 87 74 37
52 59 97 18
93 82 70 94
54 60 23 59

Output: 794990212

Input:
6
69 85 49 90 88 86
77 96 13 42 51 68
68 92 85 68 87 45
66 47 92 78 100 96
66 70 47 24 73 78
44 62 66 84 17 96

Output: 710967466

Input:
5
48 17 41 3 8
9 51 32 31 56
58 25 38 95 10
27 36 13 7 46
44 40 18 74 22

Output: 867818040

Input:
6
17 14 22 5 45 68
47 29 19 60 6 13
8 42 48 7 67 20
36 31 40 21 41 27
51 3 56 43 12 33
15 28 65 59 39 18

Output: 91887121

Input:
6
87 56 53 27 22 24
29 66 60 37 61 94
79 32 85 64 36 95
58 52 42 99 62 21
41 83 88 73 6 8
33 20 28 25 92 5

Output: 110718409

Input:
6
1 1 1 1 1 1
0 1 1 0 1 0
0 1 1 0 1 0
1 1 1 1 1 1
0 1 1 0 1 0
0 1 1 0 1 0

Output: 0

Input:
6
87 48 67 31 76 91
56 97 66 54 79 61
99 59 85 81 50 92
89 72 64 96 14 88
90 71 75 78 98 83
30 35 93 82 69 43

Output: 584631181

Input:
5
100 100 0 100 0
0 0 0 0 0
0 100 100 0 100
100 100 0 100 0
0 100 0 0 0

Output: 0

Input:
6
0 100 0 0 0 0
0 100 0 100 0 0
0 100 0 0 0 0
0 0 0 0 100 0
0 0 0 100 0 100
0 0 0 0 0 0

Output: 0

Input:
6
0 0 0 100 100 100
100 100 0 100 0 0
0 0 0 100 0 0
0 0 0 100 0 100
0 100 0 0 100 0
0 0 0 0 0 0

Output: 0

Input:
6
100 0 0 100 0 0
0 0 100 0 100 100
100 0 0 0 0 0
0 0 0 0 100 100
100 100 0 100 0 0
100 0 0 100 0 100

Output: 1


While playing with geometric figures Alex has accidentally invented a concept of a $$$n$$$-th order rhombus in a cell grid.A $$$1$$$-st order rhombus is just a square $$$1 \times 1$$$ (i.e just a cell).A $$$n$$$-th order rhombus for all $$$n \geq 2$$$ one obtains from a $$$n-1$$$-th order rhombus adding all cells which have a common side with it to it (look at the picture to understand it better).    Alex asks you to compute the number of cells in a $$$n$$$-th order rhombus.

NoteImages of rhombus corresponding to the examples are given in the statement.

The first and only input line contains integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — order of a rhombus whose numbers of cells should be computed.

Print exactly one integer — the number of cells in a $$$n$$$-th order rhombus.


You have a given integer $$$n$$$. Find the number of ways to fill all $$$3 \times n$$$ tiles with the shape described in the picture below. Upon filling, no empty spaces are allowed. Shapes cannot overlap.  This picture describes when $$$n = 4$$$. The left one is the shape and the right one is $$$3 \times n$$$ tiles.

NoteIn the first example, there are $$$4$$$ possible cases of filling.In the second example, you cannot fill the shapes in $$$3 \times 1$$$ tiles.

The only line contains one integer $$$n$$$ ($$$1 \le n \le 60$$$) — the length.


Polycarp knows that if the sum of the digits of a number is divisible by $$$3$$$, then the number itself is divisible by $$$3$$$. He assumes that the numbers, the sum of the digits of which is divisible by $$$4$$$, are also somewhat interesting. Thus, he considers a positive integer $$$n$$$ interesting if its sum of digits is divisible by $$$4$$$.Help Polycarp find the nearest larger or equal interesting number for the given number $$$a$$$. That is, find the interesting number $$$n$$$ such that $$$n \ge a$$$ and $$$n$$$ is minimal.

The only line in the input contains an integer $$$a$$$ ($$$1 \le a \le 1000$$$).

Print the nearest greater or equal interesting number for the given number $$$a$$$. In other words, print the interesting number $$$n$$$ such that $$$n \ge a$$$ and $$$n$$$ is minimal.


The only difference between the easy and the hard versions is constraints.A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between them. For example, for the string "abaca" the following strings are subsequences: "abaca", "aba", "aaa", "a" and "" (empty string). But the following strings are not subsequences: "aabaca", "cb" and "bcaa".You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.In one move you can take any subsequence $$$t$$$ of the given string and add it to the set $$$S$$$. The set $$$S$$$ can't contain duplicates. This move costs $$$n - |t|$$$, where $$$|t|$$$ is the length of the added subsequence (i.e. the price equals to the number of the deleted characters).Your task is to find out the minimum possible total cost to obtain a set $$$S$$$ of size $$$k$$$ or report that it is impossible to do so.

NoteIn the first example we can generate $$$S$$$ = { "asdf", "asd", "adf", "asf", "sdf" }. The cost of the first element in $$$S$$$ is $$$0$$$ and the cost of the others is $$$1$$$. So the total cost of $$$S$$$ is $$$4$$$.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 100$$$) — the length of the string and the size of the set, correspondingly. The second line of the input contains a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.

Print one integer — if it is impossible to obtain the set $$$S$$$ of size $$$k$$$, print -1. Otherwise, print the minimum possible total cost to do it.

Input:
4 5
asdf

Output: 4

Input:
5 6
aaaaa

Output: 15

Input:
5 7
aaaaa

Output: -1

Input:
10 100
ajihiushda

Output: 233

Input:
1 2
u

Output: 1

Input:
1 5
w

Output: -1

Input:
1 10
s

Output: -1

Input:
1 25
o

Output: -1

Input:
1 50
s

Output: -1

Input:
1 100
p

Output: -1

Input:
5 2
ufdpx

Output: 1

Input:
5 5
wnxcc

Output: 4

Input:
5 10
bzitq

Output: 13

Input:
5 25
wjsel

Output: 52

Input:
5 50
bhhaj

Output: -1

Input:
5 100
nvyoj

Output: -1

Input:
10 2
mllbxoykle

Output: 1

Input:
10 5
nrdmcxnnbb

Output: 4

Input:
10 10
hittmcsvmo

Output: 9

Input:
10 25
bpehfvamul

Output: 38

Input:
10 50
fpsafelqno

Output: 88

Input:
10 100
wfykkiubdk

Output: 242

Input:
25 2
vwxvqvouhtbprdhrhlhotyqjp

Output: 1

Input:
25 5
xcrhvdevynotmxzxqafeijadl

Output: 4

Input:
25 10
quomusasazkywxnfvfjimiytg

Output: 9

Input:
25 25
mdxynjiiivwifvaspplpkoffc

Output: 27

Input:
25 50
qbntoutmcylbrtfzauvxmqvyn

Output: 73

Input:
25 100
iasrasqpntslqjkefyzbklmtr

Output: 173

Input:
50 2
vjrvahvokiudpiocpvoqsqhukavyrckhcbctrbprqxizcofrfr

Output: 1

Input:
50 5
xplfeoiobchekdeiwkmgkbunixgcyzngznoicllobsqbpkbwnp

Output: 4

Input:
50 10
dnovfytvosvwbeykfnkkebgonntfqapbuphspjsclowovrgrae

Output: 9

Input:
50 25
axxjyqblymjgkciyzwnochociulhtdsabhrdtfldmtugmlsbwu

Output: 24

Input:
50 50
dxldyzmsrrwzwaofkcxwehgvtrsximxgdqrhjthkgfucrjdvwl

Output: 49

Input:
50 100
bybehmveefoqvsronaztdwjzhfspmoszgibthctsamgixqailz

Output: 149

Input:
100 2
zqdvwjzmgfmgngaxzgvuuukxyfzecafuflxpkvemenkorwhmnsxuoxsatlymyjugwjmutfxcksnwhxrwruyqbouyflxhwqhflczz

Output: 1

Input:
100 5
ayvharmmxcxhibqfixtjmhurxchhkvhubxjcveajrkssbsbrxpijxolrtmvanzyybzbdpgzocicakipmkpxhcjtegksbvabfghpf

Output: 4

Input:
100 10
maorgdrrnhytzrswsuomkdkdrqyqmwcdekbkgymqaqnacrbbbvwqzcqsdboztxygqjxsqwhjnftiguhemxhvvrnjwpdvbjexhlqt

Output: 9

Input:
100 25
ihxdcuahvemeipfkmdqqiktqnyrsrxfdmclwmvgretjsulnlxlvcuvjxxvnmrhjlerhvrzfdvxehnvgslrjzvbscfehtsxvvcabq

Output: 24

Input:
100 50
mhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxcgcxjdloyicqkfwulytkpiflkrsdjseynwohymlehmtgswjfxzp

Output: 49

Input:
100 100
oaxflkpcwimoiocbudbxgzvekmengbumbcumwxjjcdtqzlijdqoelpevcqfiommjgioxaxdrhbyoszifgxjfprraisgzpxrjhyln

Output: 101

Input:
100 1
yyojtyktazyfegvnnsexxiosqxdlpdwlyojsghpvjpavnvjvttbylqcdabyhleltltzalmgoelxdalcbjejsjxnfebzsxusnujdy

Output: 0

Input:
7 100
asdfgha

Output: 299

Input:
7 100
asdagha

Output: 309

Input:
7 100
asafgsa

Output: 319

Input:
7 86
djfjfdj

Output: 273

Input:
7 87
djfjfdj

Output: -1

Input:
6 50
fdjfjd

Output: 139

Input:
6 49
fdjfjd

Output: 133

Input:
6 51
fdjfjd

Output: -1

Input:
10 1023
hsjztkorpv

Output: 5110

Input:
10 992
lzgbtqybar

Output: 4912

Input:
10 889
ltwnwdluhx

Output: -1

Input:
20 688037
ttwnmquescldhxwdzxdi

Output: 6756991

Input:
20 1019648
alhmijcknryfkeurtcqk

Output: 10129664

Input:
20 999409
bfxajupatylfrczbfsgi

Output: -1

Input:
30 363904895
fwhadwbsskiitjkuwupbrsobdttmqz

Output: 5380084386

Input:
30 642235040
qxkzwaiqbtffqogfkznyjfcshyjoao

Output: 9468426224

Input:
30 656341937
qrzlwlvhfatfwmlpvndtgrxyphfjnn

Output: -1

Input:
40 550188209247
sxspwbifsqgndvxlrrdxwyvwygtvyiusxiyjgnuz

Output: 10734053749240

Input:
40 313915447382
fjljjtmxouncvyrsawkkflkzarwolwkuznyqtnnk

Output: 6160842348859

Input:
40 739620532705
fdawkecoubadbyxcmkahawfhiapgvwvdhjklxaec

Output: -1

Input:
100 1000
ojlksfclwvhxhyhddsosbkwxgpbhnvdgtvvcvrajpiimqsqlxicqyehwsiqcbzqzdxsfbtlldefawclzezvbpwiomvkneibmwtfw

Output: 1902

Input:
100 10000
xxprqtlnkqpurdilqdjnnmpsloumhbxymxmzplcwuyfexardpwodnhhkktipqcfwudbivaehhmqexffzgkpztmwrpzzzoudypoqe

Output: 25621

Input:
100 1000000
pjsakcxuoyyivmfmzuqafyqvcmvmjqitckfnixurgmdshuejptqvrwomnalijputhnylyqesycwjvxflneuwyecyiaxwahlougoa

Output: 3833346

Input:
100 1000000000
gaoxttalzmmhfhjphaftcwnnhjotuyxcnzlhqoynmcfhhmpzumichrghshdmbtjxmkwegnajkbtfhglkhnapizhltzxgfhyxyvfc

Output: 5936118201

Input:
100 1000000000000
djgykfqaywhkhpocyxcpvbiiouyielmighclnuopadzuvrirbecucwnzwahahagvfstbxxaednajfauscxwttiglbbxtomnnalcl

Output: 8854753825335

Input:
40 1000000000000
azipixmkcmxyzsyxerzggtjbfknpebgtwggrhyuu

Output: -1

Input:
50 1000000000000
fltdysjwwsfhuklxnzfesrnmvdinquktuaaqduxyacvdsgxshy

Output: 13601148116701

Input:
45 1000000000000
sakuacuunmcmnrqewlpukirumntsygulpywneaaipboho

Output: 15850182637674

Input:
41 1000000000000
xfubvojhogeggntkezhpbigfqbdkdnzxueylitqxr

Output: 19636604785323

Input:
100 100
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Output: 4950

Input:
30 60
aaaaaaaaaaaaaaaaaaaaaaaaaaaaab

Output: 900

Input:
50 60
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab

Output: 900

Input:
100 20
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Output: 190

Input:
100 100
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab

Output: 2500

Input:
30 30
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Output: 435

Input:
82 100
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Output: -1

Input:
98 100
abaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Output: 453

Input:
100 100
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbb

Output: 850

Input:
50 100
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Output: -1


The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!Heidi designed a series of increasingly difficult tasks for them to spend their time on, which would allow the Doctor enough time to save innocent lives!The funny part is that these tasks would be very easy for a human to solve.The first task is as follows. There are some points on the plane. All but one of them are on the boundary of an axis-aligned square (its sides are parallel to the axes). Identify that point.

NoteIn both examples, the square has four sides $$$x=0$$$, $$$x=2$$$, $$$y=0$$$, $$$y=2$$$.

The first line contains an integer $$$n$$$ ($$$2 \le n \le 10$$$). Each of the following $$$4n + 1$$$ lines contains two integers $$$x_i, y_i$$$ ($$$0 \leq x_i, y_i \leq 50$$$), describing the coordinates of the next point. It is guaranteed that there are at least $$$n$$$ points on each side of the square and all $$$4n + 1$$$ points are distinct.

Print two integers — the coordinates of the point that is not on the boundary of the square.

Input:
2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2

Output: 1 1

Input:
2
0 0
0 1
0 2
0 3
1 0
1 2
2 0
2 1
2 2

Output: 0 3

Input:
2
5 14
5 17
25 43
26 43
32 41
33 0
38 0
48 17
48 30

Output: 32 41

Input:
2
17 44
19 14
19 25
24 27
32 1
34 27
38 1
45 5
45 12

Output: 17 44

Input:
2
1 2
1 27
1 45
10 45
28 48
38 1
44 1
45 7
45 26

Output: 28 48

Input:
2
2 27
2 40
9 44
10 13
12 1
22 44
26 13
33 22
33 36

Output: 12 1

Input:
2
0 30
0 33
18 1
21 1
31 47
42 50
49 16
49 21
49 50

Output: 31 47

Input:
3
1 3
1 18
1 41
4 43
12 1
21 50
27 1
27 50
33 1
34 50
50 6
50 7
50 26

Output: 4 43

Input:
3
8 18
8 25
8 31
13 43
14 43
24 11
33 43
34 11
37 11
40 21
40 28
40 35
44 38

Output: 44 38

Input:
3
9 8
23 15
23 19
23 23
27 30
31 30
37 30
38 6
39 6
47 6
47 16
47 21
47 25

Output: 9 8

Input:
3
10 9
10 39
10 40
21 2
26 40
28 40
41 38
43 2
45 2
46 40
48 4
48 11
48 33

Output: 41 38

Input:
3
8 7
8 26
8 27
14 32
15 7
16 32
17 7
18 32
24 36
31 7
33 12
33 16
33 28

Output: 24 36

Input:
4
22 8
22 9
22 14
22 26
22 32
25 30
30 5
30 30
32 30
34 30
39 5
41 5
47 5
47 11
47 20
47 23
47 25

Output: 22 32

Input:
4
5 15
5 19
5 28
5 46
9 6
14 49
22 6
27 6
27 49
29 23
32 6
37 49
45 49
48 21
48 33
48 34
48 48

Output: 29 23

Input:
4
3 7
3 17
3 18
3 22
8 2
10 32
15 32
18 2
21 25
22 2
28 32
29 2
29 32
33 14
33 18
33 21
33 26

Output: 21 25

Input:
4
0 41
1 11
1 17
1 21
1 40
10 47
19 3
19 47
27 3
28 3
35 3
36 47
42 47
45 4
45 24
45 27
45 41

Output: 0 41

Input:
4
3 0
10 24
10 36
10 38
10 47
11 19
18 50
22 50
23 19
28 19
29 50
33 50
35 19
41 21
41 25
41 45
41 47

Output: 3 0

Input:
5
7 3
7 8
7 18
7 24
7 29
7 35
8 35
9 3
14 35
18 35
22 35
26 3
26 13
34 3
34 35
39 3
39 5
39 9
39 10
39 20
39 26

Output: 26 13

Input:
5
0 4
0 35
0 36
0 42
0 43
2 50
3 50
5 0
20 0
21 50
23 5
24 0
28 0
32 0
38 50
42 50
50 3
50 34
50 37
50 38
50 44

Output: 23 5

Input:
5
7 20
7 23
7 30
7 32
7 43
9 47
14 10
15 47
18 10
26 47
27 10
28 29
29 10
38 47
41 10
44 10
44 20
44 39
44 41
44 45
44 47

Output: 28 29

Input:
5
3 23
3 32
3 33
3 34
3 35
4 41
6 11
6 41
9 41
11 21
13 21
17 21
17 41
18 21
21 21
21 41
23 23
23 30
23 33
23 38
23 39

Output: 6 11

Input:
5
3 10
3 18
3 24
3 27
3 42
4 7
8 45
8 48
9 7
11 45
21 7
21 45
28 7
29 7
31 45
39 45
41 7
41 21
41 25
41 28
41 36

Output: 8 48

Input:
6
9 19
9 23
9 26
9 28
9 30
9 35
10 39
16 19
17 19
20 39
21 19
21 39
25 19
25 39
26 19
27 39
28 19
28 39
29 22
29 24
29 27
29 31
29 32
29 36
49 23

Output: 49 23

Input:
6
2 17
2 22
2 23
2 29
2 36
2 42
3 9
3 43
4 43
6 9
7 43
8 9
11 9
23 43
24 43
24 47
25 9
29 43
34 9
36 10
36 13
36 20
36 26
36 27
36 32

Output: 24 47

Input:
6
21 7
21 12
21 16
21 19
21 24
21 25
21 28
24 28
27 7
29 7
34 7
35 7
35 28
37 28
40 7
41 28
42 7
42 8
42 10
42 11
42 21
42 22
42 24
42 28
44 49

Output: 44 49

Input:
6
1 14
1 16
1 18
1 19
1 31
1 39
5 14
7 14
7 49
9 37
9 49
10 14
14 14
15 14
21 49
22 14
25 49
27 49
31 49
36 26
36 30
36 31
36 36
36 41
36 44

Output: 9 37

Input:
6
11 15
20 10
20 13
20 14
20 16
20 27
20 28
22 32
24 6
25 6
27 32
30 32
34 32
35 6
36 6
39 6
39 32
43 6
43 32
46 7
46 12
46 18
46 22
46 27
46 31

Output: 11 15

Input:
7
14 11
14 12
14 15
14 18
14 22
14 31
14 37
16 11
16 20
17 11
17 38
18 11
22 38
25 11
25 38
27 11
30 38
31 38
35 11
37 11
37 38
38 38
41 11
41 18
41 21
41 25
41 26
41 31
41 37

Output: 16 20

Input:
7
4 1
4 5
4 9
4 25
4 26
4 37
4 40
4 41
5 1
9 1
14 1
15 42
17 42
20 42
22 1
25 1
28 42
30 42
37 42
38 33
40 1
41 42
45 6
45 12
45 30
45 32
45 34
45 35
45 40

Output: 38 33

Input:
7
7 15
7 17
7 22
7 24
7 26
7 30
7 36
9 8
11 8
13 8
18 36
19 8
20 8
20 36
25 36
28 8
29 36
31 8
32 36
33 36
35 9
35 11
35 18
35 20
35 24
35 25
35 31
35 36
50 32

Output: 50 32

Input:
7
2 7
2 11
2 12
2 16
2 22
2 30
2 39
9 50
11 50
12 4
13 50
16 4
17 4
18 32
22 4
23 4
27 50
28 4
28 50
36 50
40 4
40 50
48 10
48 14
48 17
48 20
48 32
48 37
48 42

Output: 18 32

Input:
7
9 5
9 10
9 13
9 14
9 17
9 19
9 22
12 2
14 35
16 2
17 2
20 35
22 34
25 2
25 35
30 2
31 2
31 35
34 35
39 2
39 35
41 35
42 16
42 20
42 25
42 27
42 28
42 30
42 35

Output: 22 34

Input:
8
3 3
15 16
15 17
15 20
15 23
15 27
15 28
15 42
15 48
16 49
20 16
21 16
21 49
23 49
27 16
30 49
31 16
32 16
32 49
35 16
35 49
43 16
46 16
47 49
48 16
48 20
48 26
48 31
48 34
48 37
48 39
48 48
48 49

Output: 3 3

Input:
8
0 11
0 26
0 28
0 35
0 37
0 44
0 46
0 47
1 3
3 50
7 3
8 50
9 50
10 50
13 3
18 3
18 50
19 50
26 3
28 37
33 50
34 3
44 50
45 3
47 3
47 12
47 15
47 16
47 17
47 18
47 33
47 45
47 50

Output: 28 37

Input:
8
14 10
14 14
14 23
14 30
14 31
14 34
14 35
14 38
15 27
16 10
18 44
19 44
22 44
23 44
24 44
25 10
26 44
28 10
30 10
31 10
38 44
39 10
40 10
43 10
47 44
48 11
48 17
48 22
48 30
48 35
48 36
48 43
48 44

Output: 15 27

Input:
8
15 29
28 26
28 28
28 29
28 33
28 37
28 39
28 40
28 41
30 23
30 44
31 44
33 23
33 44
34 44
36 23
37 23
37 44
39 23
40 23
40 44
42 44
44 44
45 23
47 23
49 23
49 25
49 30
49 34
49 36
49 41
49 42
49 44

Output: 15 29

Input:
8
1 0
1 2
1 19
1 29
1 30
1 35
1 38
1 39
3 39
8 0
12 39
14 39
15 0
19 39
20 0
24 24
24 39
25 0
26 0
28 39
29 39
30 0
33 0
34 39
36 0
40 0
40 9
40 17
40 19
40 24
40 25
40 31
40 39

Output: 24 24

Input:
9
7 1
7 5
7 8
7 16
7 22
7 28
7 29
7 30
7 37
7 40
11 41
15 1
20 41
22 1
23 1
23 27
26 41
28 41
29 1
29 41
31 41
32 1
33 41
35 41
43 1
44 1
44 41
47 1
47 2
47 5
47 6
47 9
47 22
47 23
47 29
47 31
47 37

Output: 23 27

Input:
9
25 6
25 7
25 8
25 12
25 16
25 17
25 18
25 25
25 26
27 6
28 29
30 29
31 6
31 29
32 6
34 6
36 6
36 29
37 6
38 29
39 6
40 29
40 37
42 6
42 29
44 29
46 29
48 6
48 7
48 9
48 11
48 12
48 14
48 21
48 24
48 28
48 29

Output: 40 37

Input:
9
0 5
0 15
0 16
0 17
0 25
0 32
0 33
0 38
0 45
1 1
4 1
4 46
10 1
14 46
17 46
18 46
19 1
21 1
21 46
22 1
22 46
33 46
34 1
35 1
38 46
40 1
43 46
44 4
45 2
45 4
45 5
45 11
45 19
45 21
45 27
45 44
45 45

Output: 44 4

Input:
9
0 13
0 16
0 22
0 25
0 27
0 33
0 34
0 38
0 39
0 40
2 41
3 41
4 13
5 41
7 41
8 13
9 13
12 13
13 13
14 13
16 41
18 41
22 41
24 41
26 13
27 13
27 41
28 20
28 22
28 25
28 30
28 31
28 32
28 36
28 37
28 39
32 33

Output: 32 33

Input:
9
0 2
0 3
0 8
0 10
0 15
0 19
0 20
0 25
0 27
1 47
3 1
5 47
7 1
7 47
8 47
9 1
9 47
11 1
20 1
22 1
23 1
29 47
30 47
31 47
32 47
36 19
39 1
44 1
46 2
46 3
46 5
46 11
46 21
46 25
46 34
46 45
46 47

Output: 36 19

Input:
10
11 11
11 12
11 15
11 17
11 18
11 19
11 28
11 33
11 38
11 40
12 11
15 46
17 11
17 46
18 46
19 11
19 46
20 11
20 46
24 46
25 46
26 11
32 11
32 46
33 11
34 46
36 11
39 11
40 46
43 11
44 0
46 14
46 15
46 17
46 22
46 26
46 28
46 32
46 43
46 45
46 46

Output: 44 0

Input:
10
4 7
4 14
4 15
4 16
4 17
4 18
4 24
4 28
4 29
4 32
6 32
7 6
7 32
9 6
11 6
12 6
12 32
14 6
14 32
17 6
17 32
19 32
20 32
21 32
22 6
23 32
24 6
26 6
28 32
29 6
30 9
30 10
30 11
30 12
30 18
30 21
30 28
30 29
30 30
30 31
38 42

Output: 38 42

Input:
10
8 1
8 2
8 7
8 12
8 14
8 17
8 18
8 22
8 26
8 29
8 30
9 1
9 41
11 41
12 22
14 1
14 41
25 1
26 41
29 1
31 1
33 41
38 41
41 1
41 41
42 1
42 41
44 1
44 41
46 1
48 4
48 14
48 17
48 21
48 27
48 31
48 32
48 37
48 38
48 39
48 41

Output: 12 22

Input:
10
0 17
0 24
0 28
0 30
0 32
0 33
0 36
0 39
0 42
0 43
4 16
7 16
8 43
9 16
10 16
10 43
12 16
12 43
15 43
16 16
17 16
19 43
21 16
22 43
23 16
23 43
25 16
25 43
26 43
27 21
27 26
27 27
27 28
27 31
27 33
27 34
27 36
27 40
27 42
27 43
30 33

Output: 30 33

Input:
10
0 2
0 5
0 6
0 15
0 20
0 33
0 34
0 40
0 41
0 46
6 44
9 2
11 47
13 2
15 2
16 47
18 2
19 47
22 47
23 2
26 2
26 47
28 2
29 2
30 47
31 47
39 2
40 47
42 47
43 2
43 47
45 2
45 7
45 9
45 13
45 14
45 15
45 20
45 40
45 41
45 44

Output: 6 44


Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions $$$a$$$, $$$b$$$ and $$$c$$$ respectively. At the end of the performance, the distance between each pair of ropewalkers was at least $$$d$$$.Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by $$$1$$$ (i. e. shift by $$$1$$$ to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can "walk past each other".You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to $$$d$$$.Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.

NoteIn the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position $$$8$$$), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be $$$|5 - 2| = 3$$$, the distance between Boniface and Konrad will be $$$|2 - 8| = 6$$$ and the distance between Agafon and Konrad will be $$$|5 - 8| = 3$$$. Therefore, all three pairwise distances will be at least $$$d=3$$$, so the performance could be finished within 2 seconds.

The only line of the input contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$1 \le a, b, c, d \le 10^9$$$). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.

Output one integer — the minimum duration (in seconds) of the performance.

Input: 5 2 6 3

Output: 2

Input: 3 1 5 6

Output: 8

Input: 8 3 3 2

Output: 2

Input: 2 3 10 4

Output: 3

Input: 1000000000 1000000000 1000000000 1000000000

Output: 2000000000

Input: 500000000 250000000 750000000 1000000000

Output: 1500000000

Input: 1 3 2 5

Output: 8

Input: 2 3 1 6

Output: 10

Input: 9 6 2 5

Output: 3

Input: 1 1 1 1

Output: 2

Input: 1 1 500 10

Output: 10

Input: 500 1 500 1000

Output: 1501

Input: 1 2 1 1

Output: 1

Input: 89 983 751 1000

Output: 1106

Input: 716270982 22102638 553198855 1000000000

Output: 1305831656

Input: 1000000000 1 1000000000 999999999

Output: 999999999

Input: 999999999 1 1 1000000000

Output: 1000000002

Input: 1 2 3 4

Output: 6

Input: 1 3 4 5

Output: 7

Input: 1 3 2 6

Output: 10

Input: 2 2 3 4

Output: 7

Input: 1 1 4 5

Output: 7

Input: 5 5 2 6

Output: 9

Input: 1 3 3 6

Output: 10

Input: 1 4 4 6

Output: 9

Input: 1 3 3 5

Output: 8

Input: 1 4 4 5

Output: 7

Input: 1000000000 1000000000 1000000000 1

Output: 2

Input: 2 1 1 3

Output: 5

Input: 3 2 2 3

Output: 5

Input: 5 5 4 1

Output: 1

Input: 3 1 4 2

Output: 1

Input: 5 4 2 3

Output: 3

Input: 3 2 1 4

Output: 6

Input: 3 2 3 5

Output: 9

Input: 1 3 4 6

Output: 9

Input: 3 1 2 7

Output: 12

Input: 1 5 4 8

Output: 12

Input: 1 4 3 9

Output: 15

Input: 5 3 4 10

Output: 18

Input: 3 5 8 1

Output: 0

Input: 1 1 2 100

Output: 199

Input: 5 5 7 5

Output: 8

Input: 1 5 10 3

Output: 0

Input: 1 2 9 5

Output: 4

Input: 2 4 7 6

Output: 7

Input: 1 1 1 1000000000

Output: 2000000000

Input: 1 500000000 1000000000 1000000000

Output: 1000000001

Input: 15 15 15 15

Output: 30


The only difference between easy and hard versions is constraints.A session has begun at Beland State University. Many students are taking exams.Polygraph Poligrafovich is going to examine a group of $$$n$$$ students. Students will take the exam one-by-one in order from $$$1$$$-th to $$$n$$$-th. Rules of the exam are following:  The $$$i$$$-th student randomly chooses a ticket.  if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.  if the student finds the ticket easy, he spends exactly $$$t_i$$$ minutes to pass the exam. After it, he immediately gets a mark and goes home. Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.The duration of the whole exam for all students is $$$M$$$ minutes ($$$\max t_i \le M$$$), so students at the end of the list have a greater possibility to run out of time to pass the exam.For each student $$$i$$$, you should count the minimum possible number of students who need to fail the exam so the $$$i$$$-th student has enough time to pass the exam.For each student $$$i$$$, find the answer independently. That is, if when finding the answer for the student $$$i_1$$$ some student $$$j$$$ should leave, then while finding the answer for $$$i_2$$$ ($$$i_2>i_1$$$) the student $$$j$$$ student does not have to go home.

NoteThe explanation for the example 1.Please note that the sum of the first five exam times does not exceed $$$M=15$$$ (the sum is $$$1+2+3+4+5=15$$$). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are $$$0$$$.In order for the $$$6$$$-th student to pass the exam, it is necessary that at least $$$2$$$ students must fail it before (for example, the $$$3$$$-rd and $$$4$$$-th, then the $$$6$$$-th will finish its exam in $$$1+2+5+6=14$$$ minutes, which does not exceed $$$M$$$).In order for the $$$7$$$-th student to pass the exam, it is necessary that at least $$$3$$$ students must fail it before (for example, the $$$2$$$-nd, $$$5$$$-th and $$$6$$$-th, then the $$$7$$$-th will finish its exam in $$$1+3+4+7=15$$$ minutes, which does not exceed $$$M$$$).

The first line of the input contains two integers $$$n$$$ and $$$M$$$ ($$$1 \le n \le 100$$$, $$$1 \le M \le 100$$$) — the number of students and the total duration of the exam in minutes, respectively. The second line of the input contains $$$n$$$ integers $$$t_i$$$ ($$$1 \le t_i \le 100$$$) — time in minutes that $$$i$$$-th student spends to answer to a ticket. It's guaranteed that all values of $$$t_i$$$ are not greater than $$$M$$$.

Print $$$n$$$ numbers: the $$$i$$$-th number must be equal to the minimum number of students who have to leave the exam in order to $$$i$$$-th student has enough time to pass the exam.

Input:
7 15
1 2 3 4 5 6 7

Output: 0 0 0 0 0 2 3

Input:
5 100
80 40 40 40 60

Output: 0 1 1 2 3

Input:
1 1
1

Output: 0

Input:
1 100
99

Output: 0

Input:
1 100
100

Output: 0

Input:
2 100
100 100

Output: 0 1

Input:
2 100
1 100

Output: 0 1

Input:
2 100
1 99

Output: 0 0

Input:
3 100
34 34 34

Output: 0 0 1

Input:
10 50
9 9 9 9 9 9 9 9 9 9

Output: 0 0 0 0 0 1 2 3 4 5

Input:
10 50
10 10 10 10 10 10 10 10 10 10

Output: 0 0 0 0 0 1 2 3 4 5

Input:
8 2
1 1 1 1 1 1 1 1

Output: 0 0 1 2 3 4 5 6

Input:
9 14
3 4 3 9 1 1 9 8 9

Output: 0 0 0 2 1 1 3 4 5

Input:
100 100
55 70 81 73 51 6 75 45 85 33 61 98 63 11 59 1 8 14 28 78 74 44 80 7 69 7 5 90 73 43 78 64 64 43 92 59 70 80 19 33 39 31 70 38 85 24 23 86 79 98 56 92 63 92 4 36 8 79 74 2 81 54 13 69 44 49 63 17 76 78 99 42 36 47 71 19 90 9 58 83 53 27 2 35 51 65 59 90 51 74 87 84 48 98 44 84 100 84 93 73

Output: 0 1 2 3 4 4 5 6 7 7 8 11 11 10 12 11 12 12 13 16 16 16 19 17 20 18 18 25 23 22 26 25 26 26 32 29 31 33 30 31 32 33 37 35 41 37 38 44 44 48 44 49 46 51 45 46 46 53 53 48 55 53 51 57 55 56 59 56 63 64 69 62 62 64 68 64 73 65 70 75 72 70 69 72 75 77 78 83 79 83 86 86 82 92 84 90 96 92 95 92

Input:
100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100

Output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

Input:
10 13
3 5 9 6 7 3 8 2 3 2

Output: 0 0 1 2 3 3 5 4 5 5

Input:
6 10
5 4 8 1 7 5

Output: 0 0 2 1 3 3

Input:
9 10
5 2 6 2 9 7 4 6 6

Output: 0 0 1 1 4 4 4 5 6

Input:
9 11
3 8 10 2 2 9 2 1 9

Output: 0 0 2 2 2 4 3 3 7

Input:
10 10
1 4 5 3 8 7 7 2 1 6

Output: 0 0 0 1 3 4 5 4 5 6

Input:
9 10
8 2 2 1 3 7 1 7 9

Output: 0 0 1 1 1 3 2 5 7

Input:
100 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

Input:
10 50
10 2 10 8 4 2 10 6 10 1

Output: 0 0 0 0 0 0 0 1 2 2

Input:
11 55
3 3 7 7 10 9 8 7 7 7 6

Output: 0 0 0 0 0 0 0 0 1 2 2

Input:
12 60
2 8 9 10 7 9 2 5 4 9 6 3

Output: 0 0 0 0 0 0 0 0 0 1 2 2

Input:
13 65
9 4 10 7 3 10 10 6 8 9 6 9 7

Output: 0 0 0 0 0 0 0 0 1 2 2 3 4

Input:
14 70
2 8 10 1 10 6 10 6 9 4 10 10 10 9

Output: 0 0 0 0 0 0 0 0 0 0 1 2 3 4

Input:
15 75
9 6 5 9 2 6 2 7 2 3 9 2 10 5 4

Output: 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1

Input:
16 80
8 1 4 3 10 8 2 2 3 6 3 10 3 1 5 10

Output: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Input:
17 85
1 2 10 3 10 9 1 6 6 5 9 2 10 1 3 3 7

Output: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

Input:
18 90
8 7 9 7 7 5 7 5 7 8 1 9 7 9 8 7 8 10

Output: 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5

Input:
19 95
1 9 5 5 9 8 9 6 3 7 1 1 6 7 4 4 4 2 10

Output: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

Input:
20 100
6 7 6 3 1 3 2 5 7 3 9 10 1 10 7 1 9 1 2 7

Output: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Input:
100 100
1 2 3 5 5 7 7 8 8 10 10 11 14 14 14 16 18 19 20 20 21 22 22 22 22 23 23 23 24 27 27 29 30 32 35 38 38 39 42 43 45 45 45 45 46 48 49 49 50 50 52 54 56 56 57 57 57 60 62 63 63 65 65 65 65 68 71 72 72 73 73 73 76 77 78 78 79 82 84 84 85 86 86 87 88 89 89 90 90 90 90 92 92 95 95 95 97 98 98 100

Output: 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 18 19 20 21 22 24 25 26 27 28 29 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 52 53 54 55 56 57 58 60 61 62 63 64 65 66 67 69 70 71 72 73 74 76 77 78 79 80 81 82 84 85 86 87 88 89 91 92 93 94 96 97 99

Input:
100 100
100 99 99 98 97 96 96 95 95 90 90 89 89 85 85 84 84 82 80 80 79 79 79 76 75 75 74 73 73 73 72 72 70 69 67 66 65 65 64 64 62 61 60 60 59 58 58 55 54 54 53 53 49 48 44 38 37 36 36 34 32 32 31 28 27 27 27 25 23 21 20 19 19 19 19 19 18 18 17 17 16 16 15 13 12 11 7 7 7 6 5 5 4 2 2 2 2 2 1 1

Output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 52 53 54 55 56 57 58 59 59 60 61 62 63 64 65 66 66 67 68 69 69 70 71 72 73 74 75 76 77 77 78 79 79 80 80 81 81 81 82 82 82 82 82 82 83 83 83

Input:
100 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

Input:
100 99
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

Input:
100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Input:
100 100
99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99

Output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99


The only difference between easy and hard versions is constraints.Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $$$T$$$ minutes.In the player, Polycarp stores $$$n$$$ songs, each of which is characterized by two parameters: $$$t_i$$$ and $$$g_i$$$, where $$$t_i$$$ is the length of the song in minutes ($$$1 \le t_i \le 15$$$), $$$g_i$$$ is its genre ($$$1 \le g_i \le 3$$$).Polycarp wants to create such a playlist so that he can listen to music all the time on the way from the university to his home, and at the time of his arrival home, the playlist is over. Polycarp never interrupts songs and always listens to them from beginning to end. Thus, if he started listening to the $$$i$$$-th song, he would spend exactly $$$t_i$$$ minutes on its listening. Polycarp also does not like when two songs of the same genre play in a row (i.e. successively/adjacently) or when the songs in his playlist are repeated.Help Polycarpus count the number of different sequences of songs (their order matters), the total duration is exactly $$$T$$$, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different.

NoteIn the first example, Polycarp can make any of the $$$6$$$ possible playlist by rearranging the available songs: $$$[1, 2, 3]$$$, $$$[1, 3, 2]$$$, $$$[2, 1, 3]$$$, $$$[2, 3, 1]$$$, $$$[3, 1, 2]$$$ and $$$[3, 2, 1]$$$ (indices of the songs are given).In the second example, the first and second songs cannot go in succession (since they have the same genre). Thus, Polycarp can create a playlist in one of $$$2$$$ possible ways: $$$[1, 3, 2]$$$ and $$$[2, 3, 1]$$$ (indices of the songs are given).In the third example, Polycarp can make the following playlists: $$$[1, 2, 3]$$$, $$$[1, 3, 2]$$$, $$$[2, 1, 3]$$$, $$$[2, 3, 1]$$$, $$$[3, 1, 2]$$$, $$$[3, 2, 1]$$$, $$$[1, 4]$$$, $$$[4, 1]$$$, $$$[2, 3, 4]$$$ and $$$[4, 3, 2]$$$ (indices of the songs are given).

The first line of the input contains two integers $$$n$$$ and $$$T$$$ ($$$1 \le n \le 15, 1 \le T \le 225$$$) — the number of songs in the player and the required total duration, respectively. Next, the $$$n$$$ lines contain descriptions of songs: the $$$i$$$-th line contains two integers $$$t_i$$$ and $$$g_i$$$ ($$$1 \le t_i \le 15, 1 \le g_i \le 3$$$) — the duration of the $$$i$$$-th song and its genre, respectively.

Output one integer — the number of different sequences of songs, the total length of exactly $$$T$$$, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. Since the answer may be huge, output it modulo $$$10^9 + 7$$$ (that is, the remainder when dividing the quantity by $$$10^9 + 7$$$).

Input:
3 3
1 1
1 2
1 3

Output: 6

Input:
3 3
1 1
1 1
1 3

Output: 2

Input:
4 10
5 3
2 1
3 2
5 1

Output: 10

Input:
1 1
1 1

Output: 1

Input:
1 1
1 3

Output: 1

Input:
1 2
1 2

Output: 0

Input:
1 15
15 1

Output: 1

Input:
1 225
15 1

Output: 0

Input:
2 1
1 2
1 2

Output: 2

Input:
2 1
1 1
1 1

Output: 2

Input:
2 1
3 1
2 2

Output: 0

Input:
2 2
1 3
1 3

Output: 0

Input:
2 2
1 3
1 1

Output: 2

Input:
2 2
2 3
3 3

Output: 1

Input:
2 3
1 1
1 1

Output: 0

Input:
2 3
2 2
2 3

Output: 0

Input:
2 3
2 3
2 1

Output: 0

Input:
2 4
1 3
1 2

Output: 0

Input:
15 15
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 3

Output: 420863916

Input:
2 4
1 1
2 1

Output: 0

Input:
2 5
1 1
1 3

Output: 0

Input:
15 50
9 1
14 3
6 1
10 1
5 1
7 1
6 2
13 3
7 3
3 2
4 1
14 3
2 2
8 1
5 3

Output: 683736

Input:
15 200
13 3
13 2
15 2
15 2
15 2
13 3
14 1
14 3
13 2
14 3
13 2
13 2
15 2
15 2
13 1

Output: 0

Input:
3 1
1 2
1 3
1 3

Output: 3

Input:
3 1
1 3
1 3
1 1

Output: 3

Input:
3 1
3 3
3 3
3 1

Output: 0

Input:
3 2
1 1
1 1
1 2

Output: 4

Input:
3 2
2 2
1 3
2 1

Output: 2

Input:
3 2
1 2
2 1
2 3

Output: 2

Input:
3 3
1 3
1 3
1 1

Output: 2

Input:
3 3
2 2
1 3
1 3

Output: 4

Input:
3 3
2 1
3 3
2 3

Output: 1

Input:
3 4
1 2
1 3
1 2

Output: 0

Input:
3 4
1 1
1 3
2 1

Output: 2

Input:
3 4
2 2
1 3
3 3

Output: 0

Input:
3 5
1 3
1 1
1 3

Output: 0

Input:
3 5
2 2
2 2
2 3

Output: 0

Input:
3 5
2 3
2 2
2 1

Output: 0

Input:
4 1
1 3
1 2
1 1
1 1

Output: 4

Input:
4 1
1 1
2 2
2 1
2 2

Output: 1

Input:
4 1
3 2
3 1
2 1
3 3

Output: 0

Input:
4 2
1 3
1 2
1 3
1 2

Output: 8

Input:
4 2
2 3
1 2
1 1
1 1

Output: 5

Input:
4 2
1 3
3 2
3 2
3 3

Output: 0

Input:
4 3
1 2
1 1
1 2
1 2

Output: 6

Input:
4 3
1 2
1 2
2 3
2 3

Output: 8

Input:
4 3
3 1
1 1
1 2
1 2

Output: 3

Input:
4 4
1 3
1 2
1 3
1 3

Output: 0

Input:
4 4
2 1
1 1
2 2
1 1

Output: 4

Input:
4 4
3 2
2 2
3 2
2 3

Output: 2

Input:
4 5
1 2
1 2
1 2
1 3

Output: 0

Input:
4 5
2 1
1 2
1 3
1 3

Output: 12

Input:
4 5
2 3
1 2
2 3
3 2

Output: 6

Input:
5 1
1 3
1 3
1 1
1 2
1 3

Output: 5

Input:
5 1
2 1
2 2
1 3
2 3
1 2

Output: 2

Input:
5 1
1 3
2 3
3 2
2 3
1 3

Output: 2

Input:
5 2
1 2
1 3
1 1
1 1
1 3

Output: 16

Input:
5 2
2 2
2 2
2 2
1 2
2 2

Output: 4

Input:
5 2
2 2
1 3
1 1
1 3
2 3

Output: 6

Input:
5 3
1 3
1 2
1 1
1 3
1 1

Output: 36

Input:
5 3
1 1
2 1
2 3
2 1
2 1

Output: 2

Input:
5 3
3 1
2 2
2 2
3 1
2 1

Output: 2

Input:
5 4
1 2
1 3
1 1
1 1
1 3

Output: 56

Input:
5 4
2 2
1 1
1 3
1 2
1 3

Output: 32

Input:
5 4
3 3
1 3
1 1
1 1
3 2

Output: 10

Input:
5 5
1 1
1 1
1 3
1 1
1 1

Output: 0

Input:
5 5
1 3
1 3
2 1
1 2
2 3

Output: 22

Input:
5 5
3 2
3 1
2 2
1 1
2 3

Output: 12

Input:
2 5
2 2
2 2

Output: 0

Input:
15 70
7 3
13 3
13 1
15 2
3 1
10 2
3 3
9 2
13 3
13 3
11 2
5 1
8 2
4 1
15 2

Output: 2141640

Input:
15 130
14 2
13 3
14 1
8 3
9 3
15 2
10 2
10 2
4 2
4 2
12 1
12 2
6 3
3 3
10 1

Output: 159107833

Input:
15 150
12 1
11 1
7 1
11 3
9 2
2 3
5 1
5 3
9 3
15 2
11 1
1 1
13 3
8 3
4 1

Output: 0

Input:
15 180
13 1
15 1
14 3
5 1
3 2
7 2
14 1
3 1
6 3
7 1
10 3
12 1
8 1
14 2
4 1

Output: 0

Input:
15 200
11 2
1 2
1 1
1 1
4 2
4 2
7 1
1 2
7 1
8 1
14 3
11 3
15 3
15 2
15 2

Output: 0

Input:
15 49
3 1
14 3
9 1
8 1
14 2
5 1
14 3
10 3
9 3
9 1
8 3
2 1
10 2
4 3
6 1

Output: 57996

Input:
15 225
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

Output: 0

Input:
15 15
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

Output: 0

Input:
15 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

Output: 15

Input:
15 2
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

Output: 0

Input:
15 10
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1

Output: 33868800

Input:
15 20
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1

Output: 0

Input:
15 30
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1

Output: 0

Input:
15 40
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1

Output: 0

Input:
15 50
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1

Output: 0

Input:
15 225
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1

Output: 0

Input:
15 10
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3

Output: 486518400

Input:
15 20
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3

Output: 0

Input:
15 30
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3

Output: 0

Input:
15 40
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3

Output: 0

Input:
15 50
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3

Output: 0

Input:
15 225
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3

Output: 0

Input:
15 112
15 3
15 2
13 2
12 2
12 1
15 3
13 3
15 2
15 1
14 2
14 2
14 2
15 3
13 3
14 2

Output: 1579680

Input:
15 113
15 2
13 1
12 1
12 1
14 1
13 1
15 1
12 1
13 1
12 1
15 1
15 1
15 2
12 1
14 1

Output: 0

Input:
15 114
15 2
15 3
15 3
15 1
15 1
15 1
15 2
15 1
15 2
15 3
15 2
15 1
15 1
15 1
15 3

Output: 0

Input:
15 90
14 2
15 2
15 2
14 2
15 2
14 2
15 2
14 2
15 2
15 1
15 1
14 1
14 1
14 1
15 1

Output: 720

Input:
15 78
14 2
15 2
14 2
15 1
13 1
13 1
14 1
13 1
15 1
14 1
15 1
15 1
13 2
14 1
13 2

Output: 0

Input:
15 225
14 1
14 1
15 3
15 3
15 3
15 2
14 3
15 2
14 1
14 1
14 1
14 3
14 2
14 2
14 2

Output: 0

Input:
2 5
2 3
1 3

Output: 0

Input:
15 14
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 3

Output: 733951888

Input:
15 13
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 3

Output: 306303923

Input:
15 12
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 3

Output: 126975965

Input:
15 11
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 3

Output: 758671993

Input:
15 10
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 3

Output: 486518400

Input:
15 9
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 3

Output: 112838400

Input:
15 15
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 3
1 3
1 3
1 3
1 3

Output: 203212800

Input:
15 15
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 1
1 3
1 3
1 3
1 3
1 3
1 3
1 3

Output: 66867193

Input:
15 15
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

Output: 203212800

Input:
15 15
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 3
1 3
1 3
1 3
1 3
1 3
1 3
1 3

Output: 203212800

Input:
2 4
1 3
2 3

Output: 0


Vus the Cossack holds a programming competition, in which $$$n$$$ people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly $$$m$$$ pens and $$$k$$$ notebooks.Determine whether the Cossack can reward all participants, giving each of them at least one pen and at least one notebook.

NoteIn the first example, there are $$$5$$$ participants. The Cossack has $$$8$$$ pens and $$$6$$$ notebooks. Therefore, he has enough pens and notebooks.In the second example, there are $$$3$$$ participants. The Cossack has $$$9$$$ pens and $$$3$$$ notebooks. He has more than enough pens but only the minimum needed number of notebooks.In the third example, there are $$$8$$$ participants but only $$$5$$$ pens. Since the Cossack does not have enough pens, the answer is "No".

The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \leq n, m, k \leq 100$$$) — the number of participants, the number of pens, and the number of notebooks respectively.

Print "Yes" if it possible to reward all the participants. Otherwise, print "No". You can print each letter in any case (upper or lower).

Input: 5 8 6

Output: YES

Output: yes

Output: Yes

Input: 3 9 3

Output: YES

Output: yes

Output: Yes

Input: 8 5 20

Output: No

Output: NO

Output: no

Input: 1 1 1

Output: YES

Output: yes

Output: Yes

Input: 54 82 100

Output: YES

Output: yes

Output: Yes

Input: 1 100 100

Output: YES

Output: yes

Output: Yes

Input: 100 99 99

Output: No

Output: NO

Output: no

Input: 8 20 5

Output: No

Output: NO

Output: no

Input: 68 91 90

Output: YES

Output: yes

Output: Yes

Input: 92 35 39

Output: No

Output: NO

Output: no

Input: 20 84 93

Output: YES

Output: yes

Output: Yes

Input: 44 28 47

Output: No

Output: NO

Output: no

Input: 68 73 96

Output: YES

Output: yes

Output: Yes

Input: 92 17 54

Output: No

Output: NO

Output: no

Input: 20 61 100

Output: YES

Output: yes

Output: Yes

Input: 44 2 53

Output: No

Output: NO

Output: no

Input: 68 54 3

Output: No

Output: NO

Output: no

Input: 58 92 33

Output: No

Output: NO

Output: no

Input: 2 1 2

Output: No

Output: NO

Output: no

Input: 2 2 1

Output: No

Output: NO

Output: no

Input: 2 2 2

Output: YES

Output: yes

Output: Yes

Input: 2 1 1

Output: No

Output: NO

Output: no

Input: 100 100 100

Output: YES

Output: yes

Output: Yes

Input: 100 1 1

Output: No

Output: NO

Output: no

Input: 5 3 2

Output: No

Output: NO

Output: no


The only difference between easy and hard versions is constraints.Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $$$T$$$ minutes.In the player, Polycarp stores $$$n$$$ songs, each of which is characterized by two parameters: $$$t_i$$$ and $$$g_i$$$, where $$$t_i$$$ is the length of the song in minutes ($$$1 \le t_i \le 50$$$), $$$g_i$$$ is its genre ($$$1 \le g_i \le 3$$$).Polycarp wants to create such a playlist so that he can listen to music all the time on the way from the university to his home, and at the time of his arrival home, the playlist is over. Polycarp never interrupts songs and always listens to them from beginning to end. Thus, if he started listening to the $$$i$$$-th song, he would spend exactly $$$t_i$$$ minutes on its listening. Polycarp also does not like when two songs of the same genre play in a row (i.e. successively/adjacently) or when the songs in his playlist are repeated.Help Polycarpus count the number of different sequences of songs (their order matters), the total duration is exactly $$$T$$$, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different.

The first line of the input contains two integers $$$n$$$ and $$$T$$$ ($$$1 \le n \le 50, 1 \le T \le 2500$$$) — the number of songs in the player and the required total duration, respectively. Next, the $$$n$$$ lines contain descriptions of songs: the $$$i$$$-th line contains two integers $$$t_i$$$ and $$$g_i$$$ ($$$1 \le t_i \le 50, 1 \le g_i \le 3$$$) — the duration of the $$$i$$$-th song and its genre, respectively.

Input:
3 3
1 1
1 2
1 3

Output: 6

Input:
3 3
1 1
1 1
1 3

Output: 2

Input:
4 10
5 3
2 1
3 2
5 1

Output: 10

Input:
1 1
1 1

Output: 1

Input:
1 1
1 3

Output: 1

Input:
1 2
1 2

Output: 0

Input:
1 50
50 1

Output: 1

Input:
1 2500
50 1

Output: 0

Input:
2 1
1 2
1 2

Output: 2

Input:
2 1
1 1
1 1

Output: 2

Input:
2 1
3 1
2 2

Output: 0

Input:
2 2
1 3
1 3

Output: 0

Input:
2 2
1 3
1 1

Output: 2

Input:
2 2
2 3
3 3

Output: 1

Input:
2 3
1 1
1 1

Output: 0

Input:
2 3
2 2
2 3

Output: 0

Input:
2 3
2 3
2 1

Output: 0

Input:
2 4
1 3
1 2

Output: 0

Input:
2 4
1 3
2 3

Output: 0

Input:
2 4
1 1
2 1

Output: 0

Input:
2 5
1 1
1 3

Output: 0

Input:
50 500
31 3
13 2
32 1
47 1
25 3
50 3
49 1
35 3
2 2
30 2
46 1
37 1
44 1
48 2
10 3
25 1
20 1
48 1
40 1
32 2
1 3
26 2
38 3
37 2
13 3
40 1
10 2
29 3
30 3
46 1
41 3
3 1
3 3
15 1
14 2
14 1
28 3
16 3
22 1
21 3
7 3
18 1
36 3
32 2
37 2
29 1
26 1
34 3
36 2
21 3

Output: 615116396

Input:
50 2000
48 1
49 1
49 1
49 3
49 2
50 3
48 2
48 2
50 1
50 1
49 1
49 1
49 3
50 2
50 1
50 2
50 2
48 1
48 3
48 1
50 1
49 2
49 2
49 2
48 1
48 1
48 3
49 3
50 2
48 3
48 1
50 2
48 1
48 1
50 3
48 3
48 1
50 1
49 2
48 1
50 3
49 3
49 2
48 1
49 1
48 3
49 1
48 2
48 2
49 1

Output: 432808558

Input:
3 1
1 2
1 3
1 3

Output: 3

Input:
3 1
1 3
1 3
1 1

Output: 3

Input:
3 1
3 3
3 3
3 1

Output: 0

Input:
3 2
1 1
1 1
1 2

Output: 4

Input:
3 2
2 2
1 3
2 1

Output: 2

Input:
3 2
1 2
2 1
2 3

Output: 2

Input:
3 3
1 3
1 3
1 1

Output: 2

Input:
3 3
2 2
1 3
1 3

Output: 4

Input:
3 3
2 1
3 3
2 3

Output: 1

Input:
3 4
1 2
1 3
1 2

Output: 0

Input:
3 4
1 1
1 3
2 1

Output: 2

Input:
3 4
2 2
1 3
3 3

Output: 0

Input:
3 5
1 3
1 1
1 3

Output: 0

Input:
3 5
2 2
2 2
2 3

Output: 0

Input:
3 5
2 3
2 2
2 1

Output: 0

Input:
4 1
1 3
1 2
1 1
1 1

Output: 4

Input:
4 1
1 1
2 2
2 1
2 2

Output: 1

Input:
4 1
3 2
3 1
2 1
3 3

Output: 0

Input:
4 2
1 3
1 2
1 3
1 2

Output: 8

Input:
4 2
2 3
1 2
1 1
1 1

Output: 5

Input:
4 2
1 3
3 2
3 2
3 3

Output: 0

Input:
4 3
1 2
1 1
1 2
1 2

Output: 6

Input:
4 3
1 2
1 2
2 3
2 3

Output: 8

Input:
4 3
3 1
1 1
1 2
1 2

Output: 3

Input:
4 4
1 3
1 2
1 3
1 3

Output: 0

Input:
4 4
2 1
1 1
2 2
1 1

Output: 4

Input:
4 4
3 2
2 2
3 2
2 3

Output: 2

Input:
4 5
1 2
1 2
1 2
1 3

Output: 0

Input:
4 5
2 1
1 2
1 3
1 3

Output: 12

Input:
4 5
2 3
1 2
2 3
3 2

Output: 6

Input:
5 1
1 3
1 3
1 1
1 2
1 3

Output: 5

Input:
5 1
2 1
2 2
1 3
2 3
1 2

Output: 2

Input:
5 1
1 3
2 3
3 2
2 3
1 3

Output: 2

Input:
5 2
1 2
1 3
1 1
1 1
1 3

Output: 16

Input:
5 2
2 2
2 2
2 2
1 2
2 2

Output: 4

Input:
5 2
2 2
1 3
1 1
1 3
2 3

Output: 6

Input:
5 3
1 3
1 2
1 1
1 3
1 1

Output: 36

Input:
5 3
1 1
2 1
2 3
2 1
2 1

Output: 2

Input:
5 3
3 1
2 2
2 2
3 1
2 1

Output: 2

Input:
5 4
1 2
1 3
1 1
1 1
1 3

Output: 56

Input:
5 4
2 2
1 1
1 3
1 2
1 3

Output: 32

Input:
5 4
3 3
1 3
1 1
1 1
3 2

Output: 10

Input:
5 5
1 1
1 1
1 3
1 1
1 1

Output: 0

Input:
5 5
1 3
1 3
2 1
1 2
2 3

Output: 22

Input:
5 5
3 2
3 1
2 2
1 1
2 3

Output: 12

Input:
2 5
2 2
2 2

Output: 0

Input:
50 700
31 3
28 1
37 3
16 2
5 2
34 1
37 3
30 1
46 3
20 3
15 3
9 2
36 3
26 1
12 3
3 2
37 3
8 2
19 3
30 3
29 1
11 3
7 1
19 3
48 2
23 2
7 2
45 2
32 3
10 3
27 1
7 1
19 1
5 2
16 2
7 2
33 3
25 3
20 3
22 3
18 2
45 1
21 1
35 3
1 1
40 1
48 2
8 3
12 2
25 1

Output: 690529621

Input:
50 1300
43 2
1 1
17 1
49 1
19 3
1 3
45 2
2 2
5 3
3 2
28 3
50 3
30 1
17 3
20 3
18 1
34 3
44 2
34 1
4 3
2 2
27 3
36 3
38 3
50 1
6 2
7 2
23 3
31 2
5 2
36 3
46 3
43 2
50 2
36 2
29 3
46 3
10 1
23 2
21 3
50 1
44 2
40 1
43 2
23 2
50 3
25 2
19 2
19 1
24 2

Output: 123766817

Input:
50 1500
47 2
16 1
26 3
14 1
2 3
27 3
33 2
1 1
45 3
46 1
47 3
14 1
23 3
50 2
14 2
1 1
6 3
3 2
9 1
2 1
14 1
12 3
5 3
28 1
27 1
34 3
45 2
5 2
29 3
24 1
18 3
12 2
17 3
40 3
37 1
13 2
43 1
23 1
21 1
30 3
7 1
22 2
22 2
35 1
49 2
19 3
1 3
43 3
3 2
28 2

Output: 0

Input:
50 1800
4 1
30 2
22 1
43 2
21 1
10 2
44 3
6 2
7 2
37 1
29 1
39 1
36 1
3 1
30 2
24 3
28 3
39 1
29 3
38 3
19 3
36 2
43 3
28 1
26 2
48 1
37 2
19 1
36 2
50 3
27 1
2 2
17 2
29 3
34 2
4 2
11 3
41 3
27 3
28 3
2 3
30 1
33 1
41 2
47 2
40 2
29 3
26 2
21 2
48 1

Output: 0

Input:
50 2100
8 1
28 3
17 2
30 3
39 1
15 1
13 1
17 2
16 1
5 1
14 3
2 2
23 2
39 1
19 1
39 3
14 1
20 1
1 3
22 1
15 3
29 3
17 1
15 1
41 1
46 1
27 1
27 2
16 1
48 3
16 1
18 3
10 1
32 2
21 3
20 2
22 1
20 3
48 2
21 2
16 2
29 2
10 3
5 2
24 1
48 1
18 2
7 1
17 1
8 2

Output: 0

Input:
50 2500
15 3
4 1
42 2
6 2
9 2
34 1
39 2
49 2
50 2
45 2
9 2
38 2
45 1
5 1
7 1
8 2
45 2
39 1
13 2
9 1
13 3
3 2
9 2
37 3
4 2
49 2
7 1
28 2
25 1
31 3
15 1
39 1
46 3
12 3
24 2
38 1
27 3
45 1
6 1
19 3
30 1
23 1
35 3
45 1
22 2
35 1
9 3
6 3
27 2
1 1

Output: 0

Input:
50 2500
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

Output: 0

Input:
50 50
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

Output: 0

Input:
50 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

Output: 50

Input:
50 2
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

Output: 0

Input:
50 10
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2

Output: 550150928

Input:
50 20
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2

Output: 618317190

Input:
50 30
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2

Output: 496037523

Input:
50 40
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2

Output: 617287847

Input:
50 50
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2

Output: 944934584

Input:
50 2500
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2

Output: 0

Input:
50 10
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2

Output: 377652720

Input:
50 20
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2

Output: 84582199

Input:
50 30
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2

Output: 982500536

Input:
50 40
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2

Output: 310820833

Input:
50 50
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2

Output: 570412467

Input:
50 2500
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2
1 3
1 1
1 2

Output: 0

Input:
50 73
2 2
1 2
3 1
2 2
4 1
1 1
3 2
1 1
2 1
1 2
1 2
4 1
2 1
5 2
2 1
4 2
3 2
1 2
3 1
4 2
4 1
4 1
4 1
2 1
5 2
1 2
5 1
5 1
4 1
1 2
5 1
5 1
4 1
3 1
4 2
5 1
5 1
1 2
4 2
1 1
4 2
2 2
1 1
2 1
2 1
4 2
1 2
2 1
3 2
2 1

Output: 467024102

Input:
50 273
17 2
12 1
10 1
4 1
10 2
7 2
2 1
6 1
19 1
19 1
4 1
7 1
1 1
5 2
6 2
9 2
9 1
10 2
4 1
9 1
9 2
12 1
16 1
8 1
4 1
7 1
14 1
6 1
5 2
12 2
16 2
10 2
3 1
9 2
14 2
3 2
17 1
14 1
3 1
11 2
3 1
16 1
13 2
19 2
14 1
9 1
15 2
19 2
15 2
9 1

Output: 548493050

Input:
50 695
35 1
8 2
50 1
50 1
34 2
47 2
9 2
50 1
45 1
45 1
14 2
50 1
14 2
23 2
20 1
29 1
41 2
47 1
42 1
7 2
34 1
22 2
5 1
3 2
32 1
45 2
21 1
8 2
13 1
38 2
6 2
29 2
7 2
48 1
35 1
6 1
26 2
42 2
22 2
25 2
12 1
50 2
6 2
43 1
27 2
31 2
4 2
24 2
41 1
48 2

Output: 50865976

Input:
50 67
2 3
1 2
1 3
2 2
4 2
2 2
4 1
2 3
1 1
1 3
1 1
4 3
3 3
5 1
3 3
4 3
1 1
3 3
4 3
4 1
5 2
1 1
5 2
4 3
2 2
5 1
3 2
3 1
3 3
2 3
5 3
5 3
2 2
5 2
1 3
5 3
2 3
5 1
2 3
2 1
1 3
5 3
2 2
1 1
5 3
3 1
4 3
4 1
1 3
4 3

Output: 210683057

Input:
50 259
6 1
17 2
7 1
16 3
20 3
11 1
7 3
15 2
2 2
8 2
8 3
11 1
7 2
18 2
4 2
7 2
6 1
17 1
15 1
8 3
5 3
9 3
11 2
8 2
17 1
1 2
7 2
8 2
3 3
9 1
3 1
13 1
12 2
19 1
1 3
3 2
1 3
10 1
20 3
12 2
18 2
1 2
13 3
20 1
10 2
3 3
16 1
1 3
12 3
11 2

Output: 213126757

Input:
50 629
35 1
15 3
22 3
9 3
23 3
42 1
32 2
22 2
17 1
47 1
23 1
7 2
39 3
43 1
50 2
17 3
4 1
23 1
34 3
4 2
19 2
19 2
16 3
17 1
8 2
38 2
13 1
49 3
14 2
50 3
42 1
2 3
34 1
47 1
34 3
17 3
5 1
2 2
25 3
29 3
38 3
35 1
20 2
47 3
15 3
34 2
22 2
40 1
25 2
21 2

Output: 659505402

Input:
50 1250
47 3
48 2
48 1
48 3
50 1
48 2
48 1
49 1
47 1
50 1
47 1
48 2
50 2
49 3
47 1
48 1
49 1
50 3
49 2
49 1
48 3
48 3
50 3
48 3
48 3
50 2
47 1
50 1
47 3
50 3
49 2
49 1
49 3
48 2
49 1
48 2
48 3
50 2
48 3
50 3
48 1
49 3
47 3
47 1
47 3
50 2
47 2
49 2
49 3
49 3

Output: 629245299

Input:
50 1250
49 2
47 1
48 1
49 2
48 1
48 1
47 2
47 1
47 1
48 1
47 2
48 2
48 2
47 1
49 2
50 1
48 2
48 2
50 2
49 1
47 2
50 1
47 2
47 2
47 2
47 2
50 1
48 1
48 1
48 2
47 2
49 2
48 2
50 2
50 1
48 2
48 1
50 2
50 1
49 1
49 2
49 2
47 2
50 2
47 1
47 2
47 2
47 2
47 1
47 2

Output: 81355073

Input:
50 2500
50 1
50 1
50 2
50 1
50 2
50 2
50 1
50 1
50 2
50 1
50 2
50 1
50 3
50 2
50 1
50 3
50 1
50 3
50 3
50 3
50 3
50 3
50 1
50 1
50 2
50 3
50 3
50 2
50 1
50 1
50 1
50 3
50 2
50 2
50 3
50 2
50 1
50 2
50 2
50 1
50 1
50 1
50 3
50 1
50 3
50 1
50 1
50 3
50 3
50 1

Output: 908436174

Input:
50 2500
50 1
49 1
50 2
49 1
49 1
49 1
49 1
50 2
49 2
49 1
49 2
49 2
50 2
50 1
49 2
49 2
50 1
50 1
50 1
50 1
50 1
50 2
50 2
50 2
50 1
49 1
50 1
50 2
50 1
49 2
50 1
49 1
49 2
50 1
50 2
49 1
50 1
49 2
50 2
50 1
49 1
49 1
50 2
50 2
50 1
49 1
50 2
50 1
50 2
49 1

Output: 0

Input:
50 2000
50 1
48 2
48 2
48 1
49 2
50 2
49 2
48 1
49 2
48 1
48 1
49 2
49 2
50 1
50 2
50 1
48 2
49 1
49 2
48 1
49 2
50 1
48 2
50 1
48 2
49 1
49 2
50 1
50 1
50 1
48 2
48 2
48 2
48 1
50 1
48 1
50 2
49 1
50 2
48 1
49 2
49 2
50 1
48 1
49 1
48 2
49 1
50 1
49 2
49 2

Output: 667547422

Input:
50 2500
49 3
50 3
49 1
50 2
50 1
49 1
50 1
50 3
49 1
49 3
50 3
49 2
50 3
49 3
50 1
50 3
49 1
49 1
49 2
49 1
49 2
50 1
49 2
49 1
49 2
50 1
50 2
50 2
49 1
50 3
49 1
50 3
49 3
50 3
49 1
49 2
50 3
49 1
50 3
49 2
49 2
49 2
50 1
50 2
50 1
50 2
50 2
50 1
50 1
49 3

Output: 0

Input:
2 5
2 3
1 3

Output: 0

Input:
50 2500
50 1
50 1
50 1
50 1
50 1
50 1
50 1
50 1
50 1
50 1
50 1
50 1
50 1
50 1
50 1
50 1
50 2
50 2
50 2
50 2
50 2
50 2
50 2
50 2
50 2
50 2
50 2
50 2
50 2
50 2
50 2
50 2
50 2
50 3
50 3
50 3
50 3
50 3
50 3
50 3
50 3
50 3
50 3
50 3
50 3
50 3
50 3
50 3
50 3
50 3

Output: 570412467


The leader of some very secretive organization has decided to invite all other members to a meeting. All members of the organization live in the same town which can be represented as $$$n$$$ crossroads connected by $$$m$$$ two-directional streets. The meeting will be held in the leader's house near the crossroad $$$1$$$. There are $$$k$$$ members of the organization invited to the meeting; $$$i$$$-th of them lives near the crossroad $$$a_i$$$. All members of the organization receive the message about the meeting at the same moment and start moving to the location where the meeting is held. In the beginning of each minute each person is located at some crossroad. He or she can either wait a minute at this crossroad, or spend a minute to walk from the current crossroad along some street to another crossroad (obviously, it is possible to start walking along the street only if it begins or ends at the current crossroad). In the beginning of the first minute each person is at the crossroad where he or she lives. As soon as a person reaches the crossroad number $$$1$$$, he or she immediately comes to the leader's house and attends the meeting.Obviously, the leader wants all other members of the organization to come up as early as possible. But, since the organization is very secretive, the leader does not want to attract much attention. Let's denote the discontent of the leader as follows  initially the discontent is $$$0$$$;  whenever a person reaches the crossroad number $$$1$$$, the discontent of the leader increases by $$$c \cdot x$$$, where $$$c$$$ is some fixed constant, and $$$x$$$ is the number of minutes it took the person to reach the crossroad number $$$1$$$;  whenever $$$x$$$ members of the organization walk along the same street at the same moment in the same direction, $$$dx^2$$$ is added to the discontent, where $$$d$$$ is some fixed constant. This is not cumulative: for example, if two persons are walking along the same street in the same direction at the same moment, then $$$4d$$$ is added to the discontent, not $$$5d$$$. Before sending a message about the meeting, the leader can tell each member of the organization which path they should choose and where they should wait. Help the leader to establish a plan for every member of the organization so they all reach the crossroad $$$1$$$, and the discontent is minimized.

NoteThe best course of action in the first test is the following:  the first person goes along the street $$$2$$$ to the crossroad $$$2$$$, then goes along the street $$$1$$$ to the crossroad $$$1$$$ and attends the meeting;  the second person waits one minute on the crossroad $$$3$$$, then goes along the street $$$2$$$ to the crossroad $$$2$$$, then goes along the street $$$1$$$ to the crossroad $$$1$$$ and attends the meeting;  the third person waits two minutes on the crossroad $$$3$$$, then goes along the street $$$2$$$ to the crossroad $$$2$$$, then goes along the street $$$1$$$ to the crossroad $$$1$$$ and attends the meeting;  the fourth person waits three minutes on the crossroad $$$3$$$, then goes along the street $$$2$$$ to the crossroad $$$2$$$, then goes along the street $$$1$$$ to the crossroad $$$1$$$ and attends the meeting.

The first line of the input contains five integer numbers $$$n$$$, $$$m$$$, $$$k$$$, $$$c$$$ and $$$d$$$ ($$$2 \le n \le 50$$$, $$$n - 1 \le m \le 50$$$, $$$1 \le k, c, d \le 50$$$) — the number of crossroads, the number of streets, the number of persons invited to the meeting and the constants affecting the discontent, respectively. The second line contains $$$k$$$ numbers $$$a_1$$$, $$$a_2$$$, ..., $$$a_k$$$ ($$$2 \le a_i \le n$$$) — the crossroads where the members of the organization live. Then $$$m$$$ lines follow, each denoting a bidirectional street. Each line contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$, $$$x_i \ne y_i$$$) denoting a street connecting crossroads $$$x_i$$$ and $$$y_i$$$. There may be multiple streets connecting the same pair of crossroads. It is guaranteed that every crossroad can be reached from every other crossroad using the given streets.

Print one integer: the minimum discontent of the leader after everyone reaches crossroad $$$1$$$.

Input:
3 2 4 2 3
3 3 3 3
1 2
2 3

Output: 52

Input:
3 3 4 2 3
3 2 2 3
1 2
2 3
2 3

Output: 38

Input:
50 49 49 1 1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50

Output: 2450

Input:
50 49 49 50 1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50

Output: 62475

Input:
50 49 49 1 50
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50

Output: 62475

Input:
2 50 50 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2

Output: 100

Input:
2 50 50 50 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2

Output: 2550

Input:
2 50 50 1 50
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2

Output: 2550

Input:
2 50 50 50 50
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2

Output: 5000

Input:
50 49 50 1 50
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 19
21 20
22 21
23 22
24 23
25 24
26 25
27 26
28 27
29 28
30 29
31 30
32 31
33 32
34 33
35 34
36 35
37 36
38 37
39 38
40 39
41 40
42 41
43 42
44 43
45 44
46 45
47 46
48 47
49 48
50 49

Output: 126175

Input:
50 49 50 50 50
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 19
21 20
22 21
23 22
24 23
25 24
26 25
27 26
28 27
29 28
30 29
31 30
32 31
33 32
34 33
35 34
36 35
37 36
38 37
39 38
40 39
41 40
42 41
43 42
44 43
45 44
46 45
47 46
48 47
49 48
50 49

Output: 306250

Input:
50 49 50 50 1
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 19
21 20
22 21
23 22
24 23
25 24
26 25
27 26
28 27
29 28
30 29
31 30
32 31
33 32
34 33
35 34
36 35
37 36
38 37
39 38
40 39
41 40
42 41
43 42
44 43
45 44
46 45
47 46
48 47
49 48
50 49

Output: 144656

Input:
50 49 50 1 1
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 19
21 20
22 21
23 22
24 23
25 24
26 25
27 26
28 27
29 28
30 29
31 30
32 31
33 32
34 33
35 34
36 35
37 36
38 37
39 38
40 39
41 40
42 41
43 42
44 43
45 44
46 45
47 46
48 47
49 48
50 49

Output: 6125

Input:
50 50 50 1 1
12 50 38 33 26 24 40 43 7 30 18 9 14 9 39 21 10 16 49 35 18 8 15 44 21 39 29 45 16 41 29 13 4 42 27 34 2 13 10 42 36 21 8 13 13 24 14 39 34 24
1 29
1 18
29 23
1 49
1 31
29 5
49 45
23 33
45 7
33 9
5 25
25 46
7 32
7 43
23 38
7 35
9 17
1 11
5 30
23 28
1 50
38 24
7 12
17 21
45 41
28 4
24 19
18 14
24 15
1 37
33 10
31 40
5 20
9 47
37 2
40 22
17 36
17 39
1 44
31 26
46 27
41 42
28 48
49 13
31 8
8 34
29 6
18 3
44 16
43 24

Output: 443

Input:
25 50 50 1 1
2 11 11 14 14 24 12 18 2 21 17 12 13 19 20 7 2 14 2 9 8 23 23 21 5 11 13 9 7 11 25 17 10 2 15 18 5 10 8 15 12 23 11 8 15 10 10 14 18 7
1 22
22 11
1 12
22 14
12 10
1 16
10 2
10 21
14 8
12 15
10 23
8 17
17 9
1 5
11 7
12 4
8 18
22 24
2 13
10 25
5 20
24 6
13 19
24 3
21 10
21 8
18 1
4 19
13 2
2 14
7 10
22 17
14 11
4 22
17 1
5 15
12 22
7 5
8 24
18 25
10 13
17 23
16 25
25 2
9 14
12 17
25 20
18 19
13 24
19 8

Output: 291

Input:
50 50 50 1 1
38 11 32 42 47 43 33 24 12 48 31 49 42 17 44 46 12 40 8 41 33 35 40 22 44 20 41 16 5 46 49 6 29 13 11 39 17 26 18 2 23 8 8 47 50 7 16 29 37 37
1 3
1 49
1 36
36 42
1 34
34 39
3 15
36 32
34 25
49 16
15 29
16 31
16 19
36 33
25 43
42 22
29 45
32 47
32 4
42 14
36 21
25 28
28 35
19 7
14 24
28 26
22 6
22 12
39 8
15 50
29 2
36 30
39 9
15 27
34 13
31 37
43 5
47 38
6 11
14 48
21 18
15 46
38 20
32 10
46 44
28 23
12 41
12 17
1 40
23 47

Output: 453

Input:
25 50 50 1 1
14 14 9 23 8 4 20 23 12 16 9 16 4 18 22 11 15 4 9 14 14 22 7 18 8 11 17 11 14 10 18 12 7 13 18 8 6 21 14 2 23 4 21 14 13 17 20 14 7 8
1 20
1 19
19 3
20 23
20 14
14 13
20 2
20 8
19 10
23 16
19 18
2 22
20 24
19 7
10 12
3 6
6 5
6 25
20 15
8 17
7 9
14 4
18 21
13 11
14 16
23 14
19 24
3 11
13 9
3 2
25 10
9 19
14 17
3 7
7 23
9 4
23 14
4 9
7 14
15 16
13 4
5 9
11 9
13 22
5 18
6 20
16 8
13 20
1 16
12 5

Output: 385

Input:
50 50 50 1 1
25 43 16 50 21 34 35 5 16 26 6 39 11 25 11 31 4 6 26 7 38 22 37 10 7 21 4 8 15 21 31 40 5 43 23 44 31 30 16 10 11 32 7 41 27 30 7 9 50 49
1 24
1 44
1 47
44 29
44 27
29 45
24 13
47 30
30 15
1 6
15 8
45 39
6 28
30 41
15 19
41 49
6 40
28 18
40 4
15 38
44 26
47 35
6 21
1 10
39 14
26 37
41 46
44 22
29 12
30 7
40 25
24 11
22 3
29 20
13 42
25 48
38 33
18 23
45 16
44 36
20 9
48 5
22 2
28 50
6 34
38 17
39 31
33 43
1 32
7 27

Output: 406

Input:
25 50 50 1 1
2 25 14 9 18 24 11 12 14 4 10 20 12 2 23 24 20 11 7 4 4 21 24 23 18 19 12 14 13 24 2 23 5 16 5 15 6 16 3 5 2 9 15 4 4 17 23 13 13 9
1 5
1 13
5 15
13 19
1 18
15 6
5 16
19 8
18 3
18 10
15 9
19 11
19 12
5 24
8 14
15 4
24 2
1 21
24 23
14 7
21 22
9 20
9 25
3 17
15 4
12 4
7 22
23 3
25 24
8 14
1 13
24 20
11 15
24 20
18 21
25 10
14 20
15 18
12 9
25 8
13 17
3 24
13 16
6 23
6 4
11 1
3 10
19 24
9 23
4 18

Output: 315

Input:
50 50 50 1 1
11 4 39 10 42 24 38 34 10 33 19 20 29 32 6 18 36 31 35 12 43 49 13 37 29 2 27 38 15 26 12 23 19 14 44 9 8 5 25 29 7 18 17 46 5 4 8 10 4 23
1 32
1 7
32 50
32 17
1 21
1 6
6 23
50 9
21 4
17 10
9 38
10 46
10 22
9 49
9 43
4 45
10 39
39 24
32 26
24 14
22 15
21 8
1 3
26 20
17 36
32 42
9 5
14 35
39 12
43 30
14 11
11 37
36 48
39 2
45 13
10 16
36 41
26 18
50 47
48 44
6 33
3 40
24 27
36 19
20 25
37 34
9 28
34 29
26 31
37 3

Output: 481

Input:
25 50 50 1 1
23 12 19 19 11 20 19 17 8 7 18 8 12 17 25 20 18 9 22 9 17 20 9 21 21 2 23 24 5 23 19 3 11 3 16 14 15 3 8 23 20 22 24 10 18 24 17 20 2 2
1 9
9 21
9 6
21 12
1 19
21 13
1 18
1 14
14 24
21 11
1 5
19 23
5 7
18 17
1 10
6 2
6 15
9 4
21 20
17 3
1 25
3 16
11 22
12 8
11 9
10 14
21 20
9 2
4 7
9 23
2 13
11 4
21 5
17 11
5 10
2 23
7 14
14 10
19 17
10 1
6 20
12 4
1 22
6 3
6 19
2 20
25 7
15 12
20 2
25 2

Output: 272

Input:
50 50 50 1 1
37 14 23 28 15 15 42 16 15 2 42 20 45 39 12 33 38 46 43 17 9 26 11 15 2 4 28 20 4 2 33 16 44 34 17 13 22 8 13 28 43 4 7 31 32 27 49 39 8 35
1 44
44 15
1 22
1 34
34 17
1 2
2 29
22 13
29 25
29 21
22 20
2 49
44 40
22 9
29 11
34 43
20 50
13 42
22 30
30 12
12 10
1 37
21 47
2 38
40 24
24 45
29 35
15 6
44 27
43 48
42 19
27 16
10 4
38 8
42 33
4 23
48 7
1 18
18 3
19 5
11 31
2 46
23 36
48 26
43 14
46 39
8 32
38 41
30 28
17 29

Output: 373

Input:
25 50 50 1 1
3 23 24 12 21 9 10 22 18 19 2 12 19 8 19 17 7 16 4 23 23 3 10 2 16 2 19 11 20 14 3 6 9 15 3 4 8 22 21 2 15 19 18 16 16 24 20 4 16 11
1 18
1 7
18 9
7 5
5 23
9 6
1 21
9 16
6 24
24 11
16 13
9 15
23 10
7 4
4 17
5 14
24 12
17 25
14 20
1 19
12 8
21 3
3 2
14 22
12 18
12 25
22 18
25 19
9 22
18 10
23 8
22 2
24 20
3 14
20 3
20 6
16 22
5 14
5 21
14 20
4 12
11 20
21 20
8 6
20 16
10 14
4 5
16 9
12 3
15 13

Output: 355

Input:
50 50 50 1 50
13 28 46 41 47 30 34 13 5 12 33 13 49 24 7 7 15 40 23 43 19 45 42 41 31 45 21 31 44 8 34 4 34 20 17 15 5 33 4 31 49 34 20 46 20 22 8 42 49 2
1 41
41 34
1 33
41 11
34 22
41 12
1 35
1 30
33 49
30 36
33 17
1 7
30 27
34 48
11 42
48 19
7 3
19 8
27 6
48 32
27 2
30 46
6 43
12 40
2 21
36 5
19 50
30 38
35 39
11 31
1 9
7 44
2 28
48 4
7 20
20 26
2 25
38 18
28 13
39 24
42 15
46 16
42 29
38 37
21 10
38 45
28 23
35 14
32 47
30 25

Output: 7568

Input:
25 50 50 1 50
19 24 16 2 10 19 15 25 18 12 21 18 6 3 13 7 13 4 17 13 18 9 15 24 5 20 7 22 24 22 15 24 2 19 23 20 24 19 22 21 23 19 19 9 11 10 12 18 12 20
1 9
1 5
1 3
9 21
1 7
3 22
3 4
4 6
7 23
5 2
9 19
6 14
14 10
1 20
10 15
22 17
7 13
6 16
1 8
6 12
16 11
9 18
12 25
3 24
11 19
19 18
5 14
3 16
18 17
11 6
22 6
5 19
10 18
21 3
16 20
1 9
18 6
22 10
7 12
13 25
5 1
9 17
1 15
17 16
14 23
1 10
12 17
23 24
10 24
7 23

Output: 4639

Input:
50 50 50 1 50
49 48 21 49 20 21 37 43 9 29 47 3 27 22 12 41 7 6 41 48 25 31 18 29 43 46 43 21 4 13 15 36 49 40 29 20 30 36 2 40 46 10 20 40 46 45 9 32 42 24
1 24
24 30
1 15
1 38
1 42
24 35
38 49
1 23
42 33
30 20
33 48
1 29
38 16
48 31
15 7
33 41
15 45
41 32
7 6
6 28
15 27
30 43
33 4
24 34
16 26
41 12
7 8
43 17
38 18
8 22
48 3
20 14
45 36
48 39
43 44
6 19
36 9
44 2
18 5
29 11
17 50
42 40
36 25
36 37
22 21
35 13
29 47
14 46
3 10
9 47

Output: 7772

Input:
25 50 50 1 50
24 11 21 20 12 15 7 6 12 7 5 14 14 2 15 11 2 11 24 19 8 16 8 14 7 4 10 24 7 13 7 19 16 22 18 11 25 14 19 8 2 16 4 7 10 9 23 17 17 6
1 12
12 23
23 9
12 11
11 13
12 7
9 16
23 21
9 6
6 2
23 18
7 14
7 19
19 20
13 22
16 17
2 5
21 8
19 15
22 3
20 25
16 10
6 24
20 4
4 24
13 20
11 20
15 7
1 4
16 18
1 9
16 21
20 4
10 9
3 21
11 22
18 14
7 20
20 18
2 18
8 9
20 5
14 24
15 19
23 18
22 24
21 16
3 15
1 6
15 8

Output: 5840

Input:
50 50 50 1 50
26 9 5 19 3 50 39 14 3 7 21 43 35 29 18 18 10 31 40 15 29 48 15 7 16 27 45 13 42 38 35 20 25 11 2 24 44 2 10 10 33 35 20 25 33 19 50 12 45 36
1 23
23 39
23 27
27 18
18 9
23 29
18 37
23 48
27 36
1 40
48 21
1 35
27 32
21 34
36 33
18 5
27 6
37 8
6 24
1 2
29 49
8 28
24 43
35 7
36 19
34 30
36 45
48 25
6 13
35 41
32 17
48 38
40 3
1 11
7 20
39 10
17 46
10 22
19 44
39 16
1 4
41 47
28 14
9 26
26 42
18 12
26 15
40 31
4 50
43 27

Output: 8276

Input:
25 50 50 1 50
12 14 2 6 14 11 15 11 14 11 13 10 13 10 16 24 16 9 6 8 5 7 9 19 18 11 14 11 6 20 16 6 14 9 5 9 9 25 24 3 13 5 14 13 24 25 9 17 23 15
1 24
1 25
24 7
24 15
15 18
15 22
22 4
22 12
22 13
1 2
7 5
7 16
13 21
12 20
18 8
4 6
6 23
8 11
4 19
25 3
23 10
6 9
12 17
24 14
14 5
20 18
5 7
13 11
13 2
23 9
7 1
10 22
25 1
17 23
13 9
20 4
5 23
18 19
20 12
12 13
7 21
18 7
16 10
4 24
3 5
11 1
8 18
8 19
18 10
9 21

Output: 5612

Input:
50 50 50 1 50
3 20 38 18 14 30 42 44 8 25 35 33 14 37 33 43 40 45 9 20 34 25 41 34 28 19 8 34 4 4 16 14 50 30 33 39 20 16 47 19 19 21 29 30 11 42 2 13 9 49
1 11
11 10
10 34
10 48
10 19
11 31
10 9
11 40
19 27
31 15
15 35
40 8
40 41
31 50
27 29
50 23
34 14
35 5
1 49
27 36
50 33
23 46
31 2
40 43
5 24
33 20
10 42
2 18
5 26
49 12
8 22
31 47
35 25
22 32
25 30
14 17
17 45
22 38
30 39
24 37
27 7
33 44
41 28
15 13
19 21
11 6
18 3
34 4
7 16
23 3

Output: 11326

Input:
25 50 50 1 50
24 9 16 15 15 16 6 25 24 22 22 6 21 25 10 20 13 24 13 14 3 14 9 24 21 11 9 13 22 3 9 2 4 21 16 24 2 20 13 21 7 2 7 11 6 16 20 16 12 8
1 4
4 17
4 2
4 11
4 12
12 15
2 18
4 10
1 6
4 23
1 8
10 3
2 20
23 5
3 22
18 19
5 9
10 21
22 24
6 16
11 14
9 7
10 13
12 25
1 14
8 16
4 16
25 24
9 22
22 14
20 4
22 24
21 8
10 4
11 12
23 17
21 23
4 2
25 2
23 6
14 22
10 13
8 5
18 17
4 17
4 16
21 8
16 4
17 22
22 17

Output: 6160

Input:
50 50 50 1 50
39 41 12 26 36 21 46 35 2 42 48 14 32 35 29 18 33 22 27 26 40 13 38 22 2 9 29 25 42 18 46 46 16 50 45 43 35 29 7 27 16 7 28 24 37 25 41 43 13 23
1 25
1 12
25 37
25 16
25 5
37 32
25 8
25 2
8 29
1 35
25 6
16 31
2 9
35 39
29 30
29 47
37 49
31 27
35 42
39 26
49 24
39 50
26 43
37 34
35 11
43 45
25 48
29 41
12 28
26 3
45 36
16 23
1 22
41 40
1 19
16 38
16 44
1 17
36 14
47 33
50 4
31 21
39 10
39 7
27 46
11 15
34 13
9 18
25 20
3 29

Output: 8357

Input:
25 50 50 1 50
20 20 5 25 17 12 14 22 18 2 22 10 13 17 12 9 19 22 19 11 16 5 18 22 7 19 20 15 13 25 17 13 18 24 3 6 3 7 18 8 10 15 17 10 12 16 6 16 18 17
1 18
1 21
18 23
21 6
6 3
23 8
3 2
3 9
2 4
9 20
9 15
8 10
3 16
4 11
20 5
2 14
23 7
9 19
4 13
5 24
1 25
6 22
24 12
1 17
2 1
18 19
23 20
22 9
19 2
25 3
9 25
6 2
24 2
18 1
8 4
17 14
16 11
7 10
18 24
12 17
9 25
2 3
11 4
1 22
8 24
2 22
2 7
15 25
17 20
15 14

Output: 5039

Input:
50 50 50 50 1
21 40 29 43 29 35 12 48 28 11 48 6 40 31 44 22 44 11 43 27 14 8 2 8 7 35 48 40 15 38 22 33 44 2 26 43 11 20 42 50 18 23 9 5 30 21 30 11 37 3
1 28
1 45
1 19
1 46
1 24
28 20
28 11
20 39
11 13
39 37
28 42
46 26
1 50
37 6
11 49
6 29
50 8
19 34
8 15
15 30
8 18
29 12
39 40
37 33
42 23
46 21
39 5
26 22
34 3
13 36
21 47
24 7
45 4
37 48
23 2
45 27
26 38
30 25
36 43
38 35
47 10
25 44
48 41
30 32
8 31
36 9
35 14
6 17
6 16
19 26

Output: 9737

Input:
25 50 50 50 1
21 18 25 8 14 9 15 4 21 10 8 23 23 14 13 13 21 13 8 5 21 7 16 20 23 20 9 18 24 6 17 18 18 18 13 23 18 3 10 18 9 7 4 5 12 24 2 19 20 11
1 15
15 9
1 17
9 7
1 25
7 10
17 4
4 23
23 12
9 24
1 2
15 21
15 11
24 6
11 14
10 19
1 16
2 13
9 22
15 8
7 5
10 18
18 20
1 3
15 25
7 3
8 4
5 15
11 20
11 13
15 6
20 5
11 15
9 3
25 1
5 6
21 17
7 5
5 4
8 7
23 18
2 1
13 1
19 16
24 5
8 17
10 6
25 19
6 23
17 2

Output: 6245

Input:
50 50 50 50 1
47 50 3 3 2 15 15 28 32 38 21 45 9 39 40 46 36 26 2 43 19 34 47 45 29 17 21 31 14 13 42 26 10 32 38 9 26 34 50 11 45 9 48 10 8 44 21 2 41 16
1 18
18 44
1 42
42 9
42 19
18 24
18 36
24 5
24 15
9 40
1 8
5 45
15 49
8 39
39 30
15 2
49 13
45 27
1 31
5 17
17 47
39 35
47 22
19 7
42 29
40 14
44 50
35 38
44 21
40 33
18 48
42 12
38 23
30 11
11 34
27 37
27 43
47 3
14 26
8 20
42 28
7 16
22 10
29 4
15 6
5 41
29 32
20 25
7 46
49 6

Output: 9629

Input:
25 50 50 50 1
2 6 22 25 8 5 14 9 23 13 17 3 15 13 15 9 3 19 14 10 2 6 9 17 9 4 4 4 23 21 2 22 16 21 8 21 19 14 23 21 12 20 13 3 10 23 4 10 10 4
1 23
1 18
23 3
3 17
3 24
17 12
3 13
18 22
12 5
3 25
5 6
25 16
3 8
1 7
16 4
12 21
12 2
17 19
5 14
22 9
22 11
4 10
11 15
16 20
12 5
21 10
14 2
24 7
15 23
8 25
23 10
11 7
14 4
23 18
7 15
5 7
6 13
13 11
8 1
4 13
1 14
7 24
17 19
10 14
18 24
18 9
1 22
22 5
7 11
1 8

Output: 5704

Input:
50 50 50 50 1
34 22 37 2 33 5 19 9 36 45 25 37 26 46 45 33 28 2 21 47 24 2 24 23 41 18 22 3 13 19 23 10 34 3 21 13 40 37 48 20 32 43 8 44 34 19 23 31 44 37
1 7
7 45
1 12
45 38
1 47
38 37
47 24
37 40
12 30
45 3
37 46
38 18
47 15
7 16
16 22
38 17
16 10
18 36
40 29
15 39
45 13
38 23
30 8
17 5
17 31
30 32
23 49
40 48
1 9
10 4
12 27
7 2
31 21
18 42
7 50
47 41
8 33
40 43
16 26
42 28
5 34
22 19
31 11
9 6
23 25
47 44
38 35
21 20
5 14
29 32

Output: 10245

Input:
25 50 50 50 1
22 17 11 3 17 2 6 15 17 9 25 23 23 13 8 6 8 9 13 8 8 13 10 22 20 4 8 22 7 20 19 25 14 16 19 20 4 9 4 15 15 17 15 9 25 6 23 17 15 14
1 21
21 19
19 10
10 18
10 17
17 24
24 3
24 25
25 16
24 20
19 14
14 13
20 7
10 2
19 15
3 23
18 22
14 12
18 8
15 5
14 6
23 9
20 4
3 11
13 11
23 20
23 8
11 7
24 10
17 9
16 9
5 8
25 19
12 25
1 8
25 2
23 19
19 18
24 11
7 19
6 9
25 1
1 22
11 5
10 15
18 4
3 5
5 7
6 25
13 8

Output: 6243

Input:
50 50 50 50 1
11 43 20 20 46 35 11 39 30 24 49 27 44 5 12 9 30 17 29 14 30 38 10 50 14 48 34 44 24 43 4 3 9 23 42 18 6 12 7 29 29 20 18 39 12 42 14 31 8 40
1 44
44 24
24 22
44 21
1 20
1 40
40 8
40 26
20 25
40 33
22 41
41 45
20 4
33 6
45 23
23 15
6 34
22 10
41 11
6 3
4 5
40 12
12 13
21 48
4 49
41 39
5 35
10 29
4 36
24 2
40 28
28 38
4 14
25 9
33 19
3 47
29 37
25 18
38 43
49 16
14 46
24 27
23 17
27 7
47 30
23 31
19 32
33 42
30 50
13 9

Output: 9425

Input:
25 50 50 50 1
10 12 8 5 11 22 14 4 3 20 9 3 22 4 10 10 14 16 3 13 6 4 2 12 23 19 3 25 14 19 3 4 4 20 6 10 21 20 25 10 10 6 24 7 15 22 2 17 5 7
1 24
24 4
24 19
19 8
19 25
1 21
19 22
24 13
4 23
22 20
20 14
24 15
8 10
21 16
19 18
22 2
20 5
22 7
5 12
4 6
22 11
22 9
15 3
20 17
5 16
16 10
3 7
2 24
11 21
1 21
13 12
21 6
10 9
2 20
16 18
2 14
3 9
10 1
2 15
6 9
8 13
3 14
24 11
22 20
17 8
12 9
11 4
21 16
13 25
12 11

Output: 6422

Input:
50 50 50 50 1
37 4 43 29 18 26 14 20 35 41 24 18 23 3 18 33 13 41 47 19 34 15 46 38 37 49 7 25 13 48 24 36 24 43 5 32 31 15 5 48 16 6 8 43 38 26 15 12 11 4
1 16
16 37
1 10
1 44
10 34
1 26
10 12
12 38
38 21
1 19
37 6
6 11
21 22
6 50
6 42
21 33
50 36
6 8
50 32
32 47
33 48
34 29
21 49
49 15
29 25
21 46
47 9
44 18
46 7
6 2
11 39
7 40
19 41
40 35
11 31
44 24
41 23
44 43
18 5
49 20
34 27
9 30
34 3
10 13
27 28
9 4
39 45
24 17
28 14
42 35

Output: 9488

Input:
25 50 50 50 1
22 7 14 6 21 18 5 9 21 8 18 23 6 12 12 23 11 14 10 3 19 11 3 17 10 19 14 11 13 9 20 8 18 23 17 9 22 23 22 21 4 3 18 13 13 21 20 8 2 24
1 9
1 24
1 25
25 8
1 19
24 17
24 12
19 3
1 20
3 21
12 11
21 14
12 13
21 10
20 4
12 22
1 6
8 2
19 18
3 16
11 7
22 5
1 15
5 23
10 21
18 20
13 5
25 19
11 7
23 9
10 4
21 20
12 23
2 7
12 2
3 24
9 6
5 23
18 7
14 9
3 9
14 9
6 3
25 8
2 6
24 11
17 7
12 19
3 14
11 7

Output: 5328

Input:
50 50 50 50 50
32 19 21 12 34 28 45 8 42 7 39 34 4 3 35 11 4 30 25 48 9 46 6 48 2 12 46 48 41 4 20 32 29 25 39 18 44 21 16 24 19 30 25 43 24 15 11 44 32 19
1 11
11 35
35 30
1 20
1 5
30 44
1 47
11 50
47 17
47 46
35 16
17 8
20 42
50 7
44 43
43 41
7 29
46 49
16 4
44 32
49 6
5 36
46 12
12 14
46 27
1 3
12 15
8 10
1 34
27 2
27 23
11 26
2 33
12 18
43 38
49 48
17 21
26 37
41 9
44 22
46 28
30 31
5 45
15 40
40 25
47 19
19 24
24 39
3 13
4 46

Output: 25050

Input:
25 50 50 50 50
23 12 5 24 15 4 7 14 14 18 14 4 5 7 22 23 18 21 8 9 18 21 24 16 17 25 8 14 4 19 11 15 16 4 2 14 16 6 11 8 10 2 21 23 18 19 5 8 7 17
1 24
1 6
1 5
6 19
24 15
15 11
11 2
19 21
15 8
8 13
15 23
13 25
8 18
24 10
6 20
5 9
6 16
2 3
3 7
9 22
21 14
18 12
23 17
3 4
15 7
21 14
3 2
8 17
24 1
23 12
18 15
16 23
9 20
22 9
4 17
1 23
16 19
19 5
19 6
5 15
5 15
1 14
17 23
1 21
22 13
5 3
22 17
15 11
1 13
20 15

Output: 13400

Input:
50 50 50 50 50
19 30 6 31 17 9 48 39 46 24 3 24 22 11 41 47 44 6 33 14 14 33 3 26 24 3 48 30 40 18 40 16 44 45 11 22 10 34 4 33 6 5 25 47 2 38 2 24 45 32
1 26
26 11
1 42
42 33
42 22
26 10
10 25
26 35
26 44
26 17
35 4
1 24
33 23
23 43
10 28
17 49
28 50
1 34
23 15
4 5
1 31
42 18
5 13
4 39
11 6
39 38
18 29
11 9
23 16
17 21
22 14
14 45
29 48
11 27
6 3
26 8
28 47
23 37
3 41
31 46
15 20
9 12
41 19
3 40
24 2
14 30
21 36
20 32
38 7
34 27

Output: 21200

Input:
25 50 50 50 50
3 23 10 2 17 9 23 3 16 5 14 24 20 23 16 20 24 3 22 15 23 4 25 14 20 25 11 8 11 18 3 10 5 7 13 4 24 25 8 11 13 15 14 21 25 19 15 23 12 18
1 6
1 17
17 16
17 23
23 4
17 19
17 18
1 22
22 8
1 25
17 5
16 21
21 3
3 10
17 20
23 7
6 12
16 11
19 24
17 9
16 14
23 2
1 13
4 15
16 12
22 12
5 8
24 12
3 8
7 24
25 7
4 12
2 13
8 19
10 4
5 9
8 23
1 13
18 25
11 7
4 10
20 4
15 9
18 10
23 24
15 9
9 20
20 10
5 21
8 23

Output: 17150

Input:
50 50 50 50 50
45 40 49 39 39 48 50 9 2 42 27 6 50 29 46 13 36 21 41 19 20 10 28 4 36 43 22 11 40 43 22 9 19 26 43 27 25 48 12 42 42 41 35 42 29 22 3 25 38 45
1 8
8 38
38 20
38 4
38 25
38 34
4 35
8 10
20 21
21 33
33 19
10 44
1 49
20 41
25 43
25 27
43 7
21 17
20 2
44 29
19 47
25 5
10 12
34 26
43 46
25 14
33 23
7 3
14 48
20 50
20 24
48 11
27 31
31 6
14 42
27 22
29 9
10 28
24 39
4 37
22 30
43 45
48 16
37 18
17 15
48 36
33 13
17 32
22 40
14 49

Output: 32450

Input:
25 50 50 50 50
23 10 7 20 19 21 6 25 10 17 7 4 4 6 18 16 5 9 5 20 21 3 10 11 7 8 14 10 10 9 20 22 19 18 24 11 17 12 13 21 8 12 24 3 23 10 2 23 2 20
1 10
10 17
1 2
17 12
12 7
10 11
7 16
2 19
11 18
16 8
2 9
7 6
17 3
19 15
19 25
12 5
11 21
8 4
1 23
18 24
16 13
3 22
17 14
21 20
9 17
16 23
18 11
22 8
7 24
5 6
19 21
13 2
4 22
3 8
16 17
2 24
8 20
18 19
9 23
7 23
14 2
8 13
20 7
21 16
17 22
22 14
21 24
7 11
6 14
12 2

Output: 18350

Input:
50 50 50 50 50
32 2 23 38 2 39 5 50 46 10 40 6 19 27 3 47 39 6 11 24 24 36 25 40 10 34 34 41 40 48 42 43 34 46 15 42 40 4 20 2 38 27 34 27 6 45 43 5 42 17
1 13
13 29
1 20
13 22
1 48
29 35
48 4
13 45
13 32
20 46
32 49
22 19
1 2
19 24
48 44
1 43
43 40
13 8
48 10
2 31
10 37
2 26
37 21
32 27
4 42
20 6
46 12
21 34
21 9
8 38
35 18
12 14
40 36
38 3
13 39
22 41
8 11
24 25
10 50
29 23
45 5
50 33
20 30
23 28
18 15
35 7
48 47
19 17
41 16
48 29

Output: 19250

Input:
25 50 50 50 50
12 21 12 5 20 17 22 14 20 4 15 24 4 22 20 13 3 16 19 2 2 2 3 8 17 16 18 21 18 8 21 25 9 5 11 2 18 7 10 16 3 25 17 9 21 18 12 22 7 21
1 12
1 21
21 18
21 16
12 11
18 9
11 22
22 7
1 19
7 6
16 13
6 23
7 25
6 24
22 3
16 10
25 17
21 14
25 2
1 15
13 8
24 5
24 20
15 4
13 23
9 12
6 9
9 4
16 6
9 24
23 5
10 23
23 17
15 13
10 18
5 4
3 15
23 7
19 20
21 4
15 18
6 10
17 25
10 24
8 12
21 2
9 22
3 24
6 13
4 7

Output: 17200

Input:
50 50 50 50 50
19 32 7 8 23 29 47 30 40 37 15 36 35 35 8 24 31 22 29 40 29 14 2 17 22 25 6 33 39 24 33 26 49 17 27 46 25 27 19 22 25 2 34 31 33 29 44 35 6 30
1 6
1 48
6 39
1 50
39 12
48 32
48 38
48 25
1 49
25 2
50 44
50 17
49 35
17 23
12 43
2 42
42 5
2 16
25 21
16 7
6 10
42 33
25 29
17 11
42 19
49 13
49 31
49 9
7 20
44 14
17 27
19 26
12 15
21 22
39 24
29 28
29 8
43 18
8 4
15 46
10 47
13 45
10 41
12 40
1 37
18 34
8 30
10 36
38 3
27 5

Output: 23050

Input:
25 50 50 50 50
24 8 9 23 22 13 22 3 14 16 23 4 11 21 21 17 16 6 18 7 16 25 4 14 20 23 13 15 25 23 13 4 7 16 6 24 3 18 7 11 5 22 19 7 11 17 15 22 21 14
1 3
3 7
1 4
4 17
3 23
17 21
7 15
7 13
4 16
23 25
3 19
4 14
19 9
9 20
9 24
17 22
19 11
4 2
15 10
20 8
21 6
7 18
9 12
24 5
6 11
7 23
8 7
3 12
3 21
18 7
23 1
25 20
13 7
12 16
4 11
11 13
4 22
10 12
5 3
17 19
21 14
5 23
11 23
4 6
8 13
4 10
19 12
11 18
3 16
21 10

Output: 17900

Input:
8 10 10 8 5
6 3 7 5 2 5 7 3 8 7
1 7
1 4
4 6
4 5
6 2
5 8
5 3
7 3
2 6
4 7

Output: 319

Input:
2 1 50 1 50
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 2

Output: 3775

Input:
2 1 10 50 1
2 2 2 2 2 2 2 2 2 2
1 2

Output: 600


Tokitsukaze is one of the characters in the game "Kantai Collection". In this game, every character has a common attribute — health points, shortened to HP.In general, different values of HP are grouped into $$$4$$$ categories:  Category $$$A$$$ if HP is in the form of $$$(4 n + 1)$$$, that is, when divided by $$$4$$$, the remainder is $$$1$$$;  Category $$$B$$$ if HP is in the form of $$$(4 n + 3)$$$, that is, when divided by $$$4$$$, the remainder is $$$3$$$;  Category $$$C$$$ if HP is in the form of $$$(4 n + 2)$$$, that is, when divided by $$$4$$$, the remainder is $$$2$$$;  Category $$$D$$$ if HP is in the form of $$$4 n$$$, that is, when divided by $$$4$$$, the remainder is $$$0$$$. The above-mentioned $$$n$$$ can be any integer.These $$$4$$$ categories ordered from highest to lowest as $$$A > B > C > D$$$, which means category $$$A$$$ is the highest and category $$$D$$$ is the lowest.While playing the game, players can increase the HP of the character. Now, Tokitsukaze wants you to increase her HP by at most $$$2$$$ (that is, either by $$$0$$$, $$$1$$$ or $$$2$$$). How much should she increase her HP so that it has the highest possible category?

NoteFor the first example, the category of Tokitsukaze's HP is already $$$A$$$, so you don't need to enhance her ability.For the second example:  If you don't increase her HP, its value is still $$$98$$$, which equals to $$$(4 \times 24 + 2)$$$, and its category is $$$C$$$.  If you increase her HP by $$$1$$$, its value becomes $$$99$$$, which equals to $$$(4 \times 24 + 3)$$$, and its category becomes $$$B$$$.  If you increase her HP by $$$2$$$, its value becomes $$$100$$$, which equals to $$$(4 \times 25)$$$, and its category becomes $$$D$$$. Therefore, the best way is to increase her HP by $$$1$$$ so that the category of her HP becomes $$$B$$$.

The only line contains a single integer $$$x$$$ ($$$30 \leq x \leq 100$$$) — the value Tokitsukaze's HP currently.

Print an integer $$$a$$$ ($$$0 \leq a \leq 2$$$) and an uppercase letter $$$b$$$ ($$$b \in \lbrace A, B, C, D \rbrace$$$), representing that the best way is to increase her HP by $$$a$$$, and then the category becomes $$$b$$$. Note that the output characters are case-sensitive.

Output: 0  A

Output: 0 A

Output: 1 B

Output: 1  B

Output: 1 A

Output: 1  A

Output: 1 B

Output: 1  B

Output: 2 A

Output: 2   A

Output: 0  A

Output: 0 A

Output: 2 A

Output: 2   A

Output: 1 B

Output: 1  B

Output: 2 A

Output: 2   A

Output: 2 A

Output: 2   A

Output: 1 A

Output: 1  A

Output: 1 A

Output: 1  A

Output: 1 A

Output: 1  A

Output: 1 A

Output: 1  A

Output: 2 A

Output: 2   A

Output: 1 B

Output: 1  B

Output: 2 A

Output: 2   A

Output: 1 A

Output: 1  A

Output: 0  A

Output: 0 A

Output: 1 A

Output: 1  A

Output: 2 A

Output: 2   A


Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $$$1$$$ to $$$9$$$). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, $$$\ldots$$$, 9m, 1p, 2p, $$$\ldots$$$, 9p, 1s, 2s, $$$\ldots$$$, 9s.In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.Do you know the minimum number of extra suited tiles she needs to draw so that she can win?Here are some useful definitions in this game:  A mentsu, also known as meld, is formed by a koutsu or a shuntsu;  A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;  A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples:   [2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu;  [4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;  [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.

NoteIn the first example, Tokitsukaze already has a shuntsu.In the second example, Tokitsukaze already has a koutsu.In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].

The only line contains three strings — the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from $$$1$$$ to $$$9$$$ and the second character is m, p or s.

Print a single integer — the minimum number of extra suited tiles she needs to draw.

Input: 1s 2s 3s

Output: 0

Input: 9m 9m 9m

Output: 0

Input: 3p 9m 2p

Output: 1

Input: 8p 2s 9m

Output: 2

Input: 5s 8m 5s

Output: 1

Input: 9s 4s 3m

Output: 2

Input: 4p 8m 9s

Output: 2

Input: 8s 5s 7p

Output: 2

Input: 4p 7p 2p

Output: 1

Input: 3p 2p 3p

Output: 1

Input: 5s 9p 5s

Output: 1

Input: 9m 6s 1p

Output: 2

Input: 4m 2p 8m

Output: 2

Input: 8p 6s 4p

Output: 2

Input: 9s 6m 7p

Output: 2

Input: 4m 1p 3m

Output: 1

Input: 8s 8m 1p

Output: 2

Input: 5m 3p 8m

Output: 2

Input: 9m 7p 4s

Output: 2

Input: 4p 4s 2m

Output: 2

Input: 8p 8m 7s

Output: 2

Input: 5p 4s 5p

Output: 1

Input: 9s 1m 1s

Output: 2

Input: 4s 5s 8p

Output: 1

Input: 2p 8p 8p

Output: 1

Input: 7m 3m 6m

Output: 1

Input: 8p 5m 9m

Output: 2

Input: 3p 9p 5s

Output: 2

Input: 7s 6s 3m

Output: 1

Input: 4s 1p 8s

Output: 2

Input: 8m 5s 6p

Output: 2

Input: 3m 3p 4s

Output: 2

Input: 7m 7m 9p

Output: 1

Input: 5p 1s 1m

Output: 2

Input: 9p 5m 8s

Output: 2

Input: 6s 9s 4p

Output: 2

Input: 1s 6m 2s

Output: 1

Input: 5m 2p 7p

Output: 2

Input: 2m 6p 5m

Output: 2

Input: 6p 3s 1p

Output: 2

Input: 1m 7p 8m

Output: 2

Input: 5m 4s 6s

Output: 1

Input: 2p 9m 2m

Output: 2

Input: 7s 2s 3m

Output: 2

Input: 4m 7p 1s

Output: 2

Input: 8m 2m 6p

Output: 2

Input: 3p 8p 4s

Output: 2

Input: 7p 3m 9p

Output: 1

Input: 4p 7p 7m

Output: 2

Input: 8p 5s 5p

Output: 2

Input: 3p 9p 1m

Output: 2

Input: 7s 6s 8s

Output: 0

Input: 4s 1p 4m

Output: 2

Input: 3p 2m 4m

Output: 1

Input: 7p 8s 2s

Output: 2

Input: 2p 4m 7p

Output: 2

Input: 6s 1s 5s

Output: 1

Input: 3s 5m 1p

Output: 2

Input: 7s 9p 8m

Output: 2

Input: 2s 6m 6s

Output: 2

Input: 6m 2s 2m

Output: 2

Input: 3m 6p 9s

Output: 2

Input: 7m 3s 5p

Output: 2

Input: 5s 4p 6m

Output: 2

Input: 9s 1s 4p

Output: 2

Input: 4m 5s 9m

Output: 2

Input: 8s 3m 7s

Output: 1

Input: 5m 7p 5m

Output: 1

Input: 9m 2m 1s

Output: 2

Input: 4m 8p 8p

Output: 1

Input: 1p 3m 4s

Output: 2

Input: 5p 8p 2p

Output: 2

Input: 9s 5s 7m

Output: 2

Input: 7m 6s 8m

Output: 1

Input: 2p 3m 6p

Output: 2

Input: 6m 7s 2m

Output: 2

Input: 3m 2m 9s

Output: 1

Input: 7p 9s 7m

Output: 2

Input: 3p 4m 3s

Output: 2

Input: 7s 1p 1p

Output: 1

Input: 4s 5m 6s

Output: 1

Input: 8m 9s 4p

Output: 2

Input: 3m 7p 9m

Output: 2

Input: 1p 8s 9m

Output: 2

Input: 5p 5p 7s

Output: 1

Input: 2p 9s 5m

Output: 2

Input: 6s 4p 1s

Output: 2

Input: 1s 1m 8p

Output: 2

Input: 5s 6p 4s

Output: 1

Input: 2m 1m 2p

Output: 1

Input: 6m 7p 7m

Output: 1

Input: 1p 2m 5p

Output: 2

Input: 5m 8p 3m

Output: 1

Input: 3s 9p 2s

Output: 1

Input: 7s 7s 9p

Output: 1

Input: 4s 2p 7s

Output: 2

Input: 8m 6s 3p

Output: 2

Input: 3m 3m 1m

Output: 1

Input: 9p 7s 6p

Output: 2

Input: 4p 3m 4m

Output: 1

Input: 8p 9s 9s

Output: 1

Input: 3p 4m 7m

Output: 2

Input: 9p 1p 5s

Output: 2

Input: 9p 2p 1p

Output: 1

Input: 2p 2p 2p

Output: 0

Input: 6s 6s 6s

Output: 0

Input: 2p 4p 3p

Output: 0

Input: 7p 8p 6p

Output: 0

Input: 3m 5m 4m

Output: 0

Input: 9s 7s 8s

Output: 0

Input: 3p 9p 4m

Output: 2

Input: 7m 2m 3m

Output: 1

Input: 3p 5p 9p

Output: 1

Input: 2p 5p 9p

Output: 2

Input: 4s 5s 2s

Output: 1

Input: 8s 9s 5s

Output: 1

Input: 9p 6p 1p

Output: 2

Input: 1s 4s 3s

Output: 1

Input: 3p 9p 2p

Output: 1

Input: 9s 1s 3s

Output: 1

Input: 4p 7p 7p

Output: 1

Input: 5m 3m 5m

Output: 1

Input: 5m 5m 8m

Output: 1

Input: 5p 6p 5p

Output: 1

Input: 8m 8m 6m

Output: 1

Input: 9p 2p 9p

Output: 1

Input: 8s 9s 8s

Output: 1

Input: 9m 1m 1m

Output: 1

Input: 7m 4m 9p

Output: 2

Input: 7p 5p 5m

Output: 1

Input: 5m 3m 9p

Output: 1

Input: 6p 8p 6s

Output: 1

Input: 2p 4m 2m

Output: 1

Input: 8s 2m 6s

Output: 1

Input: 6s 1p 8s

Output: 1

Input: 7m 7s 1s

Output: 2

Input: 2p 8s 2s

Output: 2

Input: 4s 1m 1s

Output: 2

Input: 2s 3m 3s

Output: 1

Input: 2s 2p 3s

Output: 1

Input: 2s 8p 3s

Output: 1

Input: 3m 3p 1p

Output: 1

Input: 3p 1p 2m

Output: 1

Input: 7s 9m 9s

Output: 1

Input: 1p 9s 7s

Output: 1

Input: 1m 2p 8m

Output: 2

Input: 8p 1m 1p

Output: 2

Input: 9m 8m 2p

Output: 1

Input: 9m 8s 9s

Output: 1

Input: 2m 9s 1m

Output: 1

Input: 1m 8s 9m

Output: 2

Input: 7p 7p 7m

Output: 1

Input: 2s 2p 2p

Output: 1

Input: 2s 8p 2s

Output: 1

Input: 8p 8p 1m

Output: 1

Input: 9p 9m 9m

Output: 1

Input: 1p 9m 1p

Output: 1

Input: 7p 7m 7s

Output: 2

Input: 8m 2s 7p

Output: 2

Input: 2m 2s 2p

Output: 2

Input: 2s 8p 2m

Output: 2

Input: 1p 1m 1s

Output: 2

Input: 1p 1m 9s

Output: 2

Input: 4m 7m 6m

Output: 1

Input: 1s 2s 3p

Output: 1

Input: 9s 9s 9s

Output: 0

Input: 1s 3s 9m

Output: 1

Input: 1s 1s 7s

Output: 1

Input: 5m 6m 7s

Output: 1

Input: 1s 2s 5s

Output: 1

Input: 1s 2p 3s

Output: 1

Input: 2s 4s 6s

Output: 1

Input: 1s 4s 7s

Output: 2

Input: 1m 5m 9m

Output: 2

Input: 9m 1m 2m

Output: 1

Input: 1p 2s 4s

Output: 1

Input: 3m 4p 5s

Output: 2

Input: 1m 3m 1s

Output: 1

Input: 1s 3s 2p

Output: 1

Input: 2p 3s 4p

Output: 1

Input: 7s 8s 9s

Output: 0

Input: 1m 4m 7m

Output: 2

Input: 1s 2s 4s

Output: 1

Input: 3s 4m 4s

Output: 1

Input: 1s 2m 3p

Output: 2

Input: 1s 2p 4p

Output: 1

Input: 1p 8s 9s

Output: 1

Input: 1m 1m 2m

Output: 1

Input: 1s 2s 3m

Output: 1

Input: 1s 3s 5s

Output: 1

Input: 3m 6m 7m

Output: 1

Input: 1s 2p 3m

Output: 2

Input: 8m 7s 9s

Output: 1

Input: 1s 3s 2s

Output: 0

Input: 3s 5s 7s

Output: 1

Input: 6s 4s 3s

Output: 1

Input: 4m 7s 5s

Output: 1

Input: 1s 3s 4s

Output: 1

Input: 3s 5s 1s

Output: 1

Input: 1p 5p 9p

Output: 2

Input: 1p 2p 4p

Output: 1

Input: 1s 1p 1p

Output: 1

Input: 1m 1s 2m

Output: 1

Input: 1p 2s 3m

Output: 2

Input: 1m 3m 5m

Output: 1

Input: 1m 1p 1s

Output: 2

Input: 5m 5p 6m

Output: 1

Input: 6p 8s 9s

Output: 1

Input: 9s 1s 2m

Output: 2

Input: 1s 3s 5p

Output: 1

Input: 1s 8m 9m

Output: 1

Input: 1m 2p 3s

Output: 2

Input: 1p 8m 9m

Output: 1