module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int n;
	int[] a;
}

void parseInput(T)(out Input input, T adapter)
{
	with (input)
	{
		adapter.readf!"%d\n"(n);
		a.length = n;
		for (int i = 0; i < n; i++)
		{
			adapter.readf!"%d "(a[i]);
		}
	}
}

struct Output
{
}

alias ModLong = Mod!long;

auto main2(Input* input)
{
	ModLong sum = ModLong(10 ^^ 9 + 7, 0);
	with (input)
	{
		ModLong subsum = ModLong(10 ^^ 9 + 7, 0);
		for (int i = cast(int)a.length - 2; i >= 0; i--)
		{
			subsum += a[i+1];
			sum += subsum * a[i];
		}
	}
	return sum.value;
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`3
1 2 3`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 11);
	}

	unittest // example2
	{
		string example =
`4
141421356 17320508 22360679 244949`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 437235829);
	}

	unittest // example3
	{
		string example =
``;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == _placeholder_);
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		parseInput(input, new StringAdapter(example));
	}
}

class StdinAdapter
{
	// readf!"%s"は使えない
	// https://issues.dlang.org/show_bug.cgi?id=19820
	uint readf(alias format, A...)(auto ref A args) { return std.stdio.readf!format(args); }
	string readln() { return std.stdio.readln().strip(); }
}

class StringAdapter
{
	import std.format;
	string _s;
	this(string input) { _s = input; }
	uint readf(alias format, A...)(auto ref A args) { return _s.formattedRead!format(args); }
	string readln()
	{
        string ret;
		auto i = _s.countUntil("\n");
		if (i == -1) { ret = _s; _s = ""; }
        else { ret = _s[0..i]; _s = _s[i+1..$]; }
		return ret;
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, new StdinAdapter());
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}

struct Mod(T)
if ((is(T : int) || is(T : long)))
{
    private
    {
        T _m;
        T _value;
    }
    invariant
    {
        assert(_m > 0);
        assert(_value >= 0);
        assert(_value < _m);
    }
    this() @disable;
    this(T m, T t)
    {
        _m = m;
        _value = t % m;
    }
    void value(T t) { _value = t % _m; }
    T value() const { return _value; }
    void opAssign(typeof(this) mod) { value = mod._value; }
    typeof(this) opBinary(string op)(T t)
    {
        static if (op == "+") { return Mod(_m, _value + t); }
        else static if (op == "-")
        {
            auto temp = _value - t % _m;
            if (temp < 0)
                temp += _m;
            return Mod(_m, temp);
        }
        else static if (op == "*") { return Mod(_m, _value * t); }
        else static if (op == "^^")
        {
            if (t < 0) assert(0);
            else if (t == 0) return Mod(_m, 1);
            else if (t == 1) return this;
            else if (t % 2 == 1) return this * (this ^^ (t - 1));
            else
            {
                auto temp = this ^^ (t / 2);
                return temp * temp;
            }
        }
        else static assert(0);
    }
    typeof(this) opBinary(string op)(typeof(this) mod) { return opBinary!op(mod._value); }
    void opOpAssign(string op)(T t) { this = this.opBinary!op(t); }
    void opOpAssign(string op)(typeof(this) mod) { opOpAssign!op(mod._value); }
    bool opEquals()(auto ref const T t) const { return _value == t; }
    bool opEquals()(auto ref const typeof(this) mod) const { return opEquals(mod._value); }
}
