Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math
q=int(input())
a=[]
n=10**5
for i in range(q):
    start,end=map(int,input().split())
    a.append(list(range(start,end+1,2)))

def sieve_of_eratosthenes(n):
    prime=[]
    limit=math.sqrt(n)
    data=[i+1 for i in range(1,n)]
    while True:
        p=data[0]
        if limit<=p:
            return prime+data
        prime.append(p)
        data=[e for e in data if e%p!=0]

prime_data=sieve_of_eratosthenes(n)
for i in range(q):
    ans=0
    for j in range(len(a[i])):
        if a[i][j] in prime_data and (a[i][j]+1)//2 in prime_data:
            ans+=1
    print(ans)

Fixed submission:
import math
import itertools
 
def prime_boolean_table(n):
    primes=[True]*(n+1)
    primes[0]=False
    primes[1]=False
    limit=math.floor(math.sqrt(n)+1)
    for i in range(2,limit+1):
        if primes[i]:
            for j in range(i*2,n+1,i):
                primes[j]=False
    return primes

n=10**5
q=int(input())
a=[list(map(int,input().split())) for _ in range(q)]
primes=prime_boolean_table(10**5)
c=[0]*(n+1)
for i in range(n):
    if primes[i+1] and primes[(i+2)//2]:
        c[i+1]=c[i]+1
    else:
        c[i+1]=c[i]
for i in range(q):
    ans=c[a[i][1]]-c[a[i][0]-1]
    print(ans)
Buggy python submission (verdict: Runtime Error):
print(input()**2-input())

Fixed submission:
print(int(input())**2-int(input()))

Buggy python submission (verdict: Runtime Error):
n,a=map(int,input().split())
print(n**2-a)

Fixed submission:
print(int(input())**2-int(input()))
Buggy python submission (verdict: Runtime Error):
n=int(input())
P=list(map(int,input().split()))
cnt=0
for i in range(n-1):
    if P[i]==i+1:
        tmp=P[i]
        P[i]=P[i+1]
        P[i+1]=tmp
        cnt+=1
if P[n]==n+1:
    cnt+=1
print(cnt)

Fixed submission:
n=int(input())
P=list(map(int,input().split()))
cnt=0
for i in range(n-1):
    if P[i]==i+1:
        tmp=P[i]
        P[i]=P[i+1]
        P[i+1]=tmp
        cnt+=1
if P[n-1]==n:
    cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n=int(input())
t=list(map(int,[input() for i in range(n)]))

def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)

if n==1:
    print(t[0])
else:
    ans=lcm(t[0],t[1])
    for i in range(n-1):
        ans=lcm(ans,lcm(t[i],t[i+1]))
    print(ans)

Fixed submission:
n=input()
m=n[::-1]
if n==m:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
t=list(map(int,[input() for i in range(n)]))

def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)

ans=lcm(t[0],t[1])
for i in range(n-1):
    ans=lcm(ans,lcm(t[i],t[i+1]))
print(ans)

Fixed submission:
n=int(input())
t=list(map(int,[input() for i in range(n)]))

def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)

if n==1:
    print(t[0])
else:
    ans=lcm(t[0],t[1])
    for i in range(n-1):
        ans=lcm(ans,lcm(t[i],t[i+1]))
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
from collections import Counter
n,m=map(int,input().split())
A,B=[],[]
for _ in range(n):
    A.append(tuple(map(lambda x:int(x)-1,input().split())))
    B.append(A[-1][0])
delete=[False]*m
ans=n
for _ in range(m-1):
    c=Counter(B)
    sport,num=c.most_common()[0]
    ans=min(ans,num)
    delete[sport]=True
    for i in range(n):
        idx=0
        while delete[A[i][idx]]:
            idx+=1
        B[i]=A[i][idx]
print(ans)

Fixed submission:
import sys
input=sys.stdin.readline
from collections import Counter
n,m=map(int,input().split())
A,B=[],[]
for _ in range(n):
    A.append(tuple(map(lambda x:int(x)-1,input().split())))
    B.append(A[-1][0])
delete=[False]*m
ans=n
idx=[0]*n
for _ in range(m-1):
    c=Counter(B)
    sport,num=c.most_common()[0]
    ans=min(ans,num)
    delete[sport]=True
    for i in range(n):
        while delete[A[i][idx[i]]]:
            idx[i]+=1
        B[i]=A[i][idx[i]]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
