@@ -0,0 +1,1993 @@
+//https://www.hackerrank.com/contests/w2/challenges/manasa-and-stones%0D%0Aimport java.io.*;%0D%0A%0D%0Apublic class Solution%7B%0D%0A    %0D%0A    public static void main(String%5B%5D args) throws IOException %7B%0D%0A        StringBuffer sb = new StringBuffer();%0D%0A        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));%0D%0A        for(byte T = Byte.parseByte(br.readLine()); T %3E 0; --T)%7B%0D%0A            short N = Short.parseShort(br.readLine());%0D%0A            short A = Short.parseShort(br.readLine());%0D%0A            short B = Short.parseShort(br.readLine());%0D%0A            %0D%0A            //Each stones's difference has two choices: Either it's A or B%0D%0A            //If we have 4 stones, that's 2%5E3 different permutations%0D%0A            //But the order does not matter: %0D%0A            //    AAB's last stone == ABA's last stone == BAA's last stone%0D%0A            // The only thing that matters is the amount of A's and B's%0D%0A            //If we make sure A %3C= B, we know A * N is the min value for last stone.%0D%0A            //Then we switch each stone consecutively from A to B %0D%0A            //by adding the difference of A and B, resulting in min to max last stone values%0D%0A            %0D%0A            //Make sure A %3C= B%0D%0A            if (A %3E B)%7B%0D%0A                short temp = A;%0D%0A                A = B;%0D%0A                B = temp;%0D%0A            %7D%0D%0A            %0D%0A            //Get min value of last stone (all A's)%0D%0A            //There are N-1 gaps between stones%0D%0A            int val = ((int)--N)*A;%0D%0A            %0D%0A            //Calculate change in val per switch to B%0D%0A            short dval = (short)(B - A);%0D%0A            %0D%0A            //Print possible last stone values from smallest to largest%0D%0A            //Avoid duplicate prints if A == B (dval == 0)%0D%0A            sb.append(val);%0D%0A            if (dval %3E 0)%7B%0D%0A                while(N-- %3E 0)%7B%0D%0A                    sb.append(%22 %22 + (val += dval));%0D%0A                %7D%0D%0A            %7D%0D%0A            sb.append(%22%5Cn%22);%0D%0A        %7D%0D%0A        System.out.print(sb);%0D%0A    %7D%0D%0A%7D

Add solution to manasa-and-stones for 2nd weekly contest