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

import heapq

H, W = map(int, input().split())
board = []
visited = [[False for _ in range(W)] for _ in range(H)]
goal_dst = [[float("inf") for _ in range(W)] for _ in range(H)]
no = 0

for _ in range(H):
	board.append(list(map(str, input())))
	no += board[-1].count("#")
	
# bfsで最短路を求める
Q = [[0, 0, 1]]
juuji = [[-1, 0], [1, 0], [0, -1], [0, 1]]

while Q:
	cur = heapq.heappop(Q)
	visited[cur[0]][cur[1]] = True
	dist = cur[2]
	if goal_dst[cur[0]][cur[1]] < dist or goal_dst[-1][-1] < dist: continue
	goal_dst[cur[0]][cur[1]] = dist
	for move in juuji:
		new_y = cur[0] + move[0]
		new_x = cur[1] + move[1]
		if not (0 <= new_x and new_x <= W - 1 and 0 <= new_y and new_y <= H - 1): continue 
		if board[new_y][new_x] == "." and visited[new_y][new_x] == False:
			heapq.heappush(Q, [new_y, new_x, dist + 1])
			
if goal_dst[-1][-1] == float("inf"):
	print(-1)
else:
	print(H * W - goal_dst[-1][-1] - no)

### FIXED CODE ###

from heapq import heappush, heappop
H, W = map(int, input().split())
s = [input() for _ in range(H)]

dist = [[float('inf')] * W for _ in range(H)]
q = [(0, 0, 0)]
while q :
    cost, cx, cy = heappop(q)
    if cost >= dist[cy][cx] :
        continue
    dist[cy][cx] = cost
        
    for dx, dy in ((0, 1), (0, -1), (1, 0), (-1, 0)) :
        if 0 <= cx + dx < W and 0 <= cy + dy < H and s[cy+dy][cx+dx] != '#' :
            heappush(q, (cost+1, cx+dx, cy+dy))
            
if dist[H-1][W-1] == float('inf') :
    print(-1)
else :
    ret = 0
    for s_ in s :
        ret += s_.count('#')
    print(H * W - ret - dist[H-1][W-1] - 1)
### BUGGY CODE ###

import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

def prime_factorize(n):
    a = []
    a.append(1)
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    
    b = [[],[]]
    cnt = 1
    for i in range(len(a)+1):
        if i > 0 and i < len(a):
            if a[i] == a[i-1]:
                cnt += 1
            else:
                b[0].append(a[i-1])
                b[1].append(cnt)
                cnt = 1
        if i == len(a) and i > 0:
            b[0].append(a[i-1])
            b[1].append(cnt)
        elif i == len(a) and i == 0:
            b[0].append(a[i])
            b[1].append(cnt)
    return b

n = INT()
a = LIST()
ll = [[], []]
aa = []
for i in range(n):
    aa.append(prime_factorize(a[i]))
    for j in range(len(aa[i][0])):
        if aa[i][0][j] in ll[0]:
            idx = ll[0].index(aa[i][0][j])
            ll[1][idx] += max(0, aa[i][1][j] - ll[1][idx])
        else:
            ll[0].append(aa[i][0][j])
            ll[1].append(aa[i][1][j])
ans = 0
l = 1
for i in range(n):
    b = 1
    for j in range(len(ll[0])):
        if ll[0][j] in aa[i][0]:
            idx = aa[i][0].index(ll[0][j])
            tmp1 = ll[1][j] - aa[i][1][idx]
            b *= ll[0][j] ** tmp1
        else:
            b *= ll[0][j] ** ll[1][j]
    ans += b
    ans %= mod
print(ans)

### FIXED CODE ###

import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
l = 1
for i in a:
    l = lcm(l, i)
l %= mod
ans = 0
for i in a:
    ans += l * pow(i, mod - 2, mod)
