Problem:


Score : 100 points

Problem Statement

Snuke has N integers: 1,2,\ldots,N.
He will choose K of them and give those to Takahashi.

How many ways are there to choose K consecutive integers?

Constraints

All values in input are integers.

1 \leq K \leq N \leq 50

Input

Input is given from Standard Input in the following format:

N K

Output

Print the answer.

Sample Input 1

3 2

Sample Output 1

2

There are two ways to choose two consecutive integers: (1,2) and (2,3).

Sample Input 2

13 3

Sample Output 2

11



Sample input:
3 2


Sample output:
2

Submission status: Runtime Error

Solution code:
n = int(input())
 
ans = 0
A = 0
B = 0
AB = 0
for _ in range(n):
    s = input()
    ans += s.count('AB')
    
    if s[-1] == 'A' and s[0] != 'B':
        A += 1 
    if s[0] == 'B' and s[-1] != 'A':
        B += 1
    if s[-1] == 'A' and s[0] == 'B':
        AB += 1
    
ans += min(A+AB, B+AB)


if AB>0 and A==0 and B==0:
    ans -= 1

print(ans)

Submission status: Runtime Error

Solution code:
inp = input().split()

tmp = inp[0]-inp[1]

print(tmp+1)

Submission status: Runtime Error

Solution code:
  inputdata=input().split()
  n=int(inputdata[0])
  k=int(inputdata[1])
  pointer=1
  while pointer +k <= n:
    pointer = pointer +1
  print(pointer)

Submission status: Runtime Error

Solution code:
r,g,b,n=map(int, input().split())

r_max=n//r
g_max=n//g

sum=0

