Harryxun/stf_run huggingface dataset:
n, k = map(int, input().split())
a = list(map(int, input().split()))

digit_n = 0
kk = k
while kk > 0:
    kk >>= 1
    digit_n += 1

count = [0] * digit_n
mask = ~((1 << digit_n) - 1)

ans = 0
for i in range(n):
    ans += a[i] & mask
    for j in range(digit_n):
        if (a[i] >> j) & 1:
            count[j] += 1 

dp = [[0] * (digit_n + 1) for _ in range(2)]

for i in range(1, digit_n + 1):
    j = n - i
    bit = (k >> j) & 1
    dp[0][i] = (dp[0][i-1] << 1) + (n - count[j] if bit else count[j])
    dp[1][i] = (dp[1][i-1] << 1) + max(n - count[j], count[j])
    if bit == 1:
        dp[1][i] = max(dp[1][i], (dp[0][i-1] << 1) + count[j])
ans += max(dp[0][-1], dp[1][-1])
print(ans)

### FIXED CODE ###

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

digit_n = 0
kk = k
while kk > 0:
    kk >>= 1
    digit_n += 1

count = [0] * digit_n
mask = ~((1 << digit_n) - 1)

ans = 0
for i in range(n):
    ans += a[i] & mask
    for j in range(digit_n):
        if (a[i] >> j) & 1:
            count[j] += 1 

dp = [[0] * (digit_n + 1) for _ in range(2)]

for i in range(1, digit_n + 1):
    j = digit_n - i
    bit = (k >> j) & 1
    dp[0][i] = (dp[0][i-1] << 1) + (n - count[j] if bit else count[j])
    if dp[1][i-1]:
        dp[1][i] = (dp[1][i-1] << 1) + max(n - count[j], count[j])
    if bit == 1:
        dp[1][i] = max(dp[1][i], (dp[0][i-1] << 1) + count[j])
ans += max(dp[0][-1], dp[1][-1])
print(ans)
from itertools import product
N, M = map(int, input().split())
denkyu = []
for i in range(M):
    denkyu.append([int(j) for j in input().split()])
p = [int(i) for i in input().split()]
ls = [0, 1]
ans = 0
for x in product(ls, repeat=N):
    num = 0
    for denkyu_, j in enumerate(denkyu):
        judge_light_on = 0
        for s, i in enumerate(denkyu_):
            if i != 0 and x[s-1] == 1:
                judge_light_on += 1
        if judge_light_on%2 == p[j]:
            num += 1
    if num == 0 or num == M:
        ans += 1
print(ans)

### FIXED CODE ###

from itertools import product
N, M = map(int, input().split())
denkyu = []
for i in range(M):
    denkyu.append([int(j) for j in input().split()])
p = [int(i) for i in input().split()]
ls = [0, 1]
ans = 0
for x in product(ls, repeat=N):
    num = 0
    for j, denkyu_ in enumerate(denkyu):
        num_light_on = 0
        for i, s in enumerate(denkyu_):
            if i != 0 and x[s-1] == 1:
                num_light_on += 1
        if num_light_on%2 == p[j]:
            num += 1
    if num == M:
        ans += 1
print(ans)
from scipy.special import comb
x, y = map(int, input().split())

n = ((x + y) / 3)
r = min(x, y) - n

a = comb(n, r, exact=True)
print(a)

### FIXED CODE ###

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, y = map(int, input().split())

n = int(((x + y) / 3))
r = min(x, y) - n

if (min(x, y)<n)or((x + y)%3!=0):   
    print(0)
else:
    a = cmb(n, r)%(10**9 + 7)
    print(int(a))
a, b, c = map(int, input().split())
if((c - a - b > 0) and ((c-a-b)**2 > 4ab)):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a, b, c = map(int, input().split())
if((c - a - b > 0) and ((c-a-b)**2 > 4*a*b)):
  print("Yes")
else:
  print("No")
N, Y = map(int, input().split())

for x in range(N+1):
    for y in range(N-x+1):
        z = N - x -y
        if 10000*a + 5000*b + 1000*c == Y:
            print(a, b, c)
        else:
            print(-1, -1, -1)

### FIXED CODE ###

N, Y = map(int, input().split())

