JerryL/AlgoSimBench huggingface dataset:
558_E. A Simple Task

This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order if k = 1 or in non-increasing order if k = 0.

Output the final string after applying the queries.

Input

The first line will contain two integers n, q (1 ≤ n ≤ 105, 0 ≤ q ≤ 50 000), the length of the string and the number of queries respectively. 

Next line contains a string S itself. It contains only lowercase English letters.

Next q lines will contain three integers each i, j, k (1 ≤ i ≤ j ≤ n, <image>).

Output

Output one line, the string S after applying the queries.

Examples

Input

10 5
abacdabcda
7 10 0
5 8 1
1 4 0
3 6 0
7 10 1


Output

cbcaaaabdd

Input

10 1
agjucbvdfk
1 10 1


Output

abcdfgjkuv

Note

First sample test explanation:

<image>

<image>

<image>

<image>

<image>

Example input:
10 5
abacdabcda
7 10 0
5 8 1
1 4 0
3 6 0
7 10 1

10 1
agjucbvdfk
1 10 1


Example output:
cbcaaaabdd
abcdfgjkuv

Tags: data structures
sortings
strings
Difficulty rating: 2300

Solution:
#include <bits/stdc++.h>
using namespace std;
vector<int> v[26];
int main() {
  int n, q, l, r, k;
  string s;
  cin >> n >> q >> s;
  for (int i = 0; i < s.size(); i++) v[s[i] - 'a'].push_back(i);
  while (q--) {
    cin >> l >> r >> k;
    int cnt = --l;
    r--;
    if (k)
      for (int i = 0; i <= 26; ++i) {
        int ss = lower_bound(v[i].begin(), v[i].end(), l) - v[i].begin(),
            ff = upper_bound(v[i].begin(), v[i].end(), r) - v[i].begin();
        for (int j = ss; j < ff; j++) v[i][j] = cnt++;
      }
    else
      for (int i = 26; i >= 0; --i) {
        int ss = lower_bound(v[i].begin(), v[i].end(), l) - v[i].begin(),
            ff = upper_bound(v[i].begin(), v[i].end(), r) - v[i].begin();
        for (int j = ss; j < ff; ++j) v[i][j] = cnt++;
      }
  }
  for (int i = 0; i < 27; i++)
    for (int j = 0; j < v[i].size(); j++) s[v[i][j]] = char('a' + i);
  cout << s << endl;
  return 0;
}
817_F. MEX Queries

You are given a set of integer numbers, initially it is empty. You should perform n queries.

There are three different types of queries: 

  * 1 l r — Add all missing numbers from the interval [l, r]
  * 2 l r — Remove all present numbers from the interval [l, r]
  * 3 l r — Invert the interval [l, r] — add all missing and remove all present numbers from the interval [l, r]



After each query you should output MEX of the set — the smallest positive (MEX ≥ 1) integer number which is not presented in the set.

Input

The first line contains one integer number n (1 ≤ n ≤ 105).

Next n lines contain three integer numbers t, l, r (1 ≤ t ≤ 3, 1 ≤ l ≤ r ≤ 1018) — type of the query, left and right bounds.

Output

Print MEX of the set after each query.

Examples

Input

3
1 3 4
3 1 6
2 1 3


Output

1
3
1


Input

4
1 1 3
3 5 6
2 4 4
3 1 6


Output

4
4
4
1

Note

Here are contents of the set after each query in the first example:

  1. {3, 4} — the interval [3, 4] is added 
  2. {1, 2, 5, 6} — numbers {3, 4} from the interval [1, 6] got deleted and all the others are added 
  3. {5, 6} — numbers {1, 2} got deleted 

Example input:
4
1 1 3
3 5 6
2 4 4
3 1 6

3
1 3 4
3 1 6
2 1 3


Example output:
4
4
4
1

1
3
1


