#Lutece0195. Controlling Companies

Controlling Companies

Migrated from Lutece 195 Controlling Companies

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Some companies are partial owners of other companies because they have acquired part of their total shares of stock. For example, Ford owns 12%12\% of Mazda. It is said that a company AA controls company BB if at least one of the following conditions is satisfied:

  • Company AA = Company BB
  • Company AA owns more than 50%50\% of Company BB
  • Company AA controls KK (K1K\geq 1) companies denoted C1,,CKC_1, \cdots, C_K with each company CiC_i owning xi%x_i\% of company BB and x1++xK>50%x_1 + \cdots + x_K > 50\%.

Given a list of triples (i,j,p)(i,j,p) which denote company ii owning p%p\% of company jj, calculate all the pairs (h,s)(h,s) in which company hh controls company ss. There are at most 100100 companies.

Write a program to read the list of triples (i,j,p)(i,j,p) where ii, jj and pp are positive integers all in the range [1100][1\cdots 100] and find all the pairs (h,s)(h,s) so that company hh controls company ss.

Input

Line 11: nn, the number of input triples to follow

Line 2n+12\cdots n+1: Three integers per line as a triple (i,j,p)(i,j,p) described above.

Output

List 00 or more companies that control other companies. Each line contains two integers that denote that the company whose number is the first integer controls the company whose number is the second integer. Order the lines in ascending order of the first integer (and ascending order of the second integer to break ties). Do not print that a company controls itself.

Samples

3
1 2 80
2 3 80
3 1 20
1 2
1 3
2 3

Resources

USACO TRAINING selected by rectaflex