print(ans % mod)
### BUGGY CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    K = int(readline())

    subs = set()

    S_sorted = sorted(set(S))
    for c_min in S_sorted:
        indices = [i for i, c in enumerate(S) if c == c_min]
        for i in indices:
            for j in range(i + 1, len(S) + 1):
                subs.add(S[i:j])

        if len(subs) >= K:
            break

    subs = sorted(subs)
    print(subs[K - 1])

    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    K = int(readline())

    subs = set()

    S_sorted = sorted(set(S))
    for c_min in S_sorted:
        indices = [i for i, c in enumerate(S) if c == c_min]
        for i in indices:
            for j in range(i + 1, min(len(S) + 1, i + K + 1)):
                subs.add(S[i:j])

        if len(subs) >= K:
            break

    subs = sorted(subs)
    print(subs[K - 1])

    return


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

import sys
sys.setrecursionlimit(10**7)

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

G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

def dfs(v, u, depth):

    depth_min[v] = depth
    memo[v] = u

    for next_v in G[v]:
        if next_v == 0:
            continue
        if depth_min[next_v] > depth+1:
            dfs(next_v, v, depth+1)

depth_min = [float("inf")] * N
memo = [-1] * N
dfs(0, 0, 0)
if -1 in memo:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(memo[i]+1)

### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
g = [[int(i) for i in input().split()] for j in range(M)]

G = [[] for i in range(N)]
for i in range(M):
    a, b = g[i]
    G[a-1].append(b-1)
    G[b-1].append(a-1)

marks = [-1 for i in range(N)]
node = deque([[0, 0]])
while len(node) > 0:
    v = node.popleft()
    if marks[v[0]] == -1:
        marks[v[0]] = v[1]
        for i in G[v[0]]:
            if marks[i] == -1:
                node.append([i, v[0]])

if -1 not in marks:
    print("Yes")
    for i in range(1, N):
        print(marks[i]+1)
else:
    print("No")
### BUGGY CODE ###

import sys

def longestcommonsubsequence(seq1, seq2):
    a,b = len(seq1)+1, len(seq2)+1
    length = [[0 for i in range(b)] for j in range(a)]

    for i in range(a):
        for j in range(b):
            if i==0 or j==0:
                pass
                length[i][j]=0
            else:
                if seq1[i-1] == seq2[j-1]:
                    length[i][j] = length[i-1][j-1] + 1
                else:
                    length[i][j] = max(length[i-1][j], length[i][j-1])
    return length[a-1][b-1]

n = input()
for i2 in range(n):
    seq1 = raw_input()
    seq2 = raw_input()

    print longestcommonsubsequence(seq1, seq2)

### FIXED CODE ###

import sys

def longestcommonsubsequence():
    seq1 = raw_input()
    seq2 = raw_input()

    a, b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = seq1[i]
        x2 = x1+[]
        #x1 = [0 for i2 in range(b+1)]
        for j in range(b):
            if e1 == seq2[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1]<x1[j]:
                x1[j+1] = x1[j]
    return x1[-1]

n = input()
for i2 in range(n):

    print longestcommonsubsequence()
### BUGGY CODE ###

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

def main():
    s = input()
    q = int(input())

    r_flg = True

    for i in range(q):
        query = input()

        # query 1
        if query[0] == '1':
            r_flg = not r_flg
        
        # query 2
        else:
            # Fi = 1
            if query[2] == '1':
                if r_flg:
                    s = query[4] + s
                else:
                    s = s + query[4]
            # Fi = 2
            else:
                if r_flg:
                    s = s + query[4]
                else:
                    s = query[4] + s

        # print('cont:{}, s:{}, r_flg:{}'.format(i, s, r_flg))

    if not r_flg:
        s = ''.join(reversed(s))

    print(s)

if __name__ == "__main__":
    main()


### FIXED CODE ###

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

