Harryxun/stf_run huggingface dataset:
A = []

for _ in range(3):
    lis=list(map(int,input().split()))
    A.append(lis)

N = int(input())
ans=[]
for _ in range(N):
    b=int(input())
    for i in range(3):
        if(b in A[i]):
            ans.append([i+1,A[i].index(b)+1])
            break
tate=False
if(ans == []):
    print("No")
else:
    counter1=[0,0,0]
    counter2=[0,0,0]
    counter3=0
    for a in ans:
        if(a[0]==1):
            counter1[0]+=1
        elif(a[0] == 2):
            counter1[1]+=1
        elif(a[0] == 3):
            counter1[2]+=1

        if(a[1] == 1):
            counter2[0]+=1
        elif(a[1] == 2):
            counter2[1]+=1
        elif(a[1] == 3):
            counter2[2]+=1
        if(a[0] == a[1] or a[0] == 1 and a[1] == 3 or a[1]==1 and a[0]==3):
            counter3+=1

    if(3 in counter1 or 3 in counter2 or counter3 >=3):
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

import sys
N,M=map(int,input().split())
SC=[]

for _ in range(M):
    s,c=map(int,input().split())
    SC.append([s,c])

ans=-1
for i in range(10**N):
    if(len(str(i)) == N):
        for j in range(M):
            s=SC[j][0] - 1
            c=SC[j][1]
            tmp=list(str(i))
            if(tmp[s] != str(c) ):
                break
        else:
            if(ans == -1):
                ans=i
            else:
                ans=min(ans,i)
print(ans)
T

### FIXED CODE ###


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

if (a == b == c):
    print(str(a) + ' ' + str(b) + ' ' + str(c))
else:
    a, b = b, a
    a, c = c, a
    print(str(a) + ' ' + str(b) + ' ' + str(c))
N, K =map(int, input().split())
A = list(map(int, input().split()))
for i in range(0, N-K):
  if A[K+i] ＞ A[i]:
    print('Yes')
  else:
    print('No')


### FIXED CODE ###

N, K =map(int, input().split())
A = list(map(int, input().split()))
for i in range(N-K):
    if A[K+i] > A[i]:
        print('Yes')
    else:
        print('No')
x,y = map(int,input())
ans = 0
while True:
  if x == y:
    print(ans)
    break
  
  if x == -y:
    x = -x
    ans += 1
    continue

  if (abs(x)<abs(y) and x<0) or (abs(y)<abs(x) and 0<=x):
    x = -x
    ans += 1
    continue
  
  ans += abs(abs(x)-abs(y))
  x += abs(abs(x)-abs(y))

### FIXED CODE ###

x,y = map(int,input().split())
ans = 0
while True:
  if x == y:
    print(ans)
    break
  
  if x == -y:
    x = -x
    ans += 1
    continue

  if (abs(x)<abs(y) and x<0) or (abs(y)<abs(x) and 0<=x):
    x = -x
    ans += 1
    continue
  
  ans += abs(abs(x)-abs(y))
  x += abs(abs(x)-abs(y))
import re
text = input()
b_length = re.sub('B', '', text)
for _ in range(b_length):
    text = re.sub('(0|1)??B', '', text, 1)
print(text)

### FIXED CODE ###

import re
text = input()
b_length = len(re.sub('[^B]', '', text))
for _ in range(b_length):
    text = re.sub('(0|1)??B', '', text, 1)
print(text)
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n,k=get_ints()
h=get_array()
li=[999999999999]*n
li[0]=0

li[1]=abs(h[1]-h[0])
for i in range(2,n):
    for j in range(i-1,(i-k)-1,-1):
        if j<0:
            break

            #3print(i,j)
        li[i]=min(li[i],li[j]+abs(h[i]-h[j]))
##print(li)
print(li[n-1])


### FIXED CODE ###


n=int(input())
h=list(map(int,input().split()))
li=[0]*n
li[1]=abs(h[1]-h[0])
for i in range(2,n):
    li[i]=min(li[i-1]+abs(h[i]-h[i-1]),li[i-2]+abs(h[i]-h[i-2]))
##print(li)
print(li[n-1])
a, b = map( int, input().split())
print(math.ceil((a + b)/2))


### FIXED CODE ###

