Harryxun/stf_run huggingface dataset:
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 01:03:03 2018

@author: Yuki
"""
import numpy as np

N = int(input())
A = sorted([int(i) for i in input().split()])
#N = 8
#A = sorted([2, 7, 1, 8, 2, 8, 1, 8])
A_uni = np.array(sorted(list(set(A))))
A = np.array(A)


tmp = 0
res_cnt = 0
i = 0
for i in range(len(A_uni)):
    tmp_number = A_uni[i]
    if len(A) <= tmp_number+1:
        res_cnt += len(A)
        break
    else:
        if A[tmp_number-1] != tmp_number:
            del_cnt = 1
            while True:
                if A[del_cnt] == tmp_number:
                    del_cnt += 1
                else:
                    res_cnt += del_cnt
                    A = A[del_cnt:]

                    break
        else:
            if A[tmp_number] != tmp_number:
                A = A[tmp_number:]
            else:
                A = A[tmp_number:]
                del_cnt = 1
                while True:
                    if A[del_cnt] != tmp_number:
                        A = A[del_cnt:]
                        res_cnt += del_cnt
                        break
                    else:
                        del_cnt += 1
                    
print(res_cnt)

    
    


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 01:03:03 2018

@author: Yuki
"""


N = int(input())
A = sorted([int(i) for i in input().split()])
import collections
#N = 5
#A = sorted([2, 4, 1, 4, 2])
cnt_dict = collections.Counter(A)
res_cnt = 0
for key in cnt_dict.keys():
    if key == cnt_dict[key]:
        pass
    else:
        if key < cnt_dict[key]:
            res_cnt += cnt_dict[key] - key
        else:
            res_cnt += cnt_dict[key]
print(res_cnt)
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
tmp = 1000000
ans = 0
for i in range(n):
  c = t - h[i] * 0.006
  d = a - c
  if d < 0:
    d = -d
  if d < tmp:
    tmp = d
    ans = i + 1
print(ans)

### FIXED CODE ###

X,Y = map(int, input().split())
print(int (X + Y/2))
def main():
    c=[[0]*3001for _ in range(3001)]
    h,w,k=map(int,input().split())
    for i in range(k):
        y,x,v=map(int,input().split())
        c[y][x]=v
    dp=[[0]*(w+1)for _ in range(h+1)]
    for i in range(1,h+1):
        x=y=z=p=0
        for j in range(1,w+1):
            v=c[i][j]
            if v>x:x,y,z=v,x,y
            elif v>y:y,z=v,y
            elif v>z:z=v
            if x+y+z+p<=dp[i-1][j]+v:
                x,y,z=v,0,0
                p=dp[i-1][j]
            dp[i][j]=x+y+z+p
    a=dp[h][w]
    dp=[[[0]*(w+1)for _ in range(h+1)]for _ in range(4)]
    for i in range(1,h+1):
        for j in range(1,w+1):
            x=max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
            for k in range(4):
                if k:dp[k][i][j]=max(dp[k][i][j-1],dp[k-1][i][j-1]+c[i][j])
                else:dp[k][i][j]=max(dp[k][i][j-1],x)
            dp[1][i][j]=max(dp[1][i][j],x+c[i][j])
    if a<max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w]):1/0
    else:print(a)
main()

### FIXED CODE ###

c=[[0]*3001for _ in range(3001)]
dp=[[[0]*3001for _ in range(3001)]for _ in range(4)]
h,w,k=map(int,input().split())
for i in range(k):
    y,x,v=map(int,input().split())
    c[y][x]=v
for i in range(1,h+1):
    for j in range(1,w+1):
        x=max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
        for k in range(4):
            if k:dp[k][i][j]=max(dp[k][i][j-1],dp[k-1][i][j-1]+c[i][j])
            else:dp[k][i][j]=max(dp[k][i][j-1],x)
        dp[1][i][j]=max(dp[1][i][j],x+c[i][j])
print(max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w]))
def factorial(x):
  if x == 1: return 1
  else: return x*factorial(x-1)
 
n = int(input())
n_bikkuri = factorial(n)
 
total = 1
 
for i in range(2, n_bikkuri+1):
  n_b = n_bikkuri
  while(not n_b % i):
    total += 1
    n_b /= i
  
print(total % (1e9+7))

### FIXED CODE ###