Tags: binary search
data structures
trees
Difficulty rating: 2300

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MOD = 1000000007;
map<long long, bool> seq;
void upd(int t, long long l, long long r) {
  auto it = seq.lower_bound(l);
  int prev = -1;
  if (it != seq.begin() && (it == seq.end() || it->first != l)) {
    it--;
    prev = it->second;
    it++;
  }
  int last = -1;
  while (it != seq.end() && it->first <= r) {
    last = it->second;
    if (t == 3) {
      it->second = !it->second;
      it++;
    } else {
      it = seq.erase(it);
    }
  }
  if (t == 1) {
    seq[l] = 1;
  } else if (t == 2) {
    seq[l] = 0;
  }
  if (prev != -1) {
    if (t == 3) seq[l] = !prev;
    if (last == -1) last = prev;
  }
  if (last == -1) last = 0;
  if (it == seq.end() || it->first > r + 1) {
    seq[r + 1] = last;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  seq[1] = 0;
  while (n--) {
    long long t, l, r;
    cin >> t >> l >> r;
    upd(t, l, r);
    auto it = seq.begin();
    while (it != seq.end() && it->second == 1) it++;
    cout << it->first << endl;
  }
}
580_E. Kefa and Watch

One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering by the road. As he came nearer he understood that it was a watch. He decided to take it to the pawnbroker to earn some money. 

The pawnbroker said that each watch contains a serial number represented by a string of digits from 0 to 9, and the more quality checks this number passes, the higher is the value of the watch. The check is defined by three positive integers l, r and d. The watches pass a check if a substring of the serial number from l to r has period d. Sometimes the pawnbroker gets distracted and Kefa changes in some substring of the serial number all digits to c in order to increase profit from the watch. 

The seller has a lot of things to do to begin with and with Kefa messing about, he gave you a task: to write a program that determines the value of the watch.

Let us remind you that number x is called a period of string s (1 ≤ x ≤ |s|), if si = si + x for all i from 1 to |s| - x.

Input

The first line of the input contains three positive integers n, m and k (1 ≤ n ≤ 105, 1 ≤ m + k ≤ 105) — the length of the serial number, the number of change made by Kefa and the number of quality checks.

The second line contains a serial number consisting of n digits.

Then m + k lines follow, containing either checks or changes. 

The changes are given as 1 l r c (1 ≤ l ≤ r ≤ n, 0 ≤ c ≤ 9). That means that Kefa changed all the digits from the l-th to the r-th to be c. 

The checks are given as 2 l r d (1 ≤ l ≤ r ≤ n, 1 ≤ d ≤ r - l + 1).

Output

For each check on a single line print "YES" if the watch passed it, otherwise print "NO".

Examples

Input

3 1 2
112
2 2 3 1
1 1 3 8
2 1 2 1


Output

NO
YES


Input

6 2 3
334934
2 2 5 2
1 4 4 3
2 1 6 3
1 2 3 8
2 3 6 1


Output

NO
YES
NO

Note

In the first sample test two checks will be made. In the first one substring "12" is checked on whether or not it has period 1, so the answer is "NO". In the second one substring "88", is checked on whether or not it has period 1, and it has this period, so the answer is "YES".

In the second statement test three checks will be made. The first check processes substring "3493", which doesn't have period 2. Before the second check the string looks as "334334", so the answer to it is "YES". And finally, the third check processes substring "8334", which does not have period 1.

Example input:
3 1 2
112
2 2 3 1
1 1 3 8
2 1 2 1

6 2 3
334934
2 2 5 2
1 4 4 3
2 1 6 3
1 2 3 8
2 3 6 1


Example output:
NO
YES

NO
YES
NO


Tags: data structures
hashing
strings
Difficulty rating: 2500

Solution:
#include <bits/stdc++.h>
char s[100100];
int n, m, k, L, R, c, type;
int main() {
  scanf("%d%d%d%s", &n, &m, &k, s + 1);
  m += k;
  while (m--) {
    scanf("%d%d%d%d", &type, &L, &R, &c);
    if (type == 1)
      memset(s + L, c + '0', R - L + 1);
    else
      puts(memcmp(s + L, s + L + c, R - L - c + 1) ? "NO" : "YES");
  }
}
1252_K. Addition Robot

Adding two numbers several times is a time-consuming task, so you want to build a robot. The robot should have a string S = S_1 S_2 ... S_N of N characters on its memory that represents addition instructions. Each character of the string, S_i, is either 'A' or 'B'.

You want to be able to give Q commands to the robot, each command is either of the following types: 

  * 1 L R. The robot should toggle all the characters of S_i where L ≤ i ≤ R. Toggling a character means changing it to 'A' if it was previously 'B', or changing it to 'B' if it was previously 'A'. 
  * 2 L R A B. The robot should call f(L, R, A, B) and return two integers as defined in the following pseudocode: 
    
            function f(L, R, A, B):  
          FOR i from L to R  
            if S[i] = 'A'  
              A = A + B  
            else  
              B = A + B  
          return (A, B)  
      




You want to implement the robot's expected behavior.

Input

Input begins with a line containing two integers: N Q (1 ≤ N, Q ≤ 100 000) representing the number of characters in the robot's memory and the number of commands, respectively. The next line contains a string S containing N characters (each either 'A' or 'B') representing the initial string in the robot's memory. The next Q lines each contains a command of the following types. 

  * 1 L R (1 ≤ L ≤ R ≤ N) 
  * 2 L R A B (1 ≤ L ≤ R ≤ N; 0 ≤ A, B ≤ 10^9) 

There is at least one command of the second type.

Output

For each command of the second type in the same order as input, output in a line two integers (separated by a single space), the value of A and B returned by f(L, R, A, B), respectively. As this output can be large, you need to modulo the output by 1 000 000 007.

Example

Input


5 3
ABAAA
2 1 5 1 1
1 3 5
2 2 5 0 1000000000


Output


11 3
0 1000000000

Note

Explanation for the sample input/output #1

For the first command, calling f(L, R, A, B) causes the following: 

  * Initially, A = 1 and B = 1. 
  * At the end of i = 1, A = 2 and B = 1. 
  * At the end of i = 2, A = 2 and B = 3. 
  * At the end of i = 3, A = 5 and B = 3. 
  * At the end of i = 4, A = 8 and B = 3. 
  * At the end of i = 5, A = 11 and B = 3. 

Therefore, f(L, R, A, B) will return (11, 3).

For the second command, string S will be updated to "ABBBB".

For the third command, the value of A will always be 0 and the value of B will always be 1 000 000 000. Therefore, f(L, R, A, B) will return (0, 1 000 000 000).

Example input:
5 3
ABAAA
2 1 5 1 1
1 3 5
2 2 5 0 1000000000


Example output:

11 3
0 1000000000


Tags: data structures
math
matrices
Difficulty rating: 2100

Solution:
p02575 AtCoder Beginner Contest 177 - I hate Shortest Path Problem

There is a grid of squares with H+1 horizontal rows and W vertical columns.

You will start at one of the squares in the top row and repeat moving one square right or down. However, for each integer i from 1 through H, you cannot move down from the A_i-th, (A_i + 1)-th, \ldots, B_i-th squares from the left in the i-th row from the top.

For each integer k from 1 through H, find the minimum number of moves needed to reach one of the squares in the (k+1)-th row from the top. (The starting square can be chosen individually for each case.) If, starting from any square in the top row, none of the squares in the (k+1)-th row can be reached, print `-1` instead.

Constraints

* 1 \leq H,W \leq 2\times 10^5
* 1 \leq A_i \leq B_i \leq W

Input

Input is given from Standard Input in the following format:


H W
A_1 B_1
A_2 B_2
:
A_H B_H


Output

Print H lines. The i-th line should contain the answer for the case k=i.

Example

Input

4 4
2 4
1 1
2 3
2 4


Output

1
3
6
-1

Example input:
4 4
2 4
1 1
2 3
2 4

Example output:
1
3
6
-1

Difficulty rating: 0

Solution:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int W;
  cin >> W >> W;
  map<int, int> X;
  multiset<int> Y;
  for (int i = 0; i < W; i++) X[i] = i, Y.insert(0);
  for (int h = 1, A, B, C, D; cin >> A >> B;  ) {
    C = -1;
    for(auto j = X.lower_bound(--A);j != X.end() && j -> first <= B; X.erase(j++)){
      D = j -> first;
      C = max(C, X[D]);
      Y.erase(Y.find(D - X[D]));
    }
    if (C + 1 && B < W) X[B] = C, Y.insert(B - C);
    cout << ((Y.size()) ? *Y.begin() + h++ : -1) << "\n";
  }
}
1263_C. Everyone is a Winner!

