Harryxun/stf_run huggingface dataset:
class Heap:
    
    def maintain_heapify(self,A,i):
        l=2*i+1
        r=2*i+2
        if self.name=='max':
            if l<len(A) and A[l]>A[i]:
                largest=l
            else:
                largest=i
            
            if r<len(A) and A[r]>A[largest]:
                largest=r
            
            if largest!=i:
                A[largest],A[i]=A[i],A[largest]
                self.maintain_heapify(A,largest)

        elif self.name=='min':
            if l<len(A) and A[l]<A[i]:
                smallest=l
            else:
                smallest=i
            if r<len(A) and A[r]<A[smallest]:
                smallest=r
            if smallest!=i:
                A[smallest],A[i]=A[i],A[smallest]
                self.maintain_heapify(A,smallest)

    def build_heap(self,A):
        i=len(A)//2
        while i>=0:
            self.maintain_heapify(A,i)
            i-=1

    def __init__(self,A,name='max'):
        self.name=name
        self.build_heap(A)
        self.heap=A

    def insert(self,v):
        self.heap.append(v)
        self.build_heap(self.heap)

    def deleteroot(self):
        root=self.heap[:1]
        tmp=self.heap[1:len(self.heap)-1]
        self.heap=self.heap[len(self.heap)-1:]+tmp
        self.build_heap(self.heap)
        return root[0]

    def get_root(self):
        return self.heap[0]
    def get_sum(self):
      	for i in range(len(self.heap)):
          self.heap[i] = int(self.heap[i])
        return sum(self.heap)


def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    heap = Heap(A)
    tmp = 0
    for cnt in range(M):
        first = heap.deleteroot()
        plus = first / 2
        heap.insert(plus)
    print(heap.get_sum())
    return
main()


### FIXED CODE ###

def minus(a:str):
    return int(a)*-1

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

import heapq as hq

def main():
    hq.heapify(A)
    for _ in range(M):
        target = hq.heappop(A)
        target = -1*((-1*target) // 2)
        hq.heappush(A,target)
    print(sum(A)*-1)
    return 

if __name__ == "__main__":
    main()
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = {}
d = 0


def has_edge(edges, v, g, d):
    target = edges.get(v)
    if target is not None and mem.get(v) is None:
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)


### FIXED CODE ###

n = int(input())
edges = {i: int(input())-1 for i in range(n)}


def push_buttom(v, goal):
    for i in range(n):
        v = edges[v]
        if v == goal:
            return i+1
    return -1


print(push_buttom(0, 1))
S,T = map(input().split())
A,B = map(int,input().split())
U = input().split()

if S==U:
  A-=1
else:
  B-=1
  
print(f"{A} {B}")

### FIXED CODE ###

S,T = input().split(" ")
A,B = map(int,input().split(" "))
U = input()

if S==U:
  A-=1
else:
  B-=1
  
print("{} {}".format(A,B))
a,b,k=map(int,input().split())
l=list(range(a,b+1))
la= set(l[:k]) | set(l[-k:])
for i in (sorted(la)):
  print(i)

### FIXED CODE ###

a,b,k=map(int,input().split())
if b-a < k*2:
  for i in range(a,b+1):
    print(i)
else:
  for i in list(range(a,a+k)) + list(range(b-k+1,b+1)):
    print(i)
N, X = map(int, input().split())
L = [int(i) for i in input().split()]

ans = 0
D = [0] * (N + 2)
for i in range(N+2):
    if i != 1:
        D[i] = D[i-1] + L[i-1]
    if D[i] <= X:
        ans += 1
    else:
        break
print(ans)

### FIXED CODE ###

N, X = map(int, input().split())
L = [int(i) for i in input().split()]
 
ans = 1
now = 0
for i in range(N):
    now = now + L[i]
    if now <= X:
        ans += 1
    else:
        break
print(ans)
import math


def find_root(ele):
    root = node_list[ele]['root']
    if root is not None:
        return find_root(root)
    return ele


N, M = list(map(int, input().split()))
bridge_list = list()
for _ in range(M):
    bridge_list.append(list(map(int, input().split())))

