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

import sys
input = sys.stdin.readline

n = int(input())
arr = [int(x) for x in input().split()]
Max = 3005

dp = [[0] * n for _ in range(n)]

for l in range(n-1,-1,-1):
    for r in range(l, n):
        if l == r:
            dp[l][r] = arr[l]
        else:
            dp[l][r] = max(arr[l] - dp[l+1][r], arr[r] - dp[l][r-1])

print(dp[0][n-1])

### FIXED CODE ###

def deque(n, arr):
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = arr[i]

    for l in range(n-2, -1, -1):
        for r in range(l+1, n):
            L = arr[l] - dp[l+1][r]
            R = arr[r] - dp[l][r-1]
            dp[l][r] = L if L > R else R
    return dp[0][n-1]

n = int(input())
arr = [int(x) for x in input().split()]
print(deque(n, arr))
### BUGGY CODE ###

import heapq

def main():
    n, m = map(int, input().split())
    dics = [{} for _ in range(n)]
    rmky = [set() for _ in range(n)]
    for _ in range(m):
        l, r, c = map(int, input().split())
        ky = (l-1, r-1)
        if ky in dics[l-1]:
            if c < dics[l-1][ky]:
                dics[l-1][ky] = c
        else:
            dics[l-1][ky] = c
        if r < n:
            rmky[r].add(ky)
    dist = [float("inf")]*n
    dist[0] = 0
    hq = []
    heapq.heappush(hq, [0, 0])
    idx = 0
    while len(hq) > 0:
        v, p = heapq.heappop(hq)
        if v > dist[p]:
            continue
        if p == n-1:
            break
        for i in range(idx, p):
            if len(dics[i]) > 0:
                dics[p].update(dics[i])
            if len(rmky[i]) > 0:
                for ky in rmky[i]:
                    dics[p].pop(ky)
        idx = p
        for l, r in dics[p].keys():
            if dist[r] > v + dics[p][(l, r)]:
                heapq.heappush(hq, [v + dics[p][(l, r)], r])
            for i in reversed(range(l, r+1)):
                if dist[i] > v + dics[p][(l, r)]:
                    dist[i] = v + dics[p][(l, r)]
                else:
                    break
    if dist[n-1] == float("inf"):
        print(-1)
    else:
        print(dist[n-1])

if __name__ == "__main__":
    main()


### FIXED CODE ###

import heapq

def main():
    n, m = map(int, input().split())
    dics = [{} for _ in range(n)]
    for _ in range(m):
        l, r, c = map(int, input().split())
        ky = r-1
        if ky in dics[l-1]:
            if c < dics[l-1][ky]:
                dics[l-1][ky] = c
        else:
            dics[l-1][ky] = c
    dist = [float("inf")]*n
    dist[0] = 0
    hq = []
    heapq.heappush(hq, [0, 0])
    idx = 0
    while len(hq) > 0:
        v, p = heapq.heappop(hq)
        if p < idx:
            continue
        if p == n-1:
            break
        for i in range(idx+1, p):
            if len(dics[i]) > 0:
                for ky in dics[i].keys():
                    if ky in dics[p]:
                        if dics[p][ky] > dics[i][ky]:
                            dics[p][ky] = dics[i][ky]
                    else:
                        if p < ky:
                            dics[p][ky] = dics[i][ky]
        idx = p
        for r in dics[p].keys():
            if dist[r] > v + dics[p][r]:
                dist[r] = v + dics[p][r]
                heapq.heappush(hq, [v + dics[p][r], r])
    if dist[n-1] == float("inf"):
        print(-1)
    else:
        print(dist[n-1])

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


def factorization(n):
    pf_cnt = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            pf_cnt[i] = cnt

    if temp != 1: pf_cnt[temp] = 1
    if not pf_cnt: pf_cnt[n] = 1

    return pf_cnt


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

al_fac = []
for a in al:
    fac = factorization(a)
    al_fac.append(fac)

gcd_l = [1]*n
gcd_r = [1]*n

gcd_l[0] = al_fac[0]
gcd_r[-1] = al_fac[-1]

