A company produces two types of goods, A and B, that require gold and silver. Each unit of type A requires 3gm of silver and 1 gm of gold while that of type B requires 1 gm of silver and 2gm of gold. The company can produce 9gm of silver and 8gm of gold. If each unit of type A brings a profit of Rs. 40 and that of type B Rs. 50, find the number of units of each type that the company should produce to maximize the profit. What is the maximum profit?