Vasya has a pile, that consists of some number of stones. $$$n$$$ times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.You are given $$$n$$$ operations which Vasya has made. Find the minimal possible number of stones that can be in the pile after making these operations.

NoteIn the first test, if Vasya had $$$3$$$ stones in the pile at the beginning, after making operations the number of stones will be equal to $$$0$$$. It is impossible to have less number of piles, so the answer is $$$0$$$. Please notice, that the number of stones at the beginning can't be less, than $$$3$$$, because in this case, Vasya won't be able to take a stone on some operation (the pile will be empty).In the second test, if Vasya had $$$0$$$ stones in the pile at the beginning, after making operations the number of stones will be equal to $$$4$$$. It is impossible to have less number of piles because after making $$$4$$$ operations the number of stones in the pile increases on $$$4$$$ stones. So, the answer is $$$4$$$.In the third test, if Vasya had $$$1$$$ stone in the pile at the beginning, after making operations the number of stones will be equal to $$$1$$$. It can be proved, that it is impossible to have less number of stones after making the operations.In the fourth test, if Vasya had $$$0$$$ stones in the pile at the beginning, after making operations the number of stones will be equal to $$$3$$$.

The first line contains one positive integer $$$n$$$ — the number of operations, that have been made by Vasya ($$$1 \leq n \leq 100$$$). The next line contains the string $$$s$$$, consisting of $$$n$$$ symbols, equal to "-" (without quotes) or "+" (without quotes). If Vasya took the stone on $$$i$$$-th operation, $$$s_i$$$ is equal to "-" (without quotes), if added, $$$s_i$$$ is equal to "+" (without quotes).

Print one integer — the minimal possible number of stones that can be in the pile after these $$$n$$$ operations.

Input:
3
---

Output: 0

Input:
4
++++

Output: 4

Input:
2
-+

Output: 1

Input:
5
++-++

Output: 3

Input:
1
+

Output: 1

Input:
100
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Output: 100

Input:
100
----------------------------------------------------------------------------------------------------

Output: 0

Input:
100
-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++++++++++-++++++++++++++++++++++++++++++++++-++++++++++++++++++++++

Output: 69

Input:
100
+-+-+-++--++-++-+-+---+--++++++-++++--++-++---+--++++--+++++++-++-+--+-+-+--+-+++++-+--+---+-++-++-+

Output: 17

Input:
100
++-+-+-+-+++-++++--+++----+-+-+-------+-+-++--++--+-+++++---+-++---++-+-++---+--+-+-++-++-+---++-+--

Output: 0

Input:
100
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

Output: 0

Input:
99
--+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------

Output: 1

Input:
100
+-----+-++++----++-+--+-+++-++--+--++---++++----+-+++--+++--+---++--++--++-+--+-+-+-+-+-+-+-++-+--+-

Output: 0

Input:
100
+++++--+-+++-+-++---+-++-+---++-------++-+--+-++-+--+-+--+-+-+----++-+-----++----++++-+-+---+--+--+-

Output: 0

Input:
100
-------+-++-------------+-----+--+----++----+-----+----+-----++-------------------+-+-------+-------

Output: 0

Input:
100
-+--+-++--+-+-+-+-+-+-+-+-++--++--+-+-+-+-+-+-+-+-+-+-+-++--+-+-+-+-+-+-+-++--+-+-+-+-+-+-+-+-+-+-+-

Output: 0

Input:
100
+-++--+-+-++--++-+++-++++----+--+---+-+-+-+-++--+-+-+-+-+-+-++--+-+-+-+-+-+-+-+++---+++-+-+-+---++--

Output: 0

Input:
100
-++------+---++++-+---++---+--+-++--+-+-++--+-+-++++-+++-+-----++-+--++-+++++---+-----+++---+-+-+-+-

Output: 0

Input:
100
------+---+--------+++--+--------------++--+----------+-+---+------+-+-----++---+------+-+---++-+---

Output: 0

Input:
100
-+--+++-++-+-+--++-++-------+-++--++----+--++-++------++--+++-+-+-+--+++---+----+--+++++-++----+---+

Output: 1

Input:
100
--+++--+---+-++--++-+--++++++--+-------+-+----+-++-+--+-+-+++---+++--+--+-+-+-+-++--++-++---++--+-++

Output: 2

Input:
99
-++-+-+++--++--+-+--++-+-++-+-----+---+++-+++++--+-+-+-+--+++-+++++---+-+--+----+---------+-+-+-++-

Output: 1

Input:
100
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++

Output: 2

Input:
100
---------------------------------------------------------------------------------------------------+

Output: 1

Input:
99
-+-++--------++--++----------------------------++-------++-+--+---------+-+--------+---+----------+

Output: 1

Input:
100
++--+-+-+-++--+-+-+-+-+-+-+-+-+-+-+-+-+-+-++-+--+-++--+-+-+-++--++--++--+-++--+-+-+-++--+-++--+-+-++

Output: 2

Input:
100
--+--++--+--++-+---++-+++-+--++-+-+++--+-----+++-+++-+-+-+--+---++-+-+-++-++---+---+-+-+++--+--+-++-

Output: 1

Input:
100
-----+-+-++--++++-+++---+-++--++-----+-+-+-+-++--+-+++-+--+-+++--+---+-+-++--+-+-+-++-++--+-+-+--+++

