#K42837. Valid Pattern Lock Sequence

    ID: 27176 Type: Default 1000ms 256MiB

Valid Pattern Lock Sequence

Valid Pattern Lock Sequence

You are given a sequence of integers that represent an attempt at drawing a pattern lock on a 3x3 grid (numbered 1 through 9). Your task is to determine whether the given sequence constitutes a valid pattern lock. A pattern lock is valid if it satisfies the following conditions:

  • Each number in the sequence must be between 1 and 9.
  • No number appears more than once in the sequence.
  • For any two consecutive numbers a and b in the sequence, if there is a number c that lies between a and b (according to the pattern lock rules), then c must have been visited earlier in the sequence.

The intermediate number conditions can be formally stated as follows: if the move from a to b requires passing over an intermediate digit c (i.e. if \( (a,b) \) is one of the pairs {(1,3), (3,1)} with \( c=2 \), {(1,7), (7,1)} with \( c=4 \), {(3,9), (9,3)} with \( c=6 \), {(7,9), (9,7)} with \( c=8 \), {(1,9), (9,1)} with \( c=5 \), {(2,8), (8,2)} with \( c=5 \), {(3,7), (7,3)} with \( c=5 \), {(4,6), (6,4)} with \( c=5 \)), then c must already be part of the pattern before the move from a to b is made.

Your program should read the pattern sequence from standard input and output either True if the sequence forms a valid pattern lock, or False otherwise.

inputFormat

The input is provided via standard input. It consists of a single line containing the sequence of integers separated by spaces. For example:

1 2 3 6 5 4 7 8 9

outputFormat

The output should be a single line printed to standard output: True if the pattern is valid, or False if it is not.

## sample
1 2 3 6 5 4 7 8 9
True