TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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).

Submission attempts (in order):
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)

N = int(input())
ans = N


def simulate(m):
    for a in range(1, m):
        global ans
        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


if N % 2 == 0:
    simulate(N//2+1)
else:
    simulate(N//2+2)

print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
if n % 10 == 0:
  print(10)
else:
  a = str(n)
  b = sum(a)
  print(b)

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

Verdicts: Runtime Error

Accepted
Problem: 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).

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

from numpy import inf
n=int(input())
ans=inf
for i in range(n-1):
    ans=min(ans,sum(list(map(int, list(str(n-i+1)))))+sum(list(map(int, list(str(i+1))))))
print(ans)

from numpy import inf
n=int(input())
ans=inf
for i in range(n-1):
    ans=min(ans,sum(list(map(int, list(str(n-i-1)))))+sum(list(map(int, list(str(i+1))))))
print(ans)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
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))

n = int(input())
l = []
for a in range(1,n):
        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))

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())

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

n = int(input())

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

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
N=int(input())

M=10**9
for i in range(1,N//2+10):
    a=list(str(i))
    b=list(str(N-i))
    #print(a,b)
    k=0
    for q in range(len(a)):
        k+=int(a[q])
    for p in range(len(b)):
        k+=int(b[p])
    M=min(M,k)
print(M)

N=int(input())

M=10**9
for i in range(1,N//2+1):
    a=list(str(i))
    b=list(str(N-i))
    #print(a,b)
    k=0
    for q in range(len(a)):
        k+=int(a[q])
    for p in range(len(b)):
        k+=int(b[p])
    M=min(M,k)
print(M)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
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)

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

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
import math


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


n =  int(input())



rank = int(math.log10(n)) 
print(rank)


div =  n % 10**rank
if rank < 1:
    a = 2
    b = n %2

elif div == 0:
    a = n / 2
    b = n / 2
else :
    a = 10**rank
    b = div

#print("{} : {}".format(a, b))


count = 0
count += digitSum(int(a))
count += digitSum(int(b))

print(count)



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)







    



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

rank = math.ceil(math.log10(n)) 
div =  n % 10**rank
if div == 0:
    print(10)
else :
    print(digitSum(int(n)))


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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).

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

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

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)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
import itertools


if __name__ == '__main__':
    N, A, B, K = map(int, input().split())
    li = [i for i in range(N)]
    ans = 0
    for ai in range(N):
        tmp = K-(ai*A)
        if tmp / B <= N and tmp % B == 0:
            bi = tmp // B
            a = len(list(itertools.combinations(li, ai)))
            b = len(list(itertools.combinations(li, bi)))
            ans += a*b
    print(ans)


if __name__ == '__main__':
    n = int(input())
    ans = 99999999
    for i in range(1, n):
        total = list(str(n-i)) + list(str(i))
        tmp = 0
        for t in total:
            tmp += int(t)
        ans = min(ans, tmp)
    print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N, C, D = map(int, input().split())
check = [i*i for i in range(N)]
time = 0
stop = N * N

if C * D % 2 ==1:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 0:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
elif (C+D) % 2 == 0:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 1:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
else:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 0:
    if C % 2 == 1:
     if D - j * j not in check:
      print(i, j)
      time += 1
      if stop == time:
       break
    else:
     if C - j * j not in check:
      print(i, j)
      time += 1
      if stop == time:
       break
   if stop == time:
    break


N, C, D = map(int, input().split())
check = [i*i for i in range(N)]
time = 0
stop = N * N

if C * D % 2 ==1:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 0:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
elif (C+D) % 2 == 0:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 1:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break



 

N, C, D = map(int, input().split())
check = [i*i for i in range(N+1)]
time = 0
stop = N * N
 
print(check)
if C * D % 2 ==1:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 0:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
elif (C+D) % 2 == 0:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 1:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
else:
 for i in range(2*N):
  tt = i * i
  if C - tt in check or D - tt in check:
   continue
  else:
   for j in range(2*N):
    print(i,j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break

N = int(input())
while(N%10 == 0):
 N /= 10
if N == 1:
 print(10)
else:
 s = str(N)
 array = list(map(int, list(s)))
 print(sum(array))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
c = n
for i in range(1, n//2+1):
  a = digitsum(i)
  b = digitsum(n-i)
  if c > a + b:
    c = a + b
print(c)

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

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = input()
num = 0
for num in n:
    ans += int(num)
if ans == 1:
    ans = 10
print(ans)

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

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))
if A == 1:
    print(5)
