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

N = int(input())
S = input()

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                if j - i != k - j:
                    cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
S = input()

r = 0
g = 0
b = 0
for s in S:
    if s == "R":
        r += 1
    elif s == "G":
        g += 1
    else:
        b += 1

cnt = r * g * b
for i in range(N):
    for j in range(i, N):
        k = 2 * j - i
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            cnt -= 1
        
print(cnt)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        ans += sum(list(map(lambda x: A[i] * x, A[i + 1:])))
    print(ans % (10 ** 9 + 7))


main()


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    all_num = sum(A)
    for i in range(N, 1, -1):
        all_num -= A[i - 1]
        ans += A[i - 1] * all_num
    print(ans % (10 ** 9 + 7))


main()
### BUGGY CODE ###

S = input()
Q = int(input())
ans = S
turncnt = 0
for i in range(Q):
    query = input().split()
    if (query[0] == "1"):
        turncnt = turncnt + 1
    if (query[0] == "2"):
        if (query[1] == "1"):
            if (turncnt % 2 == 0):
                ans = query[2] + ans
            else:
                ans = ans + query[2]
        if (query[1] == "2"):
            if (turncnt % 2 == 0):
                ans = ans + query[2]
            else:
                ans = query[2] + ans

if (turncnt % 2 == 1):
    ans = ans[::-1]    
print(ans)

### FIXED CODE ###

from collections import deque

S = input()
Q = int(input())
ans = deque()
ans.append(S)
turncnt = 0
for i in range(Q):
    query = input().split()
    if (query[0] == "1"):
        turncnt = turncnt + 1
    if (query[0] == "2"):
        if (query[1] == "1"):
            if (turncnt % 2 == 0):
                ans.appendleft(query[2])
            else:
                ans.append(query[2])
        if (query[1] == "2"):
            if (turncnt % 2 == 0):
                ans.append(query[2])
            else:
                ans.appendleft(query[2])

anstr = "".join(ans)
if (turncnt % 2 == 1):
    anstr = anstr[::-1]
print(anstr)
### BUGGY CODE ###

N, M = list(map(int, input().split()))
X = []
Y = []
for i in range(M):
    S, E = list(map(int, input().split()))
    if S == 1:
        X.append(E)
    if E == N:
        Y.append(S)
while 1:
    if X == [] or Y == []:
        print("IMPOSSIBLE")
        break
    min_x = min(X)
    min_y = min(Y)
    if min_x == min_y:
        print("POSSIBLE")
        break
    elif min_x > min_y:
        Y.remove(min_y)
    elif min_x < min_y:
        X.remove(min_x)
else:
    print("IMPOSSIBLE")


### FIXED CODE ###

N, M = list(map(int, input().split()))
X = [0] * N
Y = [0] * N
for i in range(M):
    S, E = list(map(int, input().split()))
    if S == 1:
        X[E-1] = 1
    if E == N:
        Y[S-1] = 1
for i in range(N):
    if X[i] == 1 and Y[i] == 1:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)

(N, M), *miti = [[*map(int, line.split())] for line in open(0)]

# print(miti)

A = [list() for _ in range(N+1)]
for m in miti:
    a, b = m
    A[a].append(b)
    A[b].append(a)

# print(A)

ans = [0] * (N + 1)
dist = [N] * (N + 1)


def check(p, d):
    for t in A[p]:
        if d + 1 < dist[t]:
            dist[t] = d + 1
            ans[t] = p
            check(t, d + 1)


dist[1] = 0
ans[1] = 88888
check(1, 0)

dist = dist[1:]
ans = ans[2:]
if all(d < N for d in dist):
    print("Yes")
    for a in ans:
        print(a)
else:
    print("No")

### FIXED CODE ###

(N, M), *miti = [[*map(int, line.split())] for line in open(0)]

# print(miti)

A = [list() for _ in range(N+1)]
for m in miti:
    a, b = m
    A[a].append(b)
    A[b].append(a)

# print(A)

ans = [0] * (N + 1)
dist = [N] * (N + 1)
R = [list() for _ in range(N)]

