JerryL/AlgoSimBench huggingface dataset:
186_D. Mushroom Scientists

As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc.

To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task.

Note that in this problem, it is considered that 00 = 1.

Input

The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point.

The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists.

Output

Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations.

A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞.

Examples

Input

3
1 1 1


Output

1.0 1.0 1.0


Input

3
2 0 0


Output

3.0 0.0 0.0

Example input:
3
2 0 0

3
1 1 1


Example output:
3.0000000000 0.0000000000 0.0000000000

1.0000000000 1.0000000000 1.0000000000


Tags: math
ternary search
Difficulty rating: 1800

Solution:
S = int(input())
v = [int(x) for x in input().strip().split()]
print(*[S * v[i] / sum(v) for i in range(3)] if sum(v) != 0 else "000")
222_C. Reducing Fractions

To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that the programs that work with fractions in this representations aren't complete, they lack supporting the operation of reducing fractions. Implement this operation and the Empire won't forget you.

Input

The first input line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) that show how many numbers the first set (the numerator) and the second set (the denominator) contain, correspondingly.

The second line contains n space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 107) — the numbers that are multiplied to produce the numerator.

The third line contains m space-separated integers: b1, b2, ..., bm (1 ≤ bi ≤ 107) — the numbers that are multiplied to produce the denominator.

Output

Print the answer to the problem in the form, similar to the form of the input data. The number of values in the sets you print nout, mout must satisfy the inequality 1 ≤ nout, mout ≤ 105, and the actual values in the sets aout, i and bout, i must satisfy the inequality 1 ≤ aout, i, bout, i ≤ 107. 

Separate the values in the lines by spaces. The printed fraction must be reduced, that is, there mustn't be such integer x (x > 1), that the numerator and the denominator of the printed fraction are divisible by x. If there are several matching answers, print any of them.

Examples

Input

3 2
100 5 2
50 10


Output

2 3
2 1
1 1 1


Input

4 3
2 5 10 20
100 1 3


Output

1 1
20
3

Note

In the first test sample the numerator equals 1000, the denominator equals 500. If we reduce fraction 1000/500 by the greatest common divisor of the numerator and the denominator (by 500), we obtain fraction 2/1.

In the second test sample the numerator equals 2000, the denominator equals 300. If we reduce fraction 2000/300 by the greatest common divisor of the numerator and the denominator (by 100), we obtain fraction 20/3.

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

3 2
100 5 2
50 10


Example output:
4 3
1 1 1 20 
1 1 3 
3 2
1 1 2 
1 1 

Tags: implementation
math
number theory
sortings
Difficulty rating: 1800

Solution:
#include <bits/stdc++.h>
const int MaxN = 100010, MaxAB = 10000010;
int N, M, a[MaxN], b[MaxN], A[MaxAB], B[MaxAB], prm[MaxAB];
void work(int N, int* a, int* A) {
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &a[i]);
    for (int j = a[i]; j > 1; j /= prm[j]) ++A[prm[j]];
  }
}
void prt(int N, int* a, int* B) {
  for (int i = 1; i <= N; ++i) {
    int ans = 1;
    for (int j = a[i]; j > 1; j /= prm[j])
      B[prm[j]] ? --B[prm[j]] : ans *= prm[j];
    printf(i == N ? "%d\n" : "%d ", ans);
  }
}
int main() {
  scanf("%d%d", &N, &M);
  printf("%d %d\n", N, M);
  for (int i = 2; i < MaxAB; ++i)
    if (!prm[i])
      for (int j = i; j < MaxAB; j += i) prm[j] = i;
  work(N, a, A);
  work(M, b, B);
  prt(N, a, B);
  prt(M, b, A);
  return 0;
}
243_E. Matrix

Let's consider an n × n square matrix, consisting of digits one and zero.

We'll consider a matrix good, if it meets the following condition: in each row of the matrix all ones go in one group. That is, each row of the matrix looks like that 00...0011...1100...00 (or simply consists of zeroes if it has no ones).

You are given matrix a of size n × n, consisting of zeroes and ones. Your task is to determine whether you can get a good matrix b from it by rearranging the columns or not.

Input

The first line contains integer n (1 ≤ n ≤ 500) — the size of matrix a.

Each of n following lines contains n characters "0" and "1" — matrix a. Note that the characters are written without separators.

Output

Print "YES" in the first line, if you can rearrange the matrix columns so as to get a good matrix b. In the next n lines print the good matrix b. If there are multiple answers, you are allowed to print any of them.

If it is impossible to get a good matrix, print "NO".

Examples

Input

6
100010
110110
011001
010010
000100
011001


Output

YES
011000
111100
000111
001100
100000
000111


Input

3
110
101
011


Output

NO

