JerryL/AlgoSimBench huggingface dataset:
546_D. Soldier and Number Game

Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive integer x > 1, such that n is divisible by x and replacing n with n / x. When n becomes equal to 1 and there is no more possible valid moves the game is over and the score of the second soldier is equal to the number of rounds he performed.

To make the game more interesting, first soldier chooses n of form a! / b! for some positive integer a and b (a ≥ b). Here by k! we denote the factorial of k that is defined as a product of all positive integers not large than k.

What is the maximum possible score of the second soldier?

Input

First line of input consists of single integer t (1 ≤ t ≤ 1 000 000) denoting number of games soldiers play.

Then follow t lines, each contains pair of integers a and b (1 ≤ b ≤ a ≤ 5 000 000) defining the value of n for a game.

Output

For each game output a maximum score that the second soldier can get.

Examples

Input

2
3 1
6 3


Output

2
5

Example input:
2
3 1
6 3


Example output:
2
5


Tags: constructive algorithms
dp
math
number theory
Difficulty rating: 1700

Solution:
#include <bits/stdc++.h>
int a[5555555];
int main() {
  int i, j, k, n;
  for (i = 2; i <= 5000000; i++) {
    if (!a[i])
      for (j = 1; i * j <= 5000000; j++)
        for (k = i * j; k % i == 0; k /= i) a[i * j]++;
    a[i] += a[i - 1];
  }
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &j, &k);
    printf("%d\n", a[j] - a[k]);
  }
}
1555_B. Two Tables

You have an axis-aligned rectangle room with width W and height H, so the lower left corner is in point (0, 0) and the upper right corner is in (W, H).

There is a rectangular table standing in this room. The sides of the table are parallel to the walls, the lower left corner is in (x_1, y_1), and the upper right corner in (x_2, y_2).

You want to place another rectangular table in this room with width w and height h with the width of the table parallel to the width of the room.

The problem is that sometimes there is not enough space to place the second table without intersecting with the first one (there are no problems with tables touching, though).

You can't rotate any of the tables, but you can move the first table inside the room. 

<image> Example of how you may move the first table.

What is the minimum distance you should move the first table to free enough space for the second one?

Input

The first line contains the single integer t (1 ≤ t ≤ 5000) — the number of the test cases.

The first line of each test case contains two integers W and H (1 ≤ W, H ≤ 10^8) — the width and the height of the room.

The second line contains four integers x_1, y_1, x_2 and y_2 (0 ≤ x_1 < x_2 ≤ W; 0 ≤ y_1 < y_2 ≤ H) — the coordinates of the corners of the first table.

The third line contains two integers w and h (1 ≤ w ≤ W; 1 ≤ h ≤ H) — the width and the height of the second table.

Output

For each test case, print the minimum distance you should move the first table, or -1 if there is no way to free enough space for the second table.

Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}.

Example

Input


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


Output


1.000000000
-1
2.000000000
2.000000000
0.000000000

Note

The configuration of the first test case is shown in the picture. But the movement of the first table is not optimal. One of the optimal movement, for example, is to move the table by (0, -1), so the lower left corner will move from (2, 1) to (2, 0). Then you can place the second table at (0, 3)-(4, 5).

In the second test case, there is no way to fit both tables in the room without intersecting.

In the third test case, you can move the first table by (0, 2), so the lower left corner will move from (0, 3) to (0, 5).

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


Example output:
1.000000000
-1
2.000000000
2.000000000
0.000000000


Tags: brute force
Difficulty rating: 1300

Solution:
t = int(input())
for _ in range(t):
	w,h = map(int,input().split())
	x1,y1,x2,y2 = map(int,input().split())
	xx,yy = map(int,input().split())
	ans = 10**8
	if w>=x2-x1+xx:
	    ans = min(ans,max(0,xx-x1),max(0,x2-(w-xx)))
	if h>=y2-y1+yy:
	    ans = min(ans,max(0,yy-y1),max(0,y2-(h-yy)))
	print(ans if ans<10**8 else -1)
632_C. The Smallest String Concatenation

You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.

Given the list of strings, output the lexicographically smallest concatenation.

Input

The first line contains integer n — the number of strings (1 ≤ n ≤ 5·104).

