Numbering path#1101

Numbering path

1 second
128 megabytes
Very easy

Intersections in a city are connected by one-way streets. Write a program to calculate the number of different routes between each pair of intersections. A route is a sequence of one-way streets connecting two intersections.

Intersections are labeled with non-negative integers. A one-way street is specified by the pair of intersections it connects. For example, indicates that there is a one-way street from intersection to intersection . Note that a two-way street can be modeled by two one-way streets: and .

Consider a city with four intersections connected as follows:

There is one route from intersection to , two routes from to (these are 0 \to 1 \to 2 and 0 \to 2), two routes from to , one route from to , one route from to , one route from to , and no other routes.

It is possible for an infinite number of different routes to exist between some intersections. For example, if the street is added to the above, there is still only one route from to , but now there are infinitely many different routes from to . This is because after reaching and , you can repeat traveling from to and back any number of times, yielding distinct routes. For example, 0 \to 2 \to 3 \to 2 \to 3 \to 2 and 0 \to 2 \to 3 \to 2 are both different routes.

Input

The first number is the number of one-way streets in the city, followed by a description of those streets. Each street is represented by a pair of intersections it connects: each pair represents a one-way street from intersection to intersection . In all cities, intersections are numbered sequentially from to the largest intersection. All integers in the input are separated by a space.

There is never a one-way street from an intersection to itself. No city will have more than intersections.

Output

Print a square matrix containing the number of different routes between intersections and . If we denote the output matrix as , then M_{j k} is the number of different routes from intersection to intersection . Print matrix row-by-row, in increasing order of rows.

If there are infinitely many routes between two intersections, print . Do not worry about the alignment and formatting of the output. All numbers in each row of the matrix should be separated by a single space.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading