Problem:


Score : 200 points

Problem Statement

Takahashi has two positive integers A and B.

It is known that A plus B equals N.
Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).

Constraints

2 ≤ N ≤ 10^5

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B".

Sample Input 1

15

Sample Output 1

6

When A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the value in question.

Sample Input 2

100000

Sample Output 2

10



Sample input:
15


Sample output:
6

Submission status: Accepted

Solution code:
N = int(input())

ans = 10 ** 6
for i in range(1, N//2+1):
    A = i
    B = N - i
    ans = min(ans, sum(map(int, str(A))) + sum(map(int, str(B))))

print(ans)

Submission status: Accepted

Solution code:
def sum_of_dig(n):
    s = str(n)
    l = len(s)
    return sum(int(s[i]) for i in range(l))

N = int(input())
ans = sum_of_dig(N//2)+sum_of_dig(N-N//2)
for A in range(1, N//2):
    tmp = sum_of_dig(A)+sum_of_dig(N-A)
    if ans > tmp:
        ans = tmp
else:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = 10000
for a in range(1, n):
    wa = (sum(list(map(int, list(str(a)))))) + (sum(list(map(int, list(str(n - a))))))
    if ans > wa:
        ans = wa

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = 0

for i in str(N):
    a += int(i)
if a == 1:
    print(10)
else:
    print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
minsum=float('inf')
for i in range(1,(n//2)+1):
    a=i
    b=n-i
    asum=0
    bsum=0
    while a>0:
        asum+=a%10
        a=a//10
    while b>0:
        bsum+=b%10
        b=b//10
    sum=asum+bsum
    if sum<minsum:
        minsum=sum
print(int(minsum))

Submission status: Accepted

Solution code:
#import pysnooper
import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
from itertools import accumulate,combinations#,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
ans=10**9
if n&1:
    s,e=0,n
else:
    s,e=1,n-1
while s<=e:
    if s+e==n:
        now=0
        for i in str(s):
            now+=int(i)
        for i in str(e):
            now+=int(i)
        ans=min(ans,now)
    s+=1
    e-=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 10**18
for A in range(1,N):
    result = 0
    B = str(N-A)
    A = str(A)
    for i in A+B:
        result += int(i)
    ans = min(ans,result)
print(ans)

Submission status: Accepted

Solution code:
ans=999

N=int(input())
for p in range(1,N//2+1):
    q= N-p

    p=list(str(p))
    p=list(map(int,p))
    q=list(str(q))
    q=list(map(int,q))

    ans=min(ans,sum(p)+sum(q))

print(ans)

Submission status: Accepted

Solution code:
def ketanowa(num):
  return sum(list(map(int,str(num))))

N = int(input())
ans = 10**5
for i in range(1, N//2+1):
  goukei = ketanowa(i) + ketanowa(N-i)
  ans = min(goukei, ans)
print(ans)

Submission status: Accepted

Solution code:
def ketanowa(num):
  return sum(list(map(int,str(num))))

N = int(input())
ans = 10**5
for i in range(1, N//2+1):
  goukei = ketanowa(i) + ketanowa(N-i)
  if goukei < ans:
    ans = goukei
print(ans)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  ans = 100000
  for i in range(1, (n+2)//2):
    r = (n-i)//10000 + ((n-i)//1000)%10 + ((n-i)//100)%10 + ((n-i)//10)%10 + (n-i)%10 
    l = i//10000 + (i//1000)%10 + (i//100)%10 + (i//10)%10 + i%10
    ans = min(ans, r + l)
  print(ans)
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N = int(input())
ans = 100000
for i in range(1, N):
    A = i
    B = N - i
    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())
ans = 1000

for A in range(1,N):
  Asum = sum(list(map(int, str(A)))) 
  Bsum = sum(list(map(int, str(N-A)))) 
  if ans > (Asum+Bsum):
    ans = (Asum+Bsum)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

ans = 10**7

for A in range(1, N):
    B = N - A
    a = [int(a) for a in str(A)]
    b = [int(b) for b in str(B)]
    s = sum(a) + sum(b)
    
    if s < ans:
        ans = s
        
print(ans)

Submission status: Accepted

Solution code:
import math

if __name__ == '__main__':
    N = int(input())
    
    A_last = N // 2
    
    for A in range(1, A_last + 1):
        B = N - A
        A_origin = A
        
        A_sum = 0
        B_sum = 0
        
        while A > 0:
            r = A % 10
            A_sum += r
            A = A // 10
        
        while B > 0:
            r = B % 10
            B_sum += r
            B = B // 10
        
        total = A_sum + B_sum
        
        if A_origin == 1:
            total_min = total
        else:
            if total < total_min:
                total_min = total
    
    print(total_min)

Submission status: Accepted

Solution code:
n = int(input())
_min = None
for a in range(1, n):
    t = sum(map(int, list(str(a)))) + sum(map(int, list(str(n - a))))
    if _min is None or _min > t:
        _min = t
print(_min)

Submission status: Accepted

Solution code:
s=sum(map(int,input()));print(s*(s!=1)or 10)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

minimum = 1e+9999
for a in range(1,N):
  b = N - a
  a_str = str(a)
  b_str = str(b)
  sum = 0
  for i in range(len(a_str)):
    sum += int(a_str[i])
  for i in range(len(b_str)):
    sum += int(b_str[i])
  if sum < minimum:
    minimum = sum
print(minimum)

Submission status: Accepted

Solution code:
n = int(input())

min = n
for i in range(1, n):
  j = n -i
  
  a = i
  b = j
  # print(a, b)
  
  total = 0
  while a > 0:
    total += a % 10
    a = int(a/10)
  while b > 0:
    total += b % 10
    b = int(b/10)
  if min > total:
    min = total
        
print(min)

Submission status: Accepted

Solution code:
N = int(input())

s = 0
while N > 0:
    s += N % 10
    N //= 10
print(10 if s == 1 else s)

Submission status: Accepted

Solution code:
n=input()

if int(n)%10==0:
    print(10)
else:
    s=list(n)
    print(sum([int(ss) for ss in s]))

Submission status: Accepted

Solution code:
n=int(input())
val=10**5
for a in range(1,n):
	if sum(map(int,str(a)))+sum(map(int,str(n-a)))< val:
		val = sum(map(int,str(a))) + sum(map(int,str(n-a)))
print(val)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    m_t = 10 ** 10
    for i in range(1, n):
        a = list(map(int, list(str(i))))
        b = list(map(int, list(str(n-i))))
        m_t = min(m_t, sum(a) + sum(b))
    print(m_t)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    def digitsum(n):
        res = 0
        while n:
            res += n%10
            n //= 10
        return res
    n = I()
    ans = float("inf")
    for a in range(1,(n>>1)+1):
        b = n-a
        m = digitsum(a)+digitsum(b)
        if m < ans:
            ans = m
    print(ans)
    return

#B
def B():
    def comb(a,b):
        return fact[a]*inv_fact[b]*inv_fact[a-b]%mod
    mod = 998244353
    n,a,b,k = LI()
    fact = [1]*(n+1)
    for i in range(1,n+1):
        fact[i] = fact[i-1]*i%mod
    inv_fact = [None]*(n+1)
    inv_fact[n] = pow(fact[n],mod-2,mod)
    for i in range(n)[::-1]:
        inv_fact[i] = inv_fact[i+1]*(i+1)%mod

    ans = 0
    for x in range(n+1):
        if (k-a*x)%b == 0 and k >= a*x and k-a*x <= n*b:
            y = (k-a*x)//b
            ans += comb(n,x)*comb(n,y)%mod
        ans %= mod
    print(ans)

#C
def C():
    n = I()
    d = LIR(n)
    x = [None for i in range(n)]
    for i in range(n):
        if d[i][0]*d[i][1] <= 0:
            x[i] = 0
        else:
            if d[i][1] < 0:
                x[i] = d[i][1]
            else:
                x[i] = d[i][0]
    x.sort(key = lambda x:x)
    l = 0
    r = n-1
    ans = abs(x[l])
    k = 1
    while r-l > 0:
        ans += x[r]-x[l]
        if k:
            k = 0
            l += 1
        else:
            k = 1
            r -= 1
    ans += abs(x[r])
    l = 0
    r = n-1
    ans2 = abs(x[r-1])
    k = 0
    while r-l > 0:
        ans2 += x[r]-x[l]
        if k:
            k = 0
            l += 1
        else:
            k = 1
            r -= 1
    ans2 += abs(x[r])
    print(max(ans,ans2))
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())

        ans = 100000000000000
        for A in range(1, N):
            B = N - A
            ans = min(ans, self.f(A) + self.f(B))
        print(ans)

    def f(self, n: int) -> int:
        s = str(n)
        res = 0
        for c in s:
            res += int(c)
        return res


if __name__ == '__main__':
    AtCoder().main()

Submission status: Accepted

Solution code:
n=int(input())
a=0
s=list(str(n))
sets=list(set(s))
sets.sort()
if len(sets)==2 and sets[0]=='0' and sets[1]=='1':
  print(10)
else:
  for i in s:
    a+=int(i)
  print(a)

Submission status: Accepted

Solution code:
N = int(input())
m = 999
M = []
N1 = 0
N2 = 0
for i in range(N-1):
  L1 = list(str(i+1))
  N1 = 0
  N2 = 0
  for j in range(len(L1)):
    N1 += int(L1[j])
  L2 = list(str(N - (i+1)))
  for j in range(len(L2)):
    N2 += int(L2[j])
  M.append(N1+N2)
print(min(M))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    min_v = float('inf')
    for i in range(1, N//2+1):
        s = str(i)
        t = str(N-i)
        v = sum([int(c) for c in s + t])
        min_v = min(min_v, v)
    return min_v


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
x=int(input())
count=10000
for a in range(1, x):
    suma=0
    sumb=0
    b=x-a
    while (a > 0):
        suma += a%10
        a= a//10
    while (b > 0):
        sumb += b%10
        b=b//10
    count = min(count, suma+sumb)
print(count)

Submission status: Accepted

Solution code:
x=int(input())
count=100000
suma=0
sumb=0
for a in range(1, x):
    b = x-a
    y = sum(map(int, str(a))) + sum(map(int, str(b)))
    if y<count:
        count=y
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
kij=100
for i in range(1,n):
  aa = len(str(i))
  bb = len(str(n-i))
  asum=0
  bsum=0
  t=i
  s=n-i
  while(t>0):
    asum += t%10
    t = (t-t%10)/10
  while(s>0):
    bsum += (s)%10
    s = (s-s%10)/10
  if asum+bsum<kij:
    kij=asum+bsum
print(int(kij))

Submission status: Accepted

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

Submission status: Accepted

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

def sum_digits(val):
    work = 0
    while True:
        work += val % 10
        val //= 10
        if val == 0:
            break
    return work
   
n = int(input())

values = []
for a in range(1, n + 1):
    b = n - a
    if b < 1:
        continue
    # print("{}, {} / {}, {}".format(a, sum_digits(a), b, sum_digits(b)))
    values.append(sum_digits(a) + sum_digits(b))

values.sort()
# print(values)
print("0" if len(values) == 0 else values[0])

Submission status: Accepted

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

import sys
N = int(sys.stdin.readline().rstrip())
min = 1000000
for i in range(1, N):
    a = sumOfDigits(i)
    b = sumOfDigits(N-i)
    if min > a + b:
        min = a + b
print(min)

Submission status: Accepted

Solution code:
N = int(input())
candidates = []
for A in range(1,N):
  sumA = sum(list(map(int,str(A))))
  sumB = sum(list(map(int,str(N-A))))
  candidates.append(sumA + sumB)

candidates.sort()
print(candidates[0])

Submission status: Accepted

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

for a in range(1,n):
  b = n - a
  suma = 0
  sumb = 0
  for i in range(5):
    suma = suma + a%10
    a= a//10
  for i in range(5):
    sumb = sumb + b%10
    b= b//10
  array.append(suma+sumb)
  
print(min(array))

Submission status: Accepted

Solution code:
N = int(input())
a_sum = 0
b_sum = 0
Sum = []
for a in range(1,N):
  b = N-a
  a_sum = 0
  b_sum = 0
  while (a>0):
    a_sum += a%10
    a //= 10
  while (b>0):
    b_sum += b%10
    b //= 10
  Sum.append(a_sum+b_sum)
print(min(Sum))

Submission status: Accepted

Solution code:
n = int(input())
result = 1000
for i in range(1,n//2 + 1):
    b = n - i
    a2 = str(i)
    b2 = str(b)
    a_sum = 0
    b_sum = 0
    for x in range(len(a2)):
        a_sum += int(a2[x])
    for y in range(len(b2)):
        b_sum += int(b2[y])
    result = min(result,a_sum + b_sum)
print(result)

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
for i in range(6):
    ans += N % 10
    N //= 10
if ans == 1:
    ans = 10

print (ans)

Submission status: Accepted

Solution code:
n= int(input())

lis1 = []
lis2 = []
ans = n

for a in range(1, int(n/2)+1):
	aa = 0
	bb = 0
	b = n - a
	
	for j in str(a):#文字列を一文字ずつの配列にする
		lis1.append(j)
	for i in range(len(lis1)):
		aa += int(lis1[i])
		
	for j in str(b):#文字列を一文字ずつの配列にする
		lis2.append(j)
	for i in range(len(lis2)):
		bb += int(lis2[i])
	s 	= aa + bb
	if s < ans:#和がansより小さかったら
		ans = s
		
	lis1.clear()#配列の中身を全消しする
	lis2.clear()#配列の中身を全消しする

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A_up = N // 2
f_min = 10 ** 5
for A in range(1, A_up+1):
    B = N - A
    f = sum(map(int, list(str(A)+str(B))))
    if f_min > f:
        f_min = f
print(f_min)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int):
    m = 1e18
    for i in range(1, N):
        res = sum([int(a) for a in list(str(i))]) + sum([int(b) for b in list(str(N-i))])
        m = min(res, m)
    print(m)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
n = int(input())

def f(x):
    s = 0
    for xi in str(x):
        s += int(xi)
    return s

ans = float("inf")
for i in range(1,n):
    a = i
    b = n-i
    ans = min(ans,f(a)+f(b))
print(ans)

Submission status: Accepted

Solution code:
n=input()
a=["10","100","1000","10000","100000"]
new=sum(list(map(int,n)))
if n in a:
    print(10)
else:
    print(new)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc025/tasks/agc025_a


def sum_of_digits(x):
    return sum(map(int, str(x)))


N = int(input())
digits = [sum_of_digits(i) for i in range(0, N + 1)]
answer = digits[1] + digits[N - 1]
for i in range(1, N):
    a = digits[i] + digits[N - i]
    if answer > a:
        answer = a
print(answer)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

box =[]

for x in range(1,n):
    y = n -x
    xsum = sum(list(map(int, str(x))))
    ysum = sum(list(map(int, str(y))))
    box.append(xsum + ysum)
            
    
            
print(min(box))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

n = input().strip()

if str(n)[0] == "1" and all(c=="0" for c in str(n)[1:]):
    print(10)
else:
    ans = 0
    for c in str(n):
        ans += int(c)
    print(ans)

Submission status: Accepted

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

n = input().strip()

a = ""
b = ""

import math

for c in n:
    d = int(c)
    a += str(math.ceil(d/2))
    b += str(math.floor(d/2))

ans = 0
if int(n) % 10 == 0:
    ans += 9
for c in a:
    ans += int(c)
for c in b:
    ans += int(c)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
m = 1000
for i in range(1, n):
    m = min(m, sum(list(map(int, str(i)))) + sum(list(map(int, str(n - i)))))
print(m)

Submission status: Accepted

Solution code:
Num = int(input())
stack =0
Min = 100000000000

for i in range(1,Num):
    Num_Array = [Num - i , i]

    for x in range(2):
        while not 0 <= Num_Array[x] < 1:
             stack +=  Num_Array[x] % 10
             Num_Array[x] = int(Num_Array[x] / 10)
    if Min > stack:
        Min = stack

    stack = 0
print(Min)

Submission status: Accepted

Solution code:
n = int(input())
x = n

ans = 10 ** 5

for i in range(1, n//2+1):
  t = str(i) + str(x-i)
  temp = 0
  for j in t:
    temp += int(j)
  ans = min(ans, temp)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
t = 10 ** (len(str(n - 1)) - 1)
print(sum(int(e) for e in str(t)) + sum(int(e) for e in str(n - t)))

Submission status: Accepted

Solution code:
n=int(input())
count=[]
for a in range(1,n) :
  b=n-a
  la=list(str(a));lb=list(str(b))
  suma=0;sumb=0
  for sa in la :
    suma+=int(sa)
  for sb in lb :
    sumb+=int(sb)
  count.append(suma+sumb)
print(min(count))

Submission status: Accepted

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

for i in range(1, N//2+1):
    a = str(i)
    b = str(N - i)
    wa_a = sum([int(t) for t in a])
    wa_b = sum([int(t) for t in b])
    if result > wa_a + wa_b:
        result = wa_a + wa_b
print(result)

Submission status: Accepted

Solution code:
n=int(input());s=lambda x:sum(map(int,str(x)));print(min(s(x)+s(n-x)for x in range(1,n//2+2)))

Submission status: Accepted

Solution code:

def main():
    ans = sum(list(map(int,list(input()))))
    if  ans!=1:
        print(ans)
    else:
        print(10)
 

    
if __name__== "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
mt = 10 ** 9
for i in range(1, n):
    t = 0
    for j in range(len(str(i))):
        t += int(str(i)[j])
    for j in range(len(str(n - i))):
        t += int(str(n - i)[j])
    mt = min(mt, t)
print(mt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())


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


s = sumdigit(1) + sumdigit(N-1)  # 初期値
for i in range(N // 2):
    A = i + 1
    B = N - A
    tmp = sumdigit(A) + sumdigit(B)
    s = min(s, tmp)
print(str(s))

Submission status: Accepted

Solution code:
n = int(input())

def find(a):
    global total
    total = 0
    while a > 0:
        total += a % 10
        a //= 10
    return total

ans = float('inf')
for i in range(1,n):
    tmp = find(i) + find(n-i)
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())

min_sum = None
for A in range(1,N):
  B = N - A
  a = [int(i) for i in list(str(A))]
  b = [int(i) for i in list(str(B))]
  y = sum(a) + sum(b)
  if min_sum is None or y < min_sum:
    min_sum = y
print(min_sum)

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())

sum_list = []

def findSumOfDigit(n):
    s = 0
    while(n > 0):
        s += n % 10
        n = int(n / 10)
    return s

for a in range(1, N):
    b = N - a
    sum_list.append(findSumOfDigit(a) + findSumOfDigit(b))

print(min(sum_list))

Submission status: Accepted

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

for i in range(1,N):
    tmp1 = list(str(i))
    tmp2 = list(str(N-i))
    s1 = 0
    s2 = 0
    for j in range(len(tmp1)):
        s1 += int(tmp1[j])
    for j in range(len(tmp2)):
        s2 += int(tmp2[j])
    tmp3 = abs(s1+s2)
    l.append(tmp3)

ans = min(l)
print(ans)

Submission status: Accepted

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

def get_val(num1, num2):
  num1 = sum([int(i) for i in str(num1)])
  num2 = sum([int(i) for i in str(num2)])
  return num1 + num2
  
ans = 10**9
for i in range(1, n+2):
  pool = get_val(i, N-i)
  if ans > pool:
    ans = pool
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

wa_min = n
for i in range(1,n+1):
	n1 = n - i
	n2 = i
	wa1 = 0
	wa2 = 0
	while n1 > 0:
		mod = n1 % 10
		wa1 += mod
		n1 = n1 // 10
	while n2 > 0:
		mod2 = n2 % 10
		wa2 += mod2
		n2 = n2 // 10
	if (wa1 + wa2) < wa_min:
		wa_min = (wa1 + wa2)
	if i == n-i:
		break
print(wa_min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

mi = 100000000

for a in range(1,N):
    x = a
    sa = 0
    
    while x!=0:
        sa = sa + x%10
        x = x//10
   
    x = N-a
    sb = 0
    
    while x!=0:
        sb = sb +x%10
        x = x //10

    if sa +sb < mi:
        mi = sa + sb

print(mi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
e = 10 ** 9
for i in range(10 ** 6):
    if i > a:
        break
    else:
        b = str(i)
        c = str(a - int(b))
        d = 0
        if int(b) > 0 and int(c) > 0:
            for j in range(len(b)):
                d += int(b[j])
            for j in range(len(c)):
                d += int(c[j])
            e = min(e, d)
print(e)

Submission status: Accepted

Solution code:
n=sum(map(int,input()));print([n,10][n==1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

print(10 if n in [10 ** x for x in range(6)] else sum(map(int,str(n))))

Submission status: Accepted

Solution code:
N=int(input())
ans=10000000000
for i in range(N-1):
        sum = 0
        num = i+1
        smu=0
        while num!=0:
        	dig = num % 10
        	sum = sum + dig
        	num = int(num / 10)
        smu+=sum
        sum=0
        num = N-(i+1)
        while num!=0:
        	dig = num % 10
        	sum = sum + dig
        	num = int(num / 10)
        smu+=sum
        ans=min(ans,smu)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = []
for i in range(1,N):
    a = 0
    b = 0
    A = i
    B = N-i
    while A != 0:
        a += A%10
        A = A//10
    while B !=0:
        b += B%10
        B = B//10
    add = a+b
    s.append(add)
print(min(s))

Submission status: Accepted

Solution code:
n=int(input())
ans=10**9+7
for i in range(1,n//2+1):
    tmp=sum([int(i) for i in list(str(i))])+sum([int(i) for i in list(str(n-i))])
    if tmp<ans:ans=tmp
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def sum_10(n):
  return sum([int(l) for l in str(n)])

li=[]
for i in range(1,N//2 +1):
    if N - N//2 <= N - i <= N:
      li.append(sum_10(i)+sum_10(N - i))
print(min(li))

Submission status: Accepted

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

for i in range(1, N):
  temp = 0
  n = str(i)
  m = str(N-i)
  for j in range(len(n)):
    temp += int(n[j])
  for j in range(len(m)):
    temp += int(m[j])
  ans = min(ans, temp)
print(ans)

Submission status: Accepted

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

N = int(input())
examples = list()

for i in range((N//2)+1)[1:]:
    A = i
    B = N - i
    total = findSumOfDigits(A) + findSumOfDigits(B)
    examples.append(total)

print(min(examples))

Submission status: Accepted

Solution code:
N = int(input())
sum_min = 10000000
for a in range((N)//2+1):
    n_a = a+1
    n_b = N-a-1
    sum_a = 0
    sum_b = 0
    while(n_a>0):
        sum_a += n_a%10
        n_a //= 10
    while(n_b>0):
        sum_b += n_b%10
        n_b //= 10
    sum_all = sum_a + sum_b
    if(sum_all <= sum_min):
        sum_min = sum_all
print(sum_min)

Submission status: Accepted

Solution code:
# AGC025A - Digits Sum
# Better ver.
def main():
    n = int(input())
    ans = sum(map(int, str(n)))  # ds: digit sum
    print(ans if ans != 1 else 10)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# AGC025A - Digits Sum
def main():
    n = int(input())
    ans = float("inf")
    for i in range(1, n // 2 + 1):
        j = n - i
        ds = sum(map(int, str(i))) + sum(map(int, str(j)))  # digits sum
        ans = min(ans, ds)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a = int(input())
f = 10 ** 9
for i in range(1, a):
    c = str(a-i)
    d = str(i)
    e = 0
    for j in range(len(c)):
        e += int(c[j])
    for j in range(len(d)):
        e += int(d[j])
    f = min(f, e)
print(f)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
Ns = input()
Nint = int(Ns)
tens = [10**i for i in range(1,6)]

result = 0
if Nint in tens:
    result = 10
else:
    result = sum(list(map(int,list(Ns))))

print(result)

Submission status: Accepted

Solution code:
n = input()
nint = int(n)


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

print(ans if(ans != 1) else 10)

Submission status: Accepted

Solution code:
n = int(input())

def dig(a):
    ret = 0
    while a:
        ret += a % 10
        a //= 10
    return ret

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re

BIGNUM = 10 ** 9 + 7

def numsum(x):
    return sum([int(i) for i in str(x)])

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

    minnum = BIGNUM
    for A in range(1, N):
        B = N - A
        n = numsum(A) + numsum(B)
        if n < minnum:
            minnum = n
    print(minnum)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = int(input())
min = 10**9
tmp = 0
for A in range(1,N//2+2):
    B = N-A
    tmp = addnum(A)+addnum(B)
    if min>tmp:
        min = tmp
print(min)

Submission status: Accepted

Solution code:
N = int(input())

def get_sum(num):
    i = num
    s = 0
    while i != 0:
        s += i % 10
        i = i // 10
    return s

# A >= Bとして考える
if N % 2 == 0:
    last_A = int(N/2)
else:
    last_A = int((N-1)/2 + 1)

ans = float("inf")
for A in range(1, last_A + 1):
    B = N - A
    sum_of_AB = get_sum(A) + get_sum(B)
    ans = min(ans, sum_of_AB)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

ans = N
for A in range(1, N):
    B = N - A
    Asum = sum([int(a) for a in list(str(A))])
    Bsum = sum([int(b) for b in list(str(B))])
    ans = min(Asum+Bsum, ans)
print(ans)