Added solution to problem 3. Included 2 variants