Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/raqamlar-almashinuvchi-yigindisi

Alternating digit sum

Easy 1000 ms 64 MB 29%
Share

A positive integer $n$ is given. Starting from the last digit, add and subtract its digits in turn: the last digit is added, the one before it is subtracted, the one before that is added, and so on. For example, for $1234$: $4 - 3 + 2 - 1 = 2$.

Alternating plus and minus signs under the digits of the number, starting from the last digit

Input

One positive integer $n$.

Output

One integer — the alternating sum.

Note

$1 \le n \le 10^{18}$

Examples

Input #1
1234
Output #1
2
Input #2
909
Output #2
18

Sign in to submit a solution

Signing up is free and takes a minute.