JerryL/AlgoSimBench huggingface dataset:
633_C. Spy Syndrome 2

After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.

For a given sentence, the cipher is processed as: 

  1. Convert all letters of the sentence to lowercase. 
  2. Reverse each of the words of the sentence individually. 
  3. Remove all the spaces in the sentence. 



For example, when this cipher is applied to the sentence

Kira is childish and he hates losing

the resulting string is

ariksihsidlihcdnaehsetahgnisol

Now Yash is given some ciphered string and a list of words. Help him to find out any original sentence composed using only words from the list. Note, that any of the given words could be used in the sentence multiple times.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 10 000) — the length of the ciphered text. The second line consists of n lowercase English letters — the ciphered text t.

The third line contains a single integer m (1 ≤ m ≤ 100 000) — the number of words which will be considered while deciphering the text. Each of the next m lines contains a non-empty word wi (|wi| ≤ 1 000) consisting of uppercase and lowercase English letters only. It's guaranteed that the total length of all words doesn't exceed 1 000 000.

Output

Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those.

Examples

Input

30
ariksihsidlihcdnaehsetahgnisol
10
Kira
hates
is
he
losing
death
childish
L
and
Note


Output

Kira is childish and he hates losing 


Input

12
iherehtolleh
5
HI
Ho
there
HeLLo
hello


Output

HI there HeLLo 

Note

In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them. 

Example input:
12
iherehtolleh
5
HI
Ho
there
HeLLo
hello

30
ariksihsidlihcdnaehsetahgnisol
10
Kira
hates
is
he
losing
death
childish
L
and
Note


Example output:
HI there hello

Kira is childish and he hates losing


Tags: data structures
dp
hashing
implementation
sortings
string suffix structures
strings
Difficulty rating: 1900

Solution:
import sys
p = sys.stdin.read().split()
n, t = int(p[0]), p[1][::-1]
d = {q.lower(): q for q in p[3:]}
k, s = 0, []
l = sorted(set(map(len, d)))
while n:
    k -= 1
    if len(l) + k < 0: k, n = s.pop()
    elif n >= l[k] and t[n - l[k]:n] in d:
        s.append((k, n))
        n -= l[k]
        k = 0
print(*[d[t[n - l[i]:n]] for i, n in s])
1137_B. Camp Schedule

The new camp by widely-known over the country Spring Programming Camp is going to start soon. Hence, all the team of friendly curators and teachers started composing the camp's schedule. After some continuous discussion, they came up with a schedule s, which can be represented as a binary string, in which the i-th symbol is '1' if students will write the contest in the i-th day and '0' if they will have a day off.

At the last moment Gleb said that the camp will be the most productive if it runs with the schedule t (which can be described in the same format as schedule s). Since the number of days in the current may be different from number of days in schedule t, Gleb required that the camp's schedule must be altered so that the number of occurrences of t in it as a substring is maximum possible. At the same time, the number of contest days and days off shouldn't change, only their order may change.

Could you rearrange the schedule in the best possible way?

Input

The first line contains string s (1 ⩽ |s| ⩽ 500 000), denoting the current project of the camp's schedule.

The second line contains string t (1 ⩽ |t| ⩽ 500 000), denoting the optimal schedule according to Gleb.

Strings s and t contain characters '0' and '1' only.

Output

In the only line print the schedule having the largest number of substrings equal to t. Printed schedule should consist of characters '0' and '1' only and the number of zeros should be equal to the number of zeros in s and the number of ones should be equal to the number of ones in s.

In case there multiple optimal schedules, print any of them.

Examples

Input


101101
110


Output


110110

Input


10010110
100011


Output


01100011


Input


10
11100


Output


01

Note

In the first example there are two occurrences, one starting from first position and one starting from fourth position.

In the second example there is only one occurrence, which starts from third position. Note, that the answer is not unique. For example, if we move the first day (which is a day off) to the last position, the number of occurrences of t wouldn't change.

In the third example it's impossible to make even a single occurrence.

Example input:
10
11100

10010110
100011

101101
110


Example output:
10

10001101

110110


Tags: greedy
hashing
strings
Difficulty rating: 1600

Solution:
flip = {'0': '1', '1': '0'}

s, t = input(), input()
n, m = len(s), len(t)

