
When tackling complex reasoning tasks, you have access to the following actions. Use them as needed to progress through your thought process.

[ASSESS]

[ADVANCE]

[VERIFY]

[SIMPLIFY]

[SYNTHESIZE]

[PIVOT]

[OUTPUT]

You should strictly follow the format below:

[ACTION NAME]

# Your action step 1

# Your action step 2

# Your action step 3

...

Next action: [NEXT ACTION NAME]


system
A certain pharmacy sells two types of masks, $A$ and $B$. It is known that selling 80 masks of type $A$ and 45 masks of type $B$ yields a profit of 21 yuan, while selling 40 masks of type $A$ and 60 masks of type $B$ yields a profit of 18 yuan.  
$(1)$ Find the profit per mask for type $A$ and type $B$.  
$(2)$ The pharmacy plans to purchase a total of 2000 masks of both types, with the quantity of type $B$ masks not less than the quantity of type $A$ masks and not exceeding three times the quantity of type $A$ masks. Let $x$ represent the quantity of type $A$ masks purchased. The total profit from selling these 2000 masks is $y$ yuan. Find the functional relationship between $y$ and $x$, and determine the range of values for the independent variable $x$.  
$(3)$ Under the conditions of $(2)$, how many masks of type $A$ and type $B$ should the pharmacy purchase to maximize the total profit?

Present the answer in LaTex format: \boxed{Your answer}
user