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:
n = int(input())
absum = []
for a in range(1,n//2+1):
    b = n-a
    asum = 0
    bsum = 0
    alen = len(str(a))
    blen = len(str(b))
    for j in range(alen):
        a0 = (a//(10**j)) % 10
        asum = asum + a0
    for k in range(blen):
        b0 = (b//(10**k)) % 10
        bsum = bsum + b0
    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
    alen = len(str(a))
    blen = len(str(b))
    for j in range(alen):
        a0 = (a//(10**j)) % 10
        asum = asum + a0
    for k in range(blen):
        b0 = (b//(10**k)) % 10
        bsum = bsum + b0
    absum.append(asum+bsum)
print(min(absum))

Submission status: Accepted

Solution code:
N = int(input())
n = N - 1
A = list(str(n))
A = list(int(n) for n in A)
ans1 = sum(A) + 1

n = N // 2
A = list(str(n))
A = list(int(n) for n in A)
ans2 = 2 * sum(A)

if N % 2 == 0:
    ans = min(ans1, ans2)
else:
    ans = min(ans1, ans2 + 1)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()



def main():
	n=II()

	ans=10**10


	for i in range(1,n):
		a=str(i)
		b=str(n-i)
		cnt=0
		for aa in a:
			cnt+=int(aa)
		for bb in b:
			cnt+=int(bb)
		ans=min(ans,cnt)
	print(ans)









if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
N = int(input())

def digit_sum(A):
    S = 0
    while A > 0:
        S += A % 10
        A //= 10
    return S

ans = 10e+5
for A in range(1, N):
    cand = digit_sum(A) + digit_sum(N - A)
    ans = min(ans, cand)

print(ans)

Submission status: Accepted

Solution code:
def digits_sum(n):
    return sum(int(c) for c in str(n))


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ans = float('inf')
for i in range(N//2):
  A = i+1
  B = N-A
  ans = min(ans, sum(list(map(int,str(A)))) + sum(list(map(int,str(B))) ))

print(ans)

Submission status: Accepted

Solution code:
S = input()
ansA = 0
ansB = 0
for i in range(len(S)):
    N = int(S[i])
    if N == 1:
        ansA += 1
    elif N % 2 == 0:
        ansA += N//2
        ansB += N//2
    else:
        N -= 1
        ansA += N//2+1
        ansB += N//2
if ansA == 1 and ansB == 0:
    ans = 10
else:
    ans = ansA+ansB
print(ans)

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:
import sys
n=int(input())
ans=0
flag=0
while n%10==0:
  n=n//10
if n==1:
  print(10)
  sys.exit()
s=str(n)
for i in range(len(s)):
  ans+=int(s[i])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
cmin = N
for i in range(1,N//2):
    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())
ans = 10**9
for a in range(1,n):
    b = n - a
    a_sum = 0
    b_sum = 0
    for ai in str(a):
        a_sum += int(ai)
    for bi in str(b):
        b_sum += int(bi)
    v = a_sum+b_sum
    ans = min(ans,v)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
if N == 10 or N == 100 or N == 1000 or N == 10000 or N == 100000:
    print(10)
else:
    ans = sum(list(map(int, str(N))))
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

if n == 10 or n == 100 or n == 1000 or n == 10000 or n == 100000:
    ans = 10
else:
    n = str(n)
    ans = 0
    for l in n:
        ans += int(l)

print(ans)

Submission status: Accepted

Solution code:
def digitsum(n):
    tmp = 0
    while n > 0:
        tmp += n % 10
        n //= 10
    return tmp


N = int(input())
m = 10**5+1
for i in range(1, N//2+1):
    A = digitsum(i)
    B = digitsum(N-i)
    m = min(m, A+B)
print(str(m))

Submission status: Accepted

Solution code:
def findSumOfDigits(n):
    sum = 0
    while n > 0:
        sum += n % 10
        n //= 10
    return sum

n = int(input())
minTotal = float('inf')
for i in range(1,n+1):
    if 0 < n - i < n:
        a = findSumOfDigits(i)
        b = findSumOfDigits(n-i)
        if a + b < minTotal:
            minTotal = a + b
print(minTotal)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def digit_sum(x): 
    y = str(x) 
    y_len = len(y) 
    ans = 0
    for j in range(y_len):
        ans += int(y[j]) 

    return ans

answer = 10**8 
n = int(input()) 
for i in range(1,n):
    a = i 
    b = n - a 
    answer = min(answer, digit_sum(a)+ digit_sum(b))

print(answer)

Submission status: Accepted

Solution code:
n = int(input())
ans = 10 ** 9
for a in range(1, n):
  b = n - a
  total = sum([int(digit_a) for digit_a in str(a)]) + sum([int(digit_b) for digit_b in str(b)])
  if total < ans:
    ans = total
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans  = 10**5+1
for i in range(1,N//2 + 1):
    A = i
    B = N - i
    tmp = 0
    while(A > 0):
        tmp += A % 10
        A //= 10
    while(B > 0):
        tmp += B % 10
        B //= 10
    ans = min(ans,tmp)
print(str(ans))

Submission status: Accepted

Solution code:
#
# agc025 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """15"""
        output = """6"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """100000"""
        output = """10"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    ans = float('inf')
    for a in range(1, N):
        b = N - a
        A = str(a)
        B = str(b)
        t = 0
        for i in range(len(A)):
            t += int(A[i])
        for i in range(len(B)):
            t += int(B[i])
        ans = min(ans, t)
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
N = int(input())

n = 1
ans = 10**5

def calucurate(M):
    n = 0
    while M > 0:
        n += M%10
        M //= 10
    return n

while n < N:
    t = N - n
    m = calucurate(t) + calucurate(n)
    ans = min(ans,m)
    n += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = float("inf")
for i in range(1,N):
    if sum(map(int, str(i))) + sum(map(int, str(N-i))) < ans:
        ans = sum(map(int, str(i))) + sum(map(int, str(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
    m = len(str(a))
    l = len(str(b))
    cnt = 0
    for j in range(m):
        cnt += int(str(a)[j])
    for j in range(l):
        cnt += int(str(b)[j])
    ans = min(ans, cnt)

print(ans)

Submission status: Accepted

Solution code:
def calc_sum_of_digits(num):
	ans = 0

	while True:
		if num // 10 == 0:
			ans += num
			break

		ans += num % 10
		num //= 10

	return ans


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

	for A in range(1, N):
		B = N - A

		A_sum = calc_sum_of_digits(A)
		B_sum = calc_sum_of_digits(B)

		if A_sum + B_sum < min_sum:
			min_sum = A_sum + B_sum

	print(min_sum)

  
if __name__ == "__main__":
  	main()

Submission status: Accepted

Solution code:
def digitsum(N):
    return sum(map(int,list(str(N))))
N = int(input())
m = 100000
for A in range(1,N//2+1):
    B = N-A
    m = min(m,digitsum(A)+digitsum(B))
print(m)

Submission status: Accepted

Solution code:
N = int(input())
if N%10 ==0:
  ans = 10
else:
  NN = list(str(N))
  ans = 0
  for i in NN:
    ans += int(i)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
if n == 10 or n == 10 ** 2 or n == 10 ** 3 or n == 10 ** 4 or n == 10 ** 5:
    print(10)
else:
    ans = 0
    a = str(n)
    for i in range(len(a)):
        ans += int(a[i])
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def d_sum(n):
    ret = 0
    while(n>0):
        ret += n%10
        n //= 10
    return ret

ans = N
for i in range(1, N//2+2):
    ans = min(ans, d_sum(i)+d_sum(N-i))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())


def digit_sum(x):
    return sum(int(si) for si in str(x))


ans = 10**5
for a in range(1, n):
    b = n - a
    ans = min(ans, digit_sum(a) + digit_sum(b))

print(ans)

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    m = 10**100
    for i in range(1, N//2+1):
        A = i
        B = N-i
        Da = sum(int(a) for a in str(A))
        Db = sum(int(b) for b in str(B))
        m = min(m, Da+Db)
    print(m)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = 0
b = 0
ans = 1000000000
for i in range(1, n):
    a = n - i
    b = n - a
    a = list(map(int,str(a)))
    b = list(map(int,str(b)))
    if sum(a) + sum(b) <= ans:
        ans = sum(a) + sum(b)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = float('inf')
for i in range(1,N):
    A = i
    B = N - i
    Sum = 0
    for power in range(4,-1,-1):
        q_a,r_a = divmod(A,10**power)
        A = r_a
        q_b,r_b = divmod(B,10**power)
        B = r_b
        Sum += q_a + q_b
    ans = min(Sum, ans)
print(ans)

Submission status: Accepted

Solution code:
def digitsum(s):
    su = 0
    for i in range(len(s)):
        su += int(s[i])

    return su

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

    ans = 10**10
    for a in range(1, N):
        b = N - a
        tmp = digitsum(str(a)) + digitsum(str(b))

        ans = min(ans, tmp)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

ans = 2 * 10**5

for n in range(1,N//2 + 1):
  a = n
  b = N - n
  
  sum_a = sum(list(map(int,list(str(a)))))
  sum_b = sum(list(map(int,list(str(b)))))
  
  ans = min(ans,sum_a+sum_b)
print(ans)

Submission status: Accepted

Solution code:
import sys
import collections
import bisect
import math
import time


def main():
    n = input()
    if len(n) == 1:
        print(int(n))
        return

    if len(n) - list(n).count("0") >= 2:
        print(sum(list(map(lambda x: int(x), list(n)))))
        return

    if n[0:2] == "10":
        print(10)
        return

    print(n[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = 0
b = n
ans = 1e9
while (1 < b):
    a += 1
    b -= 1
    sa = str(a)
    sb = str(b)
    sum = 0
    for i in range(len(sa)):
        sum += int(sa[i])
    for i in range(len(sb)):
        sum += int(sb[i])
    ans = min(ans, sum)
print(ans)

Submission status: Accepted

Solution code:
# AGC 025 A - Digits Sum
N = int(input())

def sum_of(num): 
    list_b = []
    k = 0
    while num > 0:
        list_b.append(num%10)
        num //= 10
    for i in range(len(list_b)):
        k += list_b[i]
    return k 

list_a =[]
if N <= 10:
    print(str(N))
if N > 10:
    for i in range(2,(N-1)//2+1):
        A = i
        B = N - i
        list_a.append(sum_of(A) + sum_of(B))
    print(min(list_a))

Submission status: Accepted

Solution code:
n = int(input())

ans = 10**10
for i in range(1,n):
    a = i
    b = n-i
    s = sum([int(i) for i in str(a)]) + sum([int(i) for i in str(b)])
    ans = min(ans,s)
print(ans)

Submission status: Accepted

Solution code:
# AGC 025 A - Digits Sum
N = int(input())

def sum_of(num): 
    list_b = []
    k = 0
    while num > 0:
        list_b.append(num%10)
        num //= 10
    for i in range(len(list_b)):
        k += list_b[i]
    return k 

list_a =[]
if N <= 10:
    print(str(N))
if N > 10:
    for i in range(2,N-1):
        A = i
        B = N - i
        list_a.append(sum_of(A) + sum_of(B))
    print(min(list_a))

Submission status: Accepted

Solution code:
N = int(input())

def sum_of(num): 
    list_b = []
    k = 0
    while num > 0:
        list_b.append(num%10)
        num //= 10
    for i in range(len(list_b)):
        k += list_b[i]
    return k 

list_a =[]
if N == 2:
    print(str(2))
if N == 3:
    print(str(3))
if N >= 4:
    for i in range(2,N-1):
        A = i
        B = N - i
        list_a.append(sum_of(A) + sum_of(B))
    print(min(list_a))

Submission status: Accepted

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

for a in range(1,N):
  sum = 0
  A = a
  B = N-a
  while A > 0:
    sum += A%10
    A = int(A/10)
  while B > 0:
    sum += B%10
    B = int(B/10)
  if minval > sum:
    minval = sum

print(minval)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import math

n = int(input())
m = math.log10(n)
if int(m) == m:
    print(10)
    exit()

ans = sum(map(int, list(str(n))))
print(ans)

Submission status: Accepted

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

n = int(input())

def sumdigits(n):
    ret = 0 
    s = list(str(n))
    for i in range(len(s)):
        ret += int(s[i])
    return ret 

a = 1 
ans = 1000000
while n-a > 0:
    tmp = sumdigits(a) + sumdigits(n-a)
    if ans >= tmp:
        ans = tmp 
    a += 1

print(ans)

Submission status: Accepted

Solution code:
def solve(x):
  n = len(str(x))
  res = 0
  for i in str(x):
    res += int(i)
  return res

n=int(input())
ans = 10**20
for a in range(1,n):
  ans = min(ans,solve(a)+solve(n-a))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
mn=10**8
for A in range(1,N):
    B=N-A
    sm=0
    while A!=0:
        sm+=A%10
        A//=10
    while B!=0:
        sm+=B%10
        B//=10
    if mn>sm:
        mn=sm
print(mn)

Submission status: Accepted

Solution code:
N=int(input())
if N==10 or N==10**2 or N==10**3 or N==10**4 or N==10**5:
  print(10)
else:
  a=list(str(N))
  b=sum([int(i) for i in a])
  print(b)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    ans = INF
    for a in range(1,N//2+1):
        b = N-a
        res = 0
        for i in str(a):
            res += int(i)
        for i in str(b):
            res += int(i)
        ans = min(ans, res)
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
ans=100000000000
for a in range(1,N):
    b=N-a
    tempa=0
    tempb=0
    for i in range(len(str(a))):
        tempa+=a%10
        a=a//10
    for j in range(len(str(b))):
        tempb+=b%10
        b=b//10
    if tempa+tempb<ans:
        ans=tempa+tempb

print(ans)

Submission status: Accepted

Solution code:
#-------------
N = int(input())
#-------------

if N%2 == 0:
  k = N//2
else:
  k = (N+1)//2

cmb = []
for i in range(1,k+1):
  cmb.append([i , N-i])
  
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)

ans = []
for i in range(k-1):
  X = digitSum(cmb[i][0])
  Y = digitSum(cmb[i][1])
  ans.append(X+Y)


if ans == []:
  print("2")
else:
  print(min(ans))

Submission status: Accepted

Solution code:
Max = 1000000
def digit_sum(n):
	res = 0
	while n>0:
		res += int(n%10)
		n /= 10
	return res

N = int(input())
if N==10 or N==100 or N==1000 or N==10000 or N==100000:
	print(10)
else:
	print(digit_sum(N))

Submission status: Accepted

Solution code:
N=int(input())

def digitsum(x):
    res=0
    while x>0:
        res+=x%10
        x//=10
    return res

counter=90
for A in range(1,N):
    if digitsum(A)+digitsum(N-A)<counter:
        counter=digitsum(A)+digitsum(N-A)

print(counter)

Submission status: Accepted

Solution code:
INF = 1 << 60
n = int(input())
ans = INF
for a in range(1, n):
    b = str(n - a)
    a = str(a)
    total_a = 0
    total_b = 0
    for i in a:
        total_a += int(i)
    for i in b:
        total_b += int(i)
    ans = min(ans, total_a + total_b)
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    if 10**(len(str(N))-1) == N:
        print("10")
    else:
        print(sum(map(int, str(N))))
resolve()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
ans = 10**18
for i in range(1,n):
    j = n-i
    s = str(i).rjust(6,"0")[::-1]
    t = str(j).rjust(6,"0")[::-1]
    res = 0
    for i,j in zip(s,t):
        res += int(i)+int(j)
    ans = min(res,ans)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
if n%10 == 0:
    print(10)
else:
    cnt = 0
    while n != 0:
        cnt += n%10
        n //= 10
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=input()
ans=0
for n in N:
    ans+=int(n)
if ans==1:
    ans=10
print(ans)

Submission status: Accepted

Solution code:
N = int(input())


def f(x):
    ret = 0
    while x:
        x, r = divmod(x, 10)
        ret += r
    return ret


ret = 10 ** 9
for a in range(1, N):
    b = N - a
    ret = min(ret, f(a) + f(b))
print(ret)

Submission status: Accepted

Solution code:
N=input()
import re
if re.match('10+',N):
    print(10)
else:
    ans=0
    for n in N:
        ans+=int(n)
    print(ans)

Submission status: Accepted

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

ans=10**10

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

    X = sum(A) + sum(B)

    if ans > X:
        ans = X
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def f(n):
    ans = 0
    for s in str(n):
        ans += int(s)
    return ans

ans = float("INF")
for i in range(1, N):
    j = N-i
    ans = min(ans, f(i) + f(j))
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = float('inf')
for i in range(1, N):
    j = N-i
    i_str = str(i)
    j_str = str(j)
    i_sum, j_sum = 0, 0
    for p in range(len(i_str)):
        i_sum += int(i_str[p])
    for q in range(len(j_str)):
        j_sum += int(j_str[q])
    ans = min(ans, i_sum+j_sum)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def f(k):
    s = str(k)
    n = len(s)
    ans = 0
    for i in range(n):
        ans += int(s[i])
    return ans

ans = float("INF")
for i in range(1, N):
    j = N-i
    t = f(i) + f(j)
    ans = min(ans, t)

print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
MIN = 10**18
for i in range(1, N):
    val = 0
    a, b = i, N-i
    while a or b:
        x = a%10
        y = b%10
        val += (x+y)
        a //=10
        b //= 10
    MIN = min(MIN, val)

print(MIN)

Submission status: Accepted

Solution code:
n=int(input())
ans=10**18
for a in range(1,n):
  b=n-a
  tmp=0
  for aa in str(a):
    tmp+=int(aa)
  for bb in str(b):
    tmp+=int(bb)
  ans=min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
def calc(a):
  ret = 0
  while a != 0:
    ret += a % 10
    a //= 10
  return ret

def resolve():
  n = int(input())
  ans = 1000000000
  for a in range(1, n):
    b = n - a
    ans = min(ans, calc(a) + calc(b))
  print(ans)
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
n=int(input())
while n%10==0 and n!=10:
  n=n//10
if n==10:
  print(10)
else:
  s=str(n)
  ans=0
  for i in range(len(s)):
    ans+=int(s[i])
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

def f(n):
    n = str(n)
    res = 0
    for i in range(len(n)):
        res += int(n[i])
    return res

ans = 1000000
for i in range(1, N//2+1):
    ans = min(ans, f(i)+f(N-i))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()


def dsum(x):
    r = 0
    while x:
        r += x % 10
        x //= 10
    return r


def solve():
    ans = 1 << 60
    for a in range(1, N // 2 + 2):
        b = N - a
        ans = min(ans, dsum(a) + dsum(b))
    return ans


print(solve())

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    ans = INF

    for x in range(1, n):
        score = 0
        a = x
        b = n - a
        while a > 0:
            score += a % 10
            a //= 10
        while b > 0:
            score += b % 10
            b //= 10
        ans = min(ans, score)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

if n%10 == 0: print(10)
else: print(sum([int(i) for i in str(n)]))

Submission status: Accepted

Solution code:
n = int(input())
s = 0
while True:
    s += n % 10
    n = n // 10
    if n == 0:
        break

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

Submission status: Accepted

Solution code:
n = int(input())
min_k = 10000000000
for i in range(1,n//2+1):
    sum_k = 0
    a = str(i)
    b = str(n-i)
    for j in a:
        sum_k += int(j)
    for j in b:
        sum_k += int(j)
    min_k = min(min_k,sum_k)
print(min_k)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

Submission status: Accepted

Solution code:
n = int(input())

def Digits_sum(a):
    a_s = str(a)
    sum_ = 0
    for i in a_s:
        sum_ += int(i)
    return sum_

ans = 10000

for i in range(1,(n//2)+1):
    A = i
    B = n-A
    sum_ = Digits_sum(A)+Digits_sum(B)
    ans = min(ans,sum_)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

mn = 10**10
for a in range(1, n // 2+1):
    mn = min(mn, sum(int(i) for i in str(a)) + sum(int(i) for i in str(n-a)))
print(mn)

Submission status: Accepted

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

for A in range(1,1+int(N/2)):
  tmp = 0
  B = N - A
  A = str(A)
  B = str(B)
  for i in range(0,len(A)):
    tmp += int(A[i])
  for i in range(0,len(B)):
    tmp += int(B[i])
  ans.append(tmp)

print(min(ans))

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 1000000
for i in range(1,n):
  if ans > digit(i) + digit(n-i):
    ans = digit(i) + digit(n-i)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [10 ** 1,10 ** 2,10 ** 3,10 ** 4,10 ** 5]
if n in a:
    print(10)
    exit(0)

l = 10 ** 5
for i in range(1,n):
    m = n
    p = i
    q = m - 1
    z = 0
    while p > 0:
        z += p % 10
        p = p // 10
    while q > 0:
        z += q % 10
        q = q // 10
    l = min(l,z)

print(l)

Submission status: Accepted

Solution code:
n = int(input())

res = 0

while n:
    res += n % 10
    n //= 10
if res == 1:
    print(10)
else:
    print(res)

Submission status: Accepted

Solution code:
n=int(input())

m=[]
for i in range(1,n//2+2):
    a=0
    k=i
    l=n-i
    while k>0 or l>0:
        a=a+k%10+l%10
        k=k//10
        l=l//10

    m.append(a)

print(min(m))

Submission status: Accepted

Solution code:
n = int(input())
res = 0
while n:
    res += n % 10
    n //= 10
if res == 1:
    print(10)
else:
    print(res)

Submission status: Accepted

Solution code:
n = int(input())
res = 10000
for i in range(1, n // 2 + 1):
  s = str(i)
  t = str(n - i)
  cnt = 0
  for j in s + t:
    cnt += int(j)
  res = min(res, cnt)
print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())

ans = 999999

for i in range(1, n):
    a = [int(c) for c in str(i)]
    b = [int(c) for c in str(n - i)]

    k = sum(a) + sum(b)

    if k < ans:
        ans = k

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = 0
b = 0
ans = 0
s = 10000
for i in range(1,int(N/2) + 1):
    a = i
    b = N - i
    ans = 0
    while 1:
        ans += a % 10 + b % 10
        a = a // 10
        b = b // 10
        if a == 0 and b == 0:
            if ans < s:
                s = ans
            break
print(s)

Submission status: Accepted

Solution code:
n = int(input())
ans = 46
for i in range(1, n):
    tmp = 0
    j = n - i
    while i > 0:
        tmp += i % 10
        i //= 10
    while j > 0:
        tmp += j % 10
        j //= 10
    ans = min(tmp, ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
N_half = N//2

min_sum = N

for A in range(1,N_half+1):
  digit_a = 0
  digit_b = 0
  B = N-A
  while A!=0:
    num = A%10
    digit_a += num
    A = A//10
  while B!=0:
    num = B%10
    digit_b += num
    B = B//10
  digit = digit_a + digit_b
  if digit<min_sum:
    min_sum = digit

print(min_sum)

Submission status: Accepted

Solution code:
n=int(input())

def sum0f(n):
    sum=0
    while n>0:
        sum+=n%10
        n//=10
    return sum

list=[]    
for a in range(1,n):
    list.append(sum0f(a)+sum0f(n-a))
    
print(min(list))

Submission status: Accepted

Solution code:
n = int(input())

def wa(n):
  ret = 0
  while n > 0:
    ret += n%10
    n //= 10
  return ret

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

Submission status: Accepted

Solution code:
N=int(input())
ans=100000000000
for A in range(1,N):
    B=N-A
    sa=0
    sb=0
    for i in range(len(str(A))):
        sa+=A%10
        A=(A-A%10)//10
    for j in range(len(str(B))):
        sb+=B%10
        B=(B-B%10)//10
    if sa+sb<ans:
        ans=sa+sb

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
rt = n
def sums(st: str):
  return sums(st[:-1])+int(st[-1]) if len(st) >1 else int(st)
for a in range(1,n//2):
  b = n - a
  tmp = sums(str(b)) + sums(str(a))
  if tmp < rt:
    rt = tmp
print(rt)

Submission status: Accepted

Solution code:
n = str(input())
ans = 0
for x in n:
  ans+=int(x)
if ans==1:
  ans=10
print(ans)

Submission status: Accepted

Solution code:
import numpy as np


def sum_of_digits(x):
  res = np.zeros_like(x)
  for i in range(len(x)):
    s = 0
    while x[i] > 0:
      s += x[i] % 10
      x[i] = int(x[i] / 10)
    res[i] = s
  return res


n = int(input())
a = np.arange(1, n)
b = a[::-1].copy()
print(np.min(sum_of_digits(a) + sum_of_digits(b)))

Submission status: Accepted

Solution code:
num = int(input())
val = 0
while num > 0:
    val += num%10
    num //= 10
if val == 1:
    print(10)
else:
    print(val)

Submission status: Accepted

Solution code:
n=int(input())
if n in [10,100,1000,10000,100000]:
  print(10)
else:
  x=str(n)
  ans=0
  for i in x:
    ans+=int(i)
  print(ans)

Submission status: Accepted

Solution code:
n = int(input())
if n%10==0:
  print(10)
else:
  ans = [char for char in str(n)]
  for i in range(0, len(ans)): 
    ans[i] = int(ans[i]) 
  print(sum(ans))

Submission status: Accepted

Solution code:
n = int(input())
ans = 1e18
for i in range(1, n):
    a = i
    b = n-i
    tmp = 0
    while a:
        tmp += a%10
        a //= 10
    while b:
        tmp += b%10
        b //= 10
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
sum = float('inf')
 
for i in range(1, n):
    k = 0
    for j in range(len(str(i))):
        k += float(str(i)[j])
    for l in range(len(str(n-i))):
        k += float(str(n-i)[l])
    sum = min(sum, k)
 
print(int(sum))

Submission status: Accepted

Solution code:
n = int(input())
sum = float('inf')

for i in range(1, n):
    k = 0
    for j in range(len(str(i))):
        k += float(str(i)[j])
    for l in range(len(str(n-i))):
        k += float(str(n-i)[l])
    sum = min(sum, k)

print(int(sum))

Submission status: Accepted

Solution code:
N = int(input())
L = [10, 10**2, 10**3, 10**4, 10**5]
if N in L:
  print(10)
else:
  X = list(str(N))
  Y = sum([int(i) for i in X])
  print(Y)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(1,6):
    if n%(10*i) == 0:
        print(10)
        exit()
print(sum(list(map(int, str(n)))))

Submission status: Accepted

Solution code:
n = int(input())
ans = 100000
for i in range(1, n):
    a, b = str(i), str(n-i)
    A, B = 0, 0
    for x in a:
        A += int(x)
    for y in b:
        B += int(y)
    ans = min(ans, A+B)
print(ans)