Harryxun/stf_run huggingface dataset:
n = int(input())

colors = list(map(int,input().split()))

col_n = [0]*9

for c in colors:
    if c >= 1 and c <= 399:
        col_n[0] += 1
    elif c >= 400 and c <= 799:
        col_n[1] += 1
    elif c >= 800 and c <= 1199:
        col_n[2] += 1
    elif c >= 1200 and c <= 1599:
        col_n[3] += 1
    elif c >= 1600 and c <= 1999:
        col_n[4] += 1
    elif c >= 2000 and c <= 2399:
        col_n[5] += 1
    elif c >= 2400 and c <= 2799:
        col_n[6] += 1
    elif c >= 2800 and c <= 3199:
        col_n[7] += 1
    else:
        col_n[8] += 1

if col_n[8] == 0:
    print(8-col_n[:8].count(0),8-col_n[:8].count(0))

else:
    if 8-col_n[:8].count(0) >= col_n[8]:
        print(8-col_n[:8].count(0),(8-col_n[:8].count(0)+col_n[8]))
    
    else:
        print(col[8],(8-col_n[:8].count(0))+col_n[8])


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))

color_n = [0 for i in range(9)]

for i in a:
    if 1 <= i <= 399:
        color_n[0] += 1
    
    elif 400 <= i <= 799:
        color_n[1] += 1
    
    elif 800 <= i <= 1199:
        color_n[2] += 1
    
    elif 1200 <= i <= 1599:
        color_n[3] += 1
    
    elif 1600 <= i <= 1999:
        color_n[4] += 1
    
    elif 2000 <= i <= 2399:
        color_n[5] += 1
    
    elif 2400 <= i <= 2799:
        color_n[6] += 1
    
    elif 2800 <= i <= 3199:
        color_n[7] += 1
    
    else:
        color_n[8] += 1

print(max(8-color_n[:-1].count(0), 1),8-color_n[:-1].count(0)+color_n[-1])
A,B,C=map(int,input())
if(A+B>=C+1):
  print(B+C)
else:
  print(B+A+B+1)

### FIXED CODE ###

A,B,C=map(int,input().split())
if(A+B>=C-1):
  print(B+C)
else:
  print(B+A+B+1)
X=int(input())
five=[i**5 for i in range(100) ]
flg=0
for i in range(len(five)):
    for j in range(len(five)):
        if five[i]+five[j]==X:
            flg=1
            ans_1=i
            ans_2=-j
        if five[i]-five[j]==X:
            ans_1=i
            ans_2=j
print(ans_1,ans_2)

### FIXED CODE ###

X=int(input())
five=[i**5 for i in range(1000) ]
flg=0
for i in range(len(five)):
    for j in range(len(five)):
        if five[i]+five[j]==X:
            flg=1
            ans_1=i
            ans_2=-j
        if five[i]-five[j]==X:
            ans_1=i
            ans_2=j
print(ans_1,ans_2)
def dfs(num,lis,count,target):
    visited[num]=count
    n_city=A[num]
    if visited[n_city]!=-1:
        lis.append(num)
        if target<=count:
              print(lis[target]+1)
        else:
            rep=len(lis)-visited[n_city]
            target-=visited[n_city]
            amari=target%rep
            temp=lis[visited[n_city]:]
            print(temp[amari]+1)
        exit()
    else:
        dfs(n_city,lis+[num],count+1,target)
    

N,K=map(int,input().split())
A=list(map(int,input().split()))
A=list(map(lambda x:x-1,A))

visited=[-1]*N

dfs(0,[],0,K)

### FIXED CODE ###

import sys

sys.setrecursionlimit(10**9)

def dfs(num,lis,count,target):
    visited[num]=count
    n_city=A[num]
    if visited[n_city]!=-1:
        lis.append(num)
        if target<=count:
              print(lis[target]+1)
        else:
            rep=len(lis)-visited[n_city]
            target-=visited[n_city]
            amari=target%rep
            temp=lis[visited[n_city]:]
            print(temp[amari]+1)
        exit()
    else:
        lis.append(num)
        dfs(n_city,lis,count+1,target)
    

