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

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0
  for i in range(h):
    for j in range(w):

      q=collections.deque()
      if field[i][j]=='#':
        visited=[[False]*w for _ in range(h)]
        q.append((i,j))
        while q:
          y,x=q.popleft()
          visited[y][x]=True
          for dy,dx in dd:
            ny=y+dy
            nx=x+dx

            if 0<=ny<h and 0<=nx<w:
              if visited[ny][nx]:
                continue
              if field[ny][nx]=='#':
                continue
              visited[ny][nx]=True #忘れがち
              # print(i,j,ny,nx)
              ans+=1
              for ddy,ddx in dd:
                nny=ny+ddy
                nnx=nx+ddx
                if 0<=nny<h and 0<=nnx<w:
                  if visited[nny][nnx]:
                    continue
                  if field[nny][nnx]=='.':
                    continue
                  q.append((nny,nnx))

      # print(ans)
  return ans

# main()
print(main())


### FIXED CODE ###

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0
  visited=[[False]*w for _ in range(h)]
  for i in range(h):
    for j in range(w):
      if visited[i][j]:
        continue
      if field[i][j]!='#':
        continue
      q=collections.deque()
      q.append((i,j))
      b=0
      wh=0
      while q:
        y,x=q.popleft()
        if visited[y][x]:
          continue
        if field[y][x]=='#':
          b+=1
        else:
          wh+=1
        visited[y][x]=True
        for dy,dx in dd:
          ny=y+dy
          nx=x+dx
          if not (0<=ny<h and 0<=nx<w):
            continue
          if field[y][x]==field[ny][nx]:
            continue
          if visited[ny][nx]:
            continue
          q.append((ny,nx))
      ans+=b*wh
      # print(i,j,b,wh,ans)
  return ans

# main()
print(main())
### BUGGY CODE ###

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

ans = []
front_max = back_max = 0

for i in reversed(range(N)):
    now = A.pop()
    front_max = max(A) if A else 0
    ans.append(max(front_max, back_max))
    back_max = max(now, back_max)

for i in reversed(range(N)):
    print(ans[i])


### FIXED CODE ###

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

ans = []
front_max_list, back_max_list = [0], [0]

for i in range(N):
    front_max_list.append(max(front_max_list[i], A[i]))
    back_max_list.append(max(back_max_list[i], A[N - i - 1]))

for i in range(N):
    print(max(front_max_list[i], back_max_list[N - i - 1]))
### BUGGY CODE ###

import math
a,b,n = map(int,input().split())
m = 0
x = 1
ax = a*x
while ax/b <0.01:
    x*=10
    ax = a*x
    if x>n:
        x//10
        break
if a-b==1:
    print(n)
elif b-a==1:
    print(n-1)
else:
    for i in range(x,n+1):
        ch = math.floor(a*i/b)-a*math.floor(i/b)
        m = max(m,ch)
        if m!=0 and ch==0:
            break
    print(m)

### FIXED CODE ###

import math
a,b,n = map(int,input().split())
x = min(b-1,n)
print(math.floor(a*x/b)-a*math.floor(x/b))
### BUGGY CODE ###

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
         
n = [1, 1]
cnt = 2
while cnt!=N+1:
    if cnt-2 in a:n[0]=0
    if cnt-1 in a:n[1]=0
    n[0], n[1] = n[1], n[0]+n[1] 
    cnt += 1

print(n[-1]%(10**9+7))

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

broken= [False]*(N+1)
for i in range(M):
    broken[int(input())] = True

dp = [0]*(N+1)
dp[0] = 1
if not broken[1]:dp[1] = 1

         
for i in range(2, N+1):
    if broken[i]:continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= (10**9 + 7)
print(dp[N])
### BUGGY CODE ###

import itertools
X = int(input())
price=[100,101,102,103,104,105]
num = int(X / 100)
state=False
for i in range(1,num+1):
    for j in itertools.combinations_with_replacement(price, i):
        if sum(j) == X:
            print(1)
            state=True
            exit()
if state != True:
    print(0)

### FIXED CODE ###

import itertools
X = int(input())
price=[100,101,102,103,104,105]
num = int(X / 100)
state=False
for i in range(num,0,-1):
    for j in itertools.combinations_with_replacement(price, i):
        if sum(j) == X:
            print(1)
            state=True
            exit()
if state != True:
    print(0)
### BUGGY CODE ###