def main():
    s = input()
    q = int(input())
    q_list = list()

    for i in range(q):
        q_list.append(input())

    r_flg = True
    s_str = ''
    e_str = ''

    for query in q_list:
        # query 1
        if query[0] == '1':
            r_flg = not r_flg
        
        # query 2
        else:
            # Fi = 1
            if query[2] == '1':
                if r_flg:
                    s_str = query[4] + s_str
                else:
                    e_str = e_str + query[4]
            # Fi = 2
            else:
                if r_flg:
                    e_str = e_str + query[4]
                else:
                    s_str = query[4] + s_str

        # print('cont:{}, s:{}, r_flg:{}'.format(i, s, r_flg))

    s = s_str + s + e_str

    if not r_flg:
        s = ''.join(reversed(s))

    print(s)

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

N = int(input())
S = list(input() for _ in range(N))

S_sorted = sorted(list(set(S)))

dic = dict(zip(S_sorted, [0 for _ in range(len(S_sorted))]))

for s in S: dic[s] += 1

K_max = max(list(dic.values()))

for (k, v) in dic.items():
    if K_max != v:
        S_sorted.pop(S_sorted.index(k))
        
for s in S_sorted: print(s)

### FIXED CODE ###

N = int(input())
S = list(input() for _ in range(N))

S_set= sorted(list(set(S)))

dic = dict(zip(S_set, [0 for _ in range(len(S_set))]))

for s in S: dic[s] += 1

K_max = max(list(dic.values()))
        
for (i,s) in enumerate(sorted(S_set)): 
    if dic[s] == K_max: 
        print(s)
### BUGGY CODE ###

#d
def main():
    n=int(input())
    a=[0]*(n-1)
    b=[0]*(n-1)
    for i in range(n-1):
        a[i],b[i] = map(int,input().split())
    import collections
    k=collections.Counter(a+b).most_common()[0][1]
    color_list=list(range(k))
    
    tree=[[] for _ in range(n)]
    for i in range(n-1):
        tree[a[i]-1].append(b[i])
        tree[b[i]-1].append(a[i])
        
    used_colors=[[] for _ in range(n)]
    ans=dict()
    q = collections.deque([(1,0)])
    #while q:
    for _ in range(n):
        x,parent = q.popleft()
        if parent!=0:
            for j in range(k):
                if not j in used_colors[parent-1]:
                    current_color=j
                    break
            used_colors[parent-1].append(current_color)
            used_colors[x-1].append(current_color)
        
            ans[str(parent)+"_"+str(x)]=current_color
        for y in tree[x-1]:
            if y == parent:
                continue
            q.append((y,x))   
    print(k)
    for i in range(n-1):
        s=str(a[i])+"_"+str(b[i])
        print(ans[s]+1)
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n=int(input())
    a=[0]*(n-1)
    b=[0]*(n-1)
    for i in range(n-1):
        a[i],b[i] = map(int,input().split())
    import collections
    k=collections.Counter(a+b).most_common()[0][1]
    color_list=list(range(k))
    
    tree=[[] for _ in range(n)]
    for i in range(n-1):
        tree[a[i]-1].append(b[i])
        
    q = collections.deque([(0,1,0)])#親、子、色
    ans=dict()
    while q:
        parent,togo,old_color = q.popleft()
    #    print(parent,togo,old_color)
        col=1
        for togotogo in tree[togo-1]:
    #        print(togotogo)
            if togotogo == parent:
                continue
            if col == old_color:
                col+=1
            q.append((togo,togotogo,col))
            ans["_".join(map(str,(togo,togotogo)))]=col
            col+=1
        
    print(k)
    for i in range(n-1):
        s=str(a[i])+"_"+str(b[i])
        print(ans[s])
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import deque


def insert(ary, x):
    ary.appendleft(x)


def delete(ary, x):
    if x in ary:
        ary.remove(x)


def delete_first(ary):
    ary.popleft()


def delete_last(ary):
    ary.pop()


n = int(input())
ary = deque([])

for _ in range(n):
    op = input().split()
    cmd = op[0]

    if cmd == 'insert':
        x = int(op[1])
        insert(ary, x)
    elif cmd == 'delete':
        x = int(op[1])
        delete(ary, x)
    elif cmd == 'deleteFirst':
        delete_first(ary)
    elif cmd == 'deleteLast':
        delete_last(ary)