Output: 3

Input:
99
-+-+-+++--+--+-+-++--+-++--+++-+++-++-+++++-+-+-++----------+--++--++--++--+-++--+-+-+-++--+-+-++-+

Output: 2

Input:
100
--+---++++-+++-++-++----++-++-+-++--++-+--++++-++--+---+-++-+-+-+---+-+----------+-+--+--+--+++-++-+

Output: 4

Input:
100
+-+++--++++-+-++--+--+-++-------+---+-+---+++++++---+----+++-+-++--+-+--+-+-+--+-+-++-+---++-+-+++++

Output: 6

Input:
100
+---+++--+++--+--++--+--+---+-----+++-+++-+-+--+--+-+--++-+--+-+--+++--++---+-+-++-++-+-+++++++-+--+

Output: 8

Input:
100
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++++-+++++--+++

Output: 9

Input:
100
----------------------------------------------------------------------++++++++++++++++-++-++++++++++

Output: 26

Input:
100
--++---+---------+-++--+--++---------------+---------+---+----+-----+--------------+++++--++++-++-+-

Output: 7

Input:
100
+--+-+-+-+-+++--++---+-+-+-+-+-+-+-+-++--+-+-+-+-+-+-+-+-+-++--+-+-+-+-++--+-++-+-+-+-+-+-+-+-+-+-+-

Output: 1

Input:
100
+-++++--+-----++--+-++--++-+++-++-+-+++--+--++-----++---+-+-++++++++++++-++-+++-+++-+-+++++-+--+++++

Output: 24

Input:
100
-+-+---+-+-+-++-+--+-+++-+---+-++-+-+--++-+--+-+-+-+-+-++--+-+-++--+++++-+-++++++++++-++++++++++++++

Output: 27

Input:
100
-++-+-++----+++--+++++-+--++--++----+---+-++++++--+---+-+--+--+--+++++++++++++++++++++++++++++++++++

Output: 35

Input:
100
++++++++++++++++++++------------------------------++++++++++++++++++++++++++++++++++++++++++++++----

Output: 42

Input:
100
--------------------------------------------------++++++++++++++++++++++++++++++++++++++++++++++++++

Output: 50

Input:
100
----------++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Output: 90

Input:
100
--------------------------------------------------------------------------------------------------++

Output: 2

Input:
100
++--+-+-+-++++++++++++++--+-+++++++++-++++++++++++++++++++++-+-++++-+++++++++-+-+-+++-+++++++++-+++-

Output: 64

Input:
100
++++----------------++++-+---+++-++++++++++++++++++++++-++--+++++++-+-++++++++++++++++++++++++++++++

Output: 60

Input:
100
++++++-+++++++-++++++++++-++++++++++++++++++++++++-++++-++++++--+++-++++++++++++++++++++++++++-+-+++

Output: 80

Input:
100
--------------------++-+++---+-++--+-++--++--++--+-+-+++---+-+-++--+-+-+-+-+-+-+-+-+-+-+-++--+-+-+-+

Output: 2

Input:
100
-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Output: 99

Input:
100
+-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Output: 98

Input:
100
--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Output: 98

Input:
100
+-+-+-+-+-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Output: 90

Input:
89
+++-++-----+------+-+-++-----+-+------++--+-++++-+-++-+++++-+++-+-+--+++-+-+-++-+---+++-+

Output: 13

Input:
78
+++++++++-----------------------------------------------+++++++++++++---++++++

Output: 16

Input:
100
---+-----------+-++---+----------++++++++++++++++++++++++++++++++++++++++++++-----------------------

Output: 21

Input:
100
-----++--+-++-------+-+---++-+++-++++++++++++++-++-++-+-+++++++-+---++-+-+++++-++++++++++++++-+-++++

Output: 44

Input:
100
---+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Output: 97

Input:
99
-+-++--++++++--++++--+--------+-+--++--+--++-++++-+-+++++++-+-++++--+---+-+++---+--+---+++++-+-+--+

Output: 11

Input:
17
-++++--+-+----++-

Output: 1

Input:
73
+++-+-++-+++--+-----+++---+-+-++++-+++--+-+-++--++----+--+--+---+-++-+-+-

Output: 1

Input:
51
-++---+++++-+-++------+---+-++-+-+-+-++++-++++++-+-

Output: 9

Input:
98
----+-+--+-+-++-++++---+-++++-+--++-++++++-+++--+++-+-----+-+--+-----+++++--+-++-+++-+-+++-+---++-

Output: 11

Input:
100
+-+++-+++++-++--+++++++++-+-+-+--+++-+---+-+-+--+++-+-+-+-+-----++++++-+++++----++--+++-++--++---+--

Output: 16

Input:
100
++-+-+---+-+--+++++-++++++---++-+-----+++++----++++-+--+--+-+-+++-++-++-+---+-++-++-+-+-----+----+++

Output: 6

Input:
100
++-+++-+---+-++-+-++------+++-----++-++++-+-+-+----+++-++++------++++--+-+-+++--+---------++-+-+-+--

Output: 0

Input:
100
+-------+-+++-+++-++-+-----+----+----+-+----+-++--+++-+---++-++-+-+++-+----+++-+-----+--+-++----++++

Output: 4

Input:
4
--++

Output: 2

Input:
4
-++-

Output: 1

Input:
4
-+--

Output: 0

