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: Runtime Error

Solution code:
n = int(input())

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

all = []

for a in range(2,n):
    sum_A =sum_digit(a)
    sum_B =sum_digit(n-a)
    all.append(sum_A + sum_B)

print(min(all))

Submission status: Runtime Error

Solution code:
n = int(input())

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

all = []

for a in range(n+2):
    sum_A =sum_digit(a)
    sum_B =sum_digit(n-a)
    all.push(sum_A + sum_B)

print(min(all))

Submission status: Runtime Error

Solution code:
for i in range(100000):
  g = N -i
  a=sum(map(int,list(str(g))))
  b=sum(map(int,list(str(i))))
  ans =  a + b
  if ans == 0:
    num = ans
  elif num >= ans:
    num = ans
  else:
    continue

Submission status: Runtime Error

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: Runtime Error

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

print(ans)

Submission status: Runtime Error

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)))
        ans = np.flip(ans)
        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: Runtime Error

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)))
        ans = np.flip(ans)
        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: Runtime Error

Solution code:
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)))
        ans = np.flip(ans)
        return ans
                
    else:
        print("too large")
        return N
    
digit = Num_Each_Digit(N,10)
    
if N == 10**(len(digit)+1):
    print(10)
    
else:
    print(np.sum(digit))

Submission status: Runtime Error

Solution code:
N=int(input())
ls=[]
for i in range(1,N-1):
  b=N-i
  e=i%10
  f=i%100
  g=i%1000
  h=i%10000
  j=i%100000
  E=b%10
  F=b%100
  G=b%1000
  H=b%10000
  J=b%100000
  x=e+(f-e)/10+(g-f)/100+(h-g)/1000+(j-h)/10000
  X=E+(F-E)/10+(G-F)/100+(H-G)/1000+(J-H)/10000
  ls.append(x+X)