mod=10**9+7
from collections import Counter
def comb(n,r):
    if n<r:
        return 0
    else:
        r=min(r,n-r)
        result=1
        for i in range(n-r+1,n+1):
            result*=i
        for i in range(1,r+1):
            result//=i
        return result
n=int(input())
A=list(map(int,input().split()))
C=Counter(A)
i=C.most_common()[0][0]
idx=[k for k, x in enumerate(A) if x==i]
for k in range(1,n+2):
    print((comb(n+1,k)%mod-comb(n+idx[0]-idx[1],k-1)%mod)%mod)

Fixed submission:
#077-D
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import Counter
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
factorial=[1]
for i in range(1,n+2):
    factorial.append(factorial[i-1]*i%mod)
inverse=[0]*(n+2)
inverse[n+1]=pow(factorial[n+1],mod-2,mod)
for i in range(n,-1,-1):
    inverse[i]=inverse[i+1]*(i+1)%mod
def comb(n,r):
    if n<r:
        return 0
    return factorial[n]*inverse[r]*inverse[n-r]%mod
C=Counter(A)
i=C.most_common()[0][0]
idx=[k for k, x in enumerate(A) if x==i]
for k in range(1,n+2):
    print((comb(n+1,k)-comb(n+idx[0]-idx[1],k-1))%mod)
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import deque
from math import ceil

def dist(h,w,x,y):
    return min(x-1,h-x,y-1,w-y)

h,w,k=map(int,input().split())
MAP=[]
A=['#']*(w+2)
MAP.append(A)
for i in range(h):
    s='#'+input().strip()+'#'
    for j,t in enumerate(s):
        if t=='S':
            sx,sy=i+1,j
    MAP.append(list(s))
MAP.append(A)
delta=[[1,0],[0,1],[-1,0],[0,-1]]
P=[]
Visited=[[False]*(w+2) for _ in range(h+2)]
Visited[sx][sy]=True
q=deque()
q.append((sx,sy,k))
while q:
    x,y,t=q.popleft()
    if t<0:
        break
    P.append([x,y])
    t-=1
    for dx,dy in delta:
        if MAP[y+dy][x+dx]=='.' and not Visited[x+dx][y+dy]:
            q.append((y+dy,x+dx,t))
            Visited[x+dx][y+dy]=True
ans=float('inf')
for x,y in P:
    ans=min(ans,1+ceil(dist(h,w,x,y)/k))
print(ans)

Fixed submission:
a,b,c=map(int,input().split())
if a==b==c:
    print(-int(not a%2))
else:
    cnt=0
    while not (a%2 or b%2 or c%2):
        cnt+=1
        a,b,c=(b+c)//2,(c+a)//2,(a+b)//2
    print(cnt)
Buggy python submission (verdict: Runtime Error):
import string
from collections
n=int(input())
A=list(string.ascii_lowercase)
d={}
for _ in range(n):
    s=input()
    c=collections.Counter(s)
    for i in A:
        if i in c.keys():
            if i not in d:
                d[i]=c[i]
            else:
                d[i]=min(d[i],c[i])
        else:
            d[i]=0
ans=[]
for i in d:
    ans+=i*d[i]
ans.sort()
print(*ans,sep='')

Fixed submission:
import string
import collections
n=int(input())
A=list(string.ascii_lowercase)
d={}
for _ in range(n):
    s=input()
    c=collections.Counter(s)
    for i in A:
        if i in c.keys():
            if i not in d:
                d[i]=c[i]
            else:
                d[i]=min(d[i],c[i])
        else:
            d[i]=0
ans=[]
for i in d:
    ans+=i*d[i]
