CodeEff/ECCO huggingface dataset:
# Original solution
# your code goes here
N,C = list(map(int,input().split()))
D = [list(map(int,input().split())) for i in range(C)]
c = [list(map(int,input().split())) for i in range(N)]

ans = 1145141919810
for i in range(C):
	for j in range(C):
		if j == i:
			continue
		for k in range(C):
			if k == i or k == j:
				continue
			tmp = 0
			for x in range(N):
				for y in range(N):
					if (x+y+2)%3==2:
						tmp+= D[c[x][y]-1][i]
					elif (x+y+2)%3==0:
						tmp+= D[c[x][y]-1][j]
					else:
						tmp+= D[c[x][y]-1][k]
			ans = min(ans,tmp)
print(ans)


# Optimized solution
# your code goes here
N,C = list(map(int,input().split()))
D = [list(map(int,input().split())) for i in range(C)]
c = [list(map(int,input().split())) for i in range(N)]

Color = [[0 for i in range(C)] for j in range(3)]

for x in range(N):
	for y in range(N):
		Color[(x+y+2)%3][c[x][y]-1] += 1

ans = 1145141919810
for i in range(C):
	for j in range(C):
		if j == i:
			continue
		for k in range(C):
			if k == i or k == j:
				continue
			tmp = 0
			for x in range(3):
				for y in range(C):
					if x == 0:
						tmp += Color[x][y]*D[y][i]
					elif x == 1:
						tmp += Color[x][y]*D[y][j]
					else:
						tmp += Color[x][y]*D[y][k]
			ans = min(ans,tmp)
print(ans)
# Original solution
N,C=list(map(int,input().split(' ')))
D=[]
for _ in range(C):
  D.append([ x for x in map(int,input().split(' '))])

c=[]
for _ in range(N):
  c.append([ x for x in map(int,input().split(' '))])

x=float('inf')

for seq in [[0,1,2],[0,2,1],[1,0,2],[1,2,0],[2,0,1],[2,1,0]]:
  counter=[[0]*C for _ in range(3)]
  for i in range(N):
    for j in range(N):
      b=i%3
      cur=c[i][j]
      counter[seq[(j+b)%3]][cur-1]+=1
      #s+=D[cur-1][seq[(j+b)%3]]
  for c0 in range(C):
    for c1 in range(C):
      if c1==c0:
        continue
      for c2 in range(C):
        if c2==c0 or c2==c1:
          continue
        s=0
        for i, cx in enumerate(counter[0]):
          s+=D[i][c0]*cx
        for i, cx in enumerate(counter[1]):
          s+=D[i][c1]*cx
        for i, cx in enumerate(counter[2]):
          s+=D[i][c2]*cx
        if s<x:
          x=s

print(x)



# Optimized solution
N,C=list(map(int,input().split(' ')))
D=[]
for _ in range(C):
  D.append([ x for x in map(int,input().split(' '))])

c=[]
for _ in range(N):
  c.append([ x for x in map(int,input().split(' '))])

x=float('inf')

memo={}

counter=[[0]*C for _ in range(3)]
for i in range(N):
  for j in range(N):
    b=i%3
    cur=c[i][j]
    counter[(j+b)%3][cur-1]+=1
    #s+=D[cur-1][seq[(j+b)%3]]

for c0 in range(C):
  for c1 in range(C):
    if c1==c0:
      continue
    for c2 in range(C):
      if c2==c0 or c2==c1:
        continue
      s=0
      for i, cx in enumerate(counter[0]):
        s+=D[i][c0]*cx
      for i, cx in enumerate(counter[1]):
        s+=D[i][c1]*cx
      for i, cx in enumerate(counter[2]):
        s+=D[i][c2]*cx
      if s<x:
        x=s


print(x)
# Original solution
from itertools import *

N,C=list(map(int,input().split()))
D=[list(map(int,input().split())) for i in range(C)]
c=[list(map(int,input().split())) for i in range(N)]

lst=[[],[],[]]

for y in range(N):
    for x in range(N):
        lst[(y+x)%3].append(c[y][x])


Revalue=10**18
for Color1,Color2,Color3 in list(permutations(list(range(1,C+1)),3)):
    value=0
    for i in lst[0]:
        value+=D[i-1][Color1-1]
    for i in lst[1]:
        value+=D[i-1][Color2-1]
    for i in lst[2]:
        value+=D[i-1][Color3-1]
    Revalue=min(Revalue,value)