import math
a, b = map( int, input().split())
print(math.ceil((a + b)/2))
n,k=map(int,input().split())
b=[i for i in range(k+1,n+1)]
ans=0
if k==0:
    for i in range(len(b)):
    t=b[i]
    j=t-k
    ii=n//t
    ans+=ii*j
    ans+=max(n-ii*t-k,0)
    print(ans)
    exit()
for i in range(len(b)):
    t=b[i]
    j=t-k
    ii=n//t
    ans+=ii*j
    ans+=max(n-ii*t-k+1,0)
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
b=[i for i in range(k+1,n+1)]
ans=0
if k==0:
    for i in range(len(b)):
        t=b[i]
        j=t-k
        ii=n//t
        ans+=ii*j
        ans+=max(n-ii*t-k,0)
    print(ans)
    exit()
for i in range(len(b)):
    t=b[i]
    j=t-k
    ii=n//t
    ans+=ii*j
    ans+=max(n-ii*t-k+1,0)
print(ans)
n = int(input())
a = map(int, input().split())
count = 0
while all[i%2==0 for i in a]:
  a = [i//2 for i in a]
  count += 1
print(count)

### FIXED CODE ###

n = int(input())
a = map(int, input().split())
m = float('inf')
for i in a:
  count = 0
  while i%2 == 0:
    i = i//2
    count += 1
  m = min(m, count)
  if m==0:
    break
print(m)
a,b,c = map(int, raw_input().split())
aa = [1, 2, 3]

sorted(aa)

print aa[0],aa[1],aa[2]\n

### FIXED CODE ###

a,b,c = sorted(map(int, raw_input().split()))
print a,b,c
n,m = map(int,input().split())
A = list(int(input()).split())
tmp = n-sum(A)

if tmp >= 0:
  print(tmp)
else:
  print(-1)
  

### FIXED CODE ###

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

a = N - sum(list)

if a < 0:
    print("-1")
else:
    print(a)
input_N = input()
if 100>input_N and 900<input_N;
  sys.exit()

print ('ABC') + input_N

### FIXED CODE ###

N = int(input())
print ('ABC%d' %N)
A,B = map(int,input().split)
x = A + B if A % B == 0 else B - A
print(x)

### FIXED CODE ###

A,B = map(int,input().split())
x = A + B if B % A == 0 else B - A
print(x)
import math
A,B = map(int,input().split())
gcd = math.gcd(A,B)
print(int(A*B/gcd))

### FIXED CODE ###

A,B = map(int,input().split())
def gcd(A,B):
    temp = A % B
    while temp != 0:
        A = B
        B = temp
        temp = A%B
    return B
print(int(A*B/gcd(A,B)))
l, r = map(int, input().split())
dif = r - l
ans = 0
if dif >= 2019:
    ans = 0
else:
    mod_l = l % 2019
    mod_r = r % 2019
    if mod_l < mod_r:
        if 3 >= mod_l and mod_r <= 673:
            ans = 0
        else:
            ans = mod_l * (mod_l + 1)
    else:
        ans = 0
print(dif, mod_l, mod_r)
print(ans%2019)

### FIXED CODE ###

l, r = map(int, input().split())
dif = r - l
ans = 30000
if dif >= 2019:
    ans = 0
else:
    mod_l = l % 2019
    mod_r = r % 2019
    if mod_l < mod_r:
        if 3 >= mod_l and mod_r >= 673:
            ans = 0
        else:
            for i in range(mod_l, mod_r + 1):
                for j in range(i + 1, mod_r + 1):
                    ans = min(ans, (i * j) % 2019)
    else:
        ans = 0
#print(dif, mod_l, mod_r)
print(ans%2019)
import math


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

R = math.inf

for n in range(N):
    c, t = map(int, input().split())
    if t <= T and c < R:
        R = c

if R != math.inf:
    print(R)
else:
    print('TLE')


### FIXED CODE ###

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

R = 9999

for n in range(N):
    c, t = map(int, input().split())
    if t <= T and c < R:
        R = c

if R != 9999:
    print(R)
else:
    print('TLE')
import math

a, b, h, m = map(float, input().split())
hour = 30 * h + 0.5 * m
minute = 6 * m

radian = abs(hour - minute)
if radian > 180:
    radian = 360 - abs(hour - minute)

dist = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(radian))
print(math.sqrt(dist))


