Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[*input()]
q=int(input())
# BIT
B={chr(97+i):[0]*(n+1) for i in range(26)}
def bsum(c,i):
  s=0
  while i:
    s+=B[c][i]
    i-=i&-i
  return s
def badd(c,i,x):
  while i<=n:
    B[c][i]+=x
    i+=i&-i
for i,c in enumerate(s):
  badd(c,i+1,1)
for _ in range(q):
  x,y,z=input().split()
  y=int(y)-1
  if x=='1':
    badd(s[y],y+1,-1)
    s[y]=z
    badd(z,y+1,1)
  else:
    print(sum(bsum(c,int(z))-bsum(c,y)>0 for c in B))

Fixed submission:
n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))

Buggy python submission (verdict: Time Limit Exceeded):
f=input; n=int(f()); s=list(f())
d={chr(97+i):[0]*(n+1) for i in range(26)}
def bsum(k,i):
  s=0
  while i: s+=d[k][i]; i-=i&-i
  return s
def badd(k,i,x):
  while i<=n: d[k][i]+=x; i+=i&-i
for i in range(n): badd(s[i],i+1,1)
for i in range(int(f())):
  a,b,c=f().split(); b=int(b)-1
  if a>'1': print(sum(1 for k in d.keys() if bsum(k,int(c))-bsum(k,b)))
  else: badd(s[b],b+1,-1); s[b]=c; badd(c,b+1,1)

Fixed submission:
n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))

Buggy python submission (verdict: Time Limit Exceeded):
f=input
n,s,q=int(f()),list(f()),int(f())
d={chr(97+i):[] for i in range(26)}
for i in range(n):
  d[s[i]]+=[i]
from bisect import *
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    d[s[b]].pop(bisect(d[s[b]],b)-1)
    s[b]=c
    insort(d[c],b)
  else:
    t=0
    for l in d.values():
      m=bisect(l,b-1)
      if m<len(l) and l[m]<int(c): t+=1
    print(t)

Fixed submission:
n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))

Buggy python submission (verdict: Time Limit Exceeded):
f=input
n,s,q=int(f()),list(f()),int(f())
L=[[] for i in range(26)]
for i in range(n):
  L[ord(s[i])-97].append(i)
from bisect import *
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    l=L[ord(s[b])-97]
    l.pop(bisect(l,b)-1)
    s[b]=c
    insort(L[ord(c)-97],b)
  else:
    t=0
    for l in L:
      m=bisect(l,b-1)
      if m<len(l) and l[m]<int(c): t+=1
    print(t)

Fixed submission:
n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))

Buggy python submission (verdict: Time Limit Exceeded):
f=input
n,s,q=int(f()),list(f()),int(f())
L=[[] for i in range(26)]
for i in range(n):
  L[ord(s[i])-97]+=[i]
from bisect import *
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    l=L[ord(s[b])-97]
    l.pop(bisect(l,b)-1)
    s[b]=c
    insort(L[ord(c)-97],b)
  else:
    t=0
    for l in L:
      m=bisect(l,b-1)
      if m<len(l) and l[m]<int(c): t+=1
    print(t)

Fixed submission:
n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))

Buggy python submission (verdict: Time Limit Exceeded):
f=input
n,s,q=int(f()),list(f()),int(f())
L=[[]*n for i in range(26)]
for i in range(n):
  L[ord(s[i])-97]+=[i]
from bisect import *
for i in range(q):
  a,b,c=input().split(); b=int(b)-1
  if a=='1':
    l=L[ord(s[b])-97]
    l.pop(bisect(l,b)-1)
    s[b]=c
    insort(L[ord(c)-97],b)
  else:
    t=0
    for l in L:
      m=bisect(l,b-1)
      if m<len(l) and l[m]<int(c): t+=1
    print(t)

Fixed submission:
n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
s = list(input())
q = int(input())
for _ in range(q):
  a,b,c = input().split()
  if a=='1':
    s[int(b)-1]=c
  else:
    print(len(set(s[int(b)-1:int(c)])))

Fixed submission:
n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
s = list(input())
q = int(input())
for _ in range(q):
  a,b,c = input().split()
  if a=='1':
    s[int(b)-1]=c
  else:
    print(len(set(s[int(b)-1:int(c)])))

Fixed submission:
n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(input())
q = int(input())
for _ in range(q):
  a,b,c = input().split()
  b = int(b)-1
  if a=='1':
    l[b] = c
  else:
    s = set()
    for t in l[b:int(c)]:
      s |= {t}
    print(len(s))

Fixed submission:
n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
q = int(input())
for _ in range(q):
  a,b,c = input().split()
  if a=='1':
    s[int(b)-1]=c
  else:
    print(len(set(s[int(b)-1:int(c)])))

Fixed submission:
n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
q = int(input())
for _ in range(q):
  a,b,c = input().split()
  if a=='1':
    s[int(b)-1]=c
  else:
    print(len(set(s[int(b)-1:int(c)])))

Fixed submission:
n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))