print(Revalue)


# Optimized solution
from itertools import *
N,C=list(map(int,input().split()))
D=[list(map(int,input().split())) for i in range(C)]
c=[list(map(int,input().split())) for i in range(N)]

lst=[[],[],[]]

for y in range(N):
    for x in range(N):
        lst[(y+x)%3].append(c[y][x])


Revalue=10**18

valuelst=[[0 for i in range(C)] for i in range(3)]
for v in range(3):
    for Color in range(1,C+1):
        value=0
        for i in lst[v]:
            value+=D[i-1][Color-1]
        valuelst[v][Color-1]=value


for Color1,Color2,Color3 in list(permutations(list(range(1,C+1)),3)):
    value=valuelst[0][Color1-1]+valuelst[1][Color2-1]+valuelst[2][Color3-1]

    Revalue=min(Revalue,value)
print(Revalue)
# Original solution
N,C = list(map(int,input().split()))
D = []
for i in range(C):
    D.append(list(map(int,input().split())))
G = []
for i in range(N):
    G.append(list(map(int,input().split())))

X = [[] for i in range(3)]
for i in range(N):
    for j in range(N):
        X[(i+j+2)%3].append(G[i][j])
ans = float('inf')
for c1 in range(C):
    for c2 in range(C):
        if c1 == c2:
            continue
        for c3 in range(C):
            if c1 == c3 or c2 == c3:
                continue
            cost = 0
            for i,x in enumerate(X):
                for e in x:
                    if i == 0:
                        cost += D[e-1][c1]
                    elif i == 1:
                        cost += D[e-1][c2]
                    else:
                        cost += D[e-1][c3]
            ans = min(cost,ans)
print(ans)



# Optimized solution
N,C = list(map(int,input().split()))
D = []
for i in range(C):
    D.append(list(map(int,input().split())))
G = []
for i in range(N):
    G.append(list(map(int,input().split())))

X = [[] for i in range(3)]
for i in range(N):
    for j in range(N):
        X[(i+j+2)%3].append(G[i][j])
ans = float('inf')

Costs = [[0 for i in range(C)] for j in range(3)]

for c in range(C):
    for i in range(3):
        for e in X[i]:
            Costs[i][c] += D[e-1][c]

for c1 in range(C):
    for c2 in range(C):
        if c1 == c2:
            continue
        for c3 in range(C):
            if c1 == c3 or c2 == c3:
                continue
            cost = 0
            for i,e in enumerate([c1,c2,c3]):
                cost += Costs[i][e]
            ans = min(cost,ans)
print(ans)
# Original solution
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n,c = list(map(int,input().split()))
D = [list(map(int,input().split())) for _ in range(c)]
C = [list(map(int,input().split())) for _ in range(n)]
ans = inf
for (a,b,c) in permutations(list(range(c)),3):
    cur = 0
    for i in range(n):
        for j in range(n):
            if (i+j)%3 == 0:
                cur += D[C[i][j]-1][a]
            elif (i+j)%3 == 1:
                cur += D[C[i][j]-1][b]
            else:
                cur += D[C[i][j]-1][c]
    ans = min(ans,cur)
print(ans)


# Optimized solution
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n,c = list(map(int,input().split()))
D = [list(map(int,input().split())) for _ in range(c)]
C = [list(map(int,input().split())) for _ in range(n)]
C0,C1,C2 = [0]*c,[0]*c,[0]*c
for i in range(n):
    for j in range(n):
        if (i+j)%3 == 0:
            C0[C[i][j]-1] += 1
        elif (i+j)%3 == 1:
            C1[C[i][j]-1] += 1
        else:
            C2[C[i][j]-1] += 1
ans = inf
for (i,j,k) in permutations(list(range(c)),3):
    cur = 0
    for l in range(c):
        cur += D[l][i]*C0[l]+D[l][j]*C1[l]+D[l][k]*C2[l]
    ans = min(ans,cur)
print(ans)
# Original solution
N, C = list(map(int,input().split()))
D = [0] * C
for i in range(C):
    t = list(map(int,input().split()))
    D[i] = t