### FIXED CODE ###

book_num = int(input())
first_digit = book_num % 10
if first_digit in [2, 4, 5, 7, 9]:
    print('hon')
elif first_digit in [0, 1, 6, 8]:
    print('pon')
else:
    print('bon')
import math

N = int(input())
mod = 1000000007
dic = {} #{[2,3]:[正の数,負の数]}
zero = 0
dic[0,1] = [0,0]

#辞書登録
for i in range(N):
    A,B = list(map(int,input().split()))

    if(A == 0 and B == 0):
        zero += 1
        continue
    elif(A == 0 and B != 0):
        dic[[0,1]][0] += 1
        continue
    elif(A != 0 and B == 0):
        dic[[0,1]][1] += 1
        continue

    if(A*B < 0):
        A = (-1) * abs(A)
    else:
        A = abs(A)
    B = abs(B)
    As /= gcd(A,B)
    Bs /= gcd(A,B)
    if(A*B < 0):
        if([B,abs(A)] in dic):
            dic[[B,abs(A)]][1] += 1
        else:
            dic[[B,abs(A)]] = [0,1]
    else:
        if([A,B] in dic):
            dic[[A,B]][0] += 1
        else:
            dic[[A,B]] = [1,0]

cnt_iso = 0
ans = 1

#ペアになってない数
for key in dic.key:
    if(key[0] == 0):
        cnt_iso += key[1]
    elif(key[1] == 0):
        cnt_iso += key[1]

ans *= 2**cnt_iso % mod

for key in dic.key:
    if(key[0] != 0 and key[1] != 0):
        ans *= (2**key[0] + 2**key[1]) % mod

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(300000)
from fractions import gcd
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
d = defaultdict(int)
zero = 0
for i in range(N):
    a, b = MI()
    if a == 0 and b == 0:
        zero += 1
        continue
    g = gcd(a, b)
    a, b = a // g, b // g
    minus = (-1) ** ((a < 0) + (b < 0))
    d[(minus * abs(a), abs(b))] += 1

ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        if (a, b) in [(1, 0), (0, 1)]:
            ainv, binv = b, a
        else:
            ainv, binv = b * (1 if a < 0 else -1), abs(a)
        lans = (2 ** d[(a, b)] - 1)
        lans += (2 ** d[(ainv, binv)] - 1) if d.get((ainv, binv)) is not None else 0
        lans += 1
        ans = ans * lans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
ans = (ans + zero) % MOD
print((ans + MOD - 1) % MOD)
s = input()
t = input()
     
if s == t[:len(s)]:
	if t[-1] in 'abcdefghijklmnopqrstuvwxyz':
		print('Yes')
        exit(0)       
print('No')

### FIXED CODE ###

s = input()
t = input()
     
if s == t[:len(s)]:
	if t[-1] in 'abcdefghijklmnopqrstuvwxyz':
		print('Yes')
		exit(0)       

print('No')
from functools import reduce

mod = 10**9+7

def modcumprod(*args):
    return reduce(lambda x, y: x*y%mod, args)

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

if n == k:
    print(modcumprod(*a))
elif max(a) < 0 and k % 2 == 1:
    a.sort(reverse=True)
    print(modcumprod(*a[:k]))
else:
    a.sort(key=abs, reverse=True)
    res = 1
    cnt_neg = 0
    pos1 = neg1 = 0
    for e in a[:k]:
        res *= e
        res %= mod
        if e > 0:
            pos1 = e
        else:
            cnt_neg += 1
            neg1 = e

    if cnt_neg % 2 == 0:
        print(res)
    else:
        pos2 = neg2 = 0
        for e in a[k:]:
            if e > 0 and not pos2:
                pos2 = e
            elif e < 0 and not neg2:
                neg2 = e
            if pos2 and neg2:
                break
        if abs(pos1 * pos2) < abs(neg1 * neg2):
            res *= pow(pos1, -1, mod)
            res *= neg2
            res %= mod
        else:
            res *= pow(neg1, -1, mod)
            res *= pos2
            res %= mod
        print(res)


### FIXED CODE ###

from functools import reduce

mod = 10**9+7

