Problem:
Score : 200 points

Problem Statement

Takahashi has two positive integers A and B.

It is known that A plus B equals N.
Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).

Constraints

2 ≤ N ≤ 10^5

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B".

Sample Input 1

15

Sample Output 1

6

When A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the value in question.

Sample Input 2

100000

Sample Output 2

10

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

use std::cmp;

fn main(){
  let n: u32 = read();

  let mut mv: u32 = dsum(1) + dsum(n-1);
  
  for i in 2 .. n / 2 + 1 {
    mv = cmp::min(mv, dsum(i) + dsum(n-i));
  }
  
  println!("{}", mv);
}

fn dsum(x: u32) -> u32 {
  let mut q :u32 = x / 10;
  let mut r :u32 = x % 10;
  let mut ans :u32 = r;

  while q > 0 {
    r = q % 10;
    ans += r;
    q /= 10;
  }
  ans
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}