inputt = input().strip()

if not inputt or inputt.isspace():
    print("ERROR")
else:
    if '  ' in inputt:
        print("ERROR")
    else:
        names = inputt.split()
        student = []
        i = 0
        n = len(names)
        error = False
        
        while i < n and not error:
            if i + 1 >= n:
                error = True
                break
            
            name = names[i]
            h_str = names[i+1]
            if name.isdigit():
                error = True
                break
            
            if not h_str.isdigit():
                error = True
                break
            h = int(h_str)
            if h < 50 or h > 250:
                error = True
                break
            
            student.append((name, h))
            i += 2
        
        if i != n:
            error = True
        
        if error:
            print("ERROR")
        else:
            student.sort(key=lambda x: (-x[1], x[0]))
            for name, h in student:
                print(f"{name} {h}")