for i in range(1,n):
    next_l = al_fac[i]
    next_l_gcd = {1:1}
    for prime,cnt in next_l.items():
        if prime in gcd_l[i-1]:
            next_l_gcd[prime] = min(cnt, gcd_l[i-1][prime])
    gcd_l[i] = next_l_gcd

    next_r = al_fac[n-i-1]
    next_r_gcd = {1:1}
    for prime,cnt in next_r.items():
        if prime in gcd_r[n-i]:
            next_r_gcd[prime] = min(cnt, gcd_r[n-i][prime])
    gcd_r[n-i-1] = next_r_gcd

ans = 1
for i in range(1,n-1):
    curr_gcd = 1
    for prime,cnt in gcd_l[i-1].items():
        if prime in gcd_r[i+1]:
            min_cnt = min(cnt, gcd_r[i+1][prime])
            curr_gcd *= prime**min_cnt
    ans = max(ans, curr_gcd)


# i = 0
curr_gcd = 1
for prime,cnt in gcd_r[1].items():
    curr_gcd *= (prime**cnt)
ans = max(ans, curr_gcd)

# i = n-1
curr_gcd = 1
for prime,cnt in gcd_l[n-2].items():
    curr_gcd *= (prime**cnt)
ans = max(ans, curr_gcd)

# print(al_fac)
# print(gcd_l)
# print(gcd_r)
print(ans)

### FIXED CODE ###

from fractions import gcd

def factorization(n):
    pf_cnt = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            pf_cnt[i] = cnt

    if temp != 1: pf_cnt[temp] = 1
    if not pf_cnt: pf_cnt[n] = 1
    return pf_cnt


def main():
    n = int(input())
    al = list(map(int, input().split()))

    gcd_l = [1]*n
    gcd_r = [1]*n

    gcd_l[0] = al[0]
    gcd_r[-1] = al[-1]

    for i in range(1,n):
        next_l = al[i]
        gcd_l[i] = gcd(next_l, gcd_l[i-1])

        next_r = al[n-i-1]
        gcd_r[n-i-1] = gcd(next_r, gcd_r[n-i])


    ans = max(gcd_r[1], gcd_l[n-2])
    for i in range(1,n-1):
        curr_gcd = gcd(gcd_l[i-1], gcd_r[i+1])
        ans = max(ans, curr_gcd)

    print(ans)


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

K, S = map(int, input().split())
ans = 0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x+y+z == S:
                ans += 1
print(ans)

### FIXED CODE ###

K, S = list(map(int, input().split()))
count = 0

for x in range(K + 1):
    for y in range(K + 1):
        z = S - x - y
        if z >= 0 and z <= K:
            count += 1

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

from scipy.sparse.csgraph import dijkstra
import sys
def main():
	input = sys.stdin.readline

	n,x,y = map(int,input().split())

	route = [[0 for _ in range(n)]for _ in range(n)]
	for i in range(n-1):
		route[i][i+1] = 1

	route[x-1][y-1] = 1
	route[y-1][x-1] = 1
	route = tuple(route)
	#res = shortest_path(route, unweighted=False,directed=False)
	res = dijkstra(route, directed=False)

	ans = [0 for _ in range(n)]
	for i in range(n):
		for j in range(i,n):
			ans[int(res[i][j])] += 1

	for i in range(1,n):
		print(ans[i])
if __name__ == '__main__':
    main()

### FIXED CODE ###

from scipy.sparse.csgraph import dijkstra
import sys
def main():
	input = sys.stdin.readline

	n,x,y = map(int,input().split())

	route = [[0 for _ in range(n)]for _ in range(n)]
	for i in range(n-1):
		route[i][i+1] = 1

	route[x-1][y-1] = 1
	route[y-1][x-1] = 1
	route = tuple(route)
	#res = shortest_path(route, unweighted=False,directed=False)
	res = tuple(dijkstra(route, directed=False))

	ans = [0 for _ in range(n)]
	for i in range(n):
		for j in range(i,n):
			ans[int(res[i][j])] += 1

	for i in range(1,n):
		print(ans[i])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N, M = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(M)]

from collections import defaultdict
from collections import deque
g = defaultdict(set)

for x, y in XY:
  g[x].add(y)

  
def bfs(u):
  s = deque([u])
  cost = {u: 0}
  done = set()
  while s:
    u = s.popleft()
    if u not in done:
      done.add(u)
    else:
      continue
    for v in g[u]:
      cost[v] = cost[u] + 1
      if v in done:
        done.remove(v)
      s.append(v)

  return cost
  
