Antiarithmetic?
Time limit1sMemory limit128 MB
Given a permutation of 0 to n-1, decide whether any three positions contain values forming an arithmetic progression.
- Level
Medium4 of 10
- Topics
- Hash map, Brute force, Math
- Solved
- No attempts yet
Problem
A permutation of is a bijection on the first natural numbers . A permutation is called antiarithmetic if none of its subsequences of length greater than forms an arithmetic progression; that is, there are no three indices such that is an arithmetic progression ().
For example, the sequence is an antiarithmetic permutation of . The sequence is not antiarithmetic: its first, fifth and sixth terms form an arithmetic progression, and so do its second, fourth and fifth terms .
Your task is to decide whether a given permutation of is antiarithmetic.
Input
The input contains several test cases, followed by a line containing a single . Each test case is one line: a natural number (), followed by a colon (:), followed by distinct numbers separated by whitespace. These numbers are all natural numbers smaller than — i.e. a permutation of through .
Output
For each test case, print yes if the permutation is antiarithmetic and no otherwise, one answer per line.