def main():
    [n, k] = [int(x) for x in input().split()]
    arr = [int(x) for x in input().split()]

    temp = 1
    for i in range(k):
        temp *= arr[i]

    t = temp
    for i in range(k, n):
        t  = (temp // arr[i-k])
        t *= arr[i]
        if t > temp:
            print('Yes')
        else:
            print('No')

        temp = t


main()



### FIXED CODE ###

def main():
    [n, k] = [int(x) for x in input().split()]
    arr = [int(x) for x in input().split()]

    for i in range(k, n):
        if arr[i-k] >= arr[i]:
            print('No')
        else:
            print('Yes')



main()
### BUGGY CODE ###

N = int(input())

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

ans = 1
for i in range(N):
    ans *= A[i]

if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!

def main():
    N = int(input())
    A = list(map(int,input().split()))
    
    if 0 in A:
        print(0)
        return
        
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 1000000000000000000:
            print(-1)
            return
    
    print(ans)

main()
### BUGGY CODE ###

import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())


def FLIST(n):
    res = [1]
    for i in range(1, n+1):
        res.append(res[i-1]*i % DVSR)
    return res


N = II()
AS = LI()
DP = {}
DP[(0, 0)] = 0

mm = -(10**18)
for i in range(N):
    NX = {}
    for ((cnt, isUsed), value) in DP.items():
        if isUsed:
            if cnt >= (i // 2 - 5):
                NX[(cnt, 0)] = max(value, NX.get((cnt, 0)) or mm)
        else:
            if cnt >= (i // 2 - 5):
                NX[(cnt, 0)] = max(value, NX.get((cnt, 0)) or mm)
            if cnt >= (i // 2 - 5):
                NX[(cnt+1, 1)] = max(value + AS[i],
                                     NX.get((cnt+1, 1)) or mm)
    DP = NX

res = -(10**18)
for ((cnt, _), value) in DP.items():
    if cnt == N//2:
        res = max(res, value)
print(res)


### FIXED CODE ###

import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())


def FLIST(n):
    res = [1]
    for i in range(1, n+1):
        res.append(res[i-1]*i % DVSR)
    return res


N = II()
AS = LI()
DP = {}
DP[(0, 0)] = 0

mm = -(10**18)
for i in range(N):
    NX = {}
    for ((cnt, isUsed), value) in DP.items():
        if isUsed:
            if cnt >= (i // 2 - 5):
                NX[(cnt, 0)] = max(value, NX.get((cnt, 0)) or mm)
        else:
            if cnt >= (i // 2 - 5):
                NX[(cnt, 0)] = max(value, NX.get((cnt, 0)) or mm)
            if cnt >= (i // 2 - 5):
                NX[(cnt+1, 1)] = max(value + AS[i],
                                     NX.get((cnt+1, 1)) or mm)
    DP = NX
    # print(NX)

res = -(10**18)
for ((cnt, _), value) in DP.items():
    if cnt == N//2:
        res = max(res, value)
print(res)
### BUGGY CODE ###

def main():
    S = input()
    Q = int(input())
    t = [-1] * Q
    f = [-1] * Q
    c = [""] * Q
    for i in range(Q):
        query = input()
        if len(query)==1:
            t[i] = 1
        else:
            tmp = list(query.split())
            t[i] = int(tmp[0])
            f[i] = int(tmp[1])
            c[i] = tmp[2]

    ans = S
    for i in range(Q):
        if t[i]==1:
            ans = ans[::-1]
        else:
            if f[i]==1:
                ans = c[i]+ans
            else:
                ans = ans+c[i]
    print(ans)

main()


### FIXED CODE ###

def main():
    S = input()
    Q = int(input())
    rev = False # rev=1で反転した状態
    tail = ""
    head = ""
    for i in range(Q):
        query = input()
        if len(query)==1:
            rev = not rev
        else:
            tmp = list(query.split())
            f = int(tmp[1])
            c = tmp[2]
            if rev:
                if f==1:
                    tail+=c
                else:
                    head=c+head
            else:
                if f==1:
                    head=c+head
                else:
                    tail+=c

    ans = tail[::-1]+S[::-1]+head[::-1] if rev else head+S+tail
    print(ans)

main()
### BUGGY CODE ###

n = int(input())

a = []
b = []

for i in range(n):
    aa, bb = map(int, input().split(' '))
    a.append(aa)
    b.append(bb)

order = list(range(n))
tmp_b = b[:]

while(True):
    ok = False
    for i in range(n - 1):
        ok = False
        if tmp_b[i] > tmp_b[i + 1]:
            tmp = tmp_b[i]
            tmp_b[i] = tmp_b[i + 1]
            tmp_b[i + 1] = tmp

            tmp = order[i]
            order[i] = order[i + 1]
            order[i + 1] = tmp
            break
        ok = True
    if ok:
        break

available = False

for i in range(100):

    margin = [0 for i in range(n)]
    now_time = 0
    for i in range(n):
        j = order[i]
        margin[j] = b[j] - (now_time + a[j])
        now_time += a[j]
    
    if min(margin) >= 0:
        available = True
        break
    else:
        min_index = margin.index(min(margin))
        max_index = margin.index(max(margin))

        tmp = order[min_index]
        order[min_index] = order[max_index]
        order[max_index] = tmp


if available:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n = int(input())

a = []
b = []

for i in range(n):
    aa, bb = map(int, input().split(' '))
    a.append(aa)
    b.append(bb)

order = sorted(range(len(b)), key=lambda k: b[k])

available = False


margin = [0 for i in range(n)]
now_time = 0
for i in range(n):
    j = order[i]
    margin[j] = b[j] - (now_time + a[j])
    now_time += a[j]

if min(margin) >= 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

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

for i in range(Q):
    l,r = map(int,input().split())
    ans = S[l-1:r].count('AC')
    print(ans)

### FIXED CODE ###

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

csum = [0,0]
for i in range(1, N):
    if S[i-1] + S[i] == 'AC':
        csum.append(csum[i-1] + 1)
    else:
        csum.append(csum[i])
        
#文字番号に合わせた形になっている
for i in range(Q):
    l, r = map(int, input().split())
    print(csum[r]-csum[l])
### BUGGY CODE ###

N = int(input())

S = []
for i in range(N):
    S.append(input())
    
V = []
for i in S:
    V.append(S.count(i))

W = []
for i in range(N):
    if V[i] == max(V):
        W.append(S[i])

W = list(set(W))
W.sort()

for i in W:
    print(i)

### FIXED CODE ###

import collections as clcts

N = int(input())

V = []
for i in range(N):
    V.append(input())

P = clcts.Counter(V)

W = max(P.values())
A = [i for i, j in P.items() if j == W]
A.sort()

for i in A:
    print(i)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    S = input()
    Q = INT()
    reverse_flag = False

    for _ in range(Q):
        query = list(input().split())
        if len(query) == 3:
            F = int(query[1])
            C = query[2]
            if F == 1:
                if reverse_flag:
                    S += C
                else:
                    S = C + S
            elif F == 2:
                if reverse_flag:
                    S = C + S
                else:
                    S += C
        else:
            if reverse_flag:
                reverse_flag = False
            else:
                reverse_flag = True
    
    if reverse_flag:
        S = S[::-1]
    print(S)
    return
        
if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

from collections import deque
def main():
    S = input()
    queue = deque(list(S))
    Q = INT()
    reverse_flag = False

    for _ in range(Q):
        query = list(input().split())
        if len(query) == 3:
            F = int(query[1])
            C = query[2]
            if F == 1:
                if reverse_flag:
                    queue.append(C)
                else:
                    queue.appendleft(C)
            elif F == 2:
                if reverse_flag:
                    queue .appendleft(C)
                else:
                    queue.append(C)
        else:
            if reverse_flag:
                reverse_flag = False
            else:
                reverse_flag = True
    answer = ''.join(queue)
    if reverse_flag:
        answer = answer[::-1]
    print(answer)
    return
        
if __name__ == '__main__':
    main()
### BUGGY CODE ###

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import math
k = inn()
sm = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            sm += math.gcd(math.gcd(i,j),m)
print(sm)


### FIXED CODE ###

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

from math import gcd
k = inn()
sm = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        g = gcd(i,j)
        if g==1:
            sm += k
        else:
            for m in range(1,k+1):
                sm += gcd(g,m)
print(sm)
### BUGGY CODE ###

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
s=[0]*(n+1)
s[0]=1
for i in range(1,n+1):
    if a.count(i)!=0:
        s[i]=0
    else:
        if i-2>=0:
            s[i]+=s[i-1]+s[i-2]
        else:
            s[i]+=s[i-1]
print(s[n]%1000000007)
        


### FIXED CODE ###

n,m=map(int,input().split())
a=0
if m!=0:
    a=int(input())
    
b=1
s=[1]*(n+1)
for i in range(1,n+1):
    if i!=a:
        if i-2>=0:
            s[i]=(s[i-1]+s[i-2])%1000000007
        else:
            s[i]=s[i-1]%1000000007
    elif b!=m:
        s[i]=0
        a=int(input())
        b+=1
    else:
        s[i]=0
print(s[n])
### BUGGY CODE ###

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

dp = list([9e9] * (h + 1) for i in range(n + 1))
dp[0][0] = 0

for i in range(n):
  for j in range(h + 1):
    dp[i + 1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][min(j+a[i], h)] = min(dp[i+1][min(j+a[i], h)], dp[i+1][j] + b[i])

print(dp[n][h])



### FIXED CODE ###

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

dp = list([9e9] * (h + 1) for i in range(n + 1))
dp[0][0] = 0

for i in range(n):
  for j in range(h + 1):
    dp[i + 1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][min(j+a[i], h)] = min(dp[i+1][min(j+a[i], h)], dp[i+1][j] + b[i])

print(dp[n][h])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
i = 0
while i < N-1:
  
  if A[-1]%A[i]==0:
    A[-1] = 0
    i += 1
    A.sort()
  else:
    A[-1] = A[-1]%A[i]
    A.sort()
ans = A[-1]
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
g=A[0]
import fractions
for i in range(1,N):
  g = fractions.gcd(g,A[i])
print(g)
### BUGGY CODE ###

mod = 1000000007
def gcd(a, b):
    while(b > 0):
        a = a%b
        c = b
        b = a
        a = c
    return a

n = int(input())
s = input()

s = s.split(" ")

l = int(s[0])

for i in range(1, n):
    l = (l*int(s[i]))//gcd(l, int(s[i]))

ans = 0
for x in s:
    x = int(x)
    ans = (ans +l//x)%mod

print(ans%mod)




### FIXED CODE ###

def gcd(a, b):
    while(b > 0):
        a = a%b
        c = b
        b = a
        a = c
    return a

n = int(input())
s = input()

s = s.split(" ")
# for i s:
#     x = int(input())
#     arr.append(x)

l = int(s[0])

for i in range(1, n):
    l = (l*int(s[i]))//gcd(l, int(s[i]))

ans = 0
for x in s:
    x = int(x)
    ans += l//x

print(ans%1000000007)
### BUGGY CODE ###

K = int(input())
if K % 2 == 0:
  print(-1)
else:
  A = 7 % K
  X = 7 % K
  n = 1
  while A != 0:
    X = (X * 10) % K
    A = (A + X) % K
    n += 1
  print(n)

### FIXED CODE ###

K = int(input())
A = 7 % K
X = 7 % K
n = 1
f = 0
while A != 0:
  X = (X * 10) % K
  A = (A + X) % K
  n += 1
  if n > K:
    print(-1)
    f = 1
    break
if f == 0:
  print(n)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
dpm = [[0]*(K+1) for _ in range(N+1)]
dpm[0][0] = 1
for i, a in enumerate(A):
    for j in range(K, -1, -1):
        dpm[i+1][j] = dpm[i][max(0, j-a)] + dpm[i][j]

r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
    for j in range(K, -1, -1):
        # 後ろiこの合計がjのもの
        if dp2&(1<<j) and dpm[N-i-1][max(0, K-j-a)] > dpm[N-i-1][K-j]:
            # K-j > x >= K-j-a
            break
    else:
        r += 1
    dp2 |= dp2<<a
    dp2 &= (1<<(K+1))-1
print(r)


### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
#dpm = [+1) for _ in range(N+1)]
dpm = [0]*(N+1)
dpm[0] = 1<<(K-1)
for i, a in enumerate(A):
    dpm[i+1] = dpm[i] | (dpm[i] >> a)

r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
    for j in range(a):
        if dp2 & dpm[N-i-1]:
            break
        dpm[N-i-1] >>= 1
    else:
        r += 1
    dp2 |= dp2<<a
    dp2 &= (1<<K)-1
print(r)
### BUGGY CODE ###

s = input()
t = input()
N = len(s)

schr = dict()
for i in range(N):
    if s[i] in schr:
        schr[s[i]].append(i+1) 
    else:
        schr[s[i]] = [i+1]

ans, pos = 0, 0
for i in range(len(t)):
    if t[i] in schr:
        c = schr[t[i]]
        if c[-1] <= pos:
            ans += N - pos + c[0]
            pos = c[0]
        else:
            j = 0
            while c[j] <= pos:
                j += 1
            ans += c[j] - pos
            pos = c[j]
    else:
        print(-1)
        exit()
print(ans)

### FIXED CODE ###

s = input()
t = input()
N, M = len(s), len(t)

schr, indchr = dict(), dict()
for i in range(N):
    if s[i] in schr:
        schr[s[i]].append(i+1) 
    else:
        schr[s[i]] = [i+1]
        indchr[s[i]] = 0

schrset = set(schr)
ans, pos, pre, back = 0, 0, set(), True
for i in range(M):
    if t[i] in schrset:
        c = schr[t[i]]
        if c[-1] <= pos:
            ans += N - pos + c[0]
            pos = c[0]
            if not back:
                for x in indchr.keys():
                    indchr[x] = 0
                back, pre = True, set()
        else:
            j = indchr[t[i]]
            while c[j] <= pos:
                j += 1
            if j > 0:
                pre.add(t[i])
            ans += c[j] - pos
            pos, back, indchr[t[i]] = c[j], False, j
    else:
        print(-1)
        exit()
print(ans)
### BUGGY CODE ###

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

money = []
for i in range(len(a)):
    arr = [0]+a[:i]+a[i+1:]+[0]
    tmp = []
    for j in range(len(arr)-1):
        tmp.append(abs(arr[j]-arr[j+1]))
    money.append(sum(tmp))


print(*money, sep='\n')


### FIXED CODE ###

n = int(input())
a = [0] + list(map(int, input().split())) + [0]


total = sum(abs(a[i+1]-a[i]) for i in range(n+1))
for i in range(1, n+1):
    print(total + abs(a[i-1]-a[i+1]) - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]))
### BUGGY CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))

ans = 0

for i in range(N - K + 1):
    ans = max(ans, sum(P[i: i + K]))
    
print((ans + K) / 2)


### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))

a = [0] * (N - K + 1)
a[0] = sum(P[:K])
for i in range(1, N - K + 1):
    a[i] = a[i - 1] - P[i - 1] + P[i + K - 1]
    
print((max(a) + K) / 2)
### BUGGY CODE ###

import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    R, C, K = map(int, input().split())

    field = [[0 for j in range(C)] for i in range(R)]

    for _ in range(K):
        r, c, v = map(int, input().split())
        field[r - 1][c - 1] = v

    dp = [[[0] * 4 for j in range(C)] for i in range(R)]

    for i in range(R):
        for j in range(C):
            ct = field[i][j]
            premax = max(dp[i - 1][j][0], dp[i - 1][j][1], dp[i - 1][j][2], dp[i - 1][j][3])
            if ct == 0:
                dp[i][j][0] = max(dp[i][j - 1][0], premax)

                for k in range(1, 4):
                    if j > 0:
                        dp[i][j][k] = dp[i][j - 1][k]
            else:
                dp[i][j][0] = max(dp[i][j - 1][0], premax)
                dp[i][j][1] = max(ct + max(dp[i][j - 1][0], premax), dp[i][j - 1][1])
                for k in range(2, 4):
                    if j > 0:
                        dp[i][j][k] = max(dp[i][j - 1][k - 1] + ct, dp[i][j - 1][k])

    print(max(dp[R - 1][C - 1]))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    R, C, K = map(int, input().split())

    field = [[0 for j in range(C)] for i in range(R)]

    for _ in range(K):
        r, c, v = map(int, input().split())
        field[r - 1][c - 1] += v

    dp = [[0] * 4 for j in range(C)]

    for i in range(R):
        for j in range(C):
            ct = field[i][j]
            premax = max(dp[j])

            if ct == 0:
                if j>0:
                    dp[j][0] = max(dp[j - 1][0], premax)
                else:
                    dp[j][0] = premax

                for k in range(1, 4):
                    if j > 0:
                        dp[j][k] = dp[j - 1][k]
            else:
                if j>0:
                    dp[j][0] = max(dp[j - 1][0], premax)
                    dp[j][1] = max(ct + max(dp[j - 1][0], premax), dp[j - 1][1])
                else:
                    dp[j][0] = premax
                    dp[j][1] = premax +ct
                for k in range(2, 4):
                    if j > 0:
                        dp[j][k] = max(dp[j - 1][k - 1] + ct, dp[j - 1][k])

    print(max(dp[C - 1]))


if __name__ == "__main__":
    main()