Example input:
3
110
101
011

6
100010
110110
011001
010010
000100
011001


Example output:
NO

YES
011000
111100
000111
001100
100000
000111


Tags: data structures
Difficulty rating: 3000

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, mxd[N][N], pn[N], sum[N], mxatd[N];
char mp[N][N];
bool vis[N];
bool invalid(int tt) {
  for (int i = 1; i <= n; i++) sum[i] = 0;
  for (int i = 1; i <= tt; i++) ++sum[i];
  for (int i = 1; i <= n; i++)
    if (!vis[i]) ++sum[mxatd[i]];
  for (int i = 1; i <= n; i++) {
    sum[i] += sum[i - 1];
    if (sum[i] > i) return 1;
  }
  return 0;
}
int *et[N * N], ev[N * N], ptr;
inline void edit(int &a, int b) {
  et[++ptr] = &a;
  ev[ptr] = a;
  a = b;
}
void rollback(int t) {
  while (ptr > t) {
    *et[ptr] = ev[ptr];
    --ptr;
  }
}
bool dfs(int i) {
  if (i > n) return 1;
  if (invalid(i - 1)) return 0;
  for (int j = 1; j <= n; j++)
    if (!vis[j]) {
      int tt = ptr;
      for (int k = 1; k <= n; k++)
        if (mxatd[k] > i + mxd[j][k]) edit(mxatd[k], i + mxd[j][k]);
      vis[j] = 1;
      pn[i] = j;
      if (dfs(i + 1)) return 1;
      vis[j] = 0;
      rollback(tt);
    }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> (mp[i] + 1);
  memset(mxd, 63, sizeof(mxd));
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= n; j++)
      if (mp[i][j] == '1') ++cnt;
    for (int j = 1; j <= n; j++)
      if (mp[i][j] == '1')
        for (int k = j + 1; k <= n; k++)
          if (mp[i][k] == '1')
            mxd[j][k] = min(mxd[j][k], cnt - 1),
            mxd[k][j] = min(mxd[k][j], cnt - 1);
  }
  for (int i = 1; i <= n; i++) mxatd[i] = n;
  if (dfs(1)) {
    cout << "YES" << endl;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) cout << mp[i][pn[j]];
      cout << endl;
    }
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}
25_D. Roads not only in Berland

Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way roads. Because of the recent financial crisis, the Berland Government is strongly pressed for money, so to build a new road it has to close some of the existing ones. Every day it is possible to close one existing road and immediately build a new one. Your task is to determine how many days would be needed to rebuild roads so that from each city it became possible to reach all the others, and to draw a plan of closure of old roads and building of new ones.

Input

The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road between a pair of cities. No road connects the city with itself.

Output

Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between cities i and j became closed and a new road between cities u and v is built. Cities are numbered from 1. If the answer is not unique, output any.

Examples

Input

2
1 2


Output

0


Input

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


Output

1
3 1 3 7

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

2
1 2


Example output:
1
3 1 1 4 
0


Tags: dsu
graphs
trees
Difficulty rating: 1900

Solution:
def root(k):
    while (a[k]!=k):
        k=a[k]
    return k

def union(u,v):
    ru=root(u)
    rv=root(v)
    a[rv]=ru
    
n=input()
a=range(n+1)
e=[]
for _ in range(n-1):
    u,v=map(int,raw_input().split())
    if root(u)==root(v):
        e.append([u,v])
    else:
        union(u,v)
#print a
s=[]
for i in a[1:]:
    s.append(root(i))
s=list(set(s))
print len(e)
for i in range(len(e)):
    print e[i][0],e[i][1],s[i],s[i+1]
266_D. BerDonalds

BerDonalds, a well-known fast food restaurant, is going to open a cafe in Bertown. The important thing is to choose the new restaurant's location so that it would be easy to get there. The Bertown road system is represented by n junctions, connected by m bidirectional roads. For each road we know its length. We also know that we can get from any junction to any other one, moving along the roads.

Your task is to find such location of the restaurant, that the shortest distance along the roads from the cafe to the farthest junction would be minimum. Note that the restaurant can be located not only on the junction, but at any point of any road.

Input

The first line contains two integers n and m (<image>) — the number of junctions and the number of roads, correspondingly. Then m lines follow, describing all Bertown roads. Each road is described by three integers ai, bi, wi (1 ≤ ai, bi ≤ n, ai ≠ bi; 1 ≤ wi ≤ 105), where ai and bi are the numbers of the junctions, connected by the i-th road, and wi is the length of the i-th road. 

It is guaranteed that each road connects two distinct junctions, there is at most one road between any two junctions, and you can get from any junction to any other one.

Output

