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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static int GetSum(int a,int b)
        {
            int m = 5,sum=0;
            for(int i = m; i >=0; i--)
            {
                sum += (a / (int)Math.Pow(10, i)) + (b / (int)Math.Pow(10, i));
                a -= (a / (int)Math.Pow(10, i))*(int)Math.Pow(10,i);
                b -= (b / (int)Math.Pow(10, i))*(int)Math.Pow(10,i);
            }
            return sum;
        }

        static void Main()
        {
            IO io = new IO();

            //ここから

            int n = io.ReadLineToInt();

            int a = n-2, b = 2, min = int.MaxValue,sum=0;

            for(int i = 0; i < n / 2 +1; i++)
            {
                sum = GetSum(a-i, b+i);
                if (min > sum)
                {
                    min = sum;
                }
            }

            //ここまで
            Console.Write(min);
            Console.ReadKey();
        }
    }

    //IOを担う関数群
    public class IO
    {
        //stringの入力
        public string ReadLineToString()
        {
            return Console.ReadLine();
        }

        //intの入力
        public int ReadLineToInt()
        {
            return int.Parse(Console.ReadLine());
        }

        //空白区切りの複数の文字列の入力をstring[]にして返す
        public string[] ReadLineToStringArray()
        {
            return Console.ReadLine().Split(' ').ToArray();
        }


        //空白区切りの複数の整数の入力をint[]にして返す
        public int[] ReadLineToIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        //空白区切りの複数の文字列の入力をList<string>で受け取る
        public List<string> ReadLineToStringList()
        {
            return Console.ReadLine().Split(' ').ToList();
        }

        //空白区切りの複数の整数の入力をList<int>で受け取る
        public List<int> ReadLineToIntList()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        }

    }

}