def solve(N, AS):
m = max(AS)
count = 0
ret = None
for k in range(2, m + 1):
v = sum(1 for a in AS if a % k == 0)
if v > count:
ret = k
count = v
return ret
def solve(N):
total = sum(N) % 3
if total == 0:
return 0
if len(N) == 1:
return -1
from collections import Counter
xs = Counter(x % 3 for x in N)
if xs[total]:
return 1
if len(N) == 2:
return -1
if xs[1] > 1 or xs[2] > 1:
return 2
return -1
def solve(N, AS):
pos = 0
dpos = 0
maxdpos = 0
ret = 0
for a in AS:
dpos += a
if dpos > maxdpos:
maxdpos = dpos
if pos + maxdpos > ret:
ret = pos + maxdpos
pos += dpos
return ret
def solve(H, W, mapdata):
maph = mapdata[:]
for y in range(H):
ypos = y * W
for x in range(1, W):
pos = ypos + x
if maph[pos] == 0 and maph[pos - 1] == 1:
maph[pos] = 1
for x in range(W - 2, -1, -1):
pos = ypos + x
if maph[pos] == 0 and maph[pos + 1] == 1:
maph[pos] = 1
mapv = mapdata[:]
for x in range(W):
for y in range(1, H):
pos = y * W + x
if mapv[pos] == 0 and mapv[pos - W] == 1:
mapv[pos] = 1
for y in range(H - 2, -1, -1):
pos = y * W + x
if mapv[pos] == 0 and mapv[pos + W] == 1:
mapv[pos] = 1
ret = 0
for i in range(W * H):
if maph[i] == 1 or mapv[i] == 1:
ret += 1
return ret