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 "stdlib.h"

int digit(int A,int B);

int main(void)
{
  int N;
  scanf("%d",&N);
  int A,B,tmp;
  int min = 114514810;

  for(int i = 1;i <= N;i++)
    {
      A = i;
      B = N - i;
      tmp = digit(A,B);
      if(min > tmp)
	min = tmp;
    }
  printf("%d\n",min);
}

int digit(int A,int B)
{
  int Adigitsum,Bdigitsum;
  Adigitsum = 0;
  Bdigitsum = 0;
  Adigitsum += A / 10000 != 0 ? A / 10000 : 0;
  Bdigitsum += B / 10000 != 0 ? B / 10000 : 0;
  A = A % 10000;
  B = B % 10000;
  Adigitsum += A / 1000 != 0 ? A / 1000 : 0;
  Bdigitsum += B / 1000 != 0 ? B / 1000 : 0;
  A = A % 1000;
  B = B % 1000;
  Adigitsum += A / 100 != 0 ? A / 100 : 0;
  Bdigitsum += B / 100 != 0 ? B / 100 : 0;
  A = A % 100;
  B = B % 100;
  Adigitsum += A / 10 != 0 ? A / 10 : 0;
  Bdigitsum += B / 10 != 0 ? B / 10 : 0;
  A = A % 10;
  B = B % 10;
  Adigitsum += A / 1 != 0 ? A / 1 : 0;
  Bdigitsum += B / 1 != 0 ? B / 1 : 0;
  return Adigitsum + Bdigitsum;
}