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

s = input()
dp = [0 for _ in range(13)]
dp[0] = 1
c = 1000000007
m = 1
r13 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
r10 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
for i in range(len(s) - 1, -1, -1):
    ndp = [0 for i in r13]
    if s[i] == "?":
        for j in r10:
            for k in r13:
                index = (j * m + k) % 13
                ndp[index] = (ndp[index] + dp[k]) % c
    else:
        j = int(s[i])
        for k in r13:
            index = (j * m + k) % 13
            ndp[index] = (ndp[index] + dp[k]) % c
    dp = ndp[:]
    m = m * 10 % 13
print(dp[5])


### FIXED CODE ###

s = input()
dp = [0 for _ in range(13)]
dp[0] = 1
c = 1000000007
m = 1
r13 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
r10 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
for i in range(len(s) - 1, -1, -1):
    ndp = [0 for _ in r13]
    if s[i] == "?":
        for j in r10:
            jm = j * m
            for k in r13:
                index = (jm + k) % 13
                ndp[index] = (ndp[index] + dp[k]) % c
    else:
        jm = int(s[i]) * m
        for k in r13:
            index = (jm + k) % 13
            ndp[index] = (ndp[index] + dp[k]) % c
    dp = ndp[:]
    m = m * 10 % 13
print(dp[5])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
t = [1 if a[i] == a[j] or abs(a[i] - a[j]) == 1 else 0 for i in range(n) for j in range(n)]
print(max([sum(t[i:i+n]) for i in range(0, len(t), n)]))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
count = {}
for i in a:
  for j in [-1, 0, 1]:
    count.setdefault(i+j, 0)
    count[i+j] += 1
  
print(max(count.values()))
### BUGGY CODE ###

import numpy as np

N = int(input())
# P = np.array(input().split(' '), dtype = int)
P = np.array(list(map(int, input().split(' '))))

ar_bool = np.array([(min(P[:i+1]) == P[i]) for i in range(N)])
print(sum(ar_bool))

### FIXED CODE ###

N = int(input())
# P = np.array(input().split(' '), dtype = int)
P = list(map(int, input().split(' ')))

p_min = P[0]
ans = 0
for p in P:
    if p <= p_min:
        p_min = p
        ans += 1
print(ans)
### BUGGY CODE ###

def pr(data,next,head,tail):
    i = head
    while(1):
        if i == -1:
            print("")
            break
        print(data[i],end = "")
        i = next[i]
        if i != -1 :
            print(" ",end = "")

def ins_f(data,next,prev,x,head,tail):
    size = len(data)
    if head != -1 :
        data.append(x)
        size += 1
        next.append(head)
        prev.append(-1)
        prev[head] = size -1
        head = size -1
    else :
        data.append(x)
        size += 1
        next.append(-1)
        prev.append(-1)
        tail = size-1
        head = size-1
    return head,tail

def dl(data,next,prev,x,head,tail):
    i = head
    while(1):
        if data[i] == x:
            if i == head:
                head,tail = dl_f(next,prev,head,tail)
                break
            elif i == tail:
                head,tail = dl_l(next,prev,head,tail)
                break
            else :
                prev[next[i]] = prev[i]
                next[prev[i]] = next[i]
                break
        elif i == tail:
            break
        i = next[i]
    return head,tail

def dl_f(next,prev,head,tail):
    if head == -1:
        return head
    elif next[head] == -1:
        head = -1
        tail = -1
    else:
        prev[next[head]] = -1
        head = next[head]
    return head,tail

def dl_l(next,prev,head,tail):
    if tail == -1:
        pass
    elif prev[tail] == -1:
        head = -1
        tail = -1
    else:
        next[prev[tail]] = -1
        tail = prev[tail]
    return head,tail

n = int(input())
data = []
next = []
prev = []
head = -1
tail = -1
size = len(data)

for i in range(n):
    x = input()
    l = len(x)
    if x[0] == "i":
        head,tail = ins_f(data,next,prev,x[7:],head,tail)
    elif x[6] == " ":
        head,tail = dl(data,next,prev,x[7:],head,tail)
    elif l > 10:
        head,tail = dl_f(next,prev,head,tail)
    elif l > 6:
        head,tail = dl_l(next,prev,head,tail)
