АВТ
Язык:

Дистанционный практикум по программированию

Задачи Online статус Соревнования
Новости Справка СДО
 
Здравствуйте, Гость! Войдите с паролем или зарегистрируйтесь.

1139. Последовательность.

Ограничение времени: 1 сек.
Ограничение памяти:65536 КБайт
Баллы:100
Статистика Послать на проверку Задачу добавил debug

Условия с турнира школьников на русском языке

Integer sequences are very interesting mathematical objects. Let us examine a sequence generated with the use of two operations: doubling and “digit sorting”. The latter operation consists in ascending-order sort of the individual digits in the decimal representation of the argument. For example, “digit sorting” of number 5726 gives 2567.

The first member of the considered sequence is 1. To generate a member of the sequence from the previous member, double the previous one and apply “digit sorting” to the result. The first 15 members of the sequence are as follows:

1, 2, 4, 8, 16, 23, 46, 29, 58, 116, 223, 446, 289, 578, 1156, …

Write a program to determine the value of the n-th member of this sequence.

 


Limitations

1 <= n <= 2 147 483 647.


Input

The first line contains an integer n, the number of sequence member to be calculated.


Output

The output file should contain a single integer k, the value of the n-th member of the sequence.


Example

Input

Output

1

1

 

Input

Output

6

23

 

 

All Rybinsk-2012 problems (in PDF)

Статистика Послать на проверку Обсуждение задачи Автор/источник:
Задачи с соревнований и сборов / Чемпионат мира по программированию (ICPC) / Рыбинск-2012 /
1138. B - Остров 1139. 1140. D - Selection 1141. E - Головоломка 1142. F - GCDs
Задачи с соревнований и сборов / Чемпионат мира по программированию (ICPC) / Школьники-Рыбинск-2012 /
1148. D - Малина 1139. 1144. F - Верстовые столбы 1141. G - Головоломка 1147. H - Треугольники
 
время генерации 0.125 сек.
© Copyright ВоГУ, АВТ, Носов Д.А., Андрианов И.А.