N,K=map(int,input().split())
A=list(map(int,input().split()))
A=list(map(lambda x:x-1,A))

visited=[-1]*N

dfs(0,[],0,K)
a = int(input())
b = int(input())

if a>b:
    print("GREATER")
elif a<b:
    print("LESS")
else:
    prin("EQUAL")

### FIXED CODE ###

a = int(input())
b = int(input())

if a>b:
    print("GREATER")
elif a<b:
    print("LESS")
else:
    print("EQUAL")
# coding: utf-8

import math
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

first_gcd = A[0]
for i in range(len(A)):
    first_gcd = math.gcd(first_gcd, A[i])

print(first_gcd)



### FIXED CODE ###

# coding: utf-8

import sys
input = sys.stdin.readline

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

N = int(input())
A = list(map(int, input().split()))

first_gcd = A[0]
for i in range(len(A)):
    first_gcd = gcd(first_gcd, A[i])

print(first_gcd)
N, M = map(int,input().split())

H = [0] + list(map(int,input().split()))

path = [0]
for i in range(1,N+1):
	path.append([])

for i in range(1,M+1):
	A, B = map(int,input().split())
	path[A].append(B)
	path[B].append(A)

count = 0

for i in range(1,N+1):
	if H[i] > max(H[j] for j in path[i]):
		count += 1
	
print(count)

### FIXED CODE ###


N, M = map(int,input().split())

H = [0] + list(map(int,input().split()))

path = [0]
for i in range(1,N+1):
	path.append([])

for i in range(1,M+1):
	A, B = map(int,input().split())
	path[A].append(B)
	path[B].append(A)

count = 0

for i in range(1,N+1):
	if len(path[i]) == 0:
		count += 1
	elif H[i] > max(H[j] for j in path[i]):
		count += 1
	
print(count)
a,b=map(int,input().split())
grid=[["."]*(a+2)]+[list("."+input()+".")for i in range(b)]+[["."]*(a+2)]
for s in range(1,1+a):
    for t in range(1,1+b):
        if grid[s][t]=="#" and all([grid[s+x][t+y]=="."for x,y in ([0,-1],[0,1],[1,0],[-1,0])]):
            print("No")
            exit()
print("Yes")

### FIXED CODE ###

h,w=map(int,input().split())
grid=[["."]*(w+2)]+[list("."+input()+".")for i in range(h)]+[["."]*(w+2)]
for s in range(1,1+h):
    for t in range(1,1+w):
        if grid[s][t]=="#" and all([grid[s+x][t+y]=="."for x,y in ([0,-1],[0,1],[1,0],[-1,0])]):
            print("No")
            exit()
print("Yes")
import math
a = int(input())
data_size = int (math.log10(a) + 1)
if a == 100000:
    print(90909)
elif data_size == 5:
    print(a - 10000 + 1 + 909)
elif data_size == 4:
    print(909)
elif data_size == 3:
    print(a - 100 + 1 + 9)
elif data_size == 2:   
    print(9)
elif data_size == 1:   
    print(a - 1 + 1)

### FIXED CODE ###

a,b,c=(int(x) for x in input().split())
if ((c - (a - b)) < 0):
    print(0)
else:
    print(c - (a - b))
K,S=map(int,input().split())
print(sum(1for x in range(K+1)for y in range(K+1)if0<=S-x-y<=K))


### FIXED CODE ###

K,S=map(int,input().split())
cnt=0
for x in range(K+1):
  for y in range(K+1):
    z = S - x - y
    if 0 <= z <= K:
      cnt+=1
print(cnt)
h, w = (list)(map(int, input().split()))
l = [[lin for lin in input()] for _ in range(h)]

gri = [[0 for i in range(w+2)] for _ in range(h+2)]
for i in range(h+2):
    for j in range(w+2):
        if i == 0 or i == h+1 or j == 0 or j == w+1:
            gri[i][j] = '.'
        else:
            gri[i][j] = l[i-1][j-1]

