algorithm of calculation