mod = 1000000000 + 7

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

n = int(input())
dat = [0] * 2000 # 約数として求められたある数の合計

# N! の各要素の素因数分解をする
res = 1
for i in range(1, n + 1):
    d = factorization(i)
    for j in range(len(d)):
        dat[d[j][0]] += d[j][1]

for i in range(2, n + 1):
    res *= (dat[i] + 1)
    res %= mod

print(res)
A,B,C,D = map(int,input().split())
op =['+','-']
ops = []
for a in op:
  for b in op:
    for c in op:
        ops.append(a + b + c)
        
for op in ops:
  S = "{1}{2}{3}{4}{5}{6}{7}".format(A,op[0],B,op[1],C,op[2],D)
  if eval(S) == 7:
    print("{}=7".format(S))
    break

### FIXED CODE ###

N = input()
N = [int(n) for n in N]
A,B,C,D = N
op =['+','-']
ops = []
for a in op:
  for b in op:
    for c in op:
        ops.append(a + b + c)
        
for op in ops:
  S = "{}{}{}{}{}{}{}".format(A,op[0],B,op[1],C,op[2],D)
  if eval(S) == 7:
    print("{}=7".format(S))
    break
a, b = map(int, input().split())
if a <= 8 and b <= 8:
  print("Yay!")
elif:
  print(":(")


### FIXED CODE ###

a, b = map(int, input().split())
if a <= 8 and b <= 8:
  print("Yay!")
else:
  print(":(")
import math

I=list(map(int,input().split()))
X=(2*I[1]-I[0])//3
Y=(2*I[0]-I[1])//3
n=X+Y
r=X

if ((X<0 or Y<0) or (X+Y)%3!=0):
    print(0):
    exit()

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

print(cmb(n, r, p))

### FIXED CODE ###

import math

I=list(map(int,input().split()))
X=(2*I[1]-I[0])//3
Y=(2*I[0]-I[1])//3
n=X+Y
r=X

if (X<0 or Y<0 or (I[0]+I[1])%3!=0):
    print(0)
    exit()

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

print(cmb(n, r, p))
A,P=map(int,input().split())
B=(3A+P)//2
print(B)

### FIXED CODE ###

A,P=map(int,input().split())
B=(3*A+P)//2
print(B)
N = int(input())

x_list=[]
y_list=[]
h_list=[]

def all_same(items):
	return all(map(lambda x: x == items[0], items))

for i in range(N):
	x,y,h=map(int, input().split())
	x_list.append(x)
	y_list.append(y)
	h_list.append(h)
	
if h_list[0] == 0:
	h_list[0], h_list[1]=h_list[1], h_list[0]	
	x_list[0], x_list[1]=x_list[1], x_list[0]
	y_list[0], y_list[1]=y_list[1], y_list[0]		
		
for cy in range(101):
	for cx in range(101):
		H_list = []
		for i in range(N):
			if h_list[i] != 0:
				H = abs(cx - x_list[i])+abs(cy - y_list[i])+h_list[i]
				H_list.append(H) 
			if h_list[i] == 0:
				h_mathematical=H_list[0]-abs(cx-x_list[i])-abs(cy-y_list[i])
				if h_mathematical > 0:
					break 
		if len(H_list) == N:
			if all_same(H_list):
				print(str(cx)+' '+str(cy)+' '+str(H_list[0]))
				break		
	else:
		continue
	break

### FIXED CODE ###

N = int(input())

x_list=[]
y_list=[]
h_list=[]


def all_same(items):
	return all(map(lambda x: x == items[0], items))

for i in range(N):
	x,y,h=map(int, input().split())
	x_list.append(x)
	y_list.append(y)
	h_list.append(h)
		
for cy in range(101):
	for cx in range(101):
		n = -1	
		for h in h_list:
			n += 1
			if h >= 1:
				H = abs(cx - x_list[n])+abs(cy - y_list[n])+h
				h_now_list=[]
				break
		for i in range(N):
			h_now = max((H-abs(cx - x_list[i])-abs(cy - y_list[i])), 0)
			h_now_list.append(h_now)
			if h_now != h_list[i]:
				break	
			else:
				if len(h_now_list)==N:
					print(str(cx)+' '+str(cy)+' '+str(H))
					break
	else:
		continue
	break
