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



Sample input:
15


Sample output:
6

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = list()

for i in range(2, n):
    a = sum([int(j) for j in str(i)])
    b = sum([int(j) for j in str(n - i)])
    ans.append(a + b)

if len(ans) > 0:
    print(min(ans))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 100000

for A in range(1, N - 1):
    B = N - A
    a_sum = 0
    b_sum = 0
    for i in range(0, 5):
        a_sum += (A % (10 ** (i + 1))) // (10 ** i)
        b_sum += (B % (10 ** (i + 1))) // (10 ** i)
    ans = min(ans, a_sum + b_sum)

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    #0 input
    N = int(input())
    
    minimum = 100000    

    for a in range(2, N//2 + 1):
        #1 set A and b
        b = N-a

        #2 compute sum 
        digits_sum = 0
        
        while a != 0:
            digits_sum += a%10
            a = a//10
            
        while b != 0:
            digits_sum += b%10
            b = b//10
            
        #3 check min
        if digits_sum < minimum:
            minimum = digits_sum

    print(minimum)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = input()

ans = n

for i in (1, n):
	a = map(int, str(i))
	b = map(int, str(n-i))

	tmp = sum(a) + sum(b)
	if tmp < ans:
		ans = tmp

print ans

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = [0]

for i in range(2, n):
    a = sum([int(j) for j in str(i)])
    b = sum([int(j) for j in str(n - i)])
    ans.append(a + b)

print(min(ans))

Submission status: Wrong Answer

Solution code:
import sys


def sum_digits(n):
    return sum(int(a) for a in str(n))


def solve(n):
    min_sum = sys.maxsize

    for a in range(1, (n + 1) // 2):
        b = n - a
        sum_ = sum_digits(a) + sum_digits(b)

        if sum_ < min_sum:
            min_sum = sum_

    return min_sum


print(solve(int(input())))

Submission status: Wrong Answer

Solution code:
def wa(x):
  sum = 0
  fuga = str(x)
  a = len(fuga)
  hoge = list(fuga)
  for i in range(a):
    sum+=int(hoge[i])
  return sum



n = int(input())
min = 114514
for i in range(1,int(n/2)):
  po = wa(i) + wa(n - i)
  if(min > po):
    min = po

print(min)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())

min = 9999999
for a in range(2, N-1):
    b = N - a
    a_sum = sum([int(i) for i in str(a)])
    b_sum = sum([int(i) for i in str(b)])
    if a_sum + b_sum < min:
        a_min = a
        b_min = b
        min = a_sum + b_sum
print(min)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = str(n)
    if n % 10 ** (len(s) - 1) == 0:
        print(10)
    else:
        a = 0
        for i in s:
            a += int(i)
        print(a)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
from heapq import heapify, heappop, heappush
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))


##### Library ####


##### main #####
def main():
    N = I()
    mid_N = math.ceil(N / 2) 

    ans = 10**9
    for a in range(1,mid_N):
        b = N-a

        sum_digit_a = sum(map(int,list(str(a))))
        sum_digit_b = sum(map(int,list(str(b))))

        tmp = sum_digit_a + sum_digit_b
        ans = min(ans, tmp)

    print(ans)

   
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = eval(input())
n1 = str(n)

if(n%10==0):
	print(10)
else:
	sum_ = 0
	if(len(n1)==1):
		print(n)
	else:
		while(len(n1)!=1):
			sum_=0
			for i in n1:
				sum_ += (int)(i)
			n1 = (str)(sum_)
		print(sum_)

Submission status: Wrong Answer

