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

def main():
    N = int(input())
    X = [int(i) for i in input().split()]
    
    for i in range(N):
        remove_X = X[:i]+ X[i+1:]
        
        sorted_remove_X = sorted(remove_X)
        print(sorted_remove_X[int((N-1)/2)])
    
if __name__=="__main__":
    main()

### FIXED CODE ###

def main():
    N = int(input())
    X = [int(i) for i in input().split()]
    
    sorted_X = sorted(X)
    median_1 = sorted_X[int(N/2)-1]
    median_2 = sorted_X[int(N/2)]
    
    for i in range(N):
        remove_num = X[i]
        if(remove_num > median_1):
            print(median_1)
        else:
            print(median_2)
    
if __name__=="__main__":
    main()
### BUGGY CODE ###

N, K = map(int, input().split())
A = input().split()
A = [int(s) for s in A]
scores = []

for i in range(N-K+1):
    score = 1
    for j in range(i, K+i):
        score *= A[j]
    scores.append(score)

for i in range(len(scores)-1):
    if scores[i] < scores[i+1]:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
scores = []

for i in range(N-K):
    if A[i] < A[K+i]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
cnt = 1
run = []
for i in range(1, len(S)):
    if S[i - 1] == S[i]:
        cnt += 1
    else:
        run.append(cnt)
        cnt = 1
    if i == len(S) - 1:
        run.append(cnt)
if S[0] == '0':
    run = [0] + run
if S[N - 1] == '0':
    run = run + [0]
X = [sum(run[j: j + 2 * K + 1]) for j in range(len(run) - 2 * K) if j % 2 == 0]
ans = sum(run[0: 2 * K + 1])
for j in range(2, len(run) - 2 * K):
    if j % 2 == 1:
        continue
    else:
        ans = max(ans, ans - run[j - 1] - run[j - 2] + run[j + 2 * K] + run[j + 2 * K - 1])
if len(X) == 0:
    print(N)
else:
    print(max(X))


### FIXED CODE ###

from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
cnt = 1
run = []
if len(S) == 1:
    run.append(1)
else:
    for i in range(1, len(S)):
        if S[i - 1] == S[i]:
            cnt += 1
        else:
            run.append(cnt)
            cnt = 1
        if i == len(S) - 1:
            run.append(cnt)
if S[0] == '0':
    run = [0] + run
if S[N - 1] == '0':
    run = run + [0]
if len(run) < 2 * K + 1:
    print(sum(run))
    exit()
ans = sum(run[0: 2 * K + 1])
sb = ans
for j in range(2, len(run) - 2 * K):
    if j % 2 == 1:
        continue
    else:
        sb = sb - run[j - 1] - run[j - 2] + run[j + 2 * K] + run[j + 2 * K - 1]
        if sb > ans:
            ans = sb
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from functools import lru_cache
INF = float("inf")

MOD = 998244353  # type: int


def main():
    A, B, C, D = map(int, input().split())
    DP = [[None]*(D-B) for _ in range(C-A)]

    def f(a, b):
        if a < A or b < B:
            return 0
        if a == A and b == B:
            return 1
        elif a == A:
            return pow(A, b-B, MOD)
        elif b == B:
            return pow(B, a-A, MOD)
        ans = (f(a-1, b)*b) % MOD
        ans += (f(a, b-1)*a) % MOD
        ans -= (f(a-1, b-1)*(a-1)*(b-1)) % MOD
        ans %= MOD
        return ans

    print(f(C, D))

    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from functools import lru_cache
INF = float("inf")

MOD = 998244353  # type: int