Print a single real number — the shortest distance from the optimal restaurant location to the farthest junction. The answer will be considered correct, if its absolute or relative error doesn't exceed 10 - 9.

Examples

Input

2 1
1 2 1


Output

0.50


Input

3 3
1 2 1
2 3 1
1 3 1


Output

1.00


Input

3 2
1 2 100
2 3 1


Output

50.50

Example input:
3 2
1 2 100
2 3 1

3 3
1 2 1
2 3 1
1 3 1

2 1
1 2 1


Example output:
50.5000000000

1.0000000000

0.5000000000


Tags: graphs
math
shortest paths
Difficulty rating: 2400

Solution:
#include <bits/stdc++.h>
using namespace std;
int F[210][210];
int n, m, u[210 * 210], v[210 * 210], len[210 * 210];
void read() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (i != j) F[i][j] = 1 << 29;
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %d", u + i, v + i, len + i);
    F[u[i]][v[i]] = F[v[i]][u[i]] = len[i];
  }
}
double work() {
  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) F[i][j] = min(F[i][j], F[i][k] + F[k][j]);
  int ans = 1 << 30;
  static pair<int, int> a[210];
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) a[j] = make_pair(F[j][u[i]], F[j][v[i]]);
    sort(a + 1, a + n + 1);
    int maxv = 0;
    for (int j = n; j >= 1; --j) {
      ans =
          min(ans, max(max(a[j].first, maxv) * 2, a[j].first + maxv + len[i]));
      maxv = max(maxv, a[j].second);
    }
  }
  return ans / 2.0;
}
int main() {
  read();
  printf("%f\n", work());
  return 0;
}
26_D. Tickets

As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.

Input

The input consist of a single line with three space separated integers, n, m and k (0 ≤ n, m ≤ 105, 0 ≤ k ≤ 10).

Output

Output on a single line the desired probability with at least 4 digits after the decimal point.

Examples

Input

5 3 1


Output

0.857143


Input

0 5 5


Output

1


Input

0 1 0


Output

0

Example input:
5 3 1

0 1 0

0 5 5


Example output:
0.857142857143

0

1


Tags: combinatorics
math
probabilities
Difficulty rating: 2400

Solution:
n,m,k=map(int,input().split())
if k<m<=k+n:
	t=1
	for i in range(k+1):
		t*=(m-i)/(n+k-(i-1))
	print(1-t)
else:
	print(0 if m>n+k else 1)
2_C. Commentator problem

The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. 

Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.

Input

The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium's center ( - 103 ≤ x, y ≤ 103), and r (1 ≤ r ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line. 

Output

Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.

Examples

Input

0 0 10
60 0 10
30 30 10


Output

30.00000 0.00000

Example input:
0 0 10
60 0 10
30 30 10


Example output:
30.00000 0.00000

Tags: geometry
Difficulty rating: 2600

Solution:
def diff(x):
    d=[]
    for y,z in a:
        d.append(abs(x-y)/z)
    ans=0
    for i in range(3):
        ans+=(d[i]-d[(i+1)%1])**2
    return ans

def hillclimb(a):
    x=0
    s=1
    for y,_ in a:
        x+=y/3
    while(s>1e-6):
        d0=diff(x)
        if(d0>diff(x+s)):
            x+=s
        elif(d0>diff(x-s)):
            x-=s
        elif(d0>diff(x+s*1j)):
            x+=s*1j
        elif(d0>diff(x-s*1j)):
            x-=s*1j
        else:
            s*=0.5
    return x if diff(x) < 1e-5 else None
        
        
            

a=[]
for i in range(3):
    x,y,r=map(int,input().split())
    a.append((x+y*1j,r))
answer=hillclimb(a)
if answer is not None:
    print("{:.5f} {:.5f}".format(answer.real,answer.imag))
323_B. Tournament-graph

In this problem you have to build tournament graph, consisting of n vertices, such, that for any oriented pair of vertices (v, u) (v ≠ u) there exists a path from vertex v to vertex u consisting of no more then two edges.

A directed graph without self-loops is a tournament, if there is exactly one edge between any two distinct vertices (in one out of two possible directions).

Input

The first line contains an integer n (3 ≤ n ≤ 1000), the number of the graph's vertices.

Output

Print -1 if there is no graph, satisfying the described conditions.

Otherwise, print n lines with n integers in each. The numbers should be separated with spaces. That is adjacency matrix a of the found tournament. Consider the graph vertices to be numbered with integers from 1 to n. Then av, u = 0, if there is no edge from v to u, and av, u = 1 if there is one. 

As the output graph has to be a tournament, following equalities must be satisfied: 

  * av, u + au, v = 1 for each v, u (1 ≤ v, u ≤ n; v ≠ u); 
  * av, v = 0 for each v (1 ≤ v ≤ n). 