def modcumprod(*args):
    return reduce(lambda x, y: x*y%mod, args)

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

if n == k:
    print(modcumprod(*a))
elif max(a) < 0 and k % 2 == 1:
    a.sort(reverse=True)
    print(modcumprod(*a[:k]))
else:
    a.sort(key=abs, reverse=True)
    res = 1
    cnt_neg = 0
    pos1 = neg1 = 0
    for e in a[:k]:
        res *= e
        res %= mod
        if e > 0:
            pos1 = e
        else:
            cnt_neg += 1
            neg1 = e

    if res == 0 or cnt_neg % 2 == 0:
        print(res)
    else:
        pos2 = neg2 = 0
        for e in a[k:]:
            if e > 0 and not pos2:
                pos2 = e
            elif e < 0 and not neg2:
                neg2 = e
            if pos2 and neg2:
                break
        if abs(pos1 * pos2) < abs(neg1 * neg2) and pos1:
            res *= pow(pos1, -1, mod)
            res *= neg2
            res %= mod
        else:
            res *= pow(neg1, -1, mod)
            res *= pos2
            res %= mod
        print(res)
import math

a, b = map(int, input().split())
def lcm(s, t):
    ans = s * t // (math.gcd(s, t))
    return ans
print(lcm(a, b))

### FIXED CODE ###


a, b = map(int, input().split())
def gcd(l, m):
    x = min(l, m)
    y = max(l, m)
    if y % x == 0:
        return x
    else:
        while y % x != 0:
            z = y % x
            y = x
            x = z
        else:
            return z

def lcm(s, t):
    ans = s * t // (gcd(s, t))
    return ans

print(lcm(a, b))
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9 for _ in N]
    dp[0] = 0
    for i in range(N):
        for j in range(1, K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9 for _ in range(N)]
    dp[0] = 0
    for i in range(N):
        for j in range(1, K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()
1 2
a, b= map(int , input().split())
print (a)
print (b)
unsafe
s = input()
print(s)


### FIXED CODE ###

s, w = map(int, input() .split())
if w >= s:
    print("unsafe")
else:
    print("safe")
k, n = map(int, input().split())
house_list = list(map(int, input().split()))
for i in range(n):
  house_list.append(house_list[i] - k)
tmp_list = sorted(house_list)
ans_list = []
for j in range(n + 1):
  ans_list.append(tmp_list[j + n - 1] - tmp_list[j])
print(min(ans_list)

### FIXED CODE ###

k, n = map(int, input().split())
house_list = list(map(int, input().split()))
for i in range(n):
  house_list.append(house_list[i] - k)
tmp_list = sorted(house_list)
ans_list = []
for j in range(n + 1):
  ans_list.append(tmp_list[j + n - 1] - tmp_list[j])
print(min(ans_list))
N,K = map(int, input().split())
MOD = 10**9+7
A = N - K + 1

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

print(N-K+1)
for i in range(1,K):
    print(cmb(K-1, i) * cmb(A, i+1) % MOD)


### FIXED CODE ###

#import sys
#sys.setrecursionlimit(100000)

N,K = map(int, input().split())
MOD = 10**9+7
A = N - K + 1

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for i in range(K):
    if N - K - i >= 0:
        print(cmb(K-1, i) * cmb(A, i+1) % MOD)
    else:
        print(0)
n, m, d = map(int,input().split())
pnt = 0.
if d==0:
    pnt = max(n*(m-2),1)/n**2
else:
    a = max(n-2*d,0)
    pnt = ((a*2 +(n-a))**(m-1))*max(n*(m-2),1)
    for i in range(m):
        pnt /= n
print(pnt)

### FIXED CODE ###

n, m, d = map(int,input().split())
pnt = 0.
if d==0:
    pnt = (1./n)*(m-1)
else:
    a = max(n-2*d,0)
    pnt = ((a*2 +(n-a))/n**2)*(m-1)
print(pnt)
r1, c1, r2, c2 = map(int, input().split())

n = 200004
mod = 1000000007

def pow(x, n):
    ret = 1
    while n > 0:
        if (n & 1) == 1:
            ret = (ret * x) % mod
        x = (x * x) % mod
        n //= 2
    return ret

fac = [1]
inv = [1]
for i in range(1, n + 1):
    fac.append((fac[-1] * i) % mod)
    inv.append(pow(fac[i], mod - 2))

def cmb(n, k):
    if k < 0 or k > n:
        return 0
    return ((fac[n] * inv[k]) % mod * inv[n - k]) % mod

def rect(r, c):
    return cmb(r + c, c)

ret = (rect(r2 + 1, c2 + 1) - rect(r1, c2 + 1) - rect(r2 + 1, c1) + rect(r1, c1) + mod + mod) % mod
print(ret)


### FIXED CODE ###

r1, c1, r2, c2 = map(int, input().split())

mod = 1000000007

def pow(x, n):
    ret = 1
    while n > 0:
        if (n & 1) == 1:
            ret = (ret * x) % mod
        x = (x * x) % mod
        n //= 2
    return ret

def fac(n):
    ret = 1
    for i in range(1, n + 1):
        ret = (ret * i) % mod
    return ret

def facinv(n):
    return pow(fac(n), mod - 2)

def cmb(n, k):
    if k < 0 or k > n:
        return 0
    return ((fac(n) * facinv(k)) % mod * facinv(n - k)) % mod

def rect(r, c):
    return cmb(r + c, c)

ret = (rect(r2 + 1, c2 + 1) - rect(r1, c2 + 1) - rect(r2 + 1, c1) + rect(r1, c1) + mod + mod) % mod
print(ret)
a, p = map(int(), input().split())

print(int((a * 3 + p) / 2))

### FIXED CODE ###

a, p = map(int, input().split())
print(int((3*a+p)/2))
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,m]=i2()
e=[[] for i in range(n+100)]
for i in range(m):
 [a,b]=i2()
 e[a].append(b)
 e[b].append(a)

import sys
sys.setrecursionlimit(10000)
d=[0 for i in range(n+100)]
dd=[]
def dfs1(v):
   d[v]=1
   for i in range(len(e[v])):
      if d[e[v][i]]==0:
         dd.append(e[v][i])
         dfs1(e[v][i])
         break
ddd=[]
def dfs2(v):
   d[v]=1
   for i in range(len(e[v])):
      if d[e[v][i]]==0:
         ddd.append(e[v][i])
         dfs2(e[v][i])
         break
dfs1(1)
dfs2(1)
l=ddd[::-1]+[1]+dd
print(len(l))
print(*l)


### FIXED CODE ###

def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,m]=i2()
e=[[] for i in range(n+100)]
for i in range(m):
 [a,b]=i2()
 e[a].append(b)
 e[b].append(a)