from collections import Counter as co
hit,te,ji=map(int,input().split())
l=list(co(sorted([int(input()) for u in range(hit)])).items())
inc=0
ans=0
ef=len(l)
for ix in range(hit):
  k,v=l[inc]
  ans-=(-v//te)
  nokori=te-v%te if v%te else 0
  inc+=1
  while nokori:
    if l[inc][0]>k+ji:break
    if l[inc][1]<=nokori:
      nokori-=l[inc][1]
      inc+=1
      if inc==ef:break
    else:l[inc][1]-=nokori;break
  if inc==ef:break
print(ans+1 if nokori else ans)

### FIXED CODE ###

n,c,k=map(int,input().split())
ans=0
cnt=1
t=sorted([int(input())for s in range(n)])
while t:
    now=t.pop()
    ans+=1
    while t and cnt<c and t[-1]+k>=now:
        cnt+=1
        t.pop()
    cnt=1

print(ans)
a, b = map(int, input().split())
r = -1
for price in range(1010):
    tax_8 = int(price * 0.08)
    tax_10 = int(price * 0.1)
    if tax_8 == a and tax_10 == b:
        r = price
        braek
print(r)


### FIXED CODE ###

a, b = map(int, input().split())
r = -1
for price in range(1010):
    tax_8 = int(price * 0.08)
    tax_10 = int(price * 0.1)
    if tax_8 == a and tax_10 == b:
        r = price
        break
print(r)
from collections import deque

R, C = map(int, input().split())
sy, sx = 1, 1
gy, gx = R, C

field = [["#"] * (C + 2)] + \
        [list("#" + input() + "#") for i in range(R)] + \
        [["#"] * (C + 2)]
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
flg = False
cnt = 0

dot_num = sum(r.count('.') for r in field)

q = deque()
q.append([sy, sx])
field[sy][sx] = 0

while flg == False:
    yx = q.popleft()
    cnt = field[yx[0]][yx[1]]
    for dy, dx in dxy:
        y_n, x_n = yx[0] + dy, yx[1] + dx
        if y_n == gy and x_n == gx:
            field[y_n][x_n] = cnt + 1
            flg = True
            print(dot_num - (cnt+2))
            break
        if field[y_n][x_n] == '#':
            continue
        if field[y_n][x_n] == '.':
            q.append([y_n, x_n])
            field[y_n][x_n] = cnt + 1
    if flg:
        break
if flg == False:
    print(-1)

### FIXED CODE ###

from collections import deque
 
 
def dfs(field):
    q = deque([(0, 0, 0)])
    visited = [[False] * w for _ in range(h)]
    while q:
        i, j, d = q.popleft()
        if i == h - 1 and j == w - 1:
            return d
        if visited[i][j]:
            continue
        visited[i][j] = True
        if i > 0 and field[i - 1][j] == '.':
            q.append((i - 1, j, d + 1))
        if i < h - 1 and field[i + 1][j] == '.':
            q.append((i + 1, j, d + 1))
        if j > 0 and field[i][j - 1] == '.':
            q.append((i, j - 1, d + 1))
        if j < w - 1 and field[i][j + 1] == '.':
            q.append((i, j + 1, d + 1))
    else:
        return -1
 
 
h, w = map(int, input().split())
field = [input() for _ in range(h)]
dot_cnt = sum(r.count('.') for r in field)
d = dfs(field)
if d == -1:
    print(-1)
else:
    print(dot_cnt - (d+1))
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
A = [int(x) for x in input().split()]
AA = []
for i in A:
    if(not i in AA):
        AA+=[i]
AA.sort()
cand = -1
mingcd = gcd_list(AA)
if(len(AA)==2):
    print(max(AA))
else:
    for i in range(len(AA)-1):
        if(mingcd==gcd(AA[i],AA[i+1])):
            if(i<len(AA)-2):
                if(mingcd==gcd(AA[i],AA[i+2])):
                    cand = i
                else:
                    cand = i+1
                break
            else:
                cand = i+1
    if(cand==-1):
        cand = len(AA)-1
    print(gcd_list(AA[:cand]+AA[cand+1:]))


### FIXED CODE ###

import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())
A = [int(x) for x in input().split()]
L = [0]*N
R = [0]*N
ans = 0
for i in range(N):
    if(i==0):
        L[i] = A[0]
        R[i] = A[-1]
    else:
        L[i] = gcd(A[i],L[i-1])
        R[i] = gcd(A[-i-1],R[i-1])

