Under construction

Still being built. Things may change

IQ Test

Time limit2sMemory limit128 MB

Summary
Given an integer sequence, decide whether an integer rule next = a*prev + b determines the next term uniquely, ambiguously, or not at all.
Level

Medium5 of 10

Topics
Math, Implementation, Simulation
Solved
No attempts yet

Problem

You are given an integer sequence. Determine the next value under a rule of the form next term = previous term * a + b, where both a and b are integers.

If the next value is uniquely determined, print that value. If several next values are possible, print A. If no integer pair a, b can generate the given sequence, print B.

Input

The first line contains N, a positive integer not greater than 50. The second line contains N integers separated by spaces. The absolute value of each integer is at most 100.

Output

Print the next value. If several next values are possible, print A. If the next value cannot be determined because the sequence cannot be generated by any valid rule, print B.

Examples9

  1. Example 1

    Input
    4
    1 4 13 40
    
    Expected output
    121
    
  2. Example 2

    Input
    5
    1 2 3 4 5
    
    Expected output
    6
    
  3. Example 3

    Input
    5
    3 6 12 24 48
    
    Expected output
    96
    
  4. Example 4

    Input
    1
    0
    
    Expected output
    A
    
  5. Example 5

    Input
    2
    -1 2
    
    Expected output
    A
    
  6. Example 6

    Input
    2
    57 57
    
    Expected output
    57
    
  7. Example 7

    Input
    4
    16 -8 4 -2
    
    Expected output
    B
    
  8. Example 8

    Input
    5
    6 5 4 3 1
    
    Expected output
    B
    
  9. Example 9

    Input
    4
    -12 12 -36 60
    
    Expected output
    -132