Help with solving an algorithm

Hi, I am new to CP and I was trying to solve the codeforces problem 490 I am stuck, and I have tried to solve it but couldn’t. The editorial wasn’t very helpful to me.
And here is the editorial.

The teams could be formed using greedy algorithm. We can choose any three children with different skills who are not participants of any team yet and form a new team using them. After some time we could not form any team, so the answer to the problem is minimum of the number of ones, twos and threes in given array. We can get O(N) solution if we add children with different skills into three different arrays. Also the problem could be solved in O(N2) — every iteration find new three children for new team.

I am comfortable with java. Thanks appreciate the help.