On the well-known testing system MathForces, a draw of n rating units is arranged. The rating will be distributed according to the following algorithm: if k participants take part in this event, then the n rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants.

For example, if n = 5 and k = 3, then each participant will recieve an 1 rating unit, and also 2 rating units will remain unused. If n = 5, and k = 6, then none of the participants will increase their rating.

Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help.

For example, if n=5, then the answer is equal to the sequence 0, 1, 2, 5. Each of the sequence values (and only them) can be obtained as ⌊ n/k ⌋ for some positive integer k (where ⌊ x ⌋ is the value of x rounded down): 0 = ⌊ 5/7 ⌋, 1 = ⌊ 5/5 ⌋, 2 = ⌊ 5/2 ⌋, 5 = ⌊ 5/1 ⌋.

Write a program that, for a given n, finds a sequence of all possible rating increments.

Input

The first line contains integer number t (1 ≤ t ≤ 10) — the number of test cases in the input. Then t test cases follow.

Each line contains an integer n (1 ≤ n ≤ 10^9) — the total number of the rating units being drawn.

Output

Output the answers for each of t test cases. Each answer should be contained in two lines.

In the first line print a single integer m — the number of different rating increment values that Vasya can get.

In the following line print m integers in ascending order — the values of possible rating increments.

Example