dist[1] = 0
R[0].append(1)
ans[1] = 88888
for i in range(N):
    for p in R[i]:
        for t in A[p]:
            if i + 1 < dist[t]:
                dist[t] = i + 1
                R[i+1].append(t)
                ans[t] = p

dist = dist[1:]
ans = ans[2:]
if all(d < N for d in dist):
    print("Yes")
    for a in ans:
        print(a)
else:
    print("No")
### BUGGY CODE ###

from collections import deque

def bfs(start, goal):
    queue = deque([start])
    visited = []
    tekazu = [0 for _ in range(n)] # nは頂点数

    while queue:
        label = queue.pop()

        if label == goal:
            visited.append(label)
            return tekazu[goal]

        if label not in visited:
            visited.append(label)

            for v in d[label]:
                if v not in visited:
                    tekazu[v] = tekazu[label] + 1
                    queue.appendleft(v)

    return False

n = int(input())
d = {i: [] for i in range(n)}

for _ in range(n - 1):
    a, b = map(int, input().split())
    d[a - 1].append(b - 1)
    d[b - 1].append(a - 1)

Fennec = 0
Snuke = 0

for i in range(n):
    if bfs(0, i) <= bfs(n - 1, i):
        Fennec += 1
    else:
        Snuke += 1

if Fennec > Snuke:
    print("Fennec")
else:
    print("Snuke")

### FIXED CODE ###

from collections import deque

def bfs(start):
    queue = deque([start])
    visited = []

    while queue:
        label = queue.pop()

        #if label not in visited:
        visited.append(label)

        for v in d[label]:
            if tekazu[v] == float("inf"):
                tekazu[v] = tekazu[label] + 1
                queue.appendleft(v)

    return

n = int(input())
d = [[] for _ in range(n)]

for _ in range(n - 1):
    a, b = map(int, input().split())
    d[a - 1].append(b - 1)
    d[b - 1].append(a - 1)

tekazu = [float("inf") for _ in range(n)] # nは頂点数
tekazu[0] = 0
bfs(0)
tekazu_Fennec = tekazu

tekazu = [float("inf") for _ in range(n)] # nは頂点数
tekazu[-1] = 0
bfs(n - 1)
tekazu_Snuke = tekazu

Fennec = 0
Snuke = 0

for i in range(n):
    if tekazu_Fennec[i] <= tekazu_Snuke[i]:
        Fennec += 1
    else:
        Snuke += 1

#print(tekazu_Fennec, tekazu_Snuke)

if Fennec > Snuke:
    print("Fennec")
else:
    print("Snuke")
### BUGGY CODE ###

import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from sys import stdin
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
n, m = map(int, input().split())
a = sorted(list(map(int, stdin.readline().split())))
x = [()] * m
for i in range(m):
    b, c = map(int, stdin.readline().split())
    x[i] = (c, b)
x.sort(reverse=True)
# print("x =", x)
# print("a =", a)
y = []
for i in range(m):
    z = [x[i][0]] * x[i][1]
    y.extend(z)
# print("y =", y)
ans = sum(a)
length = min(n, len(y))
for i in range(length):
    if a[i] >= y[i]:
        break
    ans += y[i] - a[i]
print(ans)


### FIXED CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)
  
for b,c in bc:
  a.extend([c]*b)
  if len(a) > n*2:
    break
a.sort(reverse=True)
print(sum(a[:n]))
### BUGGY CODE ###

a,b = map(int,input().split())
gcd = 1
for i in range(2,min(a,b)+1):
    if a%i == 0 and b%i == 0:
        gcd = i
print(gcd)
    

### FIXED CODE ###

def lcd(a,b): ##return least common multiple of a and b
    if a > b:
        return lcd(a-b,b)
    elif a < b:
        return lcd(b-a,a)
    elif a == b:
        return a

a,b = map(int,input().split())
print(lcd(a,b))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections
import heapq

n, m = list(map(int, input().split()))
a = [0] * m
b = [0] * m
path = [[] for i in range(n+1)]

