Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, m = [int(item) for item in input().split()]
a, b = [], []
for i in range(n):
  a.append(input())
for j in range(m):
  b.append(input())

match_line = 0
for i in range(n):
  for j in range(n-m):
    for k in range(m):
      if a[i+k][j:j+m] == b[k]:
        match_line += 1
        if match_line >= m:
          print("Yes")
          exit()
      else:
        match_line = 0
        continue
print("No")

Fixed submission:
n, m = [int(item) for item in input().split()]
a, b = [], []
for i in range(n):
    a.append(input().rstrip())
for i in range(m):
    b.append(input().rstrip())

for i in range(n-m+1):
    for j in range(n-m+1):
        ans = True
        for k in range(m):
            for l in range(m):
                if not a[i+k][j+l] == b[k][l]:
                    ans = False
                    break
        if ans:
            print("Yes")
            exit()
print("No")

Buggy python submission (verdict: Runtime Error):
n, m = [int(item) for item in input().split()]
a, b = [], []
for i in range(n):
  a.append(input())
for j in range(m):
  b.append(input())

match_line = 0
for i in range(n):
  for j in range(n-m):
    for k in range(m):
      if a[i+k][j:j+m] == b[k]:
        match_line += 1
        if match_line >= m:
          print("Yes")
          exit()
      else:
        match_line = 0
print("No")

Fixed submission:
n, m = [int(item) for item in input().split()]
a, b = [], []
for i in range(n):
    a.append(input().rstrip())
for i in range(m):
    b.append(input().rstrip())

for i in range(n-m+1):
    for j in range(n-m+1):
        ans = True
        for k in range(m):
            for l in range(m):
                if not a[i+k][j+l] == b[k][l]:
                    ans = False
                    break
        if ans:
            print("Yes")
            exit()
print("No")

Buggy python submission (verdict: Runtime Error):
n, m = [int(item) for item in input().split()]
a, b = [], []
for i in range(n):
  a.append(input())
for j in range(m):
  b.append(input())

ans = [0] * (n-m)
for i in range(n):
  for j in range(n-m):
    if a[i][j:j+m] == b[i]:
      ans[j] += 1
      if ans[j] >= m:
        print("Yes")
        exit()
    else:
      ans[n-m] = 0
print("No")

Fixed submission:
n, m = [int(item) for item in input().split()]
a, b = [], []
for i in range(n):
    a.append(input().rstrip())
for i in range(m):
    b.append(input().rstrip())

for i in range(n-m+1):
    for j in range(n-m+1):
        ans = True
        for k in range(m):
            for l in range(m):
                if not a[i+k][j+l] == b[k][l]:
                    ans = False
                    break
        if ans:
            print("Yes")
            exit()
print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
edge = [[] for _ in range(n)]
visited = [0] * n

def dfs(n):
    visited[n] = 1
    if len(edge[n]) == 1 and n != 0:
        return 0
    childrank = []
    for item in edge[n]:
        if visited[item] == 1:
            continue
        childrank.append(dfs(item))
    childrank.sort(reverse=True)
    for i in range(len(childrank)):
        childrank[i] += i + 1
    return max(childrank)


for i in range(1, n):
    val = int(input()) - 1
    edge[i].append(val)
    edge[val].append(i)

print(dfs(0))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
a = []
edge = [[] for _ in range(n)]
visited = [0] * n

def dfs(n):
    visited[n] = 1
    if len(edge[n]) == 1 and n != 0:
        return 0
    childrank = []
    for item in edge[n]:
        if visited[item] == 1:
            continue
        childrank.append(dfs(item))
    childrank.sort(reverse=True)
    for i in range(len(childrank)):
        childrank[i] += i + 1
    return max(childrank)


for i in range(1, n):
    val = int(input()) - 1
    edge[i].append(val)
    edge[val].append(i)

print(dfs(0))
Buggy python submission (verdict: Runtime Error):
n = int(input())
xor = 0
rank = [0] * 12 
for i in range(n):
    a = int(input())
    LSB = (a & -a).bit_length()
    rank[LSB] += 1
    xor ^= a 

