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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	int sum[100000] = {};
	for (int i = 2; i < n / 2; i++) {
		sum[i] += i % 10 + i % 100 / 10 + i % 1000 / 100 + i % 10000 / 1000 + i % 100000 / 10000 + i / 100000;
		int j = n-i;
		sum[i] += j % 10 + j % 100 /10 + j % 1000 / 100 + j % 10000 / 1000 + j % 100000 / 10000 + j /100000;
	}
	int ans=1000;
	for (int i = 2; i < n / 2; i++) {
		if (ans > sum[i])ans = sum[i];
	}
	cout << ans << endl;
}