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

n=int(input())
a=input()
for i in range(n):
  print(a.count(str(i+1),i,))





### FIXED CODE ###

n=int(input())
a=list(map(int,input().split(" ")))
t=[0 for i in range(n)]
for i in range(n-1):
  b=a[i]
  t[b-1]=t[b-1]+1
for j in range(n):
  print(t[j])
### BUGGY CODE ###

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

while H!=0 and W!=0:
    print('#'*W)
    for i in range(H-2):
        print('#'+'.'*(W-2)+'#')
    print('#'*W)
    print()        
    


### FIXED CODE ###

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

while not (H==0 and W==0):
    print('#'*W)
    for i in range(H-2):
        print('#'+'.'*(W-2)+'#')
    print('#'*W)
    print()
    H,W= map(int, input().split())
### BUGGY CODE ###

#!/usr/bin/env python3
n,k = [int(i) for i in input().split(" ")]
p = [int(i) for i in input().split(" ")]
kita = [0.5*(i+1) for i in range(max(p)+1)]
kitai = [kita[i] for i in p]
maxn = 0
for i in range(n-k+1):
    kt = 0
    for j in range(k):
        kt += kita[p[i+j]]
    if kt > maxn:
        maxn = kt
print(maxn)

### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
maxn = 0
sum = 0
for i in range(n-k+1):
	if i == 0:
		for j in range(k):
			sum += p[j]
		maxn = sum
	else:
		sum -= p[i-1]
		sum += p[i+k-1]
		if maxn < sum:
			maxn = sum
print(0.5*(maxn+k))
### BUGGY CODE ###

s = input()
d = [0 for _ in range(2019)]
for i in range(len(s)):
  r = int(s[i:])%2019
  d[r] += 1
ans = d[0]
for v in d:
  if v >= 2:
    ans += v*(v-1)//2
print(ans)


### FIXED CODE ###

s = list(map(int,input()))
d = [0 for _ in range(2019)]
r = 0
x = 1
for si in reversed(s):
  r += si*x
  r %= 2019
  d[r] += 1
  x *= 10
  x %= 2019
ans = d[0]
for v in d:
  if v >= 2:
    ans += v*(v-1)//2
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
s=1
for i in range(k):
    s*=a[i]
for i in range(n-k):
    ns=(s/a[i])*a[i+k]
    if ns>s:
        print("Yes")
    else:
        print("No")
    s=ns

### FIXED CODE ###

import numpy as np
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(0,n-k):
    if a[i]<a[i+k]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N,K = map(int,raw_input().split())
    A = sorted([int(raw_input()) for i in range(0,K)])

    if (N,K) == (0,0):
        break

    if A[0] == 0:
        flag = True
        A = A[1:]
        K -= 1
    else:
        flag = False

    ans = 0
    for i in range(K):
        for j in range(i+1,K):
            if j - i == A[j] - A[i]:
                ans = max(ans,A[j]-A[i])
            elif flag is True and j - i + 1 == A[j] - A[i]:
                ans = max(ans,A[j]-A[i])
            else:
                break

    print(ans+1)

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N,K = map(int,raw_input().split())
    A = sorted([int(raw_input()) for i in range(0,K)])

    if (N,K) == (0,0):
        break

    if A[0] == 0:
        flag = True
        A = A[1:]
        K -= 1
    else:
        flag = False

    ans = 0
    count = 0
    diff_list = []
    s = 0
    for i in range(1,K):
        if A[i] - A[i-1] == 2:
            diff_list.append(A[i-1] - A[s])
            s = i
            count = 0
        elif A[i] - A[i-1] > 2:
            diff_list.append(A[i-1] - A[s])
            diff_list.append(0)
            s = i
            count = 0
        else:
            count += 1
            ans = max(ans,count)
    else:
        diff_list.append(A[i] - A[s])

    if flag is True:
        ans = 0
        for i in range(1,len(diff_list)):
            ans = max(ans,diff_list[i] + diff_list[i-1] + 2)

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

a = int(input())
b = [int(i) for i in input().split()]
print((int)(sum(1 for x in range(a-2) for y in range(x+1,a-1) for z in range(y+1,a) if (b[x]<b[y]+b[z] and b[y]<b[x]+b[z] and b[z]<b[x]+b[y]))))