prev = False 
ans = 0
for i in range(10, -1, -1):
    bit = xor & (1 << i)
    if bit ^ prev:
        if rank[i+1] == 0:
            print(-1)
            exit()
        else:
            ans += 1
    prev = bit
print(ans)

Fixed submission:
n = int(input())
xor = 0
rank = [0] * 35 
for i in range(n):
    a = int(input())
    LSB = (a & -a).bit_length()
    rank[LSB] += 1
    xor ^= a 

prev = False 
ans = 0
for i in range(33, -1, -1):
    bit = xor & (1 << i)
    if (bit > 0 and prev == 0) or (bit == 0 and prev > 0):
        if rank[i+1] == 0:
            print(-1)
            exit()
        else:
            ans += 1
    prev = bit
print(ans)
Buggy python submission (verdict: Runtime Error):
n, x = [int(item) for item in input().split()]
if n == 1 or n == 2*n-1:
    print("No")
else:
    ans = [0] * (2*n - 1)
    used = [0] * (2*n - 1)
    if x >= n:
        ans[n-1] = 2*n-1
        used[2*n-1-1] = 1
        ans[n] = x
        used[x-1] = 1
        ans[n+1] = x-1
        used[x-2] = 1
        ans[n-2] = x-2
        used[x-3] = 1
    else:
        ans[n-1] = 1 
        used[0] = 1
        ans[n] = x
        used[x-1] = 1
        ans[n+1] = x+1
        used[x] = 1
        ans[n-2] = x+2
        used[x+1] = 1
    it = 0
    for i in range(2*n-1):
        if ans[i] == 0:
            while(used[it] != 0):
                it += 1
            ans[i] = it+1
            it += 1
    print("Yes")
    print(" ".join([str(item) for item in ans]))

Fixed submission:
n, x = [int(item) for item in input().split()]
if x == 1 or x == 2*n-1:
    print("No")
    exit()

if n == 2:
    print("Yes")
    print("1 2 3")
    exit()

ans = [0] * (2*n - 1)
used = [0] * (2*n - 1)
if x >= n:
    ans[n-1] = 2*n-1
    used[2*n-1-1] = 1
    ans[n] = x
    used[x-1] = 1
    ans[n+1] = x-1
    used[x-2] = 1
    ans[n-2] = x-2
    used[x-3] = 1
else:
    ans[n-1] = 1 
    used[0] = 1
    ans[n] = x
    used[x-1] = 1
    ans[n+1] = x+1
    used[x] = 1
    ans[n-2] = x+2
    used[x+1] = 1
it = 0
for i in range(2*n-1):
    if ans[i] == 0:
        while(used[it] != 0):
            it += 1
        ans[i] = it+1
        it += 1
