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

a,b,c,x,y = map(int,input().split())
ans = 10**10

# Aピザをi枚Bピザをj枚買う
for i in range(x+1):
    for j in range(y+1):
        # cピザを買う必要のある枚数
        k = max(x-i,y-j)*2
        # 合計金額
        ans = min(ans,i*a+j*b+k*c)

print(ans)

### FIXED CODE ###

from sys import stdin
import numpy as np
a,b,c,x,y= [int(x) for x in stdin.readline().rstrip().split()]

if x >= y:
    print(min(a*x+b*y,c*2*y+a*(x-y),c*2*x))
else:
    print(min(a*x+b*y,c*2*x+b*(y-x),c*2*y))
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
import sys
import math
def setwise_coprime(a):
  ans=a[0]
  for i in range(1,n):
    ans=math.gcd(ans,a[i])
  return ans

ruiseki=1
for i in range(n):
  ruiseki=ruiseki*a[i]

for i in range(n):
    num=math.gcd(a[i],(ruiseki//a[i])%a[i])
    if num!=1:
      if setwise_coprime(a)==1:
        print("setwise coprime")
        sys.exit()
      else:
        print("not coprime")
        sys.exit()
print("pairwise coprime")

        












### FIXED CODE ###

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

import sys
import math
def setwise_coprime(a):
  ans=a[0]
  for i in range(1,n):
    ans=math.gcd(ans,a[i])
  return ans

#エラストテネスのふるい
def create_sieve(n):
  sieve=[0]*(n+1)
  for i in range(2,n+1):
    if sieve[i]==0:
      for j in range(i*i,n+1,i):
        sieve[j]=i
  return sieve

#高速素因数分解
def fast_factorization(n, sieve):
  prime={}
  while n>1:
    p=sieve[n]
    #nが素数の場合
    if p==0:
      prime[n]=prime.get(n,0)+1
      break
    #nが素数ではない場合
    else:
      prime[p]=prime.get(p,0)+1
      n=n//p
  return prime

check=set()
if setwise_coprime(a)==1:
  #素因数のダブリをcheck
  sieve=create_sieve(10**6)
  for i in range(n):
    if a[i]!=1:
      s=fast_factorization(a[i], sieve)
      for i in s:
        if i in check:
          print("setwise coprime")
          sys.exit()
        else:
          check.add(i)
  print("pairwise coprime")    
else:
  print("not coprime")
### BUGGY CODE ###

X = list(input())

q_num = X.count("?")
a_num = 0
c_num = X.count("C")
left_q_num = 0
right_q_num = q_num
ans = 0
len_x = len(X)
q_dict = {}
for i in range(q_num + 1):
    q_dict[i] = 3 ** i

if X[0] == "?":
    right_q_num -= 1
elif X[0] == "C":
    c_num -= 1
for i, x in enumerate(X):
    if x == "B" or x == "?":
        ans += (a_num * c_num)  * (q_dict[(left_q_num + right_q_num)])
        if left_q_num + right_q_num >= 2:
            ans += (right_q_num * left_q_num  + 3*(left_q_num * c_num) + 3*(right_q_num * a_num)) * (q_dict[(left_q_num + right_q_num - 2)])
        elif left_q_num + right_q_num == 1:
            ans += ((left_q_num * c_num) + (right_q_num * a_num)) * (q_dict[(left_q_num + right_q_num - 1)])
        ans = ans % (10 ** 9 + 7)
    if  i == len_x - 1:
        break
    if x == "A":
        a_num += 1
    elif x == "?":
        left_q_num += 1
    if X[i + 1] == "C":
        c_num -= 1
    elif X[i + 1] == "?":
        right_q_num -= 1

print(ans % (10 ** 9 + 7))



### FIXED CODE ###

X = list(input())

q_num = X.count("?")
a_num = 0
c_num = X.count("C")
left_q_num = 0
right_q_num = q_num
ans = 0
len_x = len(X)
q_dict = []
b_ans = 0
q_ans = 0
q_dict = {}
q_dict[q_num - 1] = (3 ** (q_num - 1)) % (10 ** 9 + 7)
q_dict[q_num - 2] = (3 ** (q_num - 2)) % (10 ** 9 + 7)
q_dict[q_num - 3] = (3 ** (q_num - 3)) % (10 ** 9 + 7)
q_dict[q_num] = (3 ** (q_num)) % (10 ** 9 + 7)

if X[0] == "?":
    right_q_num -= 1
elif X[0] == "C":
    c_num -= 1
for i, x in enumerate(X):
    if x == "B" or x == "?":
        ans += (a_num * c_num)  * (q_dict[(left_q_num + right_q_num)])
        if left_q_num + right_q_num >= 2:
            ans += (right_q_num * left_q_num  + 3*(left_q_num * c_num) + 3*(right_q_num * a_num)) * (q_dict[(left_q_num + right_q_num - 2)])
        elif left_q_num + right_q_num == 1:
            ans += ((left_q_num * c_num) + (right_q_num * a_num)) * (q_dict[(left_q_num + right_q_num - 1)])
        ans = ans % (10 ** 9 + 7)
    if  i == len_x - 1:
        break
    if x == "A":
        a_num += 1
    elif x == "?":
        left_q_num += 1
    if X[i + 1] == "C":
        c_num -= 1
    elif X[i + 1] == "?":
        right_q_num -= 1

print(ans % (10 ** 9 + 7))
### BUGGY CODE ###

import sys

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

n_str = str(n)
li_size = len(li)

for i in range(li_size):
  li_contents = li[i] - 1
  for j in range(li_size - i):
    if li_contents > li[j + i]:
      print("No")
      sys.exit()
print("Yes")


### FIXED CODE ###

import sys

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

n_str = str(n)
li_size = len(li)
max = li[0]
for i in range(li_size):
  if max == li[i]:
    continue
  elif max > li[i]:
    print("No")
    sys.exit()
  elif max < li[i]:
    max = li[i] - 1
print("Yes")
### BUGGY CODE ###

import bisect

n = int(input())

a = []
a.append(0)

for i in range(n):
    b = int(input())
    k = bisect.bisect(a,b)
    if b != a[k-1]:
        a.insert(k,b)
    else:
        a.pop(k-1)
print(len(a)-1)

### FIXED CODE ###

import collections

n = int(input())

co = collections.Counter([int(input()) for i in range(n)])

c =0

for i in co.values():
    if i % 2 != 0:
        c  +=1
print(c)
### BUGGY CODE ###

import math

MOD = 10**9+7


def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0


def modinv(a):
    g, x, y = xgcd(a, MOD)
    return x % MOD


fact = [1] * 200100
for i in range(1, 200100):
    fact[i] = fact[i-1] * i % MOD


def comb(n, r):
    if n < r or r < 0:
        return 0
    else:
        return fact[n] * modinv(fact[n - r]) % MOD * modinv(fact[r]) % MOD


n = int(input())
a = list(map(int, input().split()))
x = sum(a) - sum(i for i in range(1, n + 1))

l = 0
while a[l] != x:
    l += 1
r = 0
while a[n - r] != x:
    r += 1
c = n + 1 - l - r - 2

for k in range(1, n + 2):
    ans = comb(n - 1, k)
    ans += 2*comb(n-1, k-1)
    if k >= 2:
        ans += comb(n - 1, k - 2)
    ans %= MOD

    ans -= comb(l + r, k - 1)
    ans += MOD
    ans %= MOD
    print(ans)


### FIXED CODE ###

import math

MOD = 10**9+7


def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0


def modinv(a):
    g, x, y = xgcd(a, MOD)
    return x


fact = [1] * 100100
for i in range(1, 100100):
    fact[i] = fact[i-1] * i % MOD


def comb(n, r):
    if n < r or r < 0:
        return 0
    else:
        return fact[n] * modinv(fact[n - r]) * modinv(fact[r]) % MOD


n = int(input())
a = list(map(int, input().split()))
x = sum(a) - n*(n+1)//2

l = 0
while a[l] != x:
    l += 1
r = 0
while a[n - r] != x:
    r += 1
c = n + 1 - l - r - 2

for k in range(1, n + 2):
    ans = comb(n+1, k) - comb(l + r, k - 1)
    if ans < 0:
        ans += MOD
    print(ans)
### BUGGY CODE ###

from math import ceil
def dot(a,b,m):
    c = [[0,0,0],[0,0,0],[0,0,0]]
    for i in range(3):
        for j in range(3):
            for k in range(3):
                c[i][j] += a[i][k]*b[k][j]
                c[i][j] %= m
    return c
def powm(a,n,m):
    if n == 0:
        return [[1,0,0],[0,1,0],[0,0,1]]
    for i in range(3):
        for j in range(3):
            a[i][j] %= m
    if n%2==0:
        return dot(powm(a,n//2,m),powm(a,n//2,m),m)
    else:
        return dot(dot(powm(a,n//2,m),powm(a,n//2,m),m),a,m)

L,A,B,M = map(int,input().split())

a = [[1,0,0],[0,1,0],[0,0,1]]
for d in range(1,19):
    C = min(max(0,ceil((10**d-A)/B)),L)-min(max(0,ceil((10**(d-1)-A)/B)),L)
    a = dot(powm([[pow(10,d,M),1,0],[0,1,B%M],[0,0,1]],C,M),a,M)
ans = (a[0][1]*A+a[0][2])%M
print(ans)

### FIXED CODE ###

def dot(a,b,m):
    c = [[0,0,0],[0,0,0],[0,0,0]]
    for i in range(3):
        for j in range(3):
            for k in range(3):
                c[i][j] += a[i][k]*b[k][j]
                c[i][j] %= m
    return c
    
def powm(a,n,m):
    if n == 0:
        return [[1,0,0],[0,1,0],[0,0,1]]
    for i in range(3):
        for j in range(3):
            a[i][j] %= m
    r = powm(a,n//2,m)
    if n%2==0:
        return dot(r,r,m)
    else:
        return dot(dot(r,r,m),a,m)

L,A,B,M = map(int,input().split())

a = [[1,0,0],[0,1,0],[0,0,1]]
for d in range(1,19):
    C = min(max(0,(10**d-A-1)//B+1),L)-min(max(0,(10**(d-1)-A-1)//B+1),L)
    a = dot(powm([[pow(10,d,M),1,0],[0,1,B%M],[0,0,1]],C,M),a,M)
ans = (a[0][1]*A%M+a[0][2])%M
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

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

# 母体の削減を試みてみる
abM2 = []
for i in range(M):
    if abM[i][0] == 1 or abM[i][1] == N:
        abM2.append(abM[i])

transit = []
for i in range(len(abM2)):
    if abM2[i][0] == 1:
        transit.append(abM2[i][1])

for i in range(len(abM2)):
    if abM2[i][1] == N:
        if abM2[i][0] in transit:
            print("POSSIBLE")
            exit()
        
print("IMPOSSIBLE")

### FIXED CODE ###

# -*- coding: utf-8 -*-

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

transit = []
transit2 = []
for i in range(M):
    if abM[i][0] == 1:
        transit.append(abM[i][1])
    if abM[i][1] == N:
        transit2.append(abM[i][0])

# setで共通要素の集合を取ってみる
if len(set(transit) & set(transit2)) != 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

import itertools

N = int(input())

def g(x, y, z):
    g_xyz = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
    return g_xyz

list_ans = []

# list_1 = []
list_g_xyz = []
list_f_n = []
N2 = int(N ** (1 /2) / 2) + 1
for x in range(1, N2 + 1):
    for y in range(x, N2 + 1):
        for z in range(y, N2 + 1):
        #   list_1.append([x, y, z])
          list_g_xyz.append(g(x, y, z))
          list_f_n.append(len(set(["".join(map(str, v)) for v in itertools.permutations([x, y, z])])))

# print(list_g_xyz)
# print(list_f_n)

list_ans = []
for target in range(1, N + 1):
    list_index = [i for i, x in enumerate(list_g_xyz) if x == target]
    ans = sum([list_f_n[i] for i in list_index])
    list_ans.append(ans)
    
for i in list_ans:
    print(i)

### FIXED CODE ###

def g(x, y, z):
    g_xyz = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
    return g_xyz


N = int(input())
ans_list = [0 for _ in range(60000)]
for x in range(1, 100):
  for y in range(1, 100):
      for z in range(1, 100):
          ans_list[g(x=x, y=y, z=z) - 1] += 1
           
for i in range(N):
    print(ans_list[i])
### BUGGY CODE ###

# ABC066C - pushpush (ARC077)
n = int(input())
lst = list(map(int, input().rstrip().split()))
b = []
parity = n % 2
for i in lst:
    if i % 2 == parity:
        b = [i] + b
    else:
        b += [i]
print(*b)

### FIXED CODE ###

# ABC066C - pushpush (ARC077)
from collections import deque

n = int(input())
lst = list(map(int, input().rstrip().split()))
b = deque()
parity = n % 2
for i, j in enumerate(lst, start=1):
    if i % 2 == parity:
        b.appendleft(j)
    else:
        b.append(j)
print(*b)
### BUGGY CODE ###

n = int(input())
p = list(map(int,input().split()))
count = 0
flag = True
for i in range(n):
    key = p[i]
    for j in range(i):
        if key > p[j]:
            flag = False
            break
    if flag == True:
        count += 1
    else:
        flag = True
print(count)


### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
count = 0
flag = True
max_l = p[0]
min_l = p[0]
for i in range(n):
    key = p[i]
    if min_l > key:
        count += 1
        min_l = key
print(count+1)
### BUGGY CODE ###

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

count = 0

for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x + y + z == s:
                count += 1

print(count)

### FIXED CODE ###

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

cnt = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - (x + y)
        if 0 <= z <= k:
            cnt += 1
print(cnt)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

import bisect
n = int(input())

a = [int(input()) for i in range(n)]

color = [a[0]]

for i in range(1,n):
    idx = bisect.bisect_left(color,a[i])
    if idx == 0:
        color.insert(0,a[i])
    else:
        color[idx-1] = a[i]
        
print(len(color))

### FIXED CODE ###

import sys
input = sys.stdin.readline

from collections import deque

import bisect
n = int(input())

a = [int(input()) for i in range(n)]

#color = [a[0]]

d = deque()
d.appendleft(a[0])

for i in range(1,n):
    idx = bisect.bisect_left(d,a[i])
    if idx == 0:
        d.appendleft(a[i])
    else:
        d[idx-1] = a[i]
        
print(len(d))
### BUGGY CODE ###

def main():
    N = int(input())
    S = input()

    cnt = float('inf')
    for i in range(N):
        tmp = S[:i].count("W") + S[i+1:].count("E")
        if cnt > tmp:
            cnt = tmp

    print(cnt)

main()

### FIXED CODE ###

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

ans = float('inf')
sum_E = [0]
sum_W = [0]
cnt_e = 0
cnt_w = 0

for i in range(N):
	if S[i] == 'E':
		cnt_e += 1
	else:
		cnt_w += 1
	sum_E.append(cnt_e)
	sum_W.append(cnt_w)

for i in range(N):
	ans = min(ans, sum_W[i] + sum_E[-1] - sum_E[i+1])

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

N,K,Q = [int(i) for i in input().split()]
mem_point = [K for i in range(N)]
_points = [-1 for i in range(N)]


for rounds in range(Q):
  temp = _points.copy()
  anser = int(input())
  temp[anser-1] = 0
  mem_point = list(map(lambda x,y:x+y,mem_point,temp))
  
for point in mem_point:
  if 0 < point:
    print("Yes")
  else:
    print("No")


### FIXED CODE ###

N,K,Q = [int(i) for i in input().split()]
mem_point = [K-Q for i in range(N)]


for rounds in range(Q):
  temp = int(input())
  mem_point[temp-1] += 1 
  
for point in mem_point:
  if 0 < point:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]
dp = [0] * (n + 1)
dp[0] = 1
mod = 10**9+7
for i in range(1,n+1):
    if i in a:
        dp[i] = 0
    elif i == 1:
        dp[i] = 1
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])

### FIXED CODE ###

n,m = map(int,input().split())
a = set([int(input()) for _ in range(m)])
dp = [0] * (n + 1)
dp[0] = 1
mod = 10**9+7
for i in range(1,n+1):
    if i in a:
        dp[i] = 0
    elif i == 1:
        dp[i] = 1
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])
### BUGGY CODE ###

import numpy as np
N = int(input())
A_str = input()
A_str_list = A_str.split()
A = [int(A_str_list[i]) for i in range(N)]
sum = 0
for i in range(N):
    for j in range(N-i-1):
        # print(i+j+1, A[i+j+1])
        mod = np.mod(A[i]*A[i+j+1], np.power(10, 9)+7)
        sum += mod
print(np.mod(sum, np.power(10, 9)+7))

### FIXED CODE ###

import numpy as np
N = int(input())
A_str = input()
A_str_list = A_str.split()
A = np.array([int(A_str_list[i]) for i in range(N)])
sum = 0
mod = 1000000007
res = np.cumsum(A)
res = [np.mod((res[-1]-res[i]), mod) for i in range(N)]
# print(res)
for i in range(N):
    sum += np.mod(res[i]*A[i], mod)
print(np.mod(sum, mod))
### BUGGY CODE ###

import numpy
h,w=map(int,input().split())
a = []
for i in range(h):
  l = input()
  l = list(l)
  a.append(l)

L = []
R = []
for i in range(h):
  l = []
  r = []
  k = 0
  m = 0
  for j in range(w):
    if a[i][w-j-1] == ".":
      k += 1
    else:
      k = 0
    if a[i][j] == ".":
      m += 1
    else:
      m = 0
    r.insert(0,k)
    l.append(m)
  R.append(r)
  L.append(l)

D = []
U = []
for i in range(h):
  D.append([])
  U.append([])
for i in range(w):
  k = 0
  m = 0
  for j in range(h):
    if a[j][i] == ".":
      k += 1
    else:
      k = 0
    if a[h-j-1][i] == ".":
      m += 1
    else:
      m = 0
    U[j].append(k)
    D[h-j-1].append(m)
A = numpy.array(L)+numpy.array(R)+numpy.array(U)+numpy.array(D)
print(max(numpy.amax(A-3),0))

### FIXED CODE ###

import numpy as np
h,w = map(int,input().split())
s = np.array([[1 if i == "." else 0 for i in input()] for j in range(h)])
l,r,u,d = np.zeros((h,w)),np.zeros((h,w)),np.zeros((h,w)),np.zeros((h,w))
for i in range(h):
  u[i] = (u[i-1]+1)*s[i]
  d[-i-1] = (d[-i]+1)*s[-i-1]
for i in range(w):
  l[:,i] = (l[:,i-1]+1)*s[:,i]
  r[:,-i-1] = (r[:,-i]+1)*s[:,-i-1]
print(int(np.max(l+r+u+d))-3)
### BUGGY CODE ###

from collections import deque


def bfs(S):  # 幅優先探索  # キュー
    dist = [[-1] * w for _ in range(h)]  # 前処理
    que, frag = deque(), set()
    for i, Si in enumerate(S):
        for j, Sij in enumerate(Si):
            if Sij == '#':
                dist[i][j] = 0
                que.append((i, j)), frag.add((i, j))

    while len(que) > 0:
        (x, y) = que.popleft()
        near = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
        for i, j in near:  # 移動先の候補
            if (i, j) in frag:  # 処理済みか否か
                continue
            if 0 <= i < h and 0 <= j < w:
                dist[i][j] = dist[x][y] + 1
                que.append((i, j)), frag.add((i, j))
    return dist


if __name__ == '__main__':
    h, w = map(int, input().split())
    a = [input() for _ in range(h)]
    ans = bfs(a)
    print(max(max(ansi) for ansi in ans))


### FIXED CODE ###

from collections import deque


def bfs(S):  # 幅優先探索  # キュー
    dist = [[-1] * w for _ in range(h)]  # 前処理
    que = deque()
    for i, Si in enumerate(S):
        for j, Sij in enumerate(Si):
            if Sij == '#':
                dist[i][j] = 0
                que.append((i, j))

    while len(que) > 0:
        (x, y) = que.popleft()
        near = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
        for i, j in near:  # 移動先の候補
            if 0 <= i < h and 0 <= j < w and dist[i][j] < 0:
                dist[i][j] = dist[x][y] + 1
                que.append((i, j))
    return dist[x][y]


h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(bfs(a))
### BUGGY CODE ###

import itertools

T = input()
# T = 'PD?D??P'
# T = 'P?P?'

ans = ''
n = 0
h = T.count('?')
for v in itertools.combinations_with_replacement(['P', 'D'], h):
    # print(v)
    T2 = T
    i = 0
    while True:
        if '?' not in T2:
            break
        T2 = T2.replace('?', v[i], 1)
        i += 1
    d = T2.count('D')
    pd = T2.count('PD')
    if n < d+pd:
        n = d+pd
        ans = T2

print(ans)


### FIXED CODE ###

T = input()
# T = 'PD?D??P'
# T = 'P?P?'

ans = ''
n = 0

T2 = T.replace('?', 'D')
d = T2.count('D')
pd = T2.count('PD')
if n < d+pd:
    n = d+pd
    ans = T2

T2 = T.replace('?D', 'PD')
T2 = T2.replace('?', 'D')
d = T2.count('D')
pd = T2.count('PD')
if n < d+pd:
    n = d+pd
    ans = T2

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

import sys
input = sys.stdin.readline


N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
dist = [[float('inf')] * N for _ in range(N)]
for i in range(N):
    dist[i][i] = 0
edges = []
for i in range(N-1):
    for j in range(i+1, N):
        edges.append((A[i][j], i, j))
edges.sort(reverse=True)
ans = 0
while edges:
    d, u, v = edges.pop()
    if d > dist[u][v]:
        ans = -1
        break
    if d < dist[u][v]:
        ans += d
        for i in range(N-1):
            for j in range(i+1, N):
                ndist = min(dist[i][j], dist[i][u] + d + dist[v][j], dist[i][v] + d + dist[u][j])
                dist[i][j] = dist[j][i] = ndist
print(ans)


### FIXED CODE ###

from copy import deepcopy
import sys
input = sys.stdin.readline


def floyd_warshall(dist):
    v = len(dist)
    for k in range(v):
        for i in range(v):
            for j in range(v):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])


N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
dist = deepcopy(A)
floyd_warshall(dist)
edges = []
for u in range(N-1):
    for v in range(u+1, N):
        edges.append((A[u][v], u, v))
edges.sort()
ans = 0
for d, u, v in edges:
    if dist[u][v] < d:
        ans = -1
        break
    ok = False
    for w in range(N):
        if w == u or w == v:
            continue
        if dist[u][w] + dist[w][v] == dist[u][v]:
            ok = True
            break
    if not ok:
        ans += d
print(ans)
### BUGGY CODE ###

n,k = map(int,input().split())
lis = list(map(int,input().split()))
new_lis = [(l+1)/2 for l in lis]
ans = 0
for i in range(n-k+1):
    if sum(new_lis[i:i+k]) > ans:
        #print(new_lis[i:i+k])
        ans = sum(new_lis[i:i+k])
print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
li = list(map(int,input().split()))
new_li = [0]
for l in li:
    new_li.append(new_li[-1]+(l+1)/2)
# print(new_li)
# [0, 1.0, 2.5, 4.0, 6.5, 9.5]
tmp_li = []
for i,n in enumerate(new_li):
    if i < k-1:
        continue
    tmp_li.append(new_li[i] - new_li[i-k])
    #print(i,i-k)
print(max(tmp_li))
### BUGGY CODE ###

n=int(input())
s=list(input())
k=int(input())

result=[]

for _ in range(k):
    a,b,c=map(str,input().split())
    if a=="1":
        s[int(b)-1]=c
        #print(s)
    else:
        temp=set(s[int(b)-1:int(c)])
        result.append(len(temp))

for item in result:
    print(item)




### FIXED CODE ###


n=int(input())
s=input()

#初期化
ind=1
while 2**ind<=n:
    ind+=1
s+="*"*(2**ind-n)
seg=[]
seg2=[]

from collections import deque
tmp=deque([s])
while len(tmp)>0:
    t=tmp.popleft()
    cnt=0
    for ss in t:
        if ss!="*":
            cnt=cnt|2**(ord(ss)-97)
    seg.append(cnt)
    seg2.append(t)
    if len(t)>1:
        tmp.append(t[:len(t)//2])
        tmp.append(t[len(t)//2:])

#セグ木が出来た！
#print(seg)
#print(seg2)

q=int(input())

def change(i,s):
    #i文字目をsに変更する
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2
    global n,seg,ind
    ii=len(seg)-2**ind+i-1
    seg[ii]=2**(ord(s)-97)
    p=(ii-1)//2
    while 1:
        seg[p]=seg[2*p+1]|seg[2*p+2]
        if p==0:
            break
        p=(p-1)//2

    #print(seg)

from collections import deque


def count(l,r):
    global n,seg,s
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2

    d = deque([(1,len(s),0)])
    ans=0

    while len(d)>0:
        tmp=d.popleft()
        #print(tmp)
        ll,rr,i=tmp[0],tmp[1],tmp[2]
        if l<=ll and rr<=r:
            ans=ans|seg[i]
        elif (ll<=l and l<=rr) or (ll<=r and r<=rr):
            d.append((ll,ll+(rr-ll)//2,2*i+1))
            d.append((ll+(rr-ll)//2+1,rr,2*i+2))

    return str(bin(ans)).count("1")


result=[]


for _ in range(q):
    b,i,c=map(str,input().split())
    if b=="1":
        #i文字目をcに変更
        change(int(i),c)
    else:
        #l文字目からr文字目までに含まれる数
        result.append(count(int(i),int(c)))

for item in result:
    print(item)
### BUGGY CODE ###

S=input()
Q=int(input())
flag_r=0
for _ in range(Q):
    Query=list(input().split())
    if int(Query[0])==1:
        flag_r=(flag_r+1)%2
    elif int(Query[1])==1+flag_r:
        S=Query[2]+S
    elif int(Query[1])==2-flag_r:
        S=S+Query[2]

if flag_r:# reverseは最後にやる
    S=S[::-1]
print(S)

### FIXED CODE ###

from collections import deque

S=input()
Q=int(input())

t=deque(S)
flag_r=0
for _ in range(Q):
    Query=input().split()
    if int(Query[0])==1:
        flag_r=(flag_r+1)%2
    elif int(Query[1])==1+flag_r:
        t.appendleft(Query[2])
    else:
        t.append(Query[2])
result=''.join(t)
if flag_r:# reverseは最後にやる
    result=result[::-1]
print(result)