Polish version    English version  
  About Olympic -> Problems


 News
 About Olympic
About contest
Problems
I OI 1993/1994
II OI 1994/1995
III OI 1995/1996
IV OI 1996/1997
V OI 1997/1998
VI OI 1998/1999
VII OI 1999/2000
VIII OI 2000/2001
IX OI 2001/2002
X OI 2002/2003
XI OI 2003/2004
XII OI 2004/2005
XIII OI 2005/2006
XIV OI 2006/2007
XV OI 2007/2008
Problems archive
 History of OI
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
III Olympiad in Informatics 1995/1996

Task: PER
Author: Wojciech Guzicki
Anti-arythmetic permutations

III stage contest  

We call a permutation p0, p1, ... , pn-1 of integers 0, 1, ... , n-1 anti-arithmetic, when there are no three-term arithmetic series in this permutation, i.e. there are no such three indices i < j < k, that integers pi, pj, pk make an arithmetic series. For example the series of integers 3, 1, 0, 4, 2 is an anti-arithmetic permutation of integers 0, 1, 2, 3, 4. The series 0, 5, 4, 3, 1, 2 is not an anti-arithmetic permutation, because its first, fifth and sixth term: 0, 1, 2 form an arithmetic series (as well as its second, forth and fifth term: 5, 3, 1 and second third and forth term: 5, 4, 3 form arithmetic series).

Task

Write a program that:

  • reads one positive integer n from the text file PER.IN,
  • computes any anti-arithmetic permutation of numbers 0, 1, ... , n-1 and writes it into the text file PER.OUT.

Input

There is one positive integer n, 3 <= n <= 1000000, written in the text file PER.IN. 

Output

The output file PER.OUT should be composed of n lines. These lines should contain different integers from the set {0, 1, ... , n-1}, one in each line. The numbers in the consecutive lines should form an anti-arithmetic permutation of numbers 0, 1, ..., n-1.

Example

If there is number 5 written in the input file PER.IN, then one of the correct solutions is the following file PER.OUT :
3
1
0
4
2

Your program should look for the file PER.IN in the current directory and produce the output file PER.OUT in the current directory too. The file containing the source code of your program should have a name PER.???, whereas you should put three-letter abbreviation of the used programming language name instead of ???. The same program in executable form should be written in file PER.EXE




Print friendly version