p = [0] * m
for i in range(1, m):
    g = p[i - 1]
    while g and (t[i] != t[g]):
        g = p[g - 1]
    p[i] = g + int(t[i] == t[g])

s_cnt = {'0': s.count('0'), '1': s.count('1')}
t = t[:m - p[-1]]

res = [''] * n
for i in range(n):
    char = t[i % len(t)]
    char = char if s_cnt[char] > 0 else flip[char]
    s_cnt[char] -= 1

    res[i] = char

print(''.join(res))
126_B. Password

Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.

A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring t of the string s.

Prefix supposed that the substring t is the beginning of the string s; Suffix supposed that the substring t should be the end of the string s; and Obelix supposed that t should be located somewhere inside the string s, that is, t is neither its beginning, nor its end.

Asterix chose the substring t so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring t aloud, the temple doors opened. 

You know the string s. Find the substring t or determine that such substring does not exist and all that's been written above is just a nice legend.

Input

You are given the string s whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.

Output

Print the string t. If a suitable t string does not exist, then print "Just a legend" without the quotes.

Examples

Input

fixprefixsuffix


Output

fix

Input

abcdabc


Output

Just a legend

Example input:
abcdabc

fixprefixsuffix


Example output:
Just a legend

fix


Tags: binary search
dp
hashing
string suffix structures
strings
Difficulty rating: 1700

Solution:
s,k,l=input(),-1,[-1]
for c in s:
    while(k!=-1)and(s[k]!=c):
        k=l[k]
    k+=1
    l+=[k]
q=l[-1]
if l.count(q)<2:
    q=l[q]
print(s[:q] if q>0 else 'Just a legend')
p04042 AtCoder Regular Contest 058 - Iroha Loves Strings

Iroha has a sequence of N strings s_1, s_2, ..., s_N.

She will choose some (possibly all) strings from the sequence, then concatenate those strings retaining the relative order, to produce a long string.

Among all strings of length K that she can produce in this way, find the lexicographically smallest one.

Constraints

* 1 ≦ N ≦ 2000
* 1 ≦ K ≦ 10^4
* For each i, 1 ≦ |s_i| ≦ K.
* |s_1| + |s_2| + ... + |s_N| ≦ 10^6
* For each i, s_i consists of lowercase letters.
* There exists at least one string of length K that Iroha can produce.

Input

The input is given from Standard Input in the following format:


N K
s_1
s_2
:
s_N


Output

Print the lexicographically smallest string of length K that Iroha can produce.

Examples

Input

3 7
at
coder
codar


Output

atcodar


Input

3 7
coder
codar
at


Output

codarat


Input

4 13
kyuri
namida
zzzzzzz
aaaaaa


Output

namidazzzzzzz

Example input:
4 13
kyuri
namida
zzzzzzz
aaaaaa
3 7
at
coder
codar
3 7
coder
codar
at

Example output:
namidazzzzzzz
atcodar
codarat

Difficulty rating: 0

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

char s[2010][10100];
int n,K,len[2010],T;
bitset<10100>F[2010];
vector<pair<int,int> >vec[2];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>K;
	for(int i=1;i<=n;++i)cin>>(s[i]+1),len[i]=strlen(s[i]+1);
	F[n+1][0]=1;
	for(int i=n;i;--i)F[i]=F[i+1]|(F[i+1]<<len[i]);
	for(int i=1;i<=n;++i)
		if(F[i+1][K-len[i]])vec[0].emplace_back(i,1);
	for(int i=1;i<=K;++i){
		char res='z';
		T^=1;vec[T].clear();
		for(auto j:vec[!T])res=min(res,s[j.first][j.second]);
		cout<<res;
		int pre=n;
		for(auto j:vec[!T]){
			if(s[j.first][j.second]!=res)continue;
			if(j.second!=len[j.first])vec[T].emplace_back(j.first,j.second+1);
			else pre=min(pre,j.first);
		}
		for(int j=pre+1;j<=n;++j)
			if(len[j]+i<=K&&F[j+1][K-i-len[j]])vec[T].emplace_back(j,1);
		while(vec[T].size()>=15000)vec[T].pop_back();
	}
	return 0;
}
525_E. Anya and Cubes

Anya loves to fold and stick. Today she decided to do just that.

Anya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has k stickers with exclamation marks. We know that the number of stickers does not exceed the number of cubes.

