algo contest t1. d with linear time