ans = 0
for i in range(1, N+1):
  d = bfs(i)
  ans = max(ans, max(d.values()))
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(M)]

from collections import defaultdict
from collections import deque
from collections import Counter
g = defaultdict(set)

for x, y in XY:
  g[x].add(y)
  
  
def TSort(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v))
    V = set(V)
    funin = Counter()
    
    for u in V:
        for v in g[u]:
            funin[v] += 1
    
    q = deque()
    for v in V:
        if funin[v] == 0:
            q.append(v)
    L = []
    while q:
        u = q.popleft()
        L.append(u)
        for v in g[u]:
            funin[v] -= 1
            if funin[v] == 0:
                q.append(v)
    return L

  
D = Counter()
ns = TSort(g)
for u in ns:
  for v in g[u]:
    D[v] = max(D[v], D[u] + 1)
print(D.most_common()[0][1])
### BUGGY CODE ###

import itertools
ans=0
N=int(input())
S=input()

for i in itertools.combinations(range(N),3):
  if (i[0]+i[2])/2 ==i[1]:
    continue
  L=[S[i[0]],S[i[1]],S[i[2]]]
  if len(set(L))!=3:
    continue
  ans+=1
  
print(ans)   

### FIXED CODE ###

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

r_cnt=S.count('R')
g_cnt=S.count('G')
b_cnt=S.count('B')

ans=r_cnt*g_cnt*b_cnt

for i in range(N):
  for d in range(N):
    j=i+d
    k=j+d
    if k>=N:break
#等号がないと範囲外参照になる、0-indexだからk=S[N]は無い      
    if S[i]!=S[j] and S[i]!=S[k] and S[k]!=S[j]:
      ans-=1
      
print(ans)
### BUGGY CODE ###

INF = 2000000000
n,limit_w = map(int, input().split())
w = [0]*n
v = [0]*n
for i in range(n):
    w[i], v[i] = map(int, input().split())
sum_v = sum(v)
dp = [INF for i in range(sum_v + 1)]
dp[0] = 0
for i in range(n):
    for j in range(sum_v ,-1 ,-1):
        if j >= v[i]:
            dp[j] = min(dp[j], dp[j - v[i]] + w[i])
for i in range(sum_v, -1, -1):
    if dp[i] <= limit_w:
        print(i)
        break

### FIXED CODE ###

INF = 2000000000
n,limit_w = map(int, input().split())
w = [0]*n
v = [0]*n
for i in range(n):
    w[i], v[i] = map(int, input().split())
sum_v = sum(v)
dp = [INF for i in range(sum_v + 1)]
dp[0] = 0
for i in range(n):
    for j in range(sum_v ,-1 ,-1):
        if j >= v[i]:
            dp[j] = min(dp[j], dp[j - v[i]] + w[i])
for i in range(sum_v, -1, -1):
    if dp[i] <= limit_w:
        print(i)
        break
### BUGGY CODE ###

n, y = map(int, input().split())
flag = False
a = 0
b = 0
c = 0

for a in range(0, n+1):
    if(10000*a+5000*b+1000*c==y and a+b+c==n):
        print('{} {} {}'.format(a, b, c))
        flag = True
        break
    for b in range(0, n+1-a):
        if(10000*a+5000*b+1000*c==y and a+b+c==n):
            print('{} {} {}'.format(a, b, c))
            flag = True
            break
        for c in range(0, n+1-a-b):
            if(10000*a+5000*b+1000*c==y and a+b+c==n):
                print('{} {} {}'.format(a, b, c))
                flag = True
                break
        else:
            continue
        break
    else:
        continue
    break
    
if not flag:
    print('-1 -1 -1')

### FIXED CODE ###

n, y = map(int, input().split())
flag = False
a = 0
b = 0
c = 0

for a in range(0, n+1):
    for b in range(0, n+1-a):
        c = n - a - b
        if(10000*a+5000*b+1000*c==y):
            print('{} {} {}'.format(a, b, c))
            flag = True
            break
        else:
            continue
        break
    else:
        continue
    break
    
if not flag:
    print('-1 -1 -1')
### BUGGY CODE ###

x,y,z,k = map(int,input().split())

info = [list(map(int,input().split())) for i in range(3)]

li = []
ans = []
li_append = li.append 
ans_append = ans.append

for i in info[0]:
  for j in info[1]:
    li_append(i+j)