print(int(min(ls)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
s = [(i+1, N-i-1) for i in range((N-1) // 2)]
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: Runtime Error

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: Runtime Error

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(2, n):
    b = n - a
    sum_a = 0
    sum_b = 0
    y = 0

    y = Checker(sum_a, a)+ Checker(sum_b, b)
    sum_list.append(y)

print(min(sum_list))

Submission status: Runtime Error

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(2, 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: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 10**9
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)
for a in range(1,n//2+3):
    b = n-a
    
    ans = min(digitSum(a)+digitSum(b),ans)
print(ans)

Submission status: Runtime Error

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

N = int(input())
range_A = range(2,100001)
min_total = 1000
for a in range_A:
	b = N - a
    if b < 1:continue
	sum_a = findSumOfDigits(a)
	sum_b = findSumOfDigits(b)
	total = sum_a + sum_b
	if total < min_total:
	min_total = total
print(min_total)

Submission status: Runtime Error

Solution code:
N = int(input())
range_A = range(2,100001)
min_total = 1000
for a in range_A:
	b = N - a
	if b < 1:continue
	sum_a = findSumOfDigits(a)
	sum_b = findSumOfDigits(b)
	total = sum_a + sum_b
    if total < min_total:
		min_total = total
print(min_total)

Submission status: Runtime Error

Solution code:
N = int(input())
range_A = range(2,50)
min_total = 1000
for a in range_A:
	b = abs(N - a)
	sum_a = findSumOfDigits(a)
	sum_b = findSumOfDigits(b)
	total = sum_a + sum_b
	if total < min_total:
		min_total = total
print(min_total)

Submission status: Runtime Error

Solution code:
def digit_10(n):
    dten = 0
    while(n>0):
        dten+=int(n%10)
        n/=10
    return dten

n = int(input())
l = []
for a in range(2,n):
    l.append(digit_10(a)+digit_10(n-a))
print(min(l))

Submission status: Runtime Error

Solution code:
def function(n):
  min=10000
  no=0
  for i in range(1,n):
    j=n-i
    list1=list(str(i))
    list2=list(str(j))
    for a in list1:
      no += int(a)
      for b in list2:
        no +=int(b)
     if no>min: min = no
    return min

Submission status: Runtime Error

Solution code:
N=int(input())
def f(x):
  s=0
  while x!=0:
    s+=x%10
    x//=10
  return(s)
minn=50
for i in range(1,N/2):
  minn=min(f(i)+f(N-i),minn)
print(minn)

Submission status: Runtime Error

Solution code:
a = int(input())
mi=[]
for i in range(1,a-1):
    x=0
    y=0
    j = a - i
    for ii in str(i):
        x+=int(ii)
    for jj in str(j):
        y+=int(jj)
    mi.append(x+y)
print(min(mi))

Submission status: Runtime Error

Solution code:
n = int(input())
res = set([])
for i, j in zip(range(1,n), range(n-1, n//2, -1)):
  q_a = sum([int(x) for x in str(i)])
  q_b = sum([int(x) for x in str(j)])
  res.add(q_a + q_b)
print(min(res))

Submission status: Runtime Error

Solution code:
N = int(input())

if N=10*i for i in range(1,5+1):
    print("10")
else
    print(sum(int(str(N)))

Submission status: Runtime Error

Solution code:
n=int(input())
import math
ans=10**40
for i in range(1,n//2+2):
	x=i
	y=n-i
	p=0
	for j in range((int(math.log(x,10)+10**-7)+1)):
		p+=x%10
		x=x//10
	for j in range((int(math.log(y,10)+10**-7)+1)):
		p+=y%10
		y=y//10
	ans=min(ans,p)
print(ans)

Submission status: Runtime Error

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

for num in range(2, n//2):
    a = num
    b = n - num
    a_s = sum(list(map(int, str(a))))
    b_s = sum(list(map(int, str(b))))
    c = a_s + b_s
    s.append(c)

print(min(s))

Submission status: Runtime Error

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

for num in range(2, n//2+1):
    a = num
    b = n - num
    a_s = sum(list(map(int, str(a))))
    b_s = sum(list(map(int, str(b))))
    c = a_s + b_s
    s.append(c)

print(min(s))

Submission status: Runtime Error

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

for num in range(2, n-1):
    a = num
    b = n - num
    a_s = sum(list(map(int, str(a))))
    b_s = sum(list(map(int, str(b))))
    c = a_s + b_s
    s.append(c)

print(min(s))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
m = 999
for i in range(N):
  N1 = sum(list(str(i+1)))
  N2 = sum(list(str(N - (i+1))))
  m = min(m, N1+N2)
print(m)

Submission status: Runtime Error

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

Submission status: Runtime Error

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(2, n + 1):
    b = n - a
    if b < 2:
        continue
    # print("{}, {} / {}, {}".format(a, sum_digits(a), b, sum_digits(b)))
    values.append(sum_digits(a) + sum_digits(b))

values.sort()
# print(values)
print(values[0])

Submission status: Runtime Error

Solution code:
def f(p):
    s = 0
    l = len(str(p))
    for i in range(l):
        s += (p // 10 ** i) % 10
    return s


N = int(input())
l = list()
for a in range(2, N):
    b = N - a
    l.append(f(a) + f(b))
print(min(l))

Submission status: Runtime Error

Solution code:
def f(p):
    s = 0
    for i in str(p):
        s += int(i)
    return int(s)


N = int(input())
l = list()
for a in range(2, N):
    b = N - a
    l.append(f(a) + f(b))
print(min(l))

Submission status: Runtime Error

Solution code:

def main():

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

    
if __name__== "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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-1):
    b = N - a
    sum_list.append(findSumOfDigit(a) + findSumOfDigit(b))

print(min(sum_list))

Submission status: Runtime Error

Solution code:
N = int(input())

sum_list = []

def findSumOfDigit(n):
    s = 0
    while(n > 0):
        s += n % 10
        n = int(n / 10)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-1):
    b = N - a
    sum_list.append(findSumOfDigit(a) + findSumOfDigit(b))

print(min(sum_list))

    return s

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

print(min(sum_list))

Submission status: Runtime Error

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(2, N):
    b = N - a
    sum_list.append(findSumOfDigit(a) + findSumOfDigit(b))

print(min(sum_list))

Submission status: Runtime Error

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

for i in range(1,N-1):
    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: Runtime Error

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):
  for k in range(N-N//2,N+1):
    if i + k == N:
      li.append(sum_10(i)+sum_10(k))
print(min(li))

Submission status: Runtime Error

Solution code:
import math
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)[1:math.ceil(N/2)]:
    A = i
    B = N - i
    total = findSumOfDigits(A) + findSumOfDigits(B)
    examples.append(total)

print(min(examples))

Submission status: Runtime Error

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)[1:round(N/2)]:
    A = i
    B = N - i
    total = findSumOfDigits(A) + findSumOfDigits(B)
    examples.append(total)

print(min(examples))

Submission status: Runtime Error

Solution code:
n = int(input())

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

print(min(sum_list))

Submission status: Runtime Error

Solution code:
n = int(input())

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

print(min(sum_list))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=sum(list(input()))
print(10 if s==1 else s)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())


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


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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
inf = 10**10

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a=input()

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

sal=sum(al)
return sal if sal > 1 else 10

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def degit_sum(n):
    s = list(str(n))
    s = [int(e) for e in s]
    return sum(s)

N = int(input())
degit = len(str(N))
if N % pow(10,degit-1) == 0:
    degit -= 1
A = pow(10,degit-1)
B = N - A
ans = degit_sum(A) + degit_sum(B)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = input()

ans = 0
for n in N:
    ans += n

print(ans)

Submission status: Runtime Error

Solution code:
N = input()
if a.count("0") == len(a)-1 and a[0] == "1":
  print(10)
else:
  count = 0
  for i in range(len(a)):
    if a[i] != "0":
      count += int(a[i])
  print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
half_n = int(n//2)
ans = []

for i in range(1, half_n):
    a = str(i)
    b = str(n-i)
    count_a = 0
    count_b = 0
    for ai in a:
        count_a += int(ai)
    for bi in b:
        count_b += int(bi)
    ans.append(count_a + count_b)

print(min(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
if a%2==0:
    a=n//2+1
else:
    a=n//2+2
def wa(k):
    kai=0
    while k>0:
        kai+=round(k%10)
        k=round((k-round(k%10))/10)
    return kai
ans=10000000000
for i in range(1,a+1):
    b=i
    c=n-i
    if ans>(wa(b)+wa(c)):
        ans=wa(b)+wa(c)
print(ans)

Submission status: Runtime Error

Solution code:
from math import log10
n = int(input())
ans=0
l = log10(n)
if int(l)==l:
  ans=10
else:
  while n>0:
  ans+=n%10
  n//=10
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
ans=0
for i in range(n//2+1):
  l=[int(j) for j in list(str(i))]
  m=[int(k) for k in list(str(n-i))]
  if ans<sum(j)+sum(m):
    ans=sum(j)+sum(m)
print(ans)

Submission status: Runtime Error

Solution code:
n, a, b, k = map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
def mod_inv(a, mod):
    return (pow(a,mod-2,mod))

def mod_combination(n, k, mod):
    return (fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod)) % mod

mod = 998244353
fact = [1] + [0] * n
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod

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

    
print(ans)

Submission status: Runtime Error

Solution code:
n, a, b, k = map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
def mod_inv(a, mod):
    return (pow(a,mod-2,mod))

def mod_combination(n, k, mod):
    return (fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod)) % mod

g = gcd(k, gcd(a, b))
a //= g
b //= g
k //= g

mod = 998244353
fact = [1] + [0] * n
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod
if a < b:
    tmp = a
    a = b
    b = tmp

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

    
print(ans)

Submission status: Runtime Error

Solution code:
n, a, b, k = map(int, input().split())

if False:
    n = 4
    a = 1
    b = 2
    k = 5

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
def mod_inv(a, mod):
    return (pow(a,mod-2,mod))

def mod_combination(n, k, mod):
    return fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod) % mod

mod = 998244353
fact = [1] + [0] * n
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod
# print(fact)
if a < b:
    tmp = a
    a = b
    b = tmp

ans = 0
# print("n, a, b =", n, a, b)
# print((k-b*n)//a, k//a+1)
for x in range(max(-int(-(k-b*n)//a),0), k//a+1):
    if (k-x*a) % b == 0:
        y = (k-x*a)//b
        
        # print("n, x, y, mod", n, x, y, mod)
        # print(mod_combination(n, x, mod))
        # print(mod_combination(n, y, mod))
        
        ans += mod_combination(n, x, mod) * mod_combination(n, y, mod)
        ans %= mod
    
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd
N,A,B,K=map(int,input().split())
mod=998244353

Factorial=[1]*(N+1)
for i in range(1,N+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return (power(x,y//2)**2)*x%mod

inverseFactorial=[1]*(N+1)
inverseFactorial[N]=power(Factorial[N],mod-2)
for i in range(0,N)[::-1]:
  inverseFactorial[i]=(inverseFactorial[i+1]*(i+1))%mod
  
def f(i,j):
  if i>j:
    i,j=j,i
  res=0
  if j<=N:
    for k in range(max(0,i+j-N),i+1):
      res+=Factorial[N]*inverseFactorial[i-k]*inverseFactorial[j-k]*inverseFactorial[k]*inverseFactorial[N-i-j+k]
  return res%mod
      
ans=0
g=gcd(A,B)
if K%g==0:
  A,B,K=A//g,B//g,K//g
else:
  print(0)
  exit()
for i in range(K//A+1):
  if (K-A*i)%B==0:
    x0=i
    y0=(K-A*i)//B
    break
m=0
while y0-A*m>=0:
  ans+=f(x0+B*m,y0-A*m)
  ans%=mod
  m+=1
    
print(ans%mod-1)

Submission status: Runtime Error

Solution code:
n=int(raw_input())
maxv=n
for a in xrang(1,n+1):
  b=n-a
  if a>b: break
  sa=sum([int(x) for x in str(a)])
  sb=sum([int(x) for x in str(b)])
  maxv=min(maxv, sa+sb)
print(maxv)

Submission status: Runtime Error

Solution code:
n = int(input())
def digitsum(x):
    array = list(map(int, list(str(x))))
    return sum(array)

dsum = [digitsum(a)+digitsum(n-a) for a in range(1,int(n/2))]
print(min(dsum))

Submission status: Runtime Error

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

N = int(input())
l = [ digit_sum(x) for x in range(1, N+1)]

sum_a_b = []

for i in range(1, int(N/2)):
    sum_a_b.append(l[i-1] + l[N-i-1])

print(min(sum_a_b))

Submission status: Runtime Error

Solution code:
n = str(input())
len = len(n)
list = list(n)
ans = 0
if n.count("0") != len - 1:
  for element in list:
    ans += int(element)
elif len(n) == 1:
  ans = int(n)
else:
  ans = 10
print(ans)

Submission status: Runtime Error

Solution code:
n = input()

m = len(n)
f = 0
ans = 0

for i in range(m):
    ans += n[i]
    
    
if m>1 and n[0] == 1:
    if n[1] == 0:
        ans += 9
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
f=lambda x:sum(map(int,str(x)))
v=1e9
for i in range(1,n//2+3):
  a=i
  b=n-i
  v=min(v,f(a)+f(b))
print(v)

Submission status: Runtime Error

Solution code:
n=int(input())
ans=inf
for i in range(n):
    ans=min(ans,sum(list(n-i))+sum(list(i)))
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
res = 0
for a in range(n):
  b = n - a
  res = sum(map(int, str(a))) + sum(map(int, str(b)))
 print(res)

Submission status: Runtime Error

Solution code:
n = input()
def sum_keta(m):
	sum_wa = 0
	while m>0:
		sum_wa = sum_wa + m%10
		m = int(m/10)

	return sum_wa

if sum_keta(n) == 1:
	print(10)
else:
	print(sum_keta(n))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
if A == 1:
    print(5)
else:
    print(A)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
i=2
digitSum=pow(10,5)
while A<math.sqrt(N):
    A=i
    B=N-A
    A_digitsum=0
    while A>10:
        A_digitsum += N%10
        A = A//10
    while B>10:
        B_digitsum += N%10
        B = B//10
    if digitSum > A_digitsum+B_digitsum:
        digitSum = A_digitsum+B_digitsum
print(digitSum)

Submission status: Runtime Error

Solution code:
N = int(input())
ret = 10000
for A in range(1, N):
    ret = min(ret, digit_sum(A) + digit_sum(N-A))
print(ret)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

N = int(input())
min_num = N
for a in range(1,N/2):
    b = N-a
    str_num_arr = list(str(a))
    sum_A = sum(map(int, str_num_arr))

    str_num_arr = list(str(b))
    sum_B = sum(map(int, str_num_arr))

    sum_all = sum_A+sum_B
    if min_num > sum_all:
        min_num = sum_all

print(min_num)

Submission status: Runtime Error

Solution code:

#N = int(input())
N = 30

min_num = N
for a in range(1,N/2):
    b = N-a
    str_num_arr = list(str(a))
    sum_A = sum(map(int, str_num_arr))

    str_num_arr = list(str(b))
    sum_B = sum(map(int, str_num_arr))

    sum_all = sum_A+sum_B
    if min_num > sum_all:
        min_num = sum_all

print(min_num)

Submission status: Runtime Error

Solution code:
N = int(input)

max = 0
for i in range(int(N/2)):
   part = sum([int(i) for j in str(i)]) + sum([int(i) for j in str(N-i)])
   if max < part:
      max = part
print(max)

Submission status: Runtime Error

Solution code:
import math

base = 998244353

n, a, b, k =  map(int, input().split())

fac = [1] * (n + 1)
rev = [1] * (n + 1)
for i in range(1, n + 1):
    fac[i] = fac[i - 1] * i % base
    rev[i] = pow(fac[i], base -2, base)



def comb(n,r):
    hoge = (fac[n] * rev[r] * rev[n - r] ) % base
    return hoge





count = 0

an = 0 

for an in range(n+1):
    if k - an * a < 0 or (k - an * a) % b != 0:
        continue
    bn = (k -an * a) // b
    if not 0 <= bn <= n:
        continue

    count += comb(n, an) * comb(n, bn) % base
    count %= base



print(count)

Submission status: Runtime Error

Solution code:
import math
n,a,b,k = map(int, input().split())
un = 998244353
def combination(n,r):
    return math.factorial(n)//(math.factorial(r) * math.factorial(n-r))

total = 0
for i in range(n+1):
    if((k-a*i)%b==0):
        count_b = (k-a*i)//b
        total += combination(n, i) * combination(n, count_b)

print(str(total % un))