import sys
sys.setrecursionlimit(10**6)
d=[0 for i in range(n+100)]
dd=[]
def dfs1(v):
   d[v]=1
   for i in e[v]:
      if d[i]==0:
         dd.append(i)
         dfs1(i)
         break
ddd=[]
def dfs2(v):
   d[v]=1
   for i in e[v]:
      if d[i]==0:
         ddd.append(i)
         dfs2(i)
         break
dfs1(1)
dfs2(1)
l=ddd[::-1]+[1]+dd
print(len(l))
print(*l)
n,a,b=map(int,input().split())
c == n%(a+b)
if c >a:
  print((n-c)*a/(a+b)+a)
else:
  print((n-c)*a/(a+b)+c)

### FIXED CODE ###

n,a,b=map(int,input().split())
c = n%(a+b)
d = n//(a+b)
print(a*d+min(a,c))
data = int(input().split())

int A = data[0]
int B = data[1]
int C = data[2]

int ans = max(A*10 + B + C, B*10 + A + C, C*10 + A + B)
print(ans)

### FIXED CODE ###

A, B, C = map(int, input().split())


ans = max(A*10 + B + C, B*10 + A + C, C*10 + A + B)
print(ans)
x = input()
    a = int( x.split[0] )
    b = int( x.split[1] )
    print( a * b, (a + b) * 2 )


### FIXED CODE ###


line = input().split()

a = int(line[0])
b = int(line[1])

print(str(a * b) + ' ' + str((a+b) * 2))
while 1:
H , W = map(int, raw_input().split(" "))

if H == W == 0:
  break
width = ''
for i in range(W):
  width += '#'
for j in range(H):
  print width
    
    