Each of the next n lines contains one string ai (1 ≤ |ai| ≤ 50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104.

Output

Print the only string a — the lexicographically smallest string concatenation.

Examples

Input

4
abba
abacaba
bcd
er


Output

abacabaabbabcder


Input

5
x
xx
xxa
xxaa
xxaaa


Output

xxaaaxxaaxxaxxx


Input

3
c
cb
cba


Output

cbacbc

Example input:
4
abba
abacaba
bcd
er

5
x
xx
xxa
xxaa
xxaaa

3
c
cb
cba


Example output:
abacabaabbabcder

xxaaaxxaaxxaxxx

cbacbc


Tags: sortings
strings
Difficulty rating: 1700

Solution:
import sys
print "".join(sorted(map(lambda s: s.rstrip(), sys.stdin.readlines()[1:]), cmp=lambda x,y: cmp(x+y,y+x)))
762_B. USB vs. PS/2

Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!

The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options.

You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once.

You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy.

Input

The first line contains three integers a, b and c (0 ≤ a, b, c ≤ 105) — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively.

The next line contains one integer m (0 ≤ m ≤ 3·105) — the number of mouses in the price list.

The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≤ vali ≤ 109) — the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.

Output

Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.

Example

Input

2 1 1
4
5 USB
6 PS/2
3 PS/2
7 PS/2


Output

3 14

Note

In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.

Example input:
2 1 1
4
5 USB
6 PS/2
3 PS/2
7 PS/2


Example output:
3 14


Tags: greedy
implementation
sortings
two pointers
Difficulty rating: 1400

Solution:
a,b,c=map(int,input().split());ans=0
m=int(input())
u=[]
p=[]
for i in range(m):
    s=input().split()
    if s[1]=='USB': u.append(int(s[0]))
    else: p.append(int(s[0]))
u.sort();p.sort()
a=min(a,len(u));b=min(b,len(p))
ans+=(sum(u[:a])+sum(p[:b]))
d=sorted(u[a:]+p[b:]);c=min(c,len(d));ans+=sum(d[:c])
print(a+b+c,ans)
755_C. PolandBall and Forest

PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree.

There is exactly one relative living in each vertex of each tree, they have unique ids from 1 to n. For each Ball i we know the id of its most distant relative living on the same tree. If there are several such vertices, we only know the value of the one with smallest id among those.

How many trees are there in the forest?

Input

The first line contains single integer n (1 ≤ n ≤ 104) — the number of Balls living in the forest.

The second line contains a sequence p1, p2, ..., pn of length n, where (1 ≤ pi ≤ n) holds and pi denotes the most distant from Ball i relative living on the same tree. If there are several most distant relatives living on the same tree, pi is the id of one with the smallest id.

It's guaranteed that the sequence p corresponds to some valid forest.

Hacking: To hack someone, you should provide a correct forest as a test. The sequence p will be calculated according to the forest and given to the solution you try to hack as input. Use the following format:

In the first line, output the integer n (1 ≤ n ≤ 104) — the number of Balls and the integer m (0 ≤ m < n) — the total number of edges in the forest. Then m lines should follow. The i-th of them should contain two integers ai and bi and represent an edge between vertices in which relatives ai and bi live. For example, the first sample is written as follows:
    
    
      
    5 3  
    1 2  
    3 4  
    4 5  
    

Output

You should output the number of trees in the forest where PolandBall lives.

Interaction

From the technical side, this problem is interactive. However, it should not affect you (except hacking) since there is no interaction.

Examples

Input

5
2 1 5 3 3

Output

2

Input

1
1


Output

1

Note

In the first sample testcase, possible forest is: 1-2 3-4-5. 

There are 2 trees overall.

In the second sample testcase, the only possible graph is one vertex and no edges. Therefore, there is only one tree.

Example input:
1
1

5
2 1 5 3 3

Example output:
1

2


Tags: dfs and similar
dsu
graphs
interactive
trees
Difficulty rating: 1300

Solution:
n, P = int(input()), list(map(int, input().split()))
print(sum(P[P[i]-1] == i+1 and P[i] < i+2 for i in range(n)))
839_C. Journey

There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.

Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities. 

Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link <https://en.wikipedia.org/wiki/Expected_value>.

Input

The first line contains a single integer n (1 ≤ n ≤ 100000) — number of cities.

Then n - 1 lines follow. The i-th line of these lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the cities connected by the i-th road.

It is guaranteed that one can reach any city from any other by the roads.

Output

Print a number — the expected length of their journey. The journey starts in the city 1.

Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.

Examples

Input

4
1 2
1 3
2 4