for i in range(m):
    # a[i], b[i] = list(map(int, input().split()))
    a, b = list(map(int, input().split()))
    path[a].append(b)
    path[b].append(a)

# 部屋1から出発して、
ans = [0]*(n+1)
visited = [1]
que = deque([[1, 1]])  # 今の場所、前の場所
# que_items = [1]
now = 1
prev = 1
# BFS
while (len(visited) != n) and len(que) > 0:
    now, prev = que.popleft()
    # print('pop', now)
    for can_go in path[now]:
        if(not (can_go in visited)):
            # print('push', can_go)
            que.append([can_go, now])
    if (now in visited):
        continue
    ans[now] = prev
    visited.append(now)

if 0 in ans[2:]:
    print('No')
else:
    print('Yes')
    for _ans in ans[2:]:
        print(_ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections
import heapq
# import time

n, m = list(map(int, input().split()))
a = [0] * m
b = [0] * m
path = [[] for i in range(n+1)]

for i in range(m):
    # a[i], b[i] = list(map(int, input().split()))
    a, b = list(map(int, input().split()))
    path[a].append(b)
    path[b].append(a)
# start = time.time()
# 部屋1から出発して、
ans = [0]*(n+1)
visited = []
que = deque([[1, 1]])  # 今の場所、前の場所
que_items = set([1])

# BFS
while len(que) > 0:
    now, prev = que.popleft()
    # print('pop', now)
    for can_go in path[now]:
        if(not (can_go in que_items)):  # ここが遅い
            # print('push', can_go)
            que.append([can_go, now])
            que_items.add(can_go)
    ans[now] = prev
    visited.append(now)
    # print(visited)

if (len(visited) != n):
    print('No')
else:
    print('Yes')
    for _ans in ans[2:]:
        print(_ans)

# print(time.time() - start)
### BUGGY CODE ###

n,m=map(int,input().split())
a=[]
ans=[1]
for i in range(m):
    a.append(int(input()))
    
if 1 in a:
    ans.append(0)
else:
    ans.append(1)    
for j in range(2,n+1):
    if j in a:
        ans.append(0)
    else:
        ans.append(ans[-1]+ans[-2])
        
print(ans[-1]%((10**9)+7))            

    
    

### FIXED CODE ###

n,m=map(int,input().split())
mod=10**9+7
a=[0]*(n+1)
dp=[0]*(n+1)
dp[0]=1
for i in range(m):
    a[int(input())]=1
    
if a[1]==1:
    dp[1]=0
else:
    dp[1]=1
    
for j in range(2,n+1):
    if a[j]==0:
        dp[j]=dp[j-1]+dp[j-2] 
                  
print(dp[n]%mod)
### BUGGY CODE ###

N = int(input())
A = [int(x) for x in input().split()]
ans = 0
for i in range(60):
    tr, fl = 0, 0
    for x in A:
        if x >> i & 1:
            tr += 1
        else:
            fl += 1
    ans += (tr * fl) * 2 ** i
    ans = ans % (10 ** 9 + 7)
print(ans)


### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]
B = []
for x in A:
    tmp_lst = []
    for _ in range(60):
        tmp = x // 2
        tmp_lst.append(x - tmp * 2)
        x = tmp
    B.append(tmp_lst)

ans = 0
for i in range(60):
    tr, fl = 0, 0
    for x in B:
        if x[i]:
            tr += 1
        else:
            fl += 1
    ans += (tr * fl) * 2 ** i
    ans = ans % (10 ** 9 + 7)
print(ans)
### BUGGY CODE ###

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

for _ in range(m):
    b, c = map(int, input().split())
    a += ([c] * b)

print(sum(sorted(a,reverse=True)[:n]))

### FIXED CODE ###

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

bc = []

for _ in range(m):
    b, c = map(int, input().split())
    bc.append((b, c))

bc = sorted(bc, key=lambda x: x[1], reverse=True)

cnt = 0

for b, c in bc:
    cnt += b
    a += [c] * b
    if cnt >= n:
        break

print(sum(sorted(a,reverse=True)[:n]))
### BUGGY CODE ###

N,X,Y=map(int,input().split())

Ans=[]

i=1
while i<=N:
    j=i+1
    while j<=N:
        Ans.append(min(j-i,abs(X-i)+1+abs(j-Y)))
        j=j+1
    i=i+1

k=1
count=0
while k<=N-1:
    A=Ans.count(k)
    print(A)
    k=k+1
    if A==0:
        while k<=N-1:
            print(0)
            k=k+1
        break

### FIXED CODE ###

N,X,Y=map(int,input().split())

Ans=[0]*N

i=1
d=0
while i<=N:
    j=i+1
    while j<=N:
        d=(min(j-i,abs(X-i)+1+abs(j-Y)))
        Ans[d]+=1
        j+=1
    i+=1

k=1
while k<=N-1:
    print(Ans[k])
    k+=1
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
 
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
 
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
 
def SMI(): return input().split()
def SLI(): return list(input())
 
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
 
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
 
def solve():
    S = SLI()
    l = len(S)
    MOD = 1000000007
    dp = [[0]*13 for _ in range(l+1)]
    dp[0][0] = 1
    mul = 1
    for i in range(l):
        s = S[-(i + 1)]
        if s == '?':
            for q in range(10):
                for j in range(13):
                    dp[i+1][(q*mul + j)%13] += dp[i][j]
                    dp[i+1][(q*mul + j)%13] %= MOD
        else:
            for j in range(13):
                k = int(s)
                dp[i+1][(k*mul + j)%13] += dp[i][j]
                dp[i+1][(k*mul + j)%13] %= MOD
 
        mul = mul * 10 % 13
    # print(dp[-1])
    print(dp[-1][5] % MOD)
 
if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SMI(): return input().split()
def SLI(): return list(input())

def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    S = SLI()
    l = len(S)
    MOD = 1000000007
    dp = [[0]*13 for _ in range(l+1)]
    dp[0][0] = 1
    mul = 1
    for i in range(l):
        s = S[-(i + 1)]
        if s == '?':
            for q in range(10):
                for j in range(13):
                    dp[i+1][(q*mul + j)%13] += dp[i][j]
                    dp[i+1][(q*mul + j)%13] %= MOD
        else:
            for j in range(13):
                k = int(s)
                dp[i+1][(k*mul + j)%13] += dp[i][j]
                dp[i+1][(k*mul + j)%13] %= MOD

        mul = mul * 10 % 13
    # print(dp[-1])
    print(dp[-1][5] % MOD)

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

n, m = map(int, input().split())
ans = 1
for i in range(1, m // n+1):
    if m % (m // n - i + 1) == 0:
        ans = m // n - i + 1
        break
print(ans)


### FIXED CODE ###

import math
n, m = map(int, input().split())
ans = 1
k = m
soy = []
for i in range(2, int(math.sqrt(m))+1):
    if k % i == 0:
        are = 0
        while True:
            if k % i == 0:
                k = k // i
                are += 1
            else:
                break
        soy.append([i, are])
if k != 1:
    soy.append([k, 1])
for i in range(10-len(soy)):
    soy.append([1, 0])
for a in range(soy[0][1] + 1):
    for b in range(soy[1][1] + 1):
        for c in range(soy[2][1] + 1):
            for d in range(soy[3][1] + 1):
                for e in range(soy[4][1] + 1):
                    for f in range(soy[5][1] + 1):
                        for g in range(soy[6][1] + 1):
                            for h in range(soy[7][1] + 1):
                                for i in range(soy[8][1] + 1):
                                    for j in range(soy[9][1] + 1):
                                        t = soy[0][0]**a * soy[1][0]**b * soy[2][0]**c * soy[3][0]**d * soy[4][0]**e * soy[5][0]**f * soy[6][0]**g * soy[7][0]**h * soy[8][0]**i * soy[9][0]**j
                                        if n <= t:
                                        	ans = max(ans, m//t)
print(ans)
### BUGGY CODE ###

import sys
import operator
from functools import reduce
from scipy.misc import comb


def ncr(n, r):
    return comb(n, r, exact=True)


def step2patterns(num_step, step_dict):
    try:
        return step_dict[num_step]
    except KeyError:
        ret = step2patterns(num_step-1, step_dict) + step2patterns(num_step-2, step_dict)
        step_dict[num_step] = ret
        return ret


sys.setrecursionlimit(100000)
num_stair, num_wet = map(int, input().split(' '))

last_wet = -1
num_pattern = 1
d = {0: 1, 1: 1, 2: 2}

for i in range(0, num_wet):
    wet = int(input())
    dry_step = wet - last_wet - 1
    last_wet = wet

    if dry_step <= 0:
        print('0')
        exit(0)

    elif dry_step == 1 or dry_step == 2:
        continue

    else:
        num_pattern *= step2patterns(dry_step - 1, d)

    num_pattern %= 1000000007

# last step
dry_step = num_stair - last_wet

num_pattern *= step2patterns(dry_step - 1, d)

print(num_pattern % 1000000007)
exit(0)


### FIXED CODE ###

def exec_ncr(max_step, record_dict):
    for i in range(2, max_step+1):
        record_dict[i] = record_dict[i-1] + record_dict[i-2]


num_stair, num_wet = map(int, input().split(' '))

last_wet = -1
num_pattern = 1
d = {0: 1, 1: 1}
exec_ncr(num_stair, d)

for i in range(0, num_wet):
    wet = int(input())
    dry_step = wet - last_wet - 1
    last_wet = wet

    if dry_step <= 0:
        print('0')
        exit(0)

    elif dry_step == 1 or dry_step == 2:
        continue

    else:
        num_pattern *= d[dry_step-1]

# last step
dry_step = num_stair - last_wet

num_pattern *= d[dry_step-1]

print(num_pattern % 1000000007)
exit(0)
### BUGGY CODE ###



N = int(input())
S = input()
#N = 8
#S = 'WWWWWEEE'


min = 1000000
for i in range(1,N-1):
    if S[i:i+1] == 'EE':
        continue
    if S[i-1:i] == 'WW':
        continue
    l = S[i]
    if l == 'W':
        left = S[0:i-1].count('W')
        right = S[i+1:].count('E')
    else:
        left = S[0:i-1].count('W')
        right = S[i+1:].count('E')
    sum = right + left
    #print(l, sum, left, right)
    if min > sum:
        min = sum
print(min)


### FIXED CODE ###



N = int(input())
S = input()
#N = 12
#S = 'WEWEWEEEWWWE'


min = 1000000
e = S.count('E')
w = 0

for i in range(0,N):
    flag = 0
    now = S[i]
    if now == 'E':
        e = e - 1
    else:
        flag = 1
    sum = w + e
    if min > sum:
        min = sum
    if flag:
        w = w + 1
print(min)
### BUGGY CODE ###

import sys
 
inf = 1 << 32
 
def solve():
    N, W = map(int, input().split())
    ws = []
    vs = []
 
    for i in range(N):
        wi, vi = map(int, input().split())
        ws.append(wi)
        vs.append(vi)
 
    dp = [[[-inf]*(3*N + 1) for j in range(N + 1)]
                              for i in range(N + 1)]
 
    dp[0][0][0] = 0
 
    for i in range(N):
        for j in range(N + 1):
            for k in range(3*N + 1):
                dp[i + 1][j][k] = dp[i][j][k]
 
                if j - 1 >= 0 and k - (ws[i] - ws[0]) >= 0:
                    dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j - 1][k - (ws[i] - ws[0])] + vs[i])
 
    ans = 0
 
    for j in range(N + 1):
        for k in range(3*N + 1):
            if ws[0]*j + k <= W:
                ans = max(ans, dp[N][j][k])
 
    print(ans)
 
if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys

inf = 1 << 32

def solve():
    N, W = map(int, input().split())
    ws = []
    vs = []

    for i in range(N):
        wi, vi = map(int, input().split())
        ws.append(wi)
        vs.append(vi)

    dp = [[[-inf]*(3*N + 1) for j in range(N + 1)]
                              for i in range(N + 1)]

    dp[0][0][0] = 0

    for i in range(N):
        for j in range(N + 1):
            for k in range(3*N + 1):
                dp[i + 1][j][k] = dp[i][j][k]

                if j - 1 >= 0 and k - (ws[i] - ws[0]) >= 0:
                    dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j - 1][k - (ws[i] - ws[0])] + vs[i])

    ans = 0

    for j in range(N + 1):
        for k in range(3*N + 1):
            if ws[0]*j + k <= W:
                ans = max(ans, dp[N][j][k])

    print(ans)

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

