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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.util.*;
import java.math.*;
class Main {
    public static void main(String[] args) {
        int A, B;
        int N;
        int[] sum;
        int maxVal;
        //N = A + B
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        sum = new int[N - 1];
        for (A = 1; A <= N - 1; A++) {
            B = N - A;
            sum[A - 1] = sumOfEachDigit(A) + sumOfEachDigit(B);
        }
        maxVal = sum[0];
        for (A = 1; A <= N - 1; A++) {
            if (maxVal < sum[A - 1]) maxVal = sum[A - 1];
        }
        System.out.println(maxVal);
    }
    public static int sumOfEachDigit (int n){
        if (n / 10000 != 0) {
            int n5, n4, n3, n2, n1;
            n5 = n / 10000;
            n4 = (n - n5 * 10000) / 1000;
            n3 = (n - n5 * 10000 - n4 * 1000) / 100;
            n2 = (n - n5 * 10000 - n4 * 1000 - n3 * 100) / 10;
            n1 = n - n5 * 10000 - n4 * 1000 - n3 * 100 - n2 * 10;
            return n5 + n4 + n3 + n2 + n1;
        } else if (n / 1000 != 0) {
            int n4, n3, n2, n1;
            n4 = n / 1000;
            n3 = (n - n4 * 1000) / 100;
            n2 = (n - n4 * 1000 - n3 * 100) / 10;
            n1 = n - n4 * 1000 - n3 * 100 - n2 * 10;
            return n4 + n3 + n2 + n1;
        } else if (n / 100 != 0) {
            int n3, n2, n1;
            n3 = n / 100;
            n2 = (n - n3 * 100) / 10;
            n1 = n - n3 * 100 - n2 * 10;
            return n3 + n2 + n1;
        } else if (n / 10 != 0) {
            int n2, n1;
            n2 = n / 10;
            n1 = n - n2 * 10;
            return n2 + n1;
        } else {
            return n;
        }
    }
}