{"task": {"agent_timeout": 600, "task": "1183", "verifier_timeout": 7200, "instruction": "Please implement a Python 3 solution to the below problem.\nReason through the problem and:\n1. Restate the problem in plain English\n2. Conceptualize a solution first in plain English\n3. Write a pseudocode solution\n4. Save your solution as solution.py\nNo outside libraries are allowed.\n\n[BEGIN PROBLEM]\nFarmer John's $N$ cows ($N \\leq 3 \\times 10^5)$ have heights $1, 2, \\ldots, N$.  One day, the cows are\nstanding in a line in some order playing frisbee; let $h_1 \\ldots h_N$ denote\nthe heights of the cows in this order (so the $h$'s are a permutation of\n$1 \\ldots N$). \n\nTwo cows at positions $i$ and $j$ in the line can successfully throw the frisbee\nback and forth if and only if every cow between them has height lower than\n$\\min(h_i, h_j)$.  \n\nPlease compute the sum of distances between all pairs of locations $i<j$ at\nwhich there resides a pair of cows that can successfully throw the frisbee  back\nand forth.  The distance between locations $i$ and $j$ is $j-i+1$.\n\nINPUT FORMAT (input arrives from the terminal / stdin):\nThe first line of input contains a single integer $N$. The next line of input\ncontains $h_1 \\ldots h_N$, separated by spaces.\n\nOUTPUT FORMAT (print output to the terminal / stdout):\nOutput the sum of distances of all pairs of locations at which there  are cows\nthat can throw the frisbee back and forth.  Note that the large  size of\nintegers involved in this problem may require the use of 64-bit integer data\ntypes (e.g., a \"long long\" in C/C++).\n\nSAMPLE INPUT:\n7\n4 3 1 2 5 6 7\nSAMPLE OUTPUT: \n24\n\nThe pairs of successful locations in this example are as follows:\n\n\n(1, 2), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (4, 5), (5, 6), (6, 7)\n\nSCORING\nTest cases 1-3 satisfy $N\\le 5000$.Test cases 4-11 satisfy no\nadditional constraints.\n\n\nProblem credits: Quanquan Liu\n\n[END PROBLEM]\n", "memory": "2048m", "runnable": false, "difficulty": "medium", "language": "", "cpus": 1, "instruction_truncated": false, "category": "python_programming", "compose": false, "has_solution": true, "oracle": null, "docker_image": "", "taskset": "usaco", "tags": ["python", "programming", "usaco"]}, "runs": []}