Harryxun/stf_run huggingface dataset:
%%time

import numpy as np
h, w = list(map(int, input().split()))
ss = []
for _ in range(h):
    s = input()
#     s = s.replace(".", "0").replace("#", "1")
#     s = list(map(int, list(s)))
    ss.append(s)
# ss = np.array(ss)
    

from collections import deque
def find(now_h, now_w):
    dp = np.zeros([h, w], dtype = np.int32) + 9999
    dp[now_h, now_w] = 0
    que = deque()
    que.append((now_h, now_w))
    while len(que) > 0:
        now_h, now_w = que.pop()
        if (now_h, now_w) in que:
            continue
        for mh, mw in ([0,1], [0,-1], [1,0], [-1,0]):
            next_h = now_h + mh
            next_w = now_w + mw
            if next_h < 0 or next_h >= h or next_w < 0 or next_w >= w:
                continue
            if ss[next_h][next_w] == "#":
                continue
            a = dp[now_h, now_w] + 1
            if dp[next_h, next_w] > a:
                dp[next_h, next_w] = a
                que.append((next_h, next_w))
    score = np.max(dp[dp != 9999])
    return score

maximum = 0
for sh in range(h):
    for sw in range(w):
        if ss[sh][sw] == ".":
            score = find(sh, sw)
            if maximum < score:
                maximum = score

print(maximum)

### FIXED CODE ###

import numpy as np
h, w = list(map(int, input().split()))
ss = []
for _ in range(h):
    s = input()
#     s = s.replace(".", "0").replace("#", "1")
#     s = list(map(int, list(s)))
    ss.append(s)
# ss = np.array(ss)
    

from collections import deque
def find(now_h, now_w):
    dp = np.zeros([h, w], dtype = np.int32) + 9999
    dp[now_h, now_w] = 0
    que = deque()
    que.append((now_h, now_w))
    while len(que) > 0:
        now_h, now_w = que.popleft()
        if (now_h, now_w) in que:
            continue
        for mh, mw in ([0,1], [0,-1], [1,0], [-1,0]):
            next_h = now_h + mh
            next_w = now_w + mw
            if next_h < 0 or next_h >= h or next_w < 0 or next_w >= w:
                continue
            if ss[next_h][next_w] == "#":
                continue
            a = dp[now_h, now_w] + 1
            if dp[next_h, next_w] > a:
                dp[next_h, next_w] = a
                que.append((next_h, next_w))
#             print(que)
    score = np.max(dp[dp != 9999])
    return score

maximum = 0
for sh in range(h):
    for sw in range(w):
        if ss[sh][sw] == ".":
            if sh > 0 and sh < h - 1 and sw > 0 and sw < w - 1:
                if 0 + (ss[sh + 1][sw] == ".") + (ss[sh - 1][sw] == ".") + (ss[sh][sw + 1] == ".") + (ss[sh][sw - 1] == ".") >= 3:
                    continue
            score = find(sh, sw)
            if maximum < score:
                maximum = score

print(maximum)
n = int(input())
w = list(map(int, input().split()))

half = sum(w) / 2

wk = 0
for i in range(n):
    
    if( wk + w[i] >= half):
        wk += w[i]      
        break
    wk += w[i]  

zenhan = 0
for j in range(0,i + 1):

    zenhan += w[j]  

kouhan = 0
for j in range(i + 1, n):
    kouhan += w[j]  

print(abs(zenhan - kouhan))

### FIXED CODE ###

p,q,r = map(int, input().split())

ans = p+q+r-max(p,q,r)
print(ans)
len = input()
print(len**3)


### FIXED CODE ###

len = int(input())
print(len**3)
N = int(input())
Y = int(input())
for x in range(N+1):
    for y in range(N+1):
        for z in range(N+1):
            if 10000*x+5000*y+1000*z == Y:
                print(x,y,z)

### FIXED CODE ###

