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

from queue import deque
from copy import deepcopy

    
H, W = map(int, input().split())
S = [['#'] * (W + 2)]
cnt = []
Checked = [[0 for _ in range(W+2)] for _ in range(H+2)]


for _ in range(H):
    S.append(['#'] + [i for i in input()] + ['#'])
S.append(['#']*(W + 2))

for start_h in range(1, H+1):
    for start_w in range(1, W+1):
        if S[start_h][start_w] == '#':
            continue
        for goal_h in range(1, H+1):
            for goal_w in range(1, W+1):
                if S[goal_h][goal_w] == '#':
                    continue
                if start_h == goal_h or start_w == goal_w:
                    cnt.append(abs(start_h - goal_h) + abs(start_w - goal_w))
                    continue
                    
                q = deque([[start_h, start_w]])
                checked = deepcopy(Checked)
                c = 0
                tmp = []
                while q:
                    h, w = q.popleft()
                    if checked[h][w]:
                        continue
                    checked[h][w] = 1
                    if h == goal_h and w == goal_w:
                        cnt.append(c)
                        break
                        
                    for dw, dh in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                        next_h, next_w = h + dh, w + dw
                        if S[next_h][next_w] == '#':
                            continue
                        if [next_h, next_w] in tmp or checked[next_h][next_w]:
                            continue
                        tmp.append([next_h, next_w])
                    if not q:
                        q.extend(tmp)
                        tmp = []
                        c += 1

print(max(cnt))

### FIXED CODE ###

from queue import deque
from copy import deepcopy

    
H, W = map(int, input().split())
S = [['#'] * (W + 2)]
cnt = []
Checked = [[0 for _ in range(W+2)] for _ in range(H+2)]


for _ in range(H):
    S.append(['#'] + [i for i in input()] + ['#'])
S.append(['#']*(W + 2))

for start_h in range(1, H+1):
    for start_w in range(1, W+1):
        if S[start_h][start_w] == '#':
            continue
        q = deque([[start_h, start_w]])
        checked = deepcopy(Checked)
        c = 0
        tmp = []
        while q:
            h, w = q.popleft()
            if checked[h][w]:
                 continue
            checked[h][w] = 1
                    
            for dw, dh in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                next_h, next_w = h + dh, w + dw
                if S[next_h][next_w] == '#':
                    continue
                if [next_h, next_w] in tmp or checked[next_h][next_w]:
                    continue
                tmp.append([next_h, next_w])
            if not q:
                q.extend(tmp)
                tmp = []
                c += 1
        cnt.append(c-1)
            
print(max(cnt))
### BUGGY CODE ###

import math

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

for k in range(N):
  ans = 0
  B = A.copy()
  del B[k] #ここでBはk番目が削除されたものとなっている。
  C = list(set(B)) 
  M = len(C)
  for i in range(M):
    if B.count(C[i]) >=2:
      t = B.count(C[i])
      ans += math.factorial(t)/((math.factorial(t-2))*(math.factorial(2)))
  print(int(ans))

### FIXED CODE ###

import math

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

C = list(set(A))
M = len(C)
t = []
anst = 0
dic = {}
for i in A:
  if not i in dic:
    dic[i] = 0
  dic[i] += 1

jisyo = {}
for i in range(M):
  temp = dic[C[i]]
  jisyo[C[i]] = temp
  #t.append(A.count(C[i]))
  if temp >=2:
    anst += temp*(temp-1)/2

#jisyo = dict(zip(C, t))
#print(jisyo)   
for i in range(N):
  #print(t[C.index(A[i])])
  print(int(anst-jisyo[A[i]]+1))
### BUGGY CODE ###

from collections import deque

h,w = map(int,input().split())
s = [input() for i in range(h)]
sy,sx = 0,0
f = False
for i,si in enumerate(s):
    if f:
        break
    for j,sij in enumerate(si):
        if sij == ".":
            sysx = i,j
            f = True
            break

t = ((0,1),(1,0),(-1,0),(0,-1))
c = 0
se = set()
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        f = [[True]*w for i in range(h)]
        f[sy][sx] = False
        while(q):
            cost,y,x = q.popleft()
            if max_cost < cost:
                max_cost = cost
                my,mx = y,x
            f[y][x] = False
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if s[ny][nx] == "." and f[ny][nx]:
                        q.append((cost,ny,nx))
        m = max(m,max_cost)
print(m)

### FIXED CODE ###