c = [0] * N
for i in range(N):
    t = list(map(int,input().split()))
    c[i] = t
Dsum = [0] * C
for k in range(C):
    ccc = [0, 0, 0]
    for i in range(N):
        for j in range(N):
            ccc[(i+j)%3] += D[c[i][j]-1][k]
    Dsum[k] = ccc
ans = 9876543210
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i != j and j != k and k != i:
                ans = min(ans, Dsum[i][0]+Dsum[j][1]+Dsum[k][2])
print(ans)

# Optimized solution
N, C = list(map(int,input().split()))
D = []
for i in range(C):
    t = list(map(int,input().split()))
    D.append(t)
c = []
for i in range(N):
    t = list(map(int,input().split()))
    c.append(t)
Dsum = []
for k in range(C):
    ccc = [0, 0, 0]
    for i in range(N):
        for j in range(N):
            ccc[(i+j)%3] += D[c[i][j]-1][k]
    Dsum.append(ccc)
ans = 9876543210
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i != j and j != k and k != i:
                ans = min(ans, Dsum[i][0]+Dsum[j][1]+Dsum[k][2])
print(ans)
# Original solution
N, C = list(map(int, input().split()))
 
D = [ [int(i) for i in input().split()] for _ in range(C) ]
c = [ [int(i) for i in input().split()] for _ in range(N) ]
 
costD = [ [0, 0, 0] for _ in range(C)]
 
for c0 in range(C):
    for i in range(N):
        for j in range(N):
            costD[c0][(i+j)%3] += D[c[i][j]-1][c0]
 
kohoD = []
 
for c1 in range(C):
    for c2 in range(C):
        if c1 == c2:
            continue
        for c3 in range(C):
            if c1 == c3 or c2 == c3:
                continue
            kohoD += [(costD[c1][0] + costD[c2][1] + costD[c3][2])]
 
print((min(kohoD)))

# Optimized solution
import itertools
 
 
def main():
    N, C = list(map(int, input().split()))
    D = [list(map(int, input().split())) for _ in range(C)]
    CC = [list([int(x) - 1 for x in input().split()]) for _ in range(N)]
 
    cost = [[0 for _ in range(C)] for _ in range(3)]
    for c in range(C):
        for i in range(N):
            for j in range(N):
                cost[(i + j) % 3][c] += D[CC[i][j]][c]
 
    res = float("inf")
    color = [i for i in range(C)]
    for i, c in enumerate(list(itertools.permutations(color, 3))):
        tmp = 0
        for it in range(3):
            tmp += cost[it][c[it]]
        res = min(res, tmp)
 
    print(res)
 
main()
# Original solution
N,C = list(map(int,input().split()))
D = [list(map(int,input().split())) for i in range(C)]
L = [list(map(int,input().split())) for i in range(N)]

d0 = {}
d1 = {}
d2 = {}

for i in range(N) :
    for j in range(N) :
        before = L[i][j] - 1
        
        if (i+j) % 3 == 0 :
            if before not in d0 :
                d0[before] = 1
            else :
                d0[before] += 1

        elif (i+j) % 3 == 1 :
            if before not in d1 :
                d1[before] = 1
            else :
                d1[before] += 1

        else :
            if before not in d2 :
                d2[before] = 1
            else :
                d2[before] += 1


B = []

for d in [d0,d1,d2] :
    A = []
    for after in range(C) :
        calc = 0
        for before in d :
            calc += D[before][after] * d[before]
        A.append([calc,after])

    A = sorted(A,key=lambda x:x[0],reverse=False)[:3]
    B.append(A)
    
    

ans = float("inf")

for i in range(3) :
    for j in range(3) :
        for k in range(3) :
            if (B[0][i][1] - B[1][j][1]) * (B[1][j][1] - B[2][k][1]) * (B[2][k][1] - B[0][i][1]) == 0 :
                continue
            
            ans = min(ans, B[0][i][0] + B[1][j][0] + B[2][k][0])

print(ans)


# Optimized solution
N,C = list(map(int,input().split()))
D = [list(map(int,input().split())) for i in range(C)]
L = [list(map(int,input().split())) for i in range(N)]

di = [{}, {}, {}]

for i in range(N) :
    for j in range(N) :
        num = (i+j) % 3
        before = L[i][j] - 1
        
        if before not in di[num] :
            di[num][before] = 1
        else :
            di[num][before] += 1