print("Yes")
print(" ".join([str(item) for item in ans]))
Buggy python submission (verdict: Runtime Error):
print((a + b) * h // 2)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
print((a + b) * h // 2)
Buggy python submission (verdict: Time Limit Exceeded):
h, w, n = [int(item) for item in input().split()]
ab = [[int(item) for item in input().split()] for _ in range(n)]
poe = []
 
for a, b in ab:
    for i in range(3):
        for j in range(3):
            ah = a+i-1
            bw = b+j-1
            if ah > 1 and ah <= h-1 and bw > 1 and bw <= w-1:
                poe.append([ah, bw])
poe.sort()
 
ans = [0] * 10 
if len(poe) > 0:
    count = 1
    for i in range(1,len(poe)):
        if poe[i] == poe[i-1]:
            count += 1
        else:
            ans[count] += 1
            count = 1
    ans[count] += 1

print((w-2)*(h-2) - sum(ans))
for item in ans[1:]:
    print(item)

Fixed submission:
#!/usr/bin/env python3
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

h, w, n = [int(item) for item in input().split()]
blk_cnt = defaultdict(int) 

for i in range(n):
    a, b = [int(item) - 1 for item in input().split()]
    for j in range(-1, 2):
        for k in range(-1, 2):
            blk_cnt[(a + j, b + k)] += 1
ans = [0] * 10 
for key in blk_cnt.keys():
    if key[0] < 1 or key[1] < 1 or key[0] >= h-1 or key[1] >= w-1:
        continue
    ans[blk_cnt[key]] += 1
total = (w - 2) * (h - 2)
ans[0] = total - sum(ans)
for item in ans:
    print(item)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

count = [0] * 26
w = input()
for ch in w:
    count[ord(ch) - ord("a")] += 1
ok = True
for item in count:
    if item % 2 == 1:
        ok = False
print("Yes" if ok else "No")

Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

count = [0] * 26
w = input().rstrip()
for ch in w:
    count[ord(ch) - ord("a")] += 1
ok = True
for item in count:
    if item % 2 == 1:
        ok = False
print("Yes" if ok else "No")
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3.6
import bisect
n = int(input())
x = [int(item) for item in input().split()]
l = int(input())
q = int(input())
ab = []
for i in range(q):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    if a > b:
        a, b = b, a
    ab.append((a, b))

dt = [[0] * n for _ in range(40)]
for i, item in enumerate(x):
    dt[0][i] = i
    dt[1][i] = bisect.bisect_right(x, item + l) - 1

for i in range(2, 40):
    for j in range(n):
        dt[i][j] = dt[i-1][dt[i-1][j]]

for a, b in ab:
    days = 0
    is_ok = False
    while a < b:
        for i in range(0, 40):
            if dt[i][a] >= b:
                if i == 1:
                    days += 1
                    is_ok = True
                else:
                    a = dt[i-1][a]
                    days += 2**(i-2)
                break
        if is_ok:
            break
    print(days)

Fixed submission:
#!/usr/bin/python3.6
import bisect
n = int(input())
x = [int(item) for item in input().split()]
l = int(input())
q = int(input())
ab = []
for i in range(q):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    if a > b:
        a, b = b, a
    ab.append((a, b))

dt = [[0] * n for _ in range(40)]
for i, item in enumerate(x):
    dt[0][i] = i
    dt[1][i] = bisect.bisect_right(x, item + l) - 1

for i in range(2, 40):
    for j in range(n):
        dt[i][j] = dt[i-1][dt[i-1][j]]

for a, b in ab:
    days = 0
    is_ok = False
    while a < b:
        for i in range(0, 40):
            if dt[i][a] >= b:
                if i == 1:
                    days += 1
                    is_ok = True
                else:
                    a = dt[i-1][a]
                    days += 2**(i-2)
                break
        if is_ok:
            break
    print(days)
Buggy python submission (verdict: Time Limit Exceeded):
h, w, a, b = [int(item) for item in input().split()]

MOD = 10**9 + 7
n = 2 * 10**5
def mod_pow(x, n):
    ans = 1
    while(n != 0):
        if n & 1:
            ans = ans * x % MOD
        x = x * x % MOD
        n = n >> 1
    return ans

fac = [1] + [0] * n
fac_inv = [1] + [0] * n
for i in range(1, n+1):
    fac[i] = fac[i-1] * (i) % MOD
    # Fermat's little theorem says
    # a**(p-1) mod p == 1
    # then, a * a**(p-2) mod p == 1
    # it means a**(p-2) is inverse element
    fac_inv[i] = fac_inv[i-1] * mod_pow(i, MOD-2) % MOD

def mod_nCr(n, r):
    if n == 0 and r == 0:
        return 1
    if n < r or n < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD

ans = 0
for i in range(h-a):
    ans += mod_nCr(b-1+i, i) * mod_nCr(w-b-1 + h-1-i, h-1-i)
    ans %= MOD
print(ans)

Fixed submission:
h, w, a, b = [int(item) for item in input().split()]

MOD = 10**9 + 7
n = h + w 
def mod_pow(x, n):
    ans = 1
    while(n != 0):
        if n & 1:
            ans = ans * x % MOD
        x = x * x % MOD
        n = n >> 1
    return ans

fac = [1] + [0] * n
fac_inv = [1] + [0] * n
for i in range(1, n+1):
    fac[i] = fac[i-1] * (i) % MOD
    # Fermat's little theorem says
    # a**(p-1) mod p == 1
    # then, a * a**(p-2) mod p == 1
    # it means a**(p-2) is inverse element
    fac_inv[i] = fac_inv[i-1] * mod_pow(i, MOD-2) % MOD

def mod_nCr(n, r):
    if n == 0 and r == 0:
        return 1
    if n < r or n < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD

if a+b > (h+w)//2:
    ans = 0
    for i in range(h-a):
        ans += mod_nCr(b-1+i, i) * mod_nCr(w-b-1 + h-1-i, h-1-i)
        ans %= MOD
else:
    ans = mod_nCr(h-1+w-1, h-1)
    for i in range(b):
        ans -= mod_nCr(h-a-1+i, i) * mod_nCr(a-1 + w-1-i, a-1)
        ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

n, k = map(int, input().split())
radius = k // 2
edge = [[] for _ in range(n)]
uv = []
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)
    uv.append((a, b))

def dfs(p, v, d):
    ret = 0
    st = []
    st.append((p, v, d))
    while st:
        p, v, d = st.pop()
        if d > radius:
            ret += 1
        for nv in edge[v]:
            if nv == p:
                continue
            st.append((v, nv, d+1))
    return ret

ans = n 
if k % 2 == 0:
    for i in range(n):
        ret = dfs(-1, i, 0)
        ans = min(ans, ret)
else:
    for u, v in uv:
        ret = dfs(u, v, 0) + dfs(v, u, 0)
        ans = min(ans, ret)

print(ans)

Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from collections import deque

n, k = map(int, input().split())
radius = k // 2
edge = [[] for _ in range(n)]
uv = []
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)
    uv.append((a, b))

