closed form SUM and COUNT