Harryxun/stf_run huggingface dataset:
import sys

sentence = sys.stdin.read().lower()
alf=[chr(i) for i in range(ord('a'), ord('z'))]

ans=list(zip(alf, [0]*26))

for a in sentence:
  if a in ans:
    ans[a] += 1

for key, val in enumerate(ans):
  print(key + " : " + val)

### FIXED CODE ###

import sys

sentence = sys.stdin.read().lower()
alf=[chr(i) for i in range(ord('a'), ord('z')+1)]

ans=dict(zip(alf, [0]*26))

for a in sentence:
  if a in ans:
    ans[a] += 1

for (key, val) in sorted(ans.items()):
  print(key ,":" , val)
from collections import*
from copy import *
n=int(input())
d=defaultdict(list)

q=[]
for i in range(n-1):
    a,b=map(int,input().split())
    d[a].append(b)
    d[b].append(a)
    q.append(tuple(sorted([a,b])))
    
#print(d)
m=max(map(len,d.values()))
print(m)

dcolars={}

def BFS(d,point,c):
    colar=set(range(1,m+1))
    for i in d[point]:
        if tuple(sorted([point,i])) not in dcolars:
            ckamo=colar.pop()
            if c==ckamo:
                csave=deepcopy(ckamo)
                ckamo=colar.pop()
                colar.add(csave)
            dcolars[tuple(sorted([point,i]))]=ckamo
            BFS(d,i,ckamo)
    return dcolars

ans=BFS(d,1,0)

for i in q:
    print(ans[i])

### FIXED CODE ###

from collections import*
import sys
sys.setrecursionlimit(10**8)
input=sys.stdin.readline

n=int(input())
d={}

q=[]
for i in range(n-1):
    a,b=map(int,input().split())
    if a not in d:
        d[a]=[]
    if b not in d:
        d[b]=[]
    d[b].append(a)
    d[a].append(b)        
    q.append(tuple(sorted([a,b])))

m=max(map(len,d.values()))
print(m)

dcolars={}

def BFS(d,point,c):
    for i in d[point]:
        if tuple(sorted([point,i])) not in dcolars:
            c+=1
            if c==m+1:
                c=1
            dcolars[tuple(sorted([point,i]))]=c
            BFS(d,i,c)
    return dcolars

ans=BFS(d,1,0)

for i in q:
    print(ans[i])
W = raw_input().lower()
ret = 0
while 1:
    text = raw_input().lower()
    if text == "END_OF_TEXT":
        break
    ret += text.count(W)
print ret

### FIXED CODE ###

W = raw_input().lower()
ret = 0
while 1:
    text = raw_input().split()
    if text[0] == "END_OF_TEXT":
        break
    for t in text:
        if W == t.lower():
            ret += 1
print ret
dat0 = input()
dat1 = input()
dat2 = input()


if dat0 == 1:
    print("Hello World")
else
    ans = int(dat1) + int(dat2)
    print(ans)


### FIXED CODE ###

dat0 = input()
if dat0 == "1":
    print("Hello World")
else:
    dat1 = input()
    dat2 = input()
    ans = int(dat1) + int(dat2)
    print(ans)
import heapq
import copy

V, M = map(int, input().split())
d = [0] * V
prev = [0] * V

cost = [[INF] * V for i in range(V)]
for i in range(M):
    a, b, c = map(int,  input().split())
    cost[a - 1][b - 1] = c
    cost[b - 1][a - 1] = c
    
def dijkstra_back(s, t):
    for i in range(V):
        prev[i] = s
        d[i] = float('inf')
    d[s] = 0
    h = []
    heapq.heappush(h, [0, s])
    
    while h != []:
        p = heapq.heappop(h)
        v = p[1]
        if d[v] < p[0]:
            continue
         
        for i in range(V):
            if d[i] > d[v] + cost[v][i]: 
                d[i] = d[v] + cost[v][i]
                heapq.heappush(h, [d[i], i])
                prev[i] = v
        
    path = [t]
    while prev[t] != s:
        path.append(prev[t])
        prev[t] = prev[prev[t]]
    path.append(s)
    path = path[::-1]
    return path