print(*ary)



### FIXED CODE ###

import sys
from collections import deque

n = int(input())
ary = deque([])

for line in sys.stdin:
    op = line.strip().split()
    cmd = op[0]

    if cmd == 'insert':
        x = op[1]
        ary.appendleft(x)

    elif cmd == 'delete':
        x = op[1]
        if x in ary:
            ary.remove(x)

    elif cmd == 'deleteLast':
        ary.pop()

    else:
        ary.popleft()

print(*ary)
### BUGGY CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, M, Q = LI()

abcd = []
for i in range(Q):
    a, b, c, d = LI()
    a -= 1
    b -= 1
    abcd.append([a, b, c, d])

def cal_ans(A):
    ans = 0
    for i in range(Q):
        a, b, c, d = abcd[i]
        if A[b] - A[a] == c:
            ans += d
    return ans
# 10進数のnを2進数のリストに変換
def n2kdigit(n,k):
    digits = []
    before = 0
    while n > 0:
        if before > n % k:
            return None
        digits.append(n % k)
        before = n % k
        n = n // k
    if len(digits) < N:
        return None

    return digits

ans = -1
for i in range(M ** (N)):
    A = n2kdigit(i, M)
    if A is not None:
        ans = max(ans, cal_ans(A))
ans = max(ans, cal_ans([0 for i in range(N)]))

print(ans)

### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import itertools
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N, M, Q = LI()

abcd = []

all = 0
for i in range(Q):
    a, b, c, d = LI()
    a -= 1
    b -= 1
    abcd.append([a, b, c, d])
    all += d

abcd = sorted(abcd, key= lambda x:x[3], reverse= True)
ans = 0
if Q <= 2:
    for q in range(Q):
        ans += abcd[q][-1]
    print(ans)
    sys.exit()

def cal_ans(A):
    ans = 0
    for i in range(Q):
        a, b, c, d = abcd[i]
        if A[b] - A[a] == c:
            ans += d
    return ans

