cswork / OAOpen practice workspace

MetaOA #27

Closest Land Mark

Estimated EasyJudge-ready

Topics (AI-labelled)Bits & Math

The Fibonacci numbers start from 0 and 1, and each later term is the sum of the previous two. Given a non-negative integer N, output the absolute difference to the nearest Fibonacci number; output only the distance, not the number itself.

Input

One line with N (0..1000000).

Output

Output the minimum absolute difference.

Example 1

Input:

25

Output:

4

Example 2

Input:

5

Output:

0

Example 3

Input:

0

Output:

0

Example notes

Example 1: 25 lies between 21 and 34, at distances 4 and 9 respectively, so the answer is 4.

Example 2: 5 is itself a Fibonacci number, so the distance is 0.

Example 3: 0 is the first term of the sequence, so the distance is 0.

Editorial

Loading solution…