Problem:
Score : 700 points

Problem Statement

Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.

Constraints

2 \leq K \leq 10^5

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K.

Sample Input 1

6

Sample Output 1

3

12=6×2 yields the smallest sum.

Sample Input 2

41

Sample Output 2

5

11111=41×271 yields the smallest sum.

Sample Input 3

79992

Sample Output 3

36

Solution in Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::input;

// 01BFS
fn shortest_path(wvv: &Vec<Vec<(usize, usize)>>, iv: usize, ev: usize) -> usize {
    let mut uv = vec![false; wvv.len()];
    let mut deque = std::collections::VecDeque::new();
    deque.push_back((iv, 0));
    while let Some((v, c)) = deque.pop_front() {
        if v == ev {
            return c;
        }
        uv[v] = true;
        for &(nv, w) in wvv[v].iter() {
            if uv[nv] {
                continue;
            }
            match w {
                0 => deque.push_front((nv, c + w)),
                1 => deque.push_back((nv, c + w)),
                _ => unreachable!(),
            }
        }
    }
    wvv.len()
}

fn main() {
    input! {
        k: usize
    };
    let wvv: Vec<Vec<(usize, usize)>> = (0..k)
        .map(|i| vec![((i + 1) % k, 1), ((i * 10) % k, 0)])
        .collect();
    println!("{}", shortest_path(&wvv, 1, 0) + 1);
}
*/

fn main() {
    let exe = "/tmp/binDE46EF41";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";