eolymp
bolt
Try our new interface for solving problems
Məsələlər

Page Count

Page Count

When you execute a word processor's print command, you are normally prompted to specify the pages you want printed. You might, for example, enter: \textbf{10-15,25-28,8-4,13-20,9,8-8} The expression you enter is a list of print ranges, separated by commas. Each print range is either a single positive integer, or two positive integers separated by a hyphen. In the latter case we call the first integer low and the second one high. A print range for which \textbf{low} > \textbf{high} is simply ignored. A print range that specifies page numbers exceeding the number of pages is processed so that only the pages available in the document are printed. Pages are numbered starting from \textbf{1}. Some of the print ranges may overlap. Pages which are common to two or more print ranges will be printed only once. (In the example given, pages \textbf{13}, \textbf{14} and \textbf{15} are common to two print ranges.) \InputFile The input will contain data for a number of problem instances. For each problem instance there will be two lines of input. The first line will contain a single positive integer: the number of pages in the document. The second line will contain a list of print ranges, as defined by the rules stated above. End of input will be indicated by \textbf{0} for the number of pages. The number of pages in any book is at most \textbf{1000}. The list of print ranges will be not be longer than \textbf{1000 }characters. \OutputFile For each problem instance, the output will be a single number, displayed at the beginning of a new line. It will be the number of pages printed by the print command.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
30
10-15,25-28,8-4,13-20,9,8-8
19
10-15,25-28,8-4,13-20,9,8-8
0
Çıxış verilənləri #1
17
12