pr(data,next,head,tail)



### FIXED CODE ###

from collections import deque

def pr(a):
    for i in range(len(a)):
        if i == len(a)-1:
            print(a[i])
        else:
            print(a[i],end = " ")

n = int(input())
q = deque()
for i in range(n):
    x = input()
    l = len(x)
    if x[0] == "i":
        q.insert(0,x[7:])
    elif x[6] == " ":
        try:
            q.remove(x[7:])
        except:
            pass
    elif l > 10:
        q.popleft()
    elif l > 6:
        q.pop()

print(*q)
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
mod = (10**9) + 7
s = 0
for i in range(n-1):
    t = 0
    for j in range(i+1,n):
        t += A[j]%mod
    s += (A[i] * t)%mod
s = s%mod
print(s)

### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
mod = (10**9) + 7
t = 0
sum = 0
for i in range(1,n):
    sum += A[i]
for i in range(n-1):
    t += (A[i]*sum)%mod
    sum -=  A[i+1]
t = t%mod
print(t)
### BUGGY CODE ###

n = int(input())
power = 1
for i in range(1, n+1):
    power = power * i
answer = power % (10 ** 9 + 7)
print(answer)

### FIXED CODE ###

n = int(input())
power = 1
for i in range(1, n+1):
    power = power * i % (10 ** 9 + 7)
print(power)
### BUGGY CODE ###

n =int(input())

ans =[]
for i in range(10**9):
  if i > n:
    break
  
  if (i ** 0.5).is_integer() and i <= n:
    ans.append(i)
    
    
print(ans[-1])
    
    

    


### FIXED CODE ###

n = int(input())
m = 1
for i in range(1, n):
    if i ** 2 > n:
        break
    m = i ** 2
print(m)
### BUGGY CODE ###

#2問目
MAX = 10 ** 18
N = int(input())
A = list(map(int, input().split()))
result = 1
for i in range(N):
    result *= A[i]
if(result > MAX):
    print(-1)
else:
    print(result)

### FIXED CODE ###

#2問目
MAX = 10 ** 18
N = int(input())
A = list(map(int, input().split()))
result = 1

if 0 in A:
    result = 0
else:
    for i in range(N):
        result *= A[i]
        if result > MAX:
            result = -1
            break
print(result)
### BUGGY CODE ###

import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")

# k: number of transfer
_,k = LI()
a = LI()
# 街の番号を0始まりに変更
a = list(map(lambda x:x-1,a))
# print(a)

# 再帰関数
def rec(visited,next):
    if next in set(visited):
        return visited,visited.index(next)
    else:
        visited.append(next)
        return rec(visited,a[next])

visited = [0]
# 訪れた街、初めて2度訪れた街のインデックスを取得
visited,loopStart = rec(visited,a[0])

# print(visited,loopStart)

if k <= len(visited):
    townIndex = visited[k]
else:
    visitedLoop = visited[loopStart:]
    # print(visitedLoop)
    # 残り回数を循環配列の長さで割った余り
    index = (k-(loopStart))%len(visitedLoop)
    # print(index)
    townIndex = visitedLoop[index]

print(townIndex+1)

### FIXED CODE ###

import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")

# k: number of transfer
_,k = LI()
a = LI()
# 街の番号を0始まりに変更
a = list(map(lambda x:x-1,a))
# print(a)

s = set([0])

# 再帰関数
def rec(visited,next):
    if next in s:
        # print(visited)
        return visited,visited.index(next)
    else:
        s.add(next)
        visited.append(next)
        return rec(visited,a[next])

visited = [0]
# 訪れた街、初めて2度訪れた街のインデックスを取得
visited,loopStart = rec(visited,a[0])

# print(visited,loopStart)

if k < len(visited):
    townIndex = visited[k]
else:
    visitedLoop = visited[loopStart:]
    # print(visitedLoop)
    # 残り回数を循環配列の長さで割った余り
    index = (k-(loopStart))%len(visitedLoop)
    # print(index)
    townIndex = visitedLoop[index]

print(townIndex+1)
### BUGGY CODE ###

H, N = map(int, input().split())
A, B = [0] * N, [0] * N
for i in range(N):
    A[i], B[i] = map(int, (input().split()))

