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

L, R = map(int, input().split())

ans = 2018
for i in range(L, R):
    for j in range(i+1, R+1):
        cnt = i*j % 2019
        ans = min(cnt, ans)

print(ans)


### FIXED CODE ###

L, R = map(int, input().split())

ans = 2018
for i in range(L, R):
    for j in range(i+1, R+1):
        cnt = i*j % 2019
        if cnt == 0:
            print(0)
            exit()
        ans = min(cnt, ans)

print(ans)
### 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()

lenC = len(C)
cnt = 0

for a in A:
    for b in B:
        if a >= b: continue

        ii = bisect.bisect_right(C, b)
        cnt += lenC - ii

print(cnt)

### 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()

lenC = len(C)

cnt = 0

for b in B:
    ind_a = bisect.bisect_left(A, b)
    ind_c = bisect.bisect_right(C, b)
    cnt += ind_a * (lenC - ind_c)

print(cnt)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    print(a.count(i+1))

### FIXED CODE ###

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

ans = [0]*n
for i in a:
    ans[i-1] += 1

print(*ans, sep="\n")
### BUGGY CODE ###

# 試合を頂点とした有向グラフを書く
# 対戦2チームを元に試合ID(頂点番号)に変換できるようにする
# 閉路があるとNGなので-1
# 閉路がない場合は最長経路が答え

import sys
readline = sys.stdin.readline

N = int(readline())

id_dic = {}
next_id = 0
def to_id(a,b):
  if a > b:
    a,b = b,a
  return id_dic[(a,b)]
def convert_to_id(a,b,next_id):
  if a > b:
    a,b = b,a
  if (a,b) not in id_dic:
    id_dic[(a,b)] = next_id
    return next_id + 1
  return next_id