Anya can stick an exclamation mark on the cube and get the factorial of the number written on the cube. For example, if a cube reads 5, then after the sticking it reads 5!, which equals 120.

You need to help Anya count how many ways there are to choose some of the cubes and stick on some of the chosen cubes at most k exclamation marks so that the sum of the numbers written on the chosen cubes after the sticking becomes equal to S. Anya can stick at most one exclamation mark on each cube. Can you do it?

Two ways are considered the same if they have the same set of chosen cubes and the same set of cubes with exclamation marks.

Input

The first line of the input contains three space-separated integers n, k and S (1 ≤ n ≤ 25, 0 ≤ k ≤ n, 1 ≤ S ≤ 1016) — the number of cubes and the number of stickers that Anya has, and the sum that she needs to get. 

The second line contains n positive integers ai (1 ≤ ai ≤ 109) — the numbers, written on the cubes. The cubes in the input are described in the order from left to right, starting from the first one. 

Multiple cubes can contain the same numbers.

Output

Output the number of ways to choose some number of cubes and stick exclamation marks on some of them so that the sum of the numbers became equal to the given number S.

Examples

Input

2 2 30
4 3


Output

1


Input

2 2 7
4 3


Output

1


Input

3 1 1
1 1 1


Output

6

Note

In the first sample the only way is to choose both cubes and stick an exclamation mark on each of them.

In the second sample the only way is to choose both cubes but don't stick an exclamation mark on any of them.

In the third sample it is possible to choose any of the cubes in three ways, and also we may choose to stick or not to stick the exclamation mark on it. So, the total number of ways is six.

Example input:
2 2 7
4 3

3 1 1
1 1 1

2 2 30
4 3


Example output:
1

6

1


Tags: binary search
bitmasks
brute force
dp
math
meet-in-the-middle
Difficulty rating: 2100

Solution:
#include <bits/stdc++.h>
using namespace std;
map<int, long long> mat[31];
long long n, k, sum, ans, a[31], jc[31];
void dfs(int x, int y, int t, long long s) {
  if ((t > k) || (s > sum)) return;
  if (x > y) {
    if (y < n)
      mat[t][s]++;
    else
      for (int i = 0; i + t <= k; i++) ans += mat[i][sum - s];
    return;
  }
  dfs(x + 1, y, t, s);
  dfs(x + 1, y, t, s + a[x]);
  if (a[x] < 19) dfs(x + 1, y, t + 1, s + jc[a[x]]);
}
int main() {
  scanf("%lld%lld%lld", &n, &k, &sum);
  jc[0] = 1;
  for (int i = 1; i <= 18; i++) jc[i] = jc[i - 1] * i;
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  if (n == 1) {
    printf("%d", (a[1] == sum) + ((k) && (a[1] < 19) && (jc[a[1]] == sum)));
    return 0;
  }
  dfs(1, (n + 1) / 2, 0, 0);
  dfs((n + 1) / 2 + 1, n, 0, 0);
  printf("%lld", ans);
}
620_D. Professor GukiZ and Two Arrays

Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum of the elements in the array b sb. So he wants to minimize the value v = |sa - sb|.

In one operation professor can swap some element from the array a and some element from the array b. For example if the array a is [5, 1, 3, 2, 4] and the array b is [3, 3, 2] professor can swap the element 5 from the array a and the element 2 from the array b and get the new array a [2, 1, 3, 2, 4] and the new array b [3, 3, 5].

Professor doesn't want to make more than two swaps. Find the minimal value v and some sequence of no more than two swaps that will lead to the such value v. Professor makes swaps one by one, each new swap he makes with the new arrays a and b.

Input

The first line contains integer n (1 ≤ n ≤ 2000) — the number of elements in the array a.

The second line contains n integers ai ( - 109 ≤ ai ≤ 109) — the elements of the array a.

The third line contains integer m (1 ≤ m ≤ 2000) — the number of elements in the array b.

The fourth line contains m integers bj ( - 109 ≤ bj ≤ 109) — the elements of the array b.

Output

In the first line print the minimal value v = |sa - sb| that can be got with no more than two swaps.

The second line should contain the number of swaps k (0 ≤ k ≤ 2).