def dfs(p, v, d):
    ret = 0
    for nv in edge[v]:
        if nv == p:
            continue
        ret += dfs(v, nv, d+1)
    if d > radius:
        return ret + 1
    else:
        return ret

ans = n 
if k % 2 == 0:
    for i in range(n):
        ret = dfs(-1, i, 0)
        ans = min(ans, ret)
else:
    for u, v in uv:
        ret = dfs(u, v, 0) + dfs(v, u, 0)
        ans = min(ans, ret)

print(ans)
Buggy python submission (verdict: Runtime Error):
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = float('inf')

# ユニオンファインド木
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.rank = [0] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        elif self.rank[x] > self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = list(map(int, input().split()))     # スペース区切り連続数字
AB = [list(map(int, input().split())) for _ in range(M)]     # スペース区切り連続数字(行列)

un = UnionFind(N)
for a, b in AB:
    un.union(a, b)

g = len(un.roots())

print("{}".format(g-1))


Fixed submission:
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = float('inf')

# ユニオンファインド木
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.rank = [0] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        elif self.rank[x] > self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = list(map(int, input().split()))     # スペース区切り連続数字
AB = [list(map(int, input().split())) for _ in range(M)]     # スペース区切り連続数字(行列)

un = UnionFind(N)
for a, b in AB:
    un.union(a-1, b-1)

g = len(un.roots())

print("{}".format(g-1))
Buggy python submission (verdict: Time Limit Exceeded):
# coding:UTF-8
import sys
from math import factorial

MOD = 998244353
INF = 10000000000

def main():
    n, k = list(map(int, input().split()))  # スペース区切り連続数字
    lrList = [list(map(int, input().split())) for _ in range(k)]  # スペース区切り連続数字(行列)

    s = []
    for l, r in lrList:
        for i in range(l, r+1):
            s.append(i)

    Interm = [0] * (n + 1)
    Interm[0] = 0
    Interm[1] = 1
    for i in range(1, n+1):
        if i >= 2:
            for j in s:
                if n - j >= 1:
                    Interm[i] = (Interm[i] + Interm[i - j]) % 998244353

    result = Interm[n]
    # ------ 出力 ------#
    print("{}".format(result))

if __name__ == '__main__':
    main()


Fixed submission:
# coding:UTF-8
import sys
from math import factorial

MOD = 998244353
INF = 10000000000

