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:
# %% AGC 025 A


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


n = int(input())
mn = n
for i in range(1, n):
    b = n - i
    mn = min(sumOfDigits(i) + sumOfDigits(b), mn)

print(mn)

Submission status: Accepted

Solution code:
n = int(input())

s = []
for i in range(1, n):
    j = n - i
    if i + j == n:
        a = sum(map(int, str(i)))
        b = sum(map(int, str(j)))
        s.append(a + b)
print(min(s))

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


def digsum(num):
    ans = 0
    while num > 0:
        p, q = divmod(num, 10)
        num = p
        ans += q
    return ans

N = I()
ans = INF
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())


def digit_sum(num):
    ret = 0
    s = str(num)
    for e in s:
        ret += int(e)

    return ret


ans = float("inf")
for a in range(1, n):
    b = n - a
    ds = digit_sum(a) + digit_sum(b)
    ans = min(ans, ds)

print(ans)

Submission status: Accepted

Solution code:
import sys
import math

def minSum(n):
    min_sum = 0
    for i in range(1, n):
        a = i
        b = n - i
        min_sum_a, min_sum_b = 0, 0
        while  a > 0:
            min_sum_a += a%10
            a = math.floor(a/10)
        while b > 0:
            min_sum_b += b%10
            b = math.floor(b/10)
        
        if i == 1:
            min_sum = min_sum_a + min_sum_b
        else:
            if min_sum > min_sum_a + min_sum_b:
                min_sum = min_sum_a + min_sum_b
    return min_sum

n = int(input())

print("{}".format(minSum(n)))

Submission status: Accepted

Solution code:
n = int(input());A = [] ; s = 0 ; t = 0

for i in range(1,n):
    for j in range(len(str(i))):
        s += int(str(i)[j])
    for k in range(len(str(n-i))):
        t += int(str(n-i)[k])
    a = s + t
    A.append(a)
    s = 0 ; t = 0
    
print(min(A))

Submission status: Accepted

Solution code:
N = int(input())

def _sum(s):
    result = 0
    S = str(s)
    for i in range(len(S)):
        result += int(S[i])

    return result

