## 11 Dec Tuesday Python Homework 18:30 – 22.12.06.

**Question for Linear Search:**

Creatnx now wants to decorate his house by flower pots. He plans to buy exactly N ones. He can only buy them from Triracle’s shop. There are only two kind of flower pots available in that shop. The shop is very strange. If you buy X flower pots of kind 1 then you must pay A×X^{2} and B×Y^{2} if you buy Y flower pots of kind 2. Please help Creatnx buys exactly N flower pots that minimizes money he pays.

**Input Format
**The first line contains a integer T denoting the number of test cases.

Each of test case is described in a single line containing three space-separated integers N,A,B.

**Output Format
**For each test case, print a single line containing the answer.

**Constraints**

1≤T≤105

1≤N,A,B≤105

Sample Input2 5 1 2 10 2 4Sample Output17 134ExplanationQuery 1: we have to buy exactly 5 pots. There are six possible options: Buy 0 pot of first kind, 5 pots of second kind. The cost is: 1×0^{2}+2×5^{2}=50. Buy 1 pot of first kind, 4 pots of second kind. The cost is: 1×1^{2}+2×4^{2}=33. Buy 2 pots of first kind, 3 pots of second kind. The cost is: 1×2^{2}+2×3^{2}=22. Buy 3 pots of first kind, 2 pots of second kind. The cost is: 1×3^{2}+2×2^{2}=17. Buy 4 pots of first kind, 1 pot of second kind. The cost is: 1×4^{2}+2×1^{2}=18. Buy 5 pots of first kind, 0 pot of second kind. The cost is: 1×5^{2}+2×0^{2}=25. So, the optimal cost is 17.

Sorry, the comment form is closed at this time.