Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import deque
H, W = map(int, input().split())
grid = []
for _ in range(H):
    grid.append([s for s in input()])

def dfs(h, w):
    cnt = 0
    if grid[h][w] == "#":
        return cnt
    q = deque([(h, w)])
    cnt += 1
    h, w = q.pop()
    for i, j in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
        if 0 <= h + i < H and 0 <= w + j < W and grid[h + i][w + j] == ".":
                cnt += 1
                q.append((h + i, w + j, (i, j)))
    while q:
        h, w, direct = q.pop()
        i, j = direct
        if 0 <= h + i < H and 0 <= w + j < W and grid[h + i][w + j] == ".":
            cnt += 1
            q.append((h + i, w + j, (i, j)))
 
    return cnt 
    
ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, dfs(h, w))
print(ans)

### FIXED CODE ###

H, W = map(int, input().split())
grid = []
for _ in range(H):
    grid.append([s for s in input()])
    
left = [[0 for _ in range(W)] for _ in range(H)]
right = [[0 for _ in range(W)] for _ in range(H)]
up = [[0 for _ in range(W)] for _ in range(H)]
down = [[0 for _ in range(W)] for _ in range(H)]

for h in range(H):
    for w in range(W):
        if grid[h][w] == ".":
            if w == 0:
                left[h][w] = 1
            else:
                left[h][w] += left[h][w - 1] + 1

for h in range(H):
    for w in range(W)[::-1]:
        if grid[h][w] == ".":
            if w == W - 1:
                right[h][w] = 1
            else:
                right[h][w] += right[h][w + 1] + 1
            
for w in range(W):
    for h in range(H):
        if grid[h][w] == ".":
            if h == 0:
                up[h][w] = 1
            else:
                up[h][w] += up[h - 1][w] + 1
                
for w in range(W):
    for h in range(H)[::-1]:
        if grid[h][w] == ".":
            if h == H - 1:
                down[h][w] = 1
            else:
                down[h][w] += down[h + 1][w] + 1
                
ans = -10000
for h in range(H):
    for w in range(W):
        ans = max(ans, up[h][w] + down[h][w] + right[h][w] + left[h][w] - 3)
print(ans)
### BUGGY CODE ###

import itertools

n = int(input())

array = []
dict = {}
dict["M"] = dict["A"] = dict["R"] = dict["C"] = dict["H"] = 0
for i in range(n):
    tmp = input()
    dict[tmp[0]] = dict.get(tmp[0], 0) + 1

if dict["M"] == 0 and dict["A"] == 0 and dict["R"] == 0 and dict["C"] == 0 and dict["H"] == 0:
    print(0)
else:
    tmp = []
    for i in [dict["M"], dict["A"], dict["R"], dict["C"], dict["H"]]:
        if i != 0:
            tmp.append(i)
    judge = 0
    for l in tmp:
        if l != 0 and l != 1:
            tmp2 = list(tmp)
            tmp2.remove(l)
            judge += (l-1)*len(tmp2)

    res = len(list(itertools.combinations(range(sum(tmp)), 3))) - judge

    print(res)


### FIXED CODE ###

import itertools
n = int(input())

array = []
dict = {}
dict["M"] = dict["A"] = dict["R"] = dict["C"] = dict["H"] = 0
for i in range(n):
    tmp = input()
    dict[tmp[0]] = dict.get(tmp[0], 0) + 1

m = dict["M"]
a = dict["A"]
r = dict["R"]
c = dict["C"]
h = dict["H"]
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+
      a*r*c+a*r*h+a*c*h+r*c*h)
### BUGGY CODE ###

def abc(n:int,lst:list):
    l=list(map(lambda x:x[2],lst))
    if min(l)==0:
        Mx=max(map(lambda x:x[0],lst))
        My=max(map(lambda x:x[1],lst))
        M=Mx*My
        for x in range(101):
            for y in range(101):
                for h in range(M):
                    for i in range(n):
                        if max(0,h-abs(lst[i][0]-x)-abs(lst[i][1]-y)) ==lst[i][2]:
                            if i ==n-1:
                                return x,y,h
                        else:
                            break
    else:
        x0 =lst[0][0]
        y0=lst[0][1]
        h0 =lst[0][2]
        for x in range(101):
            for y in range(101):
                for i in range(1,n):
                    if abs(x0-x)+abs(y0-y)-abs(lst[i][0]-x)-abs(lst[i][1]-y) ==lst[i][2]-h0:
                        if i ==n-1:
                            return x,y,h0+abs(x0-x)+abs(y0-y)
                    else:
                        break
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
x,y,h =abc(n,lst)
print(x,y,h)