a = list(map(int,input().split()))
N = a[0]
K = a[1]
H = list(map(int,input().split()))
H.sort(reverse=True)
ans = 0
if K >= N:
    print(0)
else:
    for i in range(K):
        b = H.pop(0)
    for i in range(len(H)):
        ans += H[i]
    print(ans)

### FIXED CODE ###

a = list(map(int,input().split()))
N = a[0]
K = a[1]
H = list(map(int,input().split()))
H.sort(reverse=True)
ans = 0
MOD = 10**9 + 7
if K >= N:
    print(0)
else:
    for i in range(K,N):
        ans += H[i]

    print(ans)
### BUGGY CODE ###

import bisect

def solve():
    N = int(input())
    S = list(input())
    Q = int(input())
    set_dic = {}

    for i, s in enumerate(S):
        if s not in set_dic:
            set_dic[s] = [i+1]
        else:
            bisect.insort_left(set_dic[s], i+1)

    anslist = []

    for _ in range(Q):
        query1, query2, query3 = input().split()
        if query1 == "1":
            i = int(query2)
            c = query3
            cap = S[i-1]
            if cap == c:
                continue
            set_dic[cap].remove(i)
            if c not in set_dic:
                set_dic[c] = [i]
            else:
                bisect.insort_left(set_dic[c], i)
            S[i-1] = c
        else:
            l = int(query2)
            r = int(query3)
            ansset = set()
            ans = 0
            for eachlist in set_dic.values():
                li = bisect.bisect_left(eachlist, l)
                ri = bisect.bisect_right(eachlist, r)
                if li != ri:
                    ans += 1
            anslist.append(ans)

    for i in anslist:
        print(i)