Input:
4
----

Output: 0

Input:
3
+-+

Output: 1

Input:
3
+--

Output: 0

Input:
3
++-

Output: 1

Input:
3
+++

Output: 3

Input:
3
-+-

Output: 0

Input:
3
--+

Output: 1

Input:
3
-++

Output: 2

Input:
2
++

Output: 2

Input:
2
+-

Output: 0

Input:
2
--

Output: 0

Input:
1
-

Output: 0

Input:
5
--+--

Output: 0

Input:
4
-+--

Output: 0


You are planning to build housing on a street. There are $$$n$$$ spots available on the street on which you can build a house. The spots are labeled from $$$1$$$ to $$$n$$$ from left to right. In each spot, you can build a house with an integer height between $$$0$$$ and $$$h$$$.In each spot, if a house has height $$$a$$$, you will gain $$$a^2$$$ dollars from it.The city has $$$m$$$ zoning restrictions. The $$$i$$$-th restriction says that the tallest house from spots $$$l_i$$$ to $$$r_i$$$ (inclusive) must be at most $$$x_i$$$.You would like to build houses to maximize your profit. Determine the maximum profit possible.

NoteIn the first example, there are $$$3$$$ houses, the maximum height of a house is $$$3$$$, and there are $$$3$$$ restrictions. The first restriction says the tallest house between $$$1$$$ and $$$1$$$ must be at most $$$1$$$. The second restriction says the tallest house between $$$2$$$ and $$$2$$$ must be at most $$$3$$$. The third restriction says the tallest house between $$$3$$$ and $$$3$$$ must be at most $$$2$$$.In this case, it is optimal to build houses with heights $$$[1, 3, 2]$$$. This fits within all the restrictions. The total profit in this case is $$$1^2 + 3^2 + 2^2 = 14$$$.In the second example, there are $$$4$$$ houses, the maximum height of a house is $$$10$$$, and there are $$$2$$$ restrictions. The first restriction says the tallest house from $$$2$$$ to $$$3$$$ must be at most $$$8$$$. The second restriction says the tallest house from $$$3$$$ to $$$4$$$ must be at most $$$7$$$.In this case, it's optimal to build houses with heights $$$[10, 8, 7, 7]$$$. We get a profit of $$$10^2+8^2+7^2+7^2 = 262$$$. Note that there are two restrictions on house $$$3$$$ and both of them must be satisfied. Also, note that even though there isn't any explicit restrictions on house $$$1$$$, we must still limit its height to be at most $$$10$$$ ($$$h=10$$$).

The first line contains three integers $$$n$$$, $$$h$$$, and $$$m$$$ ($$$1 \leq n,h,m \leq 50$$$) — the number of spots, the maximum height, and the number of restrictions. Each of the next $$$m$$$ lines contains three integers $$$l_i$$$, $$$r_i$$$, and $$$x_i$$$ ($$$1 \leq l_i \leq r_i \leq n$$$, $$$0 \leq x_i \leq h$$$) — left and right limits (inclusive) of the $$$i$$$-th restriction and the maximum possible height in that range.

Print a single integer, the maximum profit you can make.

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

Output: 14

Input:
4 10 2
2 3 8
3 4 7

Output: 262

Input:
50 50 1
1 50 0

Output: 0

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

Output: 4384

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

Output: 1111

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

Output: 1786

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

Output: 2711

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

Output: 3477

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

Output: 2960

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

Output: 432

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

Output: 6751

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

Output: 1243

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

Output: 2167

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

Output: 1022

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

Output: 94

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

Output: 2327

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

Output: 2979

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

Output: 498

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

Output: 3080

Input:
20 50 20
4 5 18
14 15 32
6 13 46
13 19 39
2 8 18
15 16 29
2 8 9
1 2 23
1 8 8
18 18 11
10 16 3
9 18 44
9 19 31
2 3 19
4 19 12
10 17 24
9 13 20
4 7 10
12 20 24
3 19 19

Output: 1704

Input:
50 20 20
4 15 1
26 31 15
28 40 5
16 42 1
10 26 10
42 42 1
21 49 4
24 50 10
7 32 12
5 38 18
36 41 14
16 44 2
23 33 4
18 19 15
14 21 14
18 28 16
29 38 13
6 17 10
6 44 2
17 45 1

Output: 1406

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

Output: 102

Input:
20 50 20
3 9 4
4 7 11
9 14 31
1 6 17
5 13 33
17 19 11
13 14 10
4 12 16
8 19 46
8 19 7
11 20 32
3 18 39
1 12 31
4 16 15
2 15 38
1 2 33
2 11 25
7 14 17
3 14 45
15 18 50

Output: 2204

Input:
50 20 20
19 49 15
8 29 12
28 33 20
5 40 14
1 45 14
15 50 17
20 44 17
11 18 15
20 40 6
16 21 6
12 31 10
29 49 5
20 44 17
16 41 10
3 30 9
8 36 10
45 48 5
6 27 12
35 44 8
21 42 16

Output: 2727

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

Output: 86

Input:
20 50 20
5 9 16
17 17 15
2 4 15
6 20 22
3 16 48
11 13 46
2 3 37
7 9 8
16 20 7
11 19 3
6 19 11
3 18 34
7 19 5
7 17 37
4 16 12
13 16 42
18 20 4
3 8 50
9 14 15
17 19 5