dp = [0] * (H + 1)
for i in range(1, H + 1):
    dp[i] = min([dp[i - A[n]] + B[n] if i >= A[n] else B[n] for n in range(N)])

print(dp[-1])

### FIXED CODE ###

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

dp = [[0] + [1e20] * (H) for _ in range(N)]

for i in range(N):
    A, B = map(int, (input().split()))
    for j in range(1, H + 1):
        dp[i][j] = min(dp[i - 1][j], dp[i][max(j - A, 0)] + B)

print(dp[-1][-1])
### BUGGY CODE ###

from itertools import product
N, K = map(int, input().split())
x = list(product(range(1, N + 1), repeat=3))
ans = 0
for q in x:
    w = [q[0] + q[1], q[0] + q[2], q[1] + q[2]]
    if all(list(map(lambda x: x % K == 0, w))):
        ans += 1
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
if K % 2 == 1:
    print(sum(1 for n in range(1, N + 1) if n % K == 0) ** 3)
else:
    print(sum(1 for n in range(1, N + 1) if n % K == 0) ** 3 + sum(1 for n in range(1, N + 1) if n % K == K // 2) ** 3)
### BUGGY CODE ###

X, K, D = map(int, input().split())
X=abs(X)
if D>=X and K%2==0:
    ans=X
elif D>=X and K%2==1:
    ans=D-X
elif D<X and K*D<X:
    ans=X-K*D
else:
    if X<K*D-X:
        ans=X
        for i in range(0,K):
            ans=ans-D
            if ans<0 and (K-i)%2==0:
                ans=ans+D
                break
            elif ans<0 and (K-i)%2==1:
                ans=-ans
                break
    else:
        ans=K*D-X
        for i in range(0,K):
            ans=ans-D
            if ans<0 and (K-i)%2==0:
                ans=ans+D
                break
            elif ans<0 and (K-i)%2==1:
                ans=-ans
                break
print(ans)

### FIXED CODE ###

X, K, D = map(int, input().split())
X=abs(X)
if D>=X and K%2==0:
    ans=X
elif D>=X and K%2==1:
    ans=D-X
elif D<X and K*D<X:
    ans=X-K*D
else:
    ans=X%D
    if (X-ans)%2!=K%2:
        ans=D-ans
print(ans)
### BUGGY CODE ###

s = input()
t = input()
n, m = len(s), len(t)
dp = [[["", 0] for i in range(m+1)] for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i] == t[j]:
      dp[i+1][j+1][0] = dp[i][j][0] + s[i]
      dp[i+1][j+1][1] = dp[i][j][1] + 1
    else:
      if dp[i+1][j][1] >= dp[i][j+1][1]:
        dp[i+1][j+1] = dp[i+1][j]
      else:
        dp[i+1][j+1] = dp[i][j+1]
print(dp[n][m][0])

### FIXED CODE ###

import sys
input = sys.stdin.readline

s = input().rstrip()
t = input().rstrip()
ls = len(s)
lt = len(t)
dp = [[0]*(lt+1) for _ in range(ls+1)]
for i in range(ls):
  for j in range(lt):
    if s[i] == t[j]:
      dp[i+1][j+1] = dp[i][j] + 1
    else:
      dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
ans = ""
while ls > 0 and lt > 0:
  if dp[ls][lt] == dp[ls-1][lt]:
    ls -= 1
  elif dp[ls][lt] == dp[ls][lt-1]:
    lt -= 1
  else:
    ans = s[ls-1] + ans
    ls -= 1
    lt -= 1
print(ans)
### BUGGY CODE ###

from collections import Counter
[N, X, Y] = [int(item) for item in input().split()]
X -= 1
Y -= 1
gyoretu=[]
for i in range(N):
    row=[]
    for j in range(N):
        if i == j:
            row.append(0)
        elif abs(i - j) == 1 or i == X and j == Y or i == Y and j == X:
            row.append(1)
        else:
            row.append(2000)
    gyoretu.append(row)
for k in range(N):
    for i in range(N):
        for j in range(N):
            gyoretu[i][j] = min([gyoretu[i][j], gyoretu[i][k] + gyoretu[k][j]])
array=[]
for i in range(N):
        array+=gyoretu[i][i:]
c=Counter(array)
for i in range(1, N):
    print(c[i])

### FIXED CODE ###

[N, X, Y] = [int(item) for item in input().split()]
X -= 1
Y -= 1
count=[0 for _ in range(N)]
for i in range(N):
    for j in range(i,N):
        count[min(abs(i-j),abs(i-X)+1+abs(Y-j),abs(i-Y)+1+abs(X-j))]+=1
#print(array)


for i in range(1,N):
        print(count[i])

#print(count)
### BUGGY CODE ###

class Sieve:
    """区間[2,n]の値を素因数分解する"""

    def __init__(self, n=1):
        primes = []
        f = [0] * (n + 1)
        f[0] = f[1] = -1
        for i in range(2, n + 1):  # 素数を探す
            if f[i]: continue
            primes.append(i)
            f[i] = i  # 素数には自身を代入
            for j in range(i * i, n + 1, i):  # 合成数に素因数を書き込む
                if not f[j]:
                    f[j] = i  # 最小の素因数を代入
        self.primes = primes
        self.f = f

    def is_prime(self, x) -> bool:  # 素数判定
        return self.f[x] == x

    def factor_list(self, x) -> list:  # 素因数分解の昇順リスト, [2,2,3,5,...]
        res = []
        while x != 1:
            res.append(self.f[x])
            x //= self.f[x]
        return res

    def factor(self, x) -> list:  # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]
        fl = self.factor_list(x)
        if not fl: return []
        res = [[fl[0], 0]]
        for p in fl:
            if res[-1][0] == p:
                res[-1][1] += 1
            else:
                res.append([p, 1])
        return res


def main():
    from collections import defaultdict

    MOD = 10 ** 9 + 7
    A_MX = 10 ** 6

    N = int(input())
    *a, = map(int, input().split())

    s = Sieve(n=A_MX)

    lcm = defaultdict(int)

    factors = []
    for x in a:
        f = defaultdict(int)
        for prime, cnt in s.factor(x):
            lcm[prime] = max(lcm[prime], cnt)
            f[prime] = cnt
        factors.append(f)

    ans = 0
    for f in factors:
        t = 1
        for prime, cnt in lcm.items():
            power = max(0, cnt - f[prime])
            t *= pow(prime, power, MOD)
            t %= MOD
        ans += t
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    from functools import reduce

    def gcd(a, b):
        return a if b == 0 else gcd(b, a % b)

    def lcm(a, b):
        return a * b // gcd(a, b)

    mod = 10 ** 9 + 7

    n = int(input())
    *a, = map(int, input().split())

    L = reduce(lcm, a)

    ret = 0
    for x in a:
        ret = (ret + pow(x, mod - 2, mod)) % mod
    ret = ret * L % mod
    print(ret)


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

k, s = map(int, input().split())
cnt = 0
for a in range(k+1):
    for b in range(k+1):
        for c in range(k+1):
            if a+b+c == s:
                cnt += 1
print(cnt)


### FIXED CODE ###

k, s = map(int, input().split())
cnt = 0
for a in range(k+1):
    for b in range(k+1):
        if 0 <= s-a-b <= k:
            cnt += 1
print(cnt)
### BUGGY CODE ###

n,a=map(int,input().split())
x=list(map(int,input().split()))
ans=0
dp=[[[0]*(sum(x)+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0]=1
for i in range(n+1):
  for j in range(i+1):
    for k in range(sum(x)+1):
      if i>=1 and k>=x[i-1] and j>=1:
        dp[i][j][k]=dp[i-1][j-1][k-x[i-1]]+dp[i-1][j][k]
      elif i>=1:
        dp[i][j][k]=dp[i-1][j][k]
for j in range(1,n+1):
  for k in range(sum(x)+1):
    if k%j==0 and k//j==a:
      ans+=dp[n][j][k]
print(ans)

### FIXED CODE ###

n,a=map(int,input().split())
x=list(map(int,input().split()))
ans=0
dp=[[[0]*(sum(x)+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0]=1
for i in range(n+1):
  for j in range(i+1):
    for k in range(sum(x)+1):
      if i>=1 and k>=x[i-1] and j>=1:
        dp[i][j][k]=dp[i-1][j-1][k-x[i-1]]+dp[i-1][j][k]
      elif i>=1:
        dp[i][j][k]=dp[i-1][j][k]
for j in range(1,n+1):
  for k in range(sum(x)+1):
    if k%j==0 and k//j==a:
      ans+=dp[n][j][k]
print(ans)
### BUGGY CODE ###

import heapq

def solve():
  h,w = (int(i) for i in input().split())
  maze = ["0"*(w+2)]
  for i in range(h):
    maze.append("0"+input()+"0")
  maze.append("0"*(w+2))
  black = []
  count = 0
  visit = [[False]*(w+2) for _ in range(h+2)]
  
  for i in range(h+2):
    for j in range(w+2):
      if maze[i][j] == "#":
        heapq.heappush(black,(0,i,j)) #move,h,w

  d = [(0,1),(1,0),(-1,0),(0,-1)]
  ans = 0
  
  while count != h*w:
    move,y,x = heapq.heappop(black)
    #print(move,y,x)
    if visit[y][x]:
      continue
    else:
      visit[y][x] = True
      count += 1
      for dy,dx in d:
        ny,nx = y+dy,x+dx
        if visit[ny][nx]:
          continue
        elif maze[ny][nx] ==".":
          heapq.heappush(black,(move+1,ny,nx))
  print(move)
          

    
solve()

### FIXED CODE ###


from collections import deque
def solve():
  h,w = (int(i) for i in input().split())
  maze = ["0"*(w+2)]
  for i in range(h):
    maze.append("0"+input()+"0")
  maze.append("0"*(w+2))
  black = deque([])
  count = 0
  visit = [[False]*(w+2) for _ in range(h+2)]
  
  for i in range(h+2):
    for j in range(w+2):
      if maze[i][j] == "#":
        black.append((0,i,j)) #move,h,w

  d = [(0,1),(1,0),(-1,0),(0,-1)]
  ans = 0
  
  while count != h*w:
    move,y,x = black.popleft()
    #print(move,y,x)
    if visit[y][x]:
      continue
    else:
      visit[y][x] = True
      count += 1
      for dy,dx in d:
        ny,nx = y+dy,x+dx
        if visit[ny][nx]:
          continue
        elif maze[ny][nx] ==".":
          black.append((move+1,ny,nx))
  print(move)
          

    
solve()
### BUGGY CODE ###

def divbin(s,res):
  if int(s,2)==0:
    v=res
    return v
  # ss=int(s)
  val=int(s,2)
  count=bin(val).count("1")
  val%=count
  # t_str=bin(str(count))
  t_str=bin(val)
  t_str=t_str.replace("0b","")
  res+=1
  return divbin(t_str,res)

from copy import deepcopy
n=int(input())
x=input()

# c=str(bin(n))
# c=c.replace("0b","")
s=x

p=int(x)
cnt=bin(p).count("1")
x=list(x)
# print(cnt)
for i in range(len(x)):
  tmp=cnt
  ts=""
  vv=int(s,2)
  if x[i]=="1":
    vv-=2**(len(x)-1-i)
  else:
    vv+=2**(len(x)-1-i)
  # ans=0
  # global ans
  ts=bin(vv)
  ts=ts.replace("0b","")
  ans=0
  ans=divbin(ts,ans)
  print(ans)



### FIXED CODE ###

n=int(input())
x=input()
val=int(x,2)

cnt=x.count("1")
p_cnt=cnt+1
m_cnt=cnt-1
p_amari,m_amari=0,0

p_amari=val%(cnt+1)
if cnt-1!=0:
  m_amari=val%(cnt-1)
else:
  m_amari=0

for i in range(n):
  ans=0
  if x[i]=="0":
    amari=p_amari+pow(2,n-i-1,p_cnt)
    amari%=p_cnt
  elif x[i]=="1":
    if cnt-1==0:
      print(0)
      continue
    amari=m_amari-pow(2,n-i-1,m_cnt)
    amari%=m_cnt
  ans+=1
  while amari!=0:
    amari%=bin(amari).count("1")
    ans+=1
  print(ans)
### BUGGY CODE ###

H,W = map(int,input().split())
S = list(input() for i in range(H))
Grid1 = [[0]*W for i in range(H)]
#print(S)
ans = 0
for i in range(H):
    cou = 0
    hoge = []
    for j in range(W):
        #print(i,j,S[i][j])
        if S[i][j] == ".":
            cou += 1
        else:
            hoge.append(cou)
            cou = 0
    hoge.append(cou)
    ws = []
    for j in hoge:
        ws = ws+[j]*j+[0]
    #print(ws,ws[:-1])
    Grid1[i] = ws[:-1]

for i in range(W):
    cou = 0
    hoge = []
    for j in range(H):
        #print(i,j,S[i][j])
        if S[j][i] == ".":
            cou += 1
        else:
            hoge.append(cou)
            cou = 0
    hoge.append(cou)
    ws = []
    for j in hoge:
        ws = ws+[j]*j+[0]
    #print(ws,ws[:-1])
    for j in range(H):
        ans =max( Grid1[j][i] +ws[j], ans)

print(ans-1)

### FIXED CODE ###

H,W = map(int,input().split())
S = list(input() for i in range(H))
Grid1 = [[0]*W for i in range(H)]
for i in range(H):
    cou = 0
    l = 0
    for j in range(W):
        if S[i][j] == ".":
            cou += 1
        else:
            for x in range(l,j):
                Grid1[i][x] = cou
            l = j+1
            cou = 0
    for x in range(l,j+1):
        Grid1[i][x] = cou    
for i in range(W):
    cou = 0
    l = 0
    for j in range(H):
        #print(i,j,S[i][j])
        if S[j][i] == ".":
            cou += 1
        else:
            for x in range(l,j):
                Grid1[x][i] += cou
            l = j+1
            cou = 0
    for x in range(l,j+1):
        Grid1[x][i] += cou

print(max(max(Grid1[i]) for i in range(H))-1)
### BUGGY CODE ###

import itertools

N, K = (int(i) for i in input().split(' '))
h=[]
for i in range(N):
    h.append(int(input()))

m = -1
for l in itertools.combinations(h,K):
    d = max(l) - min(l)
    if d < m or m == -1:
        m = d
print(m)

### FIXED CODE ###

N, K = (int(i) for i in input().split(' '))
h=[]
for i in range(N):
    h.append(int(input()))

h.sort()

m = -1
for i in range(N-K+1):
    d = h[i+K-1] - h[i]
    if d < m or m == -1:
        m = d
        
print(m)
### BUGGY CODE ###

from bisect import bisect_right
from bisect import bisect_left
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
s = list(input().rstrip())
q = int(input())

ind_list = [[] for _ in range(26)]

for i, x in enumerate(s):
    ind_list[ord(x)-97].append(i)

for _ in range(q):
    _type, val1, val2 = input().split()
    if _type == '1':
        i = int(val1)-1
        c = val2
        if s[i] == c:
            continue
        ind_list[ord(s[i])-97].remove(i)
        ind_list[ord(c)-97].append(i)
        ind_list[ord(c)-97].sort()
        s[i] = c
    elif _type == '2':
        l = int(val1)-1
        r = int(val2)-1
        ans = 0
        for i in range(26):
            if bisect_right(ind_list[i], r) - bisect_left(ind_list[i], l) > 0:
                ans += 1
        print(ans)
    else:
        print('Exception caught!')
        exit()


### FIXED CODE ###

from bisect import bisect_right
from bisect import bisect_left

n = int(input())
s = list(input())
q = int(input())

ind_list = [[] for _ in range(26)]

for i, x in enumerate(s):
    ind_list[ord(x)-97].append(i)

for _ in range(q):
    _type, val1, val2 = input().split()
    if _type == '1':
        i = int(val1)-1
        c = val2
        if s[i] == c:
            continue
        ind_list[ord(s[i])-97].remove(i)
        p = bisect_right(ind_list[ord(c)-97], i)
        ind_list[ord(c)-97].insert(p, i)
        s[i] = c
    elif _type == '2':
        l = int(val1)-1
        r = int(val2)-1
        ans = 0
        for i in range(26):
            if bisect_right(ind_list[i], r) - bisect_left(ind_list[i], l) > 0:
                ans += 1
        print(ans)
    else:
        print('Exception caught!')
        exit()