question archive give me a code in python in a lab that grows specialised bacteria for therapeutic purposes
Subject:Computer SciencePrice: Bought3
give me a code in python in a lab that grows specialised bacteria for therapeutic purposes. There are 2 types of substrate that are used to grow the bacteria. After 1 week of growing on type 1, the amount of bacteria multiplies by a factor of a, and after growing for the same time period on type 2 substrate, the bacteria multiplies by a factor b. When a vial is prepared, it is given a unique identifier, and filled with substrate of one of the 2 types, and a certain amount of bacteria (measured by weight) is added to the vial. This amount is carefully recorded on a card, along with the identifier. Bacteria don't do so well if left for too long in the same vial, so on Mondays, each vial that was set on the previous Monday, harvests any bacteria in it and transfers all of it to another fresher vial, but a person will mix bacteria from at most one vial of each type of substrate when doing that and keeps careful notes of such transfers, recording it on a card, in the format:
i q j k
to indicate that vial j was of type 1 and vial k was of type 2 and their harvested bacteria was mixed into vial i, which contained q weight units of the bacteria at the time of the mixing.
If only one vial was harvested and added to vial i, the other type is filled in with a placeholder of zero. In fact, when a fresh vial is prepared, this is how she recorded it: placing 2 zeros in the positions of j and k in the format.
One Tuesday, towards the end of the experiment, the person was all n of their cards together to determine the expected harvest of bacteria, when all of them fell to the floor in a great mess
Help make sense of the information on the cards and determine the largest amount of bacteria expected to be in any vial, up to the point of her last mixing activity on the previous day.
The numbers can get very large, so report your answers reduced modulo m, a constant that will be provided with the input.
Input Format
Line 1: n m
Line 2: a b
Each of the following n lines is in the format:
i q j k
which indicates that vial i had quantity q, when vial j (of type 1) and vial k (of type 2) were mixed into it. If either j or k is 0, then no bacteria from the corresponding type of substrate was added to vial i.
Output Format
A single integer indicating the largest quantity of bacteria expected to be contained within a single vial, reduced modulo .
Sample Input 0
5 101
2 3
1 7 2 4
2 3 0 0
3 11 1 5
4 1 0 0
5 9 0 0
Sample Output 0
70
Explanation 0
Scanning through the list, we can see that vials 2, 4, and 5 are all starters (because they have identifiers of 0 for their types 1 and 2 contributions). They started with 3, 1, and 9 units of bacteria, respectively, although we do not know whether they all were started at the same time.
The entry 1 7 2 4 tells us that vial 2 was a type 1 vial, and was added to vial 1 at the same time as vial 4 was, which was a type 2 vial. Also, at the time of that mixing, vial 1 had 7 units of bacteria. Since a=2, the bacteria in vial 2 (of type 1) would have doubled to 6 units, and since b=3 the bacteria in vial 4 would have tripled to 3 units. So, a total of 6+3=9 units would have been added to the 7 units already in vial 1, to produce 16 units at that time.
The entry 3 11 1 5 tells us that vial 1 was actually a type 1 substrate, and vial 5 had type 2. Also, it tells us that vial 5 must have been prepared at the same time that vial 1 had been mixed. So, the amounts being added from vial 1 would have grown to 2*16=32 and the amount in vial 5 would have tripled to 27 (3*9) units, contributing a total of 32+27 =59 units to the already in vial 3, yielding a total of 59+11=70 units.
Reporting 70 modulo 101 is still 70, so our final answer is unchanged.
def calcQty(cards, m, a, b):
# Calculate max quantity of bacteria in any vial
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
m = int(first_multiple_input[1])
second_multiple_input = input().rstrip().split()
a = int(second_multiple_input[0])
b = int(second_multiple_input[1])
cards = []
for _ in range(n):
cards.append(list(map(int, input().rstrip().split())))
result = calcQty(cards, m, a, b)
fptr.write(str(result) + 'n')
fptr.close()