Six pencils can be put in three bags such that no bag contains the same number of pencils, only if:-
Case 1: One bag contains 1 pencil, the other one contains 2 pencils and the other one contains 3 pencils.
Case 2: One bag contains 1 pencil, the other one contains 1 pencil and the other one contains 4 pencils.
The pencils are different.
Analysis of Case 1:
3 pencils can be chosen from 6 in $\binom{6}{3}$ ways = 20 ways.
2 pencils from remaining 3 can be chosen in $\binom{3}{2}$ ways = 3 ways.
1 pencil from the remaining 1 pencil can be chosen in 1 way.
Now that we have formed the groups, the pencils can be arranged in 3 bags in 3! = 6 ways
So, total ways = 20 * 3 * 1 * 6 =360 ways.
Analysis of Case 2:
4 pencils can be chosen from 6 in $\binom{6}{4}$ ways = 15 ways.
1 pencils from remaining 2 can be chosen in $\binom{2}{1}$ ways = 2 ways.
1 pencil from the remaining 1 pencil can be chosen in 1 way.
Now that we have formed the groups, the pencils can be arranged in 3 bags in 3! = 6 ways
So, total ways = 15 * 2 * 1 * 6 =180 ways.
By addition rule of counting, number of ways = 360 + 180 = 540