from collections import deque
from copy import deepcopy

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
t = ((0,1),(1,0),(-1,0),(0,-1))
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        ss = deepcopy(s)
        ss[sy][sx] = "#"
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        while(q):
            cost,y,x = q.popleft()
            max_cost = max(max_cost,cost)
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if ss[ny][nx] == ".":
                        q.append((cost,ny,nx))
                        ss[ny][nx] = "#"
        m = max(m,max_cost)
print(m)
### BUGGY CODE ###

import numpy as np

n, k, q = map(int, input().split())

a = np.full(n, k)

for _ in range(q):
    seikaisha = int(input()) - 1
    a -= 1
    a[seikaisha] += 1

for sankasha_point in a:
    if sankasha_point > 0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

import numpy as np

n, k, q = map(int, input().split())

a = np.full(n, k)
plus_point = np.zeros(n, dtype=np.int)

for _ in range(q):
    seikaisha = int(input()) - 1
    plus_point[seikaisha] += 1


a -= q
a += plus_point

for sankasha_point in a:
    if sankasha_point > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

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

if A[0] != 0:
    B = A + [K] 
else:
    B = A
#print(B)

for i in range(N):
    B.append(A[i] + K)
#print(B)

C =[]
for i in range(N):
    cnt = 0
    for j in range(i, i + N - 1):
        cnt +=B[j+1] -B[j]
    C.append(cnt)

print(min(C))


### FIXED CODE ###

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

a = K + A[0]
A = A + [a]

#print(A)

B = []
for i in range(N):
    B.append(A[i+1] - A[i])
B = sorted(B,reverse = False)

print(sum(B) - max(B))
### BUGGY CODE ###

from collections import deque

n = int(input())
lst = [deque(map(int, input().split())) for _ in range(n)]
 
current = []
for i in range(n):
    current.append(lst[i].popleft())

count = 0
while True:
    index_lst = []
    for i in range(len(current)):
        candidate = current[i]
        if candidate == 0:
            continue
        if current[candidate-1] == i+1:
            index_lst += [i+1, candidate]   
    if len(index_lst) == 0:
        if sum(current) == 0:
            print(count)
            break
        else:
            print(-1)
            break
    for i in set(index_lst):
        if len(lst[i-1]) == 0:
            current[i-1] = 0
        else:
            current[i-1] = lst[i-1].popleft()
    count += 1

### FIXED CODE ###

from collections import deque
 
n = int(input())
lst = [deque(map(int, input().split())) for _ in range(n)]
 
current = []
for i in range(n):
    current.append(lst[i].popleft())

count = 0
players = set(range(1, n+1))
while True:
    index_lst = []
    for i in players:
        candidate = current[i-1]
        if candidate in index_lst:
            continue
        if current[candidate-1] == i:
            index_lst += [i, candidate]   
    if len(index_lst) == 0:
        if sum(current) == 0:
            print(count)
            break
        else:
            print(-1)
            break
    for i in index_lst:
        if len(lst[i-1]) == 0:
            current[i-1] = 0
        else:
            current[i-1] = lst[i-1].popleft()
    players = set(index_lst)
    count += 1
### BUGGY CODE ###

# -*- coding: utf-8 -*-

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    left_ns = [e for e in range(n1 + 1)]
    right_ns = [e for e in range(n2 + 1)]

    for i in range(n1):
        left_ns[i] = ns[left + i]
    for i in range(n2):
        right_ns[i] = ns[mid + i]
    
    left_ns[n1] = infinity
    right_ns[n2] = infinity

    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


def merge_sort(ns, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(ns, left, mid)
        merge_sort(ns, mid, right)
        merge(ns, left, mid, right)


n = int(input())
ns = [int(e) for e in input().split()]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)
# ns = [str(n) for n in ns]

print(*ns)
print(count)

### FIXED CODE ###

# -*- coding: utf-8 -*-

infinity = pow(10, 9) + 1


def merge(ns, left, mid, right):
    global count
    left_ns = ns[left:mid] + [infinity]
    right_ns = ns[mid:right] + [infinity]
    i = j = 0
    for k in range(left, right):
        count += 1
        if left_ns[i] <= right_ns[j]:
            ns[k] = left_ns[i]
            i += 1
        else:
            ns[k] = right_ns[j]
            j += 1


