#C3855. Perform Operations on a List
Perform Operations on a List
Perform Operations on a List
You are given a list \( L \) of \( n \) integers and a list of \( m \) commands. Each command is specified as a string and can be one of the following operations:
- count x: Count the number of occurrences of integer \( x \) in the list.
- index x: Find the index of the first occurrence of integer \( x \) in the list. If \( x \) is not present, output "ValueError: x is not in list".
Process each command in the order they appear and output the result for each command on a new line.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains a single integer \( n \), the number of elements in the list \( L \).
- The second line contains \( n \) space-separated integers representing the list \( L \).
- The third line contains an integer \( m \), the number of commands.
- The following \( m \) lines each contain a command in the format "command value", where command is either "count" or "index", and value is an integer.
outputFormat
For each command, output the result on a separate line:
- For a count command, output the number of occurrences of the given value in the list \( L \).
- For an index command, output the index (0-indexed) of the first occurrence of the given value in \( L \). If the value is not found, output exactly "ValueError: x is not in list", where \( x \) is the queried integer.
9
1 2 3 3 3 4 5 6 3
5
count 3
index 3
count 5
index 2
index 10
4
2
1
1
ValueError: 10 is not in list
</p>