B = []

for d in di :
    A = []
    for after in range(C) :
        calc = 0
        for before in d :
            calc += D[before][after] * d[before]
        A.append([calc,after])

    A = sorted(A,key=lambda x:x[0],reverse=False)[:3]
    B.append(A)
    
ans = float("inf")

for i in range(3) :
    for j in range(3) :
        for k in range(3) :
            if (B[0][i][1] - B[1][j][1]) * (B[1][j][1] - B[2][k][1]) * (B[2][k][1] - B[0][i][1]) == 0 :
                continue
            
            ans = min(ans, B[0][i][0] + B[1][j][0] + B[2][k][0])

print(ans)
# Original solution
import itertools

N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for i in range(C)]
c = [list(map(int, input().split())) for i in range(N)]

# 全探索だと間に合わない
# 一旦実装だけしてみる
corres = list(itertools.permutations(list(range(C)), 3))
ans = float('inf')
indices = [2, 0, 1]
for corr in corres:
  cost = 0
  for i in range(N):
    idx = indices[i%3]
    for j in range(N):
      cost += D[c[i][j]-1][corr[idx]]
      idx = (idx + 1) % 3
  ans = min(ans, cost)

print(ans)

# Optimized solution
N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for i in range(C)]
c = [list(map(int, input().split())) for i in range(N)]

cost0 = []
cost1 = []
cost2 = []
indices = [2, 0, 1]
for color in range(C):
  cost = [0, 0, 0]
  for i in range(N):
    idx = indices[i%3]
    for j in range(N):
      cost[idx] += D[c[i][j]-1][color]
      idx = (idx + 1) % 3
  cost0.append([cost[0], color])
  cost1.append([cost[1], color])
  cost2.append([cost[2], color])

cost0.sort()
cost1.sort()
cost2.sort()
ans = float('inf')
for i in range(3):
  for j in range(3):
    for k in range(3):
      if len(set([cost0[i][1], cost1[j][1], cost2[k][1]])) == 3:
        ans = min(ans, cost0[i][0]+cost1[j][0]+cost2[k][0])

print(ans)
# Original solution
n,m=list(map(int,input().split()))
d=[list((list(map(int,input().split())))) for _ in range(m)]
c=[list((list(map(int,input().split())))) for _ in range(n)]
x=[[[True for _ in range(n)] for _ in range(n)] for _ in range(m)]
for k in range(m):
    for i in range(n):
        for j in range(n):
            if c[i][j]==k+1:
                x[k][i][j]=False
res=[]
for c1 in range(m):
    for c2 in range(m):
        for c3 in range(m):
            if c1==c2 or c2==c3 or c1==c3:
                pass
            else:
                t=0
                for i in range(n):
                    for j in range(n):
                        if (i+j)%3==0:
                            if x[c1][i][j]:
                                t+=d[c[i][j]-1][c1]
                        if (i+j)%3==1:
                            if x[c2][i][j]:
                                t+=d[c[i][j]-1][c2]
                        if (i+j)%3==2:
                            if x[c3][i][j]:
                                t+=d[c[i][j]-1][c3]
                res.append(t)
print((min(res)))

# Optimized solution
n,m=list(map(int,input().split()))
d=[list((list(map(int,input().split())))) for _ in range(m)]
c=[list((list(map(int,input().split())))) for _ in range(n)]
x=[[0 for _ in range(m)] for _ in range(3)]

for i in range(n):
    for j in range(n):
        x[(i+j)%3][c[i][j]-1]+=1
res=[]
for c1 in range(m):
    for c2 in range(m):
        for c3 in range(m):
            if c1==c2 or c2==c3 or c1==c3:
                pass
            else:
                ans=0
                for i in range(m):
                    ans+=x[0][i]*d[i][c1]
                for i in range(m):
                    ans+=x[1][i]*d[i][c2]
                for i in range(m):
                    ans+=x[2][i]*d[i][c3]
                res.append(ans)
print((min(res)))
# Original solution
import itertools
N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in range(C)]
G = [list(map(int, input().split())) for _ in range(N)]
count_color = [[0 for _ in range(C+1)] for _ in range(3)]
for y in range(N):
  for x in range(N):
    count_color[(x+y)%3][G[y][x]] += 1
