Implement a function evaluate_expression(n, f) which takes an integer n and a list of tuples f that represent a nested expression in a custom format. Your implementation should evaluate the expression according to the following rules:
Each tuple in the list f consists of two elements: a level (integer) and an operator or value (string).
The level indicates the depth of the expression.
The operator can be '+' or '*' for addition and multiplication, respectively, or a string representing an integer for a base case.
The evaluation starts from the top level (level 0) and processes each operation:
For a '+' operator, sum the results of all evaluated sub-expressions at the next level (level + 1) until reaching the next same level.
For a '*' operator, multiply the results of all evaluated sub-expressions at the next level (level + 1) until reaching the next same level.
If a base case is reached, return the integer value of the string.
Input/Output Requirements
Input:
n: an integer representing the number of tuples in f.
f: a list of n tuples, where each tuple is formatted as (level, operator), where level is an integer and operator is a string.
Output:
The function should return an integer which is the result of the evaluated expression.
Example
python
# Example input
n = 5
f = [(0, '+'), (1, '3'), (1, '+'), (2, '4'), (2, '5')]
# Example output
result = evaluate_expression(n, f)
# Expected output: 12 (3 + (4 + 5))
Implementation Instructions
Write your solution in a file called /app/solution.py.
Ensure the function implements the described functionality and adheres to the input/output requirements outlined above.