Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from itertools import combinations

mod = 10 ** 9 + 7


def main():
    n = int(input())
    ls = list(map(int, input().split()))

    c = combinations(ls, 2)

    ans = 0

    for cc in c:
        ans += cc[0] * cc[1] % mod

    print(ans % mod)


main()



Fixed submission:
#!/usr/bin/env python3
MOD = 10 ** 9 + 7


class ModInt:
    def __init__(self, x):
        if type(x) is str:
            x = int(x)
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(self.x * pow(other.x, MOD - 2, MOD))
            if isinstance(other, ModInt)
            else ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD))
            if isinstance(other, ModInt)
            else ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x)
            if isinstance(other, ModInt)
            else ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(other.x * pow(self.x, MOD - 2, MOD))
            if isinstance(other, ModInt)
            else ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD))
            if isinstance(other, ModInt)
            else ModInt(pow(other, self.x, MOD))
        )


def main():
    n = int(input())
    ls = list(map(ModInt, input().split()))

    ans = ModInt(0)

    sm = sum(ls)

    for i in range(n):
        ans += ls[i] * sm

    sub = ModInt(0)
    for i in range(n):
        sub += ls[i] * ls[i]

    ans -= sub

    ans = ans / 2

    print(ans)


main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from itertools import combinations

mod = 10 ** 9 + 7


def main():
    n = int(input())
    ls = list(map(int, input().split()))

    c = combinations(ls, 2)

    ans = 0

    for cc in c:
        ans += cc[0] * cc[1] % mod

    print(ans % mod)


main()


Fixed submission:
#!/usr/bin/env python3
MOD = 10 ** 9 + 7


class ModInt:
    def __init__(self, x):
        if type(x) is str:
            x = int(x)
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x)
            if isinstance(other, ModInt)
            else ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(self.x * pow(other.x, MOD - 2, MOD))
            if isinstance(other, ModInt)
            else ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD))
            if isinstance(other, ModInt)
            else ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x)
            if isinstance(other, ModInt)
            else ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(other.x * pow(self.x, MOD - 2, MOD))
            if isinstance(other, ModInt)
            else ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD))
            if isinstance(other, ModInt)
            else ModInt(pow(other, self.x, MOD))
        )


def main():
    n = int(input())
    ls = list(map(ModInt, input().split()))

    ans = ModInt(0)

    sm = sum(ls)

    for i in range(n):
        ans += ls[i] * sm

    sub = ModInt(0)
    for i in range(n):
        sub += ls[i] * ls[i]

    ans -= sub

    ans = ans / 2

    print(ans)


main()