This page is still under construction.

Parts of this page are still being built. What you see may change.

Which Planet is This?!

Time limit6sMemory limit2048 MB

Summary
Given two sets of n latitude-longitude points on a sphere, decide whether one set can be rotated about the axis to match the other.
Level

Medium7 of 10

Topics
Sorting, Hash map, Geometry, Implementation
Solved
No attempts yet

Problem

It is the year 2521, and interstellar probes have reached planets in distant solar systems. The Interstellar Consortium of Planet Cartographers (ICPC) has made detailed maps of these planets, and the maps seem to show evidence of alien life. On each map, the ICPC recorded the locations of what appear to be alien dwellings.

The ICPC planned to release this news to the public, but disaster struck at the last moment. One of the ICPC's interns deleted all metadata associated with the maps. The maps themselves are safe, but the ICPC does not know which map belongs to which planet. So the ICPC has come back in time to ask for your help. Given two maps, can you determine whether they describe the same planet? A 500-year head start should be enough time to solve this important problem.

The planetary maps consist of sets of points on the (spherical) planet surface. Each point is given by its latitude (the angle north or south of the equator) and longitude (the angle west or east of the noon meridian, which is the location of the sun when the map's data was collected). Two maps of the same planet always agree on the latitudes of the points, since the planet's axis does not change. However, the longitudes of the points may differ, because the planet rotates between measurements.

Input

The first line of input contains an integer nn (1≤n≤400 0001 \le n \le 400\,000), the number of points in each of the two maps to be compared. Then follow nn lines describing the first map. Each of these lines contains two real numbers aa and bb, where aa (−90<a<90-90 < a < 90) is the latitude and bb (−180<b≤180-180 < b \le 180) is the longitude. Coordinates are expressed in degrees and have at most four digits after the decimal point. No two points on the map will have the same coordinates. The remaining nn lines describe the second map in the same format as the first.

Output

Output Same if there is a rotation around the planet's axis that transforms one map into the other. Otherwise, output Different.

Examples2

  1. Example 1

    Input
    4
    0.0000 0.0000
    30.0000 90.0000
    -45.0000 -30.0000
    30.0000 60.0000
    30.0000 150.0000
    30.0000 120.0000
    0.0000 60.0000
    -45.0000 30.0000
    
    Expected output
    Same
    
  2. Example 2

    Input
    3
    0.0000 0.0000
    30.0000 0.0000
    30.0000 90.0000
    0.0000 0.0000
    30.0000 0.0000
    30.0000 -90.0000
    
    Expected output
    Different