Photomath Algorithm