for i in range(N):
    if(i==0):
        ans = R[-2]
    elif(i==N-1):
        ans = max(ans,L[-2])
    else:    
        ans = max(ans,gcd(L[i-1],R[-i-2]))
print(ans)
n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))

for i in range(1, n+1):
    if list(zip(*sc))[0].count(i) > 1:
        print('-1')
        exit(0)

for i in sc:
    if i[0] == 1 and i[1] == 0 and n > 1:
        print('-1')
        exit(0)


ans = [0, 0, 0]
for i in sc:
    ind, val = i[0]-1, i[1]
    if ans[ind] != 0:
        ans[ind] = min(ans[ind], val)
    else:
        ans[ind] = val

print(''.join(list(map(str, ans))))


### FIXED CODE ###

n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))


for i in range(10**n):
    s = str(i)
    if len(s) == n and all([s[sc[j][0]-1] == str(sc[j][1]) for j in range(m)]):
        print(s)
        exit(0)


print('-1')


#
# for i in range(1, n+1):
#    if list(zip(*sc))[0].count(i) > 1:
#        print('-1')
#        exit(0)
#
#
# if min(list(zip(*sc))[0]) != 1:
#    print('-1')
#    exit(0)
#
# for i in sc:
#    if i[0] == 1 and i[1] == 0 and n > 1:
#        print('-1')
#        exit(0)
#
#ans = [0, 0, 0]
# for i in sc:
#    ind, val = i[0]-1, i[1]
#    if ans[ind] != 0:
#        ans[ind] = min(ans[ind], val)
#    else:
#        ans[ind] = val
#
#print(''.join(list(map(str, ans))))
n, m = map(int, input().split())
table = {}
ac = 0
pena_arr = [0 for _ in range(m + 1)]
for _ in range(n):
    a, b = input().split()
    a = int(a)
    if a not in table and b == "AC":
        ac += 1
        table[a] = True
    elif a not in table and b == "WA":
        pena_arr[a] += 1
pena = 0
for i in range(1, m + 1):
    if pena_arr[i] > 0 and i in table:
        pena += pena_arr[i]
print(ac, pena)


### FIXED CODE ###

n, m = map(int, input().split())
table = {}
ac = 0
pena = 0
pena_arr = [0 for _ in range(n + 1)]
for _ in range(m):
    a, b = input().split()
    a = int(a)
    if a in table:
        continue
    if b == "AC":
        ac += 1
        table[a] = True
    elif b == "WA":
        pena_arr[a] += 1
pena = 0
for i in range(1, n + 1):
    if pena_arr[i] > 0 and i in table:
        pena += pena_arr[i]
print(ac, pena)
N,M = map(int,input().split())
A = [0] * M
A = [int(x) for x in input().split()]

if N - sum(A) >= 0:
    print(N - A.sum())
else:
    print(-1)
    

### FIXED CODE ###

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

if N - sum(A) >= 0:
    print(N - sum(A))
else:
    print(-1)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1]=0
vis[2]=abs(arr[0]-arr[1])
def c(i):
  if i in vis:
    #print(vis)
    return vis[i]
  x = abs(arr[i-1]-arr[i-2]) + c(i-1)
  y = abs(arr[i-1]-arr[i-3]) + c(i-2)
  vis[i]=min(x, y)
  #print(i, x, y, vis)
  return vis[i]
c(n)
print(vis[n])

### FIXED CODE ###

n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])
N,X = map(int,input().split())
l = list(map(int,input().split()))
p = 0
count = 0

for i in range(N+1):
    p += l[i]
    count += 1
    if p > X:
        print(count)
        break

### FIXED CODE ###

N,X = map(int,input().split())
l = list(map(int,input().split()))
p = 0
count = 1

for i in l:
    p += i
    count += 1
    if p > X:
        count -= 1
        break
print(count)
a = int(input())
print("Yes" if 9 in a else "No")

### FIXED CODE ###

a = input()
print("Yes" if "9" in a else "No")
# -*- coding: utf-8 -*-
# abc136/abc136_b
import sys
 
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
 