Each of the next k lines should contain two integers xp, yp (1 ≤ xp ≤ n, 1 ≤ yp ≤ m) — the index of the element in the array a and the index of the element in the array b in the p-th swap.

If there are several optimal solutions print any of them. Print the swaps in order the professor did them.

Examples

Input

5
5 4 3 2 1
4
1 1 1 1


Output

1
2
1 1
4 2


Input

5
1 2 3 4 5
1
15


Output

0
0


Input

5
1 2 3 4 5
4
1 2 3 4


Output

1
1
3 1

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

5
1 2 3 4 5
1
15

5
5 4 3 2 1
4
1 1 1 1


Example output:
1
1
3 1

0
0

                                                               1
2
1 1
3 2

Tags: binary search
two pointers
Difficulty rating: 2200

Solution:
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))

sum_a, sum_b = sum(a), sum(b)
delta = sum_b - sum_a
ans = abs(delta)
ans_swap = []

for i in range(n):
    for j in range(m):
        if abs((sum_a - a[i] + b[j]) - (sum_b + a[i] - b[j])) < ans:
            ans = abs((sum_a - a[i] + b[j]) - (sum_b + a[i] - b[j]))
            ans_swap = [(i+1, j+1)]

d = dict()
for i in range(m):
    for j in range(i+1, m):
        d[b[i]+b[j]] = (i+1, j+1)

minf, inf = -10**13, 10**13
val = [minf, minf] + sorted(d.keys()) + [inf, inf]

for i in range(n):
    for j in range(i+1, n):
        ap = a[i] + a[j]
        req = (delta + ap*2) >> 1
        k = bisect_left(val, req)

        for k in range(k-1, k+2):
            if abs(delta + ap*2 - val[k]*2) < ans:
                ans = abs(delta + ap*2 - val[k]*2)
                ans_swap = [(i+1, d[val[k]][0]), (j+1, d[val[k]][1])]

print(ans)
print(len(ans_swap))
for x, y in ans_swap:
    print(x, y)
839_E. Mother of Dragons

There are n castles in the Lannister's Kingdom and some walls connect two castles, no two castles are connected by more than one wall, no wall connects a castle to itself. 

Sir Jaime Lannister has discovered that Daenerys Targaryen is going to attack his kingdom soon. Therefore he wants to defend his kingdom. He has k liters of a strange liquid. He wants to distribute that liquid among the castles, so each castle may contain some liquid (possibly zero or non-integer number of liters). After that the stability of a wall is defined as follows: if the wall connects two castles a and b, and they contain x and y liters of that liquid, respectively, then the strength of that wall is x·y.

Your task is to print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve.

Input

The first line of the input contains two integers n and k (1 ≤ n ≤ 40, 1 ≤ k ≤ 1000).

Then n lines follows. The i-th of these lines contains n integers ai, 1, ai, 2, ..., ai, n (<image>). If castles i and j are connected by a wall, then ai, j = 1. Otherwise it is equal to 0.

It is guaranteed that ai, j = aj, i and ai, i = 0 for all 1 ≤ i, j ≤ n.

Output

Print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve.

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

3 1
0 1 0
1 0 0
0 0 0


Output

0.250000000000


Input

4 4
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0


Output

4.000000000000

Note

In the first sample, we can assign 0.5, 0.5, 0 liters of liquid to castles 1, 2, 3, respectively, to get the maximum sum (0.25).

In the second sample, we can assign 1.0, 1.0, 1.0, 1.0 liters of liquid to castles 1, 2, 3, 4, respectively, to get the maximum sum (4.0)

Example input:
3 1
0 1 0
1 0 0
0 0 0

4 4
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0


Example output:
0.2500000
4.0000000

Tags: brute force
graphs
math
meet-in-the-middle
Difficulty rating: 2700

Solution:
#include <bits/stdc++.h>
using namespace std;
int main() {
  srand(998244353);
  long long n, m, i, j, s, T, ans = 0;
  cin >> n >> m;
  long long e[50] = {}, can, t;
  int p[50] = {};
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) cin >> t, e[i] |= t << j;
  for (i = 0; i < n; i++) p[i] = i;
  for (T = 5e3; T; T--) {
    random_shuffle(p, p + n);
    can = (1LL << n) - 1;
    for (i = s = 0; i < n; i++)
      if (can >> p[i] & 1) s++, can &= e[p[i]];
    ans = max(ans, s);
  }
  printf("%.8lf\n", 0.5 * m * m * (ans - 1) / ans);
  return 0;
}
898_B. Proper Nutrition

Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.

Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles.