else:
    print(A)

N = int(input())
A = sum(list(map(int, list(str(N)))))
if A == 1:
    print(10)
else:
    print(A)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())

num = 0

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

    
print(num)

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

N = int(input())

num = 0

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

    
print(num)

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

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

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
import numpy as np
N = np.array(int(input()))
if N[-1] == 0:
  print(10)
else:
  print(N.sum())

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

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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
res = 99999
for a in range(1, N): 
        sum_ = 0 
        b = N - a 
        while (a > 0): 
                sum_ += a % 10
                a //= 10
        while (b > 0): 
                sum_ += b % 10
                b //= 10
        print(sum_)
        res = min(res, sum_)
print(res)

N = int(input())
res = 99999
for a in range(1, N): 
        sum_ = 0 
        b = N - a 
        while (a > 0): 
                sum_ += a % 10
                a //= 10
        while (b > 0): 
                sum_ += b % 10
                b //= 10
        res = min(res, sum_)
print(res)

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())


def F(num1, num2):
    sum1 = sum(map(int, list(str(num1))))
    sum2 = sum(map(int, list(str(num2))))
    return sum1 + sum2


max_num = 0
for A in range(N + 1):
    B = N - A
    max_num = max(max_num, F(A, B))
print(max_num)


N = int(input())


def F(num):
    ans = 0
    for n in str(num):
        ans += int(n)
    return ans


min_num = 10**9
for A in range(1, N):
    B = N - A
    num = F(A) + F(B)
    if num < min_num:
        min_num = num
print(min_num)


Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
n=input()
print(sum([int(i) for i in n])


n=int(input())
print(min([sum([int(a) for a in str(i)])+sum([int(b) for b in str(n-i)]) for i in range(1,int(n))]))


Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())

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

N = int(input())

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

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
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))      

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

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
A = list(map(int,input().split()))
A.sort()
ret = 0
ret += A[2]-A[1]
A[1] += ret
A[0] += ret
ret += (A[1]-A[0])//2
if (A[1]-A[0])%2==1:
  ret += 2
print(ret)


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

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
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))


n = int(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))


Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n=[int(i) for i in input().split()]
s=sum(n)
if s==1 and min(n)==0:
  print(10)
else:
  print(s)

n=[int(i) for i in list(input())]
s=sum(n)
if s==1 and min(n)==0:
  print(10)
else:
  print(s)

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())


x = n - 2
y = n - x

if n < 10:
    print(n)
if n = 10:
    print(1)
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)



def soma(a):
    res=0
    if(int(a)<10):
        return int(a)
        
    for i in range(0, len(a)):
        res+=int(a[i])

    if(res>=10):
        return soma(str(res))

    return res

def main():
    n = int(input())
    menor = soma(str(n-1))+1
    
    for i in range(1,10):
        if(soma(str(i))+soma(str(n-i))<menor):
            menor = soma(str(i))+soma(str(n-i))

    print(menor,"\n")

main()


def soma(n):
    x = sum(int(digit) for digit in str(n))
    if x < 10:
        return x
    else:
        return soma(x)

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

    somad = soma(n)
    
    for i in range(1, n):
        soman = soma(i)+soma(n-i);
        if(soman==somad):
            break
    
    print(soman,"\n")
       
main()


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)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
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)


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)


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)


def sum_digit(n):
    ret = 0
    while n>0:
        ret += n % 10
        n //= 10
    return ret

N = int(input())

mi = 999999999
for a in range(1, N):
    b = N - a
    mi = min(mi, sum_digit(a)+sum_digit(b))

print(mi)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
sumn = 0
data = 10
check = False
for i in range(5):
	if(10**i==n):
		check = True

if(check):
	print(10)
else:
	while n>=10:
		sumn += n%10
		print("n%10 =",n%10)
		print("n =",n)
		n //= 10
	sumn += n
	print(sumn)

n = int(input())
sumn = 0
data = 10
check = False
for i in range(1,6):
	if(10**i==n):
		check = True

if(check):
	print(10)
else:
	while n>=10:
		sumn += n%10
		n //= 10
	sumn += n
	print(sumn)

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
ans = 0
for i in range(1,n):
    ans = min(ans,sum(map(int,str(i)))+sum(map(int,str(n-i))))
print(ans)

n = int(input())
ans = float("inf")
for i in range(1,n):
    ans = min(ans,sum(map(int,str(i)))+sum(map(int,str(n-i))))
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):

