![]()
Trump is on the move. Tariff after tariff, he put on other countries.
You, a good American citizen, will help Trump automate his tariff using a combination of functions.
Given T countries that have money and their old tariff. You are given N simple functions that define a function composition F, F(old_tariff_rate) is the new tariff rate. Trump wants you to calculate the potential money that he will get for the great USA. Which is the sum of all countries new_tariff_rate * money.
Given this code:
class Country:
def __init__(self, money, tariff):
self.money = money
self.tariff = tariff
def func_comp(*funcs):
# Do something here
return F
t, n = map(int, input().split())
countries = {}
for _ in range(t):
line = input().split()
country_name, money, tariff_start = \
line[0], float(line[1]), float(line[2])
countries[country_name] = Country(money, tariff_start)
function_list = []
for _ in range(n):
line = input().split()
command = line[0]
num = int(line[1])
if command == "add":
# Do something
pass
elif command == "sub":
# Do something
pass
elif command == "div":
# Do something
pass
elif command == "mul":
# Do something
pass
elif command == "mod":
# Do something
pass
F = func_comp(*function_list)
# Continue this code
For each country:
new_tariff_rate = F(old_tariff_rate), (rate is a percentage, so for example if rate is 25, it means 25%)min(country_money, country_money * (new_tariff_rate / 100))
You will receive N lines of either one of these mini-functions:
add v means return x + vsub v means return x - vmul v means return x * vdiv v means return x / vmod v means return x % vYour task is to create a function composition of these functions. For example, you are given:
Your F function will equal:
> Note: remember to handle zero division error, for example x / 0 and x % 0, just return xfunc_comp function returns a function
The first line contains T and N,
T = the number of countries you will need to put a tariff on
N = the number of mini functions you will get to recalculate the next tariff rate
The next T lines you will get: country_name, country_money, country_old_tariff_rate
where:
- country_name is unique for each country
- country_money is a floating number
- country_old_tariff_rate is a floating number
The next N lines you will get: command, number
where:
- command is either add | sub | mul | div | mod
- number is an integer
T <= 1000N <= 1000number can be negativecountry_money is never negative
Output T countries and their money after the tariff is paid.
Output Trump's money, which is the sum of the money paid by all T countries
Format all floating numbers to 1 decimal place in the output.
e.g. 2.6667 = 2.7