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: Accepted

Solution code:
def main():
    n = int(input())
    print(solve(n))

def digit_sum(n):
    s = 0
    while n != 0:
        s += n % 10
        n //= 10
    return s

def digit_sums_up(n):
    s = digit_sum(n)
    yield s

    while True:
        n += 1
        s += 1
        x = 10
        while n % x == 0:
            s -= 9
            x *= 10
        yield s

def digit_sums_down(n):
    s = digit_sum(n)
    yield s

    while True:
        x = 10
        while n % x == 0:
            s += 9
            x *= 10
        s -= 1
        n -= 1
        yield s

def solve(n):
    m = float('inf')
    for i, a, b in zip(range(n - 1), digit_sums_up(1), digit_sums_down(n - 1)):
        m = min(m, a + b)
    return m


main()

Submission status: Accepted

Solution code:
n=int(input())
nl=[]
for i in range(5):
    nl.append(int((n/10**(4-i))%10))

if sum(nl)>1:
    print(sum(nl))
else:
    print(10)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n = int(input())

    ans = 999999
    for a in range(1, -(-n // 2)+1):
        t = digits(a) + digits(n-a)
        if(t < ans):
            ans = t

    print(ans)


def digits(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N = int(raw_input())
ans = 1000000
for A in range(1, 1+N/2):
  B = N - A
  a = 0
  b = 0
  tA = A
  tB = B
  for i in range(6)[::-1]:
    ta = tA/10**i
    tb = tB/10**i
    a += ta
    b += tb
    tA -= ta*(10**i)
    tB -= tb*(10**i)
  ans = min(ans, a+b)
print ans

Submission status: Accepted

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

if(n%10==0):
	print(10)
else:
	mini = 0
	sum1 = 0
	sum2 = 0
	for i in range(1,n):
		a = i
		b = n-i
		a1 = str(a)
		b1 = str(b)
		for j in a1:
			sum1+=(int)(j)
		for k in b1:
			sum2+=(int)(k)

		if(i==1):
			mini = sum1+sum2
		else:
			if((sum1+sum2)<mini):
				mini = sum1+sum2
	print(mini)

Submission status: Accepted

Solution code:
N = input()
n = [int(i) for i in N] 
if n[0] == 1 and n[1:] == [0 for _ in range(len(n)-1)]:
  print(10)
  exit()
cnt = 0
for i in n:
  cnt += i
print(cnt)

Submission status: Accepted

Solution code:
a = int(input())

def func(a):
    result = 0
    
    while a != 0:
        result += a%10
        a = int(a/10)
        
    if result == 1:
        print('10')
    else:
        print(result)

func(a)

Submission status: Accepted

Solution code:
def sum_digit(n) :
    max_sum = 999999
    for n1 in range(1, n) :
        n2 = n - n1

        l_n1 = []
        l_n2 = []
        l_n1 = list(map(int, list(str(n1))))
        l_n2 = list(map(int, list(str(n2))))
        l_n1.append(0)
        l_n2.append(0)
       
        res = sum(l_n1) + sum(l_n2)
        if res < max_sum :
            max_sum = res
            tmp_n1 = l_n1
            tmp_n2 = l_n2
            
    return max_sum

n = int(input())
print(sum_digit(n))

Submission status: Accepted

Solution code:
import math                                                                     

N = int(input())
a_dsum = 0 
b_dsum = 0 
ans = 100000

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)


for a in range(N + 1): 
    b = N - a 
    if sum(map(int, str(a))) > 1:
        a_dsum = digitSum(a)
    else:
        a_dsum = a
    if sum(map(int, str(b))) > 1:
        b_dsum = digitSum(b)
    else:
        b_dsum = b 
    tmp_sum = a_dsum + b_dsum
    if tmp_sum < ans:
        ans = tmp_sum

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
dp = [0 for i in range(n)]
min = float("inf")
for i in range(1, n//2):
    a_sum = sum(map(int, list(str(i))))
    b_sum = sum(map(int, list(str(n - i))))
    c = a_sum + b_sum
    if(min > c):
        min = c
if min == float("inf"):
    min = n
print(min)

Submission status: Accepted

Solution code:
N=int(input())
ans=0
if N==10 or N==100 or N==1000 or N==10000 or N==100000:
    ans=10
else:    
    while  True:
        ans+=N%10
        N=N//10
        if N==0:
            break


    
        
            
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0

for i in str(n):
  ans += int(i)

if ans == 1:
  print(10)
else:
  print(ans)

Submission status: Accepted

Solution code:
N = int(input())

min_val = 1000000000
for i in range(1, int(N / 2)+1):
    A = i
    B = N - i
    val = sum(map(int, str(A))) + sum(map(int, str(B)))
    if val < min_val:
        min_val = val
print(min_val)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
 
 
def getSum(n):
 
    sum = 0
 
    
    while(n > 0):
        sum += int(n%10)
        n = int(n/10)
 
    return sum
if getSum(n)==1:
    print(10)
else:
    print(getSum(n))

Submission status: Accepted

Solution code:
N = int(input())

min_num = []
for n in range(1,int(N/2)+1):
	A = str(n)
	B = str(N-n)

	A_list = list(map(int,A))
	B_list = list(map(int,B))


	min_num.append(sum(A_list)+sum(B_list))

min_num.sort()
print(min_num[0])

Submission status: Accepted

Solution code:
n = int(input())

ans = list()

for i in range(2, n // 2):
    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(2)

Submission status: Accepted

Solution code:
N = input()

ans = sum(map(int, N))
if ans != 1:
    print(ans)
else:
    print(10)

Submission status: Accepted

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

min = 99999999
for a in range(1, N):
    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: Accepted

Solution code:
n = input()

ans = n

for i in range(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: Accepted

Solution code:
def digits_sum(n):
    st = str(n)
    ans = 0
    for s in st:
        ans += int(s)

    return ans

N = int(input())

if N % 10 == 0:
    a = N//2
else:
    a = N % 10

b = N - a

print(digits_sum(a) + digits_sum(b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

ans = 100000

for A in range(1, N):
    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: Accepted

Solution code:
N = int(input())
min_cnt = 1000000
for A in range(1, N):
    cnt = 0
    B = N - A
    for i in str(A):
        cnt += int(i)
    for i in str(B):
        cnt += int(i)
    if min_cnt > cnt:
        min_cnt = cnt
print(min_cnt)

Submission status: Accepted

Solution code:
N = int(input())

MIN_ab = 999999

for a in range(1,N):
    a_sum = 0
    b_sum = 0
    for a_split in str(a):
        a_sum +=  int(a_split)
    for b_split in str(N-a):
        b_sum +=  int(b_split)
    if a_sum + b_sum < MIN_ab:
        MIN_ab = a_sum + b_sum
        
print(MIN_ab)

Submission status: Accepted

Solution code:
N = input()
ans = 99999999
for A in range(1,N):
  B = N-A
  if A<=B:
    ans = min(ans, sum(map(int, str(A)+str(B))))
print ans

Submission status: Accepted

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

n = int(input())

res = 1000000

for a in range(1, n):
    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: Accepted

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

    for a in range(1, 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: Accepted

Solution code:
n = int(input())
sum_list = [sum([int(e) for e in str(n - c)])  + sum([int(d) for d in str(c)]) for c in range(1, n)]
print(min(sum_list))

Submission status: Accepted

Solution code:
N = sum([int(i) for i in input()])
print('10' if N == 1 else N)

Submission status: Accepted

Solution code:
N=int(input())




ANS=N
for a in range(1,N):
    FIRST=a%10+(a%100)//10+(a%1000)//100+(a%10000)//1000+(a%100000)//10000
    x=N-a
    SUB=x%10+(x%100)//10+(x%1000)//100+(x%10000)//1000+(x%100000)//10000

    SUM=FIRST+SUB

    if ANS!= SUM:
        ANS=min(ANS,SUM)

print(ANS)

Submission status: Accepted

Solution code:
# https://agc025.contest.atcoder.jp/tasks/agc025_a

N = int(input())

if N < 10:
    print(N)
    exit(0)


r = str(N)[1:]
if int(r) == 0:
    print(sum(map(int, list(str(N // 2)))) * 2)
    exit(0)


l = sum(map(int, list(str(N))))


print(l)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    C = N
    if N%2 == 1:
        n = N//2+1
    else:
        n = N//2
    for i in range(1,n+1):
        A = str(i)
        B = str(N-i)
        c = 0
        for k in range(len(B)):
            if k < len(A):
                c += int(A[-k-1])+int(B[-k-1])
            else:
                c += int(B[-k-1])
        C = min(C, c)
    return C

if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def calc(i):
    s = str(i)
    sums = 0
    for e in s:
        sums += int(e)
    return sums

N = I()
lis = []
for i in range(1,N):
    lis.append(calc(i))
ans = 10**10
for i in range(N//2):
    ans = min(ans,lis[i]+lis[N-2-i])
print(ans)

Submission status: Accepted

Solution code:
def solve(N):
    digits = [int(d) for d in str(N)]
    tmp_ans = sum(digits)
    if tmp_ans == 1:
        return 10
    else:
        return tmp_ans

# assert(solve(2) == 2) # 1 and 1
# assert(solve(10) == 10) # 5 and 5
# assert(solve(15) == 6) # 2 and 13
# assert(solve(100) == 10) # 50 and 50
# assert(solve(100000) == 10) # 50000 and 50000

N = input()
print(solve(N))

Submission status: Accepted

Solution code:
n = list(map(int,list(input())))

ans = 0

if(n[0] == 1 and n.count(0) == len(n) -1):
  ans = 10

else:
  for i in range(len(n)):
    ans += n[i]

print(ans)

Submission status: Accepted

Solution code:
# encoding:utf-8


def main():
	n = int(input())
	nums = [int(x) for x in list(str(n))]
	x = [10 ** i for i in range(7)]
	for i1 in x:
		if n == i1:
			print(10)
			#print("a1")
			break
		else:
			for i2 in range(2, 10):
				if n == x * i2:
					print(i2)
					#print("a2")
					break

	else:
		print(sum(nums))
		#print("a3")

		

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
N=int(input())
suma=N
for i in range(1,N):
    factor_n1 = [int(x) for x in list(str(i))] 
    s1=sum(factor_n1)
    factor_n2 = [int(y) for y in list(str(N-i)) ]
    s2=sum(factor_n2)
    if(s1+s2<suma):
        suma=s1+s2
print(suma)

Submission status: Accepted

Solution code:
n = int(input())
ret = 10000000
for i in range(1, n//2 + 1):
    c = 0
    for s in str(i):
        c += int(s)
    for s in str(n - i):
        c += int(s)
    if ret > c:
        ret = c
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
tmp = n
k = 0
while tmp > 0 :
    tmp = tmp//10
    k += 1 

ans = 1e10
for i in range(1,n) :
    tmp = n - i
    x = 0
    while tmp > 0 :
        x += tmp%10
        tmp = tmp//10
    tmp = i
    while tmp > 0 :
        x += tmp%10
        tmp = tmp//10
    ans = min(ans, x)

print(ans)

Submission status: Accepted

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

if n == 2:
  min = 2
print(min)

Submission status: Accepted

Solution code:
n=int(input())
m=1000

def calc(n):
    ans=0
    for i in range(len(n)):
        ans+=int(n[i])
    return ans

for i in range(1,n):
    a=i
    b=n-i
    m=min([calc(str(a))+calc(str(b)),m])

print(m)

Submission status: Accepted

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 = float('inf')
    for a in range(1,mid_N+1):
        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: Accepted

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))
elif digits[0] != 1:
	print(digits[0])
else:
	print(10)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

ans = 1e5
for i in range(1, int(n/2)+1, 1):
    tmp = 0
    a = i
    b = n - i
    while(a != 0):
        tmp += a % 10
        a -= a % 10
        a /= 10
    while(b != 0):
        tmp += b % 10
        b -= b % 10
        b /= 10
    if(ans > tmp): ans = tmp

print(int(ans))

Submission status: Accepted

Solution code:
N = int(input())
c = 0
i = 1
while N !=0:
    num = N%10
    c += num
    i += 1
    N = N//10
print(c if c!=1 else 10)

Submission status: Accepted

Solution code:
N = int(input())

minimum = N * 100

def kakuiNoWa(x:int):
    digits = []
    for i in range(5):
        digits.append(int(str(int(x / (10 ** i)))[-1]))
    return sum(digits)

for i in range(1, int(N / 2) + 1):
    result = kakuiNoWa(i) + kakuiNoWa(N-i)
    minimum = min(minimum, result)

print(minimum)

Submission status: Accepted

Solution code:
from sys import stdin


def a(s):
    result = 0
    for c in s[::-1]:
        result += int(c)
    return result


def main():
    N = int(stdin.readline().rstrip())
    print(min([a(str(x)) + a(str(N - x)) for x in range(1, N // 2 + 1)]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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 if n!=2 and n!=3 else n)

Submission status: Accepted

Solution code:
N = int(input())

m = float("inf")
for i in range(1,N):
    A = i
    B = N - i
    factor_A = [int(x) for x in list(str(A))]
    factor_B = [int(x) for x in list(str(B))]
    tmp = sum(factor_A) + sum(factor_B)
    if m > tmp:
        m = tmp

print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

ans = 0

if n % 10 == 0:
    ans = 10

else:
    for i in str(n):
        ans += int(i)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

def addd(n):
    d = 0
    while n > 0:
        d += n % 10
        n //= 10
    return d


def main():
    N = int(input())

    best = 9 * 20
    for i in range(1, N):
        j = N - i
        best = min(best, addd(i) + addd(j))

    print(best)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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):
    j = N - i
    min_sum = digitSum(i) + digitSum(j)
    if min_sum < minmum:
        minmum = min_sum

print(minmum)

Submission status: Accepted

Solution code:
n = int(input())

minsum = 900000

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

Submission status: Accepted

Solution code:
n = int(input())
nmin = 10000000
for n1 in range(1,n):
    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: Accepted

Solution code:
N=int(input())
m=45
for a in range(1,N):
    b=a//100000
    c=(a-b*100000)//10000
    d=(a-b*100000-c*10000)//1000
    e=(a-b*100000-c*10000-d*1000)//100
    f=(a-b*100000-c*10000-d*1000-e*100)//10
    g=a-b*100000-c*10000-d*1000-e*100-f*10
    h=(N-a)//100000
    i=(N-a-h*100000)//10000
    j=(N-a-h*100000-i*10000)//1000
    k=(N-a-h*100000-i*10000-j*1000)//100
    l=(N-a-h*100000-i*10000-j*1000-k*100)//10
    n=N-a-h*100000-i*10000-j*1000-k*100-l*10
    m=min(m,b+c+d+e+f+g+h+i+j+k+l+n)
    
print(m)

Submission status: Accepted

Solution code:
N = int(input())
M = 150
for A in range(1,int(round(N/2+2))):
    B = N - A
    AS = sum([int(x) for x in list(str(A))])
    BS = sum([int(x) for x in list(str(B))])
    S = AS+BS
    if(S<M):
        M=S
print(M)

Submission status: Accepted

Solution code:
a = int(input())

def func(a):
    digits = []
    temp = a
    while temp != 0:
        digits.append(temp%10)
        temp = int(temp/10)
    result = sum(digits)
    if result == 1:
        print('10')
    else:
        print(result)

func(a)

Submission status: Accepted

Solution code:
N = int(input())

result = N
for A in range(1, N):
	tmp = sum(list(map(int, list(str(A))))) + sum(list(map(int, list(str(N - A)))))
	if tmp < result:
		result = tmp

print(result)

Submission status: Accepted

Solution code:
n = int(input())

def str2each_num(s):
    li = [int(_) for _ in s]
    return li


ans = min([sum(str2each_num(str(i))) + sum(str2each_num(str(n - i))) for i in range(1, n//2+1)])
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = input()
    if N%10 != 0:
        print(digitSum(N))
    else:
        print(digitSum(N)*10)

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())

    total = float('inf')
    for a in range(1, N):
        b = N - a
        n = 0
        while a > 0:
            n += a % 10
            a //= 10
        while b > 0:
            n += b % 10
            b //= 10
        total = min(total, n)

    print(total)

main()

Submission status: Accepted

Solution code:
N = int(input())

minimum = N

for i in range(1,N):
    total = 0
    A = i
    B = N-i
    a = str(A)
    b = str(B)
    for j in range(len(a)):
        total = total + int(a[j])
    for k in range(len(b)):
        total = total + int(b[k])
    minimum = min(minimum,total)

print(minimum)

Submission status: Accepted

Solution code:
n = input()
s = int(n)
min = 100000
for i in range(1,s):
  a = str(s - i)
  array1 = list(map(int, list(a)))
  array2 = list(map(int, list(str(i))))
  b = sum(array1) + sum(array2)
  if b < min:
    min = b
print(min)

Submission status: Accepted

Solution code:
M = list(input())
result = 0
if set(M[1:]) == {'0'}:
    result = 10
else:
    for i in M:
        result = result + int(i)
print(result)
print()

Submission status: Accepted

Solution code:
import math


def kk(d):
    if d == 0:
        return 0
    else:
        return kk(int(d / 10)) + (d % 10)


n = int(input())
logs = math.log10(n)
if int(logs) == logs:
    print(10)
else:
    print(kk(n))

Submission status: Accepted

Solution code:
N=int(input())
ans=10**5
for A in range(1,(N//2)+1):
  B=N-A
  ans=min(ans,sum([int(x) for x in list(str(A)+str(B))]))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

m = (N // 100000) + (N // 10000) % 10 + (N // 1000) % 10 + (N // 100) % 10 + (N // 10) % 10 + (N) % 10
if m < 2:
	m += 9

print(m)

Submission status: Accepted

Solution code:
N = int(input())
import math
n = 10*N
for i in range(1,math.ceil(N/2)+1):
    m = 0
    j = str(N-i)
    i = str(i)
    for k in range(len(i)):
        m += int(i[k])
    for k in range(len(j)):
        m += int(j[k])
    if m < n:
        n = m
print(n)

Submission status: Accepted

Solution code:
N = input()
if int(N) == 10 ** (len(N) - 1) and len(N) > 1:
    print(10)
else:
    res = 0
    for c in N:
        res += int(c)
    print(res)

Submission status: Accepted

Solution code:
from collections import Counter

n = input()
c = Counter(n)
if '0' in c:
    del c['0']

if len(c) == 1 and '1' in c and c['1'] == 1:
    print(10)
else:
    print(sum(int(f) * m for f, m in c.items()))

Submission status: Accepted

Solution code:
#agc25a

n = int(input())

lst = []

for i in range(1,int(n/2)+1):
    a = n-i

    s1 = str(a)
    s2 = str(i)
    
    #print(s1,s2)
    ans = 0
    for j in range(len(s1)):
        ans += int(s1[j])
    #print(s1,ans)
    for j in range(len(s2)):
        ans += int(s2[j])
    #print(s2,ans) 
    lst.append(ans)
lst.sort()
print(lst[0])

Submission status: Accepted

Solution code:
# coding: utf-8

cs = lambda a: sum(map(int, "{}".format(a)))

n = int(input())
ans = float("inf")
for i in range(1, n//2 + 1):
    ans = min(ans, cs(i) + cs(n-i))
print(ans)

Submission status: Accepted

Solution code:
def total(a):
    sumnum = 0
    for i in range(len(str(a))):
        sumnum += int(str(a)[i])
    return sumnum

N = int(input())

S = []
for i in range(int(N / 2)):
    num = N - i - 1
    S.append(total(i + 1) + total(num))
print(min(S))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]# }}}

def local_input():
    from pcm.utils import set_stdin
    import sys
    if len(sys.argv) == 1:
        set_stdin(os.path.dirname(__file__) + '/test/' + 'sample-1.in')

def solve():
    N = int(input())
    res = float('inf')
    for n in range(1, N):
        a = n
        b = N - n
        res = min(res, calc(a) + calc(b))
    print(res)

def calc(a):
    res = 0
    for i in range(0, 6):
        b = dcopy(a)
        t = 10**i
        b = int(b/t)
        b %= 10
        res += b
    return res


if __name__ == "__main__":# {{{
    try:
        local_input()
    except:
        pass
    solve()
# vim: set foldmethod=marker:}}}

Submission status: Accepted

Solution code:
N = input()
ans = 0
t = False
if N[0] == "1":
    for i in N[1:]:
        if i != "0":
            break
    else:
        t = True
        print(10)
if not t:
    for n in N:
        ans += int(n)
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
if N < 10:
    print(N)
    exit()

while N%10 == 0:
    N = N//10

if N == 1:
    print(10)
    exit()

str_n = str(N)
int_n = map(int, str_n)
ans = sum(int_n)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = 100000

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

print(ans)

Submission status: Accepted

Solution code:
N=input()

ans=float("inf")

for A in range(1,N):
	B=N-A
	A2=list(str(A))
	B2=list(str(B))
	ans=min( ans, sum( map(int,A2) )+ sum( map(int,B2) ) )

print ans

Submission status: Accepted

Solution code:
#coding:utf-8
p = [10, 100, 1000, 10000, 100000]
N = int(input())
if N in p:
    print(10)

else:
    N = str(N)
    total = 0
    for ch in N:
        total += int(ch)
    print(total)

Submission status: Accepted

Solution code:
n = input()
ans = 0
for i in n:
    ans += int(i)

if ans == 1:
    ans = 10

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

n = stdin.readline().strip()

l = 0
r = 0
for i in range(len(n)):
    l += int(n[i]) // 2
    r += int(n[i]) - (int(n[i])//2)

if l==0:
    l = 0
    r = 0
    ls = str(int(n) // 2)
    rs = str(int(n) - (int(n)//2))
    for i in range(len(ls)):
        l += int(ls[i])
    for i in range(len(rs)):
        r += int(rs[i])

print(l+r)

Submission status: Accepted

Solution code:
n = int(raw_input())
while n%10==0: n /= 10
if n == 1: print 10
else:
    print sum(list(map(int,str(n))))

Submission status: Accepted

Solution code:
N=int(input())

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

while( N>=0 ) :
  if N % 10 == 0:
    N = int(N / 10)
    if N == 1:
      print(10)
      break
    continue
  else:
    print(digitSum(N))
    break

Submission status: Accepted

Solution code:
n = int(input())
number = 0
for i in str(n):
    number += int(i)
if number == 1:
    number += 9
print(number)

Submission status: Accepted

Solution code:
N = int(input())
while(N%10 == 0):
 N /= 10
if N == 1:
 print(10)
else:
 s = str(N)
 array = list(map(int, list(s)))
 print(sum(array))

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
for i in range(1, 6):
    if n == 10 ** i:
        ans = 1

if ans == 1:
    print(10)
else:
    num = 0
    for i in range(1, 6):
        num += n % 10
        n = n // 10
    print(num)

Submission status: Accepted

Solution code:
def main():
    n = int(input())

    min_s = 100001
    for i in range(1, n//2+2):
        b = n - i

        a_s, b_s = i % 10, b % 10
        while i // 10 != 0:
            i //= 10
            a_s += i % 10

        while b // 10 != 0:
            b //= 10
            b_s += b % 10

        if a_s + b_s < min_s:
            min_s = a_s + b_s

    print(min_s)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

def c(n):
  digit_sum = 0
  length = n
  for i in range(length):
    digit = n % 10
    digit_sum += digit
    n = n // 10
    if n == 0:
      break
      
  return digit_sum

min_sum = n
for a in range(1, n):
  b = n - a
  digit_sum = c(a) + c(b)
  if digit_sum < min_sum:
    min_sum = digit_sum

print(min_sum)

Submission status: Accepted

Solution code:
N = int(input())

result = 10 ** 10

for a in range(1, N):
    b = N - a
    A = 0
    while a != 0:
        A += a % 10
        a = a // 10
    B = 0
    while b != 0:
        B += b % 10
        b = b // 10

    result = min(result, A + B)

print(result)

Submission status: Accepted

Solution code:
N = int(input())

def f(N):
    ll = list(str(N))
    min_num = sum([int(i) for i in ll])
    return min_num

min_num = f(N-1) + f(1)

if N % 2 == 0:
    for i in range(1, int(N/2)):
        counter = N-i
        sum_num = f(i) + f(counter)
        if min_num > sum_num:
            min_num = sum_num

else:
    for i in range(1, int((N+1)/2)):
        counter = N-i
        sum_num = f(i) + f(counter)
        if min_num > sum_num:
            min_num = sum_num

print(min_num)

Submission status: Accepted

Solution code:
N = int(input())

ans = float('inf')
for i in range(1, N//2+1):
  a = i
  b = N - a
  digitSumA = digitSumB = 0
  for i in range(6):
    digitSumA += a % 10
    a //= 10
    digitSumB += b % 10
    b //= 10
  ans = min(ans, digitSumA + digitSumB)
print(ans)

Submission status: Accepted

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(1, int(N/2)+1):
    B = N - A
    val = digit_sum(A) + digit_sum(B)
    min_ = min(min_, val)

print(min_)

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np




n = int(input())
min_sum=9999999
for a in range(1,n):
    aa=a
    bb=n-a
    sumab = 0
    while aa > 0:
        sumab += (aa % 10)
        aa = aa // 10
    while bb > 0:
        sumab += (bb % 10)
        bb = bb // 10
    min_sum = min(min_sum,sumab)
print(min_sum)

Submission status: Accepted

Solution code:
n = input()
minsofar = 100000000

def sumofdigits(a):
    ans = 0
    for i in `a`:
        ans += int(i)
    return ans

for i in range(1, n):
    a = i
    b = n - a
    minsofar = min(minsofar, sumofdigits(a) + sumofdigits(b))

print minsofar

Submission status: Accepted

Solution code:
N=int(input())

def func(i):
    s=str(i)
    return sum([int(c) for c in s])

minimum=1000000
for i in range(1,N):
    tmp=sum([func(i),func(N-i)])
    if tmp<minimum:
        minimum=tmp

print(minimum)

Submission status: Accepted

Solution code:
N = int(input())

ans = N
for A in range(1,N):
    B = N - A
    A_str = str(A)
    B_str = str(B)
    A_li = [int(A_str[i]) for i in range(len(A_str))]
    B_li = [int(B_str[i]) for i in range(len(B_str))]
    s = sum(A_li) + sum(B_li)
    if s < ans:
        ans = s

print(ans)