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

import sys
import copy

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	SS = IS()
	ans = 0
	for l in range(N-1):
		i = 1
		j = 0
		S = copy.copy(SS[l:])
		A = [0]*len(S)
		while (i < len(S)):
			while (i+j < len(S) and S[j] == S[i+j] and j < i):
				j+=1
			A[i] = j
			if (j == 0):
				i+=1
				continue
			i += 1
			j = 0
		ans = max(max(A),ans)
	print(ans)

main()

### FIXED CODE ###

import sys
import copy

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	SS = IS()
	ans = 0
	for l in range(N-1):
		i = 1
		j = 0
		S = copy.copy(SS[l:])
		A = [0]*len(S)
		while (i < len(S)):
			while (i+j < len(S) and S[j] == S[i+j]):
				j+=1
			A[i] = j
			if (j == 0):
				i+=1
				continue
			k = 1
			while (i+k < len(S) and k+A[k] < j):
				A[i+k] = A[k]
				k+=1
			i += k
			j -= k
		for m in range(len(S)):
			ans = max(ans, min(m, A[m]))
	print(ans)

main()
### BUGGY CODE ###

N = int(input())

import fractions
#import math
from functools import reduce
def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)
  #return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

for h in range(1, 3501):
    for n in range(h, 3501):
        l = lcm_list([N, h, n])
        x = 4*(l//N)-l//h-l//n
        if x <= 0:
            continue
        else:
            if l%x == 0:
                print(h, n, l//x)
                exit()


### FIXED CODE ###

N = int(input())

for h in range(1, 3501):
    for n in range(h, 3501):
        x = 4*h*n-N*n-N*h
        if x <= 0:
            continue
        else:
            if (N*h*n)%x == 0:
                print(h, n, (N*h*n)//x)
                exit()
### BUGGY CODE ###

import math

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

ANSX=ANSY=0

for i in range(N-1):
    for j in range(i+1,N):
        ANSX+=math.cos((T[i]+T[j])*math.pi/L)*(N-(j-i+1))
        ANSY+=math.sin((T[i]+T[j])*math.pi/L)*(N-(j-i+1))

        ANSX+=math.cos((T[i]+T[j])*math.pi/L+math.pi)*(j-i-1)
        ANSY+=math.sin((T[i]+T[j])*math.pi/L+math.pi)*(j-i-1)

print(ANSX/(N*(N-1)*(N-2)//6),ANSY/(N*(N-1)*(N-2)//6))

### FIXED CODE ###

import math

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

ANSX=ANSY=0

for i in range(N-1):
    for j in range(i+1,N):
        ANSX+=math.cos((T[i]+T[j])*math.pi/L)*(N-(j-i+1))
        ANSY+=math.sin((T[i]+T[j])*math.pi/L)*(N-(j-i+1))

        ANSX+=math.cos((T[i]+T[j])*math.pi/L+math.pi)*(j-i-1)
        ANSY+=math.sin((T[i]+T[j])*math.pi/L+math.pi)*(j-i-1)

print(ANSX/(N*(N-1)*(N-2)//6),ANSY/(N*(N-1)*(N-2)//6))
### BUGGY CODE ###


n, w = map(int, raw_input().split())
oo = w + 1
items = []
v = 0
for _ in range(n):
    wi, vi = map(int, raw_input().split())
    items.append((wi, vi))
    v += vi

dp = [[oo] * (v + 1) for _ in range(n + 1)]
for i in xrange(n + 1):
    dp[i][0] = 0
for i in xrange(1, n + 1):
    wi, vi = items[i - 1]
    for j in range(1, v + 1):
        dp[i][j] = dp[i - 1][j]
        if j >= vi:
            dp[i][j] = min(dp[i][j], wi + dp[i - 1][j - vi])
for i in xrange(v, -1, -1):
    if dp[n][i] <= w:
        print(i)
        break


### FIXED CODE ###


n, w = map(int, raw_input().split())
oo = w + 1
items = []
v = 0
for _ in range(n):
    wi, vi = map(int, raw_input().split())
    items.append((wi, vi))
    v += vi

dp = [[oo] * (v + 1) for _ in range(n + 1)]
for i in xrange(n + 1):
    dp[i][0] = 0
for i in xrange(1, n + 1):
    wi, vi = items[i - 1]

    for j in range(1, vi):
        dp[i][j] = dp[i - 1][j]

    for j in range(vi, v + 1):
        if j >= vi:
            dp[i][j] = min(dp[i - 1][j], wi + dp[i - 1][j - vi])
for i in xrange(v, -1, -1):
    if dp[n][i] <= w:
        print(i)
        break
### BUGGY CODE ###

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

D = INT()
C = LIST()
S = [[]] * D
for i in range(D):
    S[i]  = LIST()
T = [t-1 for t in LIST(D)]
M = 26

def check(T):
    last = [0] * M
    res = 0
    for i, t in enumerate(T):
        res += S[i][t]
        for j in range(M):
            last[j] += 1
        last[t] = 0
        for j in range(M):
            res -= C[j] * last[j]
    return res

Q = INT()
for i in range(Q):
    d, q = MAP()
    d -= 1; q -= 1

    T[d] = q
    res = check(T)
    print(res)


### FIXED CODE ###

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

D = INT()
C = LIST()
S = [[]] * D
for i in range(D):
    S[i]  = LIST()
T = [t-1 for t in LIST(D)]
M = 26

last = list2d(M, D+2, 0)
def check(T):
    score = 0
    for i, t in enumerate(T):
        score += S[i][t]
        for j in range(M):
            last[j][i+1] = last[j][i] + 1
        last[t][i+1] = 0
        for j in range(M):
            score -= C[j] * last[j][i+1]
    return score

def change(day, a, b):
    nxtday = last[a].index(0, day+2)
    w = nxtday - day - 1
    h = last[a][day] + 1
    a_change = C[a] * h * w
    for d in range(day, nxtday-1):
        last[a][d+1] = last[a][d] + 1

    nxtday = last[b].index(0, day+2)
    w = nxtday - day - 1
    h = last[b][day] + 1
    b_change = C[b] * h * w
    last[b][day+1] = 0
    for d in range(day+1, nxtday-1):
        last[b][d+1] = last[b][d] + 1

    res = -a_change + b_change - S[day][a] + S[day][b]
    return res

score = check(T)
Q = INT()
for i in range(Q):
    d, q = MAP()
    d -= 1; q -= 1

    prev = T[d]
    nxt = q
    score += change(d, prev, nxt)
    print(score)
    T[d] = q
### BUGGY CODE ###

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

a_sum = []
x = 0

for i in range(N):
    x += a[i]
    a_sum.append(x)
    
ans = []

for i in range(N-1):
    ans.append(abs(sum(a)-a_sum[i]-a_sum[i]))
    
print(min(ans))

### FIXED CODE ###

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

a_sum = [0]*N
x = 0

for i in range(N):
    x += a[i]
    a_sum[i] = x
    
ans = 10**18+1
sum_a = sum(a)

for i in range(N-1):
    ans = min(ans,abs(sum_a-2*a_sum[i]))
    
print(ans)
### BUGGY CODE ###

n = int(input())
s = input()
S=str(s)
A = set([])
ans = 0
for i in range(n-2):
  for j in range(i+1, n-1):

    x = int(S[i])
    y = int(S[j])

    if not((10*x+y) in A):
      A.add(10*x+y)
      ans += len(set(list(S[j+1::])))
print(ans)

### FIXED CODE ###

def my_index2(l, x, default=-1):
    return l.index(x) if x in l else default
n = int(input())
S = list(input())
for i in range(n):
  S[i] = int(S[i])
ans = 0
for i in range(10):
  a = my_index2(S[0:n-2],i)
  if a != -1:
    for j in range(10):
      b = my_index2(S[a+1:n-1], j) 
      if b!=-1:
        for k in range(10):
          c = my_index2(S[a+1+b+1::], k)
          if c!= -1:
            ans+=1
print(ans)
### BUGGY CODE ###

#created by  nit1n
N, S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1
for i in  range(N) :
    for j in range (S+1) :
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] = dp[i+1][j]%mod
        if j +A[i] <= S :
            dp[i+1][j+A[i]] += dp[i][j] 
            dp[i+1][j+A[i]] %= mod


print(dp[N][S])

            
            


### FIXED CODE ###

#created by  nit1n
N, S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1
for i in  range(N) :
    for j in range (S+1) :
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] = dp[i+1][j]%mod
        if j +A[i] <= S :
            dp[i+1][j+A[i]] += dp[i][j] 
            dp[i+1][j+A[i]] %= mod


print(dp[N][S])
### BUGGY CODE ###

alpha = 'abcdefghijklmnopqrstuvwxyz'
alp_num = dict(zip(alpha,range(26)))
num_alp = dict(zip(range(26),alpha))
alp_num[' ']=' ' ; num_alp[' ']=' ' ; alp_num['.']='.' ; num_alp['.']='.'
while True:
	try:
		cipher = raw_input()
		while True:
			numcipher = [alp_num[val] for val in cipher]
			cipher = ''
			for val in numcipher: cipher += str(num_alp[val])
			if 'the'in cipher or 'this'in cipher or 'that'in cipher:
				print cipher ; break
			else: continue
	except: break

### FIXED CODE ###

alpha = 'abcdefghijklmnopqrstuvwxyz'
alp_num = dict(zip(alpha,range(26)))
num_alp = dict(zip(range(26),alpha))
alp_num[' ']=' ' ; num_alp[' ']=' ' ; alp_num['.']='.' ; num_alp['.']='.'
while True:
	try:
		cipher = raw_input()
		numcipher = [alp_num[val] for val in cipher]
		while True:
			cipher = ''
			for val in numcipher: cipher += str(num_alp[val])
			if 'the'in cipher or 'this'in cipher or 'that'in cipher:
				print cipher; break
			else: 
				numcipher2 = []
				for val in numcipher:
					if val == ' ': numcipher2.append(' ')
					elif val == '.': numcipher2.append('.')
					elif val == 25: numcipher2.append(0)
					else: numcipher2.append(val+1)
				numcipher = numcipher2
				continue
	except: break
### BUGGY CODE ###

a,b,c=map(int,input().split())
ab,bc,ca=abs(a-b),abs(b-c),abs(c-a)
ans=0
while ab%2==0 and bc%2==0 and ca%2==0:
  ab//=2
  bc//=2
  ca//=2
  ans+=1
print(ans)


### FIXED CODE ###

a,b,c = map(int,input().split())
ans = 0

if a == b and a == c and a%2 == 0:
  print("-1")
elif a == b and a == c and a%2 == 0:
  print(0)
else:
  while a%2 == 0 and b%2 == 0 and c%2 == 0:
    ans += 1
    aa = b/2 + c/2
    bb = a/2 + c/2
    cc = a/2 + b/2
    a = aa
    b = bb
    c = cc
  print(ans)
### BUGGY CODE ###

def main():
    n,k = map(int,input().split())
    p = list(map(int,input().split()))
    c = list(map(int,input().split()))

    ans=-10**18
    for i in range(n):
        start,count=i,1
        val=c[start]
        while p[start]-1 != i:
            start = p[start]-1
            count += 1
            val += c[start]
        start = i
        if val > 0:
            a = (k//count-1)*val
            ans=max(a,ans)
            num=count+k%count
        else:
            a=0
            num=min(k,count)
        for _ in range(num):
            a += c[start]
            start=p[start]-1
            ans=max(a,ans)
    print(ans)
if __name__ == "__main__":
    main()
    

### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))

ans=-10**18
for i in range(n):
    start,count=i,1
    val=c[start]
    while p[start]-1 != i:
        start = p[start]-1
        count += 1
        val += c[start]
    start = i
    if val > 0:
        a = (k//count-1)*val
        ans=max(a,ans)
        num=count+k%count
    else:
        a=0
        num=min(k,count)
    for _ in range(num):
        a += c[start]
        start=p[start]-1
        ans=max(a,ans)
print(ans)
### BUGGY CODE ###

R, G, B, N = map(int,input().split())
ans = 0

for r in range(1+N//R):
    for g in range(1+N//G):
        if N-(R*r+G*g)>=0 and (N-(R*r+G*g))%B==0:
           ans += 1

print(ans)

### FIXED CODE ###

R, G, B, N = map(int,input().split())
ans = 0

for r in range(1+N//R):
    for g in range(1+N//G):
        if N-(R*r+G*g)>=0 and (N-(R*r+G*g))%B==0:
           ans += 1

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

from collections import Counter
A = input()
n = len(A)
c = Counter(A)

U = n
fact = [0]*(U+1)
fact[0] = 1
for i in range(1, U+1):
    fact[i] = fact[i-1]*i


def nCr(n, r):
    if r < 0 or n < r:
        return 0
    return fact[n]//fact[r]//fact[n-r]


ans = 1
ans += nCr(n, 2)
for v in c.values():
    ans -= nCr(v, 2)
print(ans)


### FIXED CODE ###

from collections import Counter
A = input()
n = len(A)
c = Counter(A)

ans = 1
ans += n*(n-1)//2
for v in c.values():
    ans -= v*(v-1)//2
print(ans)
### BUGGY CODE ###

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

for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                cnt += 1

print(cnt)


### FIXED CODE ###

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

for x in range(k+1):
    for y in range(k+1):
        if s-k <= x+y <= s:
            cnt += 1

print(cnt)
### BUGGY CODE ###

from math import gcd
from functools import reduce
from collections import Counter
from itertools import chain


# 素因数分解
def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n


def solve(A):
    d = reduce(gcd, A)
    if d != 1:
        return 'not coprime'

    A = [a for a in A if a != 1]

    if len(set(A)) < len(A):
        return 'setwise coprime'

    c = Counter(chain.from_iterable(set(prime_factors(a)) for a in A))
    if c and max(c.values()) > 1:
        return 'setwise coprime'
    else:
        return 'pairwise coprime'


if __name__ == '__main__':
    N = int(input())
    A = list(map(int,input().split()))

    print(solve(A))


### FIXED CODE ###

from math import gcd
from functools import reduce
from collections import Counter
from itertools import chain


# 素因数分解
def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            while n % i == 0:
                n //= i
            yield i
    if n > 1:
        yield n


def solve(A):
    d = reduce(gcd, A)
    if d != 1:
        return 'not coprime'

    A.sort()

    s = set()
    for a in A:
        for p in prime_factors(a):
            if p in s:
                return 'setwise coprime'
            else:
                s.add(p)

    return 'pairwise coprime'


if __name__ == '__main__':
    N = int(input())
    A = list(map(int,input().split()))

    print(solve(A))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
s = [0]*n

for i in range(n):
	s[i] = a.count(i+1)

for i in range(n):
  	print(s[i])

### FIXED CODE ###

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

c = [0]*n
for i in a:
	c[i-1] += 1

for i in range(n):
	print(c[i])
### BUGGY CODE ###

import functools
import operator

N = int(input())
A = list(map(int, input().split()))
INF = 10 ** 18

prod = functools.partial(functools.reduce, operator.mul)

if prod(A) > INF:
    print(-1)
else:
    print(prod(A))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
INF = 10 ** 18

if 0 in A:
    print(0)
    exit()

A.sort(reverse=True)
ans = A[0]

for i in range(1, N):
    if A[i] > INF:
        print(-1)
        exit()
    if A[i] == 1:
        break
    ans = ans * A[i]
    if ans > INF:
        print(-1)
        exit()

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

import sys
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

for val in range(A, B+1):
    if val<=A+K-1 or B-K+1<=val:
        print(val)


### FIXED CODE ###

def main():
    import sys
    def input(): return sys.stdin.readline()[:-1]
    pl = lambda x: print(*x, sep='\n')

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

    for val in range(A, B+1):
        if val<=A+K-1 or B-K+1<=val:
            print(val)

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

a,b,c,k=(int(n) for n in input().split())
count = 0
sum = 0
for i in range(a):
    if count == k:
        break
    else:
        count += 1
        sum += 1
for i in range(b):
    if count == k:
        break
    else:
        count += 1
for i in range(c):
    if count == k:
        break
    else:
        count += 1
        sum -= 1
print(sum)

### FIXED CODE ###

a,b,c,k=(int(x) for x in input().split())
if a+b >= k:
  print(min(k,a))
else:
  print(a-k+a+b)
### BUGGY CODE ###

# input
N = int(input())
A = [int(input()) for _ in range(N)]

reachable = []
i = 0
count = 1

while A[i] != 2:
    if A[i] in reachable:
        print(-1)
        exit()
    else:
        reachable.append(A[i])
        i = A[i] - 1
        count += 1

print(count)

### FIXED CODE ###

# input
N = int(input())
A = [int(input()) for _ in range(N)]

b = []
count = 0
i = 0

while count < N:
    b.append(A[i])
    i = A[i] - 1
    count += 1

if 2 in b:
    for i in range(N):
        if b[i] == 2:
            print(i + 1)
            break
else:
    print(-1)
### BUGGY CODE ###

n = int(input())
a= [int(i) for i in input().split()]

for i in range(len(a)):
    a[i]-=i+1

import math
b=math.floor(sum(a)/n)


def p(b,k):
  s=0
  for i in a:
      s+=abs(i-b)
  t=0
  for i in a:
      t+=abs(i-b-1) 
  if s>t:
    if k==-1:
      print(t)
    else:
      return p(b+1,1)
  else:
    if k==1:
      print(s)
    else:
      return p(b-1,-1)
  
p(b,0)



### FIXED CODE ###

n = int(input())
a= [int(i) for i in input().split()]

for i in range(len(a)):
    a[i]-=i+1

aa=sorted(a)
if n%2==0:
  b=(aa[int(n/2-1)]+aa[int(n/2)])/2
else:
  b=aa[int((n-1)/2)]

s=0
for i in aa:
  s+=abs(i-b)
print(int(s))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
sys.setrecursionlimit(10**7)

n=int(input())
L=list(map(int,input().split()))
A = L.count(1)
B = L.count(2)
C = L.count(3)
dp=[[[-0.1] * (n+1) for i in range(n+1)] for i in range(n+1)]

def rec (a,b,c):
  if not (a >= 0 and b >= 0 and c >= 0):
    return 0.0
  if a == b == c == 0:
    return 0.0
  if dp[a][b][c] >= 0.0:
    return dp[a][b][c]
  result = n
  result += rec(a-1,b,c) * a
  result += rec(a+1,b-1,c) * b
  result += rec(a,b+1,c-1) * c
  dp[a][b][c] = result / (a+b+c)
  return dp[a][b][c]

print(rec(A,B,C))

### FIXED CODE ###

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

S = [0] * 3
for a in A:
  S[a-1] += 1
I, J, K = S

dp = [[[0.0] * (N+1) for j in range(N+1)] for i in range(N+1)]

for k in range(S[2] + 1):
  for j in range(S[1] + S[2] - k + 1):
    for i in range(S[0] + S[1] + S[2] - j - k + 1):
      if i == j == k == 0: continue
      dp[i][j][k] = (i * (dp[i-1][j][k] if i > 0 else 0) + j * (dp[i+1][j-1][k] if j > 0 else 0) + k * (dp[i][j+1][k-1] if k > 0 else 0) + N) / (i + j + k)

print(dp[I][J][K])
### BUGGY CODE ###

l=[2658,3]
d=[2,4,5]
d_bar=[]
for m in range(10):
    if m not in d:
        d_bar.append(m) 
d_bar.sort()
n=[int(k) for k in str(l[0])]

for i in range(len(n)):
    dig1=''
    dig2=0
    for j in range(l[1]):
        p=dig1.join(str(d_bar[j]))
        if int(p)>l[0]:
          dig2=dig2+int(dig1)*l[1]**(l[0]-i)
          break
        dig1=p     
dig2=dig2+1
r=int(dig1)
q=int(dig1)
R=[]
while q!=0 or q!=1:
    q=q/l[1]
    r=q%l[1]
    R.insert(0,r)
s=''
for t in range(len(R)):
    s=s+str(R[t])
print(int(s))




### FIXED CODE ###

l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))
### BUGGY CODE ###

a,b,k=input().split()
a,b,k=int(a),int(b),int(k)

for i in range(b-a+1):
    if i<k:
        print(a+i)
    elif i>b-a-k:
        print(a+i)


### FIXED CODE ###

#from collections import deque
a,b,k=input().split()
a,b,k=int(a),int(b),int(k)

#多分両端からアクセスしないとTLEになる
'''
for i in range(b-a+1):
    if i<k:
        print(a+i)
    elif i>b-a-k:
        print(a+i)
'''

d=[]
if a+(k-1)>b:
    k=b-a+1
for i in range(k):
        d.append(a+i)
        d.append(b-i)
#辞書もsort可能
for i in sorted(set(d)):
    print(i)
### BUGGY CODE ###

N = int(input())
l = list(map(int, input().split(" ")))
k = 0
for i in range(N-2):
    a = l[i]
    for j in range(i+1, N-1):
        b = l[j]
        k += len([p for p in l[j+1:] if abs(b-a) < p < (a+b)])
print(k)

### FIXED CODE ###

from bisect import bisect_right
def main():
	N = int(input())
	L = list(map(int, input().split(" ")))
	L.sort()
	k = 0
	for i in reversed(range(2, N)):
		a = L[i]
		for j in reversed(range(1, i)):
			b = L[j]
			index = bisect_right(L, a-b, hi=j)
			k += j - index
	print(k)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

N,M,K=map(int,input().split())
O,S,T=10**9+7,N+M,6
for i in range(K):S=S*(N*M-i)%O;T*=i+1
print(S*K*~-K*pow(T,O-2,O)%O)

### FIXED CODE ###

N,M,K=map(int,input().split())
O,S,T=10**9+7,N+M,6
for i in range(K):S=S*(N*M-i)%O;T=T*-~i%O
print(S*K*~-K*pow(T,O-2,O)%O)
### BUGGY CODE ###

s = input() #sys.stdin.readlineは最後が改行
n =len(s)

from collections import defaultdict
amari = defaultdict(lambda:0)
amari[0]=1
num=0
tmp=0
ans =0

for i in range(n):
    num = tmp + int(s[-1-i])*(10**(i))
    tmp = num%2019
    amari[tmp]+=1

    if amari[tmp]>1:
        val = amari[tmp]
        ans -= (val-1)*(val-2)//2
        ans += (val)*(val-1)//2

print(ans)


### FIXED CODE ###

s = input() #sys.stdin.readlineは最後が改行
n =len(s)

from collections import defaultdict
amari = defaultdict(lambda:0)
amari[0]=1
num=0
tmp=0
ans =0

for i in range(n):
    num = tmp + int(s[-1-i])*pow(10,i,2019)
    tmp = num%2019
    amari[tmp]+=1

    if amari[tmp]>1:
        val = amari[tmp]
        ans -= (val-1)*(val-2)//2
        ans += (val)*(val-1)//2

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

# -*- coding: utf-8 -*-
from collections import deque
H, W = map(int, input().split())
map = [list(input()) for i in range(H)]
checked = list()
queue = deque()
for x in range(H):
    checked.append(list())
    for y in range(W):
        if map[x][y]=="#":
            checked[x].append(True)
            queue.append((x, y, 0))
        else:
            checked[x].append(False)
neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
while queue:
    x, y, res = queue.popleft()
    for dx, dy in neighbors:
        nx, ny = x+dx, y+dy
        if 0<=nx<H and 0<=ny<W:
            if not checked[nx][ny]:
                queue.append((nx, ny, res+1))
                checked[nx][ny] = True
print(res)


### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import deque
H, W = map(int, input().split())
map = [list(input()) for i in range(H)]
checked = list()
queue = deque()
for x in range(H):
    checked.append(list())
    for y in range(W):
        if map[x][y]=="#":
            checked[x].append(True)
            queue.append((x, y, 0))
        else:
            checked[x].append(False)
neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
while queue:
    x, y, res = queue.popleft()
    for dx, dy in neighbors:
        nx, ny = x+dx, y+dy
        if 0<=nx<H and 0<=ny<W:
            if not checked[nx][ny]:
                queue.append((nx, ny, res+1))
                checked[nx][ny] = True
print(res)