### FIXED CODE ###

a = int(input())
arr = [int(i) for i in input().split()]
arr.sort() 
count = 0
for i in range(0,a-2): 
    k = i + 2
    for j in range(i+1,a):
        while (k < a and arr[i] + arr[j] > arr[k]): 
            k += 1
        if(k>j): 
            count += k - j - 1
  
print(count)
### BUGGY CODE ###

s = input()
K = int(input())
substring = []
loong = False
for i in range(len(s)):
    for j in range(i, len(s)):
        if len(substring) <= 5:
            substring.append(s[i: j + 1])
            substring = list(set(substring))
            substring.sort()
            if len(substring) == 5:
                loong = True
        elif loong and substring[-1] > s[i: j + 1] and not s[i:j+1] in substring :
            substring[-1] = s[i: j + 1]
            substring.sort()

                
print(substring[K-1])

### FIXED CODE ###

s = input()
K = int(input())
substring = []
for i in range(len(s)):
    for j in range(i, i+5):
        substring.append(s[i: j + 1])
substring = list(set(substring))
substring.sort()                
print(substring[K-1])
### BUGGY CODE ###

N = int(input())
H = [int(a) for a in input().split()]

if (N == 1):
    print('Yes')
    exit()

for i in range(N-1):
    if max([H[i]-H[j] for j in range(i + 1, N)])>1:
        print('No')
        exit()
print('Yes')


### FIXED CODE ###

N = int(input())
H = [int(a) for a in input().split()]

if (N == 1):
    print('Yes')
    exit()
hmax=H[0]
for i in range(N - 1):  
    if (hmax - H[i + 1]) > 1:
        print('No')
        exit()
    hmax = max(hmax, H[i + 1])
print('Yes')
### BUGGY CODE ###

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

mod = int(1e9+7)
def mulmod(p,q,mod):
  return ((p%mod)*(q%mod))%mod