### FIXED CODE ###

def abc(n:int,lst:list):
    l0=list(filter(lambda x:x[2]==0,lst))
    l=list(filter(lambda x:x[2]!=0,lst))
    if len(l0):
        x0 =l[0][0]
        y0=l[0][1]
        h0 =l[0][2]
        ans=[]
        for x in range(101):
            for y in range(101):
                for i in range(len(l)):
                    if abs(x0-x)+abs(y0-y)-abs(l[i][0]-x)-abs(l[i][1]-y) == l[i][2]-h0:
                        if i ==len(l)-1:
                            ans.append([x,y,h0+abs(x0-x)+abs(y0-y)])
                    else:
                        break
        for xyh in ans:
            for i in range(len(l0)):
                if abs(l0[i][0]-xyh[0])+abs(l0[i][1]-xyh[1])>=xyh[2]:
                    if i == len(l0)-1:
                        return xyh
                else:
                    break
    else:
        x0 =lst[0][0]
        y0=lst[0][1]
        h0 =lst[0][2]
        for x in range(101):
            for y in range(101):
                for i in range(1,n):
                    if abs(x0-x)+abs(y0-y)-abs(lst[i][0]-x)-abs(lst[i][1]-y) ==lst[i][2]-h0:
                        if i ==n-1:
                            return x,y,h0+abs(x0-x)+abs(y0-y)
                    else:
                        break
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
x,y,h =abc(n,lst)
print(x,y,h)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import numpy as np

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

A.sort()
F.sort(reverse = True)
S = [0] * N
M = 0
for i in range(N):
    S[i] = A[i] * F[i]

while K != 0:
    s = np.argmax(S)
    if A[s] == 0:
        break
    A[s] -= 1
    S[s] = A[s] * F[s]
    K -= 1
    
print(max(S))

### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse = True)
sa = sum(A) 
A = np.array(A)
F = np.array(F)

l = -1 
r = A[N-1] * F[0]
while l+1 < r: 
    m = (l + r) //2
    S = sa - np.sum(np.minimum(m // F, A)) 
    if S <= K:
        r = m
    else:
        l = m
         
print(r)
### BUGGY CODE ###

from bisect import bisect_right

N, D, A = map(int, input().split())
xh = sorted([list(map(int, input().split())) for _ in range(N)])
ds = [0]*(N+1)
b = 0
for i in range(N):
  x, h = xh[i]
  d = ds[i]
  if d>=h:
    continue
  h -= d
  times = h//A if h%A==0 else h//A+1
  for j in range(i, (bisect_right(xh, [x+2*D, float('inf')]))):
  	ds[j] += times*A
  b += times
print(b)

### FIXED CODE ###

from bisect import bisect_right

N, D, A = map(int, input().split())
xh = sorted([list(map(int, input().split())) for _ in range(N)])
ds = [0]*(N+2)
b = 0
for i, (x, h) in enumerate(xh, 1):
  ds[i] += ds[i-1]
  d = ds[i]
  if d>=h:
    continue
  h -= d
  times = h//A if h%A==0 else h//A+1
  ds[i] += times*A
  ds[bisect_right(xh, [x+2*D, float('inf')])+1] -= times*A
  b += times
print(b)
### BUGGY CODE ###

import bisect

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

count = 0
for i in range(n):
    for j in range(bisect.bisect(B, A[i]), n):
        k = bisect.bisect(C, B[j])
        if k < n:
            count += (n - k)

print(count)

### FIXED CODE ###

import bisect

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

count = 0
for j in range(n):
    i = bisect.bisect_left(A, B[j])
    k = bisect.bisect(C, B[j])
    count += (i * (n - k))

print(count)
### BUGGY CODE ###

import sys
import heapq

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)

BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

mx = n*2
[heapq.heappushpop(A, bc[1]) for i, bc in enumerate(BC) for _ in range(bc[0]) if i < mx]
print(sum(A))

### FIXED CODE ###

import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))
### BUGGY CODE ###

# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

n, k = map(int, input().split())
p = list(float(i) for i in input().split())
ans = 0

for i in range(0, n - k + 1):
  temp = 0
  for j in range(0, k):
    temp += (1.00 + p[i + j]) / 2
  ans = max(ans, temp)
print('{:.10f}'.format(ans))


### FIXED CODE ###

# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

n,k = map(int, input().split())
p = (1.00 + np.array(list(int(i) for i in input().split()))) / 2
temp = np.sum(p[:k])
ans = temp

for i in range(k, n):
	temp += (p[i] - p[i - k])
	ans = max(ans, temp)

print('{:.10f}'.format(ans))
### BUGGY CODE ###

import sys
input=sys.stdin.readline
h,w = map(int, input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d=[]
for i in range(h):
    lis=[]
    for j in range(w):
        lis.append(abs(a[i][j]-b[i][j]))
    d.append(lis)

dp = [[0 for _ in range(6400)] for _ in range(h*w)]
dp[0][d[0][0]]=1

for i in range(h*w):
    nowh,noww = divmod(i,w)
    for k in range(6400):
        if not dp[nowh*w + noww][k]==1:
            continue
        nxth,nxtw=nowh+1, noww+1
        if nxtw<w:
            nxt=d[nowh][nxtw]
            if k+nxt < 6400:
                dp[nowh*w + nxtw][k+nxt] = 1
            dp[nowh*w + nxtw][abs(k-nxt)] = 1
        if nxth<h:
            nxt=d[nxth][noww]
            if k+nxt < 6400:
                dp[nxth*w + noww][k+nxt] = 1
            dp[nxth*w + noww][abs(k-nxt)] = 1


for k in range(6400):
    if dp[-1][k]==1:
        print(k)
        exit()

### FIXED CODE ###

h,w = map(int, input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        d[i][j] = abs(a[i][j]-b[i][j])

dp = [[0 for _ in range(6400)] for _ in range(h*w)]
dp[0][d[0][0]]=1

for i in range(h*w):
    nowh,noww = divmod(i,w)
    for k in range(6400):
        if not dp[nowh*w + noww][k]==1:
            continue
        nxth,nxtw=nowh+1, noww+1
        if nxtw<w:
            if k+d[nowh][nxtw] < 6400:
                dp[nowh*w + nxtw][k+d[nowh][nxtw]] = 1
            dp[nowh*w + nxtw][abs(k-d[nowh][nxtw])] = 1
        if nxth<h:
            if k+ d[nxth][noww]< 6400:
                dp[nxth*w + noww][k+d[nxth][noww]] = 1
            dp[nxth*w + noww][abs(k-d[nxth][noww])] = 1


for k in range(6400):
    if dp[-1][k]==1:
        print(k)
        exit()
### BUGGY CODE ###

def main():
    s=input()
    n=len(s)
    mod=10**9+7
    
    dp=[[0]*13 for _ in range(n)]
    if s[-1]=="?":
        dp[0]=[1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        dp[0][int(s[-1])]=1
    
    for i in range(1,n):
        ss0=s[n-i-1]
        if ss0!="?":
            dp[i] = [ dp[i-1][(j-int(ss0)*10**i)%13] %mod for j in range(13)]
        else:
            dp[i] = [sum( dp[i-1][(j-k*10**i)%13] for k in range(10)) %mod for j in range(13) ]
    print(dp[-1][5])
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

#d
def main():
    s=input()
    n=len(s)
    mod=10**9+7
    
    if s[-1]=="?":
        dp=[1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        dp=[0]*13
        dp[int(s[-1])]=1
    
    for i in range(1,n):
        imod=10**(i %12)
        ss0=s[n-i-1]
        if ss0!="?":
            dpnew = [ dp[(j-int(ss0)*imod)%13] %mod for j in range(13)]
        else:
            dpnew = [sum( dp[(j-k*imod)%13] for k in range(10)) %mod for j in range(13) ]
        dp=dpnew[:]
    print(dp[5])
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

H, W, K = map(int, input().split())
S = [[int(c) for c in input()] for i in range(H)]

s = [[0 for i in range(W+1)] for j in range(H + 1)]
for i in range(H):
    for j in range(W):
        s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + S[i][j]

n = H - 1
ans = 1 << 30
for i in range(2 ** n):
    horizon = [0]
    for j in range(n):
        if ((i >> j) & 1):
            horizon.append(j + 1)
    horizon.append(H)
    # hori = 横はどこで割るのか？
    y1 = 0
    y2 = 1
    vertical = 0
    length = len(horizon)
    # print("horizon", horizon)
    while (y2 <= W):
        # print(y1, y2)
        for i in range(length - 1):
            x2 = horizon[i + 1]
            x1 = horizon[i]
            sq = s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1]
            # print(sq, K)
            if (sq > K):
                if (y2 == 1):
                    break
                else:
                    vertical += 1
                    y1 = y2 - 1
        y2 += 1
    ans = min(ans, (vertical) + (length - 2))
print(ans)


### FIXED CODE ###

H, W, K = map(int, input().split())
S = [[int(c) for c in input()] for i in range(H)]

s = [[0 for i in range(W+1)] for j in range(H + 1)]
for i in range(H):
    for j in range(W):
        s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + S[i][j]

n = H - 1
ans = H * W
for i in range(2 ** n):
    horizon = [0]
    length = 2
    for j in range(n):
        if ((i >> j) & 1):
            horizon.append(j + 1)
            length += 1
    horizon.append(H)
    vertical = 0
    y1 = 0
    for y2 in range(1, W + 1):
        for k in range(length - 1):
            x2 = horizon[k + 1]
            x1 = horizon[k]
            sq = s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1]
            sq_pre = s[x2][y2 - 1] - s[x1][y2 - 1] - s[x2][y1] + s[x1][y1]

            if(sq > K):
                if(sq_pre > K):
                    vertical = 1e+9
                else:
                    vertical += 1
                    y1 = y2 - 1
                break
    if (vertical >= W):
        vertical = 1e+9
    ans = min(ans, (vertical) + (length - 2))
print(ans)
### BUGGY CODE ###

n=int(input())
s=1
for i in range(1,n+1):
    s = s*i
a = s % (10**9 + 7)
print(a)


### FIXED CODE ###

n=int(input())
s=1
for i in range(1,n+1):
    s = (s*i) % (10**9 + 7)
print(s)
### BUGGY CODE ###

S=list(input())
q=int(input())
Q=[input().split() for i in range(q)]

for i in range(q):
    if Q[i][0]=="1":
        S.reverse()
    elif Q[i][0]=="2":
        if Q[i][1]=="1":
            S.insert(0,Q[i][2])
        elif Q[i][1]=="2":
            S.append(Q[i][2])
for i in S:
    print(i,end="")


### FIXED CODE ###

S=list(input())
q=int(input())
Q=[input().split() for i in range(q)]

reverse=0
Top=[]
Bottom=[]
for i in range(q):
    if Q[i][0]=="1":
        reverse+=1
    elif Q[i][0]=="2" and reverse%2==0:
        if Q[i][1]=="1":
            Top.append(Q[i][2])
        elif Q[i][1]=="2":
            Bottom.append(Q[i][2])
    elif Q[i][0]=="2" and reverse%2==1:
        if Q[i][1]=="2":
            Top.append(Q[i][2])
        elif Q[i][1]=="1":
            Bottom.append(Q[i][2])
if reverse%2==1:
    Top.reverse()
    SS=Top+S+Bottom
    SS.reverse()
elif reverse%2==0:
    Top.reverse()
    SS=Top+S+Bottom
for i in SS:
    print(i,end="")
### BUGGY CODE ###

from collections import deque

n = int(input())
dll = deque()

for i in range(n):
    input_line = [str(s) for s in input().split()]
    if input_line[0] == "insert":
        dll.appendleft(input_line[1])
    elif input_line[0] == "delete":
        try:
            dll.remove(input_line[1])
        except:
            pass
    elif input_line[0] == "deleteFirst":
        dll.popleft()
    else:
        dll.pop()
        
print(*dll)

### FIXED CODE ###

from collections import deque
   
n = int(input())
dll = deque()
   
for i in range(n):
    input_line = input().split()
    if input_line[0] == "insert":
        dll.appendleft(input_line[1])
    elif input_line[0] == "delete":
        try:
            dll.remove(input_line[1])
        except:
            pass
    elif input_line[0] == "deleteFirst":
        dll.popleft()
    else:
        dll.pop()
           
print(*dll)
### BUGGY CODE ###

N = int(input())
dic = {}
for i in range(N):
  a = int(input())
  dic[i + 1] = a
l = [1]
n = dic[1]
i = 1
flg = False
if n == 2:
  print(1)
else:
  while n not in l:
    l.append(n)
    n = dic[n]
    i += 1
    if n == 2:
      flg = True
      ans = i
      break
  if flg:
    print(ans)
  else:
    print(-1)
  

### FIXED CODE ###

n = int(input())
dic = {}
push = [True] * n
for i in range(1, n+1):
  a = int(input())
  dic[i] = a
i = 1
cnt = 1
push[0] = False
while True:
  if dic[i] == 2:
    break
  else:
    k = dic[i]
    if push[k-1]:
      i = k
      cnt += 1
      push[k-1] = False
    else:
      cnt = -1
      break
print(cnt)
### BUGGY CODE ###

r,g,b,n=map(int,input().split())
ans=0
for i in range(n//b+1):
    for j in range(n//g+1):
        for k in range(n//r+1):
            if r*k+g*j+b*i==n:
                ans=ans+1
            elif r*k+g*j+b*i>n:
                break
print(ans)

### FIXED CODE ###

r,g,b,n=map(int,input().split())
ans=0
for i in range(n//b+1):
    bi=b*i
    for j in range(n//g+1):
        gj=g*j
        if gj+bi>n:
            break
        elif gj+bi==n:
            ans=ans+1
            break
        elif (n-(gj+bi))%r==0:
            ans=ans+1
print(ans)
### BUGGY CODE ###

N = int(input())


def divisor(M):
    div = set()
    for i in range(1, int(N ** 0.5 + 0.5) + 1):
        if M % i == 0:
            div.add(i)
            div.add(M // i)
    return div


def simu(M, X):
    while M >= X:
        if M % X == 0:
            M //= X
        else:
            M -= X
    if M == 1:
        return 1
    else:
        return 0


A = divisor(N)
B = divisor(N - 1)
A -= B


# N%K==1となるやつ
ans = len(B) - 1
if N % 2 == 0:
    ans += 1
A -= {2}

for a in A:
    Ntmp = min(N, N // a)
    ans += simu(Ntmp, a)

print(ans)

### FIXED CODE ###

N = int(input())


def divisor(M):
    div = set()
    for i in range(1, int(N ** 0.5 + 0.5) + 1):
        if M % i == 0:
            div.add(i)
            div.add(M // i)
    return div


def simu(M, X):
    cnt = 0
    while M >= X:
        if M % X == 0:
            M //= X
        elif M % X == 1:
            return True
        else:
            M -= X
        cnt += 1
        if cnt > 1000:
            return False
    return M == 1


A = divisor(N)
B = divisor(N - 1)

# N%K==1となるやつ
ans = len(B) - 1

for a in (A - B):
    if simu(N, a):
        ans += 1

print(ans)
### BUGGY CODE ###

n = int(input())
an = []
for _ in range(n):
    an.append(int(input()))
    
for i in range(n):
        an_i= an[i]
        an[i] = 0
        print(max(an))
        an[i] = an_i

### FIXED CODE ###

n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
max1_index = [0]
for i in range(n):
    a = int(input())
    if a > max_1:
        tmp = max_1
        max_1 = a
        count = 1
        max1_index = [i]
        max_2 = tmp
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 >  a > max_2:
        max_2 = a
    an.append(a)
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)
### BUGGY CODE ###

from collections import defaultdict

h, w, m = map(int, input().split())

row_dict = defaultdict(int)
col_dict = defaultdict(int)
row_col_dict = defaultdict(list)
for _ in range(m):
    row, col = map(int, input().split())
    row_dict[row] += 1
    col_dict[col] += 1
    row_col_dict[row].append(col)

max_row = max(row_dict.items(), key=lambda x: x[1])

max_rows = [k for k, v in row_dict.items() if v == max(row_dict.values())]
max_cols = [k for k, v in col_dict.items() if v == max(col_dict.values())]
ans = 0

for row in max_rows:
    for col in max_cols:
        bom = row_dict[row] + col_dict[col]
        if col in row_col_dict[row]:
            bom -= 1
        ans = max(ans, bom)

print(ans)


### FIXED CODE ###

from collections import defaultdict

h, w, m = map(int, input().split())

row_dict = defaultdict(int)
col_dict = defaultdict(int)
row_col_dict = defaultdict(set)
for _ in range(m):
    row, col = map(int, input().split())
    row_dict[row] += 1
    col_dict[col] += 1
    row_col_dict[row].add(col)

max_row = max(row_dict.values())
max_col = max(col_dict.values())

max_rows = [k for k, v in row_dict.items() if v == max_row]
max_cols = [k for k, v in col_dict.items() if v == max_col]
ans = max_row + max_col - 1
flg = False
if ans < m:
    for row in max_rows:
        for col in max_cols:
            if not col in row_col_dict[row]:
                ans += 1
                flg = True
                break
        if flg:
            break

print(ans)
### BUGGY CODE ###

n = int(input())
s = input()
r, g, b = [], [], []
for i in range(n):
    if s[i] == 'R':
        r.append(i)
    elif s[i] == 'G':
        g.append(i)
    else:
        b.append(i)
lr, lg, lb = len(r), len(g), len(b)
ans = lr * lg * lb

if min([lr, lg, lb]) == lb:
    r, b = b, r

for i in r:
    for j in g:
        a = 2 * j - i
        c = 2 * i - j
        if 0 <= a and a <= n-1 and a in b:
            ans -= 1
        if 0 <= c and c <= n-1 and c in b:
            ans -= 1
        if (i + j) % 2 == 0 and (i + j) / 2 in b:
            ans -= 1
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
r, g, b = [], [], []
for i in range(n):
    if s[i] == 'R':
        r.append(i)
    elif s[i] == 'G':
        g.append(i)
    else:
        b.append(i)
lr, lg, lb = len(r), len(g), len(b)
ans = lr * lg * lb

for i in r:
    for j in g:
        a = 2 * j - i
        c = 2 * i - j
        if 0 <= a and a <= n-1 and s[a] == 'B':
            ans -= 1
        if 0 <= c and c <= n-1 and s[c] == 'B':
            ans -= 1
        if (i + j) % 2 == 0 and s[int((i + j) / 2)] == 'B':
            ans -= 1
print(ans)
### BUGGY CODE ###

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

route = [tuple(map(int, input().split())) for _ in range(M)]

ans = [0]*(N+1)
stack = [1]
que = [1]

while len(stack) < N:
    temp = []
    for a, b in route:
        if a in que and b not in stack:
            ans[b] = a
            temp.append(b)
        elif b in que and a not in stack:
            ans[a] = b
            temp.append(a)
    que = temp
    stack += temp

answer = ['Yes'] + ans[2:]

print(*answer, sep='\n')


### FIXED CODE ###

from collections import deque

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

G = [[] for _ in range(N+1)]
m = [tuple(map(int, input().split())) for _ in range(M)]

for a, b in m:
    G[a].append(b)
    G[b].append(a)

par = [0] * (N + 1)
visited = [0] * (N + 1)
root = 1
visited[root] = 1
q = deque([root])

while q:
    v = q.popleft()
    for w in G[v]:
        if visited[w]:
            continue
        visited[w] = 1
        par[w] = v
        q.append(w)
print('Yes')
print(*par[2:], sep='\n')
### BUGGY CODE ###

def invNum(d,A):
    if d < 0 or not A: return 0
    cnt = 0
    L = []
    R = []
    for ai in A:
        if ai < 2**d:
            L.append(ai)
            cnt += len(R)
        else:
            R.append(ai-2**d)
    return cnt + invNum(d-1,L) + invNum(d-1,R)
 
if __name__=='__main__':
    n = int(input()) 
    print(invNum(29,list(map(int,input().split()))))

### FIXED CODE ###

cnt = 0
def merge(L,R):
    global cnt
    n = len(L)+len(R)
    lenL = len(L)
    A = []
    i = j = 0
    L.append(-1)
    R.append(-1)
    for _ in range(n):
        if L[i] > R[j]:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
            cnt += lenL-i
    return A

def mergeSort(A):
    if len(A)==1: return A
    m = len(A)//2
    return merge(mergeSort(A[:m]),mergeSort(A[m:])) 

if __name__=='__main__':
    n = int(input()) 
    A = list(map(int,input().split()))
    mergeSort(A[::-1])
    print(cnt)