n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")
import math
A, B = map(int(input()), float(input()))
if B >= 1:
    print(math.trunc(A * B))
elif 1 > B > 0:
    print(0)
else:
    print(A * B)



### FIXED CODE ###

import decimal
s = input().split()
a = int(s[0])
b = round(decimal.Decimal(s[1]), 2)
print(int(a * b))
Q,H,S,D = map(int,input().spllit())
N = int(input())

h = min(2*Q,H)
s = min(2*h,S)
d = min(2*s,D)

print((N//2)*d + (N%2)*s)

### FIXED CODE ###

Q,H,S,D = map(int,input().split())
N = int(input())
h = min(2*Q,H)
s = min(2*h,S)
d = min(2*s,D)
print((N//2)*d + (N%2)*s)
t = [0]
x = [0]
y = [0]
N = int(input())
for i in range(N):
  ti,xi,yi = map(int,input(),split())
  t.append(ti)
  x.append(xi)
  y.append(yi)
  
flg = True
 
for i in range(0,N):
  if t[i+1]-t[i] <　x[i+1]-x[i] + y[i+1]-y[i]:
    flg = False
  else (t[i+1]-t[i])%2 - (x[i+1]-x[i] + y[i+1]-y[i])%2==0:
    flg = False
if (flg):
  print('Yes')
else:
  print('No')


### FIXED CODE ###

t = [0]
x = [0]
y = [0]
n = int(input())
for i in range(n):
    ti, xi, yi = map(int, input().split())
    t.append(ti)
    x.append(xi)
    y.append(yi)
    
flg=True
for i in range(1, n+1):
    if((x[i]-x[i-1])+(y[i]-y[i-1])>(t[i]-t[i-1])):
        flg=False
    elif(((x[i]-x[i-1])+(y[i]-y[i-1]))%2!=(t[i]-t[i-1])%2):
        flg=False
if(flg):
    print("Yes")
else:
    print("No")
a,b,c = map(int,raw_input().split())
ans = []
for i in range(a,b+1):
	if c%i == 0:
		ans.append(i)
	return ans

### FIXED CODE ###

a,b,c = map(int,raw_input().split())
lst = []
for i in range(a,b+1):
	if c%i == 0:
		lst.append(i)
print len(lst)
D, N = map(int, input().split())
if D == 0:
  print(N)
elif D == 1:
  x = [100 * i for i in range(100)]
  print(x[N])
elif D == 2:
  x = [10000 * i for i in range(100)]
  print(x[N])

### FIXED CODE ###

D, N = map(int, input().split())
if N != 100:
  if D == 0:
    print(N)
  elif D == 1:
    x = [100 * i for i in range(1, 101)]
    print(x[N-1])
  elif D == 2:
    x = [10000 * i for i in range(1, 101)]
    print(x[N-1])
else:
  if D == 0:
    print(101)
  elif D == 1:
    x = [100 * i for i in range(1, 101)]
    print(x[N-1]+100)
  elif D == 2:
    x = [10000 * i for i in range(1, 101)]
    print(x[N-1]+10000)
import sys
w,h,x,y=map(int,input().split())
#l=[int(i) for i in input().split()]
a=[y*w,(h-y)*w]
a.sort()
b=[x*h,(w-x)*h]
b.sort()
d=[a[0],b[0]]
d.sort()
#print(a,b,d)
#0,0 x,y 
if abs((h/w)-(y/x) < sys.float_info.epsilon:
    print((w*h)/2,0)
elif x!=w and abs((h/w)-y/(x-w))< sys.float_info.epsilon:
    print((w*h)/2,0)
elif (x==0 and y==0) or (x==w and y==h) or (x==0 and y==h) or (x==w and y==0):
    print((w*h)/2,0)
elif d[0]==d[1]:
    print(d[1],1)
else:
    print(d[1],0)

### FIXED CODE ###

w,h,x,y=map(int,input().split())
s=(w*h)/2
if (h//2==y and h%2==0) and (w//2==x and w%x==0):
    print(s,1)
else:
    print(s,0)
# ABC083B - Some Sums
def main():
    N, A, B = tuple(map(int, input().split()))
    ans = sum(i for i in range(1, N + 1) if a <= sum(map(int, str(i))) <= b)
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

# ABC083B - Some Sums

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

for i in range(n + 1):
    total = sum(list(map(int, list(str(i)))))
    if a <= total <= b:
        answer += i
    
print(answer)
import collections
N, K, L = map(int, input().split())
road = [{"Connected":[],"seen":False,"set":-1} for _ in range(N)]
rail = [{"Connected":[],"seen":False,"set":-1} for _ in range(N)]

def dfs(graph, v, index): #深さ優先探索
    graph[v]["seen"] = True
    graph[v]["set"] = index
    for next_v in graph[v]["Connected"]:
        if graph[next_v]["seen"]:
            continue
        dfs(graph, next_v, index)

for X in ((road, K), (rail, L)): #結合を入力
    for _ in range(X[1]):
        p, q = map(int, input().split())
        X[0][p-1]["Connected"].append(q-1)
        X[0][q-1]["Connected"].append(p-1)

for X in (road, rail): #探索して連結成分に分解
    set_index = 0
    for v in range(N):
        if X[v]["seen"]:
            continue
        dfs(X, v, set_index)
        set_index += 1
        
List = [(road[i]["set"],rail[i]["set"]) for i in range(N)]
count = collections.Counter(List)
for A in List:
    print(count[A],end=" ")
        


### FIXED CODE ###

N, K, L = map(int, input().split())

def fp(x, parentList): #findParent
    if parentList[x] == x:
        return x
    else:
        parentList[x] = fp(parentList[x], parentList)
        return parentList[x]

#各ノードのparentをリストで表現(連結前は自身がparent)
road = [i for i in range(N)]
rail = [i for i in range(N)]

for _ in range(K):
    p, q = map(int, input().split())
    par_p, par_q = fp(p-1, road), fp(q-1, road) #p, qのparent 
    #連結する際、若い番号をparentとする
    if par_p < par_q:
        road[par_q] = par_p
    else:
        road[par_p] = par_q

#railについても同様
for _ in range(L):
    s, t = map(int, input().split())
    par_s, par_t = fp(s-1, rail), fp(t-1, rail)
    if par_s < par_t:
        rail[par_t] = par_s
    else:
        rail[par_s] = par_t

#連結成分の要素をカウント
cnt = {}
for i in range(N):
    key = (fp(i,road),fp(i,rail))
    if key in cnt:
        cnt[key] += 1
    else:
        cnt[key] = 1
#出力
for i in range(N):
    key = (fp(i,road),fp(i,rail))
    ans = cnt[key]
    print(ans, end=" ")
from collections import deque

n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab = list(map(lambda x: [x[0], x[1], x[0]+x[1]], ab))
ab.sort(key=lambda x:x[2], reverse=True)
ab=deque(ab)
count = 0
ans=0
while len(ab)>0:
  a, b, dif = ab.popleft()
  if count%2==0:
    ans+=a
  else:
    ans-=b
  count+=1
print(ans)


### FIXED CODE ###

n = int(input())
ans=0
if n == 1:
  print(0)
  quit()

#test = 0
#for i in range(1, n):
#  if n//i == n%i:
#    test+=i
#print(test)
  
for i in range(1, n):
  #余り、商がi
  temp=n-i
  syou=temp/i
  #print(syou)
  if syou>i:
    if syou.is_integer():
      ans+=int(syou)
  else:
    break
print(ans)
n = int(input())

a = list(map(int, input()))

import collections

b = collections.deque()

for i in range(n):
    if i % 2 == n % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

print(*b)



### FIXED CODE ###

n = int(input())

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

import collections

b = collections.deque()

for i in range(n):
    if i % 2 == n % 2:
        b.append(a[i])
    else:
        b.appendleft(a[i])

print(*b)
n = int(input())
cnt = 0

for i in range(n):
    l, r = list(map(int, input().split(' ')))
    cnt += r - l + 1

print(cnt)

### FIXED CODE ###

s = input()
k = int(input())

answer = 1
for i in range(min(k, len(s))):
    if s[i] != '1':
        answer = s[i]
        break

print(answer)
H,N = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]

INF = 10**9
DP = [0 for i in range(H+1)] #DP[h]=体力hのやつを倒す最小mp
min_mp = INF

for i in range(N):
    if min_mp > AB[i][1]:
        min_mp = AB[i][1]
        min_mp_i = i #消費mpが最小の技の番号

for h in range(1,AB[min_mp_i][0]+1):
    DP[h] = AB[min_mp_i][1]

for h in range(AB[min_mp_i][0]+1,H+1):
    min = INF
    for i in range(N):
        if h - AB[i][0] >= 0:
        #これを満たすiの存在を保証するために消費mp最小の技でDPに初期設定を与えた
            if min > DP[h - AB[i][0]] + AB[i][1]:
                min = DP[h - AB[i][0]] + AB[i][1]
    DP[h] = min

print(DP[H])


### FIXED CODE ###

H,N = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]

DP = [0 for i in range(H+1)] #DP[h]=体力hのやつを倒す最小mp

min_mp = 10**9
for i in range(N):
    if min_mp > AB[i][1]:
        min_mp = AB[i][1]
        min_mp_i = i

for h in range(1,min(AB[min_mp_i][0],H)+1):
    #最小消費mpの技でオーバーキルの場合にDP[h]がout of rangeになる
    DP[h] = min_mp

for h in range(AB[min_mp_i][0]+1,H+1):
    DP[h] = min((DP[h - a] + b) for a,b in AB )
    #最小消費mpの技で初期化しないとh - a >= 0を満たすaの存在が怪しい

print(DP[H])
import math
A,B=map(int,input().split())

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

print(lcm(A,B))



### FIXED CODE ###

import fractions
A,B=map(int,input().split())

def lcm(x,y):
    return (x*y)//fractions.gcd(x,y)

print(lcm(A,B))
import sys

x = sys.stdin.readline()

a_list = x.split(" ")

if int(a_list[0]) < int(a_list[1]) and int(a_list[1]) < int(a_list[2]):
  print Yes

else:
  print No

### FIXED CODE ###

import sys

x = sys.stdin.readline()

a_list = x.split(" ")

if int(a_list[0]) < int(a_list[1]) and int(a_list[1]) < int(a_list[2]):
  print "Yes"

else:
  print "No"
a = int(input())
b = int(input())
al = [1,2,3]

remain = al.remove(a,b)

print(remain)


### FIXED CODE ###

a = int(input())
b = int(input())
al = [1,2,3]

al.remove(a)
al.remove(b)
print(al[0])
n = int(input())
s = str(input())
for i in range(n):
    if s[i] == "Z":
        print("A",end="")
    else:
        print(chr(ord(s[i])+1),end="")
print()

### FIXED CODE ###

n = int(input())
s = str(input())
for i in range(len(s)):
    r = ord(s[i])+n
    if 90 < r:
        print(chr(r-26),end="")
    else:
        print(chr(r),end="")
print()
k, x = map(int, input())
rng = range(x-k+1, x+k)
print(' '.join(map(str, rng)))

### FIXED CODE ###

k, x = map(int, input().split())
rng = range(x-k+1, x+k)
print(' '.join(map(str, rng)))
N = input()
S = input()

a = 0
for s in S:
  if s=="B":
  	  a += 1
if a > N-a:
	print("Yes")
else:
  	print("No")

### FIXED CODE ###

N = int(input())
S = input()

a = 0
for s in S:
  if s=="R":
  	  a += 1
if a > N-a:
	print("Yes")
else:
  	print("No")
n,k=map(int,input().split())
x=list(map(int,input().split()))
from bisect import bisect_left as bl

x0=bl(x,0)
if x[x0]==0:
    k-=1
    a=x[:x0]
    a=a[::-1]
    a=list(map(lambda x:-x,a))
    b=x[x0:]
else:
    a=x[:x0]
    a=a[::-1]
    a=list(map(lambda x:-x,a))
    b=x[x0:]
#print(a,b)
ans=float("INF")
if k-1<len(a):
    ans=min(ans,a[k-1])
if k-1<len(b):
    ans=min(ans,b[k-1])
for i in range(k):
    j=k-i-2
    if i<len(a) and 0<=j and j<len(b):
        ans2=2*a[i]+b[j]
        ans=min(ans,ans2)
        #print(i,j,ans)
for i in range(k):
    j=k-i-2
    if i<len(b) and 0<=j and j<len(a):
        ans2=b[i]+2*a[j]
        ans=min(ans,ans2)
        #print(i,j,ans)
print(ans)


### FIXED CODE ###

n,k=map(int,input().split())
x=[0]
for xi in input().split():
    xi=int(xi)
    if xi==0:
        k-=1
    else:
        x.append(xi)
x.sort()
ans=float("INF")
zero=x.index(0)
for i in range(max(0,zero-k-1),min(zero+1,n-k+1)):
    if x[i+k]<0 or x[i]>0:
        continue
    jogen=abs(x[i+k])
    kagen=abs(x[i])
    ans=min(ans,jogen*2+kagen,kagen*2+jogen)
print(ans)
digits = int(input())
str = input()

num = int(digits/2)

str_forward = str[num:]
str_backward = str[:num]


if str_forward == str_backward:
 print("Yes")
else:
 print("No")
~               

### FIXED CODE ###

digits = int(input())
str = input()

num = int(digits/2)

str_forward = str[num:]
str_backward = str[:num]


if str_forward == str_backward:
 print("Yes")
else:
 print("No")
N, L = map(int, input().split())
A = [L+i for i in range(N)]

A.remove(min([abs(a) for a in A]))
print(sum(A))

### FIXED CODE ###

N, L = map(int, input().split())
A = [L+i for i in range(N)]

A.remove(min(max(A), *[abs(a) for a in A]))

print(sum(A))
n, q = [int(i) for i in input().split()]
a1 = {}
a2 = {}
for _ in range(n - 1):
    x, y = [int(i) - 1 for i in input().split()]
    if x in a1:
        a1[x].append(y)
    else:
        a1[x] = [y]
    if y in a2:
        a2[y].append(x)
    else:
        a2[y] = [x]
root = [-1] * n

def c(ind=0, ro=0):
    global root
    if root[ind] != -1:
        return 0
    root[ind] = ro
    if ind in a1:
        for i in a1[ind]:
            if i!=0:
                c(i, ind)
    if ind in a2:
        for i in a2[ind]:
            if i!=0:
                c(i, ind)


c()
p = [0] * n
for _ in range(q):
    x, y = [int(i) for i in input().split()]
    p[x - 1] += y
r = []
for i in range(n):
    j = i
    k = 0
    while True:
        k += p[j]
        if j == 0 and root[j]==0:
            break
        j = root[j]
    r.append(str(k))
print(" ".join(r))


### FIXED CODE ###

import sys

sys.setrecursionlimit(1000000)


def input():
    return sys.stdin.readline()


n, q = [int(i) for i in input().split()]
ab = [[] for _ in range(n)]
for _ in range(n - 1):
    i, j = [int(i)-1 for i in input().split()]
    ab[i].append(j)
    ab[j].append(i)
p = [0]*n
for _ in range(q):
    i, j = [int(i) for i in input().split()]
    p[i-1] += j

al = [False]*n
pp = [0]*n


def a(i=0, j=0):
    al[i] = True
    j += p[i]
    pp[i] = str(j)
    for k in ab[i]:
        if not al[k]:
            a(k, j)


a()
print(" ".join(pp))
A,B,C,K=map(int, input().split())
num_list=[]
for i in range(A):
    num_list.append(1)
for j in range(B):
    num_list.append(0)
for k in range(C):
    num_list.append(-1)

print(sum(num_list[0:K-1]))


### FIXED CODE ###

S=input()
T=input()

if S==T[0:-1] and len(S)<=10:
    print('Yes') 
else:
    print('No')
def main():
    n = int(input())
    a = sorted([int(i) for i in input().split()])
    table = [True for i in range(max(a))]
    res = 0
    amax = max(a)
    dup = 0

    for i in a:
        if table[i-1]:
            if i not in res:
                res.append(i)
            else:
                dup += 1  
                continue
        else:
            continue
        for j in range(i *2, amax, i):
            table[j-1] = False
    print(len(res) - dup)

if __name__ == '__main__':
    main()



### FIXED CODE ###

from collections import Counter

def main():
    n = int(input())
    a = sorted([int(i) for i in input().split()])
    table = [True for i in range(max(a))]
    res = 0
    amax = max(a)

    for i in a:
        if (amax/2) + 1 < i:
            break
        if table[i-1] is False:
            continue
        for j in range(i*2, amax+1, i):
            table[j-1] = False

    c = Counter(a)
    for i in set(a):
        if table[i-1]:
            if c[i] == 1:
                res += 1
    print(res)

if __name__ == '__main__':
    main()
a,b = map(int, input().split())
for 2 in range(100):
	c = (a-1) * (b-1)

### FIXED CODE ###

a,b = map(int, input().split())
c = (a-1) * (b-1)
print(c)
s = list(input())
n = len(s)
ans = 0
for i in range(n):
  if s[i] == "g" and flag == 0:
    flag+=1
  elif s[i] == "g" and flag != 0:
    flag -= 1
    ans += 1
  elif s[i] == "p" and flag == 0:
    flag += 1
    ans -= 1
  else:
    flag -= 1
print(ans)
    
    

### FIXED CODE ###

s = list(input())
n = len(s)
ans = 0
flag = 0
for i in range(n):
  if s[i] == "g" and flag == 0:
    flag+=1
  elif s[i] == "g" and flag != 0:
    flag -= 1
    ans += 1
  elif s[i] == "p" and flag == 0:
    flag += 1
    ans -= 1
  else:
    flag -= 1
print(ans)
print(((N-1)*N)/2)


### FIXED CODE ###

N=int(input())
print(((N-1)*N)//2)
N = int(input())
TA = []
for i in range(N):
    T, A = map(int, input().split())
    TA.append((T, A))

T, A = TA[0]
answer = T+A
p = 1
prev = p
pT, pA = T, A
for i in range(1,N):
    # (T+A) * p >= prev
    # p >= prev/(T+A)
    T, A = TA[i]
    s = T+A
    p = (answer+s-1)//s
    p1 = (pT+T-1)//T
    p2 = (pA+A-1)//A
    p = max([p,p1,p2])
    pT, pA = p*T, p*A
    answer =  pT+pA
    #print(T, A, p, answer, sep="\t")
print(answer)

    


### FIXED CODE ###

S = input().strip()

answer = 0

for n in range(2**(len(S)-1)):
    A = [0]
    for d in range(9):
        if n & (1 << d):
            A.append(d+1)
    T = []
    #print("A", A)
    for l, r in zip(A, A[1:]):
        T.append(int("".join(S[l:r])))
    T.append(int("".join(S[A[-1]:])))
    answer += sum(T)

print(answer)
X=int(input())
if X== 3,5, 7:
  print("YES")
else:
  print("NO")


### FIXED CODE ###

X=int(input())
if X== 3 or X==5 or X==7:
  print("YES")
else:
  print("NO")
n = int(input())
s = str(input())
k = int(input())

char = s[k-1]
result = ""
for x in s:
    if x == char:
        result += char
    else:
        result += "*"
print(result)


### FIXED CODE ###

a, b, c = (int(i) for i in input().split())  
if a <= c <= b or b <= c <= a:
    print("Yes")
else:
    print("No")
linea = int(input())
lineb = int(input())
if (linea%2)*(lineb%2)==0
	print("Even")
else 
	print("Odd")

### FIXED CODE ###

linea,lineb = map(int,input().split())
if (linea%2)*(lineb%2)==0:
	print("Even")
else :
	print("Odd")
N = int(input())
A = list(map(int, input().split()))


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += (i & -i)


BIT = BinaryIndexedTree(N)
ans = 0
for j in range(N):
    ans += j - BIT.sum(A[j])
    BIT.add(A[j], 1)
print(ans)


### FIXED CODE ###

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


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += (i & -i)

    def reset(self):
        self.bit = [0] * (self.size + 1)


BIT = BinaryIndexedTree(N)

A_sorted = {a: i for i, a in enumerate(sorted(A), start=1)}
ans = 0
for j, a in enumerate(A):
    ans += j - BIT.sum(A_sorted[a])
    BIT.add(A_sorted[a], 1)

print(ans)
n,m = map(int,input())

s = (n - 1)*(m - 1)
print(s)

### FIXED CODE ###

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

s = (n - 1)*(m - 1)
print(s)
N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)

dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=max(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=max(ans,rec(i))
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5+10)
input=sys.stdin.readline

N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)
def chmax(a,b):
  if a>=b:
    return a
  else:
    return b
dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=chmax(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=chmax(ans,rec(i))
print(ans)
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, sX, mod = mapint()

X = sX
s = set()
s.add(X)
s_loop = set()
ans = X
loop = 0
loops = []
for i in range(min(10**5*2+10, N-1)):
    X = pow(X, 2, mod)
    if X in s:
        if X in s_loop:
            break
        loop += X
        s_loop.add(X)
        loops.append(X)
    s.add(X)
    ans += X

rest = N-i-2
if rest:
    ans += (rest//len(s_loop))*loop
    amari = rest%len(s_loop)+1
    try:
        for i in range(amari):
            ans += loops[i]
    except:
        loops.append(sX)
        ans += loops[0]
    print(ans)
else:
    print(ans)

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, sX, mod = mapint()

X = sX
s = set()
s.add(X)
s_loop = set()
ans = X
loop = 0
loops = []
i = -1
for i in range(min(10**5*2+10, N-1)):
    X = pow(X, 2, mod)
    if X in s:
        if X in s_loop:
            loops.append(X)
            break
        loop += X
        s_loop.add(X)
        loops.append(X)
    s.add(X)
    ans += X

rest = N-i-2
if rest:
    ans += (rest//len(s_loop))*loop
    amari = rest%len(s_loop)+1
    for i in range(amari):
        ans += loops[i]
    print(ans)
else:
    print(ans)
s=input()
if s[0]==s[1] || s[2]==s[1] || s[2]==s[3]:
  print('Good')
else:
  print('Bad')

### FIXED CODE ###

n=int(input())
a=n//1000
b=(n//100)%10
c=(n//10)%10
d=n%10
 
if a==b:
  print('Bad')
elif b==c:
  print('Bad')
elif c==d:
  print('Bad')
else:
  print('Good')
from sys import stdin
moji=stdin.readline().rstrip()
N=int(stdin.readline().rstrip())
ite=(len(moji)//N)
ans=moji[0]
for i in range(1,ite+1):
    ans=ans+moji[i*N]
print(ans)

### FIXED CODE ###

from sys import stdin
moji=(stdin.readline().rstrip())
N=int(stdin.readline().rstrip())
ans=moji[0]
ite=len(moji)
for i in range(1,ite+1):
    if i*N > len(moji)-1:
        break
    ans=ans+moji[i*N]
print(ans)