Is it rated?

Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.

Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.

It's known that if at least one participant's rating has changed, then the round was rated for sure.

It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.

In this problem, you should not make any other assumptions about the rating system.

Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.


-----Input-----

The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of round participants.

Each of the next n lines contains two integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ 4126) — the rating of the i-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.


-----Output-----

If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".


-----Examples-----
Input
6
3060 3060
2194 2194
2876 2903
2624 2624
3007 2991
2884 2884

Output
rated

Input
4
1500 1500
1300 1300
1200 1200
1400 1400

Output
unrated

Input
5
3123 3123
2777 2777
2246 2246
2246 2246
1699 1699

Output
maybe



-----Note-----

In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.

In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.

In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.

Difficulty: interview

Starter code:

Solutions:
'''input
5
3123 3123
2777 2777
2246 2246
2246 2246
1699 1699
'''
n = int(input())
x = []
f = 0
for _ in range(n):
	a, b = list(map(int, input().split()))
	if a != b:
		f = 1
	x.append(a)
if f == 1:
	print("rated")
elif sorted(x)[::-1] == x:
	print("maybe")
else:
	print("unrated")









def sol():
    n = int(input())
    flag = False
    last = None
    for i in range(n):
        a,b = map(int, input().split(' '))
        if a != b:
            return "rated"
        if last is not None and a > last:
            flag = True
        last = a
    if flag:
        return "unrated"
    else:
        return "maybe"



print(sol())

N = int(input())
ratings = [tuple(int(x) for x in input().split()) for _ in range(N)]
if any(a != b for a, b in ratings):
    print("rated")
elif sorted(ratings, reverse=True) == ratings:
    print("maybe")
else:
    print("unrated")


n = int(input())
a=[[int(i) for i in input().split()] for i in range(n)]
ans = 'maybe'
for i in range(n):
    if a[i][0] != a[i][1]:
        ans = 'rated'
        break
else:
    for i in range(n-1):
        if a[i][0] < a[i+1][0]:
            ans = 'unrated'
            break
print(ans)


n = int(input())
a = []
a1 = []
for i in range(n):
    f,s = list(map(int, input().split()))
    if f != s:
        print("rated")
        return
    a.append(s)
    a1.append(s)
a.sort()
if a[::-1] == a1:
    print("maybe")
    return
print("unrated")



n = int(input())
s = []
for i in range(n):
    a, b = map(int, input().split())
    if a !=b:
        print("rated")
        break
    s.append(b)
else:
    if s[::-1] != sorted(s):
        print("unrated")
    else:
        print("maybe")

from sys import stdin
input = stdin.readline

n = int(input())

change = 0
unordered = 0
c = float('inf')
for i in range(n):
  a, b = [int(x) for x in input().split()]
  if a!=b:
    change = 1
    break
  elif c<a:
    unordered=1
  c = a

if change:
  print('rated')
elif unordered:
  print('unrated')
else:
  print('maybe')
  


n = int(input())

ans = 'maybe'
rate = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    rate[i] = [a, b]
    if a != b:
        ans = 'rated'
        
if ans == 'rated':
    print(ans)
else:
    mn = 10 ** 9
    for i in range(n):
        if mn < rate[i][0]:
            ans = 'unrated'
            break
        
        mn = min(mn, rate[i][0])
        
    print(ans)

n = int(input())
a = [0]*n
b = [0]*n
s1 = True
s2 = True
for i in range(n):
    a[i], b[i] = list(map(int, input().split() ))
    if a[i] != b[i]:
        s1 = False
if a == list(reversed(sorted(a))):
    s2 = False

if not s1:
    print("rated")
elif  not s2:
    print("maybe")
else:
    print("unrated")


n = int(input())

rates = []

for i in range(n):
    before, after = list(map(int, input().split()))
    rates.append(before)
    if before != after:
        print('rated')
        return

print('maybe' if rates == list(reversed(sorted(rates))) else 'unrated')


n = int(input())

ratings = []
is_rated = False
for _ in range(n):
    start, end = [int(p) for p in input().split()]
    if start != end:
        is_rated = True
    ratings.append((start, end))

if is_rated:
    print('rated')
else:
    #
    if list(reversed(sorted(ratings, key=lambda x: x[0]))) == ratings:
        print('maybe')
    else:
        print('unrated')


t=int(input())
f=1
g=0
a=[]
while(t):
    t-=1
    a.append(list(map(int,input().split())))
for i in range(len(a)):
    if(a[i][0]!=a[i][1]):
        f=0
    if(i!=0 and a[i][0]>a[i-1][0]):
        g=1
if(f==0):
    print("rated")
else:
    if(g):
        print("unrated")
    else:
        print("maybe")

import sys

input_ = sys.stdin.readline


def is_ordered(arr):
    for i in range(len(arr) - 1):
        if arr[i] < arr[i + 1]:
            return False
    else:
        return True


def main():
    n = int(input_())
    changed = False

    befores = []
    afters = []

    for x in range(n):
        before, after = list(map(int, input_().split()))

        if before != after:
            changed = True

        befores.append(before)
        afters.append(after)

    if changed:
        return "rated"

    if is_ordered(afters):
        return "maybe"

    return "unrated"


def __starting_point():
    print(main())

__starting_point()

from sys import stdin, stdout


