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

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

from itertools import accumulate
acc = [0]+list(accumulate(As))
dp = [0] * 50
mx = 0
sums = []
for i in range(n+1):
    for j in range(i+1,n+1):
        s = acc[j]-acc[i]
        # print(i,j,s)
        sums.append(s)
        for d in range(50):
            if s & (1<<d):        
                dp[d] += 1
mx = 0
for i in range(50):
    if dp[i] >= k:
        mx = max(mx,i)

ex = [a for a in sums if a&(1<<mx)]
ans = 0
from itertools import combinations
for l in combinations(ex, k):
    ret = l[0]
    for e in l[1:]:
        ret &= e
    ans = max(ret, ans)
print(ans)

### FIXED CODE ###

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

from itertools import accumulate
acc = [0]+list(accumulate(As))
dp = [0] * 50
mx = 0
sums = []
for i in range(n+1):
    for j in range(i+1,n+1):
        s = acc[j]-acc[i]
        sums.append(s)

# 最大の桁数
for d in range(50):
    if max(sums) & (1<<d):
        mx = max(mx, d)
        dp[d] += 1
mx = 0
for i in range(50):
    if dp[i] >= k:
        mx = max(mx,i)

# 計算
ans = 0
now = 0
for d in range(50,-1,-1):
    cnt = 0
    for s in sums:
        if s & (now+(1<<d)) == now+(1<<d):
            cnt += 1
    # print(d,cnt)
    if cnt >= k:
        now += 1<<d
print(now)
### BUGGY CODE ###

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

b = []
for i in range(N):
  b.append(a[i])
  b = b[::-1]
print (" ".join(b))

### FIXED CODE ###

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

print (" ".join(a[-1::-2] + a[N%2::2]))
### BUGGY CODE ###

import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b,c = map(int, input().split())
    B.append(b)
    C.append(c)

m = 100001
res = np.arange(m,dtype=int)
newA = np.zeros((m),dtype=int)


for a in A:
    newA[a] += 1

for i in range(Q):
    newA[C[i]] += newA[B[i]]
    newA[B[i]] = 0
    print(np.dot(res,newA))

### FIXED CODE ###

import numpy as np

N = int(input())
A = []
A = np.array(list(map(int, input().split())))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b,c = map(int, input().split())
    B.append(b)
    C.append(c)

m = max(max(A), max(B), max(C))+1
res = np.arange(m,dtype=int)
newA = np.zeros((m),dtype=int)


for a in A:
    newA[a] += 1

sum_r = np.dot(res,newA)


for i in range(Q):
    b = B[i]
    c = C[i]
    sum_r = sum_r - b*newA[b] + c*newA[b]
    print(sum_r)
    newA[c] += newA[b]
    newA[b] = 0
### BUGGY CODE ###

N=int(input())
S=[]
cnt=0
for _ in range(N):
    S.append(sorted(list(input())))
    
for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            cnt += 1

print(cnt)

### FIXED CODE ###

N = int(input())
d = {}
for _ in range(N):
    S = "".join(sorted(input()))
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
ans = 0
for v in d.values():
    ans += v * (v - 1) // 2
print(ans)
### BUGGY CODE ###

def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]

    N = int(input())
    S = list(input())

    if S[0]!='B' or S[-1]!='B':
        print(0)
        exit()

    mod = 10**9 + 7
    cnt_l = 1
    cnt_r = 0
    pre = 'B'
    pre_d = 1 #1がleft
    ans = 1

    for i in range(1,N*2):
        if S[i-1]==S[i]:
            if pre_d:
                pre_d = 0
                ans *= cnt_l - cnt_r
                cnt_r += 1
            else:
                pre_d = 1
                cnt_l += 1
        else:
            if pre_d:
                cnt_l += 1
            else:
                ans *= cnt_l - cnt_r
                cnt_r += 1

    for i in range(1,N+1):
        ans *= i
        ans %= mod
    if cnt_l!=N:
        print(0)
        exit()

    print(ans)

if __name__=='__main__':
    main()


### FIXED CODE ###

import math
n = int(input())
S = input()
 
RL = [None]*2*n
 
for i in range(2*n):
    if i % 2 == 0:
        if S[i] == 'B':
            RL[i] = 'L'
        else:
            RL[i] = 'R'
 
    else:
        if S[i] == 'B':
            RL[i] = 'R'
        else:
            RL[i] = 'L'
 
