Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
input=sys.stdin.readline
n=int(input())
ss=input()
s=[]
for i in ss:
  s.append(ord(i)-ord('a'))
q=int(input())
bit=np.array([[0]*(n+1) for _ in range(26)])
#print(bit)
def upd(at,by,char):
  while at<=n:
    bit[char][at]+=by
    at+=at&-at
def qry(at,char):
  ret=0
  while at>0:
    #print(at,char,end=" inside \n")
    ret+=bit[char][at]
    at-=at&-at
  return ret
for i in range(n):
  upd(i+1,1,s[i])
for _ in range(q):
  t,l,r=input().split()
  t=int(t)
  if t==1:
    # print(t,l,r,end=" inside if")
    i=int(l)
    cq=ord(r)-ord('a')
    prev=s[i-1]
    if prev==cq:
      continue
    upd(i,-1,prev)
    curr=cq
    upd(i,1,curr)
    s[i-1]=cq
    #change ith character to cq  
  else:
    #    print(t,l,r,end=" inside else")
    l=int(l)
    r=int(r)
    ans=0
    for i in range(26):
      if qry(r,i)-qry(l-1,i)>0:
        ans+=1
    print(ans)


Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
#print(n,end=' n')
data=[0]*(2*n)
def upd(i,x):
  i+=n
  data[i]=x
  while i>1:
    data[i>>1]=data[i]|data[i^1]
    i>>=1
def qry(l,r):
  l+=n
  r+=n
  res=0
  while l<r:
    if l&1:
      res|=data[l]
      l+=1
    if r&1:
      r-=1
      res|=data[r]
    l>>=1
    r>>=1
  return bin(res).count('1')

for i,c in enumerate(input()[:-1],n):
  data[i]=1<<(ord(c)-ord('a'))
for i in range(n-1,0,-1):
  data[i]=data[i<<1]|data[i<<1|1]
ans=[]
for _ in range(int(input())):
  q,a,b=input().split()
  if int(q)==1:
    upd(int(a)-1,1<<(ord(b)-ord('a')))
  else:
    ans.append(qry(int(a)-1,int(b)))
print('\n'.join(map(str,ans)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n=int(input())
ss=input()
s=[]
for i in ss:
  s.append(ord(i)-ord('a'))
q=int(input())
bit=[[0]*(n+1) for _ in range(26)]
#print(bit)
def upd(at,by,char):
  while at<=n:
    bit[char][at]+=by
    at+=at&-at
def qry(at,char):
  ret=0
  while at>0:
    #print(at,char,end=" inside \n")
    ret+=bit[char][at]
    at-=at&-at
  return ret
for i in range(n):
  upd(i+1,1,s[i])
for _ in range(q):
  t,l,r=input().split()
  t=int(t)
  if t==1:
    # print(t,l,r,end=" inside if")
    i=int(l)
    cq=ord(r)-ord('a')
    prev=s[i-1]
    if prev==cq:
      continue
    upd(i,-1,prev)
    curr=cq
    upd(i,1,curr)
    s[i-1]=cq
    #change ith character to cq  
  else:
    #    print(t,l,r,end=" inside else")
    l=int(l)
    r=int(r)
    ans=0
    for i in range(26):
      if qry(r,i)-qry(l-1,i)>0:
        ans+=1
    print(ans)


Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
#print(n,end=' n')
data=[0]*(2*n)
def upd(i,x):
  i+=n
  data[i]=x
  while i>1:
    data[i>>1]=data[i]|data[i^1]
    i>>=1
def qry(l,r):
  l+=n
  r+=n
  res=0
  while l<r:
    if l&1:
      res|=data[l]
      l+=1
    if r&1:
      r-=1
      res|=data[r]
    l>>=1
    r>>=1
  return bin(res).count('1')

for i,c in enumerate(input()[:-1],n):
  data[i]=1<<(ord(c)-ord('a'))
for i in range(n-1,0,-1):
  data[i]=data[i<<1]|data[i<<1|1]
ans=[]
for _ in range(int(input())):
  q,a,b=input().split()
  if int(q)==1:
    upd(int(a)-1,1<<(ord(b)-ord('a')))
  else:
    ans.append(qry(int(a)-1,int(b)))
print('\n'.join(map(str,ans)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n=int(input())
ss=input()
s=[]
for i in ss:
  s.append(ord(i)-ord('a'))
q=int(input())
bit=[[0]*(n+1) for _ in range(26)]
#print(bit)
def upd(at,by,char):
  while at<=n:
    bit[char][at]+=by
    at+=at&-at
def qry(at,char):
  ret=0
  while at>0:
    #print(at,char,end=" inside \n")
    ret+=bit[char][at]
    at-=at&-at
  return ret
for i in range(n):
  upd(i+1,1,s[i])
for _ in range(q):
  t,l,r=input().split()
  t=int(t)
  if t==1:
    # print(t,l,r,end=" inside if")
    i=int(l)
    cq=ord(r)-ord('a')
    prev=s[i-1]
    upd(i,-1,prev)
    curr=cq
    upd(i,1,curr)
    s[i-1]=cq
    #change ith character to cq  
  else:
    #    print(t,l,r,end=" inside else")
    l=int(l)
    r=int(r)
    ans=0
    for i in range(26):
      if qry(r,i)-qry(l-1,i)>0:
        ans+=1
    print(ans)


Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
#print(n,end=' n')
data=[0]*(2*n)
def upd(i,x):
  i+=n
  data[i]=x
  while i>1:
    data[i>>1]=data[i]|data[i^1]
    i>>=1
def qry(l,r):
  l+=n
  r+=n
  res=0
  while l<r:
    if l&1:
      res|=data[l]
      l+=1
    if r&1:
      r-=1
      res|=data[r]
    l>>=1
    r>>=1
  return bin(res).count('1')

for i,c in enumerate(input()[:-1],n):
  data[i]=1<<(ord(c)-ord('a'))
for i in range(n-1,0,-1):
  data[i]=data[i<<1]|data[i<<1|1]
ans=[]
for _ in range(int(input())):
  q,a,b=input().split()
  if int(q)==1:
    upd(int(a)-1,1<<(ord(b)-ord('a')))
  else:
    ans.append(qry(int(a)-1,int(b)))
print('\n'.join(map(str,ans)))

Buggy python submission (verdict: Runtime Error):
7
abcdbbd
6
2 3 6
1 5 z
2 1 1
1 4 a
1 7 d
2 1 7


Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
#print(n,end=' n')
data=[0]*(2*n)
def upd(i,x):
  i+=n
  data[i]=x
  while i>1:
    data[i>>1]=data[i]|data[i^1]
    i>>=1
def qry(l,r):
  l+=n
  r+=n
  res=0
  while l<r:
    if l&1:
      res|=data[l]
      l+=1
    if r&1:
      r-=1
      res|=data[r]
    l>>=1
    r>>=1
  return bin(res).count('1')

for i,c in enumerate(input()[:-1],n):
  data[i]=1<<(ord(c)-ord('a'))
for i in range(n-1,0,-1):
  data[i]=data[i<<1]|data[i<<1|1]
ans=[]
for _ in range(int(input())):
  q,a,b=input().split()
  if int(q)==1:
    upd(int(a)-1,1<<(ord(b)-ord('a')))
  else:
    ans.append(qry(int(a)-1,int(b)))
print('\n'.join(map(str,ans)))