def main():
    A, B, C, D = map(int, input().split())
    DP = [[1]*(D-B+1) for _ in range(C-A+1)]

    for i in range(C-A+1):
        for j in range(D-B+1):
            if i == j == 0:
                continue
            DP[i][j] = 0
            if 0 <= i-1:
                DP[i][j] += (DP[i-1][j]*(j+B)) % MOD
                DP[i][j] %= MOD
            if 0 <= j-1:
                DP[i][j] += (DP[i][j-1]*(i+A)) % MOD
                DP[i][j] %= MOD
            if 0 <= i-1 and 0 <= j-1:
                DP[i][j] -= (DP[i-1][j-1]*(i+A-1)*(j+B-1)) % MOD
                DP[i][j] %= MOD
            # print(i, j, DP[i][j])
    print(DP[-1][-1] % MOD)
    # print(DP)

    # @lru_cache(maxsize=None)
    # def f(a, b):
    #     if a < A or b < B:
    #         return 0
    #     if a == A and b == B:
    #         return 1
    #     elif a == A:
    #         return pow(A, b-B, MOD)
    #     elif b == B:
    #         return pow(B, a-A, MOD)
    #     ans = (f(a-1, b)*b) % MOD
    #     ans += (f(a, b-1)*a) % MOD
    #     ans -= (f(a-1, b-1)*(a-1)*(b-1)) % MOD
    #     ans %= MOD
    #     return ans

    # print(f(C, D))

    return


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

n = int(input())
d = list(int(x) for x in input().split())

ans = 0

for k in range(1, max(d) + 1):
    arc_num = 0
    abc_num = 0
    for i in range(n):
        if d[i] >= k:
            arc_num += 1
        else:
            abc_num += 1
    if arc_num == abc_num:
        ans += 1

print(ans)

### FIXED CODE ###

import bisect

n = int(input())
d = list(int(x) for x in input().split())
d.sort()