Output: 3556

Input:
50 20 20
22 39 19
23 37 18
16 38 9
30 49 15
14 31 5
1 29 16
10 46 9
27 40 16
3 42 1
33 38 6
18 40 6
3 34 5
8 23 14
5 9 14
4 34 8
1 48 16
4 15 18
9 46 18
18 29 14
25 47 20

Output: 1951

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

Output: 347

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

Output: 3


The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now $$$n$$$ cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are $$$m$$$ cats who left the circle. This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?Could you help her with this curiosity?You can see the examples and their descriptions with pictures in the "Note" section.

NoteIn the first example, originally there are $$$7$$$ cats sitting as shown below, creating a single group:  At the observed moment, $$$4$$$ cats have left the table. Suppose the cats $$$2$$$, $$$3$$$, $$$5$$$ and $$$7$$$ have left, then there are $$$3$$$ groups remaining. It is possible to show that it is the maximum possible number of groups remaining.  In the second example, there are $$$6$$$ cats sitting as shown below:  At the observed moment, $$$2$$$ cats have left the table. Suppose the cats numbered $$$3$$$ and $$$6$$$ left, then there will be $$$2$$$ groups remaining ($$$\{1, 2\}$$$ and $$$\{4, 5\}$$$). It is impossible to have more than $$$2$$$ groups of cats remaining.  In the third example, no cats have left, so there is $$$1$$$ group consisting of all cats.In the fourth example, all cats have left the circle, so there are $$$0$$$ groups.

The only line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 1000$$$, $$$0 \leq m \leq n$$$) — the initial number of cats at the party and the number of cats who left the circle at the moment Katie observes, respectively.

Print a single integer — the maximum number of groups of cats at the moment Katie observes.

Input: 7 4

Output: 3

Input: 6 2

Output: 2

Input: 3 0

Output: 1

Input: 2 2

Output: 0

Input: 9 1

Output: 1

Input: 2 0

Output: 1

Input: 543 110

Output: 110

Input: 924 576

Output: 348

Input: 1000 972

Output: 28

Input: 846 0

Output: 1

Input: 806 100

Output: 100

Input: 268 121

Output: 121

Input: 729 501

Output: 228

Input: 190 34

Output: 34

Input: 571 402

Output: 169

Input: 469 217

Output: 217

Input: 930 307

Output: 307

Input: 829 124

Output: 124

Input: 210 208

Output: 2

Input: 109 63

Output: 46

Input: 880 113

Output: 113

Input: 698 336

Output: 336

Input: 160 0

Output: 1

Input: 59 33

Output: 26

Input: 82 0

Output: 1

Input: 980 632

Output: 348

Input: 361 300

Output: 61

Input: 822 597

Output: 225

Input: 721 343

Output: 343

Input: 182 67

Output: 67

Input: 311 3

Output: 3

Input: 772 618

Output: 154

Input: 670 83

Output: 83

Input: 132 128

Output: 4

Input: 950 4

Output: 4

Input: 973 799

Output: 174

Input: 872 872

Output: 0

Input: 333 246

Output: 87

Input: 1000 1000

Output: 0

Input: 1000 843

Output: 157

Input: 1000 488

Output: 488

Input: 7 3

Output: 3

Input: 5 2

Output: 2

Input: 3 2

Output: 1

Input: 3 1

Output: 1

Input: 2 1

Output: 1

Input: 7 6

Output: 1

Input: 6 3

Output: 3

Input: 4 3

Output: 1

Input: 4 0

Output: 1

Input: 4 1

Output: 1

Input: 4 2

Output: 2

Input: 4 4

Output: 0

Input: 3 3

Output: 0


The only difference between easy and hard versions is constraints.Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions — and he won't start playing until he gets all of them.Each day (during the morning) Ivan earns exactly one burle.There are $$$n$$$ types of microtransactions in the game. Each microtransaction costs $$$2$$$ burles usually and $$$1$$$ burle if it is on sale. Ivan has to order exactly $$$k_i$$$ microtransactions of the $$$i$$$-th type (he orders microtransactions during the evening).Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for $$$1$$$ burle and otherwise he can buy it for $$$2$$$ burles.There are also $$$m$$$ special offers in the game shop. The $$$j$$$-th offer $$$(d_j, t_j)$$$ means that microtransactions of the $$$t_j$$$-th type are on sale during the $$$d_j$$$-th day.Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of types of microtransactions and the number of special offers in the game shop. The second line of the input contains $$$n$$$ integers $$$k_1, k_2, \dots, k_n$$$ ($$$0 \le k_i \le 1000$$$), where $$$k_i$$$ is the number of copies of microtransaction of the $$$i$$$-th type Ivan has to order. It is guaranteed that sum of all $$$k_i$$$ is not less than $$$1$$$ and not greater than $$$1000$$$. The next $$$m$$$ lines contain special offers. The $$$j$$$-th of these lines contains the $$$j$$$-th special offer. It is given as a pair of integers $$$(d_j, t_j)$$$ ($$$1 \le d_j \le 1000, 1 \le t_j \le n$$$) and means that microtransactions of the $$$t_j$$$-th type are on sale during the $$$d_j$$$-th day.

Print one integer — the minimum day when Ivan can order all microtransactions he wants and actually start playing.

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

Output: 8

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

Output: 20