def main():

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

    
if __name__== "__main__":
    main() 












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

    
if __name__== "__main__":
    main() 











Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
import math
N=int(input())
i=2
digitSum=pow(10,5)
A=int(2)
while i<=int(N/2):
    A=i
    B=N-A
    if B>A:
        break
    A_digitsum=0
    while A>=10:
        A_digitsum += A%10
        A = A//10
    if A<10:
        A_digitsum+=A
    B_digitsum=0
    while B>=10:
        B_digitsum += B%10
        B = B//10
    if B<10:
        B_digitsum+= B
    if digitSum > A_digitsum+B_digitsum:
        digitSum = A_digitsum+B_digitsum
    i+=1
print(digitSum)

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)

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


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

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


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
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 < 10:
  print(10+amari)
else:
  print(amari)

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)

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)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
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))]))

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

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = list(int(input()))
if N.count(0) == len(N) - 1:
  print(10)
else:
  sum(N)


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

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N,A,B,K = map(int,input().split(" "))
mod = 998244353
ncr = [1]*(N+1)
v = 1
for i in range(N):
	v = (v * ((N-i)%mod) * pow((i+1),mod-2,mod)) % mod
	ncr[i+1] = v%mod

pat = 0
for a in range(N):
	if (K - (a * A)) % B == 0:
		pat += ncr[a]*ncr[(K - (a * A))//B]
		pat %= mod

print(pat % mod)

N = int(input())
ans = float('inf')
for i in range(1,N):
	num = i
	j = N - num
	d = 0
	while num != 0:
		d += (num % 10)
		num //= 10
	while j != 0:
		d += (j % 10)
		j //= 10

	ans = min(d,ans)

print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
import sys

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

def solve(n):
    ans = sys.maxint
    for a in range(2, n//2):
        b = n - a
        ans = min(ans, digits_sum(a) + digits_sum(b))

    return ans

if __name__ == '__main__':
    n = int(input())
    print(solve(n))


import sys

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

def solve(n):
    ans = sys.maxsize
    for a in range(1, n):
        b = n - a
        ans = min(ans, digits_sum(a) + digits_sum(b))

    return ans

if __name__ == '__main__':
    n = int(input())
    print(solve(n))


Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
# coding: utf-8
import math
n=int(input())-1
a=10**int(math.log10(n))
b=n-a+1
print(sum(map(int,str(a)))+sum(map(int,str(b))))
print(a,b)

# coding: utf-8
import math
n=int(input())-1
a=10**int(math.log10(n))
b=n-a+1
print(sum(map(int,str(a)))+sum(map(int,str(b))))


Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
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)



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)

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)




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


def main()->None:
    N = int(input())
    
    range_A = range(1,N+1)
    min_total = 100000
    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)


if __name__ == "__main__":
    main()

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n=int(input())
ans=0
def calc(a,b):
  res=0
  for i in range(len(str(a))):
    res+=int(str(a)[i])
  for i in range(len(str(b))):
    res+=int(str(b)[i])
  return res
  
for i in range(1,n//2+1):
  a=i
  b=n-a
  ans=min(ans,calc(a,b))
print(ans)

n=int(input())
ans=10**6
def calc(a,b):
  res=0
  for i in range(len(str(a))):
    res+=int(str(a)[i])
  for i in range(len(str(b))):
    res+=int(str(b)[i])
  return res
  
for i in range(1,n//2+1):
  a=i
  b=n-a
  ans=min(ans,calc(a,b))
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
n=int(input())
if n==15:
  exit()
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)

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)

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
#-------------
N = int(input())
#-------------

if N%2 == 0:
  k = N//2
else:
  k = (N+1)//2

cmb = []
for i in range(1,k+1):
  cmb.append([i , N-i])

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

ans = []
for i in range(k-1):
  X = digitSum(cmb[i][0])
  Y = digitSum(cmb[i][1])
  ans.append(X+Y)


if ans == []:
  print("2")
else:
  print(min(ans))

#-------------
N = int(input())
#-------------

if N%2 == 0:
  k = N//2
else:
  k = (N+1)//2

cmb = []
for i in range(1,k+1):
  cmb.append([i , N-i])
  
def digitSum(n):
    
    s = str(n)
    
    array = list(map(int, s))
    
    return sum(array)

ans = []
for i in range(k-1):
  X = digitSum(cmb[i][0])
  Y = digitSum(cmb[i][1])
  ans.append(X+Y)


if ans == []:
  print("2")
else:
  print(min(ans))

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
aa=[]
aint=[]
a=list(input())
aint=map(int,a)
if sum(aint)==1:
    print(10)
