fork download
  1. import java.util.Scanner;
  2. class Solution
  3. {
  4. public static void main(String[]args)
  5. {
  6. Scanner s=new Scanner(System.in);
  7. int t=s.nextInt();
  8. while(t-->0)
  9. {
  10. int x=s.nextInt();
  11. int y=s.nextInt();
  12. int z=s.nextInt();
  13. if(x<=3)
  14. {
  15. System.out.print(x*y);
  16. }
  17. else if(x%3==0)
  18. {
  19. int result=(x*y)+((x/3-1)*z);
  20. System.out.print(result);
  21. }
  22. else
  23. {
  24. int temp=(x*y)+((x/3)*z);
  25. System.out.print(temp);
  26. }
  27. System.out.println();
  28. }
  29. }
  30. }
Success #stdin #stdout 0.17s 56660KB
stdin
4
2 12 10
3 12 10
7 20 8
24 45 15
stdout
24
36
156
1185