Input:
200000 200000
0 1 0 0 1 0 3 0 0 1 0 0 4 2 1 2 2 0 1 1 1 0 2 0 0 1 0 1 2 0 0 0 1 0 1 1 1 1 2 1 3 0 2 2 0 1 1 1 1 1 0 1 0 1 0 0 0 1 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 2 0 1 0 0 1 1 0 0 1 0 1 1 2 0 1 0 0 2 1 1 1 0 1 0 1 1 1 0 1 1 3 2 1 0 0 1 0 2 1 0 0 3 1 0 1 2 2 0 1 0 0 0 2 1 1 1 1 0 0 1 0 2 1 0 3 0 1 2 2 1 0 2 2 0 0 2 1 1 0 0 0 1 0 2 2 1 0 0 1 3 1 1 1 1 1 2 2 1 1 0 1 0 2 1 1 0 3 1 0 0 0 2 2 2 0 1 0 0 1 1 1 0 0 0 1 2 2 0 1 3 0 1 0 1 2 1 2 0 0 0 1 0 1 0 1 3 0 1 1 2 0 0 0 0 1 0 3 0 0 0 1 1 3 2 1 0 0 0 0 1 0 0 1 ...

Output: 273419

Input:
200000 1
2 2 0 0 0 2 3 0 1 0 1 0 1 0 1 2 3 1 3 1 0 3 0 0 1 1 0 1 1 0 1 1 1 0 1 0 0 0 0 1 1 2 1 1 2 0 0 3 0 2 0 0 0 0 1 0 2 0 0 0 0 1 0 3 1 1 1 0 1 1 1 3 0 0 1 0 1 1 1 1 1 1 2 2 2 0 3 1 3 3 2 0 0 0 2 2 0 1 1 1 1 0 0 1 2 0 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
10 52
4 63
9 35
10 67
9 17
3 43
4 38
1 27
9 44
6 74
7 3
8 18
1 52
1 68
5 51
5 2
7 50
1 72
1 37
8 64
10 30
2 68
1 59
5 12
9 11
10 23
2 51
10 56
6 17
1 49
3 20
10 62
10 40

Output: 1

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

Output: 13

Input:
1 200000
200000
40889 1
23423 1
97080 1
17666 1
12410 1
94109 1
50353 1
40581 1
50934 1
26869 1
65638 1
8810 1
27584 1
89064 1
584 1
90003 1
32072 1
38839 1
49610 1
87233 1
16127 1
4580 1
27771 1
85526 1
2774 1
90032 1
6284 1
39312 1
86302 1
37594 1
39792 1
80915 1
83081 1
68197 1
42229 1
27327 1
28422 1
7954 1
31951 1
30644 1
4552 1
61921 1
37165 1
34837 1
43359 1
27379 1
93505 1
90113 1
73372 1
9354 1
82587 1
98459 1
81584 1
28166 1
38381 1
3682 1
...

Output: 300000

Input:
2 200000
100075 99925
1 2
2 1
2 1
2 1
2 1
1 2
2 2
2 2
1 2
1 1
1 1
1 2
1 1
1 1
1 2
1 1
1 1
2 2
2 2
1 1
1 1
1 1
1 2
1 2
2 1
2 2
2 2
1 2
1 1
2 2
1 2
1 1
2 2
2 1
2 1
1 2
2 2
2 2
2 2
2 1
2 1
2 1
2 2
2 1
2 2
1 2
2 1
1 2
1 2
1 2
1 2
1 1
2 1
1 2
2 2
2 2
1 1
2 2
2 1
2 1
1 1
1 2
1 1
1 2
2 1
1 1
1 1
2 1
1 1
2 1
1 2
1 1
1 2
1 1
1 2
2 2
1 2
2 1
1 2
1 1
2 1
1 2
2 2
2 2
1 2
1 2
2 1
2 2
1 2
1 2
2 2
1 1
2 1
1 1
2 1
1 1
2 1
2 ...

Output: 399998

Input:
2 200000
99901 100099
1 1
1 1
1 1
1 2
1 2
1 1
1 1
1 2
1 1
1 2
1 2
1 1
1 2
1 2
1 2
1 2
1 1
1 1
1 1
1 1
1 1
1 2
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 1
1 2
1 1
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 1
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 1
1 2
1 1
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 1
1 1
1 1
1 2
1 1
1 1
1 2
1 2
1 1
1 2
1 2
1 2
1 2
1 2
1 1
1 2
1 2
1 2
1 1
1 1
1 1
1 2
1 1
1 1
1 2
1 2
1 1
1 2
1 2
1 1
1 2
1 1
1 ...

Output: 399999

Input:
2 200000
99784 100216
8964 1
61385 1
94316 2
74596 1
92702 2
70164 2
57662 1
11176 2
41157 1
1315 1
15775 1
2299 2
65838 2
55675 1
50885 2
64353 2
71309 1
51168 2
27779 1
84032 2
19672 2
10137 2
48400 2
79516 2
30692 1
67114 2
29920 1
88762 2
38693 2
52119 1
48744 2
59776 1
66865 2
49191 2
94365 1
84402 2
16701 1
10589 2
74197 1
6614 1
47709 2
56096 1
93411 2
6545 2
18184 2
73235 1
8670 1
21062 1
25744 2
85661 1
37659 1
34589 2
10637 1
22625 2
70957 1...

Output: 300000