ans = 10**6
for A in range(1,N):
    B = N-A
    tmp = _sum(A)+_sum(B)
    if (tmp < ans):
        ans = tmp

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    ab_sum = int(input())
    answer = float("inf")
    for i in range(1, ab_sum // 2):
        answer = min(answer, get_digit_sum(i) + get_digit_sum(ab_sum - i))
    print(answer if ab_sum > 3 else 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = 0
b = 0
ans = 10**9
for i in range(1,n):
    a = i
    b = n-i
    ans_a = 0
    ans_b = 0
    a = list(str(a))
    b = list(str(b))
    for i in range(len(a)):
        ans_a += int(a[i])
    for i in range(len(b)):
        ans_b += int(b[i])
    ans = min(ans,ans_a+ans_b)
print(ans)

Submission status: Accepted

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

N = int(input())

ans = float("inf")

for A in range(1, N):
    B = N - A
    ans = min(ans, sum_digit(B) + sum_digit(A))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
min = 100
a_sum = 0
b_sum = 0

for a in range(1, n):
  b = n-a
  while a >= 1:
    a_sum += a%10
    a = a//10
  
  while b >= 1:
    b_sum += b%10
    b = b//10
  
  if a_sum + b_sum < min:
    min = a_sum + b_sum
  
  a_sum = 0
  b_sum = 0

print(min)

Submission status: Accepted

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

def digit_sum(t):
    r = t
    result_digit_sum = 0
    while(r > 0):
        result_digit_sum += r % 10
        r //= 10
    return result_digit_sum

for i in range(1, n+1):
    if digit_sum(i)+ digit_sum(n-i) >=2:
        digit_sum_list.append((digit_sum(i) + digit_sum(n-i)))
print(min(digit_sum_list))

Submission status: Accepted

Solution code:
N = input()
ans = 0

for i in range(len(N)):
    ans += int(N[i])

if ans >= 2:
    print(ans)
else:
    print(10)

Submission status: Accepted

Solution code:
N = input()
ans = 0
for n in N :
    ans += int(n)
if ans == 1 and len(N) >= 2 :
    print(10)
else :
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
li = []
for a in range(1, n):
    b = n - a
    a_sum = sum([int(x) for x in str(a)])
    b_sum = sum([int(y) for y in str(b)])
    total_sum = a_sum + b_sum
    li.append(total_sum)
print(min(li))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
def digit(k):
  r=[int(i) for i in str(k)]
  return sum(r)
ans=100
for i in range(1,n//2 + 1):
  j=n-i
  ans = min(ans,digit(i)+digit(j))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n = int(input())
    ans = 10**18
    for i in range(1, n//2+2):
        buf = dig_sum(i) + dig_sum(n-i)
        if buf < ans:
            ans = buf
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

for A in range(1,N):
    B = N-A
    ans.append(digitSum(A)+digitSum(B))
print(min(ans))

Submission status: Accepted

Solution code:
N = int(input())
ans = 10**5
for i in range(1,N):
    a = str(i)
    b = str(N - i)
    s = 0
    for j in range(len(a)):
        s += int(a[j])
    for j in range(len(b)):
        s += int(b[j])
    ans = min(s,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=list(input())
ans=0
for x in N:
  x=int(x)
  if x%2==1:
    ans+=1
  ans+=(x//2)*2
if ans==1:
  print(10)
else:
  print(ans)

Submission status: Accepted

Solution code:
N = int(input())
mini = float("inf")
for A in range(1,N-1+1):
  mini = min(mini,sum([int(digit) for digit in str(A)])+sum([int(digit) for digit in str(N-A)]))
print(mini)

Submission status: Accepted

Solution code:
import math
n = int(input())
ans = 1001001001
for a in range(1, n):
    b = n - a
    if a > b: break
    map(int, str(a))
    cnddt = sum(map(int, str(a))) + sum(map(int, str(b)))
    ans = min(ans, cnddt)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

answer = int('9' * 5)
for i in range(1, n):
    str_w = str(n - i)
    str_i = str(i)

    answer = min(
        answer,
        sum([int(w) for w in str_w]) + sum([int(wi) for wi in str_i])
    )
print(answer)

Submission status: Accepted

Solution code:
N = list(input())
list1 = [int(x) for x in N]
if N.count("0") == len(N) - 1 and N[0] == "1" and len(N) != 1:
  print(10)
else:
  print(sum(list1))

Submission status: Accepted

Solution code:
N = int(input())
  
total = N
for i in range(N-2):
  A = i+2
  B = N - A
  a_total = 0
  for a in range(len(str(A))):
    a_total += int(str(A)[a])
  b_total = 0
  for b in range(len(str(B))):
    b_total += int(str(B)[b])
  #print(a_total, b_total)
  if a_total + b_total < total:
    total = a_total + b_total
    #print("total", total)

print(total)

Submission status: Accepted

Solution code:
N = int(input())
def kakuwa(n):
    res = 0
    while n > 0:
        res += n%10
        n //=10
    return res

ans = 10000
for a in range(1,N):
    s = kakuwa(a)+kakuwa(N-a)
    if(s < ans):
        ans = kakuwa(a)+kakuwa(N-a)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
c = n
def digitsum(n):
  s = 0
  while n>0:
    s += n % 10
    n //= 10
  return s
for i in range(1, n//2+1):
  a = digitsum(i)
  b = digitsum(n-i)
  if c > a + b:
    c = a + b
print(c)

Submission status: Accepted

Solution code:
N = int(input())

def calc_digits_sum(n):
    return sum([int(i) for i in list(str(n))])

ans = float('inf')
for i in range(1, N):
    A = i
    B = N - i
    # print(A, B)
    a_sum = calc_digits_sum(A)
    b_sum = calc_digits_sum(B)
    # print(a_sum, b_sum)
    ans = min(ans, a_sum + b_sum)
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

t = sum([int(i) for i in list(str(N))])
# print(t)

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

Submission status: Accepted

Solution code:
import math
N=int(input())
c=0
min=float("inf")
for i in range(1,(N//2)+1):
    s1=list(str(i))
    s2=list(str(N-i))
    #print(s1,s2)
    for j in range(len(s1)):
        c=c+int(s1[j])

    for j in range(len(s2)):
        c=c+int(s2[j])
    if c<min:
        min=c
    c=0
print(min)

Submission status: Accepted

Solution code:
def calc(x):
  ans=0;s=str(x)
  for c in s:
    ans+=int(c)
  return ans
N=int(input())

print(min([calc(a)+calc(N-a) for a in range(1,N)]))

Submission status: Accepted

Solution code:
n=input()
ans=0
for i in range(len(n)):
    ans+=int(n[i])
if ans==int(n[0]) and len(n)>=2:
    ans+=9
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = float("inf")
a, b = 0, 0
while True:
    a += 1
    b = n - a

    if b <= 0:
        break

    ans = min(ans, sum(map(lambda x: int(x), str(a))) + sum(map(lambda x: int(x), str(b))))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if n[0] == 1 and sum(n)  == 1:
    print(10)
else:
    print(sum(n))

Submission status: Accepted

Solution code:
n = int(input())
if n%10==0:
    print(10)
    exit(0)
ans = pow(10,10)
for a in range(n+1):
    b = n-a
    tmp_ans = 0

    for sa in str(a):
        tmp_ans += int(sa)

    for sb in str(b):
        tmp_ans += int(sb)

    ans = min(ans, tmp_ans)
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N =input()
list = [int(i) for i in N]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
mi = 9999999999999999
for i in range(1,n):
    jj = n - i
    r = 0
    si = str(i)
    sj = str(jj)
    for i in range(len(si)):
        r += int(si[i])
    for i in range(len(sj)):
        r += int(sj[i])
    if mi > r:
        mi = r
print(mi)

Submission status: Accepted

Solution code:
N = int(input())

ans = float("inf")

A = 0
B = N
for i in range(N//2):

    A += 1
    B -= 1

    if A + B > N:
        break

    else:

        s_a = str(A)
        s_b = list(str(B))

        a = [int(i) for i in s_a]
        b = [int(i) for i in s_b]

        ans = min(ans, sum(a)+sum(b))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())

def Num_Each_Digit(N,limit):
    ans = np.array([])
    
    if N < 10**(limit):
        for i in range(1,limit+1):
            if (10**(i-1) > N):
                break
            if i == 1:
                ans = np.append( ans, (N%(10**i)))
            elif i > 1:
                ans = np.append( ans, (N%(10**i)-N%(10**(i-1)))/(10**(i-1)))

        return ans
                
    else:
        print("too large")
        return N
    
digit = Num_Each_Digit(N,10)
    
if N == 10**(len(digit)-1):
    print(10)
    
else:
    print(int(np.sum(digit)))

Submission status: Accepted

Solution code:
def main():
    N = list(str(input()))
    n = int("".join(N))
    sum_N = sum(list(map(int,N)))
    if n%10 == 0 and sum_N == 1:
        print(10)
    else:
        print(sum_N)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def digit_plus(num):
    i=num
    sum=0
    while i != 0:
        digit = i % 10
        sum += digit
        i //= 10
    
    return sum

#----------
n = int(input().strip())
#----------
min=n
for a in range(2,n):
    b = n - a
    sum_a_b = digit_plus(a) + digit_plus(b)

    if min > sum_a_b:
        min = sum_a_b

print(min)

Submission status: Accepted

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

def main():
    n = int(input())
    min_val = float('inf')
    for a in range(1, int(n/2)+1):
        b = n - a
        val = sum([int(c) for c in str(a)]) + sum([int(c) for c in str(b)])
        if val < min_val:
            min_val = val
    print(min_val)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

def keta(num) :
    ket = 0
    while num > 0 :
        ket += num%10
        num //= 10
    return ket

ans = 1000

for i in range(1,N) :
    total = keta(i) + keta(N-i)
    ans = min(ans, total)

print(ans)

Submission status: Accepted

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

def Sum_Digits(D):
  SUM = 0
  while D > 0:
    SUM += D%10
    D = int((D-D%10)/10)
  return SUM

for a in range(1, N):
  b = N - a
  A = Sum_Digits(a)
  B = Sum_Digits(b)
  if A + B < MIN:
    MIN = A + B
    
print(MIN)

Submission status: Accepted

Solution code:
n = int(input())

def d_sum(x):
    return sum(int(y) for y in str(x))

ans = float('inf')
for a in range(1, n):
    b = n - a
    dsum = d_sum(a) + d_sum(b)
    ans = min(ans, dsum)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = float('inf')
for a in range(1, n):
    b = n - a
    dsum = 0
    for i in range(len(str(a))):
        x = int(str(a)[i])
        dsum += x
    for i in range(len(str(b))):
        x = int(str(b)[i])
        dsum += x
    ans = min(ans, dsum)

print(ans)

Submission status: Accepted

Solution code:
def digSum(num):
    ret = 0
    for c in num:
        ret += int(c)
    return ret

n = int(input())
ans = 10000
for i in range(1, n):
    a = str(i)
    b = str(n - i)
    ans = min(ans, digSum(a) + digSum(b))

print(ans)

Submission status: Accepted

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

N = int(input())
j = 0
ans = []

for i in range(1, N):
	j = N - i
	ans_count = count(i) + count(j)
	ans.append(ans_count)

print(int(min(ans)))

Submission status: Accepted

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

n = int(input())
min_ans = 9 * 4
for i in range(1, n):
    ans = sum_digit(i) + sum_digit(n - i)
    if min_ans > ans:
        min_ans = ans
print(min_ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
n = int(s)
for i in range(5):
    if n == 10**(i+1):
        print(10)
        exit()
        # 10**k の時
print(sum([int(i) for i in s]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N = int(input())
n = N
amari = 0
for i in range (len(str(N))):
  amari += n % 10
  n = math.floor(n / 10)
if amari == 1:
  print(10)
else:
  print(amari)

Submission status: Accepted

Solution code:
try:
    N = int(input())
    min_ = 99999
    for a in range(N):
        b = N-a
        if b>0 and a>0:
            j = sum(map(int, str(a)))
            i = sum(map(int, str(b)))
            _ = i + j
            if _<min_:
                min_ = _
    print(min_)
except EOFError:
    pass

Submission status: Accepted

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

N = int(input())

result = 10**5

for A in range(1, N):
    B = N - A
    result = min(result, digits_sum(A) + digits_sum(B))

print(result)

Submission status: Accepted

Solution code:
N = int(input())

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

infinity = float('inf')
min = infinity

for x in range(1, N//2 + 1):
    #print('============')
    #print(x, N - x)
    #print(SumDigits(x) + SumDigits(N - x))
    if SumDigits(x) + SumDigits(N - x) < min:
        min = SumDigits(x) + SumDigits(N - x)
print(min)

Submission status: Accepted

Solution code:
N = int(input())

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

infinity = float('inf')
min = infinity

for x in range(1, N):
    if SumDigits(x) + SumDigits(N - x) < min:
        min = SumDigits(x) + SumDigits(N - x)
print(min)

Submission status: Accepted

Solution code:
N = int(input())
loopnum, _ = divmod(N,2)
min_count = 100000
ans = 100000

for num in range(1,loopnum+1):
    count = 0
    A = str(num)
    B = str(N-num)
    for i in range(len(str(A))):
        count += int(A[i])
    for j in range(len(str(B))):
        count += int(B[j])
    if min_count >= count:
#         print(A + B)
        min_count = count
        ans = count
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
print(min([sum([ord(c) - 48 for c in str(A)]) + sum([ord(c) - 48 for c in str(N - A)]) for A in range(1, N)]))

Submission status: Accepted

Solution code:
N = int(input())
n = 10 ** (len(str(N-1)) - 1)
a = list(str(N - n))
print(sum(list(map(int, a)))+1)

Submission status: Accepted

Solution code:
N = int(input())

if N%10 == 0:
    print(10)
else:
    l = []
    for i in range(6):
        l.append(int(N%10))
        N /= 10
    print(sum(l))

Submission status: Accepted

Solution code:
N = int(input())

summ = []
for i in range(1,N//2 + 1):
    A = []
    B = []
    k = N-i
    for __ in range(6):
        A.append(int(i%10))
        B.append(int(k%10))
        i /= 10
        k /= 10
    summ.append(sum(A+B))
print(min(summ))

Submission status: Accepted

Solution code:

import numpy as np
N = int(input())
Nd2 = int(np.ceil(N / 2))
min_total = np.inf
for i in range(1, -~Nd2):
    n = i
    n2 = N - i
    total = 0
    dig = 10
    while n:
        a, b = divmod(n, dig)
        n = a
        total += b
    while n2:
        a, b = divmod(n2, dig)
        n2 = a
        total += b
    min_total = min(min_total, total)

print(min_total)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=[0]+[sum(map(int, list(str(i)))) for i in range(1, N+1)]
print(min([a[i]+a[N-i] for i in range(1, N//2+1)]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N =int(input())
x=0
y=0
while N//10**(y+1)>0:
    y=y+1
if N==10**y:
    print(10)
else:
    while y>=0:
        x=x+N//10**y
        N=N-(10**y)*(N//10**y)
        y=y-1
    print(x)

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 = 0
	N = str(N)
	for i in range(len(N)):
		ans += int(N[i])
	print(ans)

Submission status: Accepted

Solution code:
n=int(input())
m=100000
for x in range(1,n//2+1):
  y=n-x
  x,y=list(str(x)),list(str(y))
  z=sum(list(map(int,x)))+sum(list(map(int,y)))
  m=min(m,z)
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [i for i in str(N)]
result = 0
for j in range(len(A)):
  result += int(A[j])
if result == 1 and A[0] == "1":
  print(10)
else:
  print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

#n, a, b= map(int, input().split())
#a, b  = map(int, input().split())
#h = list(map(int, input().split()))
#s = list(str(input()))
n = int(input())
n_1 = n-1

tot = 0
count = 0
num = int(n/2)
list_ini = list(str(n_1))
tot_min = 1 + sum(int(i) for i in list_ini)

for i in range(num):
  a = i+1
  b = n-i-1
  list_a = list(str(a))
  list_b = list(str(b))
  tot_a = sum(int(ii) for ii in list_a)
  tot_b = sum(int(ii) for ii in list_b)
  if(tot_min > tot_a + tot_b):
    tot_min = tot_a + tot_b
    
print(tot_min)

Submission status: Accepted

Solution code:
N = int(input())
s = [(i+1, N-i-1) for i in range((N-1) // 2 + 1)]
ss = [sum(list(map(int,list(str(v[0])[::1])))) + sum(list(map(int,list(str(v[1])[::1])))) for v in s]
print(min(ss))

Submission status: Accepted

Solution code:
ans=float('inf')
n=int(input())
for i in range(1,n):
    z=0
    j=n-i
    c=str(i)+str(j)
    for k in c:
        z+=int(k)
    ans=min(ans,z)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 9*10
def f(x):
    kurainowa = 0
    while x>0:
        kurainowa += x%10
        x = x // 10
    return kurainowa
for a in range(1,n):
    b = n-a
    if ans > f(a) + f(b):
        ans = f(a) + f(b)
print(ans)

Submission status: Accepted

Solution code:
def sumNum(num, sums):
    if num == 0:
        return sums
    sums += num % 10
    num = num // 10
    return sumNum(num, sums)

N = int(input())
keta = 0

for A in range(1, N):
    B = N - A
    _A = sumNum(A, 0)
    _B = sumNum(B, 0)
    ret = _A + _B
    if keta == 0:
        keta = ret
    if keta <= ret:
        continue
    keta = ret

print(keta)

Submission status: Accepted

Solution code:
import math
N = int(input())
n = N
amari = 0
for i in range (len(str(N))):
  amari += n % 10
  n = math.floor(n / 10)
if amari == 1:
  print(10)
else:
  print(amari)

Submission status: Accepted

Solution code:
N = int(input())
ans = 10**9
def f(x):
    answer = 0
    while x>0:
        answer += x % 10
        x //= 10
    return answer

for a in range(1, N+1):
    b = N - a
    if f(a)+f(b)<ans and b != 0:
        ans = f(a)+f(b)
print(ans)

Submission status: Accepted

Solution code:
# B 
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
def calc(a,b):
    sa=list(str(a))
    sb=list(str(b))
    res=0
    for aa in sa:
        res+=int(aa)
    for bb in sb:
        res+=int(bb)
    return res

n=ni()
ans=10**6
for i in range(1,n):
    a=i
    b=n-i
    t=calc(a,b)
    ans=min(ans,t)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

anslist=[]

for i in range(1,N):
    a = str(i)
    b = str(N-i)
    asum = sum(list(map(int,a)))
    bsum = sum(list(map(int,b)))
    SUM = asum + bsum
    anslist.append(SUM)

print(min(anslist))

Submission status: Accepted

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

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

for a in range(1, n+1):
    b = n-a
    if mi > f(a)+f(b) and b>0:
        mi = f(a)+f(b)
print(mi)

Submission status: Accepted

Solution code:
n = input()
length = len(n)

if n[0] == "1" and n[1:] == "0" * (length - 1):
  print(10)
else:
  print(sum(list(map(int, list(n)))))

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())

mi = 10**10

for i in range(1,n):
    a = str(i)
    b = str(n-i)
    point = 0
    for i in a:
        point += int(i)
    for j in b:
        point += int(j)
    mi = min(point,mi)
print(mi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

#　Xの格桁の和を求める
def f(X):
  return sum(list(map(int, str(X))))

summedDigit = 0
sumArray = []
for A in range(N+1):
  if A > 0 and A != N:
    B = N - A
    summedDigit = f(A) + f(B)
    sumArray.append(summedDigit)

print(min(sumArray))

Submission status: Accepted

Solution code:
N = int(input())

#　Xの格桁の和を求める
def f(X):
  return sum(list(map(int, str(X))))

summedDigit = 0
sumArray = []
for A in range(N+1):
  if A > 0:
    B = N - A
    if A != N:
      summedDigit = f(A) + f(B)
      sumArray.append(summedDigit)

print(min(sumArray))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = 0

for i in reversed(range(6)):
    k = n // (10 ** i)
    n = n % (10 ** i)
    ans += k

if ans != 1:
    print(ans)
elif ans == 1:
    print(10)

Submission status: Accepted

Solution code:
N = int(input())
cmin = 10**5
for x in range(1,N):
    y = str(N-x)
    x = str(x)
    cnt = 0
    for i in range(len(x)):
        cnt += int(x[i])
    for j in range(len(y)):
        cnt += int(y[j])
    cmin = min(cmin,cnt)
print(cmin)

Submission status: Accepted

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

for a in range(1, n):

    b = n - a
    _list.append(sum(list(map(int, str(a)[::]))) + sum(list(map(int, str(b)[::]))))

print(min(_list))

Submission status: Accepted

Solution code:
def examA():
    N = SI()
    ans = 0
    for i in N:
        ans += int(i)
    if ans==1:
        ans = 10
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examA()

Submission status: Accepted

Solution code:
n = int(input())

def Checker(sum, x):
    sum =  0
    while x > 0:
        sum += x % 10
        x = x // 10
    return sum

sum_list = []
for a in range(1, n):
    b = n - a
    sum_a = 0
    sum_b = 0
    
    y = Checker(sum_a, a)+ Checker(sum_b, b)
    sum_list.append(y)

print(min(sum_list))

Submission status: Accepted

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

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

def main():
	N = int(input())
	#S = input().rstrip()
	#N,A,B = map(int,input().split())
	
	res = 1001001001
	t = 0
	for i in range(1,N):
		x = dsum(i)+dsum(N-i)
		if res>x:
			res = x
			t = i

	print(t,N-t,file=sys.stderr)
	print(res)
	
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

ans = float("inf")
for a in range(1,n):
	b = n-a
	sa = str(a).rjust(6,"0")
	sb = str(b).rjust(6,"0")
	cnt = 0
	for i in range(6):
		cnt += int(sa[i]) + int(sb[i])

	ans = min(ans, cnt)

print(ans)

Submission status: Accepted

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