In other words, you should find two non-negative integers x and y such that Vasya can buy x bottles of Ber-Cola and y Bars bars and x·a + y·b = n or tell that it's impossible.

Input

First line contains single integer n (1 ≤ n ≤ 10 000 000) — amount of money, that Vasya has.

Second line contains single integer a (1 ≤ a ≤ 10 000 000) — cost of one bottle of Ber-Cola.

Third line contains single integer b (1 ≤ b ≤ 10 000 000) — cost of one Bars bar.

Output

If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly n burles print «NO» (without quotes).

Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers x and y — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly n burles, i.e. x·a + y·b = n. If there are multiple answers print any of them.

Any of numbers x and y can be equal 0.

Examples

Input

7
2
3


Output

YES
2 1


Input

100
25
10


Output

YES
0 10


Input

15
4
8


Output

NO


Input

9960594
2551
2557


Output

YES
1951 1949

Note

In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.

In second example Vasya can spend exactly n burles multiple ways: 

  * buy two bottles of Ber-Cola and five Bars bars; 
  * buy four bottles of Ber-Cola and don't buy Bars bars; 
  * don't buy Ber-Cola and buy 10 Bars bars. 



In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly n burles.

Example input:
7
2
3

9960594
2551
2557

100
25
10

15
4
8


Example output:
YES
2 1

YES
1951 1949

YES
0 10

NO


Tags: brute force
implementation
number theory
Difficulty rating: 1100

Solution:
n=input();a=input();b=input()
nTmp=n
while n%a and n>0:
    n-=b
if n<0:
    print "NO"
else:
    print "YES"
    print n/a,(nTmp-n)/b
1260_C. Infinite Fence

You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor.

You must paint a fence which consists of 10^{100} planks in two colors in the following way (suppose planks are numbered from left to right from 0): 

  * if the index of the plank is divisible by r (such planks have indices 0, r, 2r and so on) then you must paint it red; 
  * if the index of the plank is divisible by b (such planks have indices 0, b, 2b and so on) then you must paint it blue; 
  * if the index is divisible both by r and b you can choose the color to paint the plank; 
  * otherwise, you don't need to paint the plank at all (and it is forbidden to spent paint on it). 



Furthermore, the Government added one additional restriction to make your punishment worse. Let's list all painted planks of the fence in ascending order: if there are k consecutive planks with the same color in this list, then the Government will state that you failed the labor and execute you immediately. If you don't paint the fence according to the four aforementioned conditions, you will also be executed.

The question is: will you be able to accomplish the labor (the time is not important) or the execution is unavoidable and you need to escape at all costs.

Input

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

The next T lines contain descriptions of test cases — one per line. Each test case contains three integers r, b, k (1 ≤ r, b ≤ 10^9, 2 ≤ k ≤ 10^9) — the corresponding coefficients.

Output

Print T words — one per line. For each test case print REBEL (case insensitive) if the execution is unavoidable or OBEY (case insensitive) otherwise.

Example

Input


4
1 1 2
2 10 4
5 2 3
3 2 2


Output


OBEY
REBEL
OBEY
OBEY

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


Example output:
OBEY
REBEL
OBEY
OBEY


Tags: greedy
math
number theory
Difficulty rating: 1700

Solution:
import math

for _ in range(int(input())):
	r,b,k=map(int,input().split())
	r,b=min(r,b),max(r,b)
	g= math.gcd(r,b)
	if g+(k-1)*r<b:
		print("REBEL")
	else:
		print("OBEY")
7_C. Line

A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from  - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist.

Input

The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0.

Output

If the required point exists, output its coordinates, otherwise output -1.

Examples

Input

2 5 3


Output

6 -3

Example input:
2 5 3


Example output:
6 -3


Tags: math
number theory
Difficulty rating: 1800

Solution:
def E(a,b):
    if not a: return 0,1,b
    x,y,g=E(b%a,a)
    return y-(b/a)*x,x,g
a,b,c=map(int,raw_input().split())
x,y,g=E(a,b)
C=-c/g
print -1 if c%g else "%s %s"%(C*x,C*y)