[Question]
  [
[Programming Puzzles & Code Golf](https://codegolf.stackexchange.com/) is about to get a [new moderator](http://meta.codegolf.stackexchange.com/a/5749/26997), [Dennis](https://codegolf.stackexchange.com/users/12012/dennis)! This challenge is a tribute to him and our other active (or recently active) moderators: [Doorknob](https://codegolf.stackexchange.com/users/3808/doorknob), [Martin Büttner](https://codegolf.stackexchange.com/users/8478/martin-b%C3%BCttner), and [Chris Jester-Young](https://codegolf.stackexchange.com/users/3/chris-jester-young). The challenge title is meant to be read to the tune of the [Pepto Bismol song](https://www.youtube.com/watch?v=XghJuH6GSCo).
Basically, we're going to treat them all to pizza at [The Nineteenth Bite Pizzeria](https://chat.stackexchange.com/transcript/message/23740052#23740052), but we need to make sure they share it fairly because [some](https://chat.stackexchange.com/transcript/240?m=18791027#18791027) of [the](https://chat.stackexchange.com/transcript/240?m=19372677#19372677) mods are known to be pizza addicts!
The pizzas sold by the pizzeria are all rectangular blocks of text. The width and length of a pizza may be any non-negative integers as long as their product is divisible by four. Each grid space in the block of text pizza represents a slice, so it's always possible to split the slices up into four equal groups.
The mods will collectively order a single pizza, providing its width and length parameters to their server in any reasonable format such as `[width],[length]`. Just before the pizza arrives at their table, you need to label each slice with the initial of the mod who gets to eat it to ensure they all share fairly. Everyone should get the same number of slices.
* `E` is for Dennis
* `D` is for Doorknob
* `M` is for Martin
* `C` is for Chris
The mods are a little persnickety, however, and require that their respective sets of slices be [path-connected](https://en.wikipedia.org/wiki/Connected_space#Path_connectedness), that is, that all their slices can be reached from one another by moving up, down, left, and right, not crossing anyone else's slices (and not moving diagonal). The don't care *how* you do this as long as it is done.
Once you've accurately labeled each slice, deliver the pizza to the mods with an optional trailing newline.
Your labeler may be a program or a function and can print or return the labeled pizza. The shortest labeler in bites wins.
# Examples
**Example 1**
Order: `4,1`
Some Possible Labeled Pizzas:
```
EDMC
```
```
MEDC
```
```
CDEM
```
**Example 2**
Order: `4,4`
Some Possible Labeled Pizzas:
```
MMMM
CCCC
DDDD
EEEE
```
```
DEMC
DEMC
DEMC
DEMC
```
```
CCCC
DEEM
DEEM
DDMM
```
**Example 3**
Order: `8,3`
Some Possible Labeled Pizzas:
```
MMMMMMCC
DDDDCCCC
DDEEEEEE
```
```
DDDCMMMM
DCDCMEEE
DCCCMEEE
```
**Example 4**
Order: `20,5`
A Possible Labeled Pizza:
```
DDDDDDDDDDDDMCCCCCCCCCCC
DEEEEEEEEEEDMMMMMMMCCCCC
DEEEEEEEEEEDMMMCCCCCCCCC
DEEEEEEEEEEDMMMMMMMMCCCC
DDDDDDDDDDDDMMMMMMMMMMMC
```
(The `D`'s here are not [simply-connected](https://en.wikipedia.org/wiki/Simply_connected_space) but that's ok.)
  
[Answer]
# CJam, 20 bytes
```
q~1$*4/"CEDM"e*/:$N*
```
I think this should work :)
[Try it online](http://cjam.aditsu.net/#code=q~1%24*4%2F%22CEDM%22e*%2F%3A%24N*&input=8%203)
**Explanation:**
This first makes a pizza labeled CC…EE…DD…MM… from left to right and top to bottom, then sorts each row in alphabetical order. The only disconnections can happen between the C-E border and E-D border, or E-D border and D-M border (if they fall on adjacent rows). But the sorting ensures that the E's go to the right side and the D's go to the left side, as C<E>D<M, so the E's and the D's remain connected.
```
q~          read and evaluate the input
1$          copy the width
*4/         multiply with the height and divide by 4
"CEDM"e*    repeat each letter in "CEDM" that many times
/           split into rows of the given width
:$          sort each row
N*          join with newlines
```
[Answer]
# K, 61 bytes
```
{[a;b]{((+:;|:)@x!2)[r@x]}'!#r:(b;a)#,/{(_(a*b)%4)#x}'"EDMC"}
```
Examples:
```
ryan@DevPC-LX:~/golf$ rlwrap k2
K 2.8 2000-10-10 Copyright (C) 1993-2000 Kx Systems
Evaluation. Not for commercial use. 
\ for help. \\ to exit.
  `0:{[a;b]{((+:;|:)@x!2)[r@x]}'!#r:(b;a)#,/{(_(a*b)%4)#x}'"EDMC"}[4;1]
EDMC
  `0:{[a;b]{((+:;|:)@x!2)[r@x]}'!#r:(b;a)#,/{(_(a*b)%4)#x}'"EDMC"}[4;4]
EEEE
DDDD
MMMM
CCCC
  `0:{[a;b]{((+:;|:)@x!2)[r@x]}'!#r:(b;a)#,/{(_(a*b)%4)#x}'"EDMC"}[8;3]
EEEEEEDD
MMMMDDDD
MMCCCCCC
  `0:{[a;b]{((+:;|:)@x!2)[r@x]}'!#r:(b;a)#,/{(_(a*b)%4)#x}'"EDMC"}[20;5]
EEEEEEEEEEEEEEEEEEEE
DDDDDDDDDDDDDDDEEEEE
DDDDDDDDDDMMMMMMMMMM
CCCCCMMMMMMMMMMMMMMM
CCCCCCCCCCCCCCCCCCCC
  
ryan@DevPC-LX:~/golf$ 
```
I would hate to be the person who has to slice these things...
[Answer]
# Pyth, ~~30~~ 25 bytes
```
jb.eu_GkbceQs*R/*FQ4"EDMC
```
[Live demo and all test cases](https://pyth.herokuapp.com/?code=jb.eu_GkbceQs*R%2F*FQ4%22EDMC&input=%5B8%2C3%5D&test_suite=1&test_suite_input=%5B4%2C1%5D%0A%5B4%2C4%5D%0A%5B8%2C3%5D%0A%5B20%2C5%5D&debug=1).
Cut off 5 bytes thanks to @Jakube!
Same algorithm as my K answer...but a *lot* shorter.
30-byte version:
```
jb.e?%k2_bbcjkm*/*FQ4d"EDMC"hQ
```
[Live demo and all test cases for 50-byte version](https://pyth.herokuapp.com/?code=jb.e%3F%25k2_bbcjkm*%2F*FQ4d%22EDMC%22hQ&input=%5B8%2C3%5D&test_suite=1&test_suite_input=%5B4%2C1%5D%0A%5B4%2C4%5D%0A%5B8%2C3%5D%0A%5B20%2C5%5D&debug=1).
[Answer]
# Pyth, 20 bytes
```
VceQs*L/*FQ4"CEDM"SN
```
Uses @aditsu's sorting trick.
[Demonstration.](https://pyth.herokuapp.com/?code=VceQs*L%2F*FQ4%22CEDM%22SN&input=12%2C3&debug=0)
I came up with a large number of alternative programs of the same length while trying to golf this:
```
VceQs*L/*FQ4"CEDM"SN
VceQsCm"CEDM"/*FQ4SN
VceQs*L*FQ"CEDM"%4SN
VceQ%4s*L*FQ"CEDM"SN
VcQs*L/*Qvz4"CEDM"SN    (Newline separated input)
jbSMceQs*L/*FQ4"CEDM
Vcs*L/*FQ4"CEDM"hQSN
```
[Answer]
# [Stuck](http://esolangs.org/wiki/Stuck), ~~42~~ 33
It returns! And in awfully long form. :( -- I stole aditsu's sort idea to save 9 bytes :)
```
t;g*4/[4*"CEDM"z"];F*":j0GK'$:Nj
```
### Explanation:
```
t;g*4/                              # Take |-separated input,
                                    #   store the first value in var stack,
                                    #   multiply the two numbers and divide by 4.
      [4*"CEDM"z                    # Wrap that value in an array, make 3 copies
                                    #   to get a list of length 4, zip with "EDMC"
                "];F*":j0GK         # For each item, multiply letter by value to
                                    #   to get string, join the result, split into
                                    #   segments the size of the saved variable.
                            '$:Nj   # For each item, sort so the letters are in the correct
                                    #   order, join by newline, print.
```
### Example input:
```
20|5
```
### Example output:
```
CCCCCCCCCCCCCCCCCCCC
CCCCCEEEEEEEEEEEEEEE
DDDDDDDDDDEEEEEEEEEE
DDDDDDDDDDDDDDDMMMMM
MMMMMMMMMMMMMMMMMMMM
```
[Answer]
# Rev 1 C, 74
```
i;f(w,h){for(i=w*h;i--;i%w||puts(""))putchar(h-i/w*2==1^"CDEM"[i*4/w/h]);}
```
For a 1-byte saving, this version reverses (only) the middle row of slices for any odd number of rows.
# Rev 0 C,75
```
i;f(w,h){for(i=w*h;i--;i%w||puts(""))putchar(h==3&i/w==1^"CDEM"[i*4/w/h]);}
```
Many answers here zigzag, but in most cases, just outputting the letters in order (left to right, top to bottom) works fine:
No need to zigzag for heights 1,2 or 4
No need to zigzag for heights greater than 4 (each mod's pizza ration will wrap around.)
Therefore we only actually need to zigzag when the height is 3, and then we only need to reverse the middle row.
As it turns out, Dennis and Doorknob are the only mods on that row. And they can be interchanged by XORing their ASCII codes with 1.
This is handy given that there's no easy way to reverse a string in C.
Ungolfed in test program
```
i;
f(w,h){
  for(i=w*h;i--;i%w||puts(""))            //loop through all squares. puts inserts a newline at the END of each line.
  putchar(h==3&i/w==1^"CDEM"[i*4/w/h]);   //put the letter, XORing D and E for the middle row of height 3.
}
W,H;
main(){
  scanf("%d%d",&W,&H);
  f(W,H);
} 
```
[Answer]
# JavaScript (ES6) 107
Zigzag solution. Using template string, the newline is significant and counted.
Test running the snippet with FireFox.
```
f=(w,h)=>{for(i=o=r='',z=l=1;--l?l:c='CDEM'[l=w*h/4,i++];r[w-1]&&(o+=r+`
`,r='',z=!z))r=z?r+c:c+r;return o}
//TEST
(test=_=>([w,h]=I.value.match(/\d+/g),O.innerHTML=f(w,h)))()
```
```
<input id=I value='8 3'><button onclick='test()'>-></button>
<pre id=O></pre>
```
[Answer]
## [Retina](https://github.com/mbuettner/retina), 83 bytes
The features used in this answer are newer than this challenge (not that it matters...). Byte count assumes ISO 8859-1 encoding.
```
\d+
$*#
#(?=.*¶(.+))
$1
\G####
CDEM
S_`((.)+?(?=.*¶(?<-2>#)+$))|\D
O`.
T`DE`ED
O%`.
```
[Try it online!](http://retina.tryitonline.net/#code=XGQrCiQqIwojKD89LirCtiguKykpCiQxClxHIyMjIwpDREVNClNfYCgoLikrPyg_PS4qwrYoPzwtMj4jKSskKSl8XEQKT2AuClRgREVgRUQKTyVgLg&input=Mwo4)
This implements aditsu's solution which is now somewhat feasible thanks to the new sort stages.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
×:4“CEDM”xsṢ€Y
```
[Try it online!](https://tio.run/##y0rNyan8///wdCuTRw1znF1dfB81zK0ofrhz0aOmNZH/Dy/X18x61Ljv0LZD2/7/jzbRMYzVUQBSJiDKQscYRBkZ6JiCaGMdi1gA "Jelly – Try It Online")
Implements [aditsu's algorithm](https://codegolf.stackexchange.com/a/55585/66833)
## How it works
```
×:4“CEDM”xsṢ€Y - Main link. Takes h on the left and w on the right
×              - Yield h×w
 :4            - Integer divide by 4; Yield R = (h×w):4
   “CEDM”      - Yield "CEDM"
         x     - Repeat each character R times
          s    - Split into rows of length w
           Ṣ€  - Sort each row
             Y - Join by newlines
```
]