Algorithm

Optimized by WPJAM Basic