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: Runtime Error)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;


    bool[,] check;

    int H, W;
    bool inside(int y, int x)
    {
        return y >= 0 && x >= 0 && y < H && x < W;
    } 

    void calc()
    {
        
        /*
        Dictionary<int, int> dic = new Dictionary<int, int>();
        for (int i = 0; i < 300; i+=1)
        {
            for (int j = 0; j < 300; j+=1)
            {
                int ans = i * i + j * j;
                if (!dic.ContainsKey(ans)) dic[ans] = 0;
                dic[ans]++;
            }
        }

        foreach (var item in dic)
        {
            if (item.Value <= 6) continue;
            Console.WriteLine(item.Key + " " + item.Value);
        }
        */
        

        cin = new Scanner();
        int N = cin.nextInt();
        int D1 = cin.nextInt();
        int D2 = cin.nextInt();

        H = W = N * 2;

        check = new bool[H, W];
        int D1Type = -1;
        int D2Type = -1;

        List<Tuple<int, int>> l = new List<Tuple<int, int>>();

        for (int i = 0; i < 2 * N; i++)
        {
            for (int j = 0; j < 2 * N; j++)
            {
                if (i * i + j * j == D1)
                {
                    l.Add(Tuple.Create(i, j));
                    if (i % 2 + j % 2 == 1)
                    {
                        D1Type = 1;
                    }
                    else if (i % 2 + j % 2 == 2)
                    {
                        D1Type = 2;
                    }
                    else if ((i % 4 == 2) != (j % 4 == 2))
                    {
                        D1Type = 3;
                    }
                    else D1Type = 4;
                }
            }
        }

        for (int i = 0; i < 2 * N; i++)
        {
            for (int j = 0; j < 2 * N; j++)
            {
                if (i * i + j * j == D2)
                {
                    l.Add(Tuple.Create(i, j));
                    if (i % 2 + j % 2 == 1)
                    {
                        D2Type = 1;
                    }
                    else if (i % 2 + j % 2 == 2)
                    {
                        D2Type = 2;
                    }
                    else if ((i % 4 == 2) != (j % 4 == 2))
                    {
                        D2Type = 3;
                    }
                    else D2Type = 4;
                }
            }
        }


        List<int> x = new List<int>();
        List<int> y = new List<int>();
        for (int i = 0; i < 2 * N; i++)
        {
            for (int j = 0; j < 2 * N; j++)
            {
                if ((D1Type == 1 || D2Type == 1) && ((i % 2) != (j % 2))) continue;
                if ((D1Type == 2 || D2Type == 2) && ((i % 2) != 0)) continue;
                if ((D1Type == 3 || D2Type == 3) && ((i / 2 % 2) != (j / 2 % 2))) continue;
                if ((D1Type == 4 || D2Type == 4) && ((i / 4 % 2) != (j / 4 % 2))) continue;

                /*
                bool ok = true;
                foreach (var item in l)
                {
                    for (int mx = -1; mx <= 1; mx += 2)
                    {
                        int ny = i - item.Item1;
                        int nx = j + mx * item.Item2;
                        if (inside(ny, nx) && check[ny, nx])
                        {
                            ok = false;
                            break;
                        }
                    }
                    if (!ok) break;
                }
                if (ok)
                {
                    x.Add(i); y.Add(j); check[i, j] = true;
                }
                */
                x.Add(i);
                y.Add(j);
            }
        }


        //Console.WriteLine((N * N) + " " + x.Count);
        for (int i = 0; i < N * N; i++)
        {
            Console.WriteLine(x[i] + " " + y[i]);
        }


        /*
        int ystep = -1;
        int xstep = -1;
        for (int x = 1; x <= N; x++)
        {
            for (int y = 1; y <= 2; y++)
            {
                bool ok = true;

                foreach (var t in l)
                {
                    int Y = t.Item1;
                    int X = t.Item2;
                    
                    if (Y >= y * N) continue;
                    if (Y % y != 0) continue;

                    if (Y % (x * y) == 0 && ((Y / (x * y)) % 2 != X % 2)) continue;

                    ok = false;
                    break;
                }

                if (ok)
                {
                    xstep = x;
                    ystep = y;
                    break;
                }
            }
            if (ystep != -1) break;
        }

        if(xstep == -1)
        {
            throw new Exception("!?");
        }

        for (int i = 0; i < N; i++)
        {
            int y = i * ystep;
            for (int j = 0; j < N; j++)
            {
                int x = j * 2;
                if ((j / xstep) % 2 == 1) x += 1;
                Console.WriteLine(x + " " + y);
            }
        }
        */
    }

}






class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}