li = sorted(li,reverse=True)

for i in li[:3000]:
  for j in info[2]:
    ans_append(i+j)
ans = sorted(ans,reverse = True)

for i in range(k):
  print(ans[i])

### FIXED CODE ###

x,y,z,k = map(int,input().split())

info = [list(map(int,input().split())) for i in range(3)]
info[0]=sorted(info[0],reverse=True)
info[1]=sorted(info[1],reverse=True)
info[2]=sorted(info[2],reverse=True)
li = []
ans = []
li_append = li.append 
ans_append = ans.append

for i in info[0]:
  for j in info[1]:
    li_append(i+j)
li = sorted(li,reverse=True)

for i in li[:3000]:
  for j in info[2]:
    ans_append(i+j)
ans = sorted(ans,reverse = True)

for i in range(k):
  print(ans[i])
### BUGGY CODE ###

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

routes = []
for i in range(m):
    x,y = map(int, input().split())
    routes.append([x-1,y-1])
    # routes[i] = routes[i] - [1,1] #道の番号をずらす

rooms = [0 for i in range(n)] # 行ったら1,まだなら0
marks = [0 for i in range(n)] # 部屋におく道標
rooms_rate = [[0]] # １回目、２回目、３回目…に行ける部屋
rooms[0] = 1

turn = 0
for i in rooms_rate:
    newrate = []
    for j in rooms_rate[turn]: #turn回目に行ける部屋を調べる
        for k in range(m):
            a = routes[k][0]
            b = routes[k][1]
            if (j == a and rooms[b] == 0):
                rooms[b] = 1
                marks[b] = a
                newrate.append(b)
            elif (j == b and rooms[a] == 0):
                rooms[a] = 1
                marks[a] = b
                newrate.append(a)
    rooms_rate.append(newrate)
    if (len(newrate) == 0):
        break
    turn = turn + 1


if(all(rooms) == True):
    print('Yes')
    for i in range(1,n):
        print(str(int(marks[i]) + 1))

else:
    print('No')

### FIXED CODE ###

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

routes = [[] for i in range(n)]
for i in range(m):
    x,y = map(int, input().split())
    routes[x-1].append(y-1)
    routes[y-1].append(x-1)


rooms = [0 for i in range(n)] # 行ったら1,まだなら0
marks = [0 for i in range(n)] # 部屋におく道標
rooms_rate = [[0]] # ０回目、１回目、２回目、３回目…に行ける部屋
rooms[0] = 1

turn = 0
for i in rooms_rate:
    newrate = []
    for j in rooms_rate[turn]: #(turn)回目に行けた部屋から行ける部屋を調べる
        for k in routes[j]: 
            if (rooms[k] == 0): #行ったことのない部屋なら
                rooms[k] = 1
                marks[k] = j # 道標をセット
                newrate.append(k)
    rooms_rate.append(newrate)
    if (len(newrate) == 0): #新しく行けなくなったら終わり
        break
    turn = turn + 1


if(all(rooms) == True):
    print('Yes')
    for i in range(1,n):
        print(str(int(marks[i]) + 1))

else:
    print('No')
### BUGGY CODE ###

a, b, k = map(int, input().split())
k -= 1

for i in range(a, b+1):
    if i <= a + k:
        print(i)
    elif i >= b - k:
        print(i)

### FIXED CODE ###

a, b, k = map(int, input().split())

for i in range(a, min(a+k, b+1)):
    print(i)
for i in range(max(a+k, b+1-k), b+1):
    print(i)
### BUGGY CODE ###

N=int(input())
number_of_withdrawal=[]

def floor(float_number):
    integer = 0
    while integer < float_number:
        integer+=1
    if integer == float_number:
        return integer
    else:
        integer-=1
        return integer

for money_6 in range(0, N+1):
    money_9 = N-money_6

    i=0
    count_6_pow_number=[]
    while pow(6,i)<=money_6:
        count_6_pow_number.append((floor(money_6/pow(6,i)))%6)
        i+=1
    j=0
    count_9_pow_number=[]
    while pow(9,j)<=money_9:
        count_9_pow_number.append((floor(money_9/pow(9,j)))%9)
        j+=1

    # print(money_6, money_9, sum(count_6_pow_number), sum(count_9_pow_number))
    number_of_withdrawal.append(sum(count_6_pow_number)+sum(count_9_pow_number))