if S[0] == 'W' or S[-1] == 'W':
    print(0)
    exit()
 
left = 0
count = 1
mod = 10**9 + 7
 
for check in RL:
    if check == 'L':
        left += 1
    else:
        count = count * left % mod
        left -= 1
 
    if left < 0:
        print(0)
        exit()
 
count = count * math.factorial(n) % mod
 
if left != 0:
    print(0)
else:
    print(count)
### BUGGY CODE ###

n,q = map(int,input().split())
s = input()
word = list(s)
li = [list(input().split()) for _ in range(q)]
memo = {}


def dfs(m):
    if m in memo:
        return memo[m]
    for i in range(q):
        if word[m] == li[i][0]:
            if li[i][1] == 'R':
                m += 1
            else:
                m -= 1
        if m < 0:
            memo[m] = 'Left'
            return 'Left'
        elif m > n-1:
            memo[m] = 'Right'
            return  'Right'
    memo[m] = True
    return True

def left(a,b):
    if a == 0 and b == n-1:
        if dfs(a) != 'Left':
            return 0
        elif dfs(b) == 'Left':
            return n
    m = int((a+b)/2)
    if a == m:
        return b
    if dfs(m) == 'Left':
        return left(m,b)
    else:
        return left(a,m)

def right(a,b):
    if a == 0 and b == n-1:
        if dfs(b) != 'Right':
            return n-1
        elif dfs(a) == 'Right':
            return -1
    m = int((a+b)/2)
    if a == m:
        return a
    if dfs(m) == 'Right':
        return right(a,m)
    else:
        return right(m,b)

print(right(0,n-1) - left(0,n-1) + 1)


### FIXED CODE ###

n,q = map(int,input().split())
s = input()
word = list(s)
li = [list(input().split()) for _ in range(q)]
memo = {}

def dfs(m):
    k = m
    if m in memo:
        return memo[m]
    for x in li:
        if word[m] == x[0]:
            if x[1] == 'R':
                m += 1
            else:
                m -= 1
        if m < 0:
            memo[k] = 'Left'
            return 'Left'
        elif m > n-1:
            memo[k] = 'Right'
            return  'Right'
    memo[k] = True
    return True

def left(a,b):
    m = int((a+b)/2)
    if a == m:
        return b
    elif dfs(m) == 'Left':
        return left(m,b)
    else:
        return left(a,m)

def right(a,b):
    m = int((a+b)/2)
    if a == m:
        return a
    elif dfs(m) == 'Right':
        return right(a,m)
    else:
        return right(m,b)

if dfs(0) == 'Right':
    print(0)
elif dfs(0) == 'Left':
    if dfs(n-1) == 'Right':
        print(right(0,n-1) - left(0,n-1) + 1)
    elif dfs(n-1) == 'Left':
        print(0)
    else:
        print(n - left(0,n-1))
else:
    if dfs(b) == 'Right':
        print(right(0,n-1) + 1)
    elif dfs(b) == 'Left':
        print(0)
    else:
        print(n)
### BUGGY CODE ###

import itertools
import collections

N = int(input())
S = input()

c = collections.Counter(itertools.combinations(S, 3))
print(len(c))

### FIXED CODE ###

N = int(input())
S = input()

count = 0
for h in range(10):
  pos_h = S.find(str(h))
  if pos_h < 0:
    continue
  for i in range(10):
    pos_i = S.find(str(i), pos_h+1)
    if pos_i < 0:
      continue
    for j in range(10):
      pos_j = S.find(str(j), pos_i+1)
      if pos_j < 0:
        continue
      count += 1

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

N, Q = map(int, input().split())
S = input()
c = [0]*N
for i in range(N):
    c[i] = S[:i+1].count('AC')
for _ in range(Q):
    l, r = map(int, input().split())
    print(c[r-1]-c[l-1])

### FIXED CODE ###

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

import math as mt 
import collections
N = int(raw_input())
MAXN = N+1
  
# stores smallest prime factor for 
# every number 
spf = [0 for i in range(MAXN)] 
  