Input


4
5
11
1
3


Output


4
0 1 2 5 
6
0 1 2 3 5 11 
2
0 1 
3
0 1 3 

Example input:
4
5
11
1
3


Example output:
4
0 1 2 5 
6
0 1 2 3 5 11 
2
0 1 
3
0 1 3 


Tags: binary search
math
meet-in-the-middle
number theory
Difficulty rating: 1400

Solution:
for t in range(int(input())):
	n=int(input())
	seq=[]
	i=n+1
	while i>0:
		a=n//i
		i=(n//(a+1))
		seq.append(a)
	
	print(len(seq))
	print(*seq)
p02992 AtCoder Beginner Contest 132 - Small Products

Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7.

Constraints

* 1\leq N\leq 10^9
* ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST)
* N and K are integers.

Input

Input is given from Standard Input in the following format:


N K


Output

Print the number of sequences, modulo 10^9+7.

Examples

Input

3 2


Output

5


Input

10 3


Output

147


Input

314159265 35


Output

457397712

Example input:
10 3
314159265 35
3 2

Example output:
147
457397712
5

Difficulty rating: 0

Solution:
from itertools import accumulate as r;n,k=map(int,input().split());m=10**9+7;j=int(n**0.5);c=[n//(i+1)-n//(i+2) for i in range(n//(j+1))]+[1]*j;x=c;exec("x=[(y*d)%m for y,d in zip(r(x[::-1]),c)];"*k);print(x[-1])
909_D. Colorful Points

You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.

You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can't perform it.

How many operations will you need to perform until the next operation does not have any points to delete?

Input

Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc.

The number of the points is between 1 and 106.

Output

Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete.

Examples

Input

aabb


Output

2


Input

aabcaa


Output

1

Note

In the first test case, the first operation will delete two middle points and leave points "ab", which will be deleted with the second operation. There will be no points left to apply the third operation to.

In the second test case, the first operation will delete the four points in the middle, leaving points "aa". None of them have neighbors of other colors, so the second operation can't be applied.

Example input:
aabb

aabcaa


Example output:
2

1


Tags: data structures
greedy
implementation
Difficulty rating: 2100

Solution:
s=input()
a=[[s[0],1]]

for i in s[1:]:
    if(a[-1][0]==i):
        a[-1][1]+=1
    else:
        a.append([i,1])
turns=0
while((len(a)>1)):
    turns+=1
    temp=[]
    if(a[0][1]>1):
        temp.append([a[0][0],a[0][1]-1])
    for i in a[1:-1]:
        if(i[1]>2):
            temp.append([i[0],i[1]-2])
    if(a[-1][1]>1):
        temp.append([a[-1][0],a[-1][1]-1])
    if(len(temp)<2):
        break
    a=[temp[0],]
    for i in temp[1:]:
        if(i[0]!=a[-1][0]):
            a.append(i)
        else:
            a[-1][1]+=i[1]
print(turns)
808_B. Average Sleep Time

It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days!

When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day.

The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>.

You should write a program which will calculate average sleep times of Polycarp over all weeks.

Input

The first line contains two integer numbers n and k (1 ≤ k ≤ n ≤ 2·105).

The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105).