Output

1.500000000000000


Input

5
1 2
1 3
3 4
2 5


Output

2.000000000000000

Note

In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.

In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2.

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

4
1 2
1 3
2 4


Example output:
2.000000

1.500000


Tags: dfs and similar
dp
graphs
probabilities
trees
Difficulty rating: 1500

Solution:
n=int(input())
g={i:[] for i in range(n)}
for i in range(n-1):
  u,v=map(int,input().split())
  u-=1
  v-=1
  g[u].append(v)
  g[v].append(u)
v=set()
q=[(0,1,0)]
res=0
while q:
  s,p,l=q.pop()
  v.add(s)
  dep=0
  for to in g[s]:
    if to not in v:
      dep+=1
  if dep==0:
    res+=p*l
  else:
    for to in g[s]:
      if to not in v:
        q.append((to,p/dep,l+1))
print(res)
1077_D. Cutting Out

You are given an array s consisting of n integers.

You have to find any array t of length k such that you can cut out maximum number of copies of array t from array s.

Cutting out the copy of t means that for each element t_i of array t you have to find t_i in s and remove it from s. If for some t_i you cannot find such element in s, then you cannot cut out one more copy of t. The both arrays can contain duplicate elements.

For example, if s = [1, 2, 3, 2, 4, 3, 1] and k = 3 then one of the possible answers is t = [1, 2, 3]. This array t can be cut out 2 times. 

  * To cut out the first copy of t you can use the elements [1, \underline{2}, 3, 2, 4, \underline{3}, \underline{1}] (use the highlighted elements). After cutting out the first copy of t the array s can look like [1, 3, 2, 4]. 
  * To cut out the second copy of t you can use the elements [\underline{1}, \underline{3}, \underline{2}, 4]. After cutting out the second copy of t the array s will be [4]. 



Your task is to find such array t that you can cut out the copy of t from s maximum number of times. If there are multiple answers, you may choose any of them.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of elements in s and the desired number of elements in t, respectively.

The second line of the input contains exactly n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 2 ⋅ 10^5).

Output

Print k integers — the elements of array t such that you can cut out maximum possible number of copies of this array from s. If there are multiple answers, print any of them. The required array t can contain duplicate elements. All the elements of t (t_1, t_2, ..., t_k) should satisfy the following condition: 1 ≤ t_i ≤ 2 ⋅ 10^5.

Examples

Input


7 3
1 2 3 2 4 3 1


Output


1 2 3 


Input


10 4
1 3 1 3 10 3 7 7 12 3


Output


7 3 1 3


Input


15 2
1 2 1 1 1 2 1 1 2 1 2 1 1 1 1


Output


1 1 

Note

The first example is described in the problem statement.

In the second example the only answer is [7, 3, 1, 3] and any its permutations. It can be shown that you cannot choose any other array such that the maximum number of copies you can cut out would be equal to 2.

In the third example the array t can be cut out 5 times.

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

15 2
1 2 1 1 1 2 1 1 2 1 2 1 1 1 1

10 4
1 3 1 3 10 3 7 7 12 3


Example output:
1 2 3

1 1

1 3 3 7 

Tags: binary search
sortings
Difficulty rating: 1600

