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())
min_sum = 99999999999999
if n == 2 :
  print (2)
  exit()
for i in range (1, n - 1):
  first = i
  second = n - i
  first_sum = 0
  second_sum = 0
  while first > 0 :
    last_digit_first = first % 10
    first = first // 10
    first_sum += last_digit_first
    
  while second > 0 :
    last_digit_second = second % 10
    second = second // 10
    second_sum += last_digit_second
  
  if first_sum + second_sum <= min_sum :
    min_sum = first_sum + second_sum
print(min_sum)

Submission status: Accepted

Solution code:
N = int(input())
temp_min = sum(map(int, str(1))) + sum(map(int, str(N - 1)))
for A in range (2, N):
    x = sum(map(int, str(A))) + sum(map(int, str(N - A)))
    if x < temp_min:
        temp_min = x
print(temp_min)

Submission status: Accepted

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

Submission status: Accepted

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

N=int(input())
ans=100
for i in range(1,N):
    tmp=dig_sum(i)+dig_sum(N-i)
    if tmp<ans:
        ans=tmp
print(ans)

Submission status: Accepted

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

    ans = 100000

    for i in range(1, N):
        tmp = sum(map(int, str(i)))
        tmp += sum(map(int, str(N-i)))
        if tmp < ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input())

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

print(Min)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

def ketawa(x):
	return sum(map(int, list(str(x))))

N = INT()