for a in range(N+1):
    for b in range(N-a+1):
        c = N - a -b
        if 10000*a + 5000*b + 1000*c == Y:
            print(a, b, c)
            exit()
else:
    print(-1, -1, -1)
n=int(input())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
dp=[[0,0,0] for i in range(n)]
dp[0]=l[0]
def dp1(x):
  if dp[x]!=[0,0,0]:
    return dp[x]
  else:
    dp2=dp1(x-1)
    ansa=l[x][0]+max(dp2[1],dp2[2])
    ansb=l[x][1]+max(dp2[0],dp2[2])
    ansc=l[x][2]+max(dp2[1],dp2[1])
    dp[x]=[ansa,ansb,ansc]
    return dp[x]
print(dp1(n-1))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
n=int(input())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
dp=[[0,0,0] for i in range(n)]
dp[0]=l[0]
def dp1(x):
  if dp[x]!=[0,0,0]:
    return dp[x]
  else:
    dp2=dp1(x-1)
    ansa=l[x][0]+max(dp2[1],dp2[2])
    ansb=l[x][1]+max(dp2[0],dp2[2])
    ansc=l[x][2]+max(dp2[1],dp2[0])
    dp[x]=[ansa,ansb,ansc]
    return dp[x]
print(max(dp1(n-1)))
n = int(input())
a = [int(x) for x in input().split()]


def check(a, t):
    ans = 0
    x = 0
    for i in a:
        x += i
        if t == True and x < 1:
            ans += 1 - x
            x = 1
        elif t == False and x > -1:
            ans += x + 1
            x = -1
        t = not t
    return ans


print(min(chk(a, True), chk(a, False)))


### FIXED CODE ###

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


def check(a, t):
    ans = 0
    x = 0
    for i in a:
        x += i
        if t == True and x < 1:
            ans += 1 - x
            x = 1
        elif t == False and x > -1:
            ans += x + 1
            x = -1
        t = not t
    return ans


print(min(check(a, True), check(a, False)))
import sys
from functools import lru_cache

S = input()

DEVIDER = 10**9 + 7


def add(a, b):
    return (a + b) % DEVIDER

def mul(a, b):
    return (a % DEVIDER) * (b % DEVIDER) % DEVIDER

cache_size = len(S) * 4

@lru_cache(maxsize=32)
def check(s, j):
    if j == 0 and s == 'A':
        return True
    if j == 1 and s == 'B':
        return True
    if j == 2 and s == 'C':
        return True
    return False

@lru_cache(maxsize=cache_size)
def dp(i, j):
    if i == len(S) and j == 3:
        # end of task
        return 1
    elif i == len(S) and j < 3:
        # fail
        return 0
    elif i < len(S) and j == 3:
        # next
        if S[i] == "?":
            return (3 * (dp(i + 1, 3) % DEVIDER)) % DEVIDER
        else:
            return dp(i + 1, 3)
    else:
        # i < len(S) and j < 3
        if S[i] == "?":
            pre = (3 * (dp(i + 1, j) % DEVIDER)) % DEVIDER
            lat = dp(i + 1, j + 1)
            return (pre + lat) % DEVIDER
        if check(S[i], j):
            return (dp(i + 1, j) + dp( i + 1, j + 1)) % DEVIDER
        return dp(i + 1, j)


ret = dp(0, 0)
print(ret)





### FIXED CODE ###

import sys

S = input()

DEVIDER = 10**9 + 7


def add(a, b):
    return (a + b) % DEVIDER

def mul(a, b):
    return (a % DEVIDER) * (b % DEVIDER) % DEVIDER

cache = [[0 for _ in range(4)] for _ in range(len(S) + 1)]
cache[0][0] = 1


def check(s, j):
    if j == 0 and s == 'A':
        return True
    if j == 1 and s == 'B':
        return True
    if j == 2 and s == 'C':
        return True
    return False


for i in range(len(S)):
    for j in range(4):
        if S[i] == '?':
            cache[i + 1][j] += 3 * cache[i][j]
        else:
            cache[i + 1][j] += cache[i][j]
        if j > 0:
            if check(S[i], j-1) or S[i] == '?':
                cache[i+1][j] += cache[i][j - 1]
        cache[i+1][j] %= DEVIDER