Solution:
from collections import*
R=lambda:map(int,input().split())
n,k=R()
print(*(x for _,x in sorted((m//i,l)for
l,m in Counter(R()).items()for i in range(1,m+1))[-k:]))
51_C. Three Base Stations

The New Vasjuki village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fixed point — the xi coordinate. The village consists of n houses, the i-th house is located in the point with coordinates of xi.

TELE3, a cellular communication provider planned to locate three base stations so as to provide every house in the village with cellular communication. The base station having power d located in the point t provides with communication all the houses on the segment [t - d, t + d] (including boundaries).

To simplify the integration (and simply not to mix anything up) all the three stations are planned to possess the equal power of d. Which minimal value of d is enough to provide all the houses in the village with cellular communication.

Input

The first line contains an integer n (1 ≤ n ≤ 2·105) which represents the number of houses in the village. The second line contains the coordinates of houses — the sequence x1, x2, ..., xn of integer numbers (1 ≤ xi ≤ 109). It is possible that two or more houses are located on one point. The coordinates are given in a arbitrary order.

Output

Print the required minimal power d. In the second line print three numbers — the possible coordinates of the base stations' location. Print the coordinates with 6 digits after the decimal point. The positions of the stations can be any from 0 to 2·109 inclusively. It is accepted for the base stations to have matching coordinates. If there are many solutions, print any of them.

Examples

Input

4
1 2 3 4


Output

0.500000
1.500000 2.500000 3.500000


Input

3
10 20 30


Output

0
10.000000 20.000000 30.000000


Input

5
10003 10004 10001 10002 1


Output

0.500000
1.000000 10001.500000 10003.500000

Example input:
5
10003 10004 10001 10002 1

4
1 2 3 4

3
10 20 30


Example output:
0.500000
1.500000 10001.500000 10003.500000 
0.500000
1.500000 3.500000 3.500000

0.000000
10.000000 20.000000 30.000000 

Tags: binary search
greedy
Difficulty rating: 1800

Solution:
#!/usr/bin/env	python
#-*-coding:utf-8 -*-
n=int(input())
X=sorted(map(int,input().split()))
i=1-n
j=n-2
s=0
n=X[j]-X[i]
while s<n:
	l,r=X[i]-X[0],X[-1]-X[j]
	if l<r:
		if n<=l:
			s=n
			break
		i+=1
		s=l
	else:
		if n<=r:
			s=n
			break
		j-=1
		s=r
	n=X[j]-X[i]
s/=2
print(s)
print(s+X[0],X[j]-s,X[-1]-s)
1288_D. Minimax Problem

You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}.

You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}).

Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible.

Input

The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively.

Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9).

Output

Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them.

Example

Input


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


Output


1 5

Example input:
6 5
5 0 3 1 2
1 8 9 1 3
1 2 3 4 5
9 1 0 3 7
2 3 0 6 3
6 4 1 7 0


Example output:
1 5


Tags: binary search
bitmasks
dp
Difficulty rating: 2000

Solution:
import math as mt
import sys
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
n,m=I()
a=[I() for i in range(n)]
ans=[]
lo=0
hi=10**9
def vanguda(mid: int) -> bool:
    global ans
    f={}
    for i in range(n):
        bi=0
        for j in range(m):
            if a[i][j]>=mid:
                bi+=1
            bi<<=1
        f[bi>>1]=i
    for aa,bb in f.items():
        for cc,dd in f.items():
            if aa|cc==(2**m-1):
                ans =bb+1,dd+1
                return True
    return False

while lo<=hi:
	mid=(lo+hi)//2
	if vanguda(mid):
		lo=mid+1
	else:
		hi=mid-1
print(*ans)
412_D. Giving Awards

The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else.

Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one for the hard work this month. The CEO knows who owes money to whom. And he also understands that if he invites person x to his office for a reward, and then immediately invite person y, who has lent some money to person x, then they can meet. Of course, in such a situation, the joy of person x from his brand new money reward will be much less. Therefore, the R1 CEO decided to invite the staff in such an order that the described situation will not happen for any pair of employees invited one after another.

However, there are a lot of employees in the company, and the CEO doesn't have a lot of time. Therefore, the task has been assigned to you. Given the debt relationships between all the employees, determine in which order they should be invited to the office of the R1 company CEO, or determine that the described order does not exist.

Input

The first line contains space-separated integers n and m <image> — the number of employees in R1 and the number of debt relations. Each of the following m lines contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi), these integers indicate that the person number ai owes money to a person a number bi. Assume that all the employees are numbered from 1 to n.

It is guaranteed that each pair of people p, q is mentioned in the input data at most once. In particular, the input data will not contain pairs p, q and q, p simultaneously.

Output

Print -1 if the described order does not exist. Otherwise, print the permutation of n distinct integers. The first number should denote the number of the person who goes to the CEO office first, the second number denote the person who goes second and so on.

If there are multiple correct orders, you are allowed to print any of them.

Examples

Input

2 1
1 2


Output

2 1 


Input

3 3
1 2
2 3
3 1


Output

2 1 3 

Example input:
2 1
1 2

3 3
1 2
2 3
3 1


Example output:
2 1 
3 2 1 

Tags: dfs and similar
Difficulty rating: 2000

Solution:
n,m = map(int,input().split())
g = [set() for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    g[a-1].add(b-1)
c = [0]*n
for i in range(n):
    c[i]=i
for i in range(n):
    j=i
    while j>0 and c[j] in g[c[j-1]]:
        c[j],c[j-1]=c[j-1],c[j]
        j-=1
for i in c:
    print(i+1,end=' ')