def merge_sort(ns, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(ns, left, mid)
        merge_sort(ns, mid, right)
        merge(ns, left, mid, right)


n = int(input())
ns = [int(e) for e in input().split()]
# n = 10
# ns = [8, 5, 9, 2, 6, 3, 7, 1, 10, 4]
left = 0
right = len(ns)
count = 0
merge_sort(ns, left, right)

print(*ns)
print(count)
### BUGGY CODE ###

n,m=map(int,input().split())
a=[]
b=[0]*(n+1)
b[0]=1
MOD=(10**9)+7

for i in range(0,m):
  a.append(int(input()))
  
if 1 not in a:
  b[1]=1
  
for j in range(2,n+1):
  if j not in a:
    b[j]=(b[j-1]+b[j-2])%MOD
    
print(b[n]%MOD)    
    
  
  
  



### FIXED CODE ###

n,m=map(int,input().split())
mod=10**9+7
a=[0]*(n+1)
dp=[0]*(n+1)
dp[0]=1
for i in range(m):
    a[int(input())]=1
    
if a[1]==1:
    dp[1]=0
else:
    dp[1]=1
    
for j in range(2,n+1):
    if a[j]==0:
        dp[j]=dp[j-1]+dp[j-2] 
                  
print(dp[n]%mod)
### BUGGY CODE ###

N = int(input())

s = [sorted(list(input())) for i in range(N)]
ans=0
for i in range(N):
    for j in range(i+1, N):
        f = True
        for k in range(10):
            if s[i][k]!=s[j][k]:
                f = False
                break
        if f: ans+=1

print(ans)


### FIXED CODE ###

import collections
N = int(input())

s = [sorted(list(input())) for i in range(N)]

for i in range(N):
    s[i] = ''.join(s[i])

ans = 0

c = collections.Counter(s)
for v in c.values():
    ans += (1/2) * v * (v-1)

print(int(ans))
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    board = [input().strip() for i in range(H)]
    check = [[False] * W for i in range(H)]

    q = deque()
    for y in range(H):
        for x in range(W):
            if board[y][x] == "#":
                q.append((0, x, y))
                check[y][x] = True
    
    ans = 0
    while len(q) > 0:
        cost, x, y = q.popleft()
        ans = max(ans, cost)
        for nx, ny in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
            if 0 <= nx and nx < W and 0 <= ny and ny < H:
                if board[ny][nx] == "." and not check[ny][nx]:
                    q.append((cost+1, nx, ny))
                    check[ny][nx] = True
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    INF = int(1e7)
    a = np.array([list(map(lambda x: 0 if x=="#" else INF, list(input().strip()))) for i in range(H)])

    for i in range(H-1):
        a[i+1] = np.minimum(a[i] + 1, a[i+1])
    for i in range(H-1, 0, -1):
        a[i-1] = np.minimum(a[i] + 1, a[i-1])
    
    for i in range(W-1):
        a[:, i+1] = np.minimum(a[:, i] + 1, a[:, i+1])
    for i in range(W-1, 0, -1):
        a[:, i-1] = np.minimum(a[:, i] + 1, a[:, i-1])

    print(np.max(a))

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

import sys
input = sys.stdin.readline
import numpy as np

def main():
    N = int(input())
    act = np.array([[int(item) for item in input().split()] for _ in range(N)])

    dp = np.zeros((2, 3), dtype='int64')

    for i in range(0,N):
        for j in range(3):
            prev_dp_array = [dp[i%2][k] if k != j else 0 for k in range(3)]
            dp[i%2 ^ 1][j] = np.max(prev_dp_array + act[i][j])
        # print(dp)
    print(np.max(dp))

main()


### FIXED CODE ###

N = int(input())
act = [[int(item) for item in input().split()] for _ in range(N)]

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

for i in range(N):
    for j in range(3):
        temp_hp = []
        for k in range(3):
            if k != j:
                temp_hp.append(dp[i-1][k] + act[i][j])
        dp[i][j] = max(temp_hp)
# print(dp)
print(max(dp[N-1]))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 
MOD = 10**9+7

S = inpS()
N = len(S)
dp = [[0]*13 for _ in range(N+1)]

dp[0][0] = 1
for dgt in range(N):
  for mo in range(13):
    if S[dgt] == "?":
      for nxt in range(10):
        ind = (mo*10 + nxt) % 13
        dp[dgt+1][ind] += dp[dgt][mo]
        #dp[dgt+1][ind] %= MOD
    else:
      ind = (mo*10 + int(S[dgt])) % 13
      dp[dgt+1][ind] += dp[dgt][mo]
      #dp[dgt+1][ind] %= MOD
print(dp[N][5]%MOD)        

### FIXED CODE ###

import numpy as np
MOD = 10 ** 9 + 7

S = [int(x) if x != "?" else -1 for x in input()]
N = len(S)

# 現在考えてる一つ前の桁数で、余りが i になる整数の個数
r = [0]*13

# まず一つ目の値が１の位とする
s = S[0]
if s != -1:
  r[s] = 1
else:
  for i in range(10):
    r[i] = 1

# 桁を進めながら個数をカウント
for i in range(1, N):
    # dp[j]
    # 現在考えている桁(i)を除く、余りが j となる整数の個数
    dp = [0]*26
    # 桁が一つ上がるので、一つ前の余りが 10 倍になる
    for j in range(13):
      dp[j*10%13] += r[j] % MOD
    # アクセスを高速にするため２倍の長さとる (dp[i] == dp[i + 13])
    dp[13:26] = dp[0:13]
    r = [0]*13
    s = S[i]
    if s == -1:
      w = sum(dp[4:14])
      for j in range(13):
        r[j] += w
        w += dp[j+1] -dp[j+4]
    else:
      for j in range(13):
        r[j] += dp[13-s+j]
print(r[5]%MOD)
### BUGGY CODE ###

from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def Knapsack2(W,w,v): # n個の品物(重さw[i],価値v[i]) 価値iを達成する重量の最小化 計算量O(V*N)
    n=len(w)
    v_max=10**7+5
    # dp[i] : 価値iの組み合わせを達成する重量の最小値
    dp=[0]+[float('inf') for _ in range(v_max+1)]
    for i in range(n):
        for j in range(v_max,v[i]-1,-1):
            if j >= v[i]:
                dp[j]=min(dp[j],dp[j-v[i]]+w[i])
    ans=0
    for i in range(v_max+1):
        if dp[i]<=W:
            ans=i
    print(ans)

def main():
    n,W = inpm()
    w = []
    v = []
    for _ in range(n):
        wv = inpl()
        w.append(wv[0])
        v.append(wv[1])
    Knapsack2(W,w,v)

if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n,W = inpm()
    v = [[] for _ in range(4)]
    w0 = 0
    for i in range(n):
        wv = inpl()
        if i == 0:
            w0 = wv[0]
        v[ wv[0]-w0 ].append(wv[1])
    for i in range(4):
        v[i] = sorted(v[i])
        v[i].reverse()
        vv = [0 for _ in range(len(v[i])+1)]
        for j in range(len(v[i])):
            vv[j+1] = vv[j] + v[i][j]
        v[i] = vv
    ans = 0
    for n1 in range(len(v[0])):
        for n2 in range(len(v[1])):
            for n3 in range(len(v[2])):
                for n4 in range(len(v[3])):
                    if W < w0*(n1+n2+n3+n4) + n2 + n3*2 + n4*3:
                        continue
                    ans = max(ans,v[0][n1]+v[1][n2]+v[2][n3]+v[3][n4])
    print(ans)

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

def mygets():
    return list(map(int, input().strip().split()))

n, x = mygets()
a = mygets()

b1 = a.copy()
b2 = a.copy()

ans = sum(a)

for i in range(1, n):
    for j, v in enumerate(a):
        b2[j] = min(v, b1[(j + n - 1) % n])
    ans = min(ans, sum(b2) + i * x)
    b1, b2 = b2, b1

print(ans)

### FIXED CODE ###

def mygets():
    return list(map(int, input().strip().split(' ')))

n, x = mygets()
a = mygets()

b1 = a

ans = sum(a)

def f(k, u):
    j = k - 1
    if j < 0:
        j = n - 1
    w = b1[j]
    if u < w:
        return u
    return w

for i in range(1, n):
    b2 = [f(k, u) for k, u in enumerate(a)]
    ans = min(ans, sum(b2) + i * x)
    b1 = b2

print(ans)
### BUGGY CODE ###

def Calculator(K):
    a = 7
    for i in range(K):
        if a % K == 0:
            return (i+1)
        a = 10 * a + 7
    return -1
K = int(input())
print(Calculator(K))

### FIXED CODE ###

K = int(input())
a = 7
for i in range(K):
    if a % K == 0:
        print(i+1)
        exit()
    a = (10 * a + 7) % K
print(-1)
### BUGGY CODE ###

x  = int(input())
t = 100
ans = 0
while t<x:
  t = t//100
  ans +=1

print(ans)

### FIXED CODE ###

x  = int(input())
t = 100
ans = 0
while t<x:
  t += t//100
  ans +=1

print(ans)
### BUGGY CODE ###

import numpy as np
from scipy.sparse.csgraph import dijkstra


def calc(d):
    if d == 1 or d == 0:
        return 0
    else:
        return int(d - 1)


delta = []
n, u, v = map(int, input().split())
G = [[float("inf")] * n for i in range(n)]
Gn = np.array(G)
for i in range(n - 1):
    a, b = map(int, input().split())
    a = a - 1
    b = b - 1
    Gn[a][b] = 1
    Gn[b][a] = 1
    Gn[i][i] = 0
minimum_u = dijkstra(Gn, indices=u - 1)
minimum_v = dijkstra(Gn, indices=v - 1)
for i in range(n):
    if minimum_v[i] - minimum_u[i] > 0 and i != u - 1 and i != v - 1:
        delta.append([i, minimum_v[i]])
if delta != []:
    delta_sorted = sorted(delta, key=lambda x: x[1])
    p = delta_sorted[-1][0]
    d = int(minimum_v[p])
    print(calc(d))
else:
    print(calc(minimum_u[v - 1]))


### FIXED CODE ###

# 写経
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, u, v = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)