powerdict = {}
def powermod(p,n,mod):
  if (p,n) in powerdict:
    return powerdict[(p,n)]
  if n==0:
    powerdict[(p,n)] = 1
  if n==1:
    powerdict[(p,n)]=p%mod
  else:
    powerdict[(p,n)] = powermod(p,n//2,mod)**2 * (p**(n%2)) %mod
  return powerdict[(p,n)]

def dividemod(p,q,mod):
  # modは素数
  return mulmod(p, powermod(q,mod-2,mod), mod)

memo={}
for i, a in enumerate(A):
  if a in memo:
    L = memo[a]
    C = i - memo[a] -1
    R = len(A) - i-1
    break
  else:
    memo[a] = i
    
#print(L,C,R)
_LR = [1]*(n+2)
_LCR = [1] * (n+2) # _LCR[k] = (L+C+R)C(k)
_k = [1] * (n+2)

LR = [1]*(n+2) #LR[k] = (L+R)C(k)
LDR = [0]*(n+2)
LDDR = [0]*(n+2)

LCR = [0] * (n+2) # LCR[k] = _LCR[k] - LR[k]
LDCR = [0] * (n+2) #最後に*2を忘れないこと
LDCDR = [0] * (n+2)

for k in range(1,n+2):
  _LR[k] = _LR[k-1] * (L+R+1-k) %mod
  _LCR[k] = (_LCR[k-1] * (L+C+R+1-k))% mod
  _k[k] = _k[k-1] * powermod(k, mod-2, mod) %mod
  
  LR[k] = (_LR[k] * _k[k])%mod
  LDR[k] = LR[k-1]
  LDDR[k] = LDR[k-1]
  
  LCR[k] = (_LCR[k] * _k[k])%mod - LR[k]
  LDCR[k] = LCR[k-1]
  LDCDR[k] = LDCR[k-1]
  
  print((LR[k] + LDR[k] + LDDR[k] + LCR[k] + 2*LDCR[k] + LDCDR[k])%mod)
  
#print(LR)
#print(LDR)
#print(LDDR)
#print(_LCR)
#print(LCR)
#print(LDCR)
#print(LDCDR)

### FIXED CODE ###

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

mod = int(1e9+7)
def powermod(p,n,mod):
    #if n==0: return 1
    if n==1:
        return p%mod
    if n%2:
        return powermod(p,n//2,mod)**2 * p %mod
    else:
        return powermod(p,n//2,mod)**2 %mod


memo={}
for i, a in enumerate(A):
  if a in memo:
    L = memo[a]
    C = i - memo[a] -1
    R = len(A) - i-1
    break
  else:
    memo[a] = i
    
#print(L,C,R)
_LR = [0]*(n+3)
_LCR = [0] * (n+3) # _LCR[k] = (L+C+R)C(k)
_k = [0] * (n+3)
_LR[0] = _LCR[0] = _k[0] = 1

LR = [0]*(n+2) #LR[k] = (L+R)C(k)
LR[0] = 1
#LDR = [0]*(n+2)
#LDDR = [0]*(n+2)

LCR = [0] * (n+2) # LCR[k] = _LCR[k] - LR[k]
#LDCR = [0] * (n+2) #最後に*2を忘れないこと
#LDCDR = [0] * (n+2)

for k in range(1,n+2):
  _LR[k] = (_LR[k-1] * (L+R+1-k)) %mod
  _LCR[k] = (_LCR[k-1] * (L+C+R+1-k))% mod
  _k[k] = (_k[k-1] * powermod(k, mod-2, mod)) %mod
  
  LR[k] = (_LR[k] * _k[k])%mod
#  LDR[k] = LR[k-1]
#  LDDR[k] = LDR[k-1]
  
  LCR[k] = (_LCR[k] * _k[k])%mod - LR[k]
#  LDCR[k] = LCR[k-1]
#  LDCDR[k] = LDCR[k-1]
  #print(LR, LCR)
  print((LR[k] + LR[k-1] + LR[k-2] + LCR[k] + 2*LCR[k-1] + LCR[k-2])%mod)
  
#print(LR)
#print(LDR)
#print(LDDR)
#print(_LCR)
#print(LCR)
#print(LDCR)
#print(LDCDR)
### BUGGY CODE ###

S = list(input())
last_size = 0
size = len(S)
to_remove = []
while True:
    i = 0
    while i < len(S)-1:
        if S[i] != S[i+1]:
            to_remove.append(i)
            to_remove.append(i+1)
            i+=1
        i+=1
    to_remove.reverse()
    for t in to_remove:
        del S[t]
    to_remove = []
    if last_size == len(S) or len(S) == 0:
        break
    else:
        last_size = len(S)
print(size-len(S))

### FIXED CODE ###

s=input()
o=s.count('1')
z=s.count('0')
print(2*min(o,z))
### BUGGY CODE ###

n, k = map(int, input().split())
an = list(map(int, input().split()))
for i in range(n):
    an[i] -= 1
    
import math
dv = []
dv.append(an)
K = k
N = n
for _ in range(1, int(math.log2(K)) + 1):
    l = [0] * N
    dv.append(l)

for k in range(1, int(math.log2(K)) + 1):
    for n in range(N):
        dv[k][n] = dv[k - 1][dv[k - 1][n]]
        
# N 回目を 2 ^ t で表すためにビット演算を用いる
# a : dv の何行目を用いるかを格納
a = []
for i in range(int(math.log2(K)) + 1):
    if K >> i & 1:
        a.append(i)
        
now = 0
for i in a:
    now = dv[i][now]
        
print(now + 1)


### FIXED CODE ###

n, k = map(int, input().split())
an = list(map(int, input().split()))
for i in range(n):
    an[i] -= 1
    
import math
dv = []
dv.append(an)
K = k
N = n
for _ in range(1, int(math.log2(K)) + 1):
    l = [0] * N
    dv.append(l)

for k in range(1, int(math.log2(K)) + 1):
    for n in range(N):
        dv[k][n] = dv[k - 1][dv[k - 1][n]]
        
# N 回目を 2 ^ t で表すためにビット演算を用いる
# a : dv の何行目を用いるかを格納
a = []
for i in range(int(math.log2(K)) + 1):
    if K >> i & 1:
        a.append(i)
        
now = 0
for i in a:
    now = dv[i][now]
        
print(now + 1)
### BUGGY CODE ###

# coding: utf-8
# Your code here!

import math
import sys

n,k = map(int,input().split())
al = list(map(int,input().split()))
fl = list(map(int,input().split()))

al.sort()
fl.sort(reverse=True)

ub = max([a*f for a,f in zip(al, fl)])
lb = 0

while True:
    if ub == lb:
        print(lb)
        sys.exit()
    p = 0
    t = (ub + lb) // 2
    for a, f in zip(al, fl):
        p += max(a - t // f, 0)
    if p <= k:
        ub = t
    else:
        lb = t + 1

### FIXED CODE ###

# coding: utf-8
# Your code here!

import math
import sys

n,k = map(int,input().split())
al = list(map(int,input().split()))
fl = list(map(int,input().split()))

al.sort()
fl.sort(reverse=True)

ub = max([a*f for a,f in zip(al, fl)])
lb = 0

while True:
    if ub == lb:
        print(lb)
        sys.exit()
    p = 0
    t = (ub + lb) // 2
    for a, f in zip(al, fl):
        p += max(a - t // f, 0)
    if p <= k:
        ub = t
    else:
        lb = t + 1
### BUGGY CODE ###

import sys
from scipy.sparse.csgraph import floyd_warshall
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N = int(readline())
INF = float('inf')
graph = [[INF] * (N + 1) for _ in range(N + 1)]
for i in range(N + 1):
    graph[i][i] = 0

for _ in range(N - 1):
    a, b, c = map(int, readline().split())
    graph[a][b] = c
    graph[b][a] = c

distance = floyd_warshall(graph, directed=False)

Q, K = map(int, readline().split())
xy = map(int, read().split())
for x, y in zip(xy, xy):
    print(int(distance[x][K] + distance[K][y]))

### FIXED CODE ###

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 6)


def main():
    N = int(readline())
    edge = [[] for _ in range(N + 1)]

    for _ in range(N - 1):
        a, b, c = map(int, readline().split())
        edge[a].append((b, c))
        edge[b].append((a, c))

    Q, K = map(int, readline().split())

    distance = [None] * (N + 1)


    def measure_distance(v, d):
        distance[v] = d
        for vv, dd in edge[v]:
            if distance[vv] is not None:
                continue
            measure_distance(vv, d + dd)


    measure_distance(K, 0)

    xy = map(int, read().split())
    for x, y in zip(xy, xy):
        print(distance[x] + distance[y])


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

N = input()
n = int(N)
a = [input() for i in range(n)]
b = []
for i in range(n):
  if (a[i]in b) == False:
    b.append(a[i])
  
print(len(b))

### FIXED CODE ###

N = input()
n = int(N)
a = {input() for i in range(n)}  
print(len(a))
### BUGGY CODE ###

import sys
input=sys.stdin.readline
arr=[]
n,w=map(int,input().split())
for _ in range(n):
	arr.append(tuple(map(int,input().split())))
dp=[-1]*((n+1)*(w+1))
def f(pos,W):
	if(pos==n):
		return 0
	if dp[pos*(w+1)+W]!=-1:
		return dp[pos*(w+1)+W]
	res=f(pos+1,W)
	if(arr[pos][0]<=W):
		res=max(res,f(pos+1,W-arr[pos][0])+arr[pos][1])
	dp[pos*(w+1)+W]=res
	return res
print(f(0,w))

### FIXED CODE ###

def main():
    n, w = tuple([int(e) for e in input().split()])
    items = []
    for i in range(n):
        items.append(tuple([int(e) for e in input().split()]))
    items.sort(key=lambda x: x[0])
    
    t = [[0] * (n + 1) for _ in range(w + 1)]
    for i in range(1, w + 1):
        for j in range(1, n + 1):
            if i - items[j - 1][0] >= 0:
                t[i][j] = t[i - items[j - 1][0]][j - 1] + items[j - 1][1]
            t[i][j] = max(t[i][j], t[i][j - 1], t[i - 1][j], t[i - 1][j - 1])
    print(t[w][n])
    return 0

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
dp = [[1] + [0]*K for _ in range(N+1)]
dpm = [[1] + [0]*K for _ in range(N+1)]
dp2 = [[1] + [0]*K for _ in range(N+1)]
dpm2 = [[1] + [0]*K for _ in range(N+1)]
for i, a in enumerate(A):
    for j in range(K-1, 0, -1):
        if j - a >= 0:
            dp[i+1][j] = dp[i][j] + dp[i][j-a]
    dpm[i+1][-1] = dp[i+1][-1]
    for j in range(K-1, -1, -1):
        dpm[i+1][j] = dp[i+1][j] + dpm[i+1][j+1]

#print(dp)
#print(dpm)
r = 0
for i, a in enumerate(A[::-1]):
    f = False
    for j in range(K-1, 0, -1):
        if j - a >= 0:
            dp2[i+1][j] = dp2[i][j] + dp2[i][j-a]
#    print(i, N-i-1, a)
    for j in range(K-1, -1, -1):
        # 後ろiこの合計がjのもの
#        print("bb", i, j, K-j-a, K-j)
        if dp2[i][j] > 0:
            # K-j > x >= K-j-a
            if dpm[N-i-1][max(0, K-j-a)] > dpm[N-i-1][K-j]:
                break
    else:
        r += 1
#        print("aa", i, N-i-1)
print(r)

#    print(N-i, i+1)
#    if mx[N-i] + a + mx2[i+1] < K: 
#        r += 1


### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
#dpm = [+1) for _ in range(N+1)]
dpm = [0]*(N+1)
dpm[0] = 1<<(K-1)
for i, a in enumerate(A):
    dpm[i+1] = dpm[i] | (dpm[i] >> a)

r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
    for j in range(a):
        if dp2 & dpm[N-i-1]:
            break
        dpm[N-i-1] >>= 1
    else:
        r += 1
    dp2 |= dp2<<a
    dp2 &= (1<<K)-1
print(r)
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

# スタック最大数をセット
sys.setrecursionlimit(10**6)

h, w = map(int, input().split())
a = [[j == '#' for j in input()] for _ in range(h)]

queue = deque([(i, j, 0) for i in range(h)
               for j in range(w) if a[i][j]])

ans = 0

dx = (1, 0, 0, -1)
dy = (0, 1, -1, 0)


def bfs(y, x, cnt):

    # if (y < 0 or h <= y or x < 0 or w <= x or not a[y][x]):
    #    return
    #print(y, x, cnt)
    for ddx, ddy in zip(dx, dy):
        #print(ddx, ddy)
        if (0 <= y+ddy < h and 0 <= x+ddx < w and not a[y+ddy][x+ddx]):
            a[y+ddy][x+ddx] = True
            queue.append((y + ddy, x+ddx, cnt+1))


while (len(queue) > 0):
    l = queue.popleft()
    # print(l)
    ans = max(ans, l[2])
    bfs(l[0], l[1], l[2])
    # print(queue)
print(ans)


### FIXED CODE ###

from collections import deque
import copy
 
def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
 
 
    # スタート地点をqueueに追加
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])
 
    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
 
        if nque:
            que = copy.copy(nque)
        else:
            break
 
    print(count - 1)
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
data = input().split()

round = int(data[0])
cnt_house = int(data[1])

distance = input().split()

min_dist = None

for start in range(cnt_house):
  move_dist = 0
    
  for i in range(cnt_house - 1):
    if start + i == cnt_house - 1:
      move_dist += round - int(distance[start + i]) + int(distance[start + i - cnt_house + 1])
    elif start + i < cnt_house - 1:
      move_dist += int(distance[start + i + 1]) - int(distance[start + i])
    else:
      move_dist += int(distance[start + i - cnt_house + 1]) - int(distance[start + i - cnt_house])
  
  if min_dist is None or min_dist > move_dist:
    min_dist = move_dist

print(min_dist)

### FIXED CODE ###

# -*- coding: utf-8 -*-
data = input().split()

round = int(data[0])
cnt_house = int(data[1])

distance = input().split()

min_dist = None

for start in range(cnt_house):
  if start == 0:
    move_dist = int(distance[cnt_house - 1]) - int(distance[start])
  else:
    move_dist = (round - int(distance[start])) + int(distance[start - 1])
  
  if min_dist is None or min_dist > move_dist:
    min_dist = move_dist

print(min_dist)
### BUGGY CODE ###

MOD = 1000000007

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

ans = 0
for k in range(60):
    cnt1 = 0
    for x in a:
        if ((x>>k)&1) == 1:
            cnt1 += 1
    ans += cnt1*(n-cnt1)*(1<<k)
print(ans%MOD)

### FIXED CODE ###

MOD = 1000000007

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

ans = 0
for k in range(60):
    mask = 1<<k
    cnt1 = sum(1 for x in a if x&mask != 0)
    ans += cnt1*(n-cnt1)*(1<<k)
print(ans%MOD)
### BUGGY CODE ###

import sys

INF = float('inf')

L, N = map(int, input().split())
Xs = [0] + [int(input()) for _ in range(N)] + [L]

if N == 1:
    print(max(Xs[1], L - Xs[1]))
    sys.exit()

dp = [[[-INF] * (2) for B in range(N+1)] for A in range(N+1)]
dp[1][N][0] = 0
dp[1][N][1] = 0
for A in range(1, N+1):
    for B in reversed(range(A, N+1)):
        # C=0 ccw
        C = 0
        if B > 1:  # ccw
            dp[A][B-1][0] = max(dp[A][B-1][0], dp[A][B][C] + Xs[B+1] - Xs[B])
        if A < N:  # cw
            dp[A+1][B][1] = max(dp[A+1][B][1], dp[A][B][C] + (L - Xs[B+1]) + Xs[A])
        # C=1 cw
        C = 1
        if B > 1:  # ccw
            dp[A][B-1][0] = max(dp[A][B-1][0], dp[A][B][C] + Xs[A-1] + (L - Xs[B]))
        if A < N:  # cw
            dp[A+1][B][1] = max(dp[A+1][B][1], dp[A][B][C] + Xs[A] - Xs[A-1])

ans = 0
for A in range(N+1):
    for B in range(N+1):
        for C in range(2):
            ans = max(ans, dp[A][B][C])
print(ans)


### FIXED CODE ###

from itertools import accumulate

def getRangeSum(accXs, iFr, iTo):
    return accXs[iTo+1] - accXs[iFr]

def getAns(accXs, accRevXs, Xs, revXs):
    ans = 0
    for i in range(N):
        num = (N-i)//2
        dist = 2 * getRangeSum(accXs, i, i + num-1)
        dist += 2 * getRangeSum(accRevXs, 0, num-1)
        if (N-i)%2 == 0:
            dist -= revXs[num-1]
        else:
            dist += Xs[i + num]
        ans = max(ans, dist)
    return ans

L, N = map(int, input().split())
Xs = [int(input()) for _ in range(N)]

revXs = [L-X for X in reversed(Xs)]
accXs = [0] + list(accumulate(Xs))
accRevXs = [0] + list(accumulate(revXs))

print(max(getAns(accXs, accRevXs, Xs, revXs), getAns(accRevXs, accXs, revXs, Xs)))
### BUGGY CODE ###

import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    A, B, N = map(int, input().split())

    def func(x):
        res = (A * x) // B - A * (x // B)
        return res

    M = 0
    for i in range(N, max(0, N - 10 ** 7), -1):
        tmp = func(i)
        if tmp > M:
            M = tmp

    print(M)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    A, B, N = map(int, input().split())

    def func(x):
        res = (A * x) // B - A * (x // B)
        return res

    print(func(min(N, B - 1)))


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

from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
ans = 0
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k]) 
    
    return result

x = 0

for k in ln2:
    if k > 1:
        x += cmb(k, 2)
    
print(x)        

### FIXED CODE ###

N = int(input())
S = [''.join(sorted(list(input()))) for _ in range(N)]
 
from collections import Counter
a=Counter(S)
 
ans = 0
 
for i in a.values():
    if i>1:
        ans += i*(i-1)/2
 
print(int(ans))
### BUGGY CODE ###

import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
 
n = ni()
a = [int(ns()) for i in range(n)]
pushed = []

next_b = 1
count = 0
for _ in range(0,n):
  if next_b == 2:
    break
  count += 1
  next_b = a[next_b-1]
  if next_b in pushed:
    count = -1
    break
  pushed.append(next_b)
  
if count == n:
  count = -1
print(count)
  

### FIXED CODE ###

import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
 
n = ni()
a = [int(ns()) for i in range(n)]
pushed = {}

next_b = 1
count = 0
for _ in range(0,n):
  if next_b == 2:
    break
  count += 1
  next_b = a[next_b-1]
  if pushed.get(next_b) != None:
    count = -1
    break
  pushed[next_b] = True
  
if count == n:
  count = -1
print(count)