print(cache[len(S)][3])
import math
N, K = (int(i) for i in input().split())

pow_base = math.floor(math.log2((K-1))) + 1
base = N * (2 ** pow_base)

res = 0
for i in range(1, N+1):
    if i >= K :
        res += (2 ** pow_base)
    else:
        power = math.floor(math.log2((K-1) // i)) + 1
        res += 2 ** (pow_base - power)
print(res / base)




### FIXED CODE ###

import math
N, K = (int(i) for i in input().split())

if K == 1:
    pow_base = 1
else:
    pow_base = math.floor(math.log((K-1),2)) + 1
base = N * (2 ** pow_base)

res = 0
for i in range(1, N+1):
    if i >= K :
        res += (2 ** pow_base)
    else:
        power = math.floor(math.log((K-1) // i, 2)) + 1
        res += 2 ** (pow_base - power)
print(res / base)
N,X,M = map(int,input().split())
A = [100001]*(10**5+1)
A[1] = X
S = {X}
ans = X
for i in range(2,min(M+1,N)+1):
  X = X**2
  X %= M
  ans += X
  A[i] = X
  if X in S:
    break
  S.add(X)
  #print(i)
#[print(A[i]) for i in range(6)]
  
if i == N:
  print(ans)
else:
  j = A[:i+1].index(A[i])
  k = (N-i)//(i-j)
  l = (N-i)%(i-j)
  #print(j,k,l)
  ans += k*sum(A[j+1:i+1])+sum(A[j+1:j+l+1])
  print(ans)

### FIXED CODE ###

N,X,M = map(int,input().split())
A = [100001]*(2*(10**5)+100)
A[1] = X
S = {X}
ans = X
for i in range(2,min(2*M+1,N)+1):
  X = X**2
  X %= M
  ans += X
  A[i] = X
  if X in S:
    break
  S.add(X)
  #print(i)
#[print(A[i]) for i in range(6)]
if N == 1:
  print(X)
  exit()
elif i == N:
  print(ans)
else:
  j = A[:i+1].index(A[i])
  if i == j:
    print(ans)
  k = (N-i)//(i-j)
  l = (N-i)%(i-j)
  #print(j,k,l)
  ans += k*sum(A[j+1:i+1])+sum(A[j+1:j+l+1])
  print(ans)
N = int(input())
A = [int(input()) for _ in range(N)]

nb = 0
for i in range(N):
  nb = A[nb]
  if nb == 2:
    print(i+1)
    exit()

### FIXED CODE ###

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

nb = 1
for i in range(N):
  nb = A[nb-1]
  if nb == 2:
    print(i+1)
    exit()
print(-1)
N, M = map(int, input().split())
a = list(map(int, input().split()))
for i in range(M):
    B, C = map(int, input().split())
    if C > a[N]:
        a += [C for _ in range(B)]
        a.sort(reverse=True)
        a = a[:N]
print(sum(a))

### FIXED CODE ###

#import sys
#input = sys.stdin.readline
import numpy as np
N, M = map(int, input().split())
C = list(map(int, input().split()))
B = [1 for _ in range(N)]

for i in range(M):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
C = np.array(C)
D = np.argsort(-C)
#print(B, C, D)
S = 0
n = 0
for i in D:
    #print(B[i], N-n, min(B[i], N-n))
    S += C[i] * (min(B[i], N-n))
    n += min(B[i], N-n)
    #print(S, n)
    if n == N:
        break
print(S)
import math
def count(n, m, l):
    c_m = n // m
    c_l = n // l
    c_ml = n // (m * l // math.gcd(m, l))
    return n - (c_m + c_l - c_ml)

a, b, c, d = map(int, input().split())
b_tar = count(b, c, d)
a_tar = count(a, c, d)
is_plus_a = not(a % c == 0 or a % d == 0)
ans = b_tar - a_tar
if is_plus_a: ans += 1
print(ans)

### FIXED CODE ###

import fractions

def main():
    a, b, c, d = map(int, input().split())
    l =  (c * d) // fractions.gcd(c, d)
    cntb = b - (b // c + b // d - b // l)
    cnta = (a-1) - ((a-1) // c + (a-1) // d - (a-1) // l)
    ans = cntb - cnta

    print(ans)

if __name__ == '__main__':
    main()
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))



n=input1()

for i in range(int(math.sqrt(n)) +1,-1,-1):
	if n%i==0: #iがnの約数
		print((i-1) + (n//i -1))









### FIXED CODE ###

import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))



n=input1()

for i in range(int(math.sqrt(n)) +1,-1,-1):
	if n%i==0: #iがnの約数
		print((i-1) + (n//i -1))
		break
list_ = []
S = input()
T = input()
for i in range(len(S) - len(T)):
    cnt = 0
    for j in range(len(T)):
        if T[j] != S[i + j]:
            cnt += 1
    list_.append(cnt)
print(min(list_))


### FIXED CODE ###

S = input()
T = input()
list_a = []
if len(S) - len(T) ==0:
    cnt = 0
    for j in range(len(T)):
        if T[j] != S[j]:
            cnt += 1
    list_a.append(cnt)
else:
    for i in range(len(S) - len(T)):
        cnt = 0
        for j in range(len(T)):
            if T[j] != S[i + j]:
                cnt += 1
        list_a.append(cnt)
print(min(list_a))
import sys
s = sys.stdin.readlines()
N, K = map(int, s[0].split())
A = list(map(int, s[1].split()))

b = [1]
i = 0
while True:
    if A[i] in b:
#        print("m: "+str(b.index(A[i])))
#        print("n: "+str(len(b)-A[i]))
        m = b.index(A[i])
        n = len(b)-A[i]
        K = (K-m)%n + m
        break
    b.append(A[i])
    i = A[i] - 1
    
tmp = 0
for i in range(K):
    next_town = A[tmp]
    tmp = next_town - 1
print(next_town)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int,input().split()))
b = [0]*N
next_town = 1
for i in range(N+1):
    if b[next_town-1] != 0:
        start = next_town
        cycle = i - b[next_town-1]
#        print("start: "+str(start))
#        print("cycle: "+str(cycle))
        break
    b[next_town-1] = i
    next_town = A[next_town-1]
    
next_town = 1
if b[start-1] >= K:
    for i in range(K):
        next_town = A[next_town-1]
    print(next_town)
else:
    next_town = start
    for i in range((K-b[start-1])%cycle):
        next_town = A[next_town-1]
    print(next_town)
a,b,c=map(int,input())
if a+c==2*b:print("YES")
else:print("NO")

### FIXED CODE ###

a,b,c=map(int,input().split())
if a+c==2*b:print("YES")
else:print("NO")
S = input()
K = int(input())
 
buf=''
cnt = 1
total = 0
cnts = []
 
for s in S:
    #print(buf,s,cnt)
    if s == buf:
        cnt += 1       
    else:
        cnts.append(cnt)
        total += int(cnt/2)
        cnt = 1        
    buf = s
cnts.append(cnt)    
total += int(cnt/2)
 
if len(S)==1:
    print(int(K/2))
    
elif len(set(list(S)))==1:
    print(int(len(S*K)/2))
elif S[0]==S[-1] and cnts[1] % 2 != 0:
    if (cnts[1]+cnts[-1]) % 2 == 0:
        print(total*K+K-1)
    else:
        print(total*K)
else:
    print(total*K)

### FIXED CODE ###

from itertools import groupby
S = input()
K = int(input())
a = [len(tuple(s)) for _, s in groupby(S)]
ans = 0
 
if S[0] == S[-1] and K > 1:
    if len(a) == 1:
        ans = a[0]*K // 2
    else:
        ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
        ans += sum(n // 2 for n in a[1:-1]) * K
else:
    ans = sum(n // 2 for n in a) * K
print(ans)
N = int(input())
S = input()
K = int(input())
for i in range(N):
    if S[i] != S[K+1]:
        S = S[:i] + '*' + S[(i+1):]
print(S)

### FIXED CODE ###

N = int(input())
S = input()
K = int(input())
for i in range(N):
    if S[i] != S[K-1]:
        S = S[:i] + '*' + S[(i+1):]
print(S)
import sys
fastinput=sys.stdin.readline
N=int(input())
a=[int(i) for i in fastinput().split()]
result=[None]*N
if N%2:#odd
    c=(N-1)//2
    for num,i in enumerate(a):
        r=(num+1)//2
        if num==0:
            result[c]=i
        else:
            if num%2:#右半分
                result[c+r]=i
            else:
                result[c-r]=i
else:#even
    for num,i in enumerate(a):
        d=(N-i)//2
        if num%2:#左半分
            result[d]=i
        else:
            result[N-1-d]=i
print(" ".join([str(j) for j in result]))
            

### FIXED CODE ###

import sys
fastinput=sys.stdin.readline
N=int(input())
a=[int(i) for i in fastinput().split()]
result=[None]*N
if N%2:#odd
    c=(N-1)//2
    for num,i in enumerate(a):
        r=(num+1)//2
        if num==0:
            result[c]=i
        else:
            if num%2:#右半分
                result[c+r]=i
            else:
                result[c-r]=i
else:#even
    for num,i in enumerate(a):
        d=(N-num-1)//2
        if num%2:#左半分
            result[d]=i
        else:
            result[N-1-d]=i
print(" ".join([str(j) for j in result]))
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

a = N // K
b = ceil(N / K)
# print(a, b)
c,d = N-a, N-b
# print(c,d)
# print(N-c,N-d)

#
x = N // (N - K)
y = x+1
# print(x, y)
a = N - x * (N-K)
b = N - y * (N-K)
# print(a, b)

# print(min(abs(a), abs(b)))

if N < K:
    print(min(K-N, N))
elif K == 1:
    print(0)
else:
    ans = min(abs(a), abs(b))
    print(ans)

# if N >= K:
#     ans = min(abs(a), abs(b))
# # K > N:
# else:
#     ans = min(K-N, N)
# print(ans)


### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

if N <= K:
    print(min(K-N, N))
# elif K == 1:
#     print(0)
else:
    print(min(N % K, K - N % K))
    # a = N // K
    # b = ceil(N / K)
    # c = N % K
    # print(a, b, c)
    # print(abs(c-K), abs(c))

    # x = N // (N - K)
    # y = x + 1
    # z = x - 1
    # print(x, y, z)
    # a = N - x * (N-K)
    # b = N - y * (N-K)
    # c = N - z * (N-K)
    # print(a, b, c)
    # ans = min(abs(a), abs(b), abs(c))
    # print(ans)

# if N >= K:
#     ans = min(abs(a), abs(b))
# # K > N:
# else:
#     ans = min(K-N, N)
# print(ans)
s = input().split()
i = s[0]
m = s[1]
j = 0
el = input().split()
for p in el:
    if int(p) < 1 / (4 * m):
      j = 1 
if j == 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s = input().split()
i = s[0]
m = int(s[1])
count = 0
sun = 0
el = input().split()
for p in el:
    sun += int(p)
for k in el:
    if int(k) >= sun / (4 * m):
        count += 1
if count >= m:
    print("Yes")
else:
    print("No")
X = int(input)

ans = 0
while(1):
  ans += 1
  if (X * ans) % 360 == 0:
    print(ans)
    break

### FIXED CODE ###

X = int(input())
 
ans = 0
while(1):
  ans += 1
  if (X * ans) % 360 == 0:
    print(ans)
    break
import math

N = int(input())
ans = N-1
for i in range(1, math.sqrt(N)+1):
    if N%i==0:
        ans = min(ans, i+(N/i)-2)
print(ans)


### FIXED CODE ###

import math

N = int(input())
ans = N-1
for i in range(1, int(math.sqrt(N)+1)):
    if N%i==0:
        ans = min(ans, i+(N/i)-2)
print(int(ans))
K,S = map(int,input().split())


count = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k = S:
                count += 1
                
print(count)

### FIXED CODE ###

k,s = map(int,input().split())
count = 0
for i in range(k+1):
    for j in range(k+1):
        if 0 <= s-(i+j) <=k:
            count += 1
print(count)
n, m, q = map(int, input().split(" "))

k = []
for _ in range(q):
    k.append(list(map(int, input().split(" "))))

max_score = 0
import itertools
for a in itertools.combinations_with_replacement(range(1, m+1), m):
    score = 0
    for i in range(q):
        if a[k[i][1]-1] - a[k[i][0]-1] == k[i][2]:
            score += k[i][3]
    if score > max_score:
        max_score = score
print(max_score)

### FIXED CODE ###

n, m, q = map(int, input().split(" "))

k = []
for _ in range(q):
    k.append(list(map(int, input().split(" "))))

max_score = 0
import itertools
for a in itertools.combinations_with_replacement(range(1, m+1), n):
    score = 0
    for i in range(q):
        if a[k[i][1]-1] - a[k[i][0]-1] == k[i][2]:
            score += k[i][3]
    if score > max_score:
        max_score = score
print(max_score)
# coding: utf-8
# Your code here!

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

def gcd(x, y):
    if x == 0:
        return y
    if y == 0:
        return x
        
    if y > x:
        temp = y
        y = x
        x = temp
    amari = x % y
    if amari == 0:
        return y
    else:
        return gcd(y, amari)
        
def L(i):
    if i == 0:
        return 0
    else:
        return gcd(L(i-1), A[i-2])
        
def R(i):
    if i == N+1:
        return 0
    else:
        return gcd(R(i+1), A[i-1])
        
M = [gcd(L(i), R(i+1)) for i in range(1, N+1)] # i=1,...,N

print(max(M))


### FIXED CODE ###

# coding: utf-8
# Your code here!

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

def gcd(x, y):
    if x == 0:
        return y
    if y == 0:
        return x
        
    if y > x:
        temp = y
        y = x
        x = temp
    amari = x % y
    if amari == 0:
        return y
    else:
        return gcd(y, amari)
        
L = list(range(N))
L[0] = 0
for i in range(N-1):
    L[i+1] = gcd(L[i], A[i])
    
R = list(range(N))
R.append(0)
for i in reversed(range(N)):
    R[i] = gcd(R[i+1], A[i])

M = [gcd(L[i], R[i+1]) for i in range(N)] # i=1,...,N

print(max(M))
import sympy

sympy.divisors(10**9)

n = int(input())
print(len(list(filter(lambda x: len(sympy.divisors(x)) == 8, range(1, n + 1,2)))))


### FIXED CODE ###

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())
print(len(list(filter(lambda x: len(make_divisors(x)) == 8, range(1, n + 1,2)))))
print ('A B C = ?')
a,b,c = input(),input(),input()

if (a + b >= c):
    print ('Yes')
else:
    print ('No')


### FIXED CODE ###

a,b,c = input().split()

if (int(a) + int(b) >= int(c)):
    print ('Yes')
else:
    print ('No')
N = int(input())
A = list(map(int, input().split()))
A.sort()
for i in nrange(N-1):
  if A[i] == A[i+1]:
    print("NO")
    break
else:
  print('YES')

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
for i in range(N-1):
  if A[i] == A[i+1]:
    print("NO")
    break
else:
  print('YES')
N = int(input())


def time(n):
    if n <= 0:
        return 0
    elif n == 1:
        return 1
    else:
        return time(n-1) * n


print(time(N) % (10 ^ 9+7))


### FIXED CODE ###

N = int(input())

Ans = 1
for i in range(1, N+1):
    Ans *= i
    Ans %= (10**9+7)

print(Ans)
N = int(input())
H = list(map(int, input().split())
ans = 1
for i in range(1,N):
  if H[i]>=max(H[:i]):
    ans += 1
print(ans)


### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
ans = 1
for i in range(1,N):
  if H[i]>=max(H[:i]):
    ans += 1
print(ans)
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*-~n

    def sum(self, i):
        s = 0
        while i:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


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

k = k % (10 ** 9 + 7)
bit = Bit(n * k)
cnt = 0
for i, t in enumerate(a * k):
    bit.add(t, 1)
    cnt += i+1-bit.sum(t)


print((cnt % (10 ** 9 + 7)))


### FIXED CODE ###

MOD = 10**9+7
n, k = map(int, input().split())
a = list(map(int, input().split()))

cnt1 = 0
for i in range(len(a)-1):
    for j in range(i, len(a)):
        if a[i] > a[j]:
            cnt1 += 1

a2 = a * 2
cnt2 = 0
for i in range(len(a)):
    for j in range(len(a), len(a2)):
        if a2[i] > a2[j]:
            cnt2 += 1

print((cnt1 * k + cnt2 * k * (k-1) // 2) % MOD)