(Not ZC specific): programming code for total based on price/quantity

(Not ZC specific): programming code for total based on price/quantity

I have a non-ZC related, general programming question I thought I would post here:

A = the price of purchaser's 1st apple
B = the price of any 2 or more apples, different than A
C = the price of purchaser's 1st banana
D = the price of any 2 or more bananas, different than C

X = total number of apples, can vary, can equal zero
Y = total number of bananas, can vary, can equal zero

total = ???

I'm having an algebra meltdown and can't wrap my head around this seemingly simple equation...