Sorry for taking so long to get back

Could not figure out a single formula solution, but maybe this will work for you :omnifold.sol1.xlsx

Hope this helps