### FIXED CODE ###

while 1:
  h, w = map(int, raw_input().split())
  if h == 0 and w == 0:
    break
  for i in range(h):
    print "#" * w
  print""
r=int(input())
print(powr,2)

### FIXED CODE ###

r=int(input())
print(pow(r,2))
n = int(input())
a = [int(i) for i in input().split()]

if n < 20:
    d = a.copy()

    for i in range(1, n // 2):
        b = [0] * n
        c = -10**24
        for j in range(i * 2, n):
            c = max(c, a[j - 2])
            b[j] = c + d[j]

        a = b.copy()
    print(a[-1])
    exit()
    
b = a[:20]

for i in range(1, n // 2):
    c = [0] * 10
    d = -10**24
    for j in range(20):
        if 2 * i + j >= n:
            continue
        d = max(d, b[j])
        c[j] = d + a[2 * i + j]
    b = c.copy()
print(max(b))

### FIXED CODE ###

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

if n // 2 == 1:
    print(max(a))
    exit()
if n < 20:
    d = a.copy()
    
    for i in range(1, n // 2):
        b = [0] * n
        c = -10 ** 24
        ans = -10 ** 24
        for j in range(i * 2, n):
            c = max(c, a[j - 2])
            b[j] = c + d[j]
            ans = max(ans, c + d[j])

        a = b.copy()
    print(ans)
    exit()

b = a[:10]
e = [True]*10

for i in range(1, n // 2):
    c = [0] * 10
    f = [False]*10
    d = -10**24
    for j in range(10):
        if 2 * i + j >= n:
            continue
        if not e[j]:
            continue
        d = max(d, b[j])
        c[j] = d + a[2 * i + j]
        f[j] = True
    e = f.copy()
    b = c.copy()
ans = -10 ** 24
for i in range(10):
    if e[i]:
        ans = max(ans, b[i])
print(ans)
import sys
while 1:
    h,w = map(int,sys.stdin.readline().split())
    print('#'*w)
    print(('#' + '.' * (w-2) + '#\n')*(h-2),end = '')
    print('#'*w)

### FIXED CODE ###

while True:
    h,w = map(int,input().split())
    if h == w == 0:break
    print('#'*w)
    print(('#' + '.'*(w-2) + '#\n')*(h-2),end = '')
    print('#'*w + '\n')
from bisect import bisect_left, insort_left
N = int(input())
S = [c for c in input()]
Q = int(input())
d = {i: [] for i in range(26)}
for i, c in enumerate(S):
    d[ord(c) - ord("a")].append(i)

# print(d)
for _ in range(Q):
    q = input().split()
    if int(q[0]) == 1:
        iq, cq = int(q[1]), q[2]
        iq -= 1
        if S[iq] == cq:
            continue
        else:
            idx = bisect_left(d[ord(S[iq]) - ord("a")], iq)
            if 0 < len(d[iq]):
                d[iq].pop(idx)
            S[iq] = cq
            insort_left(d[ord(cq) - ord("a")], iq)
    else:
        l, r = int(q[1]), int(q[2])
        l -= 1
        ans = 0
        for i in range(26):
            idx = bisect_left(d[i], l)
            if d[i] and l <= d[i][-1] and d[i][idx] < r:
                ans += 1
        print(ans)



### FIXED CODE ###

from bisect import bisect_left, insort_left
N = int(input())
S = [c for c in input()]
Q = int(input())
d = {i: [] for i in range(26)}
for i, c in enumerate(S):
    d[ord(c) - ord("a")].append(i)

# print(d)
for _ in range(Q):
    q = input().split()
    if int(q[0]) == 1:
        iq, cq = int(q[1]), q[2]
        iq -= 1
        if S[iq] == cq:
            continue
        else:
            idx = bisect_left(d[ord(S[iq]) - ord("a")], iq)
            d[ord(S[iq]) - ord("a")].pop(idx)
            S[iq] = cq
            insort_left(d[ord(cq) - ord("a")], iq)
    else:
        l, r = int(q[1]), int(q[2])
        l -= 1
        ans = 0
        for i in range(26):
            idx = bisect_left(d[i], l)
            if d[i] and l <= d[i][-1] and d[i][idx] < r:
                ans += 1
        print(ans)