Polish version    English version  
  Reprezentacja -> Relacje z olimpiad


 Aktualności
 O olimpiadzie
 Komitety
 XVIII OI 2010/2011
 Historia OI
 Książeczki OI
 Reprezentacja
Lista reprezentantów
Osiągnięcia
Relacje z olimpiad
BOI 1999
CEOI 1998
CEOI 1997
 Obozy Olimpiady
 Galeria zdjęć
 Ciekawe odsyłacze
 OIG LiveCD
 IV OIG 2009/2010
 Historia OIG
 SIO
 MAIN
Ten dokument nie jest dostępny w polskiej wersji językowej.


Problem: HEX

Hexadecimal Numbers

The base of the hexadecimal system is 16. In order to write down numbers in this system one uses 16 digits 0,1,...,9,A,B,C,D,E,F. The capital letters A,..,F stands for 10,..,15, respectively. For instance the value of the hexadecimal number CF2 is 12 * 162 + 15 * 16 + 2 = 3314 in the decimal system. Let X be the set of all positive integers whose hexadecimal representations have at most 8 digits and do not contain repetitions of any digit. The most significant digit in such a representation is not zero. The largest element in X is the number with the hexadecimal representation FEDCBA98, the second largest is the number FEDCBA97, the third is FEDCBA96 and so forth.

Task

Write a program that:

  • reads positive integer n from the text file HEX.IN, n does not exceed the number of elements of X;
  • finds the n-th largest element of X;
  • writes the result to the text file HEX.OUT.

Input

The first line of the file HEX.IN contains integer n in the decimal representation.

Output

Your program should write the n-th largest element in X in the hexadecimal representation to the first line of the text file HEX.OUT

Example

For the text file HEX.IN:

11
the correct solution is the text file HEX.OUT:
FEDCBA87



Wersja do druku