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

#include <stdio.h>
int main(void){
  int n, A, B, a[6], b[6], suma = 0, sumb = 0, sum = 0, min = 1000000;
  
    scanf("%d", &n);
    
  for(int i = 0; i <= n/2; i++){
    A = i;
    B = n - i;
    
   a[5] = A % 10;//1ケタ目
   a[4] = (A % 100) / 10;//2ケタ目
   a[3] = (A % 1000) / 100;//3ケタ目
   a[2] = (A % 10000) / 1000;//4ケタ目
   a[1] = (A % 100000) / 10000;//5ケタ目
   a[0] = (A % 1000000) / 100000;//6ケタ目
    
   b[5] = A % 10;//1ケタ目
   b[4] = (A % 100) / 10;//2ケタ目
   b[3] = (A % 1000) / 100;//3ケタ目
   b[2] = (A % 10000) / 1000;//4ケタ目
   b[1] = (A % 100000) / 10000;//5ケタ目
   b[0] = (A % 1000000) / 100000;//6ケタ目 

   
    for(int j = 0; j < 6; j++){
    suma += a[j];
    sumb += b[j];
    }
    sum += suma + sumb;
    
    if(sum < min || sum != 0){   
      min = sum;
    }
  }
    printf("%d\n", min);   

    return 0;
}