Examples

Input

3


Output

0 1 0
0 0 1
1 0 0


Input

4


Output

-1

Example input:
3

4


Example output:
0 1 0 
0 0 1 
1 0 0 

-1


Tags: constructive algorithms
graphs
Difficulty rating: 2200

Solution:
#include <bits/stdc++.h>
const int N = 1005;
int n;
int g[N][N];
int main() {
  scanf("%d", &n);
  if (n == 4) return puts("-1"), 0;
  for (int i = 1; i < n; i++) g[i][i + 1] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = i + 2; j <= n; j++)
      if ((i & 1) == (j & 1))
        g[i][j] = 1;
      else
        g[j][i] = 1;
  g[n][1] = 1;
  g[1][n] = 0;
  for (int i = 1; i <= n; puts(""), i++)
    for (int j = 1; j <= n; j++) printf("%d ", g[i][j]);
}
346_B. Lucky Common Subsequence

In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substring of ABCDEF.

You are given two strings s1, s2 and another string called virus. Your task is to find the longest common subsequence of s1 and s2, such that it doesn't contain virus as a substring.

Input

The input contains three strings in three separate lines: s1, s2 and virus (1 ≤ |s1|, |s2|, |virus| ≤ 100). Each string consists only of uppercase English letters.

Output

Output the longest common subsequence of s1 and s2 without virus as a substring. If there are multiple answers, any of them will be accepted. 

If there is no valid common subsequence, output 0.

Examples

Input

AJKEQSLOBSROFGZ
OVGURWZLWVLUXTH
OZ


Output

ORZ


Input

AA
A
A


Output

0

Example input:
AA
A
A

AJKEQSLOBSROFGZ
OVGURWZLWVLUXTH
OZ


Example output:
0
OGZ

Tags: dp
strings
Difficulty rating: 2000

Solution:
a, b, v = input(), input(), input()
t = [[-1] * len(b) for x in range(len(a))]

def g(i, j):
    if i < 0 or j < 0: return ''
    if t[i][j] == -1:
        s = g(i - 1, j - 1)
        if a[i] == b[j]: s += a[i]
        t[i][j] = max(s, g(i - 1, j), g(i, j - 1), key=lambda q: len(q) - q.count(v))
    return t[i][j]

s = g(len(a) - 1, len(b) - 1)
while v in s: s = min(s.replace(v, v[:-1]), s.replace(v, v[1:]), key=lambda q: q.count(v))
print(s if s else 0)
35_C. Fire Again

After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row would have the coordinates of (i, j). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation.

The burning began in K points simultaneously, which means that initially K trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1.

Find the tree that will be the last to start burning. If there are several such trees, output any.

Input

The first input line contains two integers N, M (1 ≤ N, M ≤ 2000) — the size of the forest. The trees were planted in all points of the (x, y) (1 ≤ x ≤ N, 1 ≤ y ≤ M) type, x and y are integers.

The second line contains an integer K (1 ≤ K ≤ 10) — amount of trees, burning in the beginning. 

The third line contains K pairs of integers: x1, y1, x2, y2, ..., xk, yk (1 ≤ xi ≤ N, 1 ≤ yi ≤ M) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide.

Output

Output a line with two space-separated integers x and y — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any.

Examples

Input

3 3
1
2 2


Output

1 1


Input

3 3
1
1 1


Output

3 3


Input

3 3
2
1 1 3 3


Output

2 2

Example input:
3 3
1
2 2

3 3
1
1 1

3 3
2
1 1 3 3


Example output:
1 1

3 3

2 2

Tags: brute force
dfs and similar
shortest paths
Difficulty rating: 1500

Solution:
import java.io.*;
import java.util.*;

public class practice {

		public static void main(String[] args) throws FileNotFoundException {			
			Scanner scn = new Scanner(new FileReader("input.txt"));
			PrintWriter out = new PrintWriter(new File("output.txt"));
		 int n=scn.nextInt(),m=scn.nextInt(),k=scn.nextInt();
		 int[][] inf=new int[k][2];
		 for(int i=0;i<k;i++){
			 inf[i][0]=scn.nextInt();inf[i][1]=scn.nextInt();
		 }
		 int ans=0,x=1,y=1;
		 for(int i=1;i<=n;i++){
			 for(int j=1;j<=m;j++){
				 int temp=Integer.MAX_VALUE;
				 for(int l=0;l<k;l++){
					temp=Math.min(temp, Math.abs(i-inf[l][0])+Math.abs(j-inf[l][1])); 
				 }
				 if(temp>ans){
					 ans=temp;x=i;y=j;
				 }
			 }
		 }
		 out.print(x+ " " + y);
	   	 out.close();
		}
	}