ans = INF
for a in range(1, N//2 + 1):
	b = N-a
	ans = min(ans, ketawa(a) + ketawa(b))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = n
for i in range(n // 2):
  j = i + 1
  k = n - j
  sumj = []
  sumk = []
  for l in range(len(str(j))):
    strj = str(j)
    sumj.append(int(strj[l]))
    
  for l in range(len(str(k))):
    strk = str(k)
    sumk.append(int(strk[l]))
  if sum(sumj) + sum(sumk) < ans:
    ans = sum(sumj) + sum(sumk)
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:
    x = str(n)
    a = list(x)
    b = sum([int(i) for i in a])
    print(b)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
list_candi = []
for A in range(1, N):
  B = N - A
  list_A = list(map(int, list(str(A))))
  list_B = list(map(int, list(str(B))))
  sum_list= sum(list_A) + sum(list_B)
  list_candi.append(sum_list)
print(min(list_candi))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()

ans = INF
for i in range(1, N//2 + 1):
	j = N - i
	tmp = sum([int(x) for x in list(str(i))]) + sum([int(x) for x in list(str(j))])
	ans = min(ans, tmp)

print(ans)

Submission status: Accepted

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

def main():
    N = int(input())
    ret = 10**9
    for a in range(1,N):
        b = N-a
        ret = min(ret,sum(map(int,list(str(a))))+sum(map(int,list(str(b)))))

    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N = int(input())
if math.log10(N)%1 != 0:
  K = str(N)
  ans = 0
  for i in range(len(K)):
    ans += int(K[i])
  print(ans)
else:
  print(10)

Submission status: Accepted

Solution code:
N = int(input())

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

ans = 0

for i in range(1, N):
    j = SumOfDigits(i) + SumOfDigits(N-i)
    if ans > j:
        ans = j
    elif ans == 0:
        ans = j
    else:
        pass

print(ans)

Submission status: Accepted

Solution code:
N = list(input())
if int(''.join(N))%10 != 0:
    res = 0
    for i in range(len(N)):
        res += int(N[i])
else:
    res = 10
print(res)

Submission status: Accepted

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


N = int(input())

answer = None

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

    C = calc(A) + calc(B)

    if answer is None or answer > C:
        answer = C

print(answer)

Submission status: Accepted

Solution code:
N = int(input())

MIN = 100000000000000
for i in range(1,N):
  A = sum(map(int,list(str(i))))
  B = sum(map(int,list(str(N-i))))
  MIN = min(A+B,MIN)
  
print(MIN)

Submission status: Accepted

Solution code:
n = int(input())
ans = 10 ** 5
for a in range(1, n):
    ak = sum([int(a) for a in str(a)])
    bk = sum([int(b) for b in str(n - a)])
    if ans > ak + bk:
        ans = ak + bk
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    ans = float("inf")

    for a in range(1, N):
        b = N - a
        tmp = 0
        for s in str(a):
            tmp += int(s)
        for s in str(b):
            tmp += int(s)

        ans = min(ans, tmp)

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n = ri()
l = len(str(n)) - 1
if n % 10**l == 0:
    if str(n)[0] == '1':
        print(10)
    else:
        ans = 0
        for i in str(n):
            ans += int(i)
        print(ans) 
else:
    ans = 0
    for i in str(n):
        ans += int(i)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n//2):
    x = i+1
    y = str(n-x)
    x = str(x)
    z = 0

    for c in x:
        z += int(c)
    for c in y:
        z += int(c)
    
    if z < ans:
        ans = z

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
ans=0
if 10**(len(str(n))-1)==n:
    ans=10
else:
    listn=list(str(n))
    for i in range(len(listn)):
        ans+=int(listn[i])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
ans=9999999999999
for i in range(1,int(n/2)+1):
  tempa=list(str(i))
  tempb=list(str(n-i))
  s=0
  for j in range(len(tempa)):
    s=s+int(tempa[j])
  for j in range(len(tempb)):
    s=s+int(tempb[j])
  ans=min(ans,s)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
def f(i):
  return sum([int(j) for j in str(i)])
ans = float('inf')
for A in range(1, N):
  B = N - A
  ans = min(ans, f(A) + f(B))
print(ans)

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())


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


a = 10**5
for i in range(1, n):
    j = n-i
    tmp = func(i)+func(j)
    a = min(tmp, a)
print(a)

Submission status: Accepted

Solution code:
n = int(input())

digis_sum = 10 ** 2

def cal_digit(num):
    tmp = 0
    q = num
    while q:
        q, r = divmod(q, 10)
        tmp += r
        if q == 0:
            break
    return tmp

for x in range(1, int(n/2)+1):
    y = n - x
    t = cal_digit(x) + cal_digit(y)
    if t < digis_sum:
        digis_sum = t

print(digis_sum)

Submission status: Accepted

Solution code:
n = input()
n_ = n.replace('0','')
if n_ == '1':
  print(10)
else:
  a = 0
  for s in n:
    a += int(s)
  print(a)

Submission status: Accepted

Solution code:
N = int(input())
min = 100000000000000
for i in range(1, N):
  A = str(i)
  B = str(N - i)
  ref = 0
  for a in A:
    ref += int(a)
  for b in B:
    ref += int(b)
  if ref < min:
    min = ref
print(min)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
ans = float('inf')
for i in range(1, N):
    x = sum(int(c) for c in str(i))
    y = sum(int(c) for c in str(N-i))
    tmp = x + y
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = []

def each_sum(x):
    y = str(x)
    ans = 0
    for i in range(len(y)):
        ans += int(y[i])
    return ans

for a in range(1, n):
    b = n - a
    l.append(each_sum(a) + each_sum(b))

print(min(l))

Submission status: Accepted

Solution code:

def sum_N(a:int):
    sum = 0
    while a > 0:
        sum += a % 10
        a = a // 10
    return sum

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

Submission status: Accepted

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

for x in range(1, N // 2 + 1):
    SUM = 0
    A = x
    B = N - x
    while A > 0 or B > 0:
        SUM += A % 10 + B % 10
        A //= 10
        B //= 10
    if ans > SUM:
        ans = SUM

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

min = n

def digits_sum(x):
    _x = 0
    while x > 0:
        _x += x % 10
        x //= 10
    
    return _x


for i in range(2, n):
    a = i
    b = n - i
    if digits_sum(a) + digits_sum(b) < min:
        min = digits_sum(a) + digits_sum(b)

print(min)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getter(i):
  res=0
  while True:
    res+=i%10
    i//=10
    if i==0:
      break
  return res
n=int(input())
digit=0
hoge=n
while True:
  hoge//=10
  if hoge==0:
  	break
  digit+=1
a=10**digit
if n-a>0:
  res=1+getter(n-a)
  print(res)
  exit()
else:
  print("10")

Submission status: Accepted

Solution code:
n = int(input())

def dig(num):
    ans = 0
    while num>0:
        ans += num%10
        num//=10
    return ans

mi = float('inf')
for i in range(1,n//2+1):
    a = dig(i)+dig(n-i)
    mi = min(a,mi)
print(mi)

Submission status: Accepted

Solution code:
n = int(input())

if n % 10:
    ans = 0
    while n > 0:
        ans += n % 10
        n = n //10
    print(ans)
else:
    print(10)

Submission status: Accepted

Solution code:
N = int(input())
if N % 10 == 0:
  print(10)
else:
  ls = list(str(N))
  for i in range(len(ls)):
    ls[i] = int(ls[i])
  print(sum(ls))

Submission status: Accepted

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

n = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    N = int(input().rstrip())
    ANS = INF
    for i in range(1,N):
        ANS = min(ANS,sum(list(map(int, str(i)))) + sum(list(map(int, str(N - i)))))
    print(ANS)    

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())

A = str(N//2)
B = str(N-int(A))

ans1,ans2 = 0,1
for i in range(len(A)):
  ans1 += int(A[i])
for i in range(len(B)):
  ans1 += int(B[i])

B = str(N-1)

for i in range(len(B)):
  ans2 += int(B[i])

ans = min(ans1,ans2)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())

ans=10**5
for a in range(1,n):
  b=n-a
  aa=list(str(a))
  bb=list(str(b))
  tmp=0
  for k in (aa+bb):
    tmp+=int(k)
  ans=min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
if n%10==0:
    print(10)
else:
    print(sum(map(int,list(str(n)))))

Submission status: Accepted

Solution code:
ans=999999999
n = int(input())
for i in range(1,n//2+1):
    x=str(i)
    y=str(n-i)
    ans=min(ans, sum(map(int, x))+sum(map(int, y)))
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(input())
min = 1000000000

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

Submission status: Accepted

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


N = int(input())
ans = float('inf')
for A in range(1, N):
    B = N - A
    if A > B:
        break
    ans = min(ans, split_sum(A) + split_sum(B))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

def keta(num):
    s = str(num)
    sm=0
    for i in range(len(s)):
        sm+=int(s[i])
    return sm

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = float("inf")
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:
# A - Digits Sum

N = input()
N_int = int(N)
mylist = ['10','100','1000','10000','100000']
ans = 0

if N in mylist:
    ans = 10
else:
    for i in range(len(N)):
        ans += (N_int % 10)
        N_int = N_int // 10

print(ans)

Submission status: Accepted

Solution code:
def calc(x) -> int:
  sum = 0
  while x//10!=0:
    sum += x%10
    x = x//10
  sum+=x
  return sum


n = int(input())
best_score = float('inf')
for a in range(1,n):
  b = n-a
  score = calc(a)+calc(b)
  if score < best_score:
    best_score = score
print(best_score)

Submission status: Accepted

Solution code:
n = int(input())

l = []
for i in range(1, n):
    a = i
    b = n - i
    ra = 0
    rb = 0

    flg = True
    while flg:
        aa = a % 10
        a //= 10
        ra += aa
        if a == 0:
            flg = False
    flg = True
    while flg:
        bb = b % 10
        b //= 10
        rb += bb
        if b == 0:
            flg = False
    l.append(ra+rb)
print(min(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
candi = []
for i in range(1,int(n/2+1)):
  j = n - i
  candi.append([i,j])

#candi = [[2, 13], [3, 12], [4, 11], [5, 10], [6, 9], [7, 8]]

ans = 0
for a,b in candi:
  count = 0
  a = str(a)
  b = str(b)
  for i in a:
    count += int(i)
  for i in b:
    count += int(i)
  if ans == 0 :
    ans = count
  ans = min(ans,count)

print(ans)

Submission status: Accepted

Solution code:
from math import ceil
N = int(input())
result = 10 ** 6
for i in range(1, ceil(N / 2) + 1):
  a = str(i)
  b = str(N - i)
  result = min(result, sum(map(int, a)) + sum(map(int, b)))
print(result)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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


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

    res = f_inf
    for a in range(1, n):
        b = n - a
        cnt = digit_sum(a) + digit_sum(b)
        res = min(res, cnt)

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
n = 1e5
for i in range(1, N):
    A = i
    B = N - A
    s = 0
    while A > 0:
        s += A % 10
        A = int(A / 10)
    while B > 0:
        s += B % 10
        B = int(B / 10)
    n = min(n, s)
print(n)

Submission status: Accepted

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

    minSum = 10**18

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

        sumA = 0
        sumB = 0

        for digit in str(a):
            sumA += int(digit)
        
        for digit in str(b):
            sumB += int(digit)
        
        total = sumA + sumB
        
        if total < minSum:
            minSum = total
    
    print(minSum)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    results=[]
    for i in range(1,N):
        results.append(sum(map(int,str(i)))+sum(map(int,str(N-i))))
    print(min(results))
    


resolve()

Submission status: Accepted

Solution code:
def resolve():
    N=int(input())
    s=str(N)
    val=0
    for i in s:
        val+=int(i)
    print(10 if N in [10, 100, 1000,1000,10000,100000] else val)
    


resolve()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    ans=10**18
    for i in range(1,n):
        x=sum([int(j) for j in str(i)])+sum([int(j) for j in str(n-i)])
        ans=min(ans,x)
    print(ans)
resolve()

Submission status: Accepted

Solution code:
# 記録
N = int(input())
results = []
for i in range(1,N):
    results.append(sum(map(int,str(i))) + sum(map(int,str(N-i))))
print(min(results))

Submission status: Accepted

Solution code:
N = int(input())
results = ''
for A in range(N + 1):
    if A == 0:
        continue

    BBB = []
    AAA = []

    B = N - A
    if B >= 1:
        for b in range(len(str(B))):
            BBB.append(int(str(B)[b]))

        for a in range(len(str(A))):
            AAA.append(int(str(A)[a]))
        sums = sum(BBB) + sum(AAA)
        if sums == 1:
            print(A)
            print(B)
            print(AAA)
            print(BBB)

        if not results:
            results = sums
        else:
            if results > sums:
                results = sums
print(results)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
N = n//2
ans = float("INF")
for i in range(1,N+1):
  a,b = list(str(i)), list(str(n-i))
  A,B = sum(list(map(int, a))), sum(list(map(int, b)))
  if ans > A+B: ans = A+B
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
ans=100000
for a in range(1,n):##正
    b=n-a
    suma=sum(list(map(int, list(str(a)))))
    sumb=sum(list(map(int, list(str(b)))))
    
    ans=min(ans,sumb+suma)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

ans = 10000000

for i in range(1,n//2+2):
    memo = 0
    first = str(i)
    second = str(n-i)
    for j in first:
        memo += int(j)
    for j in second:
        memo += int(j)
    ans = min(memo,ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

total = []
for i in range(1, N):
    x = sum(list(map(int, str(i)))) + sum(list(map(int, str(N - i))))
    total.append(x)

print(min(total))

Submission status: Accepted

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

for A in range(1, N):
    B = N - A
    A = str(A)
    B = str(B)
    A_sum = sum(list(map(int, A)))
    B_sum = sum(list(map(int, B)))
    result.append(A_sum + B_sum)

print(min(result))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    ans = float("inf")
    for A in range(1, N):
        B = N - A
        total = sum(int(s) for s in str(A)) + sum(int(s) for s in str(B))
        if total < ans:
            ans = total

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

N = int(input())

if N in [10**i for i in range(1, 6)] :
    print("10")
else :
    print(sum(map(int, str(N))))

Submission status: Accepted

Solution code:
n = input()
if int(n) in [10 ** i for i in range(1, 6)]:
  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())

cdt = None
for a in range(1, N):
    b = N - a
    x = sum([int(c) for c in str(a)]) + sum([int(c) for c in str(b)])
    if cdt is None or cdt > x:
        cdt = x
print(cdt)

Submission status: Accepted

Solution code:
n = int(input())
if n % 10 == 0:
  print(10)
else:
  result = sum(list(map(int, str(n))))
  print(result)

Submission status: Accepted

Solution code:
import math
def digsum(A):
  n = math.floor(math.log10(A))
  tmp = 0
  for i in range(n,0,-1):
    tmp += A // (10**i)
    A = A % (10**i)
  return tmp + A
  
N = int(input())
ans = 10**9
for i in range(1,N//2+1):
  ans = min(ans, digsum(i) + digsum(N-i))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
sum_min = 100000
for i in range(1,n):
    i_sum = 0; j_sum = 0
    j = n-i
    i = str(i); j = str(j)
    for k in range(len(i)):
        i_sum += int(i[k])
    for k in range(len(j)):
        j_sum += int(j[k])
    tmp_sum  = i_sum + j_sum
    if sum_min >tmp_sum :
        sum_min = tmp_sum
print(sum_min)

Submission status: Accepted

Solution code:
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b, c = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    re = 1000
    for a in range(1, (n//2)+1):
        b = n - a
        sumnum = 0
        while a >= 1:
            sumnum += a % 10
            a = a //10
        while b >= 1:
            sumnum += b % 10
            b = b //10
        if re > sumnum:
            re = sumnum

    print(re)
resolve()

Submission status: Accepted

Solution code:
n = int(input())
mn = float("inf")
for i in range(1,n):
  if sum(map(int,str(i))) + sum(map(int,str(n-i))) < mn:
    mn = sum(map(int,str(i))) + sum(map(int,str(n-i)))
print(mn)

Submission status: Accepted

Solution code:
from sys import stdin


def find_sum_of_digits(n, base=10):
    _sum = 0
    while n>0:
        _sum += n%base
        n //= base
    return _sum


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = float('inf')
    for A in range(1,N):
        B = N-A
        sum_ = find_sum_of_digits(A)+find_sum_of_digits(B)
        cnt = min(cnt,sum_)
    ## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

Solution code:
ans=float("INF")
n=int(input())

s=0
for i in range(1,n//2+1):
  ans=min(sum(list(map(int,list(str(i)))))+sum(list(map(int,list(str(n-i))))),ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 100
for i in range(1, N // 2 + 1):
  A = str(i)
  B = str(N - i)
  t = 0
  for j in A:
    t += int(j)
  for j in B:
    t += int(j)
  ans = min(ans, t)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
total=10*100

def sum_digits(num):
    sum = 0
    while True:
        if num == 0:
            break
        sum += num%10
        num //= 10
    return sum

for a in range(1, n):
    b = n - a
    total = min(total, sum_digits(a)+sum_digits(b))

print(total)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=input()
    ans=0
    if int(n)%10!=0:
        for i in range(len(n)):
            ans+=int(n[i])
    else:
        ans=10
    print(ans)
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = 0
b = n
total = []

def digitSum(number):
    sum = 0
    while number > 0:
        sum += number % 10
        number //= 10
    return sum

for i in range(1, n + 1):
    a = i
    b = n - a
    if b < a:
        break
    total.append(digitSum(a) + digitSum(b))
print(min(total))

Submission status: Accepted

Solution code:
def digitsum(N): # intで渡す
    return sum(int(s) for s in str(N))
ans=INF=9*10
N=int(input())
for a in range(1,N):
    b=N-a
    ans=min(digitsum(a)+digitsum(b),ans)
print(ans)

Submission status: Accepted

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

for i in range(1,N):
  j = N-i
  ist = str(i)
  jst = str(j)
  iarray = list(map(int ,ist))
  jarray = list(map(int ,jst))
  isum = sum(iarray)
  jsum = sum(jarray)
  if isum + jsum < ans:
    ans = isum + jsum
print(ans)

Submission status: Accepted

Solution code:
n = input()
total = 0
for digit in n:
  total += int(digit)
if total == 1:
  print(10)
else:
  print(total)

Submission status: Accepted

Solution code:
n = int(input())

minv = 1 << 30

def digit_sum(n):
	lst = list(map(int, str(n)))
	return sum(lst)

for i in range(1, n//2 + 1):
	a = i
	b = n - i
	minv = min(digit_sum(a) + digit_sum(b), minv)

print(minv)

Submission status: Accepted

Solution code:
# AGC 025: A – Digits Sum
N = int(input())
n = N // 2 if N % 2 == 0 else N // 2 + 1
min_sum = 9999

for i in range(1, n + 1):
    sum_digits = 0
    A = i
    B = N - i

    while A != 0:
        sum_digits += A % 10
        A //= 10
    
    while B != 0:
        sum_digits += B % 10
        B //= 10
        
    min_sum = min(min_sum, sum_digits)

print(min_sum)

Submission status: Accepted

Solution code:
n = int(input())
mn = float("inf")
for i in range(1,n):
  count = 0
  for s in str(i):
    count += int(s)
  for p in str(n-i):
    count += int(p)
  if count < mn:
    mn = count
print(mn)

Submission status: Accepted

Solution code:
def f(x):
    return x%10+f(x//10) if x else 0
n = int(input())
print(min([f(i)+f(n-i) for i in range(1,n)]))