TSEC Round 2 (Div. 3)
A. The world of JS (Jagjeet & Sagar)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Jagjeet is a famous personality in TSEC people are mad to meet him. But there's someone for whom Jagjeet is mad.......that's his best friend Sagar. Both of them like to play cricket. But Sagar is very busy unlike Jagjeet. At time $$$a$$$ (in seconds) Sagar is busy. Then every $$$b$$$ seconds after it, he is busy for $$$b$$$ and $$$b+1$$$ interval. Thus it sagar is busy at times a, a+b, a+b+1, a+2b, a+2b+1, etc.

Jagjeet is very desperate for playing cricket, but he wants to play with sagar when he is busy. Jagjeet plans to play at time $$$c$$$ (in seconds), so he asked you to tell him if sagar is busy at that time.

Input

The first line of input contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of test cases.

The only line of each test contains 3 integers, $$$a$$$, $$$b$$$, $$$c$$$, ($$$1 \leq a, b, c \leq 10^9$$$)

Output

Print a single "YES" (without quotes) if it's possible to play for both of them at time $$$c$$$ or a single "NO" (without quotes) otherwise in the only line of output.

Example
Input
10
3 2 6
1 1 1
8 7 10
2 9 8
3 4 6
1 5 6
8 9 4
7 5 3
10 8 3
1 4 1
Output
Yes
Yes
No
No
No
Yes
No
No
No
Yes

B. Divisor Query
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Lets see how well u know your divisors, you are given q queries of two types

  • Type 1: $$$1~l~r$$$ — Return number of values having odd number of divisors between $$$l$$$ and $$$r$$$
  • Type 2: $$$2~l~r$$$ — Return number of values having even number of divisors between $$$l$$$ and $$$r$$$
Input

The first line contains one integer $$$q$$$ ($$$1 \leq q \leq 10^6$$$) — the number of queries.

Then, the next $$$q$$$ lines contain the following types of queries:

  • Type 1: $$$1~l~r$$$ — ($$$1 \leq l, r \leq 10^9$$$)
  • Type 2: $$$2~l~r$$$ — ($$$1 \leq l, r \leq 10^9$$$)
Output

For each query of type 1, return the number of numbers having odd number of divisors, and for each of type 2, return the number of numbers having even number of divisors

Example
Input
20
1 97 183
1 57 71
1 57 91
2 14 93
2 23 81
1 73 154
2 79 143
1 82 110
2 67 132
1 23 63
1 83 145
2 14 18
1 73 132
1 34 67
1 48 82
1 96 193
2 3 19
2 62 151
2 66 134
1 76 119
Output
4
1
2
74
54
4
62
1
63
3
3
4
3
3
3
4
14
85
66
2

D. Hard Work
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string of n characters

You need to find the length of the shortest substring that contains all letters 'h', 'a', 'r', 'd', 'w', 'o', 'r', 'k' in any order

Note that you the substring needs to contain two 'r'

If no substring exists which contains all these letters, print -1

Input

First line consists of a single integer t, number of tests ($$$1 \leq t \leq 1000$$$)

First line of each test consists of single integer n, size of string ($$$1 \leq n \leq 10^5$$$)

Second line of each test consists of the word

Output

For each test, print the length of the shortest substring that contains the letters 'h', 'a', 'r', 'd', 'w', 'o', 'r', 'k'

Example
Input
9
8
hardwork
7
hardwok
15
rwkrhhkkaokdrrw
15
kdrrwdoaahdoadw
15
dwororaohrkaaor
15
hhawdkowdhwarak
15
rarraakhaorkadh
15
rkrwawoarkrkdhk
15
woaodkdaoadrwdw
Output
8
-1
10
10
11
-1
-1
9
-1

E. Anime Marathon: Vivek vs. Sagar
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vivek and Sagar are at an anime marathon, where there are $$$n$$$ anime episodes lined up for them to watch. Each anime episode has a unique enjoyment value, denoted as $$$a_i$$$ for the $$$i$$$-th episode.

The two friends take turns watching episodes, with Vivek going first:

  • On his turn, Vivek can only watch an episode whose enjoyment value is strictly greater than the highest enjoyment value of all the episodes he has already watched. On his first turn, he can pick any episode he likes.
  • On his turn, Sagar picks any of the remaining episodes and watches it, without any restrictions on the enjoyment value.

The marathon continues until neither can select a suitable episode to watch. Let $$$x$$$ represent the total number of episodes Vivek manages to watch. While Vivek is eager to watch as many episodes as possible, Sagar's goal is to minimize the number of episodes Vivek gets to enjoy.