def n2kdigit(n, k):
    bi=''
    before = 1
    while n!=0:
        if before <= (n % k):
            # print(n)
            bi+=str(n%abs(k))
            before = n % k
            if k<0:n=-(-n//k)
            else:n=n//k
        else:
            return None
    if len(bi) < N:
        return None
    return bi
ans = 0

for i in itertools.combinations_with_replacement(range(1, M+1), N):
    # print(i)
    ans = max(ans, cal_ans(i))
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = count = 0; pro = 1

n=int(input())
s=list(map(int,input()))
S=set()
checked=[0]*10
# print(s)
# print(checked)
for i in range(n):
    # print(s,3456)
    # print(s[i])
    # print(checked[0])
    if not checked[s[i]]:

        C=[[0]*10 for h in range(10)]
        past=[0]*10
        for j in range(i+1,n):

            for k in range(10):
                if past[k] and C[k][s[j]]==0:
                    C[k][s[j]]+=1
            past[s[j]]=1
        for l in range(10):
            for t in range(10):
                if C[l][t]:
                    S.add(str(s[i])+str(l)+str(t))
        # for r in C:
        #     print(r)
# print(S)
print(len(S))

        
            
        
        
        
        


### FIXED CODE ###

#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = count = 0; pro = 1

n=int(input())
s=list(map(int,input()))
S=set()
checked=[0]*10
# print(s)
# print(checked)
for i in range(n):
    # print(s,3456)
    # print(s[i])
    # print(checked[0])
    if not checked[s[i]]:

        C=[[0]*10 for h in range(10)]
        past=[0]*10
        for j in range(i+1,n):

            for k in range(10):
                if past[k] and C[k][s[j]]==0:
                    C[k][s[j]]+=1
            past[s[j]]=1
        for l in range(10):
            for t in range(10):
                if C[l][t]:
                    S.add(str(s[i])+str(l)+str(t))
        checked[s[i]]=1
        # for r in C:
        #     print(r)
# print(S)
print(len(S))
### BUGGY CODE ###

import heapq
N,Q = map(int,input().split(" "))
querys = []
START = 1
GOAL = 0
GO = 2

for _ in range(N):
    s,t,x = (map(int,input().split(" ")))
    s -=(x + 0.5)
    t -= (x + 0.5)
    querys.append( (s,START,x) )
    querys.append( (t,GOAL,x) )

for _ in range(Q):

    querys.append( (int(input()),GO,-1)  )
koji_place = []
koji_um = set([])
heapq.heapify(koji_place)
querys.sort()
for query in querys:
    time,qtype,place = query
    if qtype == START:
        heapq.heappush(koji_place,place)
        koji_um.add(place)
    elif qtype == GOAL:
        koji_um.remove(place)
    else:
        while koji_place and koji_place[0] not in koji_um: #更新と最近の場所のチェックを同時に行う
            heapq.heappop(koji_place) #koji place のpopは最大で place分，つまり合計で10 ** 5回行われるため ここのwhile
            # はOに影響を与えない
        if koji_place:
            print(koji_place[0])
        else:
            print(-1)





### FIXED CODE ###

import bisect
import heapq
import sys
N,Q = [int(x) for x in sys.stdin.readline().split()]

hitos = []
ans = [-1] * Q
queries =[]
jump = [-1] * Q



queries = [[int(x) for x in sys.stdin.readline().split()] for i in range(N)]
hitos = [int(sys.stdin.readline()) for i in range(Q)]


# for i in range(N):
    # S,T,X =list(map(int,input().split(" ")))
    # lt = S -X -0.5
    # rt = T -X -0.5
    # queries.append([lt,rt,X]) #-1 → 挿入クエリ lが時間、-1がクエリの種類、Xが場所


queries.sort(key=lambda x:x[2])





for l,r,x in queries:
     lind  = bisect.bisect_left(hitos,l-x - 0.5)
     rind  = bisect.bisect_left(hitos,r -x - 0.5)
     while lind < rind:
         if ans[lind] == -1:
            ans[lind] = x
            jump[lind] = rind
            lind += 1
         else:
             temp = jump[lind]
             jump[lind] = rind
             lind = temp

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

s = input()
a = "".join([chr(97 + i) for i in range(26)])
b = "".join([a[i -1] for i in range(26)])
x = str.maketrans(a, b)
while True:
    s.translate(x)
    if "the" in s or "that" in s or "this" in s:
        print(s)
        break


### FIXED CODE ###

import sys
a = "abcdefghijklmnopqrstuvwxyz"
x = str.maketrans(a, a[1:] + a[:1])
for s in sys.stdin:
    while True:
        s = s.translate(x)
        if "the" in s or "that" in s or "this " in s:
            print(s, end = "")
            break
### BUGGY CODE ###

def main():
  _max = max
  s = input()
  t = input()
  slen = len(s)
  tlen = len(t)
  dp = [[0 for j in range(tlen + 1)] for i in range(slen + 1)]
  for i in range(slen):
    dpi = dp[i]
    dpi1 = dp[i + 1]
    si = s[i]
    for j in range(tlen):
      if si == t[j]:
        dpi1[j + 1] = _max(dpi1[j + 1], dpi[j] + 1, dpi1[j], dpi[j + 1])
      else:
        dpi1[j + 1] = _max(dpi1[j + 1],             dpi1[j], dpi[j + 1])
  result = ''
  i = slen
  j = tlen
  while i > 0 and j > 0:
    if dp[i - 1][j] == dp[i][j]:
      i -= 1
    elif dp[i][j - 1] == dp[i][j]:
      j -= 1
    else:
      result = s[i - 1] + result
      i -= 1
      j -= 1
  print(result)
main()


### FIXED CODE ###

s = input()
t = input()
slen = len(s)
tlen = len(t)
dp = [[0 for j in range(tlen + 1)] for i in range(slen + 1)]
for i in range(slen):
  for j in range(tlen):
    if s[i] == t[j]:
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])
result = ''
i = slen
j = tlen
while i > 0 and j > 0:
  if dp[i - 1][j] == dp[i][j]:
    i -= 1
  elif dp[i][j - 1] == dp[i][j]:
    j -= 1
  else:
    result = s[i - 1] + result
    i -= 1
    j -= 1