print(d[(n // 2)] - d[(n // 2) - 1])

"""
for k in range(d[n // 2], d[(n // 2) + 1]):
    if bisect.bisect_left(d, k) == n // 2:
        ans += 1
"""
### BUGGY CODE ###

import itertools
from collections import defaultdict
N,M,Q=map(int,input().split())
d=defaultdict(int)
for i in range(M):
  a,b=map(int,input().split())
  d[(a,b)]+=1
c={}
for x in range(0,N+1):
  for y in range(0,x):
    c[(x,y)]=0
  c[(x,x)]=d[(x,x)]
  for y in range(x+1,N+1):
    c[(x,y)]=c[(x,y-1)]+d[(x,y)]
for i in range(Q):
  x,y=map(int,input().split())
  print(sum(c[(j,y)]-c[(j,x-1)] for j in range(x,y+1)))

### FIXED CODE ###

N,M,Q=map(int,input().split())
c=[[0 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  c[a][b]+=1
for i in range(1,N):
  for j in range(1,N+1-i):
    c[j][i+j]+=c[j+1][i+j]+c[j][i+j-1]-c[j+1][i+j-1]
for i in range(Q):
  a,b=map(int,input().split())
  print(c[a][b])
### BUGGY CODE ###

import numpy as np
import math
from math import factorial

# K = int(input())
# N, K = map(int, input().split())
# A = list(map(int, input().split()))
# S = input() # String

mod = 1000000000 + 7

def dupcomb(n, k, p):
    return comb(n+k-1, k, p)

def comb(n,k,p):
    if n<0 or k<0 or n<k: return 0
    if n==0 or k==0: return 1
    a=factorial(n) %p
    b=factorial(k) %p
    c=factorial(n-k) %p
    return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
        return d*d %p
    if b%2==1:
        return (a*power_func(a,b-1,p ))%p


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

N, M = map(int, input().split())

primes = factorize(M)

count = 1

fk_save = dict()

for pair in primes:
    k = pair[1]
    # print('k=', k)

    if k in fk_save:
        fk = fk_save[k]
    else:
        fk = dupcomb(N, k, mod)
        fk_save[k] = fk
    # print('fk=', fk)

    count = (fk * count) % mod
    # print('count=', count)
    
print(count)
# ret = comb(10, 5, mod)
# print(ret)


### FIXED CODE ###

import numpy as np
import math
from math import factorial

# K = int(input())
# N, K = map(int, input().split())
# A = list(map(int, input().split()))
# S = input() # String

mod = 1000000000 + 7

fact_table = dict()

def dupcomb(n, k, p):
    return comb(n+k-1, k, p)

def comb(n,k,p):
    if n<0 or k<0 or n<k: return 0
    if n==0 or k==0: return 1

    if n in fact_table:
        a = fact_table[n]
    else:
        a=factorial(n) %p
        fact_table[n] = a

    if k in fact_table:
        b = fact_table[k]
    else:
        b=factorial(k) %p
        fact_table[k] = b
        
    if n-k in fact_table:
        c = fact_table[n-k]
    else:
        c=factorial(n-k) %p
        fact_table[n-k] = c
        
    return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
        return d*d %p
    if b%2==1:
        return (a*power_func(a,b-1,p ))%p


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

N, M = map(int, input().split())

primes = factorize(M)

count = 1

fk_save = dict()

for pair in primes:
    k = pair[1]
    # print('k=', k)

    if k in fk_save:
        fk = fk_save[k]
    else:
        fk = dupcomb(N, k, mod)
        fk_save[k] = fk
    # print('fk=', fk)

    count = (fk * count) % mod
    # print('count=', count)
    
print(count)
# ret = comb(10, 5, mod)
# print(ret)
### BUGGY CODE ###

def dfs(x, y, k, z):
    for l in z:
        if x[k][l] == 1 and l not in y:
            y.append(l)
            y = dfs(x, y, l, z)
    return y

n, m = map(int, input().split())
a = [None for _ in range(n)]
for i in range(n):
    a[i] = [0 for _ in range(n)]

bridge = []
for i in range(m):
    s, t = map(int, input().split())
    a[s - 1][t - 1] = 1
    a[t - 1][s - 1] = 1
    bridge.append([s - 1, t - 1])

d = [list(range(n))]
for p in range(m):
    a[bridge[p][0]][bridge[p][1]] = 0
    a[bridge[p][1]][bridge[p][0]] = 0
    b = []
    c = []
    for j in range(len(d)):
        for i in range(n):
            if i not in b:
                tmp = dfs(a, [i], i, d[j])
                b += tmp
                c.append(tmp)
    ans = 0
    if len(c) > 1:
        ans = 0
        for i in range(len(c)):
            ans += len(c[i]) * (n - len(c[i]))
        ans = ans // 2
    else:
        ans = 0
    print(ans)


### FIXED CODE ###

class UnionFind(object):
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0 for i in range(n + 1)]
        self.member = [1 for i in range(n + 1)]

    def find(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.member[y] += self.member[x]
        elif self.rank[x] > self.rank[y]:
            self.par[y] = x
            self.member[x] += self.member[y]
        else:
            self.par[y] = x
            self.rank[x] += 1
            self.member[x] += self.member[y]

    def size(self, x):
        return self.member[self.par[x]]

n, m = map(int, input().split())
E = [list(map(int, input().split())) for _ in range(m)]
ans = [0 for _ in range(m + 1)]
ans[-1] = n * (n - 1) // 2
tree = UnionFind(n)
for i, e in enumerate(E[::-1]):
    if tree.check(*e):
        ans[-(i + 2)] = ans[-(i + 1)]
    else:
        ans[-(i + 2)] = ans[-(i + 1)] -  tree.size(e[0]) * tree.size(e[1])
        tree.union(*e)
for a in ans[1:]:
    print(a)
### BUGGY CODE ###

h, w = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]

ab = [[0]*w for i in range(h)]
for ch in range(h):
    for cw in range(w):
        ab[ch][cw] = abs(a[ch][cw] - b[ch][cw])

ab0 = ab[0][0]
size = 80*(h+w)
dp = [[set([]) for ww in range(w)] for hh in range(h)]
dp[0][0] = {ab0, -ab0}
for ch in range(h):
    for cw in range(w):
        if ch < h-1:
            for ci in dp[ch][cw]:
                dp[ch+1][cw].add(ci + ab[ch+1][cw])
                dp[ch+1][cw].add(ci - ab[ch+1][cw])
        if cw < w-1:
            for ci in dp[ch][cw]:
                dp[ch][cw+1].add(ci + ab[ch][cw+1])
                dp[ch][cw+1].add(ci - ab[ch][cw+1])

ans = list({abs(i) for i in dp[h-1][w-1]})
print(min(ans))

### FIXED CODE ###

h, w = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]

ab = [[0]*w for i in range(h)]
for ch in range(h):
    for cw in range(w):
        ab[ch][cw] = abs(a[ch][cw] - b[ch][cw])

ab0 = ab[0][0]
size = 80*(h+w)
dp = [[0]*w for hh in range(h)]
dp[0][0] |= 2**(size + ab0)
dp[0][0] |= 2**(size - ab0)
for ch in range(h):
    for cw in range(w):
        if ch < h-1:
            dp[ch+1][cw] |= dp[ch][cw] << ab[ch+1][cw]
            dp[ch+1][cw] |= dp[ch][cw] >> ab[ch+1][cw]
        if cw < w-1:
            dp[ch][cw+1] |= dp[ch][cw] << ab[ch][cw+1]
            dp[ch][cw+1] |= dp[ch][cw] >> ab[ch][cw+1]

a = dp[h-1][w-1]>>size
m = a&(-a)
print(m.bit_length()-1)
### BUGGY CODE ###

import sys
from math import gcd

def triplet_gcd(a,b,c):
    if a == b == c:
        return a
    s = set((a, b, c))
    if len(s) == 2:
        return gcd(*s)
    else:
        return gcd(gcd(a, b), c)

K = int(sys.stdin.readline().rstrip())
ans = sum([triplet_gcd(a, b, c) for a in range(1, K+1) for b in range(1, K+1) for c in range(1, K+1)])

print(ans)


### FIXED CODE ###

import sys
from math import gcd

K = int(sys.stdin.readline().rstrip())
ans = 0

for a in range(1, K + 1):
    for b in range(a, K + 1):
        for c in range(b, K + 1):
            if a == b == c:
                ans += a
            elif a == b:
                ans += gcd(a, c) * 3
            elif a == c:
                ans += gcd(a, b) * 3
            elif b == c:
                ans += gcd(a, b) * 3
            else:
                ans += gcd(gcd(a, b), c) * 6

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

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

for i in range(len(A)):
  R += str(A.index(i+1)+1) + ' '

print(R)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
lst = [0]*len(A)
cnt = 1

for i in A:
  lst[i-1] = str(cnt)
  cnt += 1

print(' '.join(lst))
### BUGGY CODE ###

N,C = map(int,input().split())
table=[]
for i in range(N):
    x,v=map(int,input().split())
    table.append([x,v])
V=[0]*N
V[0]=table[0][1]
for i in range(1,N):
    V[i]=V[i-1]+table[i][1]
ans=0
for i in range(N):
    #print(V[i]-table[i][0])
    ans=max(ans,V[i]-table[i][0])
for i in range(N-1,0,-1):
    #print(V[N-1]-V[i-1]-C+table[i][0])
    ans = max(ans,V[N-1]-V[i-1]-C+table[i][0])
ans=max(ans,V[N-1]-C+table[0][0])
#print(V[N-1]-C+table[0][0])
#print(1)
for i in range(N):
    for k in range(i+1,N):
        #print(V[i]+V[N-1]-V[k-1]-C-2*table[i][0]+table[k][0])
        #print(V[i]+V[N-1]-V[k-1]-table[i][0]-2*C+2*table[k][0])
        ans = max(ans, V[i]+V[N-1]-V[k-1]-C-2*table[i][0]+table[k][0])
        ans = max(ans,V[i]+V[N-1]-V[k-1]-table[i][0]-2*C+2*table[k][0])
print(ans)

### FIXED CODE ###

import sys
N,C = map(int,input().split())
table=[]
for i in range(N):
    x,v=map(int,input().split())
    table.append([x,v])
ans=0
if N==1:
    ans=max(0,table[0][1]-table[0][0],table[0][1]+table[0][0]-C)
    print(ans)
    sys.exit()
V=[0]*N
clo=[0]*N
V[0]=table[0][1]
clo[0]=V[0]-table[0][0]
for i in range(1,N):
    V[i]=V[i-1]+table[i][1]
    clo[i]=max(clo[i-1],V[i]-table[i][0])
    ans = max(clo[i],ans)
rclo=[0]*N
rclo[N-1]=V[N-1]-V[N-2]-C+table[N-1][0]
for i in range(N-1,1,-1):
    rclo[i-1]=max(rclo[i],V[N-1]-V[i-2]-C+table[i-1][0])
    ans = max(clo[i],ans)
rclo[0]=max(rclo[1],V[N-1]-C+table[0][0])
ans = max(rclo[0],ans)

for i in range(N-1):
    t = V[i]+rclo[i+1]-2*table[i][0]
    ans=max(t,ans)
for i in range(N-1,0,-1):
    t = V[N-1]-V[i-1] + clo[i-1]-2*C+2*table[i][0]
    ans=max(t,ans)

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

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

for i in range(n):
    a = x[:]
    del a[i]
    a.sort()
    print(a[int(n/2)-1])

### FIXED CODE ###

n = int(input())
x = [int(i) for i in input().split()]
a = x[:]
a.sort()

mid = n //2
m1 = a[mid-1]
m2 = a[mid]
for i in range(n):
    if x[i] <= m1:
        ans = m2
    else:
        ans = m1
 
    print(ans)
### BUGGY CODE ###

N,M = map(int,input().split())

if M % N == 0:    print(M//N)
else:
    m = M//N
    for i in range(2,m)[::-1]:
        if M % i == 0:
            print(i)
            break
    else:
        print(1)


### FIXED CODE ###

N,M = map(int,input().split())

if M % N == 0:    print(M//N)
elif M//N > 100000:
    for i in range(N,M//2+1):
        if M % i == 0:
            print(M//i)
            break
    else:
        print(1)
else:
    m = M//N
    for i in range(2,m)[::-1]:
        if M % i == 0:
            print(i)
            break
    else:
        print(1)
### BUGGY CODE ###

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

from collections import deque
import copy

class Puzzle(list):
    def __init__(self):
        list.__init__(self)
        self.space = None
        self.path = ""
    
    def __hash__(self):
        return hash(str(self[:]))

if __name__ == '__main__':
    
    N = 3
    N2 = 9
    dx = [-1, 0, 1, 0]
    dy = [0, -1, 0, 1]
    d = ["u", "l", "d", "r"]

    p = Puzzle()
    for i in range(N):
        p += [int(x) for x in input().split()]
    for i in range(N2):
        if p[i] == 0:
            p[i] = N2
            p.space = i
    target = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    def isTarget(p):
        return p[:] == target[:]

    def bfs(s):
        Q = deque()
        V = set()
        Q.append(s)
        V.add(s)
        while Q:
            u = Q.popleft()
            if isTarget(u):
                return u.path
            sx = u.space // N
            sy = u.space % N
            for r in range(4):
                tx = sx + dx[r]
                ty = sy + dy[r]
                if not (0<= tx < N and 0 <= ty < N):
                    continue
                v = copy.copy(u)
                change = tx * N + ty
                v[u.space], v[change] = v[change], v[u.space]
                v.space = change
                if not v in V:
                    V.add(v)
                    v.path += d[r]
                    Q.append(v)

        return "unsolvable"

    ans = bfs(p)
    print(len(ans))





### FIXED CODE ###

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

from collections import deque
import copy

class Puzzle(list):
    def __init__(self):
        list.__init__(self)
        self.space = None
        self.path = ""
    
    def __hash__(self):
        return hash(str(self[:]))

if __name__ == '__main__':
    
    N = 3
    N2 = 9
    dx = [-1, 0, 1, 0]
    dy = [0, -1, 0, 1]
    d = ["u", "l", "d", "r"]

    p = Puzzle()
    for i in range(N):
        p += [int(x) for x in input().split()]
    for i in range(N2):
        if p[i] == 0:
            p[i] = N2
            p.space = i
    target = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    def isTarget(p):
        return p[:] == target[:]

    def bfs(s):
        Q = deque()
        V = set()
        Q.append(s)
        V.add(s)
        while Q:
            u = Q.popleft()
            if isTarget(u):
                return u.path
            sx = u.space // N
            sy = u.space % N
            for r in range(4):
                tx = sx + dx[r]
                ty = sy + dy[r]
                if not (0<= tx < N and 0 <= ty < N):
                    continue
                v = Puzzle()
                v[:] = u[:]
                v.path = u.path
                change = tx * N + ty
                v[u.space], v[change] = v[change], v[u.space]
                v.space = change
                if not v in V:
                    V.add(v)
                    v.path += d[r]
                    Q.append(v)

        return "unsolvable"

    ans = bfs(p)
    print(len(ans))
### BUGGY CODE ###

H, N = map(int,input().split())
A = []
B = []
dp = [None for i in range(2*10**4)]
dp[0] = 0
for i in range(N):
    tmp_A, tmp_B = map(int,input().split())
    A.append(tmp_A)
    B.append(tmp_B)
for i in range(2*10**4):
    for j in range(N):
        if i-A[j]<0:
            pass
        elif dp[i-A[j]]!=None:
            if dp[i]==None:
                dp[i]=dp[i-A[j]]+B[j]
            else:
                dp[i]=min(dp[i],dp[i-A[j]]+B[j])

ans = 10**16
for i in range(H,2*10**4):
    if dp[i]!=None:
        if dp[i]<ans:
            ans = dp[i]
print(ans)

### FIXED CODE ###

H, N = map(int,input().split())
A = []
B = []
dp = [None for i in range(2*10**4)]
dp[0] = 0
for i in range(N):
    tmp_A, tmp_B = map(int,input().split())
    A.append(tmp_A)
    B.append(tmp_B)
for i in range(2*10**4):
    for j in range(N):
        if i-A[j]<0:
            pass
        elif dp[i-A[j]]!=None:
            if dp[i]==None:
                dp[i]=dp[i-A[j]]+B[j]
            else:
                dp[i]=min(dp[i],dp[i-A[j]]+B[j])

ans = 10**16
for i in range(H,2*10**4):
    if dp[i]!=None:
        if dp[i]<ans:
            ans = dp[i]
print(ans)
### BUGGY CODE ###

def main():
	import bisect,sys
	input=sys.stdin.readline
	n=int(input())
	s=list(input().rstrip())
	q=int(input())
	word=[[]for _ in range(26)]
	for i,j in enumerate(s):
		ch=ord(j)-ord("a")
		word[ch].append(i)
	for _ in range(q):
		query=input().split()
		if query[0]=="1":
			i,x=int(query[1])-1,ord(query[2])-ord("a")
			old=ord(s[i])-ord("a")
			if s==x:
				continue
			word[old].remove(i)
			new=bisect.bisect_left(word[x],i)
			word[x].insert(new,i)
			s[i]=chr(x+ord("a"))
		else:
			l,r=int(query[1])-1,int(query[2])-1
			kind=0
			for i in range(26):
				ll=bisect.bisect_left(word[i],l)
				if ll==len(word[i]):
					continue
				if word[i][ll]<=r:
					kind+=1
			print(kind)
if __name__ == '__main__':
	main()


### FIXED CODE ###

import sys
input=sys.stdin.readline
n=int(input())
BIT=[[0]*n for i in range(26)]
w=[ord(x)-ord("a") for x in input()]
for i in range(n):
	k=i+1
	while k<=n:
		BIT[w[i]][k-1]+=1
		k=k+(k&-k)
q=int(input())
for i in range(q):
	a,b,c=input().split()
	if a=="1":
		k=int(b)
		while k<=n:
			BIT[ord(c)-ord("a")][k-1]+=1
			k=k+(k&-k)
		k=int(b)
		while k<=n:
			BIT[w[int(b)-1]][k-1]-=1
			k=k+(k&-k)	
		w[int(b)-1]=ord(c)-ord("a")
	else:
		b=int(b);c=int(c)
		ans=0
		for i in range(26):
			cnt=0
			k=c
			while k!=0:
				cnt+=BIT[i][k-1]
				k=k-(k&-k)
			k=b-1
			while k!=0:
				cnt-=BIT[i][k-1]
				k=k-(k&-k)
			if cnt>0:
				ans+=1
		print(ans)
### BUGGY CODE ###

n, W = map(int, input().split())
w, v = [], []
for i in range(n):
    w_, v_ = map(int, input().split())
    w.append(w_)
    v.append(v_)
dp = [[0] * (W + 1) for i in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, W + 1):
        if j < w[i - 1]:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1])
print(dp[n][W])

### FIXED CODE ###

n, W = map(int, input().split())
w, v = [], []
for i in range(n):
    w_, v_ = map(int, input().split())
    w.append(w_)
    v.append(v_)
dp = [[0] * (W + 1) for i in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, W + 1):
        if j < w[i - 1]:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1])
print(dp[n][W])