xorb

Problem Description

Gug was learning about the XOR operator today, and has decided to define his own operation, the xorb operation, which stands for XORing in base B!

The procedure for XORing in base B is defined as follows:

  1. First, convert X and Y into base B.
  2. For each digit position, let the digit in X be m and the digit in Y be n. The digit in that position in the answer will be (m+n) modulo B.
  3. Convert the answer back to the original base.

Refer to the samples for more details.

Given three integers, X, Y and B, your task is to implement this xorb operation and find the answer.

Limits

Subtask 1 (33%): 1 ≤ X, Y ≤ 109, B = 2.

Subtask 2 (67%): 1 ≤ X, Y, B ≤ 109.

Subtask 3 (0%): Sample Testcases.

Input

The only line of input will contain three integers, X, Y and B.

Output

The only line of output should contain one integer, the answer of the xorb operation.

Sample Testcase 1

Input

5 3 2

Output

6

Explanation

When converted to base 2, X = "101" and Y = "011". Therefore, by comparing each digit:

  • first digit: (1 + 0) % 2 = 1.
  • second digit: (0 + 1) % 2 = 1.
  • third digit: (1 + 1) % 2 = 0.

Therefore the final answer is "110", which converts back to 6.

Sample Testcase 2

Input

170 131 5

Output

276

Time Limit: 1 Seconds
Memory Limit: 256MB
Your best score: 0
Source: Dunjudge Archive

Subtask Score
1 33
2 67
3 0