graph = [[] for _ in range(n + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)


def dfs(v):
    dist = [-1] * (n + 1)
    # 初期化
    stack = [v]
    # 初期位置を記憶
    dist[v] = 0
    # 初期位置の距離を0に
    while stack:
        # stackの中身がなくなるまで頑張る
        v = stack.pop()
        # stackから1つ要素を取り出す
        dw = dist[v] + 1
        # その要素の周りを考えるので、距離としてはその要素の距離に1を加えたものを考える
        for w in graph[v]:
            # 考えている要素に対して隣接している点に対して
            if dist[w] >= 0:
                # もし今まで訪れたことがあったら無視
                continue
            dist[w] = dw
            # 訪れたことがなかったら距離を更新
            stack.append(w)
            # 訪れたことがないところだったらstackに訪れる点リストとして保存
    return dist


answer = 0
du, dv = dfs(u), dfs(v)
for u, v in zip(du[1:], dv[1:]):
    if v - u > 0:
        x = v - 1
        if answer < x:
            answer = x
print(answer)
### BUGGY CODE ###

a, b, k = map(int, input().split())
data = [i for i in range(a, b + 1)]

ans = []
if k > len(data):
    for i in data:
        print(i)
else:
    for i in range(k):
        if data[i] not in ans:
            ans.append(data[i])        
    for i in range(len(data) - k, len(data)):
        if data[i] not in ans:
            ans.append(data[i])
    
    for i in ans:
        print(i)

### FIXED CODE ###

a, b, k = map(int, input().split())
if k >= -(-(b - a + 1)//2):
    for i in range(a, b + 1):
        print(i)
else:
    for i in range(a, a + k):
        print(i)
    for i in range(b + 1 - k, b + 1):
        print(i)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

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

x = map(int, raw_input().split())
y = map(int, raw_input().split())

area = 0
for i in range(n):
    for j in range(i,n):
        for k in range(m):
            for l in range(k,m):
                area += (x[j]-x[i])*(y[l]-y[k])
                area = area%1000000007
print(area)

### FIXED CODE ###

# -*- coding: utf-8 -*-

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

x = map(int, raw_input().split())
y = map(int, raw_input().split())

mod = 10**9+7
xsum = 0
ysum = 0
for i in range(n):
    xsum += (2*(i+1)-n-1)*x[i]

for i in range(m):
    ysum += (2*(i+1)-m-1)*y[i]
area = xsum*ysum%mod
print(area)
### BUGGY CODE ###

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

mem = [-1 for i in range(n+1)]
def countd(y):
  if mem[y] == -1:
    mem[y] = len([a for a in d if a == y])
  return mem[y]

if d[0] != 0:
  print(0)
  exit()

count = 1
for i in range(n-1):
  x = d[i+1]
  if x == 0:
    print(0)
    exit()
  if x == 1:
    continue
  count = count * countd(x-1)

print(count % 998244353)

### FIXED CODE ###

from collections import Counter

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

mem = Counter(d)

if d[0] != 0 or mem[0] != 1:
  print(0)
  exit()

count = 1
for i in range(max(d)):
  count = count * mem[i] ** mem[i+1]
  count = count % 998244353

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

def main():
    from itertools import product

    n, s = int(input()), input()
    r, g, b = [], [], []
    for i, j in enumerate(s):
        if j == 'R':
            r.append(i)
        if j == 'G':
            g.append(i)
        if j == 'B':
            b.append(i)
    ans = 0
    for t in product(r, g, b):
        l = list(t)
        l.sort()
        if l[2] - l[1] != l[1] - l[0]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


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

N = int(input())
print(sum(range(1, N)))

### FIXED CODE ###

N = int(input())
print(sum(range(1, N)))