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 ACM-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

F. Connecting Vertices

time limit per test

4 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputThere are *n* points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw *n* - 1 segments, each connecting any two marked points, in such a way that all points have to be connected with each other (directly or indirectly).

But there are some restrictions. Firstly, some pairs of points cannot be connected directly and have to be connected undirectly. Secondly, the segments you draw must not intersect in any point apart from the marked points (that is, if any two segments intersect and their intersection is not a marked point, then the picture you have drawn is invalid).

How many ways are there to connect all vertices with *n* - 1 segments? Two ways are considered different iff there exist some pair of points such that a segment is drawn between them in the first way of connection, but it is not drawn between these points in the second one. Since the answer might be large, output it modulo 10^{9} + 7.

Input

The first line contains one number *n* (3 ≤ *n* ≤ 500) — the number of marked points.

Then *n* lines follow, each containing *n* elements. *a*_{i, j} (*j*-th element of line *i*) is equal to 1 iff you can connect points *i* and *j* directly (otherwise *a*_{i, j} = 0). It is guaranteed that for any pair of points *a*_{i, j} = *a*_{j, i}, and for any point *a*_{i, i} = 0.

Output

Print the number of ways to connect points modulo 10^{9} + 7.

Examples

Input

3

0 0 1

0 0 1

1 1 0

Output

1

Input

4

0 1 1 1

1 0 1 1

1 1 0 1

1 1 1 0

Output

12

Input

3

0 0 0

0 0 1

0 1 0

Output

0

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/11/2018 00:04:04 (d2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|