# Marching Through A City

There is a parade marching through a city! There are 3 main groups of marchers: the (B)and, Poster (C)arriers, and (F)lag Holders. Also, every (P)oliceman in the whole city is on duty.

Flag holders (F) can march anywhere in the parade, but two flag holders cannot march next to each other, unless three or more flag holders are together.

The band (B) has to be together. The poster carriers (C) all have to be behind the band (either together, or in two groups).

Given the number of flag holders, poster carriers, band members, and policemen separated by your choice of delimiter, print one line for every possible configuration, organized in alphabetical order.

Test case 1:

Input:
2 2 2 0
Output:
CCFBBF
CFCBBF
CFCFBB
FCCBBF
FCCFBB
FCFCBB


Test case 2:

Input:
3 3 3 0
Output:
CCCBBBFFF
CCCFFFBBB
CCFCFBBBF
CCFFFCBBB
CFCCFBBBF
CFCFCBBBF
CFFFCCBBB
FCCCFBBBF
FCCFCBBBF
FCFCCBBBF
FCFCFCBBB
FFFCCCBBB


Test case 3:

Input:
2 2 2 1
Output:
CCBBFPF
CCFBBFP
CCFBBPF
CCFPBBF
CCFPFBB
CCPFBBF
CFCBBFP
CFCBBPF
CFCFBBP
CFCFPBB
CFCPBBF
CFCPFBB
CFPCBBF
CFPCFBB
CFPFCBB
CPCFBBF
CPFCBBF
CPFCFBB
FCCBBFP
FCCBBPF
FCCFBBP
FCCFPBB
FCCPBBF
FCCPFBB
FCFCBBP
FCFCPBB
FCFPCBB
FCPCBBF
FCPCFBB
FCPFCBB
FPCCBBF
FPCCFBB
FPCFCBB
FPFCCBB
PCCFBBF
PCFCBBF
PCFCFBB
PFCCBBF
PFCCFBB
PFCFCBB


This is code-golf, so the shortest source code in bytes wins.
*Note: It doesn't count if it takes longer than 3 seconds to run each test case. I won't use integers more than 20.

• What part is in alphabetical order? Commented Jul 1, 2016 at 12:31
• I've reopened it, but at least your first example still isn't in alphabetical order. Commented Jul 2, 2016 at 10:17
• @atlasologist the lines are sorted in alphabetical order Commented Jul 3, 2016 at 0:46
• I might be misunderstanding the conditions in the question, but for the first example, why is CFCBBF not a valid arrangement? Commented Jul 3, 2016 at 3:14
• @2012ssohn whoops, it is. It probably got deleted by accident during my test-case rewrite, sorry about that. Commented Jul 3, 2016 at 6:26

# Pyth, 56 bytes

jf&!},2\FrT8!:T"B.*C|C([^C]+C+){2}|B[^B]+B"0{S.ps*V"FCBP


Try it online!

• Could be golfed much further, but just post another answer if you are using Pyth. Commented Jul 1, 2016 at 10:25
• I changed specs, but since you submitted before I changed, you don't have to redo your submission - this is valid :) Commented Jul 2, 2016 at 7:29
• Well of course it would be easier if I can just obtain the number of police directly. Commented Jul 2, 2016 at 9:38

## CJam, 49 bytes

l~"BCFP".*(a\s+m!:s{_"FP"-W%_\$=\e[2'F]e=!&},_&N*


Try it online!

Input format is [B C F P]`.