Input:
40 69
0 0 1 2 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0
11 24
15 40
14 17
23 5
5 22
22 37
28 3
1 6
10 6
31 33
11 4
22 5
12 5
23 25
8 35
21 5
18 31
10 2
19 36
33 29
3 2
32 9
10 20
1 2
27 2
30 18
28 40
26 39
23 5
26 27
19 37
1 3
19 24
11 17
17 9
2 18
15 7
5 9
25 23
32 26
9 32
24 24
6 37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 1 3 0 1 2 0 2 1 0 0 1 0 1 1 4 0 2 0 1 1 1 1 1 1 0 0 0 0 0 1 1 2 1 3 1 1 3 0 0 1 1 1 0 2 0 0 1 1 3 0 2 1 0 0 0 0 2 1 1 1 1 2 1 1 2 0 2 1 0 2 0 0 1 0 0 3 2 0 1 0 1 1 1 0 1 0 0 1 0 1 0 1 2 0 1 0 1 0 0 1 1 0 0 4 1 0 2 0 0 2 0 0 1 2 3 0 0 0 3 0 0 0 0 0 2 0 1 2 ...

Output: 1301

Input:
1000 1000
3 1 3 2 0 1 1 3 0 1 1 1 1 0 3 0 1 1 1 2 3 0 1 0 0 1 2 0 1 1 1 0 1 0 0 0 0 1 2 0 1 0 1 0 1 0 2 1 1 1 2 1 2 0 0 2 1 2 0 0 0 1 0 0 1 0 1 1 3 1 1 1 1 0 2 2 1 1 0 0 0 1 1 2 0 1 1 1 0 2 3 1 0 0 1 2 1 1 2 1 2 4 0 1 3 0 0 0 1 1 1 1 3 1 0 0 1 1 1 0 0 3 1 1 1 0 3 0 0 0 1 1 2 0 1 1 4 1 2 1 0 1 1 1 1 2 2 1 2 1 0 1 0 1 1 0 0 0 2 0 1 1 2 1 1 1 3 1 3 1 0 3 1 2 1 1 0 1 1 0 2 0 0 1 1 0 0 0 0 1 1 3 2 0 3 1 0 0 0 1 0 1 2 1 0 1 2 0 2 2 0 0 1 0 2 0 2 1 1 3 0 3 0 0 3 0 1 0 2 1 0 2 1 1 0 1 0 1 1 2 1 0 1 0 0 2 0 0 0 3 ...

Output: 1500

Input:
1 1000
1000
334 1
406 1
226 1
190 1
155 1
434 1
3 1
435 1
322 1
480 1
361 1
388 1
288 1
449 1
10 1
218 1
44 1
90 1
69 1
378 1
400 1
11 1
364 1
345 1
35 1
390 1
488 1
413 1
114 1
292 1
478 1
234 1
53 1
249 1
272 1
161 1
1 1
491 1
281 1
415 1
352 1
367 1
255 1
198 1
467 1
229 1
323 1
46 1
109 1
276 1
289 1
92 1
438 1
430 1
128 1
465 1
388 1
3 1
448 1
346 1
338 1
150 1
446 1
69 1
153 1
117 1
347 1
125 1
345 1
417 1
199 1
29 1
400 1
6 1...

Output: 1500

Input:
2 1000
499 501
2 1
2 2
1 1
2 1
2 1
1 1
2 2
1 1
1 1
2 2
2 1
1 2
2 1
1 2
1 2
1 2
2 1
1 2
1 1
2 1
2 1
1 1
2 2
2 2
1 2
1 2
2 2
1 1
2 1
2 2
1 1
1 2
2 2
1 1
1 1
1 1
2 2
2 2
2 1
2 2
2 2
1 2
2 2
1 1
1 2
1 2
2 2
1 2
1 1
1 1
2 1
1 2
2 2
2 1
1 1
1 1
1 1
2 2
1 2
1 1
1 1
2 1
1 1
1 2
1 1
1 2
1 2
2 2
2 1
1 2
1 2
1 1
2 2
2 2
1 1
2 1
1 2
1 2
1 1
1 1
2 2
1 1
2 1
1 1
1 1
2 1
2 1
1 1
1 2
1 2
2 1
1 1
1 2
2 1
2 2
2 1
2 2
2 1
1 1
...

Output: 1998

Input:
2 1000
488 512
1 1
1 1
1 2
1 1
1 2
1 1
1 1
1 2
1 2
1 2
1 1
1 2
1 1
1 1
1 1
1 2
1 1
1 2
1 1
1 2
1 2
1 1
1 2
1 1
1 1
1 2
1 2
1 2
1 1
1 1
1 2
1 2
1 2
1 1
1 1
1 2
1 1
1 1
1 1
1 1
1 2
1 1
1 2
1 2
1 1
1 1
1 1
1 2
1 1
1 1
1 1
1 2
1 1
1 1
1 2
1 1
1 1
1 1
1 2
1 2
1 1
1 2
1 2
1 2
1 2
1 2
1 1
1 2
1 2
1 2
1 1
1 1
1 2
1 2
1 1
1 2
1 1
1 2
1 1
1 2
1 2
1 2
1 2
1 2
1 2
1 1
1 1
1 1
1 2
1 1
1 1
1 1
1 2
1 1
1 1
1 1
1 1
1 2
1 2
...