# Calculating SPF (Smallest Prime Factor)  
# for every number till MAXN. 
# Time Complexity : O(nloglogn) 
def sieve(): 
    spf[1] = 1
    for i in range(2, MAXN): 
          
        # marking smallest prime factor  
        # for every number to be itself. 
        spf[i] = i 
  
    # separately marking spf for  
    # every even number as 2 
    for i in range(4, MAXN, 2): 
        spf[i] = 2
  
    for i in range(3, int(mt.ceil(mt.sqrt(MAXN)))): 
          
        # checking if i is prime 
        if (spf[i] == i): 
              
            # marking SPF for all numbers 
            # divisible by i 
            for j in range(i * i, MAXN, i):  
                  
                # marking spf[j] if it is  
                # not previously marked 
                if (spf[j] == j): 
                    spf[j] = i 
# A O(log n) function returning prime  
# factorization by dividing by smallest  
# prime factor at every step 
def getFac(x): 
    count=0
    ret = collections.Counter()
    while (x != 1): 
        ret[spf[x]]+=1
        count+=1
        x //= spf[x]
    return ret , count


sieve() 
ans = 0
for i in range(1,N+1):
    fac, count = getFac(i)
    tmp = 1
    for v in fac.values():
        tmp *= (v+1)
    ans += tmp*i
print(ans)

### FIXED CODE ###

FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
N = rri()
ans= 0
for i in range(1, N+1):
    first = i
    last = i*(N//i)
    ans += (last+first)*(N//i)/2
print(ans)


#26879
### BUGGY CODE ###

import itertools
import sys

N, N1 = tuple([int(x) for x in sys.stdin.readline().split()])
D, C = [], []

for _ in range(N1):
    D.append([int(x) for x in sys.stdin.readline().split()])
for _ in range(N):
    C.append([int(x) for x in sys.stdin.readline().split()])

min_cost = 2**64
for colors in list(itertools.permutations(range(1, N1 + 1))):
    cost = 0
    for i in range(N):
        for j in range(N):
            if C[i][j] != colors[(i + j) % 3]:
                cost += D[C[i][j] - 1][colors[(i + j) % 3] - 1]
    if cost < min_cost:
        min_cost = cost
print(min_cost)

### FIXED CODE ###

import itertools
import sys

N, N1 = tuple([int(x) for x in sys.stdin.readline().split()])
D, C = [], []

for _ in range(N1):
    D.append([int(x) for x in sys.stdin.readline().split()])
for _ in range(N):
    C.append([int(x) for x in sys.stdin.readline().split()])

color_count = [[0] * N1 for _ in range(3)]
for i in range(N):
    for j in range(N):
        color_count[(i + j) % 3][C[i][j] - 1] += 1

min_cost = 2**64
for c0 in range(N1):
    for c1 in range(N1):
        if c0 == c1:
            continue
        for c2 in range(N1):
            if c0 == c2 or c1 == c2:
                continue
            cost = 0
            for j in range(N1):
                cost += color_count[0][j] * D[j][c0]
                cost += color_count[1][j] * D[j][c1]
                cost += color_count[2][j] * D[j][c2]
            if cost < min_cost:
                min_cost = cost

print(min_cost)
### BUGGY CODE ###

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

goukei = 0
for i in range(N):
    a = A[0]
    del A[0]
    Agoukei = sum(A)
    goukei = goukei + a*Agoukei

k = 10**9 + 7
print(goukei%k)

### FIXED CODE ###

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

sumA = sum(A)
for i in range(N):
    a = A[i]
    sumA = sumA - a
    goukei = goukei + sumA*a

k = 10**9 + 7
print(goukei%k)
### BUGGY CODE ###

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

s = 0
for i in range(n-k+1):
    a = sum(p[i:i+k])
    if a > s:
        s = a
        
print((s+k)/2)

### FIXED CODE ###

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

s = 0
a = sum(p[:k])
for i in range(n-k+1):
    if i != 0:
        a = a-p[i-1]+p[i+k-1]
    if a > s:
        s = a
        
print((s+k)/2)
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
c = 0
for i in range(N):
    for j in range(i+1,N):
        tmp = N-j-1
        for k in range(N-1, j, -1):
            if L[k] < L[i]+L[j]:
                break
            tmp -= 1
        c += tmp
print(c)


### FIXED CODE ###

import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
res = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tgt = L[i]+L[j]
        res += bisect.bisect_left(L, tgt)-(j+1)
print(res)
### BUGGY CODE ###

# https://atcoder.jp/contests/abc129/tasks/abc129_d
from copy import deepcopy
def main():
    h, w = map(int, input().split())
    matrix = []
    for _ in range(h):
        row = list(input())
        matrix.append(row)

    left = [[0] * w for _ in range(h)] # 左から右
    right = [[0] * w for _ in range(h)] # 右から左
    up = [[0] * w for _ in range(h)] # 上から下
    down = [[0] * w for _ in range(h)] # 下から上

    for i in range(h):
        c = 0
        for j in range(w):
            if matrix[i][j] == '.':
                c += 1
            else:
                c = 0
            left[i][j] = c
    for i in range(h):
        c = 0
        for j in range(w)[::-1]:
            if matrix[i][j] == '.':
                c += 1
            else:
                c = 0
            right[i][j] = c
    for j in range(w):
        c = 0
        for i in range(h):
            if matrix[i][j] == '.':
                c += 1
            else:
                c = 0
            up[i][j] = c
    for j in range(w):
        c = 0
        for i in range(h)[::-1]:
            if matrix[i][j] == '.':
                c += 1
            else:
                c = 0
            down[i][j] = c
    ans = 1
    for i in range(h):
        for j in range(w):
            t = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
            ans = max(ans, t)
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

# https://atcoder.jp/contests/abc129/tasks/abc129_d
from copy import deepcopy
def main():
    h, w = map(int, input().split())
    matrix = []
    for _ in range(h):
        row = list(input())
        matrix.append(row)

    left = [[0] * w for _ in range(h)] # 左から右
    right = [[0] * w for _ in range(h)] # 右から左
    up = [[0] * w for _ in range(h)] # 上から下
    down = [[0] * w for _ in range(h)] # 下から上

    for i in range(h):
        c = 0
        for j in range(w):
            if matrix[i][j] == '.':
                c += 1
            else:
                c = 0
            left[i][j] = c
    for i in range(h):
        c = 0
        for j in range(w)[::-1]:
            if matrix[i][j] == '.':
                c += 1
            else:
                c = 0
            right[i][j] = c
    for j in range(w):
        c = 0
        for i in range(h):
            if matrix[i][j] == '.':
                c += 1
            else:
                c = 0
            up[i][j] = c
    for j in range(w):
        c = 0
        for i in range(h)[::-1]:
            if matrix[i][j] == '.':
                c += 1
            else:
                c = 0
            down[i][j] = c
    ans = 1
    for i in range(h):
        for j in range(w):
            t = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
            ans = max(ans, t)
    print(ans)

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

N,A,B=list(map(int,input().split()))
H = [int(input()) for _ in range(N)]

def can_eliminate(n): #O(N)
  H_ = [((h-B*n)+A-B-1)//(A-B) for h in H if h>B*n]
  if sum(H_)<=n:
    #print('can eliminate by ' + str(n) +'times')
    return True
  else:
    #print('can not eliminate by ' + str(n) +'times')
    return False
    
def binary_search(l,r): #r:inclusive
  #print('search between ' + str((l,r)))
  if can_eliminate(l):
    return l
  if r==l+1:
    return r
  
  c = (l+r)//2
  if can_eliminate(c):
    return binary_search(l,c)
  else:
    return binary_search(c,r)
  
print(binary_search(1, (sum(H)+2*B+1)//B))

### FIXED CODE ###

N,A,B=list(map(int,input().split()))
H = [int(input()) for _ in range(N)]

def can_eliminate(n): #O(N)
  H_ = [((h-B*n)+A-B-1)//(A-B) for h in H if h>B*n]
  if sum(H_)<=n:
    #print('can eliminate by ' + str(n) +'times')
    return True
  else:
    #print('can not eliminate by ' + str(n) +'times')
    return False
    
def binary_search(l,r): #r:inclusive
  #print('search between ' + str((l,r)))
  if r==l+1:
    if can_eliminate(l):
      return l
    else:
      return r
  
  c = (l+r)//2
  if can_eliminate(c):
    return binary_search(l,c)
  else:
    return binary_search(c,r)
  
print(binary_search(1, (sum(H)+2*B+1)//B))
### BUGGY CODE ###

from sys import exit
import copy
#import numpy as np
#from collections import deque


d, = map(int, input().split())
c= list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
#  t=[int(input()) for _ in range(d)]

sche=[0 for _ in range(d)]
s_tmp=float("inf")*(-1)
for off in range(0,26):
    last=[0 for _ in range(26)]
    sche=[0 for _ in range(d)]
    for day in range(1,d+1):
        idx=day-1
        d_tmp=float("inf")*(-1)
        i_tmp=0
        for t in range(26):    
            delta=0
            l_tmp=copy.copy(last)
            delta+=s[idx][t]
            l_tmp[t]=day
            for l in range(26):
                delta-=0.5*(off+1)*c[l]*((day-l_tmp[l])+(day+off-l_tmp[l]))
            if delta>=d_tmp:
                d_tmp=delta
                i_tmp=t
        
        sche[idx]=i_tmp+1
        # score+=d_tmp
        last[i_tmp]=day
        # print(score)
        # print(i_tmp+1)

    score=0
    last=[0 for _ in range(26)]
    for i in range(1,d+1):
        idx=i-1
        score+=s[idx][sche[idx]-1]
        for l in range(26):
            score-=c[l]*(i-last[l])
        last[sche[idx]-1]=i
    
    # print(score)
    if score>=s_tmp:
        s_tmp=score
        sche_tmp=copy.copy(sche)


for i in sche_tmp:
    print(i)
# print(s_tmp)






### FIXED CODE ###

from sys import exit
import copy
#import numpy as np
#from collections import deque


d, = map(int, input().split())
c= list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
#  t=[int(input()) for _ in range(d)]

sche=[0 for _ in range(d)]
last=[0 for _ in range(26)]

score=0
for day in range(1,d+1):
    idx=day-1
    d_tmp=0
    i_tmp=0
    for t in range(26):    
        delta=0
        l_tmp=copy.copy(last)
        delta+=s[idx][t]
        l_tmp[t]=day
        for l in range(26):
            delta-=c[l]*(day-l_tmp[l])
        if delta>=d_tmp:
            d_tmp=delta
            i_tmp=t
    sche[idx]=i_tmp
    score+=d_tmp
    last[i_tmp]=day
    # print(score)
    print(i_tmp+1)
### BUGGY CODE ###

N = int(input())
list6 = [6**x for x in range(0,7) ]
list9 = [9**x for x in range(0,6) ]

def f(x):
    if x < 6:
        return x
    else:
        max6 = max(y for y in list6 if y <= x)
        max9 = max(y for y in list9 if y <= x)
        x6 = x - max6
        x9 = x - max9
        return min(f(x6)+ 1,f(x9)+ 1)

print(f(N))

### FIXED CODE ###

N = int(input())
list6 = [6**x for x in range(0,7) ]
list9 = [9**x for x in range(0,6) ]
result = {}

def f(x):
    if x < 6:
        return x
    elif x in result:
        return result[x] 
    else:
        max6 = max(y for y in list6 if y <= x)
        max9 = max(y for y in list9 if y <= x)
        x6 = x - max6
        x9 = x - max9
        result[x] = min(f(x6)+ 1,f(x9)+ 1)
        return result[x]

print(f(N))
### BUGGY CODE ###

N,M=map(int, raw_input().split())

NG=[ 0 for i in range(N+1) ]
for i in range(M):
	a=input()
	NG[a]=1

dp=[ 0 for i in range(N+1) ]
dp[0]=1

mod=10**9+7

for i in range(N):
	if i+1<=N and NG[i+1]==0:
		dp[i+1]+=dp[i]
		dp[i+1]%=mod
	if  i+2<=N and NG[i+2]==0:
		dp[i+2]+=dp[i]
		dp[i+2]%=mod

print dp[N]%mod


### FIXED CODE ###

import sys
N,M=map(int, raw_input().split())

NG=[ 0 for i in range(N+1) ]
for i in range(M):
	a=int( sys.stdin.readline().strip() )
	NG[a]=1

dp=[ 0 for i in range(N+1) ]
dp[0]=1

mod=10**9+7

for i in range(N):
	if i+1<=N and NG[i+1]==0:
		dp[i+1]+=dp[i]
		dp[i+1]%=mod
	if  i+2<=N and NG[i+2]==0:
		dp[i+2]+=dp[i]
		dp[i+2]%=mod

print dp[N]%mod
### BUGGY CODE ###

import math


def n_choose_r(n,r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n-r)


n = int(raw_input())
nums = map(int, raw_input().split())

top = max(nums)
best_value = 0
for x in nums:
    if x == top:
        continue
        
    val = n_choose_r(top, x)
    if val > best_value:
        best_value = val
        bottom = x

print "{} {}".format(top, bottom)


### FIXED CODE ###

import bisect


def get_closest(nums, target):
    pos = bisect.bisect_left(nums, target)
    if pos == 0:
        return nums[0]
    if pos == len(nums):
        return nums[-1]

    before = nums[pos - 1]
    after = nums[pos]

    if target in [before, after]:
        return target

    if after - target < target - before:
        return after
    else:
        return before


n = int(raw_input())
nums = map(int, raw_input().split())

nums = sorted(nums)
top = nums[-1]
nums.remove(top)

if top % 2 == 0:
    optimal = top / 2
    bottom = get_closest(nums, optimal)
else:
    res1 = get_closest(nums, top / 2)
    res2 = get_closest(nums, (top + 1) / 2)

    if abs(res1 - (top/2)) < abs(res2 - ((top + 1) / 2)):
        bottom = res1
    else:
        bottom = res2

print "{} {}".format(top, bottom)
### BUGGY CODE ###

N, Z, W = list(map(int, input().split()))
A = [W] + list(map(int, input().split()))

S = set(A)
GX = {s:[None]*N + [abs(A[N]-s)] for s in S}
GY = {s:[None]*N + [abs(A[N]-s)] for s in S}
minGX = {s:10**10 for s in S}
maxGY = {s:0      for s in S}

#for s in S:
#    GX[s][N-1] = GY[A[N-1]][N]
#    GY[s][N-1] = GX[A[N-1]][N]

for k in range(N-1, -1, -1):
    ak = A[k]
    for s in S:
        GX[s][k] = max(GY[ak][k+1], maxGY[ak])
        GY[s][k] = min(GX[ak][k+1], minGX[ak])

    for s in S:
        maxGY[s] = max(GY[s][k+1], maxGY[s])
        minGX[s] = min(GX[s][k+1], minGX[s])

print(GX[W][0])

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, Z, W = list(map(int, input().split()))
A = [W] + list(map(int, input().split())) # A[0]=W, A[i]=ai

GX = [None]*N # GX[i] := YがA[i] を取った直後の状況から到達しうる最大のスコア
GY = [None]*N # GY[i] := XがA[i] を取った直後の状況から到達しうる最小のスコア
minGX = 10**20
maxGY = 0

for k in range(N-1, -1, -1):
    GX[k] = max(abs(A[k]-A[N]), maxGY)
    GY[k] = min(abs(A[k]-A[N]), minGX)
    minGX = min(minGX, GX[k])
    maxGY = max(maxGY, GY[k])

print(GX[0])
### BUGGY CODE ###

h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=[]


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.append([a,b])


hcnt,wcnt=max(hlist),max(wlist)

hh,ww=[],[]
hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in range(1,h+1):
  if hlist[i]==hcnt:
    hh+=[i]

for i in range(1,w+1):
  if wlist[i]==wcnt:
    ww+=[i]

for i in hh:
  for j in ww:
    if [i,j] not in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)

### FIXED CODE ###

h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if not (i,j) in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)
### BUGGY CODE ###

import numpy as np
import sys

next(sys.stdin)
n = np.array(list(map(int, next(sys.stdin).split())))
j = np.arange(len(n)) + 1

while True:
    k = n.argmin()
    n = np.hstack((n[k:], n[:k]))

    if np.all(n >= j):
        n -= j
    elif np.all(n == 0):
        print('YES')
        break
    else:
        print('NO')
        break


### FIXED CODE ###

import numpy as np
import sys

n = int(next(sys.stdin))
a = np.array(list(map(int, next(sys.stdin).split())))
j = np.arange(n) + 1

if np.any(a.sum() % j.sum() > 0):
    print('NO')
    exit()

s = a.sum() // j.sum()
k = s - (a[1:] - a[:-1])
if np.all(k >= 0) and np.all(k % n == 0):
    print('YES')
else:
    print('NO')