//first get the number of toys to distribute Console.WriteLine("Please enter a number of toys to distribute"); int totaltoys = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("And how many children are we distributing toys to?"); int childnum = Convert.ToInt32(Console.ReadLine()); //next, we loop through the number of children to build a list of items that we can later convert to array for the calculation List wantslist = new List(); for (int i = 0;i < childnum;i++) { Console.WriteLine("How many toys does this child want?"); wantslist.Add(Convert.ToInt32(Console.ReadLine())); } int[] wants = wantslist.ToArray(); //in this problem we are subtracting each element in the array with its neighbor and getting its positive value or absolute. //next, we are summing them up. //to solve this, we are going to get the pairwise difference which is the difference of what each child wants after recieving a toy. next, we add that up and subtract it from the total toys. int value = 0; int sum = 0; for (int i = 0; i < wants.Length - 1; i++) { value = wants[i] - wants[i + 1]; //make the value absolute value = Math.Abs(value); sum += value; } //lastly add the last value of the toys to sum sum += wants.Last(); Console.WriteLine(totaltoys - sum); }