#P8142. Interstellar Map Matching

    ID: 21324 Type: Default 1000ms 256MiB

Interstellar Map Matching

Interstellar Map Matching

In the year 2521, interstellar probes have reached distant solar systems. The Interstellar Consortium of Planet Cartographers (ICPC) has produced detailed maps of various planets. Each map contains a set of points on the spherical surface of a planet, each point described by a latitude and a longitude. The latitude values always coincide between maps of the same planet (since the planet's axis remains fixed), but the longitudes can differ by a constant rotation, due to the planet's rotation between measurements.

Your task is to determine whether two given maps describe the same planet. In other words, check if there exists a constant rotation \(d\) (in degrees) such that for every point \((lat, lon)\) in the first map, there is a corresponding point in the second map at \((lat, (lon+d)\ \bmod\ 360)\). Note that the maps may list the points in arbitrary order and may include multiple points with the same latitude.

If such a rotation exists (and is the same for all latitude groups), the maps describe the same planet; otherwise, they do not.

Note: Use the modulo operation for longitudes. That is, if \(a + d \ge 360\), then consider \((a+d) \bmod 360\).

inputFormat

The input begins with a single integer \(n\) representing the number of points in each map. The following \(n\) lines each contain two numbers \(lat\) and \(lon\) which represent a point in the first map. The next \(n\) lines contain two numbers each, representing the points in the second map.

All longitudes are in degrees and can be considered as floating point numbers. You may assume that the two maps have the same number of points.

outputFormat

Output a single line containing either Same if there exists a constant \(d\) (modulo 360) for which each point in the first map corresponds to a point in the second map using the transformation \(lon \rightarrow (lon+d)\bmod 360\), or Different otherwise.

sample

1
45 10
45 20
Same