def main():
    N = i2n()
    str_n = str(N)
    len_n = len(str_n)
    s = N - int('9' * (len_n - 1)) if len_n % 2 else 0
    for i in range(1, len_n, 2):
        s += 9 * 10**(i - 1)
    print(s)
    return
 
main()

### FIXED CODE ###

# -*- coding: utf-8 -*-
# abc136/abc136_b
import sys
from math import log10

N = int(sys.stdin.readline().rstrip())
len_n = int(log10(N)) + 1
s = N - 10**(len_n - 1) + 1 if len_n % 2 else 0
for i in range(1, len_n, 2):
    s += 9 * 10**(i - 1)
print(s)
n = 10**2
k = [0]*10**2
for x in range(1,20):
    for y in range(1,20):
        for z in range(1,20):
            for i in range(n+1):
                if (x+y+z)**2 -(x*y+y*z+z*x) == i:
                    k[i-1] += 1
for i in range(int(input())):
    print(k[i])

### FIXED CODE ###

n = 10**4
ans = [0]*10**4
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            a = (x+y+z)**2 -(x*y+y*z+z*x)
            if a <= n:
                ans[a-1] += 1
for i in range(int(input())):
    print(ans[i])
a = int(input())

btc = 0
yen = 0

for i in range(a):
    a = input().split()
    if a[1] == 'BTC':
        btc += float(a[0])
    else:
        yen += int(a[0])

btc = btc * 380000

print(float(btc + yen))3

### FIXED CODE ###

a = int(input())

btc = 0
yen = 0

for i in range(a):
    a = input().split()
    if a[1] == 'BTC':
        btc += float(a[0])
    else:
        yen += int(a[0])

btc = btc * 380000

print(float(btc + yen))
N,M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0 for i in range(N*M+1)]
b = [0 for i in range(N*M+1)]
da = [0 for i in range(N*M+1)]
db = [0 for i in range(N*M+1)]
if 
mod = 10**9+7
for i in range(N):
    a[A[i]] += 1
    if da[A[i]] == 1:
        print(0)
        quit()
    da[A[i]] += 1
for i in range(M):
    b[B[i]] += 1
    if db[B[i]] == 1:
        print(0)
        quit()
    db[B[i]] += 1
for i in range(1,N*M+1):
    a[-i-1] += a[-i]
    b[-i-1] += b[-i]
ans = 1
for i in range(N*M):
    f = 0
    g = 0
    x = N*M - i
    y = i
    if da[x] == 1:
        f = 1
    if db[x] == 1:
        g = 1
    z = 1
    if f == 0:
        z *= a[x]
    if g == 0:
        z *= b[x]
    if f+g == 0:
        z -= i
    if z <= 0:
        print(0)
        quit()
    else:
        ans *= z%mod
print(ans%mod)

### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0 for i in range(N*M+1)]
b = [0 for i in range(N*M+1)]
da = [0 for i in range(N*M+1)]
db = [0 for i in range(N*M+1)]
mod = 10**9+7
for i in range(N):
    a[A[i]] += 1
    if da[A[i]] == 1:
        print(0)
        quit()
    da[A[i]] += 1
for i in range(M):
    b[B[i]] += 1
    if db[B[i]] == 1:
        print(0)
        quit()
    db[B[i]] += 1
for i in range(1,N*M+1):
    a[-i-1] += a[-i]
    b[-i-1] += b[-i]
ans = 1
for i in range(N*M):
    f = 0
    g = 0
    x = N*M - i
    y = i
    if da[x] == 1:
        f = 1
    if db[x] == 1:
        g = 1
    z = 1
    if f == 0:
        z = z*a[x]%mod
    if g == 0:
        z = z*b[x]%mod
    if f+g == 0:
        z -= i
    if z <= 0:
        print(0)
        quit()
    else:
        ans = ans*z%mod
print(ans%mod)
from collections import Counter as co
from itertools import combinations as com
from operator import mul
from functools import reduce

def combinations_count(n, r):
  r = min(r, n - r)
  numer = reduce(mul, range(n, n - r, -1), 1)
  denom = reduce(mul, range(1, r + 1), 1)
  return numer//denom

n=int(input())
a=0
l=co([set(co(input())) for i in range(n)])
for d,s in l.items():
  if s>=2:a+=combinations_count(s, 2)
print(a)

### FIXED CODE ###

from collections import Counter as co
from operator import mul
from functools import reduce

