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

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    n = int(input())
    s = tuple(map(int, tuple(input())))
    num_pos = [] # 各数字がｓ中に最後にあらわれる位置。
    for num in range(10):
        if num in s:
            num_pos.append(n - s[::-1].index(num) - 1)
    unique_num = [0] * n # ｓの各桁でその桁以降にある数字の種類。
    for i1 in range(n):
        unique_num[i1] = sum([np >= i1 for np in num_pos])
    d1 = defaultdict(int)
    for keta1 in range(n - 2):
        for keta2 in range(keta1 + 1, n - 1):
            if not d1[(s[keta1], s[keta2])]:
                d1[(s[keta1], s[keta2])] = unique_num[keta2 + 1]
    r = sum(d1.values())
    print(r)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
#from collections import defaultdict
def main():
    n = int(input())
    s = tuple(map(int, tuple(input())))
    num_pos = [] # 各数字がｓ中に最後にあらわれる位置。
    for num in range(10):
        if num in s:
            num_pos.append(n - s[::-1].index(num) - 1)
    unique_num = [0] * n # ｓの各桁でその桁以降にある数字の種類。
    for i1 in range(n):
        unique_num[i1] = sum([np >= i1 for np in num_pos])
    unique_num.append(0)
    r = 0
    for keta1 in range(10):
        if keta1 in s:
            keta1_pos = s.index(keta1)
            for keta2 in range(10):
                if keta2 in s[keta1_pos + 1:]:
                    keta2_pos = s[keta1_pos + 1:].index(keta2) + keta1_pos + 1
                    r += unique_num[keta2_pos + 1]
    print(r)

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

def main():

    from collections import deque
    h, w = map(int, input().split())
    s = [list(input()) for _ in range(h)]
    cost = [[600] * w for _ in range(h)]
    nb = [(-1, 0), (0, -1), (1, 0), (0, 1)]
    ans = 0

    def bfs(sx, sy, gx, gy):
        q = deque([(sx, sy)])
        cost[sy][sx] = 0

        while q != deque([]):
            x, y = q.popleft()
            for dx, dy in nb:
                nx = x + dx
                ny = y + dy
                if 0 <= nx and nx < w and 0 <= ny and ny < h and s[ny][nx] == "." and cost[ny][nx] == 600:
                    q.append((nx, ny))
                    cost[ny][nx] = cost[y][x] + 1
                    if nx == gx and ny == gy:
                        return cost[gy][gx]
        return 0

    ans = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                continue
            for k in range(h):
                for l in range(w):
                    if s[i][j] == "#":
                        continue
                    cost = [[600] * w for _ in range(h)]
                    tmp = bfs(j, i, l, k)
                    ans = max(tmp, ans)

    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():

    from collections import deque
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    cost = [[600] * w for _ in range(h)]
    nb = [(-1, 0), (0, -1), (1, 0), (0, 1)]
    ans = 0

    def bfs(sx, sy):
        q = deque([(sx, sy)])
        cost[sx][sy] = 0
        value = 0
        while q:
            x, y = q.popleft()
            for dx, dy in nb:
                nx = x + dx
                ny = y + dy
                if 0 <= nx and nx < h and 0 <= ny and ny < w and s[nx][ny] == "." and cost[nx][ny] == 600:
                    q.append((nx, ny))
                    cost[nx][ny] = cost[x][y] + 1
                    value = max(value, cost[nx][ny])
        return value

    ans = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                cost = [[600] * w for _ in range(h)]
                tmp = bfs(i, j)
                ans = max(tmp, ans)

    print(ans)


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

n = int(input())
li = list(map(int, input().split()))
tmpMinIndex = li.index(1)
count = 1

while True:
    if tmpMinIndex == 0:
        break
    li = li[0:tmpMinIndex]
    minNum = min(li)
    tmpMinIndex = li.index(minNum)
    count += 1


print(count)

### FIXED CODE ###

