# Grouping large groups into smaller groups while keeping people together

Let's say we have a grouping of people as such:

   Group People
1      1     40
2      2     40
3      3     43
4      4     15
5      5     41
6      6     10
7      7     23
8      8     17
9      9     32
10    10     31
11    11     21
12    12     12
13    13     25


There are 350 people and the goal of this problem is to group those people into "tables" of size 9.

Rules:

-Make sure that all people are sitting with at least one other person of their original group

-It is best to have 9 people from the same group at the same table but obviously that will not be possible after dividing groups enough times.

-If one person cannot be grouped with another person of their original group, that is okay, but only at the end of the tabling.

-There are 350/9 = 38.88889 possible tables, so we round up to 39 possible tables. The 39th table will have less than 9 people.

Any ideas for the solution of this problem?