else:
    print(sum(aint))

a=int(input())
s=0
while True:
    if 10**s < a:
        s +=1
    else:
        break
a1=a-10**s
alist=list(str(a1))
aintlist=map(int,alist)
aa=sum(aintlist)
print(s+aa)

a=[]
aint=[]
a=list(str(input()))
aint=map(int,a)
if sum(aint)==1:
    print(10)
else:
    print(sum(aint))

a=[]
aint=[]
a=list(str(input()))
aint=map(int,a)
if sum(aint)==1:
    print(10)
else:
    print(sum(aint))


import math

n = int(input())
sum = 0
length = int(math.log10(n) + 1)

for i in range(length):
	sum += n % 10
	n = int(n / 10)

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


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows:    * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored.  Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors.  Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.

Submission attempts (in order):
from fractions import gcd
import sys
sys.setrecursionlimit(10**7) 

N,A,B,K=map(int,input().split())
mod = 998244353

table=[1]
a=1
for i in range(1,N+1):
    a=(a*pow(i,mod-2,mod))%mod
    table.append(a)

num=1
for i in range(1,N+1):
    num = (num*i) %mod


number =0
for i in range(N):
    if (K-A*i)%B==0:
        j=(K-A*i)//B
        t = (num*num)%mod
        t = (t*table[i])%mod
        t = (t*table[j])%mod
        t = (t*table[N-i])%mod
        t = (t*table[N-j])%mod
        number = (number+t)%mod
print(number)

N,A,B,K=map(int,input().split())
mod = 998244353

table=[1]
a=1
for i in range(1,N+1):
    a=(a*pow(i,mod-2,mod))%mod
    table.append(a)

num=1
for i in range(1,N+1):
    num = (num*i) %mod


number =0
for i in range(N+1):
    if (K-A*i)%B==0 and K-A*i>=0:
        j=(K-A*i)//B
        if 0<=j<=N:
            t = (num*num)%mod
            t = (t*table[i])%mod
            t = (t*table[j])%mod
            t = (t*table[N-i])%mod
            t = (t*table[N-j])%mod
            number = (number+t)%mod
print(number)

Verdicts: Runtime Error

Accepted
Problem: Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows:    * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored.  Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors.  Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.

Submission attempts (in order):
MOD = 998244353
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


