{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n N(3\u0026lt;\u003dN\u0026lt;\u003d20000) ping pong players live along a west-east street(consider the street as a line segment). \n \u003cbr\u003e \n \u003cbr\u003eEach player has a unique skill rank. To improve their skill rank, they often compete with each other. If two players want to compete, they must choose a referee among other ping pong players and hold the game in the referee\u0027s house. For some reason, the contestants can’t choose a referee whose skill rank is higher or lower than both of theirs. \n \u003cbr\u003e \n \u003cbr\u003eThe contestants have to walk to the referee’s house, and because they are lazy, they want to make their total walking distance no more than the distance between their houses. Of course all players live in different houses and the position of their houses are all different. If the referee or any of the two contestants is different, we call two games different. Now is the problem: how many different games can be held in this ping pong street? \n\u003c/div\u003e\n给定一个长度为N的序列,序列中的元素都不相同,有多少个下标三元组(i<j<k)满足A[i]<A[j]<A[k]或者A[i]>A[j]>A[k];"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains an integer T(1\u0026lt;\u003dT\u0026lt;\u003d20), indicating the number of test cases, followed by T lines each of which describes a test case. \n\u003cbr\u003e \n\u003cbr\u003e \n\u003cbr\u003eEvery test case consists of N + 1 integers. The first integer is N, the number of players. Then N distinct integers a1, a2 … aN follow, indicating the skill rank of each player, in the order of west to east. (1 \u0026lt;\u003d ai \u0026lt;\u003d 100000, i \u003d 1 … N). \n\u003cbr\u003e\n第一行一个整数n,表示测试数据组数。\u003c/br\u003e\n每组测试数据,第一行一个整数n,表示序列长度。\u003c/br\u003e\n接下来一行n个不同的数。"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output a single line contains an integer, the total number of different games.\u003c/br\u003e\n输出满足条件的三元组数量"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e1\n3 1 2 3\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e1\u003c/pre\u003e"}}]}