Problem:
Score : 100 points

Problem Statement

You went shopping to buy cakes and donuts with X yen (the currency of Japan).

First, you bought one cake for A yen at a cake shop.
Then, you bought as many donuts as possible for B yen each, at a donut shop.

How much do you have left after shopping?

Constraints

1 \leq A, B \leq 1 000

A + B \leq X \leq 10 000

X, A and B are integers.

Input

Input is given from Standard Input in the following format:

X
A
B

Output

Print the amount you have left after shopping.

Sample Input 1

1234
150
100

Sample Output 1

84

You have 1234 - 150 = 1084 yen left after buying a cake.
With this amount, you can buy 10 donuts, after which you have 84 yen left.

Sample Input 2

1000
108
108

Sample Output 2

28

Sample Input 3

579
123
456

Sample Output 3

0

Sample Input 4

7477
549
593

Sample Output 4

405

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_cols<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn execute() -> bool {
    let header = read_cols::<usize>();
    let n_variables = header[0];
    let n_info = header[1];

    let mut mat = Vec::new();
    mat.resize(n_variables, Vec::<(usize, i32)>::new());
    let mut num_ins = Vec::new();
    num_ins.resize(n_variables, 0);

    for _ in 0..n_info {
        let info = read_cols::<i32>();
        let i_left = (info[0] - 1) as usize;
        let i_right = (info[1] - 1) as usize;
        let diff = info[2];
        mat[i_left].push((i_right, diff));
        num_ins[i_right] += 1;
    }
    let mat = mat;

    let mut stack = Vec::new();
    for i in 0..n_variables {
        if num_ins[i] == 0 {
            stack.push(i);
        }
    }
    let mut tp_sorted = Vec::new();
    let mut full_mat = mat.clone();
    while let Some(n) = stack.pop() {
        tp_sorted.push(n);

        for &(m, diff) in &mat[n] {
            full_mat[m].push((n, -diff));
            num_ins[m] -= 1;
            if num_ins[m] == 0 {
                stack.push(m);
            }
        }
    }

    if tp_sorted.len() != n_variables {
        // has loop ( = inconsisetent info)
        return false;
    }

    let mut visited = Vec::new();
    visited.resize(n_variables, false);
    for i in tp_sorted {
        if visited[i] {
            continue;
        }

        let mut positions = Vec::<Option<i32>>::new();
        positions.resize(n_variables, None);
        let mut stack = Vec::new();
        stack.push(i);

        positions[i] = Some(0);
        while let Some(n) = stack.pop() {
            if visited[n] {
                continue;
            }

            visited[n] = true;
            for &(m, diff) in full_mat[n].iter().rev() {
                let pos_m = positions[n].unwrap() + diff;
                if let Some(current_pos_m) = positions[m] {
                    if current_pos_m != pos_m {
                        return false;
                    }
                    // Already pushed
                    continue;
                }

                positions[m] = Some(pos_m);
                stack.push(m);
            }
        }
    }

    return true;
}

fn main() {
    println!("{}", match execute() {
        false => "No",
        true => "Yes",
    });
}