#K32837. Conference Workshops

    ID: 24954 Type: Default 1000ms 256MiB

Conference Workshops

Conference Workshops

John is attending a conference that offers several workshops. Each workshop is defined by a start time and an end time. John wishes to maximize the number of workshops he can attend without any overlaps. Given multiple datasets, each representing a collection of workshops, determine the maximum number of non-overlapping workshops that can be attended for each dataset.

For each dataset, the input starts with an integer \(n\) (the number of workshops), and this is followed by \(n\) lines, each containing two integers \(s\) and \(e\) (the start and end times of a workshop). The input terminates when a dataset with \(n = 0\) is encountered.

Note: If the first number is 0, then there are no datasets to process.

inputFormat

The input is read from stdin and consists of one or more datasets. Each dataset starts with an integer \(n\) denoting the number of workshops. Following that are \(n\) lines, each with two space-separated integers: the start time \(s\) and the end time \(e\) of a workshop. A dataset with a single line containing \(0\) indicates the end of input.

outputFormat

For each dataset, output the maximum number of non-overlapping workshops that can be attended. Each result should be printed on a separate line to stdout.

## sample
3
1 3
2 4
3 5
0
2

</p>