n = int(input())
li = list(map(int, input().split()))
tmpMin = li[0]
count = 0

for i in range(n):
    if li[i] <= tmpMin:
        tmpMin = li[i]
        count += 1

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

import bisect

n = int(input())
length = list(map(lambda x:int(x), input().split()))
length.sort()
ans = 0
for i in range(n):  
    a = length[i]
    for j in range(i+1,n):
        b = length[j]
        if i >= j:
            continue
        else:
            c_candidates = length[j+1:]
            min_bar = bisect.bisect_right(c_candidates,b-a)
            max_bar = bisect.bisect_left(c_candidates,a+b)
            ans += max_bar - min_bar
            
print(ans)

### FIXED CODE ###

import bisect

n = int(input())
#length = list(map(lambda x:int(x), input().split()))
length = list(map(int, input().split()))
length.sort()
ans = 0
for i in range(n-2):  
    a = length[i]
    for j in range(i+1,n-1):
        b = length[j]
        if i >= j:
            continue
        else:
            max_bar = bisect.bisect_left(length,a+b)
            ans += max_bar - j - 1
            
print(ans)
### BUGGY CODE ###

data = input().split()
tab = [int(data[1])]*int(data[0])
n = int(data[2])
    
for i in range(n):
    value =int(input())
    tab[value - 1] += 1
    j =0
    while (j < len(tab)):
        tab[j] -= 1
        j += 1
        
for i in tab:
    if (i > 0):
        print ("Yes")
    else:
        print ("No")


### FIXED CODE ###

data = input().split()
score = int(data[1])
tab = [score]*int(data[0])
n = int(data[2])
    
for i in range(n):
    value =int(input())
    tab[value - 1] += 1
    j =0
for i in tab:
    if (i > n):
        print ("Yes")
    else:
        print ("No")
### BUGGY CODE ###

N,M=map(int,input().split())
B=[list(map(int,input().split())) for _ in range(M)]
li=[]
ans="IMPOSSIBLE"
for i,j in B:
  if i==1:
    li.append(j)
for l in li:
  if l==N:
    ans="POSSIBLE"
  else:
    for i,j in B:
      if i==l and j==N:
        ans="POSSIBLE"
print(ans)


### FIXED CODE ###

from collections import defaultdict
N,M=map(int,input().split())
B=[list(map(int,input().split())) for _ in range(M)]
dic=defaultdict(list)
ans="IMPOSSIBLE"
for i,j in B:
  dic[i].append(j)
O=dic.get(1)
if N in O:
    ans="POSSIBLE"
for o in O:
  T=dic.get(o)
  try:
    if N in T:
      ans="POSSIBLE"
  except:
    pass
print(ans)
### BUGGY CODE ###

import bisect
n=int(input())
A=[int(input())]

for i in range(n-1):
  a=int(input())
  b=bisect.bisect_left(A,a,lo=0,hi=len(A))
  if b==0:
    A.insert(0,a)
  else:
    A[b-1]=a
print(len(A))


### FIXED CODE ###

import bisect
from collections import deque
n=int(input())
A=deque([int(input())])

for i in range(n-1):
  a=int(input())
  b=bisect.bisect_left(A,a,lo=0,hi=len(A))
  if b==0:
    A.appendleft(a)
  else:
    A[b-1]=a
print(len(A))
### BUGGY CODE ###

from collections import Counter
n = int(input())
s = input()
c = Counter(s)
ans = c['R']*c['G']*c['B']

for i in range(n):
    for j in range(i+1, n):
        x, y = s[i], s[j]
        if x == y:
            continue
        if n <= 2*j-i:
            continue
        z = s[2*j-i]
        if x != z and y != z:
            ans -= 1

print(ans)


### FIXED CODE ###

from collections import Counter
from operator import mul
n = int(input())
s = input()
c = Counter(s)
if n < 3:
    print(0)
    exit()
elif len(c.keys()) < 3:
    print(0)
    exit()