for i in range(1, h+1):
    for j in range(1, w+1):
        if gri[i][j] == '#' and gri[i-1][j] == '.' and gri[i+1][j] == '.' and gri[i][j-1] == '.' and gri[i][j+1] == '.':
            print("No")
            exit(1)

print("Yes")
# print(l)
# print(gri)


### FIXED CODE ###

h, w = (list)(map(int, input().split()))
l = [[lin for lin in input()] for _ in range(h)]

gri = [['.' for i in range(w+2)] for _ in range(h+2)]
for i in range(1, h+1):
    for j in range(1, w+1):
        gri[i][j] = l[i-1][j-1]

flag = 1
for i in range(1, h+1):
    for j in range(1, w+1):
        if gri[i][j] == '#':
            if gri[i-1][j] == '.' and gri[i+1][j] == '.' and gri[i][j-1] == '.' and gri[i][j+1] == '.':
                flag = 0
if flag == 1:
    print("Yes")
else:
    print("No")
a,b ,k = map(int,input().split())
cnt = 0
for i in range(1,min(a,b)+1):
  if a%i == 0 and b%i == 0:
    cnt +=1
 	if cnt == k:
      print(i)
      exit()


### FIXED CODE ###

a,b,k = map(int,input().split())
c = []
for i in range(min(a,b)+1):
  if a%(i+1) == 0 and b%(i+1) == 0:
    c.append(i+1)
c.sort(reverse = True)
print(c[k-1])
A, B, C, D, E, F = map(int, input().split(' '))
maxconc = 0.0
maxwater = 100*A
maxconc = 0

