Solved algorithm 002