Determine how many episodes Vivek will end up watching if both play optimally.

Input

Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 15$$$) — the number of episodes.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the enjoyment value of the episode.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$15$$$.

Output

For each test case, output a single integer — the number of episodes Vivek will watch if both players play optimally.

Example
Input
10
15
11 8 7 8 3 15 7 15 2 1 1 9 8 2 4
15
11 14 15 1 14 4 1 1 13 8 2 6 1 15 12
15
9 3 9 12 15 5 15 2 1 15 5 14 4 6 9
15
6 15 11 7 12 3 1 13 5 15 10 5 4 4 3
15
13 6 2 4 13 4 8 7 11 11 13 15 7 10 2
15
5 13 15 13 7 5 7 5 4 15 1 8 14 1 12
15
7 3 9 13 4 9 4 1 8 8 11 13 2 8 9
15
15 6 4 12 2 3 14 8 11 8 8 14 3 3 11
15
8 8 2 15 1 10 8 2 10 9 10 12 2 13 7
15
3 9 2 9 6 6 15 15 4 11 5 10 14 3 14
Output
5
6
6
6
5
5
5
5
5
6

F1. Dhrumil and Abhishek Game 1
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Dhrumil and Abhishek are playing a game on an array, Abhishek gives Dhrumil an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ levels.

Abhishek provides Dhrumil with two types of operations:

  • Type 1: Abhishek gives Dhrumil an index and a value, and Dhrumil must update $$$a[\text{index}] = \text{value}$$$.
  • Type 2: Abhishek asks Dhrumil to calculate the weighted sum of points between two indices $$$l$$$ and $$$r$$$: $$$1 * a[l] + 2 * a[l+1] + 3 * a[l+2] + 4 * a[l+3] ....$$$

In this version, l = 1 and r = n

Your task is to help Dhrumil to accurately find the points, else he will lose the game

Input

The first line of input contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases.

For each test case:

  • The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 10^5$$$) — the size of the array and the number of queries.
  • The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the initial values of the array.

Then, the next $$$q$$$ lines contain the following types of queries:

  • Type 1: $$$1~\text{index}~\text{value}$$$ — update $$$a[\text{index}] = \text{value}$$$.
  • Type 2: $$$2~l~r$$$ — compute and output the weighted sum $$$S(l, r)$$$.

It is guaranteed that the sum of all $$$n + q$$$ across all test cases does not exceed $$$10^6$$$.

Output

For each query of Type 2, output the weighted sum $$$S(l, r)$$$.

Example
Input
3
5 3
1 2 4 1 5
2 1 5
1 3 10
2 1 5
5 1
1 2 3 4 5
2 1 5
10 4
1 3 2 7 9 6 9 2 6 7
1 1 9
2 1 10
1 6 3
2 1 10
Output
46
64
55
333
315

F2. Dhrumil and Abhishek Game 2
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Dhrumil and Abhishek are playing a game on an array, Abhishek gives Dhrumil an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ levels.

Abhishek provides Dhrumil with two types of operations:

  • Type 1: Abhishek gives Dhrumil an index and a value, and Dhrumil must update $$$a[\text{index}] = \text{value}$$$.
  • Type 2: Abhishek asks Dhrumil to calculate the weighted sum of points between two indices $$$l$$$ and $$$r$$$: $$$1 * a[l] + 2 * a[l+1] + 3 * a[l+2] + 4 * a[l+3] ....$$$

Your task is to help Dhrumil to accurately find the points, else he will lose the game

Input

The first line of input contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases.

For each test case:

  • The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 10^5$$$) — the size of the array and the number of queries.
  • The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the initial values of the array.

Then, the next $$$q$$$ lines contain the following types of queries:

  • Type 1: $$$1~\text{index}~\text{value}$$$ — update $$$a[\text{index}] = \text{value}$$$.
  • Type 2: $$$2~l~r$$$ — compute and output the weighted sum $$$S(l, r)$$$.

It is guaranteed that the sum of all $$$n + q$$$ across all test cases does not exceed $$$10^6$$$.

Output

For each query of Type 2, output the weighted sum $$$S(l, r)$$$.

Example
Input
3
5 3
1 2 4 1 5
2 1 5
1 3 10
2 1 5
5 1
1 2 3 4 5
2 1 5
10 8
1 3 2 7 9 6 9 2 6 7
1 1 9
2 1 7
2 1 6
2 3 7
1 6 3
2 3 8
2 4 6
2 1 10
Output
46
64
55
193
130
112
112
34
315