Optimization of compensation of magnetic field imperfection in K500 superconducting cyclotron