Output: 1999

Input:
2 1000
472 528
461 2
424 1
391 2
361 2
118 2
357 1
405 1
400 1
454 1
289 1
122 1
352 1
334 1
79 1
416 2
189 2
161 1
350 2
449 2
249 2
274 2
140 2
113 1
76 2
403 1
355 1
366 2
368 1
393 1
134 1
379 1
77 1
69 2
244 2
163 2
333 1
363 1
248 1
130 2
457 2
242 2
381 2
230 1
200 1
281 2
46 1
367 1
14 2
73 2
2 1
358 2
306 2
73 1
497 2
104 2
449 2
16 2
291 2
130 2
369 1
8 1
215 1
22 1
439 2
250 1
204 1
236 1
99 1
10 1
1 2
389 1
386 1
311 1
1...

Output: 1500

Input:
1000 1
1 1 1 0 1 1 1 0 1 0 1 2 1 2 1 1 2 2 0 0 0 3 0 0 1 0 0 4 0 3 0 0 3 2 0 1 2 1 0 4 1 0 2 3 1 1 0 1 4 1 1 2 0 0 1 0 0 1 1 2 0 1 0 0 2 2 1 1 1 0 1 0 0 0 1 4 2 1 0 1 1 0 3 0 2 0 0 2 0 1 2 1 1 1 0 2 1 2 0 0 2 0 1 0 0 0 1 4 1 0 0 1 0 1 1 1 0 1 0 1 4 3 0 3 0 1 1 1 0 2 1 0 0 1 0 2 1 1 1 2 1 1 1 4 2 3 0 2 2 2 0 0 1 1 4 0 1 1 0 2 1 1 1 2 2 1 1 0 0 3 1 1 2 1 2 2 2 0 5 1 0 1 1 0 0 0 1 1 2 0 2 0 1 0 1 1 2 1 1 1 0 0 1 2 0 1 0 0 3 0 1 2 0 0 1 3 2 2 0 1 0 2 0 1 1 2 1 3 0 0 0 1 0 2 0 0 1 2 0 1 0 3 0 2 2 1 3 1 2 1 1 1...

Output: 1999

Input:
1000 10
1 4 1 2 1 0 3 0 0 2 0 1 0 1 1 0 1 1 0 0 1 0 1 2 3 1 0 2 0 0 3 2 1 1 1 1 0 2 2 0 0 0 0 0 1 0 3 1 2 1 0 0 0 2 1 2 1 1 1 0 3 1 1 2 2 2 1 2 0 1 0 0 0 1 1 0 1 1 0 1 2 0 2 2 1 0 0 1 0 1 1 1 1 1 0 1 4 0 4 1 0 0 1 2 0 3 1 1 0 1 3 0 0 3 1 0 0 0 2 3 2 1 2 0 1 1 0 1 0 0 1 1 4 1 1 0 0 1 1 1 2 1 0 2 1 1 2 0 1 0 0 1 1 0 1 0 1 1 4 3 0 2 1 1 0 1 1 2 0 1 1 2 0 0 3 1 2 2 1 0 2 0 1 0 3 0 4 1 1 1 1 2 1 1 0 2 1 0 2 1 1 1 1 0 0 3 0 0 0 1 0 0 0 1 2 1 1 0 3 1 2 1 0 0 2 1 1 1 2 1 1 3 1 1 0 0 3 2 2 1 3 1 2 2 0 2 1 0 1 0 0 ...

Output: 1986


The circle line of the Roflanpolis subway has $$$n$$$ stations.There are two parallel routes in the subway. The first one visits stations in order $$$1 \to 2 \to \ldots \to n \to 1 \to 2 \to \ldots$$$ (so the next stop after station $$$x$$$ is equal to $$$(x+1)$$$ if $$$x < n$$$ and $$$1$$$ otherwise). The second route visits stations in order $$$n \to (n-1) \to \ldots \to 1 \to n \to (n-1) \to \ldots$$$ (so the next stop after station $$$x$$$ is equal to $$$(x-1)$$$ if $$$x>1$$$ and $$$n$$$ otherwise). All trains depart their stations simultaneously, and it takes exactly $$$1$$$ minute to arrive at the next station.Two toads live in this city, their names are Daniel and Vlad.Daniel is currently in a train of the first route at station $$$a$$$ and will exit the subway when his train reaches station $$$x$$$.Coincidentally, Vlad is currently in a train of the second route at station $$$b$$$ and he will exit the subway when his train reaches station $$$y$$$.Surprisingly, all numbers $$$a,x,b,y$$$ are distinct.Toad Ilya asks you to check if Daniel and Vlad will ever be at the same station at the same time during their journey. In other words, check if there is a moment when their trains stop at the same station. Note that this includes the moments when Daniel or Vlad enter or leave the subway.

NoteIn the first example, Daniel and Vlad start at the stations $$$(1, 3)$$$. One minute later they are at stations $$$(2, 2)$$$. They are at the same station at this moment. Note that Vlad leaves the subway right after that.Consider the second example, let's look at the stations Vlad and Daniel are at. They are:   initially $$$(2, 9)$$$,  after $$$1$$$ minute $$$(3, 8)$$$,  after $$$2$$$ minutes $$$(4, 7)$$$,  after $$$3$$$ minutes $$$(5, 6)$$$,  after $$$4$$$ minutes $$$(6, 5)$$$,  after $$$5$$$ minutes $$$(7, 4)$$$,  after $$$6$$$ minutes $$$(8, 3)$$$,  after $$$7$$$ minutes $$$(9, 2)$$$,  after $$$8$$$ minutes $$$(10, 1)$$$,  after $$$9$$$ minutes $$$(1, 10)$$$. After that, they both leave the subway because they are at their finish stations, so there is no moment when they both are at the same station.