ans = 10**12
for colors in itertools.permutations(list(range(1, C+1)), 3):
  iwakan = 0
  for mod in range(3):
    for c in range(1, C+1):
      iwakan += D[c-1][colors[mod]-1]*count_color[mod][c]
  if iwakan < ans:
    ans = iwakan
print(ans)



# Optimized solution
N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for _ in range(C)]
G = [list(map(int, input().split())) for _ in range(N)]
GC = []
GC.append([0]*C)
GC.append([0]*C)
GC.append([0]*C)
for y in range(N):
  for x in range(N):
    GC[(y+x)%3][G[y][x]-1] += 1
ans = 1000000000
for a in range(C):
  for b in range(C):
    if a == b:
      continue
    for c in range(C):
      if a == c or b == c:
        continue
      cost = 0
      for i in range(C):
        cost += GC[0][i]*D[i][a]
        cost += GC[1][i]*D[i][b]
        cost += GC[2][i]*D[i][c]
      ans = min(ans, cost)
print(ans)
# Original solution
import sys

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split()))

ans = 0
for i in range(N):
    if i % 2 == 0 and A[i] % 2 == 1:
        ans += 1

print(ans)

# Optimized solution
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

ans = 0
for i in range(N):
    if i % 2 == 0 and A[i] % 2 == 1:
        ans += 1

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

cnt = 0

for i in range(N):
    if i%2 == 0 and A[i]%2 != 0:
        cnt += 1
    else:
        continue
print(cnt)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0

for i in range(0, N, 2):
    if A[i]%2 != 0:
       cnt += 1
print(cnt)
# Original solution
n = int(eval(input()))
S = list(map(int, input().split()))
ans = 0
for i in range(0, n, 2):
    if i%2 == 0 and S[i]%2 == 1:
        ans += 1
print(ans)


# Optimized solution
n = eval(input())
N = int(n)

list1 = input().split(" ")
Numbers = list1[:N]

count = 0
for i in range(0, N):
    if (i+1) % 2 != 0:
        if int(Numbers[i]) % 2 != 0:
            count += 1
    else:
        continue
print(count)
# Original solution
n,*l=list(map(int,open(0).read().split()))
c=0
for e,i in enumerate(l):
  c+=((e+1)*i)%2
print(c)

# Optimized solution
_,*l=list(map(int,open(0).read().split()));print((sum(-~e*i%2 for e,i in enumerate(l))))
# Original solution
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
ans = 0
for i in range(n):
    if (i+1) % 2:
        if a[i] % 2:
            ans += 1
print(ans)

# Optimized solution
#!/usr/bin/env python3

n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(0, n, 2):
    if a[i] % 2:
        ans += 1
print(ans)
# Original solution
print((sum([int(x)%2 for x in open(0).read().split()[1::2]])))

# Optimized solution
N, *A = list(map(int, open(0).read().split()))

print((len([a for a in A[::2] if a%2])))
# Original solution
N, *a = list(map(int, open(0).read().split()))

print((sum(1 for e in a[::2] if e % 2 == 1)))


# Optimized solution
N, *a = list(map(int, open(0).read().split()))

print((sum(e % 2 for e in a[::2])))
# Original solution
n = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
for i in range(n):
    if i %2 == 1:
        continue
    if A[i] % 2 == 1:
        ans += 1
print(ans)

# Optimized solution
n = eval(input())
ans = 0
for i,j in enumerate(map(int,input().split())):
    ans += (~i&1 and j&1)
print(ans)
# Original solution
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
MOD = (10 ** 9) + 7  # operować sobie na typie int32_t


def 関数(n, a):
    res = 0
    for i, num in enumerate(a):
        index = i + 1 
        if index % 2 and num % 2:
            res += 1
    return res

def çözmek():
    N = input()
    a = list(iimr())
    res = []
    res.append(関数(N,a))
    print(*res, sep="\n")

if __name__ == "__main__":
    çözmek()


# Optimized solution
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
MOD = (10 ** 9) + 7  # operować sobie na typie int32_t


def 関数(n, a):
    res = 0
    for i, num in enumerate(a):
        index = i + 1 
        index %= MOD
        if index % 2 and num % 2:
            res += 1
    return res