ans = 0
for i in range(n):
    x = s[i]
    ans += mul(*[v for k, v in c.items()if k != x])
    c[x] -= 1
    for j in range(i+1, n):
        y = s[j]
        if x == y:
            continue
        idx_diff = j-i
        if n <= j+idx_diff:
            continue
        z = s[j+idx_diff]
        if x != z and y != z:
            ans -= 1
print(ans)
### BUGGY CODE ###

import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    M = I()
    L = [LI() for i in range(M)]
    L = L[::-1]
    temp = 0
    ans = 0
    
    for a, b in L:
        for j in range(b):
            temp += a
            ans += 1
            if temp >= 10:
                temp = 1 + temp % 10
                ans += 1

    print(ans-1)
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    M = I()
    L = [LI() for i in range(M)]
    L = L[::-1]
    temp = 0
    ans = 0
    for a, b in L:
        temp += a*b
        ans += b
        while temp >= 10:
            temp2 = temp // 10
            ans += temp2
            temp = (temp % 10) + temp2

    print(ans-1)
    
if __name__ == "__main__":
    main()
### BUGGY 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
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 fractions import gcd
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
#from decimal import *

R, G, B, N = MAP()
ans = 0
for i in range(N//R+1):
	r = i
	for j in range((N-R*r)//G + 1):
		g = j
		b = (N - R*r - G*g) / B
		if b == b//1 and 0 <= b:
			ans += 1

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
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 fractions import gcd
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
#from decimal import *

R, G, B, N = MAP()
ans = 0
for i in range(N//R+1):
	r = i
	for j in range((N-R*r)//G + 1):
		g = j
		b = (N - R*r - G*g) / B
		if b == b//1 and 0 <= b:
			ans += 1

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

N=int(input())
H=list(map(int,input().split()))
H.append(0)
h1=0
h2=0
a=0
for i in range(N-1):
    h1=H[i+1]-H[i]
    if h1<-1:
        a=1
        break
    elif h1==-1:
        for j in range(1,N-i):
            h2=H[i]-H[i+j]
            if h2>=2:
                a=1
                break
    if a==1:
        break
if a==0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

N=int(input())
H=list(map(int,input().split()))
a=0
for i in range(N-1)[::-1]:
    if H[i]>H[i+1]:
        H[i]-=1
for i in range(N-1):
    if H[i]>H[i+1]:
        a=1
        break
if a==0:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

N, M = map(int, input().split())
P = []
S = [0] * (N + 1)
for i in range(M):
  s, p = input().split()
  s = int(s)
  if s not in P:
    if p == 'AC':
      P.append(s)
    else:
      S[s] += 1
A = sum([S[i] for i in P])
print(len(P), A)

### FIXED CODE ###

N, M = map(int, input().split())
P = [0] * (N + 1)
S = [0] * (N + 1)
for i in range(M):
  x, p = input().split()
  s = int(x)
  if P[s] == 0:
    if p == 'AC':
      P[s] = 1
    else:
      S[s] += 1
A = sum([S[i] for i in range(N + 1) if P[i] == 1])
print(P.count(1), A)
### BUGGY CODE ###

import math

n = int(input())
i = 1
j = 1
k = 1
ans = 0
while i < n+1:
    j = 1
    while j < n+1:
        k = 1
        while k < n+1:
            ans += math.gcd(i,math.gcd(j,k))
            k += 1
        j += 1
    i += 1
print(ans)

### FIXED CODE ###

def gcd(x,y):
    if y == 0:
        return x
    elif x == 1 or y == 1:
        return 1
    else:
        return gcd(y,x%y)

G = []
i,j = 1,1
while i < 201:
    j = 1
    g0 = []
    while j < 201:
        g0.append(gcd(i,j))
        j += 1
    g0 = tuple(g0)
    G.append(g0)
    i += 1
n = int(input())
i = 1
j = 1
k = 1
ans = 0
while i < n+1:
    j = 1
    while j < n+1:
        k = 1
        p = G[i-1][j-1]
        while k < n+1:
            ans += G[k-1][p-1]
            k += 1
        j += 1
    i += 1
print(ans)
### BUGGY CODE ###

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

ys = [0] * (max(a)+ 1)

for x in range(len(ys)):
    y = a.count(x-1) + a.count(x) + a.count(x+1)
    ys[x] = y

print(max(ys))
    

### FIXED CODE ###

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

d = {}

for i in range(max(a)+1):
  d[i] = 0

for a_ in a:
  d[a_] += 1

d[-1] = 0
d[max(a)+1] = 0

ans = 0

for x in range(max(a)+1):
  if x-1 in d:
    ans = max(ans, d[x-1] + d[x] + d[x+1])

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

import sys
input = sys.stdin.readline
read = sys.stdin.read

def main():
  n, q = map(int, input().split())
  event = []
  stop = set()
  for _ in range(n):
    s, t, x = map(int, input().split())
    event.append((s-x, 1, x))
    event.append((t-x, -1, x))
  event.sort()
  event.append((float("inf"), 0, 0))
  D = list(map(int, read().split()))
  now = 0
  for t, b, x in event:
    m = min(stop) if stop else -1
    while t > D[now]:
      print(m)
      now += 1
      if now == q:
        exit()
    if b == 1:
      stop.add(x)
    else:
      stop.remove(x)
      
if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
read = sys.stdin.read

import heapq

def main():
  n, q = map(int, input().split())
  event = []
  stop = set()
  minque = []
  for _ in range(n):
    s, t, x = map(int, input().split())
    event.append((s-x, 1, x))
    event.append((t-x, -1, x))
  event.sort()
  event.append((float("inf"), 0, 0))
  D = list(map(int, read().split()))
  now = 0
  for t, b, x in event:
    while minque and minque[0] not in stop:
      heapq.heappop(minque)
    m = minque[0] if minque else -1
    while t > D[now]:
      print(m)
      now += 1
      if now == q:
        exit()
    if b == 1:
      stop.add(x)
      heapq.heappush(minque, x)
    else:
      stop.remove(x)
      
if __name__ == "__main__":
  main()
### BUGGY CODE ###

from collections import defaultdict


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)  # 大きい順に並べておく
    MAX_EXP = 30  # 2**30 < 2 * (10 ** 9) < 2**31
    counter = defaultdict(int)
    for a in A:
        counter[a] += 1
    # 和が2のべき乗になるペアの間をedgeで結んだグラフを作る
    adj = defaultdict(list)
    for a in A:
        for e in range(MAX_EXP + 1):
            b = 2**e - a
            if counter[b] == 0:
                continue
            if a > b:
                adj[a].append(b)
            elif a < b:
                adj[b].append(a)
    # ノードの値が大きい順に貪欲にペアを作っていく
    ans = 0
    for a in A:
        for b in adj[a]:
            cnt = min(counter[a], counter[b])
            ans += cnt
            counter[a] -= cnt
            counter[b] -= cnt
    # 最後に2のべき乗のノードはそれ単体でペアを作れるので、その分を足す
    for e in range(MAX_EXP + 1):
        a = 2**e
        ans += counter[a] // 2
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import defaultdict


def main():
    N = int(input())
    A = list(map(int, input().split()))
    MAX_EXP = 30  # 2**30 < 2 * (10 ** 9) < 2**31
    pow2 = [1] * (MAX_EXP + 1)
    for e in range(1, MAX_EXP + 1):
        pow2[e] = 2 * pow2[e - 1]
    counter = defaultdict(int)
    for a in A:
        counter[a] += 1
    DISTINCT_A = list(counter.keys())
    DISTINCT_A.sort(reverse=True)  # 大きい順に並べておく
    # 和が2のべき乗になるペアの間をedgeで結んだグラフを考え
    # ノードの値が大きい順に貪欲にペアを作っていく
    ans = 0
    for a in DISTINCT_A:
        b = pow2[a.bit_length()] - a
        if counter[b] == 0:
            continue
        cnt = min(counter[a], counter[b])
        ans += cnt
        counter[a] -= cnt
        counter[b] -= cnt
    # 最後に2のべき乗のノードはそれ単体でペアを作れるので、その分を足す
    for e in range(MAX_EXP + 1):
        a = pow2[e]
        ans += counter[a] // 2
    print(ans)


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

h,w,m = map(int,input().split())
dich = {}
dicw = {}

havew = {}
for _ in range(m):
    h,w = map(int,input().split())
    if h in dich:
        dich[h] += 1
        havew[h].append(w)
    else:
        dich[h] = 1
        havew[h] = [w]
    if w in dicw:
        dicw[w] += 1
    else:
        dicw[w] = 1

dichi = list(dich.items())
dichi.sort(reverse=True, key=lambda x:x[1])
dicwi = list(dicw.items())
dicwi.sort(reverse=True, key=lambda x:x[1])

# print(havew)
#
# print(dichi)
# print(dicwi)

hmax = dichi[0][1]
wmax = dicwi[0][1]

for hs in dichi:
    if hs[1] != hmax:
        break
    for ws in dicwi:
        if ws[1] != wmax:
            break
        if ws[0] not in havew[hs[0]]:
            print(hmax+wmax)
            exit()
print(hmax+wmax-1)



### FIXED CODE ###

import bisect
horigin,worigin,m = map(int,input().split())
dich = {}
dicw = {}
 
havew = {}
for _ in range(m):
    h,w = map(int,input().split())
    if h in dich:
        dich[h] += 1
        havew[h].append(w)
    else:
        dich[h] = 1
        havew[h] = [w]
    if w in dicw:
        dicw[w] += 1
    else:
        dicw[w] = 1
 
dichi = list(dich.items())
dichi.sort(reverse=True, key=lambda x:x[1])
dicwi = list(dicw.items())
dicwi.sort(reverse=True, key=lambda x:x[1])
 
# print(havew)
#
# print(dichi)
# print(dicwi)
 
hmax = dichi[0][1]
wmax = dicwi[0][1]
 
for hs in dichi:
    if hs[1] != hmax:
        break
    wlis = sorted(havew[hs[0]])
    for ws in dicwi:
        if ws[1] != wmax:
            break
        idx = bisect.bisect_left(wlis, ws[0])
        if idx >= len(wlis):
            print(hmax+wmax)
            exit()
        if ws[0] != wlis[idx]:
            print(hmax+wmax)
            exit()
print(hmax+wmax-1)
### BUGGY CODE ###

import numpy as np

S = list(input().strip())
length = len(S)
op = np.asarray(S)
x = -1
count = 0
for i in op:
    y = -1
    x += 1
    group = ""
    for j in op:
        y += 1
        if x > y:
            continue
        group += j
        if int(group) % 2019 == 0:
            count += 1
print(count)

def checkValue():
    count = 0
    for i in range(length):
        group = ""
        for j in range(i, length):
            group += op[j]
            if int(group) % 2019 == 0:
                count += 1
    print(count)
#checkValue()
    


### FIXED CODE ###

import numpy as np
#S = list(input().strip())
#length = len(S)
#op = np.asarray(S)

def solution():
    S = input()
    N = len(S)
    num = [0] * 2019
    num[0] = 1
    c, ans, dgt = 0, 0, 1
    for i in range(N-1, -1, -1):
        c = (c + int(S[i]) * dgt) % 2019
        dgt *= 10
        dgt %= 2019
        ans += num[c]
        num[c] += 1
        
    print(ans)

solution()



def sample():
    x = -1
    count = 0
    for i in op:
        x += 1
        group = ""
        for j, name in enumerate(op, x):
            group += name
            if int(group) % 2019 == 0:
                count += 1
    print(count)

def checkValue():
    count = 0
    for i in range(length):
        group = ""
        for j in range(i, length):
            group += op[j]
            if int(group) % 2019 == 0:
                count += 1
    print(count)
#checkValue()
### BUGGY CODE ###

k,s = map(int,input().split())

a = min(k,s)

ans = 0
for x in range(a+1):
  for y in range(a+1):
    for z in range(a+1):
      if x + y + z == s:
        ans += 1
        break

print(ans)

### FIXED CODE ###

k,s = map(int,input().split())

a = min(k,s)

ans = 0
for x in range(a+1):
  for y in range(a+1):
    z = s - x - y
    if z <= k and z >= 0:
      ans += 1

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

import sys
import copy
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
s=input()
t=input()
dic={}
for i in range(len(s)):
    dic[s[i]]=1
for i in range(len(t)):
    if t[i] not in dic:
        print(-1)
        quit()

li=[{} for i in range(len(s)+1)] 

for i in range(len(s)):
    li[-2-i]=copy.deepcopy(li[-1-i])
    li[-2-i][s[-1-i]]=len(s)-i
# print(li)
ans=0
i=0
now=0
while i<len(t):
    if t[i] in li[now]:
        ans+=li[now][t[i]]-now
        now=li[now][t[i]]
        i+=1
        if now==len(s):
            now=0
    else:
        ans+=len(s)-now
        now=0
print(ans)

### FIXED CODE ###

import sys
import bisect
def input():
    return sys.stdin.readline()[:-1]
s=input()
t=input()
ss=s+s
al=[-1]*26
for i in range(len(ss)):
    tmp=ord(ss[i])-ord("a")
    if al[tmp]==-1:
        al[tmp]=[i]
    else:
        al[tmp].append(i)
ans=0
now=0
for i in range(len(t)):
    tmp=ord(t[i])-ord("a")
    if al[tmp]==-1:
        print(-1)
        exit()
    tmp2=bisect.bisect_left(al[tmp],now)
    # print(al[tmp],tmp2)
    ans+=al[tmp][tmp2]-now+1
    now=al[tmp][tmp2]+1
    if now>=len(s):
        now-=len(s)
    # print(ans,now)
print(ans)
### BUGGY CODE ###

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

result = 0

a, b = 0, 0
na, nb = 0, 0
for i in range(len(A)):
    if a+A[i] <= K:
        a += A[i]
        na += 1
    else:
        break
for i in range(len(B)):
    if b+B[i] <= K:
        b += B[i]
        nb += 1
    else:
        break

while A != [] and K >= A[0] or B != [] and K >= B[0]:
    if na > nb:
        result += 1
        na -= 1
        K -= A.pop(0)
    elif na < nb:
        result += 1
        nb -= 1
        K -= B.pop(0)
    elif na == nb:
        result += 1
        if A[0] <= B[0]:
            na -= 1
            K -= A.pop(0)
        else:
            nb -= 1
            K -= B.pop(0)


print(result)


### FIXED CODE ###

from itertools import accumulate

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

a_accum = [0] + list(accumulate(a))
b_accum = [0] + list(accumulate(b))

j = m
for i in range(n+1):
  while k < a_accum[i] + b_accum[j] and j >= 1:
    j -= 1
  if k >= a_accum[i] + b_accum[j] and ans < i + j:
    ans = i + j

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

n,k = map(int,input().split())
h = list(map(int,input().split()))
d = [0] + [float("inf")] * (n-1)
for i in range(1,n):
    s = max(0,i-k)
    for j in range(s,i):
        d[i]=min(d[i],d[j] + abs(h[i]-h[j]))
print(d[-1])

### FIXED CODE ###

n , k = map(int,input().split())
h = list(map(int,input().split()))
import numpy as np
h = np.array(h)
dp =np.zeros(n,dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = np.min(dp[s:i] + np.abs(h[s:i] - h[i]))
print(dp[-1])