G = [[] for i in range((N * (N - 1)) // 2)] # 試合グラフ
indegree = [0 for i in range((N * (N - 1)) // 2)] # 入次数
for i in range(N):
  A = list(map(int,readline().split()))
  cur = None
  for a in A:
    # i と a - 1の試合
    next_id = convert_to_id(i,a - 1,next_id)
    game = to_id(i,a - 1)
    if cur != None:
      G[cur].append(game)
      indegree[game] += 1 # 試合に対する入次数が1
    cur = game
  
done = [False for i in range((N * (N - 1)) // 2)] # 試合完了
# 各日付ごとに、入次数が0の試合から行っていく
# 入次数が0になった試合を翌日の試合リスト
stack = []
for i in range(len(indegree)):
  if indegree[i] == 0:
    stack.append(i)

if len(stack) == 0:
  print(-1)
  exit(0)
  
day = 0
while stack:
  day += 1
  nextday = []
  while stack:
    game = stack.pop()
    if done[game]: # 既に終わっている試合の場合　閉路と見なす
      print(-1)
      exit(0)
    done[game] = True
    for child in G[game]: # 翌日のゲームを探索
      indegree[child] -= 1
      if indegree[child] == 0: # 入次数が0になれば翌日試合できる
        nextday.append(child)
  stack = nextday

if sum(done) != ((N * (N - 1)) // 2):
  print(-1)
  exit(0)
print(day)

### FIXED CODE ###

N=int(input())
a=[[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
  line=list(map(int,input().split()))
  for j in range(N-1):
    a[i][j]=line[j]-1
  a[i]=a[i][::-1]
    
q=[]

#seen=[[False for j in range(N)] for i in range(N)]

# 選手nが試合できるならqueに入れる
def check(i):
  if len(a[i])==0:
    return False
  j=a[i][-1]
  if a[j][-1]==i:
    q.append([i,j])
  
for i in range(N):
  check(i)
  
from collections import defaultdict

day=0
while q:
  day+=1
 # q=sorted(q)
  prevQ=q.copy()
  q=[]
  matched=defaultdict(list)
  for p in prevQ:
    i=p[0]
    j=p[1]
    if i>j:
      i,j=j,i
    if matched[i]:
      continue
    a[i].pop()
    a[j].pop()
    check(i)
    check(j)
    matched[i].append(j)
    
for i in range(N):
  if len(a[i])!=0:
    print(-1)
    break
else:
  print(day)
### BUGGY CODE ###

N = int(input())

P = [int(x) for x in input().split()]

cnt = 1
for i in range(1,N):
    flag = True
    for j in range(i):
        if P[i] > P[j]:
            flag = False
            break
    
    if flag == True:
        cnt += 1

print(cnt)

### FIXED CODE ###

N = int(input())

P = [int(x) for x in input().split()]

cnt = 1
min_num = P[0]

for i in range(1,N):
    if P[i] <= min_num:
        cnt += 1
        min_num = P[i]
print(cnt)
### BUGGY CODE ###

def quiz(n, a, p):
	for i in range(n):
		p[i] -= 1
	p[a-1] += 1

N, K, Q = map(int, input().split())
p = [K] * N
for i in range(Q):
	a = int(input())
	quiz(N, a, p)
for i in range(N):
	if p[i] > 0:
		print('Yes')
	else:
		print('No')

### FIXED CODE ###

N, K, Q = map(int, input().split())
p = [K] * N
for i in range(Q):
	a = int(input())
	p[a-1] += 1
for i in range(N):
	if p[i] > Q:
		print('Yes')
	else:
		print('No')
### BUGGY CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * N
for i in range(1, N):
    temp = []
    for j in range(1,K+1):
        if (i - j) == -1:
            break
        else:
            temp.append(c[i-j]+abs(h[i]-h[i-j]))
    c[i] = min(temp)
    #print(c, temp)
print(c[-1])

### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * N
for i in range(1, N):
    temp = []
    for j in range(1,K+1):
        if (i - j) == -1:
            break
        else:
            temp.append(c[i-j]+abs(h[i]-h[i-j]))
    c[i] = min(temp)
    #print(c, temp)
print(c[-1])
### BUGGY CODE ###

import math

def f(a, b, x):
    return math.floor(a*x/b) - 5 * math.floor(x/b)

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

for i in range(b):
    if i > n:
        break
    elif f(a, b, i) > max:
        max = f(a, b, i)

print(max)

### FIXED CODE ###

import math

def f(a, b, x):
    return math.floor(a*x/b) - 5 * math.floor(x/b)

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

if b <= n:
    print(f(a, b, b-1))
else:
    print(f(a, b, n))
### BUGGY CODE ###

s = input()
m = {0: 0}
for i in range(len(s)):
    t = int(s[i:])
    a = t % 2019
    if a in m:
        m.update({a: m[a] + 1})
    else:
        m.update({a: 0})
ans = 0
for _, v in m.items():
    ans += v
print(ans)


### FIXED CODE ###

s = input()
s = s[::-1]
n = len(s)
m = [0] * 2019
m[0] = 1
a = 0
d = 1
for i in range(n):
    a = (a + int(s[i]) * d) % 2019
    d = (d * 10) % 2019
    m[a] += 1
print(sum([int(x * (x - 1) / 2) for x in m if x > 1]))
### BUGGY CODE ###

import bisect

N=int(input())
city=[]
for i in range(N):
    x,y,p=map(int,input().split())
    city.append((x,y,p))

xx=[[abs(city[j][0]) for j in range(N)] for i in range(2**N)]
yy=[[abs(city[j][1]) for j in range(N)] for i in range(2**N)]

for i in range(2**N):
    X=[0]
    rest=[]
    for j in range(N):
        if i>>j&1==1:
            X.append(city[j][0])
            xx[i][j]=0
        else:
            rest.append(j)
    for j in rest:
        res=10**15
        for k in X:
            res=min(res,abs(city[j][0]-k))
        xx[i][j]=res

for i in range(2**N):
    Y=[0]
    rest=[]
    for j in range(N):
        if i>>j&1==1:
            Y.append(city[j][1])
            yy[i][j]=0
        else:
            rest.append(j)
    for j in rest:
        res=10**15
        for k in Y:
            res=min(res,abs(city[j][1]-k))
        yy[i][j]=res

ans=[10**15 for i in range(N+1)]
for i in range(3**N):
    rest=i
    X=0
    Y=0
    count=0
    amari=[]
    for j in range(N):
        r=rest%3
        if r==1:
            count+=1
            X+=2**j
        elif r==2:
            count+=1
            Y+=2**j
        else:
            amari.append(j)
        rest//=3
    res=0
    for j in amari:
        x=xx[X][j]
        y=yy[Y][j]
        res+=min(x,y)*city[j][2]
    ans[count]=min(ans[count],res)

for i in range(N+1):
    print(ans[i])


### FIXED CODE ###

import bisect

N=int(input())
city=[]
for i in range(N):
    x,y,p=map(int,input().split())
    city.append((x,y,p))

xx=[[abs(city[j][0]) for j in range(N)] for i in range(2**N)]
yy=[[abs(city[j][1]) for j in range(N)] for i in range(2**N)]

for i in range(2**N):
    X=[0]
    rest=[]
    for j in range(N):
        if i>>j&1==1:
            X.append(city[j][0])
            xx[i][j]=0
        else:
            rest.append(j)
    for j in rest:
        res=10**15
        for k in X:
            res=min(res,abs(city[j][0]-k))
        xx[i][j]=res

for i in range(2**N):
    Y=[0]
    rest=[]
    for j in range(N):
        if i>>j&1==1:
            Y.append(city[j][1])
            yy[i][j]=0
        else:
            rest.append(j)
    for j in rest:
        res=10**15
        for k in Y:
            res=min(res,abs(city[j][1]-k))
        yy[i][j]=res

ans=[10**15 for i in range(N+1)]
for i in range(2**N):
    cond=i
    rest=[j for j in range(N) if i>>j &1==0]
    count=N-len(rest)
    while True:
        X=cond
        Y=i-cond
        temp=0
        for j in rest:
            temp+=min(xx[X][j],yy[Y][j])*city[j][2]
        ans[count]=min(ans[count],temp)
        if cond==0:
            break
        else:
            cond=(cond-1)&i

for i in range(N+1):
    print(ans[i])
### BUGGY CODE ###

l = list(map(int,input().split()))
a = l[0]
b = l[1]
n = l[2]

def floor(a,b,x):
    p = (a*x)//b - a*(x//b)
    return p

max = 0
if n <= b-1:
    max = floor(a,b,n)
else:
    for i in range(b-1,n+1,b):
        c = floor(a,b,i)
        if c >= max:
            max = c

print(max)

### FIXED CODE ###

l = list(map(int,input().split()))
a = l[0]
b = l[1]
n = l[2]

def floor(a,b,x):
    p = (a*x)//b - a*(x//b)
    return p

max = 0
if b == 1:
    max = 0
elif n <= b-1:
    max = floor(a,b,n)
elif n > b-1:
    for i in range(b-1,n+1,b):
        c = floor(a,b,i)
        if c >= max:
            max = c

print(max)
### BUGGY CODE ###

s = input()
n = int(input())
top = 0
for i in range(n):
    x = input()
    if x == "1":
        top += 1
        top = top%2
    else:
        if x.split()[1] == '1':
            if top == 0:
                s = x.split()[2] + s
            else:
                s = s + x.split()[2]
        else:
            if top == 1:
                s = x.split()[2] + s
            else:
                s = s + x.split()[2]
if top == 0:
    print(s)
else:
    print(s[::-1])


### FIXED CODE ###

s = input()
n = int(input())
top = 0
llist = ""
rlist = ""
for i in range(n):
    x = input()
    if x == "1":
        top += 1
        top = top%2
    else:
        if x.split()[1] == '1':
            if top == 0:
                llist = x.split()[2] + llist
            else:
                rlist += x.split()[2]
        else:
            if top == 1:
                llist = x.split()[2] + llist
            else:
                rlist += x.split()[2]
if top == 0:
    print(llist + s + rlist)
else:
    print(rlist[::-1] + s[::-1] + llist[::-1])
### BUGGY CODE ###

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

for i in range(N):
    X_1 = sorted(X[:i] + X[i+1:])
    print(X_1[N//2-1])

### FIXED CODE ###

N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)

a = Y[(N-1)//2]
b = Y[(N+1)//2]

for i in X:
    if i > a:
        print(a)
    else:
        print(b)
### BUGGY CODE ###

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

def ncr(n, r, p):
  num = den = 1
  for i in range(r):
    num = (num * (n - i)) % p
    den = (den * (i + 1)) % p
  return (num * pow(den, p - 2, p)) % p
p=10**9+7

ans = 0
for i in range(N-K+1):
  j = N-1-i
  ans += A[j] * ncr(j, K-1, p)
  ans %= p

for i in range(N-K+1):
  ans -= A[i] * ncr(N-i-1, K-1, p)
  ans %= p

print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
B = A[:][::-1]

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
Mod = 10**9+7
def COMinit():
  #N_C_kのN
  for i in range(2, 10**5+10):
    fac.append(fac[-1]*i%Mod)
    inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
    finv.append(finv[-1] * inv[-1] % Mod)


def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod

COMinit()

comb = {}
for i in range(K-1, N):
  comb[(i, K-1)] = COM(i, K-1)

ans = 0
for i in range(K-1, N):
  ans += A[i] * comb[(i, K-1)]
  ans %= Mod
for i in range(K-1, N):
  ans -= B[i] * comb[(i, K-1)]
  ans %= Mod
print(ans)
### BUGGY CODE ###

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

ans=0
p=0

while p!=len(a):
	if a[p]==p+1:
		p=p+1
	else:
		del a[p]
		ans=ans+1
if p==0:
	if len(a)!=0:
		print(0)
	else:
		print(-1)
else:
	print(ans)

### FIXED CODE ###

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

ans=0
p=0

for i in range(x):
	if a[i]==p+1:
		p=p+1
	else:
		ans=ans+1

if p==0:
	print(-1)
else:
	print(ans)
### BUGGY CODE ###

N = int(input())

start = 0
end = N

print(0)
s0 = input()
if s0 == 'Vacant':
    exit()

ni = (start+end)//2
print(ni, flush=True)
s = input()

while s != 'Vacant':
    if not((s == s0) ^ ((s % 2) == (s0 % 2))):
        start=ni
    else:
        end=ni

    s0=s

    ni=(start+end)//2
    print(ni, flush=True)
    s=input()


### FIXED CODE ###

N = int(input())


def ask(i):
    print(i, flush=True)
    resp = input()
    if resp == 'Vacant':
        exit()
    return resp


def test(l, r, l_resp, r_resp):
    if l % 2 == r % 2:
        return l_resp == r_resp
    else:
        return l_resp != r_resp


resp = ask(0)

l = 0
r = N
l_resp = resp
r_resp = resp

for _ in range(19):
    m = (l+r)//2
    m_resp = ask(m)
    if test(l, m, l_resp, m_resp):
        l, l_resp = m, m_resp
    else:
        r, r_resp = m, m_resp
### BUGGY CODE ###

import math

k = int(input())

def gcd(x,y):

    while y:
        x,y = y,x%y

    return x

total = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            total += math.gcd(math.gcd(a,b),c)

print(total)


### FIXED CODE ###

from math import gcd
k=int(input())
        
r=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            r+=gcd(gcd(i,j),l)
print(r)
### BUGGY CODE ###

def q4():
    N, K = (int(i) for i in input().split())
    P = [int(i) for i in input().split()]
    # pが大きいほど、期待値も大きくなる
    max_sum = 0
    max_pos = 0
    for i in range(0, N-K+1):
        s = sum(P[i:(i+K)])
        if max_sum < s:
            max_sum = s
            max_pos = i

    ans = 0
    for p in P[max_pos:(max_pos + K)]:
        s = p * (p+1) / (2 * p)
        ans += s
    print('{0:.7f}'.format(ans))

if __name__ == '__main__':
    q4()

### FIXED CODE ###

def q4():
    from itertools import accumulate

    N, K = (int(i) for i in input().split())
    P = [int(i) for i in input().split()]

    P_kitai = [0]
    # 整数1からNまでの合計は、sum = N(N+1)/2
    # 期待値は sum / N より、(N+1)/2 で表される。
    for p in P:
        P_kitai.append((p+1)/2)
    accu = list(accumulate(P_kitai))
    #print(accu)
    max_sum = 0
    for i in range(0, N-K+2):
        max_sum = max(max_sum, accu[i+K-1] - accu[i-1])
    print(max_sum)

if __name__ == '__main__':
    q4()
### BUGGY CODE ###

# E

import sys

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

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

s = sum(a)

for p in range(1,s+1) :
    if s % p != 0:
        continue
    b = s // p
    
    r1 = [x % b for x in a]
    r1.sort()
    s1 = sum(r1)
    
    mn = 1e9
    s2 = 0
    for i in range(n):
        s2 += r1[i]
        mn = min(max(s2, (n-1-i)*b - (s1-s2)), mn)
        
 
    if mn <= k :
        print(int(b))
        sys.exit(0)
        
    

### FIXED CODE ###

# E

import sys

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

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

s = sum(a)

l = []

def check(b) :
    r1 = [x % b for x in a]
    r1.sort()
    s1 = sum(r1)
    
    mn = 1e9
    s2 = 0
    for i in range(n):
        s2 += r1[i]
        mn = min(max(s2, (n-1-i)*b - (s1-s2)), mn)
        
    if mn <= k :
        print(int(b))
        sys.exit(0)
        

for p in range(1,int((s+1)**0.5+1)) :
    if s % p != 0:
        continue
    b = s // p
    l.append(b)
    check(b)
    
l.reverse()

for p in l:
    b = s // p
    check(b)
### BUGGY CODE ###

n,x,y=map(int,input().split())
x-=1
y-=1
D=[[0]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        D[i][j]=min(abs(j-i),abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))

K=[0]*(n-1)

for i in range(n-1):
    for j in range(i+1,n):
        K[D[i][j]-1]+=1

for k in K:
    print(k)

### FIXED CODE ###

n,x,y=map(int,input().split())
x-=1
y-=1
D=[[0]*n for _ in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        D[i][j]=min(abs(j-i),abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))

K=[0]*(n-1)

for i in range(n-1):
    for j in range(i+1,n):
        K[D[i][j]-1]+=1

for k in K:
    print(k)
### BUGGY CODE ###

import itertools
N = int(input())
a = list(map(int, input().split()))

def check(N, a):
    flag = True
    if( (a[-1] ^ a[1]) != a[0]):
        flag != False
    if( (a[-2] ^ a[0]) != a[-1]):
        flag != False
    for i in range(1, N-1):
        if not flag:
            break
        if( (a[i-1] ^ a[i+1]) != a[i]):
            flag = False
    return flag

for ap in itertools.permutations(a):
    f = check(N, list(ap))
    if f:
        break

if f:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

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

def mae(N, a):
    sum = a[0]
    for i in range(1, N):
        sum ^= a[i]
    return sum

if mae(N, a) == 0:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

def main():
    N = int(input())
    A = list(map(int,input().split()))
    Q = int(input())
    B = [0 for i in range(Q)]
    C = [0 for i in range(Q)]
    
    A_kind = []
    A_num = []
    ans = 0
    for a in A:
        ans += a
        if not a in A_kind:
            A_kind.append(a)
            A_num.append(1)
        else:
            A_num[A_kind.index(a)] += 1
    
    for q in range(Q):
        b,c = map(int,input().split())
        if b in A_kind:
            n = A_kind.index(b)
            ans += (c - A_kind[n])*A_num[n]
            if c in A_kind:
                A_num[A_kind.index(c)] += A_num[n]
                del A_kind[n]
                del A_num[n]
            else:
                A_kind[n] = c
        print(ans)
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int,input().split()))
    Q = int(input())
    B = [0 for i in range(Q)]
    C = [0 for i in range(Q)]
    
    A_num = [0 for i in range(10**5+1)]
    ans = 0
    for a in A:
        ans += a
        A_num[a] += 1
    
    for q in range(Q):
        b,c = map(int,input().split())
        if A_num[b] != 0:
            ans += (c-b)*A_num[b]
            A_num[c] += A_num[b]
            A_num[b] = 0
            
        print(ans)
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

def main():
    N, H = map(int, input().split())

    A = [0] * N
    B = [0] * N

    num_list = []
    for i in range(N):
        a, b = map(int, input().split())
        A[i] = a
        B[i] = b
        num_list.append(a)
        num_list.append(b)

    num = sorted(num_list, reverse=True)

    ans = 0
    for a in num:
        if a in A:
            ans += -(-H // a)
            break
        else:
            ans += 1
            H -= a

    print(ans)

main()

### FIXED CODE ###

def main():
    N, H = map(int, input().split())

    A = [0] * N
    B = [0] * N

    num_list = []
    for i in range(N):
        a, b = map(int, input().split())
        A[i] = a
        B[i] = b

    sort_B = sorted(B, reverse=True)
    max_A = max(A)
    ans = 0
    for b in sort_B:
        if b > max_A:
            ans += 1
            H -= b
        else:
            break
        
        if H <= 0:
            break
    
    if H > 0:
        ans += -(-H // max_A)

    print(ans)

main()
### BUGGY CODE ###

import numpy as np
import math
import collections
import bisect


a, b, c, d = map(int, input().split())

dp = np.array([[[1 for k in range(2)] for i in range(d + 1)] for j in range(c + 1)])
dp[:, :, 1] = 0
dp[0:a, :, :] = 0
dp[:, 0:b, :] = 0
#dp = list(dp)

for i in range(a, c + 1):
    for j in range(b, d + 1):
        # print(i, j, dp[i][j])
        if a == i and b == j:
            continue
        dp[i][j][0] = (i * dp[i][j - 1][0] + dp[i][j - 1][1]) % 998244353
        dp[i][j][1] = (j * (dp[i - 1][j][0] + dp[i - 1][j][1])) % 998244353

print((dp[c][d][0] + dp[c][d][1]) % 998244353)


### FIXED CODE ###

#import numpy as np
import math
import collections
import bisect


def main():
    a, b, c, d = map(int, input().split())

    dp0 = [[1 for i in range(d + 1)] for j in range(c + 1)]
    dp1 = [[0 for i in range(d + 1)] for j in range(c + 1)]
    for i in range(c + 1):
        for j in range(d + 1):
            if j < b or i < a:
                dp0[i][j] = 0
                dp1[i][j] = 0
    for i in range(a, c + 1):
        for j in range(b, d + 1):
            # print(i, j, dp[i][j])
            if a == i and b == j:
                continue
            dp0[i][j] = ((i * dp0[i][j - 1]) % 998244353 + dp1[i][j - 1]) % 998244353
            dp1[i][j] = (j * (dp0[i - 1][j] + dp1[i - 1][j]) % 998244353) % 998244353

    print((dp0[c][d] + dp1[c][d]) % 998244353)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
MB = {}; MW = {}
for i in range(2*N):
    c, a = input().split()
    a = int(a)
    if c == 'W':
        MW[a] = i
    else:
        MB[a] = i
data = [0]*(2*N+1)
def add(k, x):
    while k <= 2*N:
        data[k] += x
        k += k & -k
def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s
AW = sorted(MW)
AB = sorted(MB)
cB = [[0]*(N+1) for i in range(N+1)]
cW = [[0]*(N+1) for i in range(N+1)]

IW = [MW[a]+1 for a in AW]
IB = [MB[a]+1 for a in AB]

for i in range(2*N):
    add(i+1, 1)
for i in range(N):
    cWi = cW[i]; cBi = cB[i]
    for j in range(N):
        cWi[j] = get(IW[i])-1
        cBi[j] = get(IB[j])-1
        add(IB[j], -1)
    cWi[N] = get(IW[i])-1

    for j in range(N):
        add(IB[j], 1)
    if i < N:
        add(IW[i], -1)
cBi = cB[N]
for j in range(N):
    cBi[j] = get(IB[j])-1
    add(IB[j], -1)

dp = [[10**9]*(N+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N+1):
    T = dp[i]
    S = dp[i-1]
    cWi = cW[i-1]; cBi = cB[i]
    for j in range(N+1):
        v = T[j]
        if i:
            v = min(v, S[j] + cWi[j])
        if j:
            v = min(v, T[j-1] + cBi[j-1])
        T[j] = v
print(dp[N][N])

### FIXED CODE ###

from bisect import bisect
N = int(input())
B = []
BW = []; BB = []
MB = {}; MW = {}
for i in range(2*N):
    c, a = input().split()
    a = int(a)
    c = "BW".index(c)
    B.append((c, a))
    if c:
        MW[a-1] = i
    else:
        MB[a-1] = i

P = [[0]*(N+1) for i in range(N+1)]
Q = [[0]*(N+1) for i in range(N+1)]

for p in range(N):
    cnt = MW[p] - sum(MW[p0] < MW[p] for p0 in range(p))

    P[p][0] = cnt
    for q in range(N):
        if MB[q] < MW[p]:
            cnt -= 1
        P[p][q+1] = cnt

for q in range(N):
    cnt = MB[q] - sum(MB[q0] < MB[q] for q0 in range(q))

    Q[q][0] = cnt
    for p in range(N):
        if MW[p] < MB[q]:
            cnt -= 1
        Q[q][p+1] = cnt

dist = [[10**9]*(N+1) for i in range(N+1)]
dist[0][0] = 0
que = [(0, 0, 0)]
for i in range(N):
    dist[i+1][0] = dist[i][0] + P[i][0]
for i in range(N):
    dist[0][i+1] = dist[0][i] + Q[i][0]
for i in range(N):
    for j in range(N):
        dist[i+1][j+1] = min(dist[i][j+1] + P[i][j+1], dist[i+1][j] + Q[j][i+1])
print(dist[N][N])