line 14: User is prompted for input. You input "2" and press enter, which puts 2\n in cin's input buffer. The >> operator then extracts the number 2, which leaves \n in cin's input buffer.
line 18: Since the input buffer is not empty, the user is NOT prompted for input. Instead, getline extracts the \n from the input buffer. Making 'line' an empty string, and clearing the input buffer. The input buffer is now empty.
line 20: cnt=1
line 24: this loop is skipped because sz==0 (line is an empty string)
line 31: cnt is printed (printing your mysterious '1')
The solution is to clear the input buffer between line 14 and line 18. You can do this by calling getline an extra time, or by calling cin.ignore and ignore all character up to the next whitespace.