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())
ans = 1000000
for i in range(1, N):
    total = 0
    A = str(i)
    for a in A:
        total += int(a)
    B = str(N-i)
    for b in B:
        total += int(b)
    if total < ans:
        ans = total

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = float('inf')
for i in range(1, N):
    num = 0
    for x in str(i):
        num += int(x)
    for x in str(N-i):
        num += int(x)
    ans = min(ans, num)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

sum_list = []
for i in range(1, int(n / 2) + 1):
    a = i
    b = n - i
    sum_a = 0
    for a_i in range(len(str(a))):
        sum_a += int(str(a)[a_i])
    sum_b = 0
    for b_i in range(len(str(b))):
        sum_b += int(str(b)[b_i])
    sum_list.append(sum_a + sum_b)

print(min(sum_list))

Submission status: Accepted

Solution code:
n = int(input())

def digit(a):
    return sum(map(int,list(str(a))))

n2 = list(str(n))
ln = len(n2)
for i in range(ln-1,-1,-1):
    if n2[i] != "0":
        b = i
        break
if b == 0 and n2[0] == "1":
    print(10)
else:
    print(digit(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ans = 10**8
for a in range(1, N//2+1):
    b = N-a
    tmp = sum([int(s) for s in str(a)])+sum([int(s) for s in str(b)])
    ans = min(ans, tmp)

print(ans)

Submission status: Accepted

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


def read_h(typ=int):
    return map(typ, input().split())


def read_v(n, typ=int):
    return [typ(input()) for _ in range(n)]


def digit_sum(i):
    return sum([int(d) for d in str(i)])


def main():
    n, = read_h()
    ans = 10000
    for a in range(1, n):
        b = n - a
        s = digit_sum(a) + digit_sum(b)
        if s < ans:
            ans = s

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
c_min=200000
for i in range(1,n):
    a=i
    b=n-i
    a_c=0
    b_c=0
    if(a==0)|(b==0):
        print('Err')
    for j in range(6):
        a_c=a_c+a%10
        a=a//10
    for j in range(6):
        b_c=b_c+b%10
        b=b//10
    if (a_c+b_c<=c_min):
        c_min=a_c+b_c
        #print(i,n-i)
    
print(c_min)

Submission status: Accepted

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

N = int(input())
answer = float("inf")
for i in range(1,N//2+1):
  A = i 
  B = N - A
  answer = min(answer, digitSum(A) + digitSum(B))

print(answer)

Submission status: Accepted

Solution code:
n=int(input())
ans=100
for i in range(1,n//2+1):
    a=i
    b=n-i
    t=0
    while a>0 or b>0:
        t+=a%10+b%10
        a//=10
        b//=10
    ans=min(t,ans)
print(ans)

Submission status: Accepted

Solution code:
n=input()
if int(n)%10==0:
  print(10)
else:
  c=0
  for i in n:
    c+=int(i)
  print(c)

Submission status: Accepted

Solution code:
N = int(input())
def sum_order(x):
    order=[]
    while True:
        order.append(x % 10)
        x = int(x/10)
        if x == 0:
            break
    return sum(order)

min_order = 9*5
for A in range(1, N):
    B = N - A
    sum_A = sum_order(A)
    sum_B = sum_order(B)
    if min_order > sum_A + sum_B:
        min_order = sum_A + sum_B

print(min_order)

Submission status: Accepted

Solution code:
s = input()
n = int(s)
ans = 0
for i in s:
    ans += int(i)
if s.count('0') == len(s)-1 and s[0]=='1':
    ans += 9
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
result=[]
for i in range(1,N):
  A=str(i)
  B=str(N-int(A))
  goukei=[]
  for j in range(len(A)):
    goukei.append(int(A[j]))
  for k in range(len(B)):
    goukei.append(int(B[k]))
  result.append(sum(goukei))

print(min(result))

Submission status: Accepted

Solution code:
N = int(input())

if not N % 10:
    print(10)
else:
    ans = [int(x) for x in list(str(N))]
    print(sum(ans))

Submission status: Accepted

Solution code:
n=input()
if int(n)==10**(len(n)-1):
  print(10)
else:
  print(sum(int(i) for i in n))

Submission status: Accepted

Solution code:
N = int(input())

def solve(n):
	return sum(list(map(int, str(n))))

min_d = 10 ** 12

for a in range(1, N):
	b = N - a
	min_d = min(min_d, solve(a) + solve(b))
print(min_d)

Submission status: Accepted

Solution code:
n = int(input())

out = 1000000

for a in range(1,n):
    b = n-a
    a = [int(i) for i in list(str(a))]
    sum_a = sum(a)
    b = [int(i) for i in list(str(b))]
    sum_b = sum(b)
    
    if sum_a + sum_b < out:
        out = sum_a + sum_b
        
print(out)

Submission status: Accepted

Solution code:
a = [int(i) for i in list(input())]
if a[0] == 1 and max(a[1:])==0:
    print(10)
else:
    print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
def sumNum(i):
    if i//10 == 0:
        s = i
    else:
        s = 0
    while i//10 > 0:
        s += i%10
        if i//10 < 10:
            s += i//10
        i = i//10
    return s

sumab = float('inf')
for i in range(1,n):
    j = n - i
    tmp = sumNum(i) + sumNum(j)
    if tmp < sumab:
        sumab = tmp
print(sumab)

Submission status: Accepted

Solution code:
def F(N):
  return N if N < 10 else N % 10 + F(N // 10)

N = int(input())
x = F(N)
if x == 1:
  answer = 10
else:
  answer = x

print(answer)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
nList = []
for i in range(1, n // 2 + 1):
    aSum = 0
    bSum = 0
    for j in range(len(str(i))):
        aSum += int(str(i)[j])
    for j in range(len(str(n - i))):
        bSum += int(str(n - i)[j])
    nList.append(aSum + bSum)
print(min(nList))

Submission status: Accepted

Solution code:
n = int(input())
minab=10**20
for i in range(1,n//2+1):
    a = str(i)
    b = str(n-i)
    sumab=0
    for j in range(len(a)):
        sumab += int(a[j])
    for j in range(len(b)):
        sumab += int(b[j])
    minab = min(minab,sumab)
print(minab)

Submission status: Accepted

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

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

  while (a > 0) or (b > 0):
    sum += (a % 10)
    a = a // 10
    sum += (b % 10)
    b = b // 10

  if sum < ans:
    ans = sum

print(ans)

Submission status: Accepted

Solution code:
def SumOfDegit(x):
  sum = 0
  while x > 0:
    sum += x % 10
    x //= 10
  return sum
 
n = int(input())
degits_sum = []
for a in range(1,n):
  degits_sum.append(SumOfDegit(a) + SumOfDegit(n-a))
print(min(degits_sum))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
A - Digits Sum
https://atcoder.jp/contests/agc025/tasks/agc025_a

"""
import sys


def solve(N):
    def calc_dsum(a, b):
        a_sum = sum([int(ch) for ch in str(a)])
        b_sum = sum([int(ch) for ch in str(b)])
        return a_sum + b_sum

    ans = []
    for a in range(1, (N//2)+1):
        b = N - a
        ans.append(calc_dsum(a, b))
    return min(ans)


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
def findSumOfDigits(num):
  sum = 0
  while num > 0:
    sum += num % 10
    num //= 10
  return sum
  
if __name__ == '__main__':
  N = int(input())
  min_total = 1000
  for i in range(1, N):
    A = i
    B = N - A
    total = findSumOfDigits(A) + findSumOfDigits(B)
    if total < min_total:
      min_total = total
  print(min_total)

Submission status: Accepted

Solution code:
n = (input())
sai = []
x = list(map(int,list(n)))

if sum(x) == 1:
    n_sum = 10
else:
	n_sum = sum(x)

print(n_sum)

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())

minsum = 10**9
for i in range(1, N//2+1):
  j = N-i
  tmp = 0
  for s in str(i)+str(j):
    tmp += int(s)
  minsum = min(tmp, minsum)

print(minsum)

Submission status: Accepted

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

n = int(input())
degits_sum = []
for a in range(1,n):
  degits_sum.append(SumOfDegit(a) + SumOfDegit(n-a))
print(min(degits_sum))

Submission status: Accepted

Solution code:
n = int(input())

if n % 10 == 0:
    while n > 10:
        n = n // 10
    ans = n
else:
    num = str(n)
    x = 0
    for i in range(len(num)):
        x += int(num[i])
    ans = x

print(ans)

Submission status: Accepted

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

N, = map(int, input().split())

ans = 10 ** 18
for i in range(1, N):
    a = sum(map(int, list(str(i))))
    b = sum(map(int, list(str(N - i))))
    ans = min(ans, a + b)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

flg = 100
for i in range(1,n):
    a = n- i
    b = i
    sum_a = sum([int(x) for x in list(str(a))])
    sum_b = sum([int(x) for x in list(str(b))])
    if flg > sum_a + sum_b:
        flg = sum_a + sum_b

print(flg)

Submission status: Accepted

Solution code:
N=int(input())
ans=10**20
for a in range(1,N//2+2):
    b=N-a
    A=a
    B=b
    s=0
    while(A!=0):
        s+=A%10
        A//=10
    while(B!=0):
        s+=B%10
        B//=10
    ans=min(ans,s)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

sum_list = []
for a in range(1, n):
    b = n - a
    a_str = str(a)
    b_str = str(b)
    tmp = 0
    for a_s in a_str:
        tmp += int(a_s)
    for b_s in b_str:
        tmp += int(b_s)
    sum_list.append(tmp)

print(min(sum_list))

Submission status: Accepted

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

ans=10**5
for i in range(1,N):
    ans = min(ans,sum(map(int,str(i)))+sum(map(int,str(N-i))))

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

min_sum = float('inf')

for i in range (1, N):
    a = sumOfDegits(i)
    b = sumOfDegits(N-i)
    if min_sum > a + b:
        min_sum = a + b

print(min_sum)

Submission status: Accepted

Solution code:
n = int(input())
ans = 10**5 
for i in range(1,n//2+1):
    val = sum([int(item) for item in list(str(i))])
    val += sum([int(item) for item in list(str(n-i))])
    ans = min(ans, val)
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:
    print(sum(list(map(int, str(N)))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

def getsum(p):
  s=str(p)
  sum=0
  for i in range(len(s)):
    sum+=int(s[i])
  return sum

min=n
for a in range(1,n):
  b=n-a
  w=getsum(a)+getsum(b)
  if min>w:
    min=w
print(min)

Submission status: Accepted

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


N = int(input())

ans = float('inf')
for A in range(1, N // 2 + 1):
    B = N - A
    ans = min(ans, f(A) + f(B))
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
def cal(x):
    y=str(x)
    cnt=0
    for i in range(len(y)):
        cnt+=int(y[i])
    return cnt
min=999999999
for a in range(1,n//2+1):
    b=n-a
    if cal(a)+cal(b)<min:
        min=cal(a)+cal(b)
print(min)

Submission status: Accepted

Solution code:
N = int(input())


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


print(min([fsod(A) + fsod(N-A) for A in range(1, N // 2 + 1)]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
print(10 if N % 10 == 0 else sum(int(s) for s in str(N)))

Submission status: Accepted

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

N = int(input())
mi = 1e10
for i in range(1, N):
    mi = min(mi, digit_sum(i) + digit_sum(N - i))
print(mi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
  
def digit_sum(N):
  ret = 0
  while N:
    ret += N%10
    N = N//10
  return ret

answer = 1e9
for i in range(1,N):
  answer = min(answer, digit_sum(i)+digit_sum(N-i))
  
print(answer)

Submission status: Accepted

Solution code:
nl = list(map(int, input()))
if len(nl) == 1:
    print(nl[0])
elif all([e == 0 for e in nl[1:]]):
    print(10)
else:
    print(sum(nl))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
ans=sum(int(i) for i in str(n))
while n%10==0:
  n//=10
print(10 if n==1 else ans)

Submission status: Accepted

Solution code:
A = int(input()) - 1
B = 1
o = 100000

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

while A >= 1:
    o = min(digitsum(A)+digitsum(B),o)
    A-=1
    B+=1

print(o)

Submission status: Accepted

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

n=int(input())
ans=[]
for i in range(1,n):
    ans.append(wa(i)+wa(n-i)) 
print(min(ans))

Submission status: Accepted

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

n=int(input())
ans=[]
for i in range(1,n):
    ans.append(wa(i)+wa(n-i)) 
    if wa(i)+wa(n-i)==1:
        print(i)
print(min(ans))

Submission status: Accepted

Solution code:
inf = 10**10

n = int(input())
ans = inf
def f(x):
    cur = 0
    while x >0:
        cur += x % 10
        x = x //10
    return cur
for a in range(1,n):
    b = n-a
    ans = min(ans,f(a)+f(b))
print(ans)

Submission status: Accepted

Solution code:
def digitsum(num):
  s=str(num)
  ret=0
  for i in range(len(s)):
    ret+=int(s[i])
  return ret

n=int(input())
arr=[digitsum(i)+digitsum(n-i) for i in range(1,n//2+1)]
print(min(arr))

Submission status: Accepted

Solution code:
N = int(input())

ns = []
while (N != 0):
    ns.append(N % 10)
    N //= 10
if sum(ns) == 1:
    ans = 10
else:
    ans = sum(ns)

print(ans)

Submission status: Accepted

Solution code:
a=input()

al=[int(c) for c in list(str(a))]

sal=sum(al)
ret= sal if sal > 1 else 10
print(ret)

Submission status: Accepted

Solution code:
N = int(input())

def digit_sum(n):
    return sum([int(s) for s in str(n)])

digit_sums = []
for a in range(1, N):
    b = N - a
    digit_sums.append(digit_sum(a) + digit_sum(b))

print(min(digit_sums))

Submission status: Accepted

Solution code:
n = int(input())

min_num = 10**9
for a in range(1,n):
    b = n-a
    a_s = sum(list(map(lambda x: int(x), str(a))))
    b_s = sum(list(map(lambda x: int(x), str(b))))
    num = a_s+b_s
    min_num = min(num, min_num)

print(min_num)

Submission status: Accepted

Solution code:
N = 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:
def sumdigit(m):
    s=str(m)
    array=list(map(int,s))
    return sum(array)
ans=9999
N=int(input())
for i in range(1,N):
    r=N-i
    if sumdigit(i)+sumdigit(r)<ans:
        ans=sumdigit(i)+sumdigit(r)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
ans=0
for i in range(1,N):
    j=N-i
    i_s=sum(map(int,list(str(i))))
    j_s=sum(map(int,list(str(j))))
    S=i_s+j_s
    if ans==0:
        ans=S
    else:
        if S<ans:
            ans=S
        else:
            continue

print(ans)

Submission status: Accepted

Solution code:
n = input()
result = 0

if int(n)%10 == 0:
    result = 10
else:
    result = sum(int(i) for i in n)

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n = int(input())
ns = list(str(n))
if(math.log10(n) == float(len(ns)-1)) : print(10)
else : print(sum([int(ns[i]) for i in range(len(ns))]))

Submission status: Accepted

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



n=int(input())

min=100000

for i in range(n):
    if i==0:
        continue
    sub=n-i
    sub=sum(sub)
    i=sum(i)
    #subとiの各桁の和を足す
    if min>sub+i:
        min=sub+i
print(min)

Submission status: Accepted

Solution code:
N=int(input())

min_=100000

for i in range(1, N//2+1):
    j=N-i
    sum_i=0
    sum_j=0
    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: Accepted

Solution code:
n=int(input())
ans=10**5
for a in range(1,n//2+1):
  b=n-a
  ans=min(ans,a%10+a//10%10+a//100%10+a//1000%10+a//10000%10+b%10+b//10%10+b//100%10+b//1000%10+b//10000%10)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
minimum = 10**5
for i in range(1,-(-N//2)+1):
    A = i
    B = N - i
    total = 0
    for _ in range(6):
        total += A % 10 + B % 10
        A //= 10
        B //= 10
    if total < minimum:
        minimum = total
print(minimum)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input())

min_count = 10**10

for i in range(1,N):
    A = i
    B = N-i
    count = 0
    for a in str(A):
        count += int(a)
    for b in str(B):
        count += int(b)
    min_count = min(min_count, count)

print(min_count)

Submission status: Accepted

Solution code:
NL = [int(x) for x in str(input())]
if NL[0] == 1 and sum(NL) == 1:
    print(10)
else:
    print(sum(NL))

Submission status: Accepted

Solution code:
N = int(input())
def sumof(N):
  sum = 0
  while(N>0):
    sum += N % 10
    N //= 10
  return sum

minsum = 9*10
for i in range(1,N//2+1):
  minsum = min(minsum,sumof(i) + sumof(N-i))
print(minsum)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
ans = np.Inf

for i in range(1,int(n/2+1)):
    a = str(i)
    b = str(n - i)
    an = 0
    for j in range(len(a)):
        an += int(a[j])
    for k in range(len(b)):
        an += int(b[k])
    if an < ans:
        ans = an
print(ans)

Submission status: Accepted

Solution code:
def dsum(n):
    ret = 0
    while n > 0:
        ret += n % 10
        n //= 10
    return ret
n = int(input())
ans = 10**7
for i in range(1, n//2+1):
    ans = min(ans, dsum(i) + dsum(n-i))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
c = 100000000000000000
for i in range(1,int(n/2)+2):
    a = list(str(i))
    b = list(str(n-i))
    a1 = [int(s) for s in a]
    b1 = [int(s) for s in b]
    if sum(a1) + sum(b1) < c:
        c = sum(a1) + sum(b1)

print(c)

Submission status: Accepted

Solution code:
n = int(input())
ans = pow(10, 15)
for a in range(1, n):
  b = n - a
  adg, bdg = 0, 0
  while a != 0:
    adg += a % 10
    a //= 10
  while b != 0:
    bdg += b % 10
    b //= 10
  if ans > adg + bdg:
    ans = adg + bdg
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
best = 10**9
for a in range(1, N):
    b = N - a
    s = sum(int(c) for c in str(a)) + sum(int(c) for c in str(b))
    if s < best:
        best = s
print(best)

Submission status: Accepted

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


def simulate(m):
    for a in range(1, m):
        global ans
        sum_a = sum([int(i) for i in str(a)])
        sum_b = sum([int(i) for i in str(N-a)])
        if sum_a + sum_b < ans:
            ans = sum_a + sum_b


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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
factor_a = []
factor_b = []
ans = N
for a in range(1, N):
    sum_a = sum([int(i) for i in str(a)])
    sum_b = sum([int(i) for i in str(N-a)])
    if sum_a + sum_b < ans:
        ans = sum_a + sum_b
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
m = float("inf")
 
for A in range(1,N):
  summ = 0
  B = N-A
  
  while A >0:
    summ += A%10
    A //=10
  while B >0:
    summ += B%10
    B//=10
  if summ < m:
    m = summ

print(m)

Submission status: Accepted

Solution code:
def digits(N):
    num = N
    sum = 0
    while num > 0:
        sum += num%10
        num //= 10
    return sum
    
def main():
    N = int(input())
    min = N
    for A in range(1,(N//2+1)):
        B = N - A
        if min > digits(A)+digits(B):
            min = digits(A)+digits(B)
    print(min)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input());minn=100
def digit_sum(x):
  a,b=0,str(x)
  for i in range(len(b)):a+=int(b[i])
  return a
for i in range(1,n//2+1):a=digit_sum(i)+digit_sum(n-i);minn=min(minn,a)
print(minn)

Submission status: Accepted

Solution code:
n =int(input())

ans = float("inf")

for i in range(1,int(n/2)+1):
    a = format(i,"05d")
    b = format(n-i,"05d")
    sm = 0
    for aa,bb in zip(a,b):
        sm += int(aa) + int(bb)
    if ans  >  sm:
        ans = sm
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

def SumOfDigits(n):
	ans=0
	while(True):
		if n==0:
			break
		ans+=n%10
		n=n//10
	return ans

ans=N
for a in range(N):
	if a!=0:
		b=N-a
		if ans>SumOfDigits(a)+SumOfDigits(b):
			ans=SumOfDigits(a)+SumOfDigits(b)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = []

def kakui(X):
    x = [0] * 6
    for i in [5,4,3,2,1,0]:
        x[i] = X // (10**i)
        X = X % (10**i)
    return(x)
def sum(x):
    sum = 0
    for i in range(6):
        sum += x[i]
    return sum

for A in range(1, N):
    B = N - A
    
    S.append(sum(kakui(A))+sum(kakui(B)))
print(min(S))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = []

a = [0] * 6
for A in range(1, N):
    realA = A
    for i in [5,4,3,2,1,0]:
       a[i] = A // (10**i)
       A = A % (10**i)
       
    b = [0] * 6
    B = N - realA
    for i in [5,4,3,2,1,0]:
        b[i] = B // (10**i)
        B = B % (10**i)
        
    def sum(x):
        sum = 0
        for i in range(6):
            sum += x[i]
        return sum
    S.append(sum(a)+sum(b))
print(min(S))

Submission status: Accepted

Solution code:
n=int(input())
def num(x):
  rec=0
  while x>0:
    rec+=x%10
    x//=10
  return rec
ans=10**18
for i in range(1,(n+3)//2):
  ans=min(ans,num(i)+num(n-i))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = float('inf')
for a in range(1, n):
    num = 0
    b = n - a
    if b < a:
        break
    while a:
        num += a % 10
        a = a // 10
    while b:
        num += b % 10
        b = b // 10
    ans = min(ans, num)

print(ans)

Submission status: Accepted

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


def main():
    n = input()
    ans = float('inf')

    for i in range(1, int(n)):
        a = i
        b = int(n) - i
        summed_a = sum(list(map(int, list(str(a)))))
        summed_b = sum(list(map(int, list(str(b)))))
        ans = min(ans, summed_a + summed_b)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
ans = 999
for a in range(1,N):
    b = N-a
    tmp = sum(int(c) for c in str(a)) + sum(int(c) for c in str(b))
    ans = min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = input()
N = np.array([int(k) for k in N])
if N[-1] == 0:
  print(10)
else:
  print(N.sum())

Submission status: Accepted

Solution code:
#AGC025 A
'''
問題
AとBは自然数とする
AとBの各桁の数の和をSA，SBとする
和がNであるとわかっているとき，SA＋SBの最小値は？

Nは2以上10000以下

考察
最大でもループは10000以下なのでしらみつぶせばよい
'''

N = int(input())

def dsum(n):
	return sum([int(x) for x in list(str(n))])

result = []

for i in range(1,(N//2)+1):
	result.append(dsum(i)+dsum(N-i))

print(min(result))

Submission status: Accepted

Solution code:
N = int(input())

def gen(n):
  if n < 10:
    yield n
  else:
    for m in gen(n//10):
      yield m
    yield n%10

digit_sum = sum(gen(N))
if(digit_sum==1):
    print(10)
else:
    print(digit_sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = 10**9

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

Submission status: Accepted

Solution code:
N = int(input())

min_n = 10**9

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

    a = sum(list(map(int, str(A))))
    b = sum(list(map(int, str(B))))

    min_n = min(min_n, a+b)


print(min_n)

Submission status: Accepted

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

def f(x):
    s = 0
    while x != 0:
        s += x % 10
        x = x//10
    return s

n = int(input())
res = 10**9
for i in range(1,n):
    res = min(res,f(i)+f(n-i))
print(res)

Submission status: Accepted

Solution code:
N = int(input())

def digSum(n):
  return sum(map(int, str(n)))

A = list(range(1,N//2+1))
B = list(range(N-1,N//2-1,-1))
ans = 1e9
for a, b in zip(A, B):
  #a, b
  ans = min(ans, digSum(a)+digSum(b))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ans = 10**9

def ketawa(b):
  if b < 10:
    return b
  return ketawa(b//10) + b%10

for i in range(1, N):
  tmp = ketawa(i) + ketawa(N-i)
  if tmp < ans:
    ans = tmp
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

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

ans=100000000000
for i in range(1,n):
    ans=min(ans,f(i)+f(n-i))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

ans = float('inf')
for a in range(1, N // 2 + 1):
    b = N - a

    t = 0
    while a > 0:
        a, r = divmod(a, 10)
        t += r

    while b > 0:
        b, r = divmod(b, 10)
        t += r

    ans = min(t, ans)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=10e6
for i in range(1,N//2+1):
  A=i;B=N-i
  numA=sum([int(i) for i in list(str(A))])
  numB=sum([int(i) for i in list(str(B))])
  a=min(numA+numB,a)
print(a)

Submission status: Accepted

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

print(min)

Submission status: Accepted

Solution code:
n = int(input())
ans = []
for i in range(1,n):
    j = n-i
    si = 0
    sj = 0
    for s in str(i):
        si += int(s)
    for t in str(j):
        sj += int(t)
    ans.append(si+sj)

print(min(ans))

Submission status: Accepted

Solution code:
import scipy as sp

def sum_of_digits(n):
    answer = 0
    while True:
        if n == 0:
            break
        else:
            answer += n%10
            n = n // 10
    return answer
     

N = int(input())
answer = N 
for a in sp.arange(1, N//2+1):
  b = N - a
  sum = sum_of_digits(a) + sum_of_digits(b)
  if sum < answer:
    answer = sum
         
     
print(answer)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 12 15:50:41 2019

@author: shinjisu
"""

#import numpy as np
#import math
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]

def zeros(n): return [0]*n
def zeros2(n, m): return [zeros(m)]*n # obsoleted zeros((n, m))で代替

def getIntLines(n): return [int(input()) for i in range(n)]

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18


class Debug():
    def __init__(self):
        self.debug = True

    def off(self):
        self.debug = False

    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


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


def prob():
    d = Debug()
    d.off()
    N = getInt()
    minSum = INF
    for i in range(1, N//2+1):
        minSum = min(minSum, digitSum(i)+digitSum(N-i))
#        d.dmp(minSum)
    return minSum


ans = prob()
if ans is None:
    pass
else:
    print(ans)
#elif ans[0] == 'col':
#    for elm in ans[1]:
#        print(elm)