cost2 = copy.deepcopy(cost)
for i in range(V - 1):
    for j in range(i + 1, V):
        g = dijkstra_back(i, j)
        # print(i, j, g)
        for k in range(len(g) - 1):
            cost2[g[k]][g[k + 1]] = INF
            cost2[g[k + 1]][g[k]] = INF
            
cnt = 0
for i in range(V):
    for j in range(V):
        if cost2[i][j] != INF:
            cnt += 1
                     
print(cnt // 2)

### FIXED CODE ###

import copy
from scipy.sparse.csgraph import floyd_warshall as wf

N, M = map(int, input().split())
INF = float('inf')

d = [[INF] * (N) for i in range(N)]
e_list = []
for i in range(N):
    d[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    d[a - 1][b - 1] = c
    d[b - 1][a - 1] = c
    e_list.append([a - 1, b - 1, c])
    
wf = wf(d)

cnt = M
for a, b, c in e_list:
    for i in range(N):
        if wf[i][a] + c == wf[i][b]:
            cnt -= 1
            break
    
print(cnt)
N = int(input())
S = map(int, input().split())

print(max(S) - min(S))

### FIXED CODE ###

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

print(max(S) - min(S))
n, m = map(int, input().split())
AC = [0] * n
WA = [0] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == 'AC' and a[p] == 0:
        AC[p] += 1
        w += W[p]
    elif s == 'WA' and a[p] == 0:
        WA[p] += 1

print(sum(a), w)


### FIXED CODE ###

n, m = map(int, input().split())
AC = [0] * n
WA = [0] * n
w = 0

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == 'AC' and AC[p] == 0:
        AC[p] += 1
        w += WA[p]
    elif s == 'WA' and AC[p] == 0:
        WA[p] += 1

print(sum(AC), w)
while 1:

x,op,y = raw_input().split()

if op == "?":
    break

x = int(x)
y = int(y)

if op == "+":
    print x+y
elif op == "-":
    print x-y
elif op == "*":
    print x*y
else:
    print x/y

### FIXED CODE ###

while 1:

    x,op,y = raw_input().split()

    if op == "?":
        break

    x = int(x)
    y = int(y)

    if op == "+":
        print x+y
    elif op == "-":
        print x-y
    elif op == "*":
        print x*y
    else:
        print x/y
N=input()

if (N ="ABC"):
    print("ARC")
else:
    print(ABC)

### FIXED CODE ###

n=input()

if (n =="ABC"):
    print("ARC")
else:
    print("ABC")
import fractions
from functools import reduce
import math
def lcm_base(x, y):
    return int((x * y) // fractions.gcd(x, y))
def lcm_list(numbers):
    return int(reduce(lcm_base, numbers, 1))

N,M = map(int,input().split())
List=list(map(int,input().split()))
aa = int(lcm_list(List)/2)
cnt = 0
a=List[0]
while a%2 == 0:
  cnt+=1
  a = int(a/2)
out = 0
if cnt == 0:
  out = 1
  cnt = 1
for i in range(len(List)):
  if List[i] % (2**cnt) == 1:
    out = 1
  elif List[i] % (2**(cnt+1)) == 0:
    out = 1

if out == 1:
  print(0)
else:
  print(int(math.ceil((M / aa)) // 2))

### FIXED CODE ###

N, M = map(int, input().split())
A = list(set(map(lambda x : int(x)//2, input().split())))
def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)
def lcm(x, y):
  return (x * y) // gcd(x, y)
l = A[0]
for a in A[1:]:
  l = lcm(l, a)
ans = (M // l + 1) // 2
for a in A[1:]:
  if (l // a) % 2 == 0:
    ans = 0
    break
print(ans)
import sys
l = raw_input().split()
N = int(l[0])
M = int(l[1])
nlist = []
list1 = []
flag = True
for i in range(0, M):
    tmp = raw_input().split()
    a = int(tmp[0])
    b = int(tmp[1])
     if a == 1:
        list1.append(b)
        continue
    if b == N:
        nlist.append(a)
        continue
matched_list = list(set(list1) & set(nlist))
if len(matched_list) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

### FIXED CODE ###

import sys
l = raw_input().split()
N = int(l[0])
M = int(l[1])
nlist = []
list1 = []
for i in range(0, M):
    tmp = raw_input().split()
    a = int(tmp[0])
    b = int(tmp[1])
    if a == 1:
        list1.append(b)
        continue
    if b == N:
        nlist.append(a)
        continue
matched_list = list(set(list1) & set(nlist))
if len(matched_list) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

N = k()
count = 0
for i in range(1,N+1):
    t = N//i
    count += i * t*(t+1)/2
print(int(count))


### FIXED CODE ###

import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

N, M = I()
H = l()
good = [1]*N
for k in range(M):
    A, B = map(int, input().split())
    if H[A - 1] >= H[B - 1]:
        good[B - 1] = 0
    if H[A - 1] <= H[B - 1]:
        good[A - 1] = 0
print(sum(good))
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()
a = LIST()

n = ceil(log2(max(a)))

A = ["{:b}".format(x).zfill(n) for x in a]


b = a[0]
for i in range(1, N):
	b ^= a[i]
b = "{:b}".format(b).zfill(n)


ans = []

for x in A:
	tmp2 = 0
	for i in range(n):
		tmp2 += ((int(b[i])+int(x[i]))%2) * (2**(n-1-i))

	ans.append(tmp2)

print(*ans)

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()
a = LIST()

if max(a) == 0:
	print(*[0]*N)
	exit()

n = ceil(log2(max(a)))+1

A = ["{:b}".format(x).zfill(n) for x in a]


b = a[0]
for i in range(1, N):
	b ^= a[i]
b = "{:b}".format(b).zfill(n)


ans = []

for x in A:
	tmp = 0
	for i in range(n):
		tmp += ((int(b[i])+int(x[i]))%2) * (2**(n-1-i))

	ans.append(tmp)

print(*ans)
n = input()
if "9" in n:
    print("Yes")
else:
    print(No)

### FIXED CODE ###

n = input()
if "9" in n:
    print("Yes")
else:
    print("No")
import random for random
n = int(input())
x = randint(1,n)
if n % 2 ==0:
  print(0.5)
else:
  count = (1+n)*n*0.5
  counts = count//2
  print(counts/count)

### FIXED CODE ###

import random
n = int(input())
x = random.randint(1,n)
if n % 2 ==0:
  print(0.5)
else:
  count = n//2
  print((n-count)/n)
s=input()
gx,gy=map(int,input().split())
lists=list(s.split("T"))
xlist=[]
ylist=[]
if s[0]=="T":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
elif s[0]=="F":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
    gx-=xlist[0]
    del xlist[0]
for some in xlist:
    some=abs(some)
for some in ylist:
    some=abs(some)
Xsum=sum(xlist)
Ysum=sum(ylist)
if (Xsum+gx)%2!=0 or (Ysum+gy)%2!=0:
    print("No")
else:
    gx1=(Xsum+gx)//2
    gx2=(Xsum-gx)//2
    gy1=(Ysum+gy)//2
    gy2=(Ysum-gy)//2
    dpx=[[False for i in range(8001)] for i in range(len(xlist)+1)]
    dpy=[[False for i in range(8001)] for j in range(len(ylist)+1)]
    #dpx[i][j]でi番目のカードまでを足して、値ｊを取れるか判定する
    dpx[1][xlist[0]]=True
    dpy[1][ylist[0]]=True
    
    for i in range(1,len(xlist)):
        for j in range(8001):
            dpx[i+1][j]=dpx[i][j-xlist[i]] or dpx[i][j]
    for i in range(1,len(ylist)):
        for j in range(8001):
            dpy[i+1][j]=dpy[i][j-ylist[i]] or dpy[i][j]    
            
    if (dpy[len(ylist)][gy1] or dpy[len(ylist)][gy2]) and (dpx[len(xlist)][gx1] or dpx[len(xlist)][gx2]):
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

      #FT robot
s=input()
gx,gy=map(int,input().split())
lists=list(s.split("T"))
xlist=[]
ylist=[]
if s[0]=="T":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
elif s[0]=="F":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
    gx-=xlist[0]
    del xlist[0]
Xsum=sum(xlist)
Ysum=sum(ylist)


if (Xsum+gx)%2!=0 or (Ysum+gy)%2!=0:
    print("No")   
else:
    gx1=(Xsum+gx)//2
    gx2=(Xsum-gx)//2
    gy1=(Ysum+gy)//2
    gy2=(Ysum-gy)//2
    dpx=[[False for i in range(Xsum+2)] for j in range(len(xlist)+2)]
    dpy=[[False for i in range(Ysum+2)] for j in range(len(ylist)+2)]
    #dpx[i][j]でi番目のカードまでを足して、値ｊを取れるか判定する
    dpx[0][0]=True
    dpy[0][0]=True
    for i in range(len(xlist)):
        for j in range(Xsum+2):
            dpx[i+1][j]=dpx[i][j-xlist[i]] or dpx[i][j]
    for i in range(len(ylist)):
        for j in range(Ysum+2):
            dpy[i+1][j]=dpy[i][j-ylist[i]] or dpy[i][j]    
    #ここまではあってそうなことがわかった
    flag1=False
    if 0<= gy1<= Ysum:   
        if dpy[len(ylist)][gy1]:
            flag1=True
    flag2=False
    if 0<=gy2<= Ysum :
        if dpy[len(ylist)][gy2]:
            flag2=True
    flag3=False
    if 0<=gx1<= Xsum:
        if dpx[len(xlist)][gx1]:
            flag3=True
    flag4=False
    if 0<=gx2<= Xsum:
        if dpx[len(xlist)][gx2]:
            flag4=True
    if (flag1 or flag2) and (flag3 or flag4):
        print("Yes")
    else:
        print("No")
for i in range(1, 10):
for j in range(1, 10):
print(i * j)

### FIXED CODE ###

for i in range(1, 10):
    for j in range(1, 10):
        print(str(i) + "x" + str(j) + "=" + str(i * j))
import sys
input_line = [int(i) for i in input().split(" ")]
n = input_line[0]
m = input_line[1]

ans = ["0"] * n
for i in range(m):
    input_line = input().split(" ")
    if ans[int(input_line[0] - 1)] == "0" or ans[int(input_line[0] - 1)] == input_line[1]:
        ans[int(input_line[0] - 1)] = input_line[1]
    else:
        print(-1)
        sys.exit()

if m == 0:
    ans[0] = "1"

ans_num = int("".join(ans))
if n == len(str(ans_num)):
    print(ans_num)
else:
    print(-1)


### FIXED CODE ###

import sys
input_line = [int(i) for i in input().split(" ")]
n = input_line[0]
m = input_line[1]

ans = ["1"] + ["0"] * (n - 1)
flag = 0
for i in range(m):
    input_line = input().split(" ")
    if int(input_line[0]) == 1 and flag == 0:
        ans[int(input_line[0]) - 1] = input_line[1]
        flag = 1
        continue
    elif int(input_line[0]) == 1 and flag == 1:
        if input_line[1] != ans[0]:
            print(-1)
            sys.exit()

    if ans[int(input_line[0]) - 1] == "0" or ans[int(input_line[0]) - 1] == input_line[1]:
        ans[int(input_line[0]) - 1] = input_line[1]
    else:
        print(-1)
        sys.exit()

if m == 0 and n == 1:
    ans[0] = "0"

ans_num = int("".join(ans))
if n == len(str(ans_num)):
    print(ans_num)
else:
    print(-1)
a = input()
print(a + a**2 + a**3)


### FIXED CODE ###

a = int(input())
print(a + a**2 + a**3)
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''D Redistribution'''
mod=10**9+7
n = r()
ans = [0]*(n+1)
dp = [0]*(n+1)
ans[0]=1
dp[0]=dp[1]=dp[2]=1
for i in range(3,n+1):
    ans[i]=dp[i-3]
    dp[i]=(dp[i-1]+ans[i])%mod
print(ans[-1])

### FIXED CODE ###

import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''D Redistribution'''
mod=10**9+7
n = r()
ans = [0]*(n+1)
dp = [0]*(n+1)
ans[0]=1
dp[0]=1
if n>=1:
    dp[1]=1
if n>=2:
    dp[2]=1
for i in range(3,n+1):
    ans[i]=dp[i-3]
    dp[i]=(dp[i-1]+ans[i])%mod
print(ans[-1])
MAX = 100
INFTY = 1 << 21
WHITE = 0
GRAY = 1
BLACK = 2
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
color = [WHITE for i in range(n)]

n = int(input())
M = [[map(int, input().split()) for i in range(n)] for j in range(n)]
for i in range(n):
    for j in range(n):
        if (M[i][j] == -1):
            M[i][j] = INFTY

def prim():
    global M, d, p, color
    d[0] = 0
    while(1):
        minv = INFTY
        u = -1
        for i in range(n):
            if (minv > d[i] and color[i] != BLACK):
                u = i
                minv = d[i]
        if (u == -1):
            break
        color[u] = BLACK
        for v in range(n):
            if (color[v] != BLACK and M[u][v] != INFTY):
                if (d[v] > M[u][v]):
                    d[v] = M[u][v]
                    p[v] = u
                    color[v] = GRAY
    
    _sum = sum([M[i][p[i]] for i in range(n) if (p[i] != -1)])
    return _sum

print(prim())

### FIXED CODE ###

INFTY = 1 << 21
WHITE = 0
GRAY = 1
BLACK = 2

n = int(input())
M = [list(map(int, input().split())) for i in range(n)]

d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
color = [WHITE for i in range(n)]

for i in range(n):
    for j in range(n):
        if (M[i][j] == -1):
            M[i][j] = INFTY

def prim():
    global M, d, p, color
    d[0] = 0
    while(1):
        minv = INFTY
        u = -1
        for i in range(n):
            if (minv > d[i] and color[i] != BLACK):
                u = i
                minv = d[i]
        if (u == -1):
            break
        color[u] = BLACK
        for v in range(n):
            if (color[v] != BLACK and M[u][v] != INFTY):
                if (d[v] > M[u][v]):
                    d[v] = M[u][v]
                    p[v] = u
                    color[v] = GRAY
    
    return sum([M[i][p[i]] for i in range(n) if p[i] != -1])

print(prim())
import numpy as np
X, N=map(int,input().split())
ps=map(int,input().split())

ps_sort=sorted(ps)

ind_crit=N-1
for p in ps_sort:
  if p>=X:
    ind_crit=ps_sort.index(p)
    break
    
if not ps_sort[ind_crit]==X:
  ans=X
else:
  diff=0
  while(True):
    diff+=1
    if not X-diff in ps_sort:
      ans=X-diff
      break
    if not X+diff in ps_sort:
      ans=X+diff
      break

print(ans)


### FIXED CODE ###

import numpy as np
X, N=map(int,input().split())
if N==0:
  ans=X
  print(ans)
else:
  ps=map(int,input().split())

  ps_sort=sorted(ps)

  ind_crit=N-1
  for p in ps_sort:
    if p>=X:
      ind_crit=ps_sort.index(p)
      break

  if not ps_sort[ind_crit]==X:
    ans=X
  else:
    diff=0
    while(True):
      diff+=1
      if not X-diff in ps_sort:
        ans=X-diff
        break
      if not X+diff in ps_sort:
        ans=X+diff
        break

  print(ans)
N = imput()
A = imput()

print (N * N - A)

### FIXED CODE ###

N = int(input())
A = int(input())

print(N*N-A)
N = int(input())
a = list(map(int, input().split()))

### FIXED CODE ###

a, b, c = map(int, input().split())
sums = [a+b,b+c,c+a]
print(min(sums))
from itertools import accumulate
from math import factorial as fc

def cmb(n,r):
    if n < 0 or r < 0 or n-r < 0:
        return 0
    return fc(n)//(fc(n-r)*fc(r))

N,K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
A = [i-1 for i in A]

sumA = list(accumulate(A))
sumA = [0]+[i % K for i in sumA]
x = sumA[:K]
modmap = [0]*K
for i in x:
    modmap[i] += 1

ans = 0
for i in range(K):
    ans += cmb(modmap[i],2)

for i in range(N-K+1):
    modmap[sumA[K+i]] += 1
    modmap[sumA[i]] -= 1
    ans += modmap[sumA[K+i]]-1

print(ans)

### FIXED CODE ###

import sys
from itertools import accumulate
from collections import defaultdict
input = sys.stdin.readline
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = [i-1 for i in a]
suma = [0]+list(accumulate(a))
suma = [i%k for i in suma]
rem = defaultdict(int)
ans = 0
if k > n:
    for i in range(n+1):
        x = suma[i]
        rem[x] += 1
    for s in rem.values():
        ans += s*(s-1)//2
    print(ans)
    exit()
for i in range(k):
    x = suma[i]
    rem[x] += 1
for s in rem.values():
    ans += s*(s-1)//2
for i in range(n-k+1):
    rem[suma[i]%k] -= 1
    rem[suma[i+k]%k] += 1
    ans += rem[suma[i+k]] -1
print(ans)
import math
N,X0=map(int,input().split())
X=list(map(int,input().split()))
X_=[]
ans=abs(X[0]-X0)
for i in range(1,N):
    ans=math.gcd(ans,abs(X[i]-X0))
print(ans)

### FIXED CODE ###

import fractions
N,X0=map(int,input().split())
X=list(map(int,input().split()))
X_=[]
ans=abs(X[0]-X0)
for i in range(1,N):
    ans=fractions.gcd(ans,abs(X[i]-X0))
print(ans)
n,q=map(int,input().split())
s=input()
a=[0]*n
k=0
for i in range(n):
  if(s[i]=='A' and s[i+1]=='C'):
    k+=1
  a[i]=k
for j in range(q):
  l,r=map(int,input().split())
  if(l==1):
    print(a[r-2])
  else:
    print(a[r-2]-a[l-2])

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
a=[0]*n
k=0
for i in range(n-1):
  if(s[i]=='A' and s[i+1]=='C'):
    k+=1
  a[i]=k
for j in range(q):
  l,r=map(int,input().split())
  if(l==1):
    print(a[r-2])
  else:
    print(a[r-2]-a[l-2])
import sys
from bisect import bisect_right

s = input()
t = input()

t_set = set(t)

if len(t_set -set(s)) != 0:
    print(-1)
    sys.exit()

s_len = len(s)
def index_list(char):
    word = s
    ret = list()
    sum = 0
    try:
        while True:
            index = word.index(char)+ 1        
            sum+=index
            ret.append(sum)
            word = word[index:]
    except:
        if sum == 0:
            ret.append(-1)
    return ret

alpha_dict = dict()
for char in t_set:
    alpha_dict[char] = index_list(char)

index_old = 0
n_s = 0
for char in t:
    index = alpha_dict[char]
    
    flg = True
    
    if index[-1] < index_old:
        pass
    else:
        index_old = index[bisect_right(index, index_old)]
        flg =False
    if flg:
        index_old = index[0]
        n_s += 1
        
print(n_s*s_len + index_old)

### FIXED CODE ###

import sys
s = input()
t = input()
tset = set(t)
slen = len(s)
if len(tset - set(s)) != 0:
    print(-1)
    sys.exit()
s2t = [i - ord('a') for i in (s + s).encode('ascii')]
lut = [[-1 for _ in range(slen)] for _ in range(26)]
for c in tset:
  b = ord(c) - ord('a')
  j = 0
  for i in range(slen * 2 - 1, -1, -1):
    if s2t[i] == b:
      j = 0
    else:
      j += 1
    if i < slen:
      lut[b][i] = j
p = 0
for c in t:
  b = ord(c) - ord('a')
  p += lut[b][p % slen] + 1
print(p)