for i in range((n//r)+1):
    for j in range((n-(i*r)//g)+1):
        if (n-(i*r)-(j*g))%b==0 and (n-(i*r)-(j*g))//b>=0:
            sum=sum+1
        #    print(i*r,j*g,(n-(i*r)-(j*g))%b)

print(sum)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
cnt = 0
for k in range(1,math.floor(math.sqrt(N)) + 1):
  if N % k == 0 and N // k > k + 1:
    cnt += N // k - 1
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
headB=0
tailA=0 
both = 0
ans = 0
for j in range(N):
    t = input()
    if t[0] == "B":
        if t[-1] == "A":
            both += 1
        else:
            headB += 1
    elif t[-1] == "A":
        tailA += 1
    ans += t.count("AB")
if tailA > 0 or headB > 0:
    while both > 0:
        tmp = min(tailA+headB,both)
        ans += tmp
        both -= tmp
else:
    ans += both-1
ans += min(headB,tailA)
print(ans)

Submission status: Runtime Error

Solution code:
R, G, B, N = map(int, input().split())
r = 0
g = 0
X = N - r*R - g*G
num = 0
while X >= 0:
	while X >= 0:
			if X % B == 0:
				num += 1
			r += 1
			X = N - r*R - g*G
	g += 1
	r = 0
	X = N - r * R - g * G
 
print(num)

Submission status: Runtime Error

Solution code:

r,g,b,n = map(int,input().split())
ans = 0

for i in range(n+1):
    for j in range(n+1):
            if (r*i + g*j + b*(n+1 - i - j)) == n:
                ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = input("N:")
k = input("K:")
answer = int(n) - int(k) + 1
print(str(answer))

Submission status: Runtime Error

Solution code:
n=int(input())
s=['' for i in range(n)]
for i in range(n):
  s[i]=input()
#print(n,s)
cnt=0
cnta=0
cntb=0
cntab=0
ans=0
for i in range(n):
    cnt+=s[i].count('AB')
    if s[i][-1]=='A' and s[i][0]=='B':
        cntab+=1
    elif s[i][-1]=='A':
        cnta+=1
    elif s[i][0]=='B':
        cntb+=1

if cntab==0:
  ans=cnt+min(cnta,cntb)
else:
  ans=cnt+cntab+min(cnta,cntb)

if cnta==0 and cntb==0:
  if cntab > 0:
    ans=cnt+cntab-1
  else:
    ans=cnt
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input())

print(N + 1 - K)

Submission status: Runtime Error

Solution code:

# coding: utf-8

# In[1]:

import sys
import math
#input = sys.stdin.readline
N = int(input())


# In[5]:

sum_ = 0
#print(math.sqrt(N))
#print(int(math.sqrt(N)))
for i in range(1, int(math.sqrt(N+0.5))+1):
    if N%i == 0:
        #print(i)
        #print(N/i-1)
        sum_ += N/i-1
print(int(sum_))


# In[ ]:

Submission status: Runtime Error

Solution code:
import sys

N = int(input())
A = [int(a) for a in input().split()]

C_sum = [0]
s = {0}

for a in A:
    C_sum.append(C_sum[-1]^a)
    s.add(C_sum[-1])

if C_sum[-1] != 0:
    print(1)
else:
    dic_state = {}
    dic = {}
    for x in s:
        dic_state[x] = 0
        dic[x] = [0]
    for c in C_sum:
        if c==0:
            for d in dic:
                if dic_state[d] == 0:
                    dic[d][-1] += 1
                else:
                    dic[d].append(1)
                    dic_state[d] = 0
        else:
            if dic_state[c] == c:
                dic[c][-1] += 1
            else:
                dic[c].append(1)
                dic_state[c] = c

    ans = pow(2,dic[0][0]-2,10**9+7)

    for d in dic:
        tmp_0 = 1
        tmp_x = 0

        for i in range(1,len(dic[d])):
            if i%2==1:
                tmp_x += tmp_0 * dic[d][i]
                tmp_x %= 10**9+7
            else:
                tmp_0 += tmp_x * dic[d][i]
                tmp_0 %= 10**9+7

        ans += tmp_x
        ans %= 10**9+7

    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
res = 0
both = 0
head = 0
last = 0
for i in range(N):
  inp = input()
  if 'AB' in inp:
    res += 1
  if inp[0]=='B' and inp[len(inp)-1]!='A':
    head+=1
  if inp[len(s[i])-1]=='A' and inp[0]!='B':
    last+=1
  if inp[0]=='B' and inp[len(inp)-1]=='A':
    both+=1
    
res += max(0,both -1)
if both !=0:
  if head > 0 and last >0:
    res += 2 + min(head-1,last-1)
  elif head>0:
    res += 1 + min(head-1,last)
  elif last>0:
    res += 1 + min(head,last-1)
else:
  res += min(head,last)
print(res)

Submission status: Runtime Error

Solution code:
n = input();
k = input();

n = int(n);
k = int(k);

ans = n - k + 1;
print (ans);

Submission status: Runtime Error

Solution code:
n = input()
k = input()

n = int(n)
k = int(k)

ans = n - k + 1
print (ans)

Submission status: Runtime Error

Solution code:
N = int(input())

import numpy as np

sum = 0

for n in range(1, int(np.sqrt(N))+1):
    x = (N - n ) // n
    if (N - n) % n == 0 and n**2 < N:
        sum += x

print(sum)

Submission status: Runtime Error

Solution code:
n = input()
k = input()

n = int(n)
k = int(k)

ans = n - k + 1
print (ans)

Submission status: Runtime Error

Solution code:
n = input()
k = input()

ans = n - k + 1
print (ans)

Submission status: Runtime Error

Solution code:
n, k=map(int, input(),split())
print(n-k+1)

Submission status: Runtime Error

Solution code:
N = int(input())
 
cnt = 0
list = [0,0,0]
 
for i in range(N):
    s = input()
    cnt += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        list[0] += 1
    elif s[-1] == 'A':
        list[1] += 1
    elif s[0] == 'B':
        list[2] += 1
 
min_ = min(list[0],list[1],list[2])
 
if min_ >= 1:
    cnt += 2*min_
    list[0] -= min_
    list[1] -= min_
    list[2] -= min_
 
if list[0] >= 2:
    cnt += 2*list[0]//2
    list[0] -= 2*(list[0]//2)
 
if list[1] == list[2]:
    cnt += list[1]
elif list[1] > list[2]:
    cnt += list[2] + min(list[0],list[1]-list[2])
elif list[1] < list[2]:
    cnt += list[1] + min(list[0],list[2]-list[1])
 
print(cnt)

Submission status: Runtime Error

Solution code:
print(N-K+1)

Submission status: Runtime Error

Solution code:
a,b,c,n=map(int,input().split())
count=0
for i in range(n//a)
  for j in range(n//b)
  	if n-i*a-j*b>=0 && n-i*a-j*b%c==0:
      count++
print(count)

Submission status: Runtime Error

Solution code:
# R*r + G*g + B*b == N の数
R, G, B, N = map(int, input().split())
R, G, B = list(sorted([R, G, B], reverse=True))
ans = 0
for r in range(N + 1):
    for g in range(N + 1):
        if (N - (r * R + g * G)) % B != 0:
            continue
        b = (N - (r * R + g * G))/B
        if b < 0:
            break
        if r * R + g * G + b * B == N:
            ans += 1
        elif r * R + g * G + b * B > N:
            break

print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
ans=0
for x in range(n//r):
    for y in range(n//g):
        if (d-x*a+y*b)//c==0:
            ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
res=0
first, end, both = 0, 0, 0


for i in range(N):
    str = input()
    res+=str.count("AB")
    if str[0]=="B":
        first+=1
    if str[-1]=="A":
        end+=1
    if str[0]=="B" and str[-1]=="A":
        both+=1

res+=min(first, end)
if both==max(first, end) and both!=0:
    res-=1

print(res)

Submission status: Runtime Error

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

rmax = int(n[3] / n[0])
ans = 0

for i in range(0, rmax+1):
  sum = i * n[0]
  while sum <= n[3]:
    if (n[3] - sum) % n[2] == 0:
      ans += 1
    sum += n[1]

print(ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
d_list = []

for i in range(3, int(math.sqrt(N))):
  if N % i == 0:
    d_list.append(i)
    if i != math.sqrt(N):
      d_lsit.append(N / i)

output = sum(d_list) - (len(d_list) - 2) - 3
print(output)

Submission status: Runtime Error

Solution code:
n=input()
m=input()
print(n-m+1)

Submission status: Runtime Error

Solution code:
R, G, B ,N = map(int, input().split())

cnt = 0
for r in range(N//R + 1):
  for g in range((N-r*R)//G + 1):
    val = N - (r*R + g*G)
    if val % B == 0 and  val >= 0:
      cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
n = int(math.sqrt(N))+1
count=0
for i in range(1,n):
    d = N - i
    if d%i==0:
        k = int(d/i)
        count+=k
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input() for _ in range(n))
m,o,f,both=0,0,0,0

for i in range(n):
    m +=s[i].count("AB")
    if s[i][0]=="B":
        o +=1
for i in range(n):
    if s[i][-1]=="A":
        f +=1
for i in range(n):
    if s[i][0]=="B" and s[i][-1]=="A":
        both+=1
        o-=1
        f-=1

if both!=0:
    if i!=0 and f!=0:
        print(m+both+min(o,f))
    else:
        print(m+both+min(o,f)-1)

else:
    print(m+min(o,f))

Submission status: Runtime Error

Solution code:
n = int(input())

s = 0
for r in range(1, int((n-1)**0.5)+5):
    if n % r == 0:
        m = n//r-1
        if n//m == n%m:
            s += m
print(s)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input() for _ in range(n))
m,i,f,both=0,0,0,0

for i in range(n):
    m +=s[i].count("AB")

    if s[i][-1]=="A":
        f +=1
    if s[i][0]=="B" and s[i][1]=="A":
        both+=1
        i-=1
        f-=1

if both!=0:
    if i!=0 and f!=0:
        print(m+both+min(i,f)-1)
    else:
        print(m+both+min(i,f))

else:
    print(min(i,f))

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input() for _ in range(n))
m,i,f,both=0,0,0,0

for i in range(n):
    m +=s[i].count("AB")
    if s[i][0]=="B":
        i +=1
    if s[i][-1]=="A":
        f +=1


if both!=0:
    if i!=0 and f!=0:
        print(m+both+min(i,f)-1)
    else:
        print(m+both+min(i,f))

else:
    print(min(i,f))

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input() for _ in range(n))
m,i,f,both=0,0,0,0

for i in range(n):
    m +=s[i].count("AB")
    if s[i][0]=="B":
        i +=1
    if s[i][1]=="A":
        f +=1
    if s[i][0]=="B" and s[i][1]=="A":
        both+=1
        i-=1
        f-=1

if both!=0:
    if i!=0 and f!=0:
        print(m+both+min(i,f)-1)
    else:
        print(m+both+min(i,f))

else:
    print(min(i,f))

Submission status: Runtime Error

Solution code:
    n,k = map(int,input().split())
    print(n-k+1)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input() for _ in range(n))
m,i,f,both=0,0,0,0

for i in range(n):
    m +=s[i].count("AB")
    if s[i][0]=="B":
        i +=1
        
    if s[i][-1]=="A":
        f +=1
        
    if s[i][0]=="B" and s[i][1]=="A":
        both+=1
        i-=1
        f-=1

if both!=0:
    if i!=0 and f!=0:
        print(m+both+min(i,f)-1)
    else:
        print(m+both+min(i,f))

else:
    print(min(i,f))

Submission status: Runtime Error

Solution code:
n,k = map(int,input().spolit())
print(n-k+1)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input() for _ in range(n))
m,i,f,both=0,0,0,0

for i in range(n):
    m +=s[i].count("AB")
    if s[i][0]=="B":
        i +=1
    if s[i][-1]=="A":
        f +=1
  

if both!=0:
    if i!=0 and f!=0:
        print(m+both+min(i,f)-1)
    else:
        print(m+both+min(i,f))

else:
    print(min(i,f))

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input() for _ in range(n))
m,i,f,both=0,0,0,0

for i in range(n):
    m +=s[i].count("AB")
   

if both!=0:
    if i!=0 and f!=0:
        print(m+both+min(i,f)-1)
    else:
        print(m+both+min(i,f))

else:
    print(min(i,f))

Submission status: Runtime Error

Solution code:
R, G, B, N = map(int, input().split())
ans = 0
for x in range(N // R + 1):
	for y in range(N // G + 1):
		if (N - R * x - G * y) % B == 0 and 0 <= (N - R * x - G * y) // B <= N // B:
			ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
r=int(math.sqrt(n))
ctr=0
for i in range(1,r+1):
    if n%i==0 and n//i>i:
        ctr+=n//i-1
print(ctr)

Submission status: Runtime Error

Solution code:
import numpy as np
    
n = int(input())
S = np.asarray([])
St = np.zeros(4) # None,B,A,BA
count = 0

for i in range(n):
    S=np.append(S,input())
    tmp = 0
    count += S[i].count("AB")
    if S[i][0] == "B":
        tmp += 1
    if S[i][-1] == "A":
        tmp += 2
    St[tmp]+=1

if (St[1] == 0)&(St[3]>0):
    St[1]+=1
    St[3]-=1

if (St[2] == 0)&(St[3]>0):
    St[2]+=1
    St[3]-=1

print(int(count+min(St[1],St[2])+St[3]))

Submission status: Runtime Error

Solution code:
    import numpy as np
        
    n = int(input())
    S = np.asarray([])
    St = np.zeros(4) # None,B,A,BA
    count = 0
     
    for i in range(n):
        S=np.append(S,input())
        tmp = 0
        count += S[i].count("AB")
        if S[i][0] == "B":
            tmp += 1
        if S[i][-1] == "A":
            tmp += 2
        St[tmp]+=1
     
    if (St[1] == 0)&(St[3]>0):
        St[1]+=1
        St[3]-=1
     
    if (St[2] == 0)&(St[3]>0):
        St[2]+=1
        St[3]-=1
     
    print(int(count+min(St[1],St[2])+St[3]))

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input() for _ in range(n))
m,i,f,both=0,0,0

for i in range(n):
    m +=s[i].count("AB")
    if s[i][0]=="B":
        i +=1
    if s[i][-1]=="A":
        f +=1
    if s[i][0]=="B" and s[i][1]=="A":
        both+=1
        i-=1
        f-=1

if both!=0:
    if i==0 and f==0:
        print(m+both+min(i,f)-1)
    else:
        print(m+both+min(i,f))

else:
    print(min(i,f))

Submission status: Runtime Error

Solution code:
N = int(input())
S = [str(input()) for i in range(N)]

ans = 0
firstB = 0
lastA = 0
cnt = 0
for s in S:
    if s[0] == 'B':
        firstB += 1
    if s[-1:] == 'A':
        lastA += 1

    if s[0] == 'B' and s[-1:] == 'A':
        cnt += 1

    ans += s.count('AB')
    
if cnt == max([firstB,lastA]):
    print(ans + cnt -1)
else:
    print(ans+ min([firstB,lastA]))

Submission status: Runtime Error

Solution code:
n=int(input())
count=countA=countB=countAB=0
for i in range(n):
    s=input()
    if "AB" in s:
        count+=1
    if s[-1]=="A":countA+=1
    if s[0]=="B":countB+=1
    if s[-1]=="A" and s[0]=="B":countAB+=1
print(countAB-1 if countA==countB==0 and countAB>0 else min(countA,countB)+countAB)

Submission status: Runtime Error

Solution code:
n=int(input())
count=countA=countB=countAB=0
for i in range(n):
    s=input()
    if "AB" in s:
        count+=1
    if s[-1]=="A":countA+=1
    if s[0]=="B":countB+=1
    if s[-1]=="A" and s[0]=="B":countAB+=1
print(countAB-1 if countA=countB=0 and countAB>0 else min(countA,countB)+countAB)

Submission status: Runtime Error

Solution code:
import math
n= int(input())
ans = 0
if math.sqrt(n) == int(math.sqrt(n)):
    for i in range(1,int(math.sqrt(n))):
        if (n-i) % i == 0:
            ans += (n-i) // i
else:
    for i in range(1,int(math.sqrt(n) + 1)):
        if (n-i) % i == 0:
            ans += (n-i) // i
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
def inpl(): return list(map(int, input().split()))

R, G, B, N = inpl()
ans = 0
for r in range(N//R + 1):
    for g in range(N//G + 1):
        tmp = N - R*r - G*g
        if tmp < 0:
            break
        if (tmp%B == 0):
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
R, G, B, N = map(int, input().split())

count = 0
for i in range(N // R + 1):
    n = N - R * i
    for j in range(n // G + 1):
        if (n - G*j) >= 0 and (n - G*j) % B == 0:
            count += 1

print(count)

Submission status: Runtime Error

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

r, g, b, n = map(int, input().split())

count = 0

for i in range(n//r+1):
    for j in range((n-i*r)//g+1):
        if (n - i*r - j*g) % b == 0:
            count += 1

# やってはいけないやつ
# for i in range(0, n+1):
#     for j in range(0, n+1):
#         for k in range(0, n+1):
#             if r*i + g*j + b*k == n:
#                 count += 1

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 0
x_max = (n+1/4)**(1/2) - 1/2
for x in range(1, int(x_max + 1)):

    m = (n-x) // x
    if (n-x) % x == 0 and x < m:
        ans += m


print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
strs=[]
ind_a=[]
ind_b=[]
ind_both=[]
num=0
for i in range(n):
   str=input()
   num=num+str.count("AB")
   if str[len(str)-1]=="A":
       if str[0]=="B":
           ind_both.append(i)
       else:
           ind_a.append(i)
   elif str[0]=="B":
       ind_b.append(i)
big=0
small=0
both=len(ind_both)
if len(ind_a) > len(ind_b):
    big=len(ind_a)
    small=len(ind_b)
else:
    big=len(ind_b)
    small=len(ind_a)
if (big-small)>=both:
    num=num+small+both
else:
    both=both-(big-small)+1
    num=num+big+int(both/2)
print(num)

Submission status: Runtime Error

Solution code:
# coding:utf-8

if __name__=="__main__":
  N = int(input())
  s = []
  a,b,ba=0,0,0
  count = 0
  for i in range(N):
      s.append(input())
      count += s.count('AB')
      if s[i][0]!='B' and s[i][-1]=='A': a+=1
      if s[i][0]=='B' and s[i][-1]!='A': b+=1
      if s[i][0]=='B' and s[i][-1]=='A': ba+=1
  if ba == 0:
      print(count+min(a,b))
  elif min(a,b)==0:
      print(count+ba-1)
  else:
      print(count+ba+min(a,b))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

n=int(input())

#normal, start_b, end_a, both

kosu=0
tokushu=[0,0,0,0]

for i in range(n):
    line=input()
    switch=0
    for l in range(len(line)):
        if switch==1:
            if line[l]=='B':
                kosu+=1
            else:
                switch=0
        if line[l]=='A':
            switch=1

    if line[0]=='B':
        if line[-1]=='A':
            tokushu[3]+=1
        else:
            tokushu[1]+=1
    else:
        if line[-1]=='A':
            tokushu[2]+=1
        else:
            tokushu[0]+=1

#print(kosu)
#print(tokushu)
kosu=0
tokushu=[1,1,2,3]
"""
if tokushu[3]>=1:
    mazu=tokushu[3]-1

else:
    mazu=0
"""
if tokushu[3]>=1:
    if tokushu[1]==0 and tokushu[2]==0:
        mazu=tokushu[3]-1
    else:
        mazu=tokushu[3]-1
        sukunai=min(tokushu[1],tokushu[2])
        mazu+=(sukunai+1)
else:
    mazu=min(tokushu[1], tokushu[2])

print(kosu+mazu)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for i in range(N)]
ABcount = 0
for i in s:
    ABcount += i.count("AB")
bvva = 0
bvvv = 0
vvva = 0
for i in s:
    if i[0] == "B" and i[-1] == "A":
        bvva += 1
    elif i[0] == "B":
        bvvv += 1
    elif i[-1] == "A":
        vvva += 1
if vvva != 0:
    if bvvv != 0:
        print(ABcount+bvva+1+(min(vvva-1,bvvv-1)))
    else:
        print(ABcount+bvva)
else:
    if bvvv != 0:
        print(ABcount+bvva)
    else:
        print(max(ABcount+bvva-1),0)

Submission status: Runtime Error

Solution code:
n = int( input() )

for i in range( 0, n ):
	m =  input() 
	print(m)
nm=0
nm1=0
cnt=m
for i in cnt:
      if i=='A' or i=='B':
              nm+=1
              nm1=max(nm1,nm)
      else:
              nm=0
print(nm1)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
cnt = 0
for i in range(1,int(math.sqrt(N))+1):
	if N % i == 0:		
		if N / i == i:
			cnt += i-1
		else:
			cnt += N/i-1
print(int(cnt))

Submission status: Runtime Error

Solution code:
import math
N = int(input())
n = int(math.sqrt(N))
if n * n != N:
    n += 1
ans = 0
for i in range(1, n):
    if N % i ==  0:
        ans += N // i - 1
if N <= 2:
    ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
R, G, B, N = map(int, input().split())

ans = 0
i = 0

while (i * R <= N):
  
  j = 0

  while (i * R + j * G <= N):

    tmp = N - (R * i) - (G * j)
    
    if tmp % B == 0 and tmp >= 0:
      ans += 1
      # print('{},{}'.format(i,j))
    j += 1
  
  i += 1

print('{0}'.format(ans))

Submission status: Runtime Error

Solution code:
r,g,b,n=list(map(int,input().split()))
i,j,k=0,0,0
R,G,B=0,0,0
c=0
while R<n:
    R=r*i
    while G<=n-R:
        G=g*j
        B,k=0,0
        while B<=n-R-G:
            B=b*k
            if n-R-G-B==0:
                c+=1
            k+=1
        j+=1
    i+=1
    G,j=0,0
print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
s_list = []
count = 0
n, m, l = 0, 0, 0

for i in range(N):
  s = input()
  s_list.append(s)
  count += s.count('AB')
  if s[0] == 'B' and s[-1] == 'A':
    n += 1
    continue
  elif s[-1] == 'A':
    m += 1
  elif s[0] == 'B':
    l += 1

if n < m and n < l:
  print(int(count + 2 * n + min(m - n, l - n)))
elif n > m and n > l:
  print(int(count + 2 * (n - max(m, l) + m + l)
else:
  print(int(count + min(n, m) + min(n, l)))

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
z =0

for i in range(1, n+1, 2):
    b = n//i
    c = n%i
    if b==c:
        a.append(i)
print(sum(a))

Submission status: Runtime Error

Solution code:
from math import sqrt 

n = int(input())

x = int(sqrt(n))
if n == 2:
    print(0)
    exit()
ans = n-1
for i in range(2, x+1):
    y = dt = n//i
    while n//dt == n//y and n%y <= n//y:
        if n//y == n%y:
            ans += y
            break
        y -= 1
        if y == 1:
            break
        # print x,y,ans
print(ans)

Submission status: Runtime Error

Solution code:
R,G,B,N = map(int,input().split())
a = sorted([R,G,B],reverse=True) 
R,G,B = a[0],a[1],a[2]

count = 0
for r in range(N//R+1):
  if r*R>N:break
  for g in range(N//G+1):
    if r*R+g*G>N: break
    for b in range(N//B+1):
      if  (r)*R+(g)*G+(b)*B == N:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
S = [input() for _ in range(n)]
cnt = 0
fb_cnt = 0
ba_cnt = 0
for s in S:
    idx = len(s) - 1
    for i in range(idx - 1):
        if s[i] == 'A' and s[i + 1] == 'B':
            cnt += 1
    if s[idx] == 'A':
        ba_cnt += 1
    if s[0] == 'B':
        fb_cnt += 1

min_cnt = min(fb_cnt, ba_cnt)
min_cnt = min_cnt - 1 if fb_cnt == ba_cnt else min_cnt
print(cnt + min_cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
cnt_AB = 0
end_A = 0
start_B = 0
start_B_and_end_A= 0
for i in range(N):
    s = input()
    cnt_AB += s.count('AB')
    if s[-1] == 'A' and s[0] == 'B':
        start_B_and_end_A += 1
    else:
        if s[-1] == 'A':
            end_A += 1
        if s[0] == 'B':
            start_B += 1
if end_A == 0 and start_B == 0:
    print(cnt_AB + start_B_and_end_A - 1)
else:
    print(cnt_AB + start_B_and_end_A + min(end_A, start_B))

Submission status: Runtime Error

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            # divisors.append(i)
            if i != n // i and i != (n // i - 1) :
                divisors.append(n//i - 1)
    return divisors

n = int(input())
print(sum(make_divisors(n)))

Submission status: Runtime Error

Solution code:
N = int(input())
stlist = []
bf = 0
al = 0
ab = 0
ba = 0
for i in range(N):
    tmp = input()
    ab += tmp.count("AB")
    if tmp[0] == 'B' and tmp[-1] == 'A':
        ba += 1
    elif tmp[0] =='B':
        bf+=1
    elif tmp[-1] =='A':
        al+=1
if al == 0 and bf ==0:
    print(ba-1+ab)
elif al * bf ==0:
    print(min(al-1, bf-1, 0) + ba + ab)
else:
    print(min(al-1, bf-1, 0) + ba +1 + ab)

Submission status: Runtime Error

Solution code:
N = int(input())
s_list = []
count = 0
n, m, l = 0, 0, 0

for i in range(N):
  s = input()
  s_list.append(s)
  count += s.count('AB')
  if s[0] == 'B' and s[-1] == 'A':
    n += 1
    continue
  elif s[-1] == 'A':
    m += 1
  elif s[0] == 'B':
    l += 1

if n < m and n < l:
  print(int(count + 2 * n + min(m - n, l - n)))
else:
  print(int(count + 2 * n))

Submission status: Runtime Error

Solution code:
n=int(input())
string_list=[input() for i in range(n)]
new_list = {}
target_chr = "AB"
count = 0
left_b_count = 0
right_a_count = 0
none_count = 0
for string in string_list:
    if string.count(target_chr) > 0 and (string[0] != "B" or string[-1] != "A"):
        count += string.count(target_chr)
        none_count += 1
        continue
    if string[0] == "B":
        left_b_count +=1
        count += string.count(target_chr)
        none_count += 1
        continue
    if string[-1] == "A":
        right_a_count += 1
        count += string.count(target_chr)
        none_count += 1
        continue

if left_b_count > right_a_count:
    if none_count == n:
        print(count + right_a_count)
    else:
        print(count + right_a_count + 1)
else:
    print(count + left_b_count)

Submission status: Runtime Error

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(input())

count_AB = 0
lefter_B = 0
righter_A = 0
only_lefter_B = 0
only_righter_A = 0
for i in range(N):
    count_AB += S[i].count('AB')
    if S[i][0] == 'B':
        lefter_B += 1
    if S[i][len(S[i])-1] == 'A':
        righter_A += 1
    if (S[i][0] == 'B')and(S[i][len(S[i])-1] != 'A'):
        only_lefter_B += 1
    if (S[i][0] != 'B')and(S[i][len(S[i])-1] == 'A'):
        only_righter_A += 1
        
if (only_lefter_B==0) and (only_righter_A==0):
    Appearing_AB = max(min(lefter_B,righter_A) - 1 , 0)
else:
    Appearing_AB = min(lefter_B,righter_A)


print(count_AB + Appearing_AB)

Submission status: Runtime Error

Solution code:
N = int(input())
S = []
a = 0
b = 0
both = 0
count = 0
for i in range(N):
    s = input()
    S.append(s)
    if "AB" in s:
        count += 1
    if s[0] == "B":
        b += 1
        if s[-1] == "A":
            both += 1
    if s[-1] == "A":
        a += 1
a -= both
b -= both
if a>0 and b>0:
    count += both+1 + min(a-1, b-1)
elif (a>0 and b==0) or (a==0 and b>0):
    count += both
else:
    count += both -1


print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = []
for i in range(N):
    S.append(str(input()))
    
start_b = 0
end_a = 0
both = 0
ab_count = 0
for i in S:
    if i[0]=="B":
        start_b = start_b + 1
    if i[-1]=="A":
        end_a = end_a + 1
    if i[0]=="B" and i[-1]=="A":
        both = both + 1
    ab_count = ab_count + i.count("AB")

additional = min(start_b, end_a)
if additional == both:
    additional = additional  - 1
ans = ab_count + additional
print(ans)

Submission status: Runtime Error

Solution code:
R,G,B,N = list(map(int,input().split()))
count = 0

for r in range(N+1):
    if r*R >= N+1:
        continue
    elif r*R == N:
        count += 1
        continue

    for g in range(N+1):
        if (r*R + g*G) >= N + 1:
            break
        elif (r*R + g*G) == N:
            count += 1
            break

        for b in range(N + 1):
            n = r * R + g * G + b * B
            if n == N:
                count += 1
                break

print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input() for _ in range(n))
m,i,f=0,0,0

for i in range(n):
    m +=s[i].count("AB")
    if s[i][0]=="B":
        i +=1
    if s[i][-1]=="A":
        f +=1
print(m+min(i,f))

Submission status: Runtime Error

Solution code:
n = int(input())
l = [input() for i in range(n)]
a = 0
b = 0
ba = 0
ab = 0
for i in range(n):
    if 'AB' in l[i]:
        for j in range(len(l[i])-1):
            if l[i][j] == 'A' and l[i][j+1] == 'B':
                ab += 1
    if l[i][0] =='B' and l[i][-1] == 'A':
        ba += 1
    elif l[i][-1] == 'A':
        a += 1
    elif l[i][0] == 'B':
        b += 1
if max(a,b) == 0　and ba <= 1:
    print(ab)
elif max(a,b) == 0:
    print(ab+ba-1)
else:
    print(min(a,b)+ab+ba)

Submission status: Runtime Error

Solution code:

v = [int(d) for d in input().split()]
f = []

for e in range(v[0]):
    f.append(input())
re = 0
for d in f:
    re += d.count('AB')
dd = [list(s) for s in f]


b = 0
a = 0
coo= 0

for q in dd:
    if q[0] == 'B':
        b += 1
    if q[-1] == 'A':
        a += 1
        if q[0] == 'B':
            coo += 1

if a > b:
    ss = b
elif a < b:
    ss = a
elif a == b:
    ss == a

if ss == coo:
    if ss == b:
        if ss == a:
            if ss != 0:
                ss -= 1
re = re + ss
print(re)

Submission status: Runtime Error

Solution code:

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

print(n-l+1)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[input() for i in range(n)]
ans=sum([s[i].count("AB") for i in range(n)])
a=[s[i].count("AB") for i in range(n)]
xxA=sum([1 if s[i][0]!="B" and s[i][-1]=="A"else 0 for i in range(n)])
Bxx=sum([1 if s[i][0]=="B" and s[i][-1]!="A" else 0 for i in range(n)])
BxA=sum([1 if s[i][0]=="B" and s[i][-1]=="A" else 0 for i in range(n)])
if abs(xxA-Bxx)>BxA:
    wer=min(xxA,Bxx)+BxA+1
else:
    wer=min(xxA,Bxx)+BxA
print(ans+wer)

Submission status: Runtime Error

Solution code:
# coding:utf-8

if __name__=="__main__":
  R,G,B,N = map(int, input().split())
  count = 0
  for r in range(int(N/R)+1):
    n1 = N - r*R
    for g in range(int(n1/G)+1):
      n2 = n1 - g*G
      if n2%B==0: count+= 1
  print(count)

Submission status: Runtime Error

Solution code:
l = raw_input().split()
N = int(l[0])
K = int(l[1])
count = 0
numbers = list(range(1, N+1))
while True:
    if len(numbers) >= K:
        numbers.pop(0)
        count = count + 1
    else:
        print(count)
        break

Submission status: Runtime Error

Solution code:
from pip._vendor.distlib.compat import raw_input

l = raw_input().split()
N = int(l[0])
K = int(l[1])
count = 0
numbers = list(range(1, N+1))
while True:
    if len(numbers) >= K:
        numbers.pop(0)
        count = count + 1
    else:
        print(count)
        break

Submission status: Runtime Error

Solution code:
import sys

N = int(sys.argv[1])
K = int(sys.argv[2])
count = 0
numbers = list(range(1, N+1))
while True:
    if len(numbers) >= K:
        numbers.pop(0)
        count = count + 1
    else:
        print(count)
        break

Submission status: Runtime Error

Solution code:
import sys

if __name__ == "__main__":
    N = int(sys.argv[1])
    K = int(sys.argv[2])
    count = 0
    numbers = list(range(1, N+1))
    while True:
        if len(numbers) >= K:
            numbers.pop(0)
            count = count + 1
        else:
            print(count)
            break

Submission status: Runtime Error

Solution code:
a = list(map(int, input().split()))
r = a[0]
g = a[1]
b = a[2]
n = a[3]
c = 0

for i in range(n+1):
    for j in range(n+1):
        k = (n - (r*i + g*j))//b
        if k >= 0:
            if n == r*i + g*j + b*k:
                c += 1
print(c)