{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"There is a number of disjoint vertical line segments in the plane. We say that two segments are horizontally visible if they can be connected by a horizontal line segment that does not have any common points with other vertical segments. Three different vertical segments are said to form a triangle of segments if each two of them are horizontally visible. How many triangles can be found in a given set of vertical segments?\r\u003cbr\u003e\r\u003cbr\u003e\r\u003cbr\u003eTask\r\u003cbr\u003e\r\u003cbr\u003eWrite a program which for each data set:\r\u003cbr\u003e\r\u003cbr\u003ereads the description of a set of vertical segments,\r\u003cbr\u003e\r\u003cbr\u003ecomputes the number of triangles in this set,\r\u003cbr\u003e\r\u003cbr\u003ewrites the result.\r\u003cbr\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains exactly one positive integer d equal to the number of data sets, 1 \u0026lt;\u003d d \u0026lt;\u003d 20. The data sets follow.\r\u003cbr\u003e\r\u003cbr\u003eThe first line of each data set contains exactly one integer n, 1 \u0026lt;\u003d n \u0026lt;\u003d 8 000, equal to the number of vertical line segments.\r\u003cbr\u003e\r\u003cbr\u003eEach of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:\r\u003cbr\u003e\r\u003cbr\u003eyi\u0027, yi\u0027\u0027, xi - y-coordinate of the beginning of a segment, y-coordinate of its end and its x-coordinate, respectively. The coordinates satisfy 0 \u0026lt;\u003d yi\u0027 \u0026lt; yi\u0027\u0027 \u0026lt;\u003d 8 000, 0 \u0026lt;\u003d xi \u0026lt;\u003d 8 000. The segments are disjoint."}},{"title":"Output","value":{"format":"HTML","content":"The output should consist of exactly d lines, one line for each data set. Line i should contain exactly one integer equal to the number of triangles in the i-th data set."}},{"title":"Sample","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\u003e1\r\n5\r\n0 4 4\r\n0 3 1\r\n3 4 2\r\n0 2 2\r\n0 2 3\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}