print(result)
### BUGGY CODE ###

s = input()
q = int(input())
flip = 1
right_edge = s
left_edge = ''
for i in range(q):
    query = input()
    if query[0] == '1':
        flip *= -1
    else:
        if query[2] == '1':
            if flip == 1:
                left_edge += query[-1]
            else:
                right_edge += query[-1]
        else:
            if flip == 1:
                right_edge += query[-1]
            else:
                left_edge += query[-1]
left_edge = left_edge[::-1]
if flip == 1:
    print(left_edge + right_edge)
else:
    print(right_edge[::-1] + left_edge[::-1])
        



### FIXED CODE ###

s = input()
q = int(input())
flip = 1
right_edge = list(s)
left_edge = []
for i in range(q):
    query = input()
    if query[0] == '1':
        flip *= -1
    else:
        if query[2] == '1':
            if flip == 1:
                left_edge.append(query[-1])
            else:
                right_edge.append(query[-1])
        else:
            if flip == 1:
                right_edge.append(query[-1])
            else:
                left_edge.append(query[-1])
left_edge = left_edge[::-1]
if flip == 1:
    print(''.join(left_edge + right_edge))
else:
    print(''.join(right_edge[::-1] + left_edge[::-1]))
### BUGGY CODE ###

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

mod = 10**9+7

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += A[i] * A[j]
print(ans % mod)

### FIXED CODE ###

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

mod = 10**9+7

sums = []
current_sum = 0
for a in A[1:][::-1]:
    current_sum += a
    sums.append(current_sum)
sums = sums[::-1]

ans = 0
for a, b in zip(A[:-1], sums):
    ans += a * b
    ans = ans % mod

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

n = int(input())
a = input().split()

c1 = a.count('1')
c2 = a.count('2')
c3 = a.count('3')

dp =[ [[-1] * (n+1) for _ in range(n+1)] for __ in range(c3+1)]
dp[0][0][0] = 0

def calc_dp(t3,t2,t1):
    global dp
    if(dp[t3][t2][t1] > -1):
        return dp[t3][t2][t1]

    temp = 0
    if(t3 > 0):
        temp += calc_dp(t3-1,t2+1,t1) * t3/(t1+t2+t3)
    if(t2 > 0):
        temp += calc_dp(t3,t2-1,t1+1) * t2/(t1+t2+t3)
    if(t1 > 0):
        temp += calc_dp(t3,t2,t1-1) * t1/(t1+t2+t3)
    temp = temp + n/(t1+t2+t3)

    dp[t3][t2][t1] = temp
    return temp

print(calc_dp(c3,c2,c1))

### FIXED CODE ###

n = int(input())
a = input().split()

c1 = a.count('1')
c2 = a.count('2')
c3 = a.count('3')

dp =[ [[0] * (n+1) for _ in range(c3+c2+1)] for __ in range(c3+1)]
# dp[0][0][0] = 0

for i in range(c3+1):
    for j in range(c3+c2+1-i):
        for k in range(n+1-i-j):
            if(i+j+k == 0):
                dp[i][j][k]=0
            else:
                temp = 0
                if(i > 0):
                    temp += dp[i-1][j+1][k] * i/(k+j+i)
                if(j > 0):
                    temp += dp[i][j-1][k+1] * j/(k+j+i)
                if(k > 0):
                    temp += dp[i][j][k-1] * k/(k+j+i)
                dp[i][j][k] = temp + n/(k+j+i)

print(dp[c3][c2][c1])
### BUGGY CODE ###

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

K = int(input())
count = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            d = gcd(a,b)
            count += gcd(c, d)
print(count)

### FIXED CODE ###

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

K = int(input())
count = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            d = gcd(a,b)
            count += gcd(c, d)
print(count)