Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official.
×

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
D. Black and White Tree

time limit per test

1 secondmemory limit per test

256 megabytesinput

standard inputoutput

standard outputThe board has got a painted tree graph, consisting of *n* nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles.

Each node of the graph is painted black or white in such a manner that there aren't two nodes of the same color, connected by an edge. Each edge contains its value written on it as a non-negative integer.

A bad boy Vasya came up to the board and wrote number *s*_{v} near each node *v* — the sum of values of all edges that are incident to this node. Then Vasya removed the edges and their values from the board.

Your task is to restore the original tree by the node colors and numbers *s*_{v}.

Input

The first line of the input contains a single integer *n* (2 ≤ *n* ≤ 10^{5}) — the number of nodes in the tree. Next *n* lines contain pairs of space-separated integers *c*_{i}, *s*_{i} (0 ≤ *c*_{i} ≤ 1, 0 ≤ *s*_{i} ≤ 10^{9}), where *c*_{i} stands for the color of the *i*-th vertex (0 is for white, 1 is for black), and *s*_{i} represents the sum of values of the edges that are incident to the *i*-th vertex of the tree that is painted on the board.

Output

Print the description of *n* - 1 edges of the tree graph. Each description is a group of three integers *v*_{i}, *u*_{i}, *w*_{i} (1 ≤ *v*_{i}, *u*_{i} ≤ *n*, *v*_{i} ≠ *u*_{i}, 0 ≤ *w*_{i} ≤ 10^{9}), where *v*_{i} and *u*_{i} — are the numbers of the nodes that are connected by the *i*-th edge, and *w*_{i} is its value. Note that the following condition must fulfill *c*_{vi} ≠ *c*_{ui}.

It is guaranteed that for any input data there exists at least one graph that meets these data. If there are multiple solutions, print any of them. You are allowed to print the edges in any order. As you print the numbers, separate them with spaces.

Examples

Input

3

1 3

1 2

0 5

Output

3 1 3

3 2 2

Input

6

1 0

0 3

1 8

0 2

0 3

0 0

Output

2 3 3

5 3 3

4 3 2

1 6 0

2 1 0

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/23/2021 12:54:15 (j2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|