Solution code:
n=int(input())
minimum =1000000000
for i in range(1,n//2):
    minimum = min(minimum,sum(list(map(int,list(str(i))))+list(map(int,list(str(n-i))))))
print(minimum)

Submission status: Wrong Answer

Solution code:
n = int(input())
digits = [int(i) for i in list(str(n))]

if n % (10 ** (len(str(n)) - 1)) != 0:
	print(sum(digits))
else:
	print(sum([int(i) for i in list(str(int(n / 2)))]) * 2)

Submission status: Wrong Answer

Solution code:
N=int(input())

Ans=N%10+(N%100)//10+(N%1000)//100+(N%10000)//1000+(N%100000)//10000

if Ans==0:
    Ans=10

print(Ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
nmin = 10000000
for n1 in range(n+1):
    n2 = n-n1
    nsum = sum(map(int, list(str(n1))))+sum(map(int, list(str(n2))))

    if nmin > nsum:
        nmin = nsum
print(nmin)

Submission status: Wrong Answer

Solution code:
n = eval(input())
n1 = str(n)

if(n%10==0):
	print(10)
else:
	sum_ = 0
	while(len(n1)!=1):
		sum_=0
		for i in n1:
			sum_ += (int)(i)
		n1 = (str)(sum_)
	print(sum_)

Submission status: Wrong Answer

Solution code:
N = input()
count = 0
while N:
  if N[:2] == '10':
    count += 10
    N = N[2:]
  else:
    count += int(N[0])
    N = N[1:]
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = 100000

for i in range(1, n - 1):
    a = n - i
    temp = sum(map(int, str(a))) + sum(map(int, str(i)))
    if temp < ans:
        ans = temp

print(ans)

Submission status: Wrong Answer

Solution code:
print(sum(map(int, list(input()))))

Submission status: Wrong Answer

Solution code:
n=input()
n2=list(map(int, n))
if sum(n2)==1 and sum(n2[1:])==0:print('5')
else: print(sum(n2))

Submission status: Wrong Answer

Solution code:
n=[int(i) for i in input().split()]
s=sum(n)
if s==1 and min(n)==0:
  print(10)
else:
  print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())

def digit_sum(X):
    s = 0
    while(X > 0):
        s += X % 10
        X = int(X / 10)
    return s

min_ = 10 ** 5
for A in range(N):
    B = N - A
    val = digit_sum(A) + digit_sum(B)
    min_ = min(min_, val)

print(min_)

Submission status: Wrong Answer

Solution code:
n=input()
print(sum([int(i) for i in n]))

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = N

for i in range(N):
    A = str(i)
    B = str(N-i)
    AB_sum = 0
    for j in A:
        AB_sum += int(j)
    for j in B:
        AB_sum += int(j)
    if AB_sum < ans:
        ans = AB_sum

print(ans)

Submission status: Wrong Answer

Solution code:
N = list(map(int, list(input())))
s = sum(N)

if s is 1:
    print(10)
else:
    print(sum)

Submission status: Wrong Answer

Solution code:
# cook your dish here
def sum_dig(n):
    sum = 0 
    n=str(n)
    for ele in n:
        sum+=int(ele)
    return sum

ans = 328932998329823983298

n = int(input())

for i in range(n):
    ans = min(sum_dig(i)+sum_dig(n-i),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans = 100000000
for i in range(2,n-1):
    ankari = 0
    for j in range (1,6):
        ankari += (i%pow(10,j))//pow(10,j-1)+((n-i)%pow(10,j))//pow(10,j-1)
    ans = min(ans,ankari)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

minsum = 900000
for i in range(n):
    count = 0
    a = i
    b = n - i
    for c in str(a):
        count += int(c)
    for c in str(b):
        count += int(c)
    if count < minsum:
        minsum = count
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 10e10
for A in range(1, (N+1)//2):
    B = N - A
    S = sum(list(map(int, str(A)))) + sum(list(map(int, str(B))))
    ans = min(ans, S)

print(ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

n = int(input())

res = 1000000

for a in range(1, n-1):
    b = n - a

    s = 0

    al = list(str(a))
    for c in al:
        s += int(c)

    bl = list(str(b))
    for c in bl:
        s += int(c)

    if s < res:
        res = s

print(res)

Submission status: Wrong Answer

Solution code:
n=input()
n2=sum(list(map(int, n)))
if n2==1:print('5')
else: print(n2)

Submission status: Wrong Answer

Solution code:
N = int(input())
res = int(1e18)

for i in range(1, (N+1)//2):
    A = map(int, list(str(i)))
    B = map(int, list(str(N-i)))
    res = min(res, sum(A)+sum(B))

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = n%10 + n//10 if n%10 != 0 else 10

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 1234567890
def c(x):
    ers = 0
    for i in str(x):
        ers += ord(i) - ord('0')
    return ers
for a in range(1, n):
    ans = min(ans, c(a) + c(n - a))

Submission status: Wrong Answer

Solution code:
print(sum(map(int,input().split())))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def digit_sum(num):
  digit_sum = 0
  while(num > 0):
    digit_sum += num % 10
    num = int(num / 10)
  return digit_sum

min_num = 100000
for A in range(1, N):
  for B in range(1, N):
    if A + B != N:
      continue
    digit_num = digit_sum(A)
    digit_num += digit_sum(B)
    if digit_num < min_num:
      min_num = digit_num

print(min_num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
results = []
for i in range(1,N):
    for j in range(1,N):
        if i+j == N:
            si = str(i)
            sj = str(j)
            count1 = 0
            for x in si:
                count1 += int(x)
            for y in sj:
                count1 += int(y)
            results.append(count1)
print(min(results))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
results = []
for i in range(1,N+1):
    for j in range(1,N+1):
        if i+j == N:
            si = str(i)
            sj = str(j)
            count1 = 0
            for x in si:
                count1 += int(x)
            for y in sj:
                count1 += int(y)
            results.append(count1)
print(min(results))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_l = []
b_l = []
l =[]
for a in range(1,n+1):
    b = n - a
    while a >= 1:
        a_l.append(a%10)
        a = a//10
    while b >= 1:
        b_l.append(b%10)
        b = b//10
    l.append(sum(a_l)+sum(b_l))
print(min(l))

Submission status: Time Limit Exceeded

Solution code:
def sumDigits(i):
    s = 0
    while i > 0:
        s += (i % 10)
        i = int(i / 10)
    return s

N = int(input())

m = 9 * 6
for i in range(1, N + 1):
    for k in range(1, N - i + 1):
        if N == i + k:
            m = min(m, sumDigits(i) + sumDigits(k))

print(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans = N+1
for i in range(1,N):
    stra = str(i)
    strb = str(N-i)
    a = ''
    b = ''
    for j in range(len(stra)):
        a += stra[j]+'+'
    a = a[:-1]
    for j in range(len(strb)):
        b += strb[j]+'+'
    b = b[:-1]
    ans = min(ans,eval(a)+eval(b))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#各桁の和を求める
def findSumOfDigits(n):
  sum = 0
  while n > 0:
    sum += int(n % 10)
    n = int(n / 10)
  return sum

N = int(input())

total = 0
for A in range(1,N + 1):
  for B in range(1,N + 1):
    if A + B == N:
      rec_A = findSumOfDigits(A)
      rec_B = findSumOfDigits(B)
      rec = rec_A + rec_B
      if total == 0:
        total = rec
      elif total >= rec:
        total = rec
        
print(total)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
min = 99999999999999
if a % 10 == 0:
    print(10)
else:
    for i in range(1, a):
        c = 0
        for j in range(i, a):
            if i + j == a:
                x = i
                y = j
                while (x > 0):
                    c += x % 10
                    x = x // 10
                while (y > 0):
                    c += y % 10
                    y = y // 10
                if min > c:
                    min = c
    print(min)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

box =[]

for x in range(1,n):
    for y in range(1,n):
        if x + y == n:
            xsum = sum(list(map(int, str(x))))
            ysum = sum(list(map(int, str(y))))
            box.append(xsum + ysum)
            
print(min(box))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def sum_10(n):
  return sum([int(l) for l in str(n)])

li=[]
for i in range(1,N//2 +1):
  for k in range(N-N//2,N+1):
    if i + k == N:
      li.append(sum_10(i)+sum_10(k))
print(min(li))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
emp = list()
count = 0

for a in range(n)[1:]:
    for b in range(n)[1:]:
        if a + b == n:
            for i in str(a)+str(b):
                count += int(i)
            emp.append(count)

print(min(emp))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

min_=100000

for i in range(1, N):
    for j in range(1, N):
        sum_i=0
        sum_j=0
        if i + j == N:
            tmp_i=i
            tmp_j=j
            while tmp_i > 0:
                sum_i += tmp_i % 10
                tmp_i = tmp_i // 10
            while tmp_j > 0:
                sum_j += tmp_j % 10
                tmp_j = tmp_j // 10
            min_=min(min_, sum_i+sum_j)



print(min_)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 10000000
for i in range(1, n+1):
    for j in range(1, n+1):
        if i + j == n:
            a = (sum(map(int, str(i)))+sum(map(int, str(j))))
            if ans>a:
                ans = a
        else:
            continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())

if n < 11:
    print(n)

else:
    if n % 10 == 0:
        print("10")

    else:
        lst = []
        while True:
            while n > 0:
                lst.append(n%10)
                n //= 10 # 必須
            n = sum(lst)
            if n < 11:
                break

        print(n)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
minmum = 10**5
def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

for i in range(1, N):
    for j in range(1, N):
        if i + j == N:
            min_sum = digitSum(i) + digitSum(j)
            if min_sum < minmum:
                minmum = min_sum

print(minmum)

Submission status: Accepted

Solution code:
n=int(input())
ans=float("inf")
for i in range(1,n):
    j=n-i
    tmp=0
    I=str(i)
    J=str(j)
    for ii in range(len(I)):
        tmp+=int(I[ii])
    for jj in range(len(J)):
        tmp+=int(J[jj])
    if tmp<ans:
        ans=tmp
print(ans)

Submission status: Accepted

Solution code:
def dig(x):
	return sum([int(i) for i in str(x)])

n = int(input())
ans = 1e20
for a in range(1, n):
	b = n - a
	ans = min(ans, dig(a)+dig(b))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

a = list(str(N))
a = [int(s) for s in a]


Z = 10 ** (len(a) - 1)

Y = N - Z

X = list(str(Y))
X = [int(s) for s in X]
SUM = 0
for i in range(len(X)):
    SUM = SUM + X[i]

if Y != 0:
    print(SUM + 1)
else:
    print(10)

Submission status: Accepted

Solution code:
N=int(input())
N_sum=[]
for A in range(1,int(N/2)+1):
  B=N-A
  N_sum.append(sum(map(int,str(A)+str(B))))
print(min(N_sum))

Submission status: Accepted

Solution code:
n = int(input())
l1 = []
l2 = []
b = 0
ans = float('inf')

def keta(x):
    l = []
    while(x > 0):
        l.append(x%10)
        x //= 10
    return l

for a in range(1, n):
    b = n - a
    l1 = keta(a)
    l2 = keta(b)
    ans = min(ans, sum(l1, sum(l2)))

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 100
i = 1
while i * 2 <= N:
  ans = min(ans, sum(map(int, list(str(i)))) + sum(map(int, list(str(N-i)))))
  i += 1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())

M=10**9
for i in range(1,N//2+1):
    a=list(str(i))
    b=list(str(N-i))
    #print(a,b)
    k=0
    for q in range(len(a)):
        k+=int(a[q])
    for p in range(len(b)):
        k+=int(b[p])
    M=min(M,k)
print(M)

Submission status: Accepted

Solution code:
n = input()
a = sum([int(n[i]) for i in range(len(n))])
if a==1:
    print(10)
else:
    print(a)

Submission status: Accepted

Solution code:
N=int(input())
N_sum=[]
for A in range(1,int(N/2)+1):
  B=N-A
  N_sum.append(sum(map(int,str(A)+str(B))))
print(min(N_sum))

Submission status: Accepted

Solution code:
N = int(input())

if (N%10 == 0):
    print(10)
    exit()
a = []
while N > 0:
    a.append(N%10)
    N //= 10

print(sum(a))

Submission status: Accepted

Solution code:
N = int(input())
if N % 10 == 0:
    ans = 10
else:
    ans = 0
    while N > 0:
        ans += N % 10
        N //= 10
print(ans)

Submission status: Accepted

Solution code:
n = str(input())

ans = 0
for i in range(len(n)):
  ans += int(n[i])
  
if ans == 1:
  print(10)
else:
  print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n = I()
i = 1
def keta(v):
    a = 0
    while v:
        a += v%10
        v //= 10
    return a
ans = INF
while 2*i <= n:
    ans = min(ans, keta(i) + keta(n-i))
    i += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

count = 10000000

for i in range (1, N//2+2):
	A = str(i)
	B = str(N-i)
	temp = 0
	for j in range (0, len(A)):
		temp+=int(A[j])
	for j in range (0, len(B)):
		temp+=int(B[j])
	count = min(count, temp)

print(count)

Submission status: Accepted

Solution code:
s = sum(map(int, list(input())))
print(10 if s == 1 else s)

Submission status: Accepted

Solution code:
n = int(input())
ans = 1001001001
for i in range(1,n):
    j = n-i
    i_sum, j_sum = 0, 0

    si, sj = list(str(i)), list(str(j))
    for s1 in si:
        i_sum += int(s1)
    for s2 in sj:
        j_sum += int(s2)

    ans = min(ans, i_sum+j_sum)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 10**9+7
for i in range(1,N):
  A = i
  B = N-i
  ans = min(ans, sum(list(map(int,str(A))))+sum(list(map(int,str(B)))))
print(ans)

Submission status: Accepted

Solution code:
def digit_sum(x):
    res = 0
    while x > 0:
        res += x % 10
        x //= 10
    return res


N = int(input())
ans = N
for i in range(1, N):
    A = i
    B = N - i
    ans = min(ans, digit_sum(A) + digit_sum(B))
print(ans)

Submission status: Accepted

Solution code:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

mod = 10**9 + 7

n = I()

m = INF
for i in range(n//2):
    a = i + 1
    b = n - a
    a = str(a)
    b = str(b)
    a = list(a)
    b = list(b)
    a = sum(list(map(int,a)))
    b = sum(list(map(int,b)))
    m = min(m,a+b)
print(m)

Submission status: Accepted

Solution code:
n = int(input())
ans = 10**5+1
for a in range(1, n//2+1):
    a,b = list(str(a)), list(str(n-a))
    ans = min(ans, sum(list(map(int, a)))+sum(list(map(int,b))))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
cmin = N
for i in range(1,N):
    j = N-i
    a = str(i)
    b = str(j)
    cnt = 0
    for k in range(len(a)):
        cnt += int(a[k])
    for k in range(len(b)):
        cnt += int(b[k])
    cmin = min(cmin,cnt)
print(cmin)

Submission status: Accepted

Solution code:
N = int(input())

min_sum = 100000

for A in range(1, N):
    Sum = 0
    sum_A = 0
    sum_B = 0
    B = N - A
    str_A = str(A)
    str_B = str(B)
    for i in str_A:
        sum_A += int(i)
    for j in str_B:
        sum_B += int(j)
    Sum = sum_A + sum_B
    if Sum < min_sum:
        min_sum = Sum
    
print("{}".format(min_sum))

Submission status: Accepted

Solution code:
n = int(input())
ans = float("inf")
for a in range(1, n):
    b = n-a
    ans = min(sum([int(i) for i in list(str(a)+str(b))]), ans)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
min_sum=1000000

for a in range(1,n):
  l_a=str(a)
  l_b=str(n-a)
  
  sum_a=0
  sum_b=0
  for e_a in l_a:
    sum_a+=int(e_a)
  for e_b in l_b:
    sum_b+=int(e_b)
  sum_ab = sum_a+sum_b
  
  if sum_ab<min_sum:
    min_sum=sum_ab
    
print(min_sum)

Submission status: Accepted

Solution code:
n=int(input())
ans=10e5
for a in range(1,n//2+1):
    b=n-a
    ans=min(ans,sum(map(int,str(a)))+sum(map(int,str(b))))
print(int(ans))

Submission status: Accepted

Solution code:
n=int(input())
ans=10e5
for a in range(1,n//2+1):
    b=n-a
    ans=min(ans,sum([int(i) for i in str(a)])+sum([int(i) for i in str(b)]))
print(int(ans))

Submission status: Accepted

Solution code:
n=int(input())
ans=10e5
for a in range(1,n//2+1):
    b=n-a
    ans=min(ans,sum([int(i) for i in str(a)])+sum([int(i) for i in str(b)]))
    ans=min(ans,sum([int(i) for i in str(a)])+sum([int(i) for i in str(b)]))
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
l = [0] * (n // 2)
for i in range(1, n // 2 + 1):
    sum1 = sum([int(d) for d in str(i)])
    sum2 = sum([int(d) for d in str(n - i)])
    l[i - 1] = sum1 + sum2
print(min(l))

Submission status: Accepted

Solution code:
def func(i):
  ret_val=0
  while 0<i:
    ret_val+=i%10
    i//=10
  return ret_val

N=int(input())
ans=10**9
for i in range(1,N):
  j=N-i
  ans=min(ans,func(i)+func(j))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

minno = 10 ** 5
for i in range(1, N):
    str_list_a = list(str(i))
    int_list_a = [int(x) for x in str_list_a]
    str_list_b = list(str(N - i))
    int_list_b = [int(y) for y in str_list_b]

    sum_a_b = sum(int_list_a) + sum(int_list_b)
    if sum_a_b < minno:
        minno = sum_a_b
print(minno)

Submission status: Accepted

Solution code:
N=int(input())
ans=float("inf")
for i in range(1,N):
   a,b=map(int,list(str(i))),map(int,list(str(N-i)))
   ans=min(ans,sum(a)+sum(b))
print(ans)

Submission status: Accepted

Solution code:
n=input()
ai=0
if int(n) % 10 != 0:
    for i in range(len(n)):
        ai += int(n[i])
else:
    ai = 10
print(ai)

Submission status: Accepted

Solution code:
n = input(); a = 0
for i in range(len(n)): a += int(n[i])
print(10) if a == 1 else print(a)

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline().rstrip("\n"))
INF = float('inf')
ans = INF
for a in range(1,(n+2)//2):
    b = n-a
    s = 0
    while a != 0:
        a,p = divmod(a, 10)
        s += p
    while b != 0:
        b,p = divmod(b, 10)
        s += p
    ans = min(ans,s)
print(ans)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
a = [int(x) for x in s]
 
if int(s) == 10 ** (l - 1):
  print(10)
else:
  print(sum(a))

Submission status: Accepted

Solution code:
'''
Created on 2020/09/03

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  A=1
  B=N-A
  m=10**9
  for i in range(N-1):
    f=0
    for j in str(A):
      f+=int(j)
    for k in str(B):
      f+=int(k)
    m=min(m,f)
    A+=1
    B-=1
  print(m)
  return 
main()

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(1,n):
  s=str(i)+str(n-i)
  c=0
  for j in s:
    c+=int(j)
  a.append(c)
    
print(min(a))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def get_digits_sum(val_str):
    digits_sum = 0
    for i in range(len(val_str)):
        digits_sum += int(val_str[i])

    return digits_sum

N = int(input())

if N==2:
    sum_min = 2

for i in range(2, N, 1):
    A = i
    B = N - i
    a_sum = get_digits_sum(str(A))
    b_sum = get_digits_sum(str(B))
    if i==2:
        sum_min = a_sum + b_sum
    elif sum_min > a_sum + b_sum:
        sum_min = a_sum + b_sum
        
print(sum_min)

Submission status: Accepted

Solution code:
N = int(input())
ans = 10**14
for i in range(1, N//2+1):
    a = sum(map(int, str(i)))
    b = sum(map(int, str(N-i)))
    ans = min(a+b, ans)
print(ans)

Submission status: Accepted

Solution code:
# vim: fileencoding=utf-8


def main():
    n = int(input())
    ans = float("inf")
    for i in range(2, n // 2 + 2):
        a = i
        b = n - a
        na = sum(map(int, list(str(a))))
        nb = sum(map(int, list(str(b))))
        if ans > na + nb:
            ans = na + nb
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def ds(x):
  ret = 0
  while x > 0:
    ret += x % 10
    x //= 10
  return ret

n = int(input())
ans = n
for i in range(1, n):
  ans = min(ans, ds(i) + ds(n-i))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = float("inf")

for i in range(1, N):
    A = i
    B = N - i
    A_sum = 0
    B_sum = 0
    while True:
        if A // 10 > 0:
            A_sum += A % 10
            A  //= 10
        else:
            A_sum += A % 10
            break
    while True:
        if B // 10 > 0:
            B_sum += B % 10
            B  //= 10
        else:
            B_sum += B % 10
            break
    if ans > (A_sum + B_sum):
        ans = A_sum + B_sum
print(ans)

Submission status: Accepted

Solution code:
def SumReturn(num):
    total=0
    while num!=0:
        total += num%10
        num //= 10
        
    return total

if __name__ == '__main__':
    
    n = int(input())
    min = 10000
    
    for i in range(1,n):
        if(min > SumReturn(i)+SumReturn(n-i)):
            min = SumReturn(i)+SumReturn(n-i)
        
        
    print(min)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
a = [int(x) for x in s]

if int(s) == 10 ** (l - 1):
  print(10)
else:
  print(sum(a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def main():
    N = int(input())
    print(
        min(
            [
                sum(list(map(int, str(i)))) + sum(list(map(int, str(N - i))))
                for i in range(1, N)
            ]
        )
    )


main()

Submission status: Accepted

Solution code:
N = int(input())

def digit_sum(num):
  digit_sum = 0
  while(num > 0):
    digit_sum += num % 10
    num = int(num / 10)
  return digit_sum

min_num = 100000
for A in range(1, N):
  B = N - A
  digit_num = digit_sum(A)
  digit_num += digit_sum(B)
  if digit_num < min_num:
    min_num = digit_num

print(min_num)

Submission status: Accepted

Solution code:
N=int(input())

ans=[]

for i in range(1,N):
    B=N-i
    ans.append(sum(map(int,str(i)))+sum(map(int,str(B))))

print(min(ans))

Submission status: Accepted

Solution code:
n = int(input())

ans=10**9+7
for i in range(1,n):
    tmp=list(str(i)) + list(str(n-i))
    tmp=[int(i) for i in tmp]
    ans=min(ans, sum(tmp))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
li = []
for i in range(1,n//2+1):
    a = sum(list(map(int, str(i))))
    b = sum(list(map(int, str(n-i))))
    li.append(a+b)
print(min(li))

Submission status: Accepted

Solution code:
n = int(input())

def sss(s):
    return sum(map(int, list(str(s))))

ans = 10**7
for a in range(1, n):
    b = n-a
    ans = min(ans, sss(a)+sss(b))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
absum = []
for a in range(1,n//2+1):
    b = n-a
    asum = 0
    bsum = 0
    astr = str(a)
    bstr = str(b)
    for j in range(len(astr)):
        asum = asum + int(astr[j])
    for k in range(len(bstr)):
        bsum = bsum + int(bstr[k])
    absum.append(asum+bsum)
print(min(absum))

Submission status: Accepted

Solution code:
n = int(input())
absum = []
for a in range(1,n):
    b = n-a
    asum = 0
    bsum = 0
    astr = str(a)
    bstr = str(b)
    for j in range(len(astr)):
        asum = asum + int(astr[j])
    for k in range(len(bstr)):
        bsum = bsum + int(bstr[k])
    absum.append(asum+bsum)
print(min(absum))