answer_list = [math.factorial(N) // math.factorial(2) // math.factorial(N - 2)]
node_list = [{'root': None, 'child_count': 0} for i in range(N)]

for bridge_list in bridge_list[:0:-1]:
    a = bridge_list[0] - 1
    b = bridge_list[1] - 1
    a_root = find_root(a)
    b_root = find_root(b)
    if a_root == a and b_root == b:
        answer_list.append(answer_list[-1] - (node_list[a]['child_count'] + 1) * (node_list[b]['child_count'] + 1))
        next_root = min(a, b)
        old_root = max(a, b)
        node_list[next_root]['child_count'] += node_list[old_root]['child_count'] + 1
        node_list[old_root]['root'] = next_root
    elif a_root == a and b_root != b:
        answer_list.append(answer_list[-1] - (node_list[a]['child_count'] + 1) * (node_list[b_root]['child_count'] + 1))
        node_list[a]['child_count'] += node_list[b_root]['child_count'] + 1
        node_list[b_root]['root'] = a
    elif a_root != a and b_root == b:
        answer_list.append(answer_list[-1] - (node_list[a_root]['child_count'] + 1) * (node_list[b]['child_count'] + 1))
        node_list[b]['child_count'] += node_list[a_root]['child_count'] + 1
        node_list[a_root]['root'] = b
    else:
        answer_list.append(answer_list[-1])

for answer in answer_list[::-1]:
    print(answer)


### FIXED CODE ###

import math


def find_root(ele):
    root = node_list[ele]['root']
    if root is not None:
        return find_root(root)
    return ele


N, M = list(map(int, input().split()))
bridge_list = list()
for _ in range(M):
    bridge_list.append(list(map(int, input().split())))

answer_list = [math.factorial(N) // math.factorial(2) // math.factorial(N - 2)]
node_list = [{'root': None, 'child_count': 0} for i in range(N)]

for bridge_list in bridge_list[:0:-1]:
    a = bridge_list[0] - 1
    b = bridge_list[1] - 1
    a_root = find_root(a)
    b_root = find_root(b)
    if a_root != b_root:
        answer_list.append(answer_list[-1] - (node_list[a_root]['child_count'] + 1) * (node_list[b_root]['child_count'] + 1))
        next_root = min(a_root, b_root)
        old_root = max(a_root, b_root)
        node_list[next_root]['child_count'] += node_list[old_root]['child_count'] + 1
        node_list[old_root]['root'] = next_root
    else:
        answer_list.append(answer_list[-1])

for answer in answer_list[::-1]:
    print(answer)
# -*- coding: utf-8 -*-
from sys import stdin
# from bisect import bisect_left
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


MOD = 10**9 + 7


def check_length(list_):
    return len(list_) > len(set(list_))


N, M = ds_in()
A_list = ds_in()
B_list = ds_in()
if check_length(A_list) or check_length(B_list):
    print(0)
    exit()

A_list.sort()
B_list.sort()

NM = N * M
ans = 1
a_idx = 0
b_idx = 0
for i in range(1, NM+1):
    flag = 1
    if i == A_list[a_idx]:
        n = 1
        a_idx += 1
        flag = 0
    else:
        n = N - a_idx

    if i == B_list[b_idx]:
        m = 1
        b_idx += 1
        flag = 0
    else:
        m = M - b_idx

    ans *= (n * m - flag * (NM - i))
    ans = ans % MOD

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
from sys import stdin
# from bisect import bisect_left
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


MOD = 10**9 + 7


def check_length(list_):
    return len(list_) > len(set(list_))


N, M = ds_in()
NM = N * M
A_list = ds_in()
B_list = ds_in()
if check_length(A_list) or check_length(B_list):
    print(0)
    exit()

A_list.sort()
B_list.sort()

if A_list[-1] < NM or B_list[-1] < NM:
    print(0)
    exit()

ans = 1
a_idx = 0
b_idx = 0
for i in range(1, NM+1):
    flag = 1
    if i == A_list[a_idx]:
        n = 1
        a_idx += 1
        flag = 0
    else:
        n = N - a_idx

    if i == B_list[b_idx]:
        m = 1
        b_idx += 1
        flag = 0
    else:
        m = M - b_idx

    ans *= (n * m - flag * (NM - i))
    ans = ans % MOD

print(ans)
def main():
  N=int(input())
  s=0
  for i in range(1,N+1):
    if i%2==0:
       s=s
    else:
       s=s+1
print(s/N)
main()

### FIXED CODE ###

N=int(input())
s=0
for i in range(1,N+1):
  if i%2==0:
    s=s
  else:
    s+=1
c=s/N
print(c)
def Cakes_and_Donuts(N):
    CP = 4
    DP = 7
    
    if N <= 3:
        return f"No"
    
    for i in range(26):
        for j in range(15):
            if (CP * i + DP * j) == N:
                return f"Yes"
    
    return f"No"
  
  N = int(input())
  Cakes_and_Donuts(N)

### FIXED CODE ###

def main(N):
  
    CP = 4
    DP = 7
    
    if N <= 3:
        return "No"
    
    for i in range(100):
        for j in range(100):
            if (CP * i + DP * j) == N:
                return "Yes"
    return "No"
N = int(input())
print(main(N))
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,q = readInts()
    s = input()
    for i in range(n):
        i,r = readInts()
        i -=1 # zero based index
        S = s[i:r]
        print(S.count('AC'))

if __name__ == '__main__':
  main()


### FIXED CODE ###

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,q = readInts()
    s = input()
    nya = [0] * (n+1)# 累積和
    for i in range(n):
        if i+1 < n:
            if s[i] == 'A' and s[i+1] == 'C':
                nya[i+1] = nya[i] + 1
            else:
                nya[i+1] = nya[i]
    #print(nya)
    for q_ in range(q):
        l,r = readInts()
        l -=1
        r -=1
        print(nya[r] - nya[l])


if __name__ == '__main__':
  main()
#!/usr/bin/env python3
#ABC132 D
import sys
sys.setrecursionlimit(1000000)
from collections import deque

inf = 10**9+7
N,K = map(int,input().split())

def fact(n):
    if n == 0:
        return 1
    return n*fact(n-1)

for i in range(1,K+1):
    if N - K + 1 < i:
        print(0)
    else:
        ans = (fact(N-K+1)/(fact(i)*fact(N-K-i+1)))*(fact(K-1)/(fact(i-1)*fact(K-i)))
        print(int(ans%inf))


### FIXED CODE ###

#!/usr/bin/env python3
#ABC132 D
import sys
sys.setrecursionlimit(1000000)
from collections import deque

inf = 10**9+7
N,K = map(int,input().split())

fact = [1]*10000
for i in range(1,10000):
    fact[i] = fact[i-1]*i

for i in range(1,K+1):
    if N - K + 1 < i:
        print(0)
    else:
        ans = (fact[N-K+1]//fact[i]//fact[N-K-i+1])
        ans *= (fact[K-1]//fact[i-1]//fact[K-i])
        print(ans%inf)
X,N=map(int,input().split())
l=[]
for i in range(100):
  l.append(i+1)
if N>0:
  p=list(map(int,input().split()))
  l1=[x for x in l if x not in p]
  d=abs(X-l1[0])
if N>0:
  for i in range(N):
    d=min(abs(X-l1[i]),d)
  print(l1[i])
else:
  print(X)

### FIXED CODE ###

x, n = map(int, input().split())
a = [int(x) for x in input().split()]
b = [i for i in range(0,102) if i not in a] 
b_tmp = list(map(lambda s:abs(s-x), b)) #b_tmpはbとxの差分のリストをさくせい
address = b_tmp.index(min(b_tmp))
print(b[address])
import math

N = input()
X = list(map(int, input().split()))
sum = 0
for a in X:
    sum = sum + a
C = sum/N
ans = 0
for b in X:
    ans = ans + (b-C)**2
print(math.ceil(ans))

### FIXED CODE ###

N = int(input())
X = list(map(int, input().split()))
sum = 0
all = True
for a in X:
    sum = sum + a
C = int(sum / N + 0.5)
ans = 0
for b in X:
    ans = ans + (b-C)**2
print(ans)
a,b,c=int(input());print(a+b+c)

### FIXED CODE ###

a,b,c=input();print(int(a)+int(b)+int(c))
a = int(input())
b = input().split()

for i in range(a):
    if b[i] == 0:
        print(0)
        return

c = 1
for i in range(a):
    c = c*int(b[i])
    if c > 1000000000000000000:
        break

if c > 1000000000000000000:
    print(-1)
else:
    print(c)

### FIXED CODE ###

a = int(input())
b = input().split()
c = 1
for i in range(a):
    if int(b[i]) == 0:
        c = 0

if c == 1:
    for i in range(a):
        c = c*int(b[i])
        if c > 1000000000000000000:
            break

if c > 1000000000000000000:
    print(-1)
else:
    print(c)
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
W = X * Y * Z
D = [0] * W
m = 0
for i in range(X):
	for j in range(Y):
		for k in range(Z):
			D[m] = A[i] + B[j] + C[k]
			m = m + 1
print(D)
E = sorted(D, reverse = True)
for n in range(K):
	print(E[n])


### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A, B, C = [sorted(list(map(int, input().split())))[:: -1][: K] for _ in range(3)]
D = []
for ai in A:
    for bi in B:
        D.append(ai + bi)

D = sorted(D)[:: -1][: K]

res = []
for di in D:
    for ci in C:
        res.append(di + ci)

res = sorted(res)[:: -1][: K]

for ans in res:
    print(ans)
A = input().split()
B = input().split()
if A[0] == B[2] and A[1] == B[1] and A[2] == B[0]:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

A = list(input())
B = list(input())
if A[0] == B[2] and A[1] == B[1] and A[2] == B[0]:
    print('YES')
else:
    print('NO')
a, b = input().split()

c = a * b 

if c % 2 == 1 :
  print('Odd')
 
else :
  print('Even')



### FIXED CODE ###

a, b = map(int, input().split())
 
c = a * b
 
if c%2 == 1	:
  print('Odd')
else :
  print('Even')
import math
A,B,N = mips()
K = N-1
print(max(math.floor(A*N/B)-A*math.floor(N/B),math.floor(A*K/B)-A*math.floor(K/B),0))

### FIXED CODE ###

import math
from math import floor
A,B,N = map(int,input().split())
def f(x):
  return floor(A*x/B) - A*floor(x/B)
print(f(min(B-1,N)))
# -*- coding: utf-8 -*-
import collections
def main():
    N = int(input())
    S = [str(input()) for i in range(N)]
    c = collections.Counter(S)
    ans = []
    for i in range(N):
        if c.most_common()[i][1] != c.most_common()[0][1]:
            break
        ans.append(c.most_common()[i][0])
    ans.sort()
    for j in ans:
        print(j)
if __name__ == '__main__':
    main()

### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import Counter
def main():
    N = int(input())
    S = [input() for i in range(N)]
    c = Counter(S)
    ans = []
    tmp = []
    tmp = c.most_common()
    cmax = c.most_common()[0][1]
    ans = [k for k , j in c.items() if j == cmax]
    ans.sort()
    print('\n'.join(ans))
if __name__ == '__main__':
    main()
a, b = map(int, input().split())
c, d = map(int, input().split())
if (a*b)==(c*d):
 print("0")
else if (a*b ) > (c*d):
  print(c*d)

### FIXED CODE ###

a, b = map(int, input().split())
c, d = map(int, input().split())
print((a-c)*(b-d))
N=int(input())
K=int(input())
import math
x=math.floor(math.log10(N))+1
def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans=0
if x<K:
  print(0)
  exit(0)
if K==1:
  ans=(x-1)*9
  ans+=(N//10**(x-1))
  print(ans)
elif K==2:
  for i in range(2,x):
    ans+=(9**2)*(i-1)
  f=(N//10**(x-1))
  n=str(N)
  for i in range(1,x):
    if n[i]!='0':
      s_n=x-i
      s=int(n[i])
      break
  ans+=(f-1)*9*(x-1)
  ans+=9*(s_n-1)
  ans+=s
  print(ans)
else:
  for i in range(3,x):
    ans+=(9**3)*combinations_count(i-1,2)
  f=(N//10**(x-1))
  n=str(N)
  s_n=0
  s=0
  t_n=0
  t=0
  for i in range(1,x):
    if n[i]!='0':
      s_n=x-i
      s=int(n[i])
      break
  for i in range(x-s_n+1,x):
    if n[i]!='0':
      t_n=x-i
      t=int(n[i])
      break
  if s_n<=2:
    ans+=(f-1)*9**2*combinations_count(x-1,2)
    if s>0:
      ans+=(s-1)*9*(s_n-1)
    if t_n!=0:
      ans+=9*(t_n-1)
    ans+=t
  else:
    ans+=(f-1)*9**2*combinations_count(x-1,2)
    print(s_n)
    ans+=9**2*combinations_count(s_n-1,2)
    ans+=(s-1)*9*(s_n-1)
    if t_n!=0:
	    ans+=9*(t_n-1)
    ans+=t
  print(ans)

### FIXED CODE ###

Nstr=input()
N=int(Nstr)
K=int(input())
x=len(Nstr)
dp0=[[0]*(K+1) for i in range(x+1)]
dp1=[[0]*(K+1) for i in range(x+1)]

dp1[0][0]=1

for i in range(1,x+1):
  dp0[i][0]=dp0[i-1][0]+dp1[i-1][0]
  for j in range(1,K+1):
    if Nstr[i-1]!='0':
      dp1[i][j]=dp1[i-1][j-1]
      dp0[i][j]+=(dp1[i-1][j-1]*(int(Nstr[i-1])-1)+dp1[i-1][j])
    else:
      dp1[i][j]=dp1[i-1][j]
    dp0[i][j]+=(dp0[i-1][j]+dp0[i-1][j-1]*9)

    
  '''  
  if Nstr[i-1]!='0':
    for j in range(1,K+1):
      dp1[i][j]=dp1[i-1][j-1]
      dp0[i][j]+=(dp1[i-1][j-1]*(int(Nstr[i-1])-1)+dp1[i-1][j])
  else:
    for j in range(1,K+1):
      dp1[i][j]=dp1[i-1][j]
  for j in range(1,K+1):
    dp0[i][j]+=(dp0[i-1][j]+dp0[i-1][j-1]*9)
  '''
print(dp0[x][K]+dp1[x][K])
from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

maze = [list(input()) for i in range(h)]
ans = [[-1]*w for i in range(h)]

dx=[0,1,0,-1]
dy=[1,0,-1,0]
count=0
#niko(x,y,ans[y][x]+1)とする。
def niko(x,y,k,ans):
  for i in range(x-2,x+2):
    for j in range(y-2,y+2):
      if 0<=i<w and 0<=j<h:
        if maze[j][i]=="." and (ans[j][i]>k or ans[j][i]==-1):
          ans[j][i]=k
  return ans
ans[ch-1][cw-1]=0
def bfs(ans):
  qu = deque([])
  qu.append([cw-1,ch-1])
  while qu:
    zahyou=qu.popleft()
    x=zahyou[0]
    y=zahyou[1]

    for i in range(x-2,x+3):
      for j in range(y-2,y+3):
        if 0<=i<w and 0<=j<h:
          if (x==i and y==j+1) or (x==i+1 and y==j) or (x==i-1 and y==j) or (x==i and y==j-1) or (x==i and y==j):
            if maze[j][i]=="." and (ans[j][i]>ans[y][x] or ans[j][i]==-1):
              qu.append([x+dx[i],y+dy[i]])
              ans[y+dy[i]][x+dx[i]] = ans[y][x]
          elif maze[j][i]=="." and (ans[j][i]>ans[y][x]+1 or ans[j][i]==-1):
            ans[j][i]=(ans[y][x]+1)
            qu.append([i,j])

bfs(ans)
print(ans[dh-1][dw-1])
#for i in ans:
#  print(*i)
  



### FIXED CODE ###

from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

maze = [list(input()) for i in range(h)]
ans = [[-1]*w for i in range(h)]

dx=[0,1,0,-1]
dy=[1,0,-1,0]

ans[ch-1][cw-1]=0
def bfs(ans):
  qu = deque([])
  qu.append([cw-1,ch-1])
  while qu:
    zahyou=qu.popleft()
    x=zahyou[0]
    y=zahyou[1]
    count=0
    for i in range(4):
      if 0 <= x+dx[i] < w and 0 <= y+dy[i] < h:
        if maze[y+dy[i]][x+dx[i]]=="." and (ans[y+dy[i]][x+dx[i]]>ans[y][x] or ans[y+dy[i]][x+dx[i]]==-1):
          qu.appendleft([x+dx[i],y+dy[i]])
          ans[y+dy[i]][x+dx[i]] = ans[y][x]
          count+=1
    if count!=4:
      for i in range(x-2,x+3):
        for j in range(y-2,y+3):
          if 0<=i<w and 0<=j<h:
            if maze[j][i]=="." and (ans[j][i]>ans[y][x]+1 or ans[j][i]==-1):
              ans[j][i]=(ans[y][x]+1)
              qu.append([i,j])

bfs(ans)
print(ans[dh-1][dw-1])
s=list(input())
s.sort()
l=[chr(ord("a")+i) for i in range(26)]
n=[]
for j in l:
  if j not in s:
    n.pop(j)
n.sort()
print(n)


### FIXED CODE ###

x,a,b=map(int,input().split())
if abs(x-a)<abs(x-b):
    print("A")
else:
    print("B")
a = input(),
b = input()
print a*b,
print 2*(a + b)

### FIXED CODE ###

a, b = map(int, raw_input().split())
print a*b, 2*a+2*b
n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]

a.sort()
a.reverse()

ans="Yes"
for i in range(m+1):
    if a[i]<sum(a)/(4*m):
        ans="No"
        break;
print(ans)

### FIXED CODE ###

n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]

a.sort()
a.reverse()

ans="Yes"
for i in range(m):
    if a[i]<sum(a)/(4*m):
        ans="No"
        break;
print(ans)
S = input()
AA = ["A", "C", "G", "T"]

ans = []
ll = 0
for i in range(len(S)):
    if S[i] in AA:
        ll += 1
    else:
        ans.append(ll)
        ll = 0

print(max(ans))


### FIXED CODE ###

S = input()
AA = ["A", "C", "G", "T"]

ans = []
ll = 0
for i in range(len(S)):
    if S[i] in AA:
        ll += 1
    else:
        ans.append(ll)
        ll = 0
ans.append(ll)

print(max(ans))
def bubble_sort_revision(target_list):

    list_length = len(target_list)
    
    flag = True
    change_count = 0
    
    for top_index in range(1,list_length):
        for i in range(top_index, list_length)[::-1]:
            if target_list[i] < target_list[i - 1] and target_list[top_index] >= target_list[i]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                
    return change_count
def solve(n, target_list):
    a = [0 for i in range(n + 1)]
    ans = 0
    for i in range(n):
        ans += i - sum(a[:target_list[i]])
        a[target_list[i]] += 1
    return ans

if __name__ == "__main__":
    l = int(input())
    target_list = [int(i) for i in input().split()]
    print(solve(l, target_list))

### FIXED CODE ###

def bubble_sort_revision(target_list):#?????????????????????

    list_length = len(target_list)
    
    flag = True
    change_count = 0
    
    for top_index in range(1,list_length):
        for i in range(top_index, list_length)[::-1]:
            if target_list[i] < target_list[i - 1] and target_list[top_index] >= target_list[i]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                
    return change_count

def my_add(bit, i, x):
    while i <= len(bit) - 1:
        bit[i] += x
        i += int(bin(i & -i), 2)
        
def my_sum(bit, i):
    s = 0
    while i > 0:
        s += bit[i]
        i -= int(bin(i & -i), 2)
    return s

def merge(l,r):
    global count
    l_index = 0
    r_index = 0
    merge_list = []
    l.append(pow(10,9) + 1)
    r.append(pow(10,9) + 1)

    len_l = len(l) - 1
    for k in range(len(l) + len(r) - 2):
        if l[l_index] < r[r_index]:
            merge_list.append(l[l_index])
            l_index += 1
            len_l -= 1
        else:
            count += len_l
            merge_list.append(r[r_index])
            r_index += 1

    return merge_list
    
def merge_sort(target_list):
    if len(target_list) == 1:
        return target_list
    
    mid = int(len(target_list) / 2)
    
    r = merge_sort(target_list[mid:])
    l = merge_sort(target_list[:mid])
    
    return merge(l, r)

def bit_solve(n, target_list):#???????????§????????????bit?????§?????????????????????
    bit = [0 for i in range(max(target_list) + 2)]
    ans = 0
    for i in range(n):
        ans += i - my_sum(bit, target_list[i] + 1)
        my_add(bit, target_list[i] + 1, 1)
        print(ans, target_list[i], bit)
    return ans

if __name__ == "__main__":
    global count
    count = 0
    l = int(input())
    target_list = [int(i) for i in input().split()]
    merge_sort(target_list)
    print(count)
a,b = map(int,input().split())
ans = 0
for i in range(a,b):
    if str(i[0]) == str(i[4]) and str(i[1]) == str(i[3]):
        ans += 1
print(ans)

### FIXED CODE ###

a,b = map(int,input().split())
ans = 0
for i in range(a,b+1):
    i = str(i)
    if i[0] == i[4] and i[1] == i[3]:
        ans += 1
print(ans)