## unknown Interview Question for Software Developers

- 0of 0 votes

AnswersYour friend has invented a new compound consisting of N elements. However, he has forgotten the amount of each element that goes into the recipe.

- Abhishek.Mathur.CA September 30, 2016 in United States

For N-1 pairs of elements, he remembers the proportion in which the elements within each pair should be added to the compound. Fortunately, these N-1 proportions are sufficient to restore the recipe of the entire compound.

You are given N-1 proportions as String. Each String is formatted "#<a> and #<b> as <p>:<q>" (quotes for clarity), which means that the mass of element <a> divided by the mass of element <b> in the cocktail must be equal to <p>/<q> (all elements are 0-indexed). Print exactly N elements, where the first line is the mass of element 0 and second line is the mass of element 1 and so on... such that all the given proportions are satisfied and the total mass is as small as possible. The total mass must be greater than 0.

Input

Line 1: N

Line 2 .. N: proportion_i

Output

N lines of masses, as stated in the problem statement

Input Explanation

Line 1: N, the number of elements

Line 2 to line N: N-1 proportions, format described in the problem statement

Output Explanation

Output will contain exactly N lines, each line is the mass of the element such that all the given proportions are satisfied and the total mass is as small as possible. The total mass must be greater than 0.

Sample Input

3

#0 and #1 as 9:8

#1 and #2 as 9:8

Sample Output

81

72

64| Report Duplicate | Flag | PURGE

unknown Software Developer

**Country:**United States

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.