The first line contains five space-separated integers $$$n$$$, $$$a$$$, $$$x$$$, $$$b$$$, $$$y$$$ ($$$4 \leq n \leq 100$$$, $$$1 \leq a, x, b, y \leq n$$$, all numbers among $$$a$$$, $$$x$$$, $$$b$$$, $$$y$$$ are distinct) — the number of stations in Roflanpolis, Daniel's start station, Daniel's finish station, Vlad's start station and Vlad's finish station, respectively.

Output "YES" if there is a time moment when Vlad and Daniel are at the same station, and "NO" otherwise. You can print each letter in any case (upper or lower).

Input: 5 1 4 3 2

Output: YES

Input: 10 2 1 9 10

Output: NO

Input: 4 3 4 2 1

Output: NO

Input: 100 2 97 84 89

Output: YES

Input: 100 43 55 42 15

Output: NO

Input: 47 15 45 28 38

Output: YES

Input: 17 14 2 12 10

Output: NO

Input: 82 9 11 15 79

Output: NO

Input: 53 10 34 1 48

Output: NO

Input: 55 55 27 45 50

Output: NO

Input: 33 15 6 1 3

Output: NO

Input: 45 26 22 39 10

Output: YES

Input: 5 3 2 4 1

Output: YES

Input: 20 19 10 17 8

Output: YES

Input: 100 26 63 60 23

Output: YES

Input: 7 2 5 6 3

Output: YES

Input: 50 22 39 33 9

Output: NO

Input: 50 40 10 4 34

Output: YES

Input: 5 3 1 2 4

Output: YES

Input: 4 1 2 3 4

Output: YES

Input: 4 1 2 4 3

Output: NO

Input: 4 1 3 2 4

Output: NO

Input: 4 1 3 4 2

Output: NO

Input: 4 1 4 2 3

Output: NO

Input: 4 1 4 3 2

Output: YES

Input: 4 2 1 3 4

Output: NO

Input: 4 2 1 4 3

Output: YES

Input: 4 2 3 1 4

Output: NO

Input: 4 2 3 4 1

Output: YES

Input: 4 2 4 1 3

Output: NO

Input: 4 2 4 3 1

Output: NO

Input: 4 3 1 2 4

Output: NO

Input: 4 3 1 4 2

Output: NO

Input: 4 3 2 1 4

Output: YES

Input: 4 3 2 4 1

Output: NO

Input: 4 3 4 1 2

Output: YES

Input: 4 4 1 2 3

Output: YES

Input: 4 4 1 3 2

Output: NO

Input: 4 4 2 1 3

Output: NO

Input: 4 4 2 3 1

Output: NO

Input: 4 4 3 1 2

Output: NO

Input: 4 4 3 2 1

Output: YES

Input: 10 9 10 3 4

Output: NO

Input: 60 1 50 51 49

Output: NO

Input: 10 1 4 3 9

Output: YES

Input: 9 7 2 6 8

Output: YES

Input: 5 4 2 1 5

Output: YES

Input: 5 4 2 1 3

Output: YES

Input: 5 3 1 2 4

Output: YES

Input: 6 4 3 6 5

Output: YES

Input: 10 10 9 6 7

Output: YES

Input: 5 1 3 2 5

Output: NO

Input: 5 5 4 1 2

Output: YES

Input: 10 5 10 3 1

Output: NO

Input: 7 5 3 2 4

Output: YES

Input: 6 4 1 2 5

Output: YES

Input: 5 2 1 4 5

Output: YES

Input: 7 1 6 5 2

Output: YES

Input: 13 1 9 2 13

Output: NO

Input: 10 1 4 5 2

Output: YES

Input: 6 3 1 5 2

Output: YES

Input: 43 41 39 40 1

Output: YES

Input: 8 7 2 3 5

Output: YES

Input: 10 2 5 8 4

Output: YES

Input: 8 1 4 5 6

Output: YES

Input: 100 1 5 20 2

Output: NO

Input: 6 5 6 3 4

Output: NO

Input: 10 9 10 5 8

Output: NO

Input: 6 5 6 3 1

Output: NO

Input: 7 7 1 2 6

Output: YES

Input: 10 2 4 7 3

Output: NO

Input: 6 3 2 5 1

Output: YES

Input: 6 5 2 3 1

Output: YES

Input: 91 36 25 5 91

Output: NO

Input: 90 1 2 5 4

Output: NO

Input: 5 4 5 3 1

Output: NO

Input: 5 5 4 1 3

Output: YES

Input: 7 5 3 1 2

Output: YES

Input: 5 5 1 2 3

Output: YES

Input: 24 14 23 18 21

Output: YES

Input: 10 9 10 1 8

Output: YES

Input: 20 19 2 1 20

Output: YES

Input: 7 1 5 4 7

Output: NO

Input: 20 19 2 1 18

Output: YES

Input: 5 5 1 2 4

Output: YES