def combinations_count(n, r):
  r = min(r, n - r)
  numer = reduce(mul, range(n, n - r, -1), 1)
  denom = reduce(mul, range(1, r + 1), 1)
  return numer//denom


n=int(input())
a=0
l=[''.join(list(map(str,sum(sorted(list(map(list,co(input()).items()))),[])))) for i in range(n)]
for d,s in co(l).items():
  if s>=2:a+=combinations_count(s, 2)
print(a)
def swap(a,b,c):
    x = a[b]
    a[b] = a[c]
    a[c] = x

     
n = input()
a = list(map(int,input().split()))
alen = len(a)
a.append(0.5)
a.append(0.5)
ans = 0

med = [0 for x in range(alen +3)]

for i in range(alen):
    if a[i] == i+1:
        med[i+1] = 1

for i in range(len(med)):
    if med[i] == 1:
      if med[i+1] == 1:
            swap(a,a[i-1],a[i])
          	med[i+1] == 0
            ans += 1
      else:
        swap(a,i,i+1)
        ans += 1
        
print(ans)

### FIXED CODE ###

n = input()
a = list(map(int,input().split()))
a.insert(0,0.5)
alen = len(a)
a.append(0.5)
a.append(0.5)

ans = 0
 
med = [0 for x in range(alen +2)]
 
for i in range(alen):
    if a[i] == i:
        med[i+1] = 1

for i in range(len(med)):
    if med[i] == 1:
        if med[i+1] == 1:
            med[i+1] = 0
            ans += 1
        else:
            ans += 1
        
print(ans)
count = list(map(int, input().split()))[0]
y = list(map(int, input().split()))[1]
from math import floor
import sys

l_lim = floor(y / 10000)
m_lim = floor(y / 5000)
n_lim = floor(y / 1000)

for l in range(l_lim + 1):
    for m in range(m_lim + 1):
        for n in range(n_lim + 1):
            if (l+m+n == count)&(10000 * l + 5000 * m + 1000 * n == y):
                print(l, m, n)
                sys.exit()
print(-1, -1, -1)

### FIXED CODE ###

input_list = list(map(int, input().split()))
count = input_list[0]
y = input_list[1]
flag = False
for l in range(count + 1):
    for m in range(count - l + 1):
        n = count - l - m
        if 10000 * l + 5000 * m + 1000 * n == y:
            print(l, m, n)
            flag = True
            break
        if flag:
            break
    if flag:
        break
if flag == False:
    print(-1, -1, -1)
n=int(input())
c1=c2=c3=0
c=0
for i in range(n):
  s=input()
  c+=s.count('AB')

  if s[0]=='B' and s[-1]=='A':
    c3+=1
  elif s[0]=='B':
    c1+=1
  elif s[-1]=='A':
    c2+=1

cc+=max(0,c3-1)
if c1<c2:
  c2-=c1
  cc+=c1
  if c2>0 and c3>0:
    cc+=1
elif c1==c2:
  cc+=c1
else:
  c1-=c2
  cc+=c2
  if c1>0 and c3>0:
    cc+=1

if c3>max(c1,c2):
  if c1<c2:
    c+=c1*2
    c3-=c1
    c+=c3
  elif c1==c2:
    c+=c1*2
    c3-=c1
    c+=max(0,c3-1)
  else:
    c+=c2*2
    c3-=c2
    c+=c3
elif c3>=min(c1,c2) and c3<=max(c1,c2):
  if c1<c2:
    c+=c1*2
    c2-=c1
    c3-=c1
    c+=c3
  else:
    c+=c2*2
    c1-=c2
    c3-=c2
    c+=c3
else:
  c+=c3*2
  c1-=c3
  c2-=c3
  c+=min(c1,c2)

print(max(c,cc))

### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ans=0

  _ba=0
  _b=0
  _a=0
  for _ in range(n):
    s=S()
    ans+=s.count('AB')

    if s[0]=='B':
      if s[-1]=='A':
        _ba+=1
      else:
        _b+=1
    else:
      if s[-1]=='A':
        _a+=1

  ans+=max(0,_ba-1)

  if _ba>0:
    if _b>0:
      ans+=1
      _b-=1
    if _a>0:
      ans+=1
      _a-=1

  if _b>0 and _a>0:
    ans+=min(_b,_a)

  return ans

# main()
print(main())