ans.sort()
print(*ans,sep='')
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
print((n+m//2)//2)n,m=map(int,input().split())
m//=2
print((n+(m-n)//2) if n<m else m)

Fixed submission:
n,m=map(int,input().split())
m//=2
print((n+(m-n)//2) if n<m else m)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
A=[int(input())-1 for _ in range(n-1)]
C=[[] for _ in range(n)]
for i,a in enumerate(A):
    C[a].append(i+1)

def depth(k):
    l=len(C[k])
    if not l:
        return 0
    else:
        D=[]
        ret=-1
        for c in C[k]:
            D.append(depth(c))
        D.sort(reverse=True)
        for i,d in enumerate(D):
            ret=max(ret,d+i+1)
        return ret

print(depth(0))

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
A=[int(input())-1 for _ in range(n-1)]
C=[[] for _ in range(n)]
for i,a in enumerate(A):
    C[a].append(i+1)

def depth(k):
    l=len(C[k])
    if not l:
        return 0
    else:
        D=[]
        ret=-1
        for c in C[k]:
            D.append(depth(c))
        D.sort(reverse=True)
        for i,d in enumerate(D):
            ret=max(ret,d+i+1)
        return ret

print(depth(0))
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

count = 0

for i in range(1,10**10):
    l = len(str(i))
    if l == 1:
        count +=1
        ans = i
        if count == k:
            print(ans)
            break
        else:
            continue
    else:
        for j in range(l-1):
            if not abs(int(str(i)[j]) - int(str(i)[j+1])) <= 1:
                continue
            elif j ==l-1:
                count +=1
                ans = i
    if count == k:
        print(ans)
        break

Fixed submission:
import queue
k = int(input())

q = queue.Queue()
for i in range(1,10):
    q.put(i)

for i in range(k):
    x = q.get()
    if i == k-1:
        break
    else:
        if not x % 10 == 0:
            q.put(10*x + (x % 10) -1)
        q.put(10*x + (x % 10))
        if not x % 10 == 9:
            q.put(10*x + (x % 10) +1)

print(x)
Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)

if S == S[::-1]:
  if S[:(n-1)//2] == S [(n+1)//2:]:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Fixed submission:
S = input()
N = len(S)

if S == S[::-1]:
  if S[:(N-1)//2] == S [(N+1)//2:]:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)

if S = S[::-1]:
  if S[:(n-1)//2] == S [(n+1)//2:]:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Fixed submission:
S = input()
N = len(S)

if S == S[::-1]:
  if S[:(N-1)//2] == S [(N+1)//2:]:
    print("Yes")
  else:
    print("No")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
 
S = []
for i in range(N):
  S.append(input())

S_set = list(set(S))
S_set.sort()

ans = [["" for i in range(2)] for i in range(len(S_set))]
n = 0
for i in range(len(S_set)):
  count = S.count(S_set[i])
  ans[i][0] = S_set[i]
  ans[i][1] = count
  if n < count:
    n = count
    
for i in range(len(S_set)):
  if ans[i][1] == n:
    print(ans[i][0])


Fixed submission:
n = int(input())
s = [input() for _ in range(n)]
 
d = {}
for i in s:
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1
        
m = max(d.values())

l = []
for i in d.keys():
  if d[i] == m:
  	l.append(i)
    
l_s = sorted(l)
for i in l_s:
  print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int,input().split()))
P_min = []
ans = 0

for i in range(N):
    P_min.append(min(P[0:i+1]))

for i in range(N):
    if P_min[i] >= P[i]:
        ans += 1
        
print(ans)


Fixed submission:
N = int(input())
P = list(map(int,input().split()))
P_min = []
a = 200000
ans = 0

for i in range(N):
    if a >= P[i]:
        ans += 1
        a = P[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int,input().split()))

ans = 0

for i in range(N):
    for j in range(i+1):
        if P[i] > P[j]:
            break
        else:
            if j == i:
                ans += 1

print(ans)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
P_min = []
a = 200000
ans = 0

for i in range(N):
    if a >= P[i]:
        ans += 1
        a = P[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
N, K, Q = map(int,input().split())

if K > Q:
    ans = ["Yes" for i in range(N)]
print(ans)
exit()

T = [0 for i in range(N)]
t = Q - K

for i in range(Q):
    a = int(input())
    T[a] += 1

for i in range(N):
    if T[i] > t:
         print("Yes")
    else:
        print("No")

Fixed submission:
N, K, Q = map(int,input().split())

if K > Q:
	for i in range(N):
		print("Yes")
	exit()

T = [0 for i in range(N)]
t = Q - K

for i in range(Q):
    a = int(input())
    T[a-1] += 1

for i in range(N):
    if T[i] > t:
         print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int,input().split()))

ans = 0
for i in range(N-1):
    count = 0
    for j in range(i,N-1):
        if H[j] >= H[j+1]:
            count += 1
            if count > ans:
                ans = count
        else:
            break


print(ans)

Fixed submission:
N = int(input())
H = list(map(int,input().split()))

h = [0 for i in range(N-1)]
ans = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        h[i] = 1

count = 0
ans = 0
for i in h:
    if i == 1:
        count += 1
        if ans < count:
            ans = count
    else:
        count = 0

print(ans)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

if A % 10 == 0:
    a = 0
else:
    a = 10 - A % 10

if B % 10 == 0:
    b = 0
else:
    b = 10 - B % 10

if C % 10 == 0:
    c = 0
else:
    c = 10 - C % 10

if D % 10 == 0:
    d = 0
else:
    d = 10 - D % 10

    if E % 10 == 0:
        e = 0
    else:
        e = 10 - E % 10

sum = A + B + C + D + E + a + b + c + d + e - max(a,b,c,d,e)

print(sum)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

if A % 10 == 0:
    a = 0
else:
    a = 10 - A % 10

if B % 10 == 0:
    b = 0
else:
    b = 10 - B % 10

if C % 10 == 0:
    c = 0
else:
    c = 10 - C % 10

if D % 10 == 0:
    d = 0
else:
    d = 10 - D % 10

if E % 10 == 0:
    e = 0
else:
    e = 10 - E % 10

sum = A + B + C + D + E + a + b + c + d + e - max(a,b,c,d,e)

print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int,input().split()))

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

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

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

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

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int,input().split()))

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

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

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

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

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int,input().split()))

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

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

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

