The quick explanation of the problem: I have a list of items in a specific order that I group by into 2 lists, left and right. Now, let's say I want to print 10 elements, and the caveat is that I want to print as many as I can from the right list (i.e. if this list has 10 elements, then great all of them from this list), but if I fall short, I want to print from the left list, but those items that are closest to the right list.

One idea I had was this ... don't know if we can write shorter, terser code.

```
var totalToPrint = 10
var listA,listB = originalList group by where some condition that is bool and hence two lists
var interimRightList = listB.Take(totalToPrint);
var myfinallist = listA.Skip(listA.length - interimRightList.Count()) + interimRightList;    

```

This is really all my brain could come up with, if you know an easier way of doing this please let me know. I still have to aactually write the real C# code for this ... i'm making this sound simple (maybe it is), but dunno...

Here's the formal description:

Given an enumeration, for example: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}

I want to group these into two sets, A and B … a function will be provided to decide which set they belong to. For simplicity, let’s assume it’s putting into an Odd set and an Even set, given the above sequence.

Now, I want to output as many items from set B (let’s say X number of items), and then output as many items from set A (let’s say Y number of items), such that X + Y = Z and no more. In other words, if Z is 10, and X is 10, then we pick nothing from list A. Similarly if Z is 5, and X is 10, then we pick 5 elements from B, and none from A.

Also, this should be stable, i.e. the ordering should not be changed.

A more complete example  

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} – let’s assume our set dividing function is any element that is less than 11, goes into A, otherwise goes into B. And let’s say we have to print 3 elements. Therefore we’ll pick {11, 12} from B, and then pick {10} from A. and print in order … so that will print 10, 11, 12.

Here's how this looks in normal code:

```
int remaining = 10;
int a = 0;
for (int i = 0; i < listB.Count() && remaining > -1; ++i, ++a, remaining--)
{
   // don't print(listB[i]); i.e do nothing
}

if (remaining > 0)
{
    for (int i = listA.length - remaining; i < listA.length; ++i)
    {
        print(listA[i]);
    }
}

for (int i = 0; i < a; ++i)
{
     print(listB[i]);
}

```

FYI, this may sound like but is not an interview question, it's a real world problem.