Output

Output average sleeping time over all weeks. 

The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point.

Examples

Input

3 2
3 4 7


Output

9.0000000000


Input

1 1
10


Output

10.0000000000


Input

8 2
1 2 4 100000 123 456 789 1


Output

28964.2857142857

Note

In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.

Example input:
8 2
1 2 4 100000 123 456 789 1

3 2
3 4 7

1 1
10


Example output:
28964.285714285713766
9.000000000000000
10.000000000000000

Tags: data structures
implementation
math
Difficulty rating: 1300

Solution:
R=lambda:map(int,raw_input().split())
n,k=R()
s=0
for i,a in enumerate(R()):
  s+=(min(n,i+k)-max(i,k-1))*a
print s/1./(n-k+1)
p02780 AtCoder Beginner Contest 154 - Dice in Line

We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.

We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.

Constraints

* 1 ≤ K ≤ N ≤ 200000
* 1 ≤ p_i ≤ 1000
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N K
p_1 ... p_N


Output

Print the maximum possible value of the expected value of the sum of the numbers shown.

Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.

Examples

Input

5 3
1 2 2 4 5


Output

7.000000000000


Input

4 1
6 6 6 6


Output

3.500000000000


Input

10 4
17 13 13 12 15 20 10 13 17 11


Output

32.000000000000

Example input:
5 3
1 2 2 4 5
10 4
17 13 13 12 15 20 10 13 17 11
4 1
6 6 6 6

Example output:
7.000000000000
32.000000000000
3.500000000000

Difficulty rating: 0

Solution:
n,k,*p=map(int,open(0).read().split())
s=m=k
for i in range(n):s+=p[i]-p[i-k]*(i>=k);m=max(m,s)
print(m/2)
p02788 AtCoder Beginner Contest 153 - Silver Fox vs Monster

Silver Fox is fighting with N monsters.

The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the health of H_i.

Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health.

Silver Fox wins when all the monsters' healths become 0 or below.

Find the minimum number of bombs needed to win.

Constraints

* 1 \leq N \leq 2 \times 10^5
* 0 \leq D \leq 10^9
* 1 \leq A \leq 10^9
* 0 \leq X_i \leq 10^9
* 1 \leq H_i \leq 10^9
* X_i are distinct.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N D A
X_1 H_1
:
X_N H_N


Output

Print the minimum number of bombs needed to win.

Examples

Input

3 3 2
1 2
5 4
9 2


Output

2


Input

9 4 1
1 5
2 4
3 3
4 2
5 1
6 2
7 3
8 4
9 5


Output

5


Input

3 0 1
300000000 1000000000
100000000 1000000000
200000000 1000000000


Output

3000000000

Example input:
9 4 1
1 5
2 4
3 3
4 2
5 1
6 2
7 3
8 4
9 5
3 3 2
1 2
5 4
9 2
3 0 1
300000000 1000000000
100000000 1000000000
200000000 1000000000

Example output:
5
2
3000000000

Difficulty rating: 0

Solution:
from bisect import*
n,d,a,*t=map(int,open(0).read().split())
c=[0]*-~n
z=sorted(zip(*[iter(t)]*2))
s=0
for i,(x,h)in enumerate(z):c[i]+=c[i-1];h-=c[i];t=min(-h//a,0);c[i]-=t*a;c[bisect(z,(x+d+d,9e9))]+=t*a;s-=t
print(s)