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

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

# bit全探索
s_max = 0
for bit in range(1<<n):

    s_tmp = 0
    for i in range(n):
        if bit >> i & 1:
            s_tmp += s[i]
    
    if s_tmp % 10 == 0:
        s_tmp = 0

    s_max = max(s_max, s_tmp)
    
print(s_max)

### FIXED CODE ###

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

s.sort()
s_max = sum(s)

if s_max % 10 != 0:
    print(s_max)
    exit()
else:
    for i in s:
        if i % 10 != 0:
            print(s_max - i)
            exit()

print(0)
### BUGGY CODE ###

from fractions import gcd

N,M=map(int,input().split())
#List=list(map(lambda x:int(x)/2,input().split()))
List=list(map(int,input().split()))

def main():
    LCM=1
    cut2count=0
    a=List[0]/2
    while a%2==0:
        a/=2
        cut2count+=1

    for i in List:
        i/=2
        LCM*=i/gcd(LCM,i)
            
        cut2countb=0
        b=i
        while b%2==0:
            b/=2
            cut2countb+=1
        if cut2count!=cut2countb:
            print(0)
            exit()


    #for i in List:
    #   if LCM/i%2==0:
    #      print(0)
    #     exit()

    print(int(M//(LCM*2)+M%(LCM*2)//LCM))


if __name__ == '__main__':
    main()

### FIXED CODE ###

from fractions import gcd
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
List=list(map(lambda x:int(x)//2,map(int, set(input().split()))))

def main():
    LCM=1

    for i in List:
        LCM*=i//gcd(LCM,i)

    for i in List:
        if LCM//i%2==0:
            print(0)
            exit()

    print(int(M//(LCM*2)+M%(LCM*2)//LCM))


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

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

for count in range(k):
    range_diff = [0] * n
    for pos in range(n):
        candidate_min = pos - a[pos]
        candidate_max = pos + a[pos] + 1
        if pos - a[pos] >= 0:
            min = pos - a[pos]
        else:
            min = 0
        range_diff[min] += 1
        if candidate_max <= n-1:
            range_diff[candidate_max] -= 1
    for i in range(1, n):
        range_diff[i] += range_diff[i-1]
    a = range_diff
    if count >= 43:
        break

print(' '.join(list(map(str,a))))

### FIXED CODE ###

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

for count in range(k):
    range_diff = [0] * n
    for pos in range(n):
        candidate_min = pos - a[pos]
        candidate_max = pos + a[pos] + 1
        if pos - a[pos] >= 0:
            min = pos - a[pos]
        else:
            min = 0
        range_diff[min] += 1
        if candidate_max <= n-1:
            range_diff[candidate_max] -= 1
    for i in range(1, n):
        range_diff[i] += range_diff[i-1]
    a = range_diff
    if count >= 43:
        break

print(' '.join(list(map(str,a))))
### BUGGY CODE ###

N = int(input())
A = [[int(x) for x in input().split()] for _ in range(N)]

flag = True
for k in range(N):
	for i in range(N):
		for j in range(i):
			if A[i][j] > A[i][k] + A[k][j]:
				flag = False
				break
		if not flag:
			break
	if not flag:
		break

ans = 0
if flag:
	for i in range(N):
		for j in range(i):
			flag = True
			for k in range(N):
				if k != i and k != j:
					if A[i][j] == A[i][k] + A[k][j]:
						flag = False
						break
			if flag:
				ans += A[i][j]
	print(ans)
else:
	print(-1)

### FIXED CODE ###

N = int(input())
A = [[int(x) for x in input().split()] for _ in range(N)]

flag = True
for k in range(N):
	for i in range(N):
		for j in range(i):
			if A[i][j] > A[i][k] + A[k][j]:
				flag = False
				break
		if not flag:
			break
	if not flag:
		break

ans = 0
if flag:
	for i in range(N):
		for j in range(i):
			flag = True
			for k in range(N):
				if k != i and k != j:
					if A[i][j] == A[i][k] + A[k][j]:
						flag = False
						break
			if flag:
				ans += A[i][j]
	print(ans)
else:
	print(-1)
### BUGGY CODE ###

N,Q = map(int,input().split())
S = input()
A = [list(map(int,input().split())) for _ in range(Q)]
AC_list = []
for i in range(N-1):
    if S[i:i+2] == 'AC':
        AC_list.append(1)
    else:
        AC_list.append(0)
for a in A:
    check = AC_list[a[0]-1:a[1]-1]
    print(sum(check))

### FIXED CODE ###

import numpy as np
N,Q = map(int,input().split())
S = np.array(list('_' + input()), dtype='U2')
A = (S == 'A')
C = (S == 'C')
AC = (A[:-1] & C[1:])
AC_cum = AC.cumsum()

for _ in range(Q):
    L,R = map(int,input().split())
    print(AC_cum[R-1] - AC_cum[L-1])
### BUGGY CODE ###

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

sum_x = 0
for i in range(0, n):
    tmp_x = x[i]
    sum_x += sum(list(filter(lambda ele: ele > 0, (map(lambda ele: ele - tmp_x, x)))))

sum_y = 0
for i in range(0, m):
    tmp_y = y[i]
    sum_y += sum(list(filter(lambda ele: ele > 0, (map(lambda ele: ele - tmp_y, y)))))

ans = sum_x * sum_y

divide_num = pow(10, 9) + 7
print(ans % divide_num)


### FIXED CODE ###

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

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

sum_y = 0
for i in range(0, m):
    sum_y += i * y[i] - (m - (i + 1)) * y[i]

ans = sum_x * sum_y

divide_num = pow(10, 9) + 7
print(ans % divide_num)
### BUGGY CODE ###

N, M, Q = map(int, input().split())
LR = []
for i in range(M):
    l, r = map(int, input().split())
    LR.append([l-1, r])
PQ = []
for i in range(Q):
    p, q = map(int, input().split())
    PQ.append([p-1, q-1])
    

import numpy as np
ar = np.zeros([M, N])
for m in range(M):
    ar[m, LR[m][0]:LR[m][1]] = 1
flags_start = [np.ones(M, dtype=np.bool)]
flags_end = []
for i in range(1, N):
    flags_start.append((ar[:, :i].max(axis=1)==0))# * (ar[:, i:].max(axis=1)==1))
    flags_end.append((ar[:, i:].max(axis=1)==0))# * (ar[:, :i].max(axis=1)==1))
flags_end.append(np.ones(M, dtype=np.bool))
for q in range(Q):
    left = PQ[q][0]
    right = PQ[q][1]
    print(sum(flags_start[left] * flags_end[right]))


### FIXED CODE ###

import numpy as np
N, M, Q = map(int, input().split())
LR = []
for i in range(M):
    l, r = map(int, input().split())
    LR.append([l, r])
PQ = []
for i in range(Q):
    p, q = map(int, input().split())
    PQ.append([p, q])
ar_sec = np.zeros([N, N])
for i in range(M):
    l, r = LR[i][0], LR[i][1]
    ar_sec[l-1][r-1] += 1


ar_sum = np.zeros([N+1, N+1])
for i in range(N):
    for j in range(N):
        ar_sum[i+1][j+1] = ar_sum[i][j+1]+ar_sum[i+1][j]-ar_sum[i][j]+ar_sec[i][j]

for i in range(Q):
    p, q = PQ[i][0], PQ[i][1]
    print(int(ar_sum[q][q]-ar_sum[p-1][q]))
### BUGGY CODE ###

import math

n = int(input())
s = input()
s2 = list(s)

if s[0] == 'B':
    s2[0] = 'L'
else:
    s2[0] = 'R'

for i in range(1,2*n): 
    if s[i-1] == s[i]:
        if s2[i-1] == 'L':
            s2[i] = 'R'
        else:
            s2[i] = 'L'
    else:
        if s2[i-1] == 'L':
            s2[i] = 'L'
        else:
            s2[i] = 'R'
        
if s2[0] == 'R' or s2[2*n-1] == 'L' or s2.count('L') != s2.count('R'):
    print(0)
    exit()
            
ans = 1
count_l = 0
for i in range(0,2*n): 
    if s2[i] == 'L':
        count_l += 1
    else:
        ans *= count_l
        count_l -= 1
    
print((ans * math.factorial(n)) % (10**9 + 7))

### FIXED CODE ###

import math

n = int(input())
s = input()
s2 = list(s)

if s[0] == 'B':
    s2[0] = 'L'
else:
    s2[0] = 'R'

for i in range(1,2*n): 
    if s[i-1] == s[i]:
        if s2[i-1] == 'L':
            s2[i] = 'R'
        else:
            s2[i] = 'L'
    else:
        if s2[i-1] == 'L':
            s2[i] = 'L'
        else:
            s2[i] = 'R'
        
if s2[0] == 'R' or s2[2*n-1] == 'L' or s2.count('L') != s2.count('R'):
    print(0)
    exit()
            
ans = 1
count_l = 0
for s2_str in s2: 
    if s2_str == 'L':
        count_l += 1
    else:
        ans *= count_l
        ans %= 10**9 + 7
        count_l -= 1
    
print(ans * math.factorial(n) % (10**9 + 7))
### BUGGY CODE ###

def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, w = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    A = [list(map(int, input().split())) for i in range(n)]

    Knap = [[0] * (w+1) for _ in range(n+1)]

    for i in range(n):
        for j in reversed(range(i+1)):
            for k in range(w+1):
#                if (Knap[j][k] > 0 or (j == 0 and k ==0)) and k + A[i][0] <= w:
                point = k + A[i][0]
                if point <= w:
                    Knap[j+1][k + A[i][0]] = max((Knap[j+1][point]), (Knap[j][k] + A[i][1]))

    knapmax = 0
    for i in range(n):
        knapmax = max(knapmax, max(Knap[i+1]))
    print(knapmax)

resolve()

### FIXED CODE ###

def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, w = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    A = [list(map(int, input().split())) for i in range(n)]

    Knap = [[0] * (w+1) for _ in range(n+1)]
#    Knap = [[0] * (110) for _ in range(10**5+10)]

    for i in range(n):
        for k in range(w+1):
            if k + A[i][0] <= w:
#                point = k + A[i][0]
                Knap[i+1][k+A[i][0]] = max(Knap[i+1][k+A[i][0]], (Knap[i][k] + A[i][1]))

            Knap[i+1][k] = max(Knap[i][k], Knap[i+1][k])

#    knapmax = 0
    # for i in range(n):
    #     knapmax = max(knapmax, max(Knap[i+1]))
    print(Knap[n][w])
#    print(*Knap, sep="\n")
resolve()
### BUGGY CODE ###

from math import sqrt, floor, log


def is_prime(num):
    if num <= 1:
        return False

    for i in range(2, floor(num / 2) + 1):
        if i == num:
            break
        if num % i == 0:
            return False
    return True


def prime_list(num):
    """
    num以下の素数を求める
    """
    ans = []
    for i in range(2, num + 1):
        if is_prime(i):
            ans.append(i)
    return ans


def factorize(num):
    """
    num >= 2
    numは素数ではない

    :return: [(底, 指数)]
    :rtype: [(int, int)]
    """
    l = prime_list(floor(num / 2))
    print(l)


def get_divisors(num):
    """
    num >= 2
    """
    ans = set()
    for i in range(2, floor(sqrt(num) + 1)):
        if num % i == 0:
            ans.add(i)
    return ans


def get_divisors2(num):
    ans = set()
    for i in range(2, floor(sqrt(num)) + 1):
        if num % i == 0:
            ans.add(i)
    return ans


def get_divisors3(num):
    ans = []
    value = num
    i = 2
    while value != 1:
        count = 0
        while value % i == 0:
            count += 1
            value = value // i

        if count != 0:
            ans.append((i, count))
        i += 1
    return ans


def main():
    n, p = [int(i) for i in input().split()]
    if n == 1:
        print(p)
    elif p == 1:
        print(1)
    else:
        ds = get_divisors3(p)
        ans = 1
        for d in ds:
            if d[1] >= n:
                ans *= d[0] ** (d[1] // n)
        print(int(ans))


if __name__ == '__main__':
    main()


### FIXED CODE ###

from math import sqrt, floor, log


def is_prime(num):
    if num <= 1:
        return False

    for i in range(2, floor(num / 2) + 1):
        if i == num:
            break
        if num % i == 0:
            return False
    return True


def get_divisors3(num):
    ans = []
    value = num
    i = 2
    while (i * i) <= num:
        count = 0
        while value % i == 0:
            count += 1
            value = value // i

        if count != 0:
            ans.append((i, count))
        i += 1
    return ans


def main():
    n, p = [int(i) for i in input().split()]
    if n == 1:
        print(p)
    elif p == 1:
        print(1)
    else:
        ds = get_divisors3(p)
        ans = 1
        for d in ds:
            if d[1] >= n:
                ans *= d[0] ** (d[1] // n)
        print(int(ans))


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

import re
p = re.compile("AC")
N, Q = map(int, input().split())
S = input()
for _ in range(Q):
    l, r = map(int, input().split())
    print(len(p.findall(S[l - 1:r])))


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
lr = [tuple(map(int, input().split())) for _ in range(Q)]
acindex_list = []
ac = 0
old = ""
for c in S:
    if old == "A" and c == "C":
        ac += 1
    old = c
    acindex_list.append(ac)
for l, r in lr:
    print(acindex_list[r - 1] - acindex_list[l - 1])
### BUGGY CODE ###

import copy
N, M = map(int, input().split())
res = [[] for i in range(N+5)]


for i in range(M) :
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    res[a].append(b)
    res[b].append(a)
    
pre = [-1] * N
d = 1
dl = []
pre[0] = 0

for i in res[0] :
    dl.append((i,0))

while(len(dl) != 0) :
    a,b = dl[0]
    dl.pop(0)
    if(pre[a] != -1) :
        continue
    pre[a] = b
    for i in res[a] :
        dl.append((i,a))
        
for i in range(N) :
    if(i == 0) :
        print("Yes")
        continue
    print(pre[i] + 1)

### FIXED CODE ###

import copy
N, M = map(int, input().split())
res = [[] for i in range(N+5)]


for i in range(M) :
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    res[a].append(b)
    res[b].append(a)
    
pre = [-1] * N
dist = [-1] * N
d = 1
dl = []
pre[0] = 0
dist[0] = 0
dl.append(0)

while(len(dl) != 0) :
    a = dl[0]
    dl.pop(0)
    for i in res[a] :
        if(dist[i] != -1):
            continue
        dist[i] = dist[a] + 1
        pre[i] = a
        dl.append(i)
        
for i in range(N) :
    if(i == 0) :
        print("Yes")
        continue
    print(pre[i] + 1)
### BUGGY CODE ###

from collections import deque
S = deque(list(input().strip()))
Q = int(input())
cnt = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0])==1:
        cnt += 1
    else:
        if cnt%2==0:
            if int(q[1])==1:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if int(q[1])==1:
                S.append(q[2])
            else:
                S.appendleft(q[2])
if cnt%2==0:
    print("".join(S))
else:
    x=""
    for i in range(len(S)-1,-1,-1):
        x += S[i]
    print(x)

### FIXED CODE ###

from collections import deque
S = deque(list(input().strip()))
Q = int(input())
cnt = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0])==1:
        cnt += 1
    else:
        if cnt%2==0:
            if int(q[1])==1:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if int(q[1])==1:
                S.append(q[2])
            else:
                S.appendleft(q[2])
if cnt%2==0:
    print("".join(S))
else:
    S.reverse()
    print("".join(S))
### BUGGY CODE ###

import numpy as np
n, x, y = map(int, input().split())
g1 = np.zeros((n+1,n+1),dtype=np.int64)
g2 = np.zeros((n+1,n+1),dtype=np.int64)
ans = np.zeros(n+1,dtype=np.int64)
for i in range(1,n+1):
    g1[i,i:] = range(n - i + 1)

#for i in range(1,n+1):
#    print(g1[i,1:])


for i in range(1,x+1):
    g2[i,i:y+1] = range(x - i + 1 , x - 2 * i + 2 + y )[::-1]
    g2[i,y+1:] = range(x - i + 2,x - i + 2 + n - y)

for i in range(x+1,n+1):
    #print(i,i - x + 1 , i - x + 1 + n - i )
    if i+1 < y+1:
        g2[i,i+1:y+1] = range(i - x + 1 , i - x + 1 + y - i  )[::-1]
    g2[i,y+1:] = range(i - x + 2,i - x + 2 + n - y)


#for i in range(1,n+1):
#    print(g2[i,1:])

#print('aaa')
g = np.minimum(g1,g2)

#for i in range(1,n+1):
#    print(g[i,1:])

for i in range(1,n + 1):
    for j in range(i+1,n+1):
        ans[g[i][j]] += 1

for i in range(1,n):
    print(ans[i])


### FIXED CODE ###

import numpy as np
n, x, y = map(int, input().split())

ans = [0] * n
for i in range(1,n):
    for j in range(i+1,n+1):
        ans[min(j-i,abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j))] += 1

for i in range(1,n):
    print(ans[i])
### BUGGY CODE ###

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

for i in range(Q):
  start, end  = map(int,input().split())
  s = S[start-1:end]
  out = s.count('AC')
  print(out)

### FIXED CODE ###

import sys
 
stdin = sys.stdin

N,Q = map(int,input().split())
S = input()
se = [list(map(int, stdin.readline().split())) for i in range(Q)]

list_out = [0] * N
cnt = 0
f = 0

# AC文字列のAの位置をリストに収めた
for i in range(len(S)):
  if S[i] == 'A':
    f = 1
    list_out[i] = list_out[i-1]    
  elif S[i] == 'C':
    if f == 1:
      cnt += 1
      f = 0
      list_out[i] = cnt
    else:
      list_out[i] = list_out[i-1]
  else:
    f = 0
    list_out[i] = list_out[i-1]    


# 指定した文字列範囲を含む要素数を表示
for i in se:
  print(list_out[i[1]-1] - list_out[i[0]-1])
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)


N = int(input())
x, y = [], []
for i in range(N):
    a, b = map(int, input().split())
    x.append([a, i])
    y.append([b, i])
x.sort()
y.sort()

e = []
for i in range(N-1):
    e.append([abs(x[i][0]-x[i+1][0]), x[i][1], x[i+1][1]])
    e.append([abs(y[i][0]-y[i+1][0]), y[i][1], y[i+1][1]])

e.sort()

uft = UnionFind(N)

ans = 0
for w, s, t in e:
    if not uft.same(s, t):
        uft.union(s, t)
        ans += w

print(ans)


### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)


N = int(input())
x, y = [], []
for i in range(N):
    a, b = map(int, input().split())
    x.append([a, i])
    y.append([b, i])
x.sort()
y.sort()

e = []
for i in range(N-1):
    e.append([abs(x[i][0]-x[i+1][0]), x[i][1], x[i+1][1]])
    e.append([abs(y[i][0]-y[i+1][0]), y[i][1], y[i+1][1]])

e.sort()

uft = UnionFind(N)

ans = 0
for w, s, t in e:
    if not uft.same(s, t):
        uft.union(s, t)
        ans += w

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

import sys
sys.setrecursionlimit(10**7)
n, q = list(map(int, input().split(' ')))
inf = [[] for _ in range(n)]
p_list = [0 for _ in range(n)] 
for i in range(n-1):
    a, b = list(map(int, input().split(' ')))
    inf[a-1].append(b-1)
    inf[b-1].append(a-1)   
for i in range(q):
    p, x = list(map(int, input().split(' ')))
    p_list[p-1] += x
visit = [0]*n
def add_p(num):
    visit[num] = 1
    for k in inf[num]:
        if visit[k] == 0:
            p_list[k] += p_list[num]
            add_p(k)
    return 0
add_p(0)
print(*p_list)

### FIXED CODE ###

def main():
    n, q = map(int, input().split(' '))
    import sys
    from collections import deque
    sys.setrecursionlimit(10**7)

    visit = [True for _ in range(n)]
    point = [0 for _ in range(n)]
    dic = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split(' '))
        dic[a-1].append(b-1)
        dic[b-1].append(a-1)
    for _ in range(q):
        p, x = map(int, input().split(' '))
        point[p-1] += x
    next_visit = deque()
    next_visit.append(0)
    visit[0] = False
    counter = 1
    while counter < n:
        t = next_visit.pop()
        for s in dic[t]:
            if visit[s]:
                point[s] += point[t]
                visit[s] = False
                counter += 1
                next_visit.append(s)
    print(*point)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n=int(input())
s=set()
for i in range(n):
  s={input()}^s
print(len(s))

### FIXED CODE ###

n=int(input())
s=set()
for i in range(n):s^={input()}
print(len(s))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def Z(s):
    """
    s: str
    return list of int with length len(s)
    """
    # initialization
    n=len(s)
    z=[0]*n
    z[0]=n
    # construct
    L,R=0,0
    for i in range(1,n):
        if i>=R: # 過去の結果が全く使えない
            L=R=i
            while(R<n and s[R-L]==s[R]): R+=1
            z[i]=R-L
        elif z[i-L]<R-i: # 過去の結果が全て使える
            z[i]=z[i-L]
        else: # 過去の結果が一部使える
            L=i
            while(R<n and s[R-L]==s[R]): R+=1
            z[i]=R-L
    return z
def resolve():
    n=int(input())
    s=input()
    ans=0
    for i in range(n):
        z=Z(s[i:])
        k=len(z) # k=n-i
        for j in range(k):
            ans=max(ans,min(j,z[j]))
    print(ans)
resolve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def Z(s):
    """
    s: str
    return list of int with length len(s)
    """
    # initialization
    n=len(s)
    z=[0]*n
    z[0]=n
    # construct
    L,R=0,0
    for i in range(1,n):
        if i>=R: # 過去の結果が全く使えない
            L=R=i
            while(R<n and s[R-L]==s[R]): R+=1
            z[i]=R-L
        elif z[i-L]<R-i: # 過去の結果が全て使える
            z[i]=z[i-L]
        else: # 過去の結果が一部使える
            L=i
            while(R<n and s[R-L]==s[R]): R+=1
            z[i]=R-L
    return z
def resolve():
    n=int(input())
    s=input()
    ans=0
    for i in range(n):
        z=Z(s[i:])
        k=len(z) # k=n-i
        for j in range(k):
            ans=max(ans,min(j,z[j]))
    print(ans)
resolve()
### BUGGY CODE ###

import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

ans = 0

for h in range(1, K+1):
  for i in range(1, K+1):
    for j in range(1, K+1):
      ans += gcd(h, i, j)

print(ans)

### FIXED CODE ###

from math import gcd

K = int(input())

ans = 0

for h in range(1, K+1):
  for i in range(1, K+1):
    for j in range(1, K+1):
      ans += gcd(h, gcd(i, j))

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

n = int(input())
s= input()
ans=0
for x in range(1000):
    num=str("{0:03d}".format(x))
    for i in range(n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                if(num==s[i]+s[j]+s[k]):
                    ans+=1
                    break
            else:
                continue
            break
        else:
            continue
        break
print(ans)

### FIXED CODE ###

n = int(input())
s= input()
ans=0
for x in range(1000):
    num=str("{0:03d}".format(x))
    s1=s.find(num[0])
    if(s1!=-1):
        s2=s.find(num[1],s1+1)
        if(s2!=-1):
            s3=s.find(num[2],s2+1)
            if(s3!=-1):
                ans+=1
print(ans)