for i in X:
    if i > a:
        print(a)
    else:
        print(b)
Buggy python submission (verdict: Runtime Error):
N = int(input())

for i in range(N+1):
    if i == 0:
        L_1 = 2
    elif i == 1:
        L_2 = 1
    else:
        L_3 = L_1 + L_2
        L_1 = L_2
        L_2 = L_3
        
print(L_3)

Fixed submission:
N = int(input())

if N == 1:
  print(1)
  exit()

for i in range(N+1):
    if i == 0:
        L_0 = 2
    elif i == 1:
        L_1 = 1
    else:
        L_2 = L_0 + L_1
        L_0 = L_1
        L_1 = L_2
        
print(L_2)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int,input().split())

j = 0

for i in range(a,b+1):
    if i % x == 0:
        j += 1

print(j)

Fixed submission:
a, b, x = map(int,input().split())

if a % x == 0:
    print(b//x - a//x + 1)

else:
    print(b//x - a//x)
Buggy python submission (verdict: Runtime Error):
s = list(map(str,input()))

ans = []

for i in range(len(s)):
    if s[i] == '0':
        ans.append('0')
    elif s[i] == '1':
        ans.append('1')
    else:
        ans.pop(-1)

print(''.join(ans))

Fixed submission:
s = list(map(str,input()))

ans = []

for i in range(len(s)):
    if s[i] == '0':
        ans.append('0')
    elif s[i] == '1':
        ans.append('1')
    else:
        if ans == []:
            continue
        else:
            ans.pop(-1)

print(''.join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            x = fractions.gcd(i,j)
            y = fractions.gcd(x,l)
            ans += y
print(ans)

Fixed submission:
import fractions
 
k = int(input())
ans = 0

li = [[0]*(k+1) for i in range(k+1)]
for i in range(k+1):
    for j in range(k+1):
        li[i][j] = fractions.gcd(i,j)

for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            x = li[i][j]
            y = li[x][l]
            ans += y
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = input()
d = deque(s)
n = int(input())
for _ in range(n):
    q = input().split()
    if (len(q)==1):
        d.reverse()
    else:
        a = int(q[1])
        b = q[2]
        if (a == 1):
            d.appendleft(b)
        else:
            d.append(b)
ans = list(d)
xxx = "".join(ans)
print(xxx)

Fixed submission:
from collections import deque

s = input()
d = deque(s)
n = int(input())
flag = 0
for _ in range(n):
    q = input().split()
    if (len(q)==1):
        if(flag == 0):
            flag = 1
        else:
            flag = 0
    else:
        a = int(q[1])
        b = q[2]
        if (a == 1):
            if flag==0:
                d.appendleft(b)
            else:
                d.append(b)
        else:
            if flag==0:
                d.append(b)
            else:
                d.appendleft(b)

if flag==1:
    d.reverse()
ans = list(d)
xxx = "".join(ans)
print(xxx)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = input()
d = deque()
li = list(s)
for i in li:
    d.append(i)
n = int(input())
for _ in range(n):
    q = input().split()
    if (len(q)==1):
        d.reverse()
    else:
        a = int(q[1])
        b = q[2]
        if (a == 1):
            d.appendleft(b)
        else:
            d.append(b)
ans = list(d)
xxx = "".join(ans)
print(xxx)

Fixed submission:
from collections import deque

s = input()
d = deque(s)
n = int(input())
flag = 0
for _ in range(n):
    q = input().split()
    if (len(q)==1):
        if(flag == 0):
            flag = 1
        else:
            flag = 0
    else:
        a = int(q[1])
        b = q[2]
        if (a == 1):
            if flag==0:
                d.appendleft(b)
            else:
                d.append(b)
        else:
            if flag==0:
                d.append(b)
            else:
                d.appendleft(b)

if flag==1:
    d.reverse()
ans = list(d)
xxx = "".join(ans)
print(xxx)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = input()
d = deque()
li = list(s)
for i in li:
    d.append(i)
n = int(input())
for _ in range(n):
    q = input().split()
    if (len(q)==1):
        d.reverse()
    else:
        a = int(q[1])
        b = q[2]
        if (a == 1):
            d.appendleft(b)
        else:
            d.append(b)
ans = list(d)
xxx = ""
for i in ans:
    xxx += i
print(xxx)
    


Fixed submission:
from collections import deque

s = input()
d = deque(s)
n = int(input())
flag = 0
for _ in range(n):
    q = input().split()
    if (len(q)==1):
        if(flag == 0):
            flag = 1
        else:
            flag = 0
    else:
        a = int(q[1])
        b = q[2]
        if (a == 1):
            if flag==0:
                d.appendleft(b)
            else:
                d.append(b)
        else:
            if flag==0:
                d.append(b)
            else:
                d.appendleft(b)

if flag==1:
    d.reverse()
ans = list(d)
xxx = "".join(ans)
print(xxx)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
q = int(input())
for _ in range(q):
    i,x,y = input().split()
    if (i == "1"):
        x = int(x)
        s = s[:x-1] + y + s[x:]
    if (i == "2"):
        x = int(x)
        y = int(y)
        ans = s[x-1:y]
        st = set(ans)
        print(len(st))

Fixed submission:
def ctoi(x):
    return ord(x)-ord("a")
n = int(input())
s = list(input())
q = int(input())
bit = [[0]*(n+1) for _ in range(26)]

def update(pos,a,x):
    while pos<=n:
        bit[a][pos] += x
        pos += pos&(-pos)

def query(pos):
    ret=[0]*26
    for i in range(26):
        tmp=0
        p=pos
        while p>0:
            tmp+=bit[i][p]
            p-=p&(-p)
        ret[i]=tmp
    return ret

for i in range(n):
    update(i+1,ctoi(s[i]),1)

for _ in range(q):
    flag,a,b = input().split()
    flag=int(flag)
    a=int(a)
    if flag==1:
        if s[a-1]==b:
            continue
        else:
            update(a,ctoi(s[a-1]),-1)
            update(a,ctoi(b),1)
            s[a-1]=b
    else:
        b=int(b)
        c1 = query(b)
        c2 = query(a-1)
        ans = 0
        for i in range(26):
            if c1[i]-c2[i]>0:
                ans += 1
        print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
q = int(input())
for _ in range(q):
    i,x,y = input().split()
    if (i == "1"):
        x = int(x)
        li = list()
        for b in s:
            li.append(b)
        li[x-1] = y
        s = ""
        for b in li:
            s += b
    if (i == "2"):
        x = int(x)
        y = int(y)
        ans = s[x-1:y]
        st = set()
        for b in ans:
            st.add(b)
        print(len(st))

Fixed submission:
def ctoi(x):
    return ord(x)-ord("a")
n = int(input())
s = list(input())
q = int(input())
bit = [[0]*(n+1) for _ in range(26)]

def update(pos,a,x):
    while pos<=n:
        bit[a][pos] += x
        pos += pos&(-pos)

def query(pos):
    ret=[0]*26
    for i in range(26):
        tmp=0
        p=pos
        while p>0:
            tmp+=bit[i][p]
            p-=p&(-p)
        ret[i]=tmp
    return ret

for i in range(n):
    update(i+1,ctoi(s[i]),1)

for _ in range(q):
    flag,a,b = input().split()
    flag=int(flag)
    a=int(a)
    if flag==1:
        if s[a-1]==b:
            continue
        else:
            update(a,ctoi(s[a-1]),-1)
            update(a,ctoi(b),1)
            s[a-1]=b
    else:
        b=int(b)
        c1 = query(b)
        c2 = query(a-1)
        ans = 0
        for i in range(26):
            if c1[i]-c2[i]>0:
                ans += 1
        print(ans)