I need to compare in and out of money in multiple bank accounts.

Imagine this:

Imagine in row one i have all the "INs"

and in row two i have all the "OUTs"

now, how do i compare say first transaction in row one to say 5 transactions in row 2 and find the relationship

It can be:

1. Transaction IN 1 = Transaction OUT 3

2. Transaction IN 1 = Transaction OUT 2+4

3. Transaction IN 1 = Transaction OUT 3, or Transaction OUT 2+4

So if its a direct relation it just displays where they are equal, if they aren't how it will display which multiple transactions will be equal, and if there are 2 different possibilities it will show both answers.

Any tips how to do this efficiently?

If its only In = Out its pretty straight forward, but how do i code it to search for combinations of transactions say 1+2+5 efficiently.

Please help me out