Under construction

Still being built. Things may change

Rank Order

Interview

Time limit3sMemory limit256 MB

Summary
Compare two judges' score lists by ranked order and report the highest place where the ranked competitors differ, or agree when all match.
Level

Easy3 of 10

Topics
Sorting
Solved
No attempts yet

Problem

A competition director supervises a panel of judges. Each judge gives every competitor an integer score, and a higher score is a better score. The competition publishes standards for what the score values mean, but judges read those standards differently, so a score of 100 can mean one thing to one judge and something else to another.

The director wants to know which competitors should receive the prizes for the top places. Absolute scores differ from judge to judge, but relative rankings carry the information the director needs. If two judges put the same competitors in first place, second place, third place, and so on, they agree on who should receive the prizes.

Write a program that compares the scores of a pair of judges. Read two lists of integer scores given in competitor order and report the highest ranking place at which the two judges disagree. First place is the highest place.

Input

The input is a series of score list pairs. Each pair begins with a single integer NN, the number of competitors, where 1<N<10000001 < N < 1000000. The next NN integers are the first judge's scores in competitor order. The NN integers after those are the second judge's scores, also in competitor order. Every score is between 00 and 100000000100000000 inclusive. Judges may not give ties, so the scores of a single judge are all different. Values are separated by one or more spaces or newlines. End of file follows the last score list pair.

Output

Print one line for each score list pair. The line holds the integer for the highest ranking place at which the two judges do not agree. If the judges agree on every place, the line holds only the word agree. The line format is Case, one space, the case number, a colon, one space, then the answer for that case, with no trailing spaces. Case numbers start at 1.

Examples5

  1. Example 1

    Input
    4
    3 8 6 2
    15 37 17 3
    8
    80 60 40 20 10 30 50 70
    160 100 120 80 20 60 90 135
    
    Expected output
    Case 1: agree
    Case 2: 3
    
  2. Example 2

    Input
    2
    5 9
    1000 2000
    
    Expected output
    Case 1: agree
    
  3. Example 3

    Input
    2
    0 1
    100000000 0
    
    Expected output
    Case 1: 1
    
  4. Example 4

    Input
    3
    0 100000000 50
    7 100000000 0
    
    Expected output
    Case 1: 2
    
  5. Example 5

    Input
    6
    1 2 3 4 5 6
    6 5 4 3 2 1
    
    Expected output
    Case 1: 1