This page is still under construction.

Parts of this page are still being built. What you see may change.

Strategy

Time limit1sMemory limit16 MB

Summary
Given the first two terms of the sequence where each next term is the absolute difference of the previous two, find the K-th term.
Level

Medium7 of 10

Topics
Number theory, Simulation
Solved
No attempts yet

Problem

During the World Cup 2014 qualifications, Serbia national football team had an interesting strategy. They were starting each attack by passing the ball from the player with the number N1 to the player with the number N2. Each following pass was to the player whose number equals the absolute value of the difference between the numbers of the two players previously having the ball. More formally, after the player Ni-2 passes the ball to the player Ni-1, the next player to receive the ball is the player Ni = |Ni-2 – Ni-1|.

This strategy, surprisingly, did not prove itself to be a useful one. Nevertheless, it made fans ponder who will be the K-th player to get the ball, given that the attack actually lasts long enough.

Input

The single line of input contains three non-negative integers, N1, N2, and K.

Output

The single line of output should contain the number Nk.

Constraints

  • 0 ≤ N1, N2 < 263
  • 1 ≤ K < 263

Hint

The players received the ball in the following order:

37, 16, 21, 5, 16, 11, 5, 6, 1, 5, 4, 1, 3, 2, 1, 1, 0, 1, 1, 0, …

The eight player to receive the ball is the player with the number 6.

Examples4

  1. Example 1

    Input
    37 16 8
    
    Expected output
    6
    
  2. Example 2

    Input
    17254968996716914 5030751795369479754 2731091466
    
    Expected output
    2019640987948
    
  3. Example 3

    Input
    0 1 3
    
    Expected output
    1
    
  4. Example 4

    Input
    1 1 5
    
    Expected output
    1