[Question]
  [
Following [last year's event](https://codegolf.meta.stackexchange.com/q/24068/78410), we're doing [**Code Golf Advent Calendar 2022**](https://codegolf.meta.stackexchange.com/q/25251/78410)!
On each day from today (Dec 1) until Christmas (Dec 25), a Christmas-themed challenge will be posted, just like an Advent calendar. It is a free-for-all and just-have-fun-by-participation event, no leaderboards and no prizes for solving them fast or solving them in the shortest code. More details can be found in the link above.
---
I've got an infinite supply of two kinds of weirdly shaped chocolate:
* White chocolate, a square pyramid of side lengths 1
* Dark chocolate, a regular tetrahedon of side lengths 1
To celebrate the upcoming Christmas, I want to assemble them into a giant chocolate pyramid. When the base of the pyramid is a rectangle of size \$R \times C\$, the process to build such a pyramid is as follows:
1. Fill the floor with \$RC\$ copies of White chocolate.
2. Fill the gaps between White chocolate with Dark chocolate.
3. Fill the holes between Dark chocolate with White chocolate. Now the top face is a rectangle of size \$(R-1) \times (C-1)\$.
4. Repeat 1-3 until the top face has the area of 0.
The diagram below shows the process for \$2 \times 3\$. It takes 8 White and 7 Dark chocolate to complete the first floor, and 10 White and 8 Dark for the entire pyramid.
![](https://upload.acmicpc.net/84e118fc-f246-4388-9f46-958758d01da5/-/preview/)
Given the width and height of the base rectangle, how many White and Dark chocolate do I need to form the chocolate pyramid?
You may assume the width and height are positive integers. You may output two numbers in any order.
Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply. The shortest code in bytes wins.
## Test cases
```
(width, height) -> (white, dark)
(2, 3) -> (10, 8)
(10, 10) -> (670, 660)
(10, 1) -> (10, 9)
```
  
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 14 bytes
```
gʁ$vεƛΠε∑;:›"Ṡ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJnyoEkds61xpvOoM614oiROzrigLpcIuG5oCIsIiIsIls1LCAzXSJd)
The main observation here is that the amount of white chocolate \$w\$ and dark chocolate \$d\$ in a layer of size (a, b) is:
$$
w = ab +(a-1)(b-1) = 2ab - a - b + 1\\
d = (a-1)b+(b-1)a = 2ab - a - b
$$
In other words, the difference between white chocolate and dark chocolate for a layer is 1
```
 ʁ             # Range from 0 to...
g              # Minimum dimension of input
  $vε          # Subtract each from the input, creating a list of pairs of bases
     ƛ   ;     # Over each base pair [a, b]
      Π        # Product ab
       ε       # Take the absolute difference - [ab - a, ab - b]
        ∑      # Sum
          :›"  # Create an incremented pair for white
             Ṡ # Sum each into the final amounts
```
[Answer]
# [Desmos](https://desmos.com/calculator), ~~47~~ ~~46~~ 37 bytes
*-1 byte thanks to emanresu A*
*-9 bytes (!!!) thanks to alephalpha*
```
N=min(h,w)
f(w,h)=Nhw-N(NN+2)/3+[N,0]
```
\$f(w,h)\$ takes in the width \$w\$ and the height \$h\$ and returns a two-element list, with the number of white chocolates in the first element and the number of dark ones in the second element.
[Try It On Desmos!](https://www.desmos.com/calculator/zda2no9d8a)
Made my own closed form formula because I figured it would be fun :)
For those who are really curious, here’s some of the scratch work for how I came up with this formula (warning: it’s completely unreadable :P): [Scratch work](https://www.desmos.com/calculator/cdquopfsrb)
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 41 bytes
```
f(r,c)=if(r*c,[t=r*c+r--*c--,t-1]+f(r,c))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMGCpaUlaboWNzXTNIp0kjVtM4G0VrJOdIktkNIu0tXVStbV1SnRNYzVhqjQhGpwSywoyKnUSFTQtVMoKMrMKwEylUAcJYU0jcRow1gdhcRoo1hNTR2F6GgjHQVjoEC0oYGOgqEBnBUbCzUN5gwA)
---
# [PARI/GP](https://pari.math.u-bordeaux.fr), 41 bytes
```
f(r,c)=m=min(r,c);[t=1+3*r*c-m^2,t-3]*m/3
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMGCpaUlaboWNzXTNIp0kjVtc21zM_PATOvoEltDbWOtIq1k3dw4I50SXeNYrVx9Y6gGt8SCgpxKjUQFXTuFgqLMvBIgUwnEUVJI00iMNozVUUiMNorV1NRRiI420lEwBgpEGxroKBgawFmxsZoQ02DOAAA)
```
f(r,c)=m=min(r,c);[t=r*c*m+m/3-m^3/3,t-m]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMGCpaUlaboWNzXTNIp0kjVtc21zM_PATOvoEtsirWStXO1cfWPd3DhjfWOdEt3cWKgGt8SCgpxKjUQFXTuFgqLMvBIgUwnEUVJI00iMNozVUUiMNorV1NRRiI420lEwBgpEGxroKBgawFmxsZoQ02DOAAA)
Using the closed form formula.
[Answer]
# [R](https://www.r-project.org), ~~42~~ 39 bytes
*Edit: -3 bytes thanks to [@Giuseppe](https://codegolf.stackexchange.com/users/67312/giuseppe).*
```
\(r,c)-c(0,m<-min(r,c))+r*c*m+m/3-m^3/3
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGiNNulpSVpuhY31WM0inSSNXWTNQx0cm10czPzwHxN7SKtZK1c7Vx9Y93cOGN9Y6jy0DQNIx0FY01lBV07BQ1DAx0FC02uNA1jHQUjdDEQw9AAKmpmDuSZmRnAJZBUW2pCDF-wAEIDAA)
Port of [alephalpha's answer](https://codegolf.stackexchange.com/a/255044/58563).
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~41~~ 40 bytes
-1 byte thanks to [Sisyphus](https://codegolf.stackexchange.com/users/48931/sisyphus)
Based on [alephalpha’s PARI/GP answer](https://codegolf.stackexchange.com/a/255044/11261).
```
->a{r,c=a.sort
[t=r/3+c*r*r-r**3/3,t-r]}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsEiN9ulpSVpuhY3NXTtEquLdJJtE_WK84tKuKJLbIv0jbWTtYq0inSLtLSM9Y11SnSLYmuh6tUKFNyio410FIxjY7nAbEMDHQVDAxRebCxE9YIFEBoA)
[Answer]
# [C (GCC)](https://gcc.gnu.org), ~~76~~ ~~72~~ 70 bytes
* -4 bytes thanks to Conor O'Brien
* -2 bytes thanks to Keven Cruijssen
```
#define C(n,c)n(a,b){a=a*b?c*--b+n(a,b):0;}
C(f,a*b+--a)C(g,~-a*b+a--)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=hZBBCoJAGIX3nUIMYUb_ATOIcJIWQpdIkXF0ZBaNoeNK7CJt3HiTLtFtUkyoTcG_-d57PPjffeBJwXnfD40WZP88rbNcSJUbIVLAsUIMUtyygNnpkduEpM4s-S7tViESMBoOIQyHqIAbmYgRgt9tjwuTCuF2JZU2dF7rhLM6r89x0HqwhY27XEdFWaEpJQOXysOOSifwcHutRk0g08qMSFtZpMtG-8ZCyoSPUhl_kbOJQaCfPobiTwDTrpt_WRZ6AQ)
`f(a,b)` returns the number of black chocolates while `g(a,b)` the number of white chocolates.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~20~~ 19 bytes
```
Ｉ⁺ΣＥ⌊θΣ⁻Π⁻θι⁻θι⟦⌊θ⁰
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEIyCntFgjuDRXwzexQMM3My8zF8gu1NRRAItl5gFlA4ryU0qTS6C8Qh2FTE2gPDJPEyQQjazbIBYoZv3/f3S0kY6CcWzsf92yHAA "Charcoal – Try It Online") Link is to verbose version of code. Takes input as a tuple or list of (rows, columns). Explanation:
```
     θ              Input tuple
    ⌊               Minimum
   Ｅ                Map over implicit range
          θ         Input tuple
         ⁻          Vectorised minus
           ι        Current value
        Π           Take the product
       ⁻            Minus
             θ      Input tuple
            ⁻       Vectorised minus
              ι     Current value
      Σ             Take the sum
  Σ                 Take the sum
 ⁺                  Vectorised add
               ⟦    List of
                 θ  Input tuple
                ⌊   Minimum
                  ⁰ Literal integer `0`
Ｉ                   Cast to string
                    Implicitly print
```
Edit: Saved 1 byte by porting @Ausername's formula. The best closed form formula I could find was 22 bytes, but adapting one of @alephalpha's versions saves 1 byte:
```
Ｉ⁻⁻×Πθ⌊θ÷⁻Ｘ⌊θ³⌊θ³⟦⁰⌊θ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwzczr7QYSoZk5qYWawQU5aeUJpdoFGrqKADFM3NLc4FsIMczr8QlsywzJRWqPCC/PLVIA6FER8EYXYsxiIg2QBaN1dTUtP7/PzraCCgdG/tftywHAA "Charcoal – Try It Online") Link is to verbose version of code. Takes input as a tuple or list of (rows, columns). Explanation:
```
     θ                  Input tuple
    Π                   Product
   ×                    Multiplied by
       θ                Input tuple
      ⌊                 Minimum
  ⁻                     Subtract
            θ           Input tuple
           ⌊            Minimum
          Ｘ             Raised to power
             ³          Literal integer `3`
         ⁻              Subtract
               θ        Input tuple
              ⌊         Minimum
        ÷               (Integer) Divide by
                 ³      Literal integer `3`
 ⁻                      Vectorised subtract
                 ⟦      List of
                  ⁰     Literal integer `0`
                    θ   Input tuple
                   ⌊    Minimum
Ｉ                       Cast to string
                        Implicitly print
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
_ⱮṂ‘PḤ_SƲ€S;ṂÄ
```
A monadic Link that accepts a list of two integers, the base dimensions, and yields a pair of integers, `[dark, white]`.
**[Try it online!](https://tio.run/##y0rNyan8/z/@0cZ1D3c2PWqYEfBwx5L44GObHjWtCbYGCh1u@f//f7ShgY6hQSwA "Jelly – Try It Online")**
---
## 16 bytes
~~Probably~~ beatable with a constructive method, but I like it.
```
Ṃð‘c3×4+²×IAʋ;⁸Ä
```
A monadic Link that accepts a list of two integers, the base dimensions, and yields a pair of integers, `[dark, white]`.
**[Try it online!](https://tio.run/##AS0A0v9qZWxsef//4bmCw7DigJhjM8OXNCvCssOXSUHKizvigbjDhP///1sxMCwxMF0 "Jelly – Try It Online")**
### How?
```
Ṃð‘c3×4+²×IAʋ;⁸Ä - Link: Dimensions
Ṃ                - minimum (Dimensions)
 ð               - start a new dyadic chain - f(M=that, Dimensions)
  ‘              - increment (M)
   c3            - choose three -> (M-1)th triangular pyramidal number
     ×4          - times four (call this Q)
            ʋ    - last four links as a dyad - f(M, Dimensions):
        ²        -   square (M)
          I      -   forward differences (Dimensions) -> [Height-Width]
         ×       -   multiply -> [M*M*(Height-Width)]
           A     -   absolute value -> [M*M*|Height-Width|]
       +         - (Q) add (that) -> [dark piece count]
              ⁸  - chain's left argument -> M
             ;   - (dark piece count) concatenate (M) -> [dark piece count, M]
               Ä - cumulative sums -> [dark piece count, white piece count]
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 13 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
WÝ¨€-DPαOD>‚O
```
Port of [*@emanresuA*'s Vyxal answer](https://codegolf.stackexchange.com/a/255045/52210), so make sure to upvote him/her as well!
Input as a pair \$[width,height]\$; output as a pair \$[dark,white]\$.
[Try it online](https://tio.run/##yy9OTMpM/f8//PDcQyseNa3RdQk4t9Hfxe5Rwyz///@jjXSMYwE) or [verify all test cases](https://tio.run/##S0oszvifnFiiYKeQnJ@SqpdfnJiUmapgY6Pg6u/GZa@k8KhtkoKS/f/ww3MPrXjUtEbXJeDcRn8Xu0cNs/z/63CBFHGVZ2TmpCoUpSamKGTmcaXkcyko6OcXlOhDzIJSaMbbKKiA1eal/o820jGO5Yo2NNAxNIDSsVwA).
**Explanation:**
```
W             # Get the minimum of the (implicit) input-pair
 Ý            # Pop and push a list in the range [0,min]
  ¨           # Remove the last item to make the range [0,min)
   €-         # Subtract each from the (implicit) input-pair
     D        # Duplicate this list of pairs
      P       # Get the product of each inner pairs
       α      # Get the absolute difference with the values in the pairs
        O     # Sum each inner pair
         D    # Duplicate this list
          >   # Increase each inner value by 1
           ‚  # Pair the two lists together
            O # Sum each inner list
              # (after which this pair is output implicitly as result [dark,white])
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 20 bytes
```
_-h=SQ
sm+*FQ*F=tMQh
```
[Try it online!](https://tio.run/##K6gsyfj/P143wzY4kKs4V1vLLVDLzbbENxAoqmFooKNgaKAJAA "Pyth – Try It Online")
Takes (width, height), outputs (white, dark)
### Explanation
```
   =SQ            sort the input, set to Q
_-h               output dark - min(Q)
s                 sum of
 m          hQ    run min(Q) times:
  +                add
   *FQ             product of elements of Q
        =tMQ       decrement each element of Q
      *F           product of elements of Q
```
[Answer]
# Python 3, 83 bytes:
```
f=lambda r,c,w=0,d=0:f(r-1,c-1,w+r*c+(r-1)*(c-1),d+r*(c-1)+c*(r-1))if r*c else(w,d)
```
[Try it online!](https://tio.run/##XYpBCsMgEEX3OYXLGZ2CNpsQ8DBGIxVsKpOA5PTGBrrp4sN7j1/O4/XZxqlwa9Fm916CE0yeqtUUrJ4j8MOQ76uKpVdfRQk9IIVeblJe3h1TFP0k1ryvUClgK5y2AyI8aUQcfmY0Gf3niO0C)
[Answer]
# JavaScript (ES7), 40 bytes
Uses the closed form formula from [alephalpha's answer](https://codegolf.stackexchange.com/a/255044/58563).
Expects `(w)(h)`.
```
w=>h=>[n=w*h*(w<h?w:w=h)+(w-w**3)/3,n-w]
```
[Try it online!](https://tio.run/##bchLDkAwEADQvVN0OVPq150YDiIW4lcirSDm@BVLicXbvLW7u7M/lv1S1g2jn8gzVYaqxhJLI4FLU3PBZDAEViylxkRHVnHre2dPt43x5maYQOQIQiMG385SfP21yBD9Aw "JavaScript (Node.js) – Try It Online")
[Answer]
# [Python](https://www.python.org), 50 bytes
```
lambda p,q:(y:=(x:=min(p,q))*(3*p*q+1-x*x)//3,y-x)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3jXISc5NSEhUKdAqtNCqtbDUqrGxzM_M0gHxNTS0NY60CrUJtQ90KrQpNfX1jnUrdCk2oTr-Cosy8Eo00DSMdBWNNHQUNQwMdBQtNTS6YOIhvaACSMTMHMs3MDNAlYbosgRIQUxcsgNAA)
Same closed formula (@alephalpha's) everybody is using.
[Answer]
# [Lil](https://beyondloom.com/decker/lil.html), 59 bytes
```
on f x do
r:min x
t:(r/3)+(r*r*max x)-(r^3)/3
t,t-r
end
```
[Try it online!](https://ktye.github.io/zoo/#lil)
Same as alephalpha.
[Answer]
# [Pip](https://github.com/dloscutoff/pip) `-p`, 26 bytes
```
Y Ngy*a*b-y*(y*y+2)/3+[y0]
```
[Try It Online!](https://dso.surge.sh/#@WyJwaXAiLCIiLCJZIE5neSphKmIteSooeSp5KzIpLzMrW3kwXSIsIiIsIjEwIDEwIiwiLXAiXQ==)
Port of my Desmos answer.
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), 15 bytes [SBCS](https://github.com/abrudz/SBCS)
```
⌊××+3÷⍨1 ¯2-⌊×⌊
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=e9TTdXj64enaxoe3P@pdYahwaL2R7iOQGJAAAA&f=M1JIUzDmMjQAUoYGUBoA&i=AwA&r=tryapl&l=apl-dyalog&m=dfn&n=f)
Closed form formula from alephalpha's [PARI/GP answer](https://codegolf.stackexchange.com/a/255044/).
[Answer]
# Raku, 49 bytes
```
{my (\r,\c)=.sort;my \t=-r**3/3+r/3+c*r*r;t,-r+t}
```
[Try it online!](https://glot.io/snippets/gfzb0fb4ir)
[Answer]
# [Perl 5](https://www.perl.org/), 68 + 3 (`-pla` option) = 71 bytes
```
($i,$j)=@F;{$d+=$k=$i*$j*2-$i---$j--;$w+=$k+1;$i*$j&&redo}$_="$w $d"
```
[Try it online!](https://tio.run/##K0gtyjH9/19DJVNHJUvT1sHNulolRdtWJdtWJVNLJUvLSFclU1dXVyVLV9dapRwkoW1oDZZSUytKTcmvVYm3VVIpV1BJUfr/39BAwdCA619@QUlmfl7xf92CnEQA "Perl 5 – Try It Online")
[Answer]
# x86-64 machine code, 26 bytes
```
92 39 F0 73 01 96 6A 03 59 F7 E1 29 F0 F7 E6 F7 E6 01 F0 F7 F1 AB 29 F0 AB C3
```
[Try it online!](https://tio.run/##hVPBjtsgED3DV0xTuYK1HaW7UVWFppeee@mpUtMDCzgmtbEFeOsom1@vFxzvrtPLIuQZmPfejGdske@FGAbuaiDwY0FwsUG9KPegZJ@B4j1Gom6jE05OY3TgChyeME5fMG6D2s6VcMegbVqwItDqrgIVHdfdz/jj9ZXDpZzFpX6YaL5x8n/2dGmVx3RBGXbedsKDVa6rPJy08fC31F5lILn9w84MPzRaQkGugTc2gxF7MSVlw3ttRNVJBV@cl7pZll9xDNVcG0LxKaaeK1iGUWsDoiALgMdYCyoaCySSDrCFjyyYd8FGJ00phtl6Ziaf9eMigwOdqe1Mnqdv671o5M/rmqMvHD1y1sGJNaDwHrNEye2YXkfiG9WjkYoK8iG2bir5VStZ67CjmF1OA7DLOIIRdsZxv@bdme9clNooEI1Um7HwmLkPmVcZHMNRNnB66W@yuv0ZpI9bQjrj9N4oCaLk9oYW9Fefpr8pO8e5VwrIMZa96r/dzXsKJNFwf/TK0Z0JSn0Mho@oswZWDJ@Hf6Ko@N4Nef1pHR7hd9gGpqqeAA "C (gcc) – Try It Online")
Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes in RDI an address at which two 32-bit integers will be consecutively placed, for the white number and the dark number, in that order; and takes the width and height in ESI and EDX.
In assembly:
```
f:  xchg edx, eax    # Switch one argument into EAX.
    cmp eax, esi     # Compare the two arguments.
    jae s            # Jump if EAX holds the higher value.
    xchg esi, eax    # Otherwise, exchange the values.
s:                   # (Now, EAX holds the higher value (which we will call m)
                     #   and ESI holds the lower value (which we will call n).)
    push 3; pop rcx  # Set ECX to 3.
    mul ecx          # Multiply EAX by ECX (3), producing 3m.
                     # (Also, the high half of the product goes in EDX.)
    sub eax, esi     # Subtract ESI (n) from EAX, producing -n+3m.
    mul esi          # Multiply EAX by ESI (n), producing -n²+3mn.
    mul esi          # Multiply EAX by ESI (n), producing -n³+3mn².
    add eax, esi     # Add ESI (n) to EAX, producing -n³+3mn²+n.
    div ecx          # Divide EDX:EAX by 3, producing (-n³+3mn²+n)/3.
    stosd            # Write that value to the address EDI, advancing the pointer.
    sub eax, esi     # Subtract ESI (n) from EAX, producing (-n³+3mn²-2n)/3.
    stosd            # Write that value to the address EDI, advancing the pointer.
    ret              # Return.
```
]