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:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())

ans = 10**3
for a in range(1,n):
    b = n-a
    tmp = 0
    for j in reversed(range(len(str(a)))):
        tmpa = (a//(10**j))
        a -= tmpa*(10**j)
        tmp += tmpa
    for j in reversed(range(len(str(b)))):
        tmpb = (b//(10**j))
        b -= tmpb*(10**j)
        tmp += tmpb

    ans = min(ans,tmp)

print(ans)

Submission status: Accepted

Solution code:
num = int(input())
if num % 10 == 0:
    ans = 10
else:   
    s = str(num)
    array = list(map(int, s))
    ans = sum(array)
print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def sum_of_digits(n):
	mod=0
	num=[]
	while n !=0:
		mod=n%10
		n=n//10
		num.append(mod)
	return (sum(num))

N=int(input())
sum_of_all =0
for i in range(1,N//2+2):
	sum1=sum_of_digits(i)
	sum2=sum_of_digits(N-i)
	sum_of_all=sum1+sum2
	if i ==1:
		ans=sum_of_all
	elif ans>sum_of_all:
		ans=sum_of_all
print(ans)

Submission status: Accepted

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

# A - Digits Sum
def digits_sum(num):
	sum = 0
	
	for s in str(num):
		sum += int(s)
	
	return sum


N = int(input())
ans = sys.maxsize

if N < 10:
	max_index = N
else:
	max_index = N // 2

for A in range(1, max_index):
	B = N - A
	sum = digits_sum(A) + digits_sum(B)
	ans = min(ans, sum)
	
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
#A=1B=N-1にしてAとBの各位の和を出す
f_x=sum(map(int,str(N-1)))
count=int((f_x)+1)
for a in range(1,N):
    f_x_a=sum(map(int,str(a)))
    b=N-a
    f_x_b=sum(map(int,str(b)))
    ans=int((f_x_a)+(f_x_b))
#f_xより小さかったらcountに入れていきたい
    if count>=ans:
        count=ans
print(count)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    def digsum(n):
        res = 0
        while n:
            res += n%10
            n //= 10
        return res
    res = 1000000
    for i in range(1, n):
        a = i
        b = n-i
        res = min(res, digsum(a)+digsum(b))
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

def digit_sum(a, b):
    ab_sum = 0
    for i in range(1, len(str(a))+1):
        ab_sum += a % 10
        a = a // 10
    
    for i in range(1, len(str(b))+1):
        ab_sum += b % 10
        b = b // 10
    
    return ab_sum

min_sum = float("inf")
for i in range(1, (N//2)+1):
    a = i
    b = N - i
    if digit_sum(a, b) < min_sum:
        min_sum = digit_sum(a, b)

print(min_sum)

Submission status: Accepted

Solution code:
from sys import stdin
import math


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

A=0
B=N-A


def sum_of_digit(n):
    total = 0
    s = str(n)
    for i in range(len(s)):
        total = total + int(s[i:i+1])

    return total


minimum = 9999999999

for a in range(1,N):
    a_total = sum_of_digit(a)
    b = N - a
    b_total = sum_of_digit(b)
    minimum = min(minimum, a_total + b_total)

print(minimum)

Submission status: Accepted

Solution code:
N = int(input())

ans = float('inf')
a, b = 1, N-1
while a <= b:
  sum_d_a = sum(map(int, str(a)))
  sum_d_b = sum(map(int, str(b)))
  ans = min(ans, sum_d_a + sum_d_b)
  a += 1
  b -= 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())

ans=9999999999999
for a in range(1,n):
    b=n-a
    a_sum=sum(list(map(int,list(str(a)))))
    b_sum=sum(list(map(int,list(str(b)))))
    ab_sum=a_sum+b_sum
    if(ans>ab_sum):
        ans=ab_sum
#        print(a,b,ab_sum)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/agc025/tasks/agc025_a
# Python 3rd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(inputNum):
    result = 0
    # algorithm
    totalDigit = 0
    inputStr = str(inputNum)
    for j in range(0, len(inputStr)):
        totalDigit = totalDigit + int(inputStr[j])
    if totalDigit == 1:
        result = 10
    else:
        result = totalDigit
    return result


if __name__ == "__main__":
    print("{}".format(solver(II())))

Submission status: Accepted

Solution code:
def digit_sum(x):
    ans=0
    while x>0:
        ans+=x%10
        x=int(x/10)

    return ans

n = int(input())
ans = 100
for a in range(1,int(n/2)+1):
    ans = min(ans, digit_sum(a)+digit_sum(n-a))

print(ans)

Submission status: Accepted

Solution code:
def readInt():
    return list(map(int,input().split()))
n = int(input())
l = []
for i in range(1,n):
    ans = 0
    j = i
    k = n-i
    while j>0:
        ans += int(j%10)
        j = int(j/10)
    while k>0:
        ans += int(k%10)
        k = int(k/10)
    l.append(ans)
# print(l)
print(min(l))

Submission status: Accepted

Solution code:
n = input()
print(10 if len(set(n)) == 2 and n[:2] == "10" else sum(int(i) for i in n))

Submission status: Accepted

Solution code:

import sys  
import numpy as np

input = sys.stdin.readline

N = input()
sum_ = 0

for i in list(N)[:-1]:
    
    sum_+=int(i)

if sum_ != 1:
    print(sum_)
else :
    print(10)

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/agc025/tasks/agc025_a
# Python 2nd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(inputNo):
    result = 36
    for a in range(1, inputNo, +1):
        strA = str(a)
        strB = str(inputNo-a)
        checkDigitAdd = 0
        for j in range(0, len(strA)):
            checkDigitAdd = checkDigitAdd + int(strA[j])
        for j in range(0, len(strB)):
            checkDigitAdd = checkDigitAdd + int(strB[j])
        if checkDigitAdd < result:
            result = checkDigitAdd
#            print("Then {} {} , changed".format(strA, strB))
    # algorithm
    return result


if __name__ == "__main__":
    print("{}".format(solver(II())))

Submission status: Accepted

Solution code:
def calc(n):
    return sum(ord(c) - ord('0') for c in str(n))

def solve():
    n = int(input())
    ans = 1 << 60
    for i in range(1, n):
        a = n - i
        ans = min(ans, calc(a) + calc(i))
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/agc025/tasks/agc025_a
# Python 1st Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def digitSum(inputNum):
    result = 0
    inputNumStr = str(inputNum)
    for j in range(0, len(inputNumStr)):
        result = result + int(inputNumStr[j])
    return result


def solver(inputNum):
    result = 10**5
    # algorithm
    for j in range(1, inputNum):
        total = digitSum(j)+digitSum(inputNum-j)
        if total <= result:
            result = total
    return result


if __name__ == "__main__":
    print("{}".format(solver(II())))

Submission status: Accepted

Solution code:
N = int(input())

def  DigitsSum(n):
    s = 0
    while True:
        if n // 10 != 0:
            s += n % 10
            n = n // 10
        else:
            s += n
            break
    return s

S = 0

for i in range(1,int(N/2)+1):
    A = i
    B = N - i
    if S == 0 :
        S = DigitsSum(A)+DigitsSum(B)
    else:
        if S > DigitsSum(A)+DigitsSum(B):
            S = DigitsSum(A)+DigitsSum(B)
        else:
            continue

print(S)

Submission status: Accepted

Solution code:
N = int(input())

A = 0
B = 0

result = 0
judg = 100000

for i in range(N-1):
    A = i + 1
    B = N - A
    for ii in range(len(str(A))):
        A_re = A % 10
        A = int(A / 10)
        result += A_re
    for iii in range(len(str(B))):    
        B_re = B % 10
        B = int(B / 10)
        result += B_re
    if judg>result:
        judg = result
    result = 0

print(judg)

Submission status: Accepted

Solution code:
n=int(input())
a=10*5
def k(n):
    s=tuple(map(int,tuple(str(n))))
    return sum(s)

for i in range(1,n):
    s=k(i)+k(n-i)
    if a>s:
        a=s
print(a)

Submission status: Accepted

Solution code:
n=int(input())
ans=10**6
for i in range(1,n+1):
    a=i
    b=n-i
    if a<=b:
        asum=sum(map(int,str(a)))
        bsum=sum(map(int,str(b)))
        if ans>(asum+bsum):
            ans=asum+bsum
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ans = 1000000
for i in range(1, N+1):
    A = i
    B = N - i
    if A <= B:
        Asum = sum(map(int, str(A)))
        Bsum = sum(map(int, str(B)))
        if ans > (Asum + Bsum):
            ans = Asum + Bsum
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
 
n = input()
c = Counter(n)
c.pop('0', None)
 
if len(c) == 1 and '1' in c and c['1'] == 1:
    print(10)
else:
    print(sum(int(f) * m for f, m in c.items()))

Submission status: Accepted

Solution code:
N=int(input())
a=100
def k(n):
    s=tuple(map(int,tuple(str(n))))
    return sum(s)
for i in range(1,N):
    s=k(i)+k(N-i)
    if s<a:
        a=s
print(a)

Submission status: Accepted

Solution code:
n=int(input())
if n in [10,100,1000,10000,100000]:
    print(10)
else:
    sum=0
    for i in range(len(str(n))):
        sum+=n%10
        n=n//10
    print(sum)

Submission status: Accepted

Solution code:
N = int(input())

v = float("inf")
for a in range(1, N):
    b = N - a
    c = sum(map(int, str(a))) + sum(map(int, str(b)))
    if c < v:
        v = c
print(v)

Submission status: Accepted

Solution code:
N = int(input())

def digsum(n):
    total = 0
    while n > 0:
        total += n%10
        n /= 10
        n = int(n)
    return total

ans = float('inf')
for i in range(2, N//2+2):
    A = i
    B = N-A
    s = digsum(A)+digsum(B)
    ans = min(ans, s)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul, add
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_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

N = INT()

if N%10 == 0:
	print(10)
else:
	print(reduce(add, map(int, list(str(N)))))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_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

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:
# AGC 025 A - Digits Sum
n = int(input())

def DegitSum(x):
    ans = 0
    while x > 0:
        ans += x%10
        x = x // 10
    return ans
    
res = 10**8
for a in range(1, n//2+1):
    b = n - a
    if DegitSum(a) + DegitSum(b) < res:
        res = DegitSum(a) + DegitSum(b)
        
print(res)

Submission status: Accepted

Solution code:
a = int(input())
lim = a // 2
soma_lista = []
menor = 100000
for i in range(a - 1, lim, -1):
    b = str(a - abs(i)) + str(abs(i))
    soma = 0
    for digit in b:
        soma += int(digit)
    if soma < menor:
        menor = soma
if a == 2:
    print(a)
else:
    print(menor)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = n - 1
    b = 1
    menor = soma_digitos(a) + soma_digitos(b)
    temp = 0
    for i in range(n-2):
        a -= 1
        b += 1
        temp = soma_digitos(a) + soma_digitos(b)
        if menor > temp:
            menor = temp
    print(menor)

def soma_digitos(n):
    soma = 0
    while n >= 1:
        soma += n%10
        n = n//10
    return soma
main()

Submission status: Accepted

Solution code:
numero = int(input())
soma = 0
minimo = 100000
for aux in range(numero-1,1,-1):
    prim = str(aux)
    seg = str(numero - aux)
    for x in range(len(prim)):
        soma += int(prim[x])
    for x in range(len(seg)):
        soma += int(seg[x])
    if soma < minimo :
        minimo = soma
    soma = 0
if numero == 2:
    print(numero)
else:
    print(minimo)

Submission status: Accepted

Solution code:
n = int(input())

if n%10 == 0 and n != 10:
    print(10)
else:
    a,b = 1,0
    sA, sB= 0,0
    soma = []

    while a<=n:
        b=n-a

        for i in str(a):
            sA+=int(i)
        for j in str(b):
            sB+=int(j)
        soma.append(sA+sB)
    
        a=a+1
    print(min(soma))

Submission status: Accepted

Solution code:
n = input()

powers10 = [10**i for i in range(1, 6)]
print(10 if int(n) in powers10 else sum(int(d) for d in n))

Submission status: Accepted

Solution code:
n = int(input())


x = n / 2
result = 0

if n <= 10:
    result = n
elif (n <= 100 and not n % 10) or not x % 10:
    result = 0

    while(x > 0):
        result += int(x % 10)
        x = x // 10
    result = result* 2
else:
    if n % 10:
        x = n % 10
    elif n % 10: 
        x = n % 100
    elif n % 1000: 
        x = n % 1000
    elif n % 10000: 
        x = n % 10000
    n = n - x
    while(x > 0):
        result += x % 10
        x = x // 10

    while(n > 0):
        result += n % 10
        n = n // 10
print(result)


#
#else:
#    resulty, resultx = 0, 0
#
#    while(x > 0):
#        resultx += x % 10
#        x = x // 10
#
#    while(y > 0):
#        resulty += y % 10
#        y = y // 10
#
#    #print(resulty+resultx)
#    z = n//2
#
#    result = 0
#    while(z > 0):
#        result += z % 10
#        z = z // 10
#
#    if result*2 < resulty+resultx:
#        print(result*2)
#    else:
#        print(resulty+resultx)
#

Submission status: Accepted

Solution code:
line = input()
num = [int(n) for n in line.split()][0]
number_of_sums = num//2 + 1 + 1*num % 2
smallest_sum = 100000
for i in range(1, number_of_sums):
    first_number = i
    second_number = num-i
    summation = 0
    while first_number and summation < smallest_sum:
        summation += first_number % 10
        first_number //= 10
    while second_number and summation < smallest_sum:
        summation += second_number % 10
        second_number //= 10
    if smallest_sum > summation:
        smallest_sum = summation
print(smallest_sum)

Submission status: Accepted

Solution code:
num = int(input())

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


arr = []
rev_arr = []
for n in range(1,num):
    arr.append(n)
rev_arr = arr[::-1]

final_arr = []
for n in range(num-1):
    val = digitSum(arr[n]) + digitSum(rev_arr[n])
    final_arr.append(val)

print(min(final_arr))

Submission status: Accepted

Solution code:
def sum_value(n):
    n = str(n)
    sum = 0
    for i in range(len(n)):
        sum+=int(n[i])
    return sum

N = int(input())
A = int(N/2)
B = int(N/2) if N%2 == 0 else int(N/2)+1
menor = -1
for i in range(int(N/2)):
    menor = sum_value(A+i)+sum_value(B-i) if menor < 0 else min(sum_value(A+i)+sum_value(B-i), menor) 
print(menor)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

lis = []
for i in range(1,N):
  A = i 
  B = N -i
  lis.append(sum(map(int,str(A)))+sum(map(int,str(B))))

print(min(lis))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

def wa(x):
    s = 0
    while x > 0:
        s += x % 10
        x = int(x / 10)
    return s
L = []
for i in range(1,N):
    A = i
    B = N - i
    x = wa(A) + wa(B)
    L.append(x)
    
L = sorted(L)
    
print(L[0])

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import os
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#############################################
n=int(input())
if is_power(n,10):
    print(10)
else:
    n=str(n)
    n=list(n)
    n=list(map(int,n))
    print(sum(n))

Submission status: Accepted

Solution code:
n = int(input())
A = []
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 k in b:
        t += int(k)
    A.append(t)
print(min(A))

Submission status: Accepted

Solution code:
n = int(input())
def func(x):
  answer = list(map(int,str(x)))
  return sum(answer)
nums = []
for a in range(1,n):
  b = n - a
  num = func(a) + func(b)
  nums.append(num)
print(min(nums))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
ans = 100
def colsum(s):
    ret = 0
    for i in s:
        ret += int(i)
    return ret

for i in range(1,n):
    cand = colsum(str(i))+colsum(str(n-i))
    ans = min(cand,ans)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())

mini=float("inf")
for A in range(1,N):
  B=N-A
  sa=str(A)
  sb=str(B)
  sum_a=0
  sum_b=0
  for st in sa:
    sum_a += int(st)
  for st in sb:
    sum_b += int(st)
  mini= min(mini, sum_a+sum_b)  
  
print(mini)

Submission status: Accepted

Solution code:
from math import log10
N=input()

if log10(int(N)) % 1==0:
    print("10")
else:
    print(sum(map(int, list(N))))

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
#issueから始める
N = int(input())
def wa(N) : #kakuketanowa
    S = str(N)
    array = list(map(int,S))
    return sum(array)
ans = 10**9+7
for i in range(1,N):
    l = i
    r = N-i
    suma = wa(l) + wa(r)
    ans = min(ans,suma)
print(ans)

Submission status: Accepted

Solution code:

n=int(input())

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

min=9999999
#b= n-a
for a in range(1,n):
    b=n-a
    sum_a=digitSum(a)
    sum_b=digitSum(b)
    sum_ab=int(sum_a)+int(sum_b)
   
    if sum_ab < min:
        min=sum_ab

print(min)

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()

ans = INF
for i in range(1, N):
    total = 0
    A = str(i)
    B = str(N-i)
    for a in A:
        total += int(a)
    for b in B:
        total += int(b)
    ans = min(ans, total)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
res = float('inf')
for a in range(1, int(n/2)+1):
    b = n-a
    tmp = 0
    for c in str(a):
        tmp += int(c)
    for c in str(b):
        tmp += int(c)
    res = min(res, tmp)
print(res)

Submission status: Accepted

Solution code:
import math
n = int(input())
if math.log10(n) %1 == 0:
    print(10)
    exit()
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())
if N == 2:
    print(2)
    exit()
ans = float('inf')
for i in range(2,N):
    A = i
    B = N - i
    tmp = 0
    for k in str(A):
        tmp += int(k)
    for k in str(B):
        tmp += int(k)
    ans = min(ans,tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 10**10
for i in range(1,n):
    j = n-i
    l1 = len(str(i))
    l2 = len(str(j))
    l1_cnt,l2_cnt = 0,0
    for k in range(l1):
        l1_cnt +=int(str(i)[k])
    for l in range(l2):
        l2_cnt +=int(str(j)[l])
    ans = min(ans,l1_cnt+l2_cnt)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
ans=10**17
for i in range(1,N//2+1):
  j=N-i
  i_str=str(i)
  j_str=str(j)
  tmp1=0
  tmp2=0
  for v1 in range(len(i_str)):
    tmp1+=int(i_str[v1])
  for v2 in range(len(j_str)):
    tmp2+=int(j_str[v2])
  ans=min(ans,tmp1+tmp2)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 10**5
for a in range(1, N//2 + 1):
    suma = 0
    sumb = 0
    b = N - a
    while a > 0:
        suma += a % 10
        a //= 10
    while b > 0:
        sumb += b % 10
        b //= 10
    if (suma + sumb) < ans:
        ans = suma + sumb
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


def solve(N: int):
    s_n = str(N)
    keta = len(s_n)

    if N == 10**(keta-1):
        print(10)
        return
    answer = 0
    for i in range(keta):
        answer += int(s_n[i])
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def sumDigits(i):
    s = 0
    while i > 0:
        s += (i % 10)
        i = int(i / 10)
    return s

def main():
    N = int(input())
    m2 = 9 * 6
    for i in range(1, N + 1):
        k = N - i
        if k > 0:
            m2 = min(m2, sumDigits(i) + sumDigits(k))
    print(m2)

main()

Submission status: Accepted

Solution code:
def sumDigits(i):
    s = 0
    while i > 0:
        s += (i % 10)
        i = int(i / 10)
    return s

N = int(input())

m = 9*6
for i in range(1, N):
    k = N - i
    m = min(m, sumDigits(i) + sumDigits(k))

print(m)

Submission status: Accepted

Solution code:
def sumDigits(i):
    s = 0
    while i > 0:
        s += (i % 10)
        i = int(i / 10)
    return s

N = int(input())

m = N
for i in range(1, N):
    k = N - i
    m = min(m, sumDigits(i) + sumDigits(k))

print(m)