memo = [0]*(N+1)
memo[0] = memo[N] = 1
for k in range(1,N//2+1):
  v = memo[k-1]*(N-k+1)*modinv(k,MOD)
  v %= MOD
  memo[k] = memo[N-k] = v

N,A,B,K = map(int,input().split())
n = 0

for i in range(N+1):
    j = K-A*i
    if j < 0:
        break
    if (K-A*i)%B==0:
        j //= B
        n+=(memo[i]*memo[j])%998244353
        n%=998244353
print(n%998244353)

N,A,B,K = map(int,input().split())
n = 0
MOD = 998244353
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


memo = [0]*(N+1)
memo[0] = memo[N] = 1
for k in range(1,N//2+1):
  v = memo[k-1]*(N-k+1)*modinv(k,MOD)
  v %= MOD
  memo[k] = memo[N-k] = v
for i in range(N+1):
    j = K-A*i
    if j < 0:
        break
    if j%B==0 and j/B <= N:
        j //= B
        n+=memo[i]*memo[j]
        n%=998244353
print(n%998244353)

Verdicts: Runtime Error

Accepted
Problem: Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows:    * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored.  Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors.  Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.

Submission attempts (in order):
N, A, B, K = map(int, input().split(" "))
mod = 998244353
ncr = [1] * (N + 1)
v = 1

print(ncr)
for i in range(N):
    v = (v * ((N - i) % mod) * pow((i + 1), mod - 2, mod)) % mod
    ncr[i + 1] = v % mod

pat = 0
for a in range(N + 1):
    if (K - (a * A) < 0):
        break
    if (K - (a * A)) % B == 0 and ((K - (a * A)) // B) <= N:
        pat += ncr[a] * ncr[(K - (a * A)) // B]
        pat %= mod

print(pat % mod)

N, A, B, K = map(int, input().split(" "))
mod = 998244353
ncr = [1] * (N + 1)
v = 1

for i in range(N):
    v = (v * ((N - i) % mod) * pow((i + 1), mod - 2, mod)) % mod
    ncr[i + 1] = v % mod

pat = 0
for a in range(N + 1):
    if (K - (a * A) < 0):
        break
    if (K - (a * A)) % B == 0 and ((K - (a * A)) // B) <= N:
        pat += ncr[a] * ncr[(K - (a * A)) // B]
        pat %= mod

print(pat % mod)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows:    * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored.  Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors.  Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.

Submission attempts (in order):
n, A, B, k = list(map(int, input().split()))

MOD = 998244353
MAX = 3*10**5+2

fac = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
ifac = [0 for i in range(MAX)]
fac[0] = 1; fac[1] = 1
inv[1] = 1
ifac[0] = 1; ifac[1] = 1

for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD
  ifac[i] = ifac[i-1]*inv[i]%MOD

def nCk(n, k):
  if n<k or n<0 or k<0: return 0
  return (((fac[n]*ifac[k])%MOD)*ifac[n-k])%MOD

ans = 0
for i in range(n+1):
  if (k-A*i)%B == 0:
    b = (k-A*i)//B
    if 0<=b<=n:
      ans = (ans+nCk(n, i)*nCk(n, b))%MOD

if ans==0:
  print(1)
else:
  print(ans)
print(nCk(4, 0))

n, A, B, k = list(map(int, input().split()))

MOD = 998244353
MAX = 3*10**5+2

fac = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
ifac = [0 for i in range(MAX)]
fac[0] = 1; fac[1] = 1
inv[1] = 1
ifac[0] = 1; ifac[1] = 1

for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD
  ifac[i] = ifac[i-1]*inv[i]%MOD

def nCk(n, k):
  if n<k or n<0 or k<0: return 0
  return (((fac[n]*ifac[k])%MOD)*ifac[n-k])%MOD

ans = 0
for i in range(n+1):
  if (k-A*i)%B == 0:
    b = (k-A*i)//B
    if 0<=b<=n:
      ans = (ans+nCk(n, i)*nCk(n, b))%MOD

if ans==0:
  print(1)
else:
  print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the _beauty of the tower_ as follows:    * The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored.  Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors.  Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K. How many such ways are there to paint the tower? Find the count modulo 998244353. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.

Submission attempts (in order):
from scipy.misc import comb
N,A,B,K = map(int, input().split())
count = 0
P = []
c = 0
while c < N:
  if K % B == 0:
    if K//B <= N:
      
      P.append([c, K//B])
  K -= A
  c += 1
for p in P:
 count += comb(N, p[0], exact=True) * comb(N, p[1], exact=True)
if count > 998244353:
  count = count % 998244353
print(count)

import math
def divide(A,B,C,D,E):
  F = [B,C,D,E]
  F.sort()
  tail = F[-1]
  F = F[:-1]
  G = 1
  for i in range(A-tail):
    G *= A - i
  for f in F:
    G /= f
  return G
N,A,B,K = map(int, input().split())
count = 0
Nf = math.factorial(N)
P = []
c = 0
while c < N:
  if K % B == 0:
    if K//B <= N:
      print((c, K//B))
      P.append([c, K//B])
  K -= A
  c += 1
for p in P:
  for G in range(min(p[0],p[1]) + 1):
    W = N - p[0] - p[1] + G
    if W >= 0:
      #divider = math.factorial(p[0]-G) * math.factorial(p[1]-G) * math.factorial(G) * math.factorial(W)
      pattern = divide(Nf, math.factorial(p[0]-G), math.factorial(p[1]-G), math.factorial(G), math.factorial(W))
      count += pattern
count *= 10 ** k
if count > 998244353:
  count = count % 998244353
print(count)

def fib(n, p):
  F = [1] * (n + 1)
  for i in range(2, n + 1):
    F[i] = F[i - 1] * i % p
  return F
def finv(F, p):
  N = len(F) - 1
  Finv = list(F)
  Finv[-1] = pow(F[-1], p - 2, p)
  for i in range(N - 1, -1, -1):
    Finv[i] = Finv[i + 1] * (i + 1) % p
  return Finv
def comb(F, Finv, n, a, p):
  return F[n] * Finv[a] * Finv[n - a] % p
N, A, B, K = map(int, input().split())
p = 998244353
F = fib(N, p)
Finv = finv(F, p)
cnt = 0
for a in range(min(N + 1, K // A + 1)):
  _A = A * a
  if _A > K:
    continue
  if (K - _A) % B > 0:
    continue
  b = (K - _A) // B
  if b > N:
    continue
  cnt += comb(F, Finv, N, a, p) * comb(F, Finv, N, b, p)
  cnt %= p
print(cnt)

Verdicts: Wrong Answer

Runtime Error

Accepted