print(min(number_of_withdrawal))

### FIXED CODE ###

import math

N=int(input())
number_of_withdrawal=[100000]

# def floor(float_number):
#     integer = 0
#     while integer < float_number:
#         integer+=1
#     if integer == float_number:
#         return integer
#     else:
#         integer-=1
#         return integer

for money_6 in range(0, N+1):
    money_9 = N-money_6

    i=0
    count_6_pow_number=0
    while pow(6,i)<=money_6:
        count_6_pow_number += (math.floor(money_6/pow(6,i)))%6
        i+=1
    j=0
    count_9_pow_number=0
    while pow(9,j)<=money_9:
        count_9_pow_number += (math.floor(money_9/pow(9,j)))%9
        j+=1

    # print(money_6, money_9, sum(count_6_pow_number), sum(count_9_pow_number))
    number_of_withdrawal.append(count_6_pow_number+count_9_pow_number)

print(min(number_of_withdrawal))
### BUGGY CODE ###

def check(a):
    if len(str(a)) == 1:
        return True
    a = list(str(a))
    b = [abs(int(a[i]) - int(a[i + 1])) for i in range(len(a) - 1)]
    if max(b) > 1:
        return False
    else:
        return True

k = int(input())
a = 0
while True:
    a += 1
    if check(a):
        k -= 1
    if k == 0:
        print(a)
        exit()

### FIXED CODE ###

from collections import deque


k = int(input())
q = deque(range(1, 10))

for i in range(k):
    x = q.popleft()
    if x % 10 != 0:
        q.append(10 * x + x % 10 - 1)
    q.append(10 * x + x % 10)
    if x % 10 != 9:
        q.append(10 * x + x % 10 + 1)

print(x)
### BUGGY CODE ###

s = input()
n = len(s)
sums_from_first_mod = [0] * (n+1)
for i in range(1,n+1):
    sums_from_first_mod[i] = (sums_from_first_mod[i-1] + int(s[i-1])) % 3
# print(sums_from_first_mod)
ind0 = [i for i, x in enumerate(sums_from_first_mod) if x == 0]
ind1 = [i for i, x in enumerate(sums_from_first_mod) if x == 1]
ind2 = [i for i, x in enumerate(sums_from_first_mod) if x == 2]
indices = [ind0, ind1, ind2]    
# print(indices)
cnt = 0
for num in range(3):
    for i in indices[num]:
        for j in indices[num]:
            if j >= i+4:
                if int(s[i:j]) % 673 == 0:
                    cnt += 1
print(cnt)

### FIXED CODE ###

s = input()
n = len(s)
p = 2019
ans = 0

num_rem = [0] * p
t = 1
mod = 0
num_rem[mod] = 1
for i in range(n):
    mod = (mod + int(s[-i-1])*t)%p
    num_rem[mod] += 1
    t = (10*t)%p
for m in num_rem:
    ans += (m*(m-1))//2
print(ans)
### BUGGY CODE ###

import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
a.sort()
s = set(a)
c = collections.Counter(a)
q = int(input())
for _ in range(q):
    cf, ca = map(int, input().split())
    if ca in c:
        c[ca] += c[cf]
        c[cf] = 0
#         del sd[cf]
#         del c[cf]
    else:
#         sd[ca] = sd[cf]
        c[ca] = c[cf]
        c[cf] = 0
#         del sd[cf]
#         del c[cf]
    total = 0
    for key, val in c.items():
#         print(key, val)
        total += key * val
    print(total)



### FIXED CODE ###

import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
c_n = np.array([(k, v) for k, v in c.items()])
total = np.dot(c_n.T[0], c_n.T[1])
q = int(input())
for _ in range(q):
    cf, ca = map(int, input().split())
    num = c[cf]
    if ca in c:
        c[ca] += c[cf]
        c[cf] = 0
#         del sd[cf]
#         del c[cf]
    else:
#         sd[ca] = sd[cf]
        c[ca] = c[cf]
        c[cf] = 0
#         del sd[cf]
#         del c[cf]
    total += num * (ca - cf)
    print(total)
### BUGGY CODE ###

N, K = map(int, input().split())
step = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0
for i, s in enumerate(step):
  for k in range(1, K + 1):
    if i < k:
      break
    dp[i] = min(dp[i], dp[i - k] + abs(step[i - k] - step[i]))