if __name__ == '__main__':
    solve()

### FIXED CODE ###

import bisect
import sys
input = sys.stdin.readline

def solve():
    N = int(input())
    S = list(input())
    Q = int(input())
    set_dic = {}

    for i, s in enumerate(S):
        if s not in set_dic:
            set_dic[s] = [i+1]
        else:
            bisect.insort_left(set_dic[s], i+1)

    anslist = []

    for _ in range(Q):
        query1, query2, query3 = input().split()
        if query1 == "1":
            i = int(query2)
            c = query3
            cap = S[i-1]
            if cap == c:
                continue
            set_dic[cap].remove(i)
            if c not in set_dic:
                set_dic[c] = [i]
            else:
                bisect.insort_left(set_dic[c], i)
            S[i-1] = c
        else:
            l = int(query2)
            r = int(query3)
            ansset = set()
            ans = 0
            for eachlist in set_dic.values():
                li = bisect.bisect_left(eachlist, l)
                ri = bisect.bisect_right(eachlist, r)
                if li != ri:
                    ans += 1
            anslist.append(ans)

    for i in anslist:
        print(i)

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

N = int(input())
L = []
i = 0
while i < N:
    tmp = input()
    L.append(sorted(tmp))
    i += 1

cnt = 0
i = 0

while i < N-1:
    j = i+1
    while j < N:
        if L[i] == L[j]:
            cnt += 1
        j += 1
    i += 1

print(cnt)

### FIXED CODE ###

n = int(input())
s = []
for _ in range(n):
    tmp = list(input())
    tmp.sort()
    s.append(str(tmp))
cnt = 0
dict = {}
for x in s:
    if x in dict:
        cnt += dict[x]
        dict[x] += 1
    else:
        dict[x] = 1
print(cnt)