In an amount x gallons of 20% alcohol solution we have x/5 gallons of pure alcohol. In 9-x gallons of 50% alcohol solution we have (9-x)/2 gallons of pure alcohol. When we mix these quantities we get 0.3*9 gallons of pure alcohol. So x/5+(9-x)/2=2.7; multiply through by 10: 2x+5(9-x)=27.
2x+45-5x=27; 18=3x, x=6 gallons. So we need 6 gallons of 20% solution and 3 gallons of 50% solution.
1.2+1.5=2.7 gallons of pure alcohol, which is 0.3 of 9 gallons of mixture.