for i in range(F//(100*A)+1):
  for j in range((F-100*A*i)//(100*B)+1):
    if i == 0 and j == 0:
      continue
    S =min(E*(A*i+B*j),F-100*(A*i+B*j))
    
    sugar=0
    for c in range(S//C+1):
      d = (S-c*C)//D
      sugar = max(sugar,c*C+d*D)
    conc = sugar / (sugar +100*(A*i+B*j))
    if conc > maxconc:
      maxconc = conc 
      maxwater = 100*(A*i+B*j)
      maxsugar = sugar
print('{0} {1}'.format(maxwater+maxsugar,maxsugar))    

### FIXED CODE ###

A, B, C, D, E, F = map(int, input().split(' '))

max_sugar = 0
max_water = 100*A
max_conc = 0.0
A_limit = F // (100*A)
for i in range(A_limit + 1):
    B_limit = (F-100*A*i) // (100*B)
    for j in range(B_limit + 1):
        if i == 0 and j == 0:
            continue
        sugar_limit = min(E * (A*i+B*j), F-100*(A*i+B*j))

        sugar_ = 0
        for c in range(sugar_limit//C + 1):
            d = (sugar_limit-c*C)//D
            temp_sugar = c*C + d*D
            sugar_ = max(sugar_, temp_sugar)
        temp_conc = sugar_/(sugar_+100*(A*i+B*j))
        if temp_conc > max_conc:
            max_conc = temp_conc
            max_water = 100*(A*i + B*j)
            max_sugar = sugar_
print('{0} {1}'.format(max_water+max_sugar, max_sugar))
N, K = map(int,input().split())
max=0
t=list(input().split())
for i in range(N-K+1):
    x=0
    for j in range(K):
        x+=int(s[i+j])
    if max<x :
        max=x
print((max+K)/2)

### FIXED CODE ###

N, K = map(int,input().split())
t=list(input().split())
s=[int(n) for n in t]
max=x=sum(s[:K])
for i in range(N-K):
    x+=(s[K+i]-s[i])
    if max<x :
        max=x
print((max+K)/2)
# https://atcoder.jp/contests/abc067/tasks/arc078_b

from collections import deque

N = int(input())
E = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

def dist_from_X(X):
    dist = [-1] * N
    
    que = deque([X])
    dist[X] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for e in E[v]:
            if dist[e] > -1:
                continue
            dist[e] = d + 1
            que.append(e)
    
    return dist

Fennec = dist_from_X(0)
Sunuke = dist_from_X(N-1)

cnt = [0,0]
for i,j in zip(Fennec, Sunuke):
    if i <= j:
        cnt[0] += 1
    else:
        cnt[1] += 1

assert cnt[0] != cnt[1]
if cnt[0] > cnt[1]:
    print("Fennec")
else:
    print("Sunuke")

### FIXED CODE ###

import numpy as np
from collections import deque

N = int(input())
E = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

# BFS
def dist_from_X(X:int):
    dist = np.full(N, -1)
    que = deque([X])
    dist[X] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for e in E[v]:
            if dist[e] > -1:
                continue
            dist[e] = d + 1
            que.append(e)
    return dist

Fennec = dist_from_X(0)
Sunuke = dist_from_X(N-1)

cnt = np.count_nonzero(Fennec <= Sunuke)

if cnt > N - cnt:
    print("Fennec")
else:
    print("Snuke")
a_b = list(map(int, input()))
i=1
sum = a_b[0]
if sum<=a_b[1]:
	for sum>=a_b[1]:
		sum+=a_b[0]-1
		i++
print(i)

### FIXED CODE ###

a,b = map(int, input().split())
i=0
sum = 1

while sum<b:
	sum+=a-1
	i+=1
print(i)
N,x = (int(i) for i in input().split())
L = [int(i) for i in input().split()] 
result = 0
D = 0
for i in range(N + 1):
    if D <= X:
        result += 1
    if i != N:
        D += L[i]
print(result)

### FIXED CODE ###

N,X = (int(i) for i in input().split())
L = [int(i) for i in input().split()] 
result = 0
D = 0
for i in range(N + 1):
    if D <= X:
        result += 1
    if i != N:
        D += L[i]
print(result)
number = list(map(int,input().split()))
line = list(map(int,input().split()))

num = number[0]
K = number[1]
dp = [0, abs(line[1] - line[0])]
for i in range(2, num):
  line2 = []
  for k in range(1, K + 1):
    a = dp[-k] + abs(line[i] - line[i - k])
    line2.append(a)
  dp += [min(line2)]
print(dp[-1])

### FIXED CODE ###

def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()
if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    adj_mat = [[0 for i in range(N)] for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        adj_mat[a-1][b-1] = 1
        adj_mat[b-1][a-1] = 1
    num = 0
    for i in range(N):
        h = H[i]
        for j in range(N):
            if adj_mat[i][j] == 1:
                flag = True
                if h < H[j]:
                    flag = False
                    break
        if flag:
            num += 1
    print(num)

### FIXED CODE ###

if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    H = list(map(int, input().split()))
    adj_max = [0 for i in range(N)]
    for i in range(M):
        a, b = list(map(int, input().split()))
        if adj_max[a-1] < H[b-1]:
            adj_max[a-1] = H[b-1]
        if adj_max[b-1] < H[a-1]:
            adj_max[b-1] = H[a-1]
    num = 0
    for i in range(N):
        if H[i] > adj_max[i]:
            num += 1
    print(num)
N,M,Q=map(int,input().split())
a=[0]*Q
b=[0]*Q
c=[0]*Q
d=[0]*Q
for i in range(Q):
  a[i],b[i],c[i],d[i]=map(int,input().split())
import itertools
for A in itertools.combinations_with_replacement(range(1,M+1),N):
    ans=0
    if i in range(Q):
        s=0
        A[b[i]]-A[a[i]]=c[i]
        s+=d[i]
        ans=max(ans,s)
print(ans)   

### FIXED CODE ###

N,M,Q=map(int,input().split())
a=[0]*Q
b=[0]*Q
c=[0]*Q
d=[0]*Q
for i in range(Q):
  a[i],b[i],c[i],d[i]=map(int,input().split())
import itertools
ans=0
for A in itertools.combinations_with_replacement(range(1,M+1),N):
    A=list(A)
    s=0
    
    for i in range(Q):
        if A[b[i]-1]-A[a[i]-1]==c[i]:
           s+=d[i]

           ans=max(ans,s)
print(ans)
D,G = map(int,input().split())
P = []
C = []
for i in range(D):
    p, c = map(int,input().split())
    P.append(p)
    C.append(C)
    s += p

#dp[i][j] = i問目まででj枚使った時の点数のmax
dp = [[0 for in range(s+1)] for j in range(D+1)]
for i in range(D):
    p = P[i]
    c = C[i]
    t = 100*i
    for j in range(s+1):
        for k in range(p+1):
            if k = p:
                if j >= k:
                dp[i+1][j] = max(dp[i+1][j],dp[i][j-k]+c)
            else:
                if j >= k:
                    d[i+1][j] = max(dp[i][j-k]+t*k,dp[i+1][j])
                else:
                    break
for i in range(s+1):
    if d[N][i] >= G:
        ans = i
print(ans)
                
            

### FIXED CODE ###

D,G = map(int,input().split())
P = [0]*D
C = [0]*D
for i in range(D):
    P[i], C[i] = map(int,input().split())
s = sum(P)

#dp[i][j] = i問目まででj枚使った時の点数のmax#
dp = [[0 for i in range(s+1)] for j in range(D+1)]
for i in range(D):
    p = P[i]
    c = C[i]
    t = 100*(i+1)
    for j in range(s+1):
        for k in range(p+1):
            if k == p:
                if j >= k:
                    dp[i+1][j] = max(dp[i+1][j],dp[i][j-k]+c+t*k)
            else:
                if j >= k:
                    dp[i+1][j] = max(dp[i][j-k]+t*k,dp[i+1][j])
                else:
                    break
for i in range(s+1):
    if dp[D][i] >= G:
        ans = i
        break
print(ans)
n=int(input())
h=list(map(int,input().split()))
mn=min(h)
cnt=1
if(mn!=1):
    print("-1")
    exit()
r=len(h)
for i in range(len(h)):
    if(len(h)==1):
        break
    cnt=cnt+h.index(i+1)-1
    del h[0:h.index(i+1)]
print(cnt)


### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
mn=min(h)
cnt=0
if(mn!=1):
    print("-1")
    exit()
i=1
for k in h:
    if(k==i):
        i=i+1
    else:
        cnt=cnt+1
print(cnt)
L,R= map(int, input().split())
d = input()
 
for L in range(R):
  if(i%d == 0) cnt++
  
print(cnt)

### FIXED CODE ###

L,R,d=map(int, input().split())
cnt=0
 
for i in range(L, R+1):
  if i%d == 0: cnt+=1
  
print(cnt)
N,A = map(int,input().split())
if N%500<=A:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

N,A=int(input()),int(input())
print('Yes' if N%500<=A else 'No')
a = int("input()")/3600
a_p = int(input())%3600
b = a_p/60
b_p = a_p%60
print a,":",b,":",b_p

### FIXED CODE ###

int = int(input())

h = int // 3600
h_mod = int % 3600

m = h_mod // 60
s = h_mod % 60

print(h, ":", m, ":", s, sep='')
import sys
K = int(sys.stdin.readline())
A, B = map(int,sys.stdin.readline().split() )
for i in range(A,B+1):
    if i%K==0:
        return "OK"
    return "NG"

### FIXED CODE ###

K=int(input())
A,B = map(int, input().split())
count=0
for i in range(A,B+1):
    if i%K==0:
        print("OK")
        count+=1
        break
if count==0:
    print("NG")
import numpy
import copy
N = int(input())
E= list(map(int,input().split()))
ans = [0 for _ in range(N)]
unique = numpy.unique(E)
#for s in range(len(unique)):
#unique = int(unique)
uniqueNum = [0 for _ in range(len(unique))]

uniqueAns = [0 for _ in range(len(unique))]

y =0
for t in range(len(unique)):
    uniqueNum[t] = E.count(unique[t])
for g in range(len(unique)):
    uni = copy.copy(uniqueNum)
    uni[g] = uni[g] -1
    for h in range(len(unique)):
        y = y + uni[h] * (uni[h]-1)/2
    uniqueAns[g] =  y
for k in range(N):
    for w in range(len(uni)):
        if unique[w] == E[k]:
            ans[k] = uniqueAns[w]
            break
for i in range(N):
    print(int(ans[i]))

### FIXED CODE ###

S = input().split()
N = int(S[0])
M = int(S[1])

print(int(N * (N-1)/2 + M * (M-1)/2))
import random

def is_prime(q,k=50):
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

n,m=(int(i) for i in input().split(' '))

if n==1:
  print(m)
  exit()
if True:
  for i in range(1,n):
    if m%i==0 and is_prime(m//i) and m//i>n:
      print('1')
      exit()
for i in range(1,m//n+1)[::-1]:
  if i==1:
    print(i)
    break
  if m%i==0 and m//i>=n:
    print(i)
    break


### FIXED CODE ###

N = int(input())
if N == 1:
    print('Hello World')
elif N == 2:
    A = int(input(''))
    B = int(input(''))
    print(A + B)
A,B,K = list(map(int,input().split(" ")))

takahashi = A
aoki = B

if A >= K:
  print(A-k, B)
elif A + B >= K:
  print(0, A+B-K)
else:
  print("0 0")

### FIXED CODE ###

A,B,K = list(map(int,input().split(" ")))

if A >= K:
  print(A-K, B)
elif A + B >= K:
  print(0, A+B-K)
else:
  print("0 0")
n = int(input())
a = list(map(int,input().split()))

b = mean(a)//1

co = 10**9
su = 0
for k in range(3):
    for i in a:
        su += abs(i-b+(k-1)) ** 2
    co = min(co,su)
    su = 0

print(co)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))

b = sum(a)//n

co = 10**9
su = 0
for k in range(3):
    for i in a:
        su += abs(i-b+(k-1)) ** 2
    co = min(co,su)
    su = 0

print(co)
import collections
N = int(input())
V = input().split(' ')

EVEN = V[0::2]
ODD = V[1::2]
EVEN_V = collections.Counter(EVEN)
ODD_V = collections.Counter(ODD)
Count_EVEN_V = EVEN_V.most_common()
Count_ODD_V =ODD_V.most_common()


if Count_EVEN_V[0][1] >= Count_ODD_V[0][1]:
  MAX_ELE = Count_EVEN_V[0][0]
  count_max = Count_EVEN_V[0][1]
  for i in range(int(N/2)):
    if MAX_ELE != Count_ODD_V[i][1]:
      SECOND_ELE = Count_ODD_V[i][0]
      count_SEC = Count_ODD_V[i][1]
      break
    else:
      pass
  
else:
  MAX_ELE = Count_ODD_V[0][0]
  count_max = Count_ODD_V[0][1]
  for i in range(N/2):
    if MAX_ELE != Count_EVEN_V[i][1]:
      SECOND_ELE = Count_EVEN_V[i][0]
      count_SEC = ount_EVEN_V[i][1]
      break
    else:
      pass
print((N- int(count_max) - int(count_SEC)))

  

### FIXED CODE ###

from collections import Counter
N = int(input())
V = input().split(' ')
V_even = V[1::2]
V_odd = V[0::2]
#偶数列の要素を数え上げ
V_even_Count = Counter(V_even)
#奇数列の数え上げ
V_odd_Count = Counter(V_odd)

#偶数列の格納
X = []
for x in V_even_Count.most_common(2):
  X.append(x)
if len(X) == 1:
  X.append(('i',0))
#奇数列の格納
Y = []
for y in V_odd_Count.most_common(2):
  Y.append(y)
if len(Y) == 1:
  Y.append(('j',0))

A,B,C,D = X[0],X[1],Y[0],Y[1]
if A[0] != C[0]:
  print(N-A[1]-C[1])
else:
  if B[1] <= D[1]:
    print(N-A[1]-D[1])
  else:
    print(N-B[1]-C[1])
X, Y = map(int, input().split())

def rec(x, y) :
    flg = False
    for i in range(2, x + 1, 2) :
        flg = flg or not rec(x-i, y+i//2)
    for i in range(2, y + 1, 2) :
        flg = flg or not rec(x+i//2, y-i)
        
    return flg
    
if rec(X, Y) :
    print('Alice')
else :
    print('Brown')

### FIXED CODE ###

X, Y = map(int, input().split())

if abs(X-Y) <= 1 :
    print('Brown')
else :
    print('Alice')
N = int(input())
A = [int(input()) for _ in range(N)]

c = 0
n = 1
checked = [False for _ in range(N)]
checked[0] = True
for _ in range(N+1):
    n = A[n-1]
    c += 1
    if n == 2:
        ok = True
        break
    if checked[n-1]:
        ok = False
        break
if ok:
    print(c)
else:
    print(-1)

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

c = 0
n = 1
checked = [False for _ in range(N)]
checked[0] = True
for _ in range(N+1):
    n = A[n-1]
    c += 1
    if n == 2:
        ok = True
        break
    if checked[n-1]:
        ok = False
        break
    checked[n-1] = True
if ok:
    print(c)
else:
    print(-1)
a = int(input())/3600
a_p = int(input())%3600
b = a_p/60
b_p = a_p%60
print a,":",b,":",b_p

### FIXED CODE ###

int = int(input())

h = int // 3600
h_mod = int % 3600

m = h_mod // 60
s = h_mod % 60

print(h, ":", m, ":", s, sep='')
import numpy as np
import pandas as pd

N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
ans=0
if N % 2 == 0:
    ans = 2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2 - 1])) + A[N // 2] - A[N // 2 - 1]
else:
    x = 2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2 - 1])) - A[N // 2] - A[N // 2 - 1]
    y = 2 * (sum(A[N // 2 + 2:]) - sum(A[:N // 2])) + A[N // 2] + A[N // 2 + 1]
    ans = max(x, y)
print(ans)

### FIXED CODE ###

s = input()
ans = []
if len(s) == 2:
    print(s)
elif len(s) == 3:
    for i in range(len(s)):
        ans.append(s[2-i])
    ans_ = map(str, ans)
    print("".join(ans_))
n=[]
line=''
while line != [0,0]:
    line=list(map(int,input().split()))
    n.append(line)
for i in range(len(n)-1):
    print('%d %d'%(n[i][0] if n[i][0]>=n[i][1] else n[i][1],n[i][0] if n[i][0]<=n[i][1] else n[i][1]))javascript:void(0)

### FIXED CODE ###

n=[]
line=''
while line != [0,0]:
    line=list(map(int,input().split()))
    n.append(line)
for i in range(len(n)-1):
    print('%d %d'%(n[i][0] if n[i][0]<=n[i][1] else n[i][1],n[i][0] if n[i][0]>=n[i][1] else n[i][1]))
# -*- coding: utf-8 -*-
import sys
from collections import deque
from math import sqrt, gcd
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]

# n = int(input())



def solve():
    n = int(input())
    ans = 0
    a = 0
    b = 0
    for _ in range(n):
        s = input()
        a += s[-1] == 'A'
        b += s[0] == 'B'
        ans += s.replace('AB', "*").count('*')
    print(ans + min(a, b))
    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()




"""




"""



### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque
from math import sqrt
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]

# n = int(input())



def solve():
    n = int(input())
    ans = 0
    a = 0
    b = 0
    c = 0
    for _ in range(n):
        s = input()
        a += s[-1] == 'A' and s[0] != 'B'
        b += s[0] == 'B' and s[-1] != 'A'
        c += s[0] == 'B' and s[-1] == 'A'
        ans += s.replace('AB', "*").count('*')
    if (a+b) > 0:
        print(ans + c + min(a, b))
    else:
        if c:
            c -= 1
        print(ans + c)
    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()




"""




"""
s1=input()
s2=input()
if s1[0] == s2[2] and s1[1]==s2[1] and s1[2]==s[0]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s1=input()
s2=input()
if s1[0] == s2[2] and s1[1]==s2[1] and s1[2]==s2[0]:
  print("YES")
else:
  print("NO")