If 18 of a pencil is black, 12 of the remaining is white and the remaining 312 cm is blue, find the total length of the pencil.