added counting for S and NP