Plagiarism Detection

Time limit: 0.15s Memory limit: 32MB Input: Output:

Giorgio is pursuing a career as a singer-songwriter! However, the music world is tough, and you always need to watch out for plagiarism. In fact, the last song that Alessandro wrote sounds suspiciously similar to one of Giorgio’s songs, and now Giorgio wants to prove Alessandro’s mischief.

Both Giorgio’s and Alessandro’s songs are NN notes long. Each note is encoded by two integers between 00 and VV: its duration did_i, followed by its pitch pip_i. Each song is then encoded as a sequence of 2N2 \cdot N integers.

Of course, the plagiarism case will be uncontroversial if the two songs are identical. If not, the plagiarism case will be stronger if Giorgio can find a short contiguous sequence of notes that needs to be modified to transform Giorgio’s song into Alessandro’s.

For such a sequence, if possible, it would be better for Giorgio if he can prove that applying some of these classical tune transformations transforms his song into Alessandro’s:

  • Transposition: increase or decrease every pitch in the sequence by the same amount;
  • Doubling (resp. halving): double (resp, halve) every duration in the sequence;
  • Retrogradation: invert the sequence of notes, playing them from the last one to the first.

Note that each operation can be used at most once.

Help Giorgio file his claim on Alessandro’s mischief as strongly as possible by finding the shortest sequence to change!

Input data

The first line contains the two integers NN and VV.

The next NN lines contain two integers each (did_i and pip_i) describing Giorgio’s song.

The next NN lines contain two integers each (did_i and pip_i) describing Alessandro’s song.

Output data

You need to write a single line with one of the following contents:

  • SAME: if the two songs are identical;
  • TRANSFORMED L: if Alessandro’s song can be obtained by modifying a sequence of length LL using some of the operations described above;
  • ORIGINAL L: there is a sequence of length LL that cannot be obtained just by applying the operations described above

Constraints and clarifications

  • 1N100 0001 \leq N \leq 100 \ 000;
  • 1V1091 \leq V \leq 10^9;
  • 0di,piV0 \leq d_i, p_i \leq V;
# Score Constraints
1 0 Examples
2 20 N,V500N, V \leq 500
3 15 N500N \leq 500
4 25 N,V10 000N, V \leq 10 \ 000
5 10 V10 000V \leq 10 \ 000
6 30 No additional limitations

Example 1

stdin

3 127
48 60
48 62
96 64
48 60
48 62
96 64

stdout

SAME

Explanation

In the first sample case, the two songs are identical.

Example 2

stdin

6 127
48 60
48 62
48 64
96 60
48 62
96 64
48 60
48 62
96 64
48 60
48 62
96 64

stdout

ORIGINAL 2

Explanation

In the second sample case, Alessandro’s song is obtained by rewriting the third and fourth notes 48 6448 \ 64, 96 6096 \ 60 into 96 6496 \ 64, 48 6048 \ 60, leaving the rest unchanged. Note that this is not obtainable through a combination of some classical tune transformations.

Example 3

stdin

7 127
48 60
48 62
48 64
96 60
48 62
48 64
96 60
48 60
24 67
48 65
24 69
24 67
48 64
96 60

stdout

TRANSFORMED 4

Explanation

In the third sample case, Alessandro’s song can be obtained by transforming the sequence from the second note to the fifth, by applying halving, retrogradation and then a +5+5 transposition.

Log in or sign up to be able to send submissions!