n = int(stdin.readline().rstrip())

a=[]
b=[]
for i in range(n):
    x,y = list(map(int, stdin.readline().rstrip().split()))
    a.append(x)
    b.append(y)

rated = 0
for i in range(n):
    if a[i]!=b[i]:
        rated=1
        break
    
if not rated:
    for i in range(n-1):
        if a[i]<a[i+1]:
            rated=-1

if rated==1:
    print("rated")
elif rated==0:
    print("maybe")
else:
    print("unrated")


n = int(input())

nochange = True
order_kept = True

prev_b = float("inf")
for i in range(n):
    b, a = list(map(int, input().split()))
    if b != a:
        nochange = False
        break
    if b > prev_b:
        order_kept = False
    prev_b = b

if not nochange:
    print("rated")
else:
    if order_kept:
        print("maybe")
    else:
        print("unrated")


n = int(input())
L = []
ans = "maybe"
for _ in range(n):
    a, b = list(map(int, input().split()))
    L.append((a,b))
    if a != b:
        ans = "rated"
        break
L1 = L[:]
L1.sort(reverse=True)
for i in range(len(L)):
    if L[i] != L1[i] and ans != "rated":
        ans = "unrated"
        break
print(ans)


import math,string,itertools,collections,re,fractions,array,copy
import bisect
import heapq
from itertools import chain, dropwhile, permutations, combinations
from collections import deque, defaultdict, OrderedDict, namedtuple, Counter, ChainMap


# Guide:
#   1. construct complex data types while reading (e.g. graph adj list)
#   2. avoid any non-necessary time/memory usage
#   3. avoid templates and write more from scratch
#   4. switch to "flat" implementations

def VI(): return list(map(int,input().split()))
def I(): return int(input())
def LIST(n,m=None): return [0]*n if m is None else [[0]*m for i in range(n)]
def ELIST(n): return [[] for i in range(n)]
def MI(n=None,m=None): # input matrix of integers
    if n is None: n,m = VI()
    arr = LIST(n)
    for i in range(n): arr[i] = VI()
    return arr
def MS(n=None,m=None): # input matrix of strings
    if n is None: n,m = VI()
    arr = LIST(n)
    for i in range(n): arr[i] = input()
    return arr
def MIT(n=None,m=None): # input transposed matrix/array of integers
    if n is None: n,m = VI()
    a = MI(n,m)
    arr = LIST(m,n)
    for i,l in enumerate(a):
        for j,x in enumerate(l):
            arr[j][i] = x
    return arr

def main(info=0):
    n = I()
    m = MI(n, 2)

    for a,b in m:
        if a != b:
            print("rated")
            return
    for i in range(1, n):
        if m[i][0] > m[i-1][0]:
            print("unrated")
            return
    print("maybe")




def __starting_point():
    main()

__starting_point()

n=int(input())
l1=[]
l2=[]
for i in range(n):
	a,b=map(int,input().split())
	l1.append(a)
	l2.append(b)
rc = False
for i in range(n):
	if(l1[i]!=l2[i]):
		rc=True
		break
if(rc==True):
	print("rated")
	return
tot = 0
for i in range(1,n):
	if(l2[i]<=l2[i-1]):
		tot+=1
if(tot==n-1):
	print("maybe")
	return
print("unrated")

# written by sak
#
#	sk<3
#
# powered by codechef

n=int(input())
change=0
ordered=1
p=997979
q=86949
while n>0:
	x=input()
	x=x.split(' ')
	if(int(x[0])>p):
		ordered=0
	p=int(x[0])
	q=int(x[1])
	if(p!=q):
		change=1
	n-=1

if(change==1):
	print("rated")
elif(ordered==0):
	print("unrated")
else:
	print("maybe")


n=int(input())
x=[]
y=[]
for i in range(n):
	s=input()
	s=s.split()
	x.append(int(s[0]))
	y.append(int(s[1]))
flag=0
for i in range(n):
	if(x[i]!=y[i]):
		flag=1
		break
	elif(i>0):
		if(x[i]>x[i-1]):
			flag=2
if(flag==1):
	print("rated")
elif(flag==2):
	print("unrated")
else:
	print("maybe")
	


n = int(input())
A = []
for i in range(n):
	b, a = map(int, input().split())
	A.append(a)
	if b != a:
		print("rated")
		break
else:
	B = sorted(A)
	A.reverse()
	if A == B:
		print("maybe")
	else:
		print("unrated")

import sys

n = int(input())

kek = False
changed = False

prev = 9999
for i in range(n):
    x, y = list(map(int, input().split()))
    if x != y:
        changed = True
    if y > prev:
        kek = True
    prev = y

if not kek and not changed:
    print("maybe")
elif kek and not changed:
    print("unrated")
else:
    print("rated")


import sys
n = int(input())

kek = []

for i in range(n):
  a, b = (int(i) for i in input().split())
  kek.append(a)
  if a != b:
    print("rated")
    return

if kek == list(sorted(kek, reverse=True)):
  print("maybe")
else:
  print("unrated")
    


n=int(input())
max=4127
T=True
for i in range(n):
	l,r=list(map(int,input().split()))
	if l==r:
		if max<l:
			T=False
		max=l
	else:
		print("rated")
		break
else:
	if T:
		print("maybe")
	else:
		print("unrated")