第六回日本最強プログラマー学生選手権-予選-(AtCoder Regular Contest 201)
A
CatCoder Double Contest
AtCoder
⌀ 797
原题
←B →
翻译中…

Problem Statement

翻译中…

The problem setting of this problem is partially shared with Problem F.

翻译中…

In the year $2222$, CatCoder will hold the CatCoder Double Contest (abbreviated as C2C).

翻译中…

There are $N$ writers who have problem proposals. Each writer's problem proposals are classified into $3$ types by difficulty: Hard, Medium, Easy, and the $i$-th writer has $A_i$, $B_i$, $C_i$ problem proposals of Hard, Medium, Easy, respectively.

翻译中…

Each C2C simultaneously holds $2$ divisions, Div.1 and Div.2. The problem proposals required for each division are as follows:

翻译中…
  • Div.1: One Hard and one Medium problem proposal from the same writer
  • Div.2: One Medium and one Easy problem proposal from the same writer
翻译中…

Note that the writers for Div.1 and Div.2 do not necessarily have to be the same. Also, each problem proposal can be used in at most one division of one C2C.

翻译中…

Find the maximum number of times C2C can be held.

翻译中…

$T$ test cases are given, so find the answer for each.

翻译中…

Constraints

翻译中…
  • $1 \le T \le 10^5$
  • $1 \le N \le 2 \times 10^5$
  • $1 \le A_i,B_i,C_i \le 10^9$
  • The sum of $N$ over all test cases is at most $2 \times 10^5$.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

N
A_1 B_1 C_1
A_2 B_2 C_2
\vdots
A_N B_N C_N

翻译中…

Output

翻译中…

Output $T$ lines.

翻译中…

The $i$-th line should contain the maximum number of times C2C can be held for the $i$-th test case.

翻译中…

样例

Input #1
5
2
3 1 4
1 5 3
1
1 1 1
3
5 7 5
1 11 99
3 1 2
5
1000000000 1000000000 1000000000
1000000000 1000000000 1000000000
1000000000 1000000000 1000000000
1000000000 1000000000 1000000000
1000000000 1000000000 1000000000
6
835549144 866512240 105679868
473233032 625162103 823002638
125467290 37501686 380787083
8043910 721085797 254272563
97327826 744196952 18713225
978152989 90127986 33086297
Output #1
2
0
7
2500000000
998830769
For the first test case, C2C can be held $2$ times by using problem proposals as follows: | | Div.1 | Div.2 | | --- | --- | --- | | $1$st time | Hard, Medium from the $1$st writer | Medium, Easy from the $2$nd writer | | $2$nd time | Hard, Medium from the $2$nd writer | Medium, Easy from the $2$nd writer |
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。