{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eYou are given an array $$$a_1, a_2, \\dots, a_n$$$. All $$$a_i$$$ are pairwise distinct.\u003c/p\u003e\u003cp\u003eLet\u0027s define function $$$f(l, r)$$$ as follows: \u003c/p\u003e\u003cul\u003e \u003cli\u003e let\u0027s define array $$$b_1, b_2, \\dots, b_{r - l + 1}$$$, where $$$b_i \u003d a_{l - 1 + i}$$$; \u003c/li\u003e\u003cli\u003e sort array $$$b$$$ in increasing order; \u003c/li\u003e\u003cli\u003e result of the function $$$f(l, r)$$$ is $$$\\sum\\limits_{i \u003d 1}^{r - l + 1}{b_i \\cdot i}$$$. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eCalculate $$$\\left(\\sum\\limits_{1 \\le l \\le r \\le n}{f(l, r)}\\right) \\mod (10^9+7)$$$, i.e. total sum of $$$f$$$ for all subsegments of $$$a$$$ modulo $$$10^9+7$$$.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains one integer $$$n$$$ ($$$1 \\le n \\le 5 \\cdot 10^5$$$) — the length of array $$$a$$$.\u003c/p\u003e\u003cp\u003eThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$, $$$a_i \\neq a_j$$$ for $$$i \\neq j$$$) — array $$$a$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint one integer — the total sum of $$$f$$$ for all subsegments of $$$a$$$ modulo $$$10^9+7$$$\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4\n5 2 4 7\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e167\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\n123456789 214365879 987654321\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e582491518\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eDescription of the first example: \u003c/p\u003e\u003cul\u003e \u003cli\u003e $$$f(1, 1) \u003d 5 \\cdot 1 \u003d 5$$$; \u003c/li\u003e\u003cli\u003e $$$f(1, 2) \u003d 2 \\cdot 1 + 5 \\cdot 2 \u003d 12$$$; \u003c/li\u003e\u003cli\u003e $$$f(1, 3) \u003d 2 \\cdot 1 + 4 \\cdot 2 + 5 \\cdot 3 \u003d 25$$$; \u003c/li\u003e\u003cli\u003e $$$f(1, 4) \u003d 2 \\cdot 1 + 4 \\cdot 2 + 5 \\cdot 3 + 7 \\cdot 4 \u003d 53$$$; \u003c/li\u003e\u003cli\u003e $$$f(2, 2) \u003d 2 \\cdot 1 \u003d 2$$$; \u003c/li\u003e\u003cli\u003e $$$f(2, 3) \u003d 2 \\cdot 1 + 4 \\cdot 2 \u003d 10$$$; \u003c/li\u003e\u003cli\u003e $$$f(2, 4) \u003d 2 \\cdot 1 + 4 \\cdot 2 + 7 \\cdot 3 \u003d 31$$$; \u003c/li\u003e\u003cli\u003e $$$f(3, 3) \u003d 4 \\cdot 1 \u003d 4$$$; \u003c/li\u003e\u003cli\u003e $$$f(3, 4) \u003d 4 \\cdot 1 + 7 \\cdot 2 \u003d 18$$$; \u003c/li\u003e\u003cli\u003e $$$f(4, 4) \u003d 7 \\cdot 1 \u003d 7$$$; \u003c/li\u003e\u003c/ul\u003e"}}]}