Optimize finding number of subjects and courses