Form teams of three students so that each team contains one member from each skill type 1, 2, and 3.
Teams
gfgProblem
You are given students. Each student has a skill type: $1, \2, or \3$.
Your task is to form as many teams as possible such that each team contains exactly three students and the three students on a team have different skill types — one student of type $1, one of type \2, and one of type \3$.
After choosing the teams, output the number of teams and the indices of the students in each team.
Goal
Maximize the number of valid teams.
Notes
- Each student can belong to at most one team.
- Any valid assignment with the maximum number of teams is accepted.
Input Format
- The first line contains an integer .
- The second line contains integers , where each .
Output Format
- On the first line, output the maximum number of teams.
- Then output that many lines, each containing three integers: the indices of students in one team.
- The order of teams and the order of indices inside a team do not matter, as long as every team is valid.
Constraints
Example 1
Input
7 1 3 1 3 2 1 2
Output
2 3 5 1 6 7 2
Explanation
There are three students of type 1, two of type 2, and two of type 3, so at most 2 teams can be formed. One valid choice is (3,5,1) and (6,7,2), where each team has one student of each type.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.