def main():
    n, k = list(map(int, input().split()))  # スペース区切り連続数字
    lrList = [list(map(int, input().split())) for _ in range(k)]  # スペース区切り連続数字(行列)

    s = []
    for l, r in lrList:
        for i in range(l, r+1):
            s.append(i)
    s.sort()

    sum = [0] * (n + 1)
    Interm = [0] * (2 * n + 1)
    sum[1] = 1
    for i in range(1, n):
        for j in range(k):
            l, r = lrList[j][0], lrList[j][1]
            Interm[i+l] += sum[i]
            Interm[i+r+1] -= sum[i]
        sum[i+1] = (sum[i] + Interm[i+1]) % MOD

    # result = Interm[n]
    result = (sum[n] - sum[n-1]) % MOD
    # ------ 出力 ------#
    print("{}".format(result))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = 10000000000


def main():
    # ------ 入力 ------#
    N, Q = list(map(int, input().split()))     # スペース区切り連続数字

    queList = [list(map(int, input().split())) for _ in range(Q)]     # スペース区切り連続数字(行列)

    # ------ 処理 ------#
    black = (N-2)**2
    chList = [[N-2] * N for _ in range(2)]

    for que in queList:
        x = que[1]
        y = que[0]-1
        ch = chList[y][x]
        black -= ch
        for i in range(2, min(ch+2, N)):
            chList[1-y][i] = min(max(x-2, 0), chList[1-y][i])

    # ------ 出力 ------#
    print("{}".format(black))

if __name__ == '__main__':
    main()


Fixed submission:
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = 10000000000

# 二分探査
def binary_search(list, item):
    # 1:以上 2:以下　
    mode = 2
    low = 0
    high = len(list) - 1
    upper = len(list) - 1
    lower = 0
    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid - 1
            upper = mid
        else:
            low = mid + 1
            lower = mid
    if mode == 1:
        return upper
    elif mode == 2:
        return lower

def main():
    # ------ 入力 ------#
    N, Q = list(map(int, input().split()))     # スペース区切り連続数字

    queList = [list(map(int, input().split())) for _ in range(Q)]     # スペース区切り連続数字(行列)

    # ------ 処理 ------#
    black = (N-2)**2
    m = [N, N]
    chList = [[-1] * N for _ in range(2)]
    for que in queList:
        x = que[1]
        y = que[0]-1
        ch = chList[y][x]
        if ch == -1:
            ch = m[1-y] - 2
            m[y] = x
            i = 0
            while x+i <= N-1 and chList[y][x+i] == -1:
                chList[y][x+i] = m[1-y] - 2
                i = i + 1
        black -= ch

    # ------ 処理 ------#
    # black = (N-2)**2
    # div = [{2: N-2}, {2: N-2}]
    # for que in queList:
    #     x = que[1]
    #     y = que[0]-1
    #     kl = list(div[y].keys())
    #     d = binary_search(kl, x)
    #     ch = div[y][kl[d]]
    #     black -= ch
    #     if d == 0:
    #         div[y][x] = div[y][kl[d]]
    #         div[y] = dict(sorted(div[y].items(), key=lambda x:x[0]))
    #         div[1-y][list(div[1-y].keys())[d]] = max(x-2, 0)

    # ------ 出力 ------#
    print("{}".format(black))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    pro = 0
    for i in range(1,n+1):
        sum = 0
        for j in range(i+1,n+1):
            sum += aList[j-1]
        pro += sum * aList[i-1]

    out = resultSur97(pro)

    # ------ 出力 ------#
    print("{}".format(out))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")


Fixed submission:
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    sum = 0
    for i in range(0, n):
        sum += aList[i]

    pro = 0
    for i in range(0, n):
        ai = aList[i]
        sum = sum - ai
        pro += sum * aList[i]

    out = resultSur97(pro)

    # ------ 出力 ------#
    print("{}".format(out))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")

Buggy python submission (verdict: Time Limit Exceeded):
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    sum = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            sum += aList[i-1]*aList[j-1]

    out = resultSur97(sum)

    # ------ 出力 ------#
    print("{}".format(out))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")


Fixed submission:
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    sum = 0
    for i in range(0, n):
        sum += aList[i]

    pro = 0
    for i in range(0, n):
        ai = aList[i]
        sum = sum - ai
        pro += sum * aList[i]

    out = resultSur97(pro)

    # ------ 出力 ------#
    print("{}".format(out))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")