print(dp[N - 1])

### FIXED CODE ###

N, K = map(int, input().split())
step = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0
for i, s in enumerate(step):
  for k in range(1, K + 1):
    if i < k:
      break
    dp[i] = min(dp[i], dp[i - k] + abs(step[i - k] - step[i]))
print(dp[N - 1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10000)
def conv(r,s,p,j):
    if j == 'r':
        return p
    if j == 's':
        return r
    if j == 'p':
        return s
def listint():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a
def perse(t,k,num):
    stri = []
    point = []
    for i in range(k):
        stri.append([])
        point.append([])
    for i in range(num):
        stri[i%k].append(t[i])
        point[i%k].append(conv(r,s,p,t[i]))
    return stri,point
def main(q,point):
    if len(q) == 1:
        return point[0]
    if len(q) == 0:
        return 0
    if q[0] != q[1]:
        return main(q[1:],point[1:]) + point[0]
    else:
        return main(q[2:],point[2:]) + point[0]
num,k = listint()
r,s,p = listint()
t = input()
afterperse,point = perse(t,k,num)
ans = 0
for i in range(k):
    ans = ans + main(afterperse[i],point[i])
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000)
def conv(r,s,p,j):
    if j == 'r':
        return p
    if j == 's':
        return r
    if j == 'p':
        return s
def listint():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a
def perse(t,k,num):
    stri = []
    for i in range(k):
        stri.append([])
    for i in range(num):
        stri[i%k].append(t[i])
    return stri
def main(q):
    i = 0
    ans = 0
    while i < len(q)-1:
        if q[i] == q[i+1]:
            ans = ans + conv(r,s,p,q[i])
            i = i+2
        else:
            ans = ans + conv(r,s,p,q[i])
            i = i+1
    if i == len(q)-1:
        ans = ans + conv(r,s,p,q[i])
    return ans
num,k = listint()
r,s,p = listint()
t = input()
afterperse = perse(t,k,num)
ans = 0
for i in range(k):
    ans = ans + main(afterperse[i])
print(ans)
### BUGGY CODE ###

N = int(input())

S = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

for j in range (0, 1000000):
	for i in range (0, 26):
		S.append(S[j]+chr(96+i))

print(S[N])

### FIXED CODE ###

N = int(input())
Alphabet = str('abcdefghijklmnopqrstuvwxyz')
import bisect

List = [0, 26, 702, 18278, 475254, 12356630, 321272406, 8353082582, 217180147158, 5646683826134, 146813779479510, 3817158266467286, 99246114928149462, 2580398988131886038, 67090373691429037014, 1744349715977154962390, 45353092615406029022166, 1179180408000556754576342, 30658690608014475618984918]
V = []

if List.count(N) == 1:
	for i in range (0, List.index(N)):
		V.append('z')
	print(*V, sep = '')
	exit()

k = 26
A = [0]
for i in range (2, 20):
	A.append(k)
	k = k+26**i
    
S = []

B = bisect.bisect_right(A, N)

N = N-A[B-1]-1
for i in range (0, B):
	S.append(Alphabet[N%26])
	N = N//26
    
S = reversed(S)
print(*S, sep = '')
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    prev_p = 1
    g = []
    while True:
        if g[:len(g)//2]==g[len(g)//2:] and len(g) > 0:
            break
        g.append(A[prev_p-1])
        prev_p = g[-1]  

    K = K % len(g)
    print(g[K-1])


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    prev_p = 1
    g = []
    seen = [0]*N
    i = 0
    while True:
        if seen[prev_p-1]:
            break
        seen[prev_p-1] = i
        g.append(A[prev_p-1])
        prev_p = g[-1]
        i += 1
    g_periodic = g[seen[prev_p-1]:]  
    g_before = g[:seen[prev_p-1]]

    if K <= len(g_before):
        print(g_before[K-1])
    else:
        K_new = (K - len(g_before)) % len(g_periodic)
        print(g_periodic[K_new-1])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

s = list(input())
ans = 0
for i in range(s.count("W")):
    ans += s.index("W")
    s.pop(s.index("W"))
print(ans)

### FIXED CODE ###

s = input()
ans = 0
count = 0
for i in range(len(s)):
    if s[i] == "W":
        ans += i - count
        count += 1
print(ans)