def çözmek():
    N = input()
    a = list(iimr())
    res = []
    res.append(関数(N,a))
    print(*res, sep="\n")

if __name__ == "__main__":
    çözmek()
# Original solution
eval(input())
print((len([i for n,i in enumerate(map(int,input().split()),1) if i%2==1 and n%2])))

# Optimized solution
eval(input())
print((len([i for i in list(map(int,input().split()))[::2] if i%2])))
# Original solution
N = int(eval(input()))
nombres = [int(x) for x in input().split()]
k = 0
for indexe,nombre in enumerate(nombres):
    if ((indexe + 1)%2 == 1 and nombre%2 == 1):
        k += 1
print(k)

# Optimized solution
n = int(eval(input()))
A = [int(x) for x in input().split()]
comp = 0
for el in range(0, n, 2):
    if A[el] % 2 != 0:
        comp += 1

print(comp)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
ans=0
for i in range(0, N, 2):
    if A[i]%2==1:
        ans+=1
print(ans)

# Optimized solution
n=int(eval(input()))
a=list(map(int, input().split()))
ans=0
for i in range(0,n,2):
  if a[i]%2==1:
    ans+=1
print(ans)
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(0, N):
    if (i+1) % 2 != 0 and a[i] % 2 != 0:
        cnt += 1
print(cnt)

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(0, N, 2):
    if a[i] % 2 != 0:
        cnt += 1
print(cnt)
# Original solution
class BIT():
    def __init__(self,number):
        self.n=number
        self.list=[0]*(number+1)
        
    def add(self,i,x):#ith added x  1indexed
        while i<=self.n:
            self.list[i]+=x
            i+=i&-i
            
    def search(self,i):#1-i sum
        s=0
        while i>0:
            s+=self.list[i]
            i-=i&-i
        return s
    
    def suma(self,i,j):#i,i+1,..j sum
        return self.search(j)-self.search(i-1)
N=int(eval(input()))
A=[int(i) for i in input().split()]
if ((N*(N+1))//2)%2==1:
    a=((N*(N+1))//2)//2+1
else:
    a=((N*(N+1))//2)//2
#a=((N*(N+1))//2)-((N*(N+1))//2)//2-1
def f(s):#ans is ijou s
    X=[1 if a>=s else -1 for a in A]
    p=[0]*(N+1)
    for i in range(1,N+1):
        p[i]=p[i-1]+X[i-1]
    tree=BIT(2*N+1)
    num=0
    for i in range(1,N+2):
        num+=tree.search(p[i-1]+N+1)
        tree.add(p[i-1]+N+1,1)
    if num>=a:
        return True
    else:
        return False
x=10**9+1
y=-1
while x-y>1:
    mid=(x+y)//2
    if f(mid):
        y=mid
    else:
        x=mid
print(y)



# Optimized solution
class BIT():
    def __init__(self,number):
        self.n=number
        self.list=[0]*(number+1)
        
    def add(self,i,x):#ith added x  1indexed
        while i<=self.n:
            self.list[i]+=x
            i+=i&-i
            
    def search(self,i):#1-i sum
        s=0
        while i>0:
            s+=self.list[i]
            i-=i&-i
        return s
    
    def suma(self,i,j):#i,i+1,..j sum
        return self.search(j)-self.search(i-1)
N=int(eval(input()))
A=[int(i) for i in input().split()]
if ((N*(N+1))//2)%2==1:
    a=((N*(N+1))//2)//2+1
else:
    a=((N*(N+1))//2)//2
#a=((N*(N+1))//2)-((N*(N+1))//2)//2-1
def f(s):#ans is ijou s
    X=[1 if a>=s else -1 for a in A]
    p=[0]*(N+1)
    ma=0
    mi=0
    for i in range(1,N+1):
        p[i]=p[i-1]+X[i-1]
        ma=max(p[i],ma)
        mi=min(p[i],mi)
    tree=BIT(ma-mi+1)
    num=0
    for i in range(1,N+2):
        num+=tree.search(p[i-1]-mi+1)
        tree.add(p[i-1]-mi+1,1)
    if num>=a:
        return True
    else:
        return False
x=10**9+1
y=-1
while x-y>1:
    mid=(x+y)//2
    if f(mid):
        y=mid
    else:
        x=mid
print(y)