[Question]
  [
Here's a very simple little problem that I don't believe has been asked before.
# Challenge
Write a program or a function that takes in four positive integers that represents the lengths of movable but unbreakable and unbendable straight fences. Output the area of the largest rectangular yard that can be fully encompassed with these fences.
The fences can be moved and rotated in increments of 90°, but can't overlap or be cut.
Fences that just touch at a yard corner still count as encompassing the yard at that corner.
For example, given fence lengths 2, 8, 5, and 9, the best you can do is to make the 2 and 5 sides parallel, and the 8 and 9 sides parallel for a yard that is 2 by 8:
```
 888888885
2yyyyyyyy5
2yyyyyyyy5
9999999995
         5
```
Make any one side longer and the fences won't fully surround the yard. Thus the output here, the area of the yard, would be 16.
As another example, given 1, 1, 2, 2, the largest area yard that can be made is 2:
```
 22
1yy1
 22
```
A yard with area 1 like
```
22
1y1
 22
```
is a valid yard since it's perimeter is fully fenced, but 1 is an invalid output since it's not maximal.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest program wins!
You may *not* assume the 4 integer inputs to your program are in any particular order.
Here are some more test cases:
```
Inputs -> Output
1,1,1,1 -> 1
1,2,3,4 -> 3
4,3,2,1 -> 3
90,1,2,1 -> 2
1,90,1,1 -> 1
44,51,50,36 -> 1800
3,3,3,3 -> 9
3,3,3,4 -> 9
3,4,3,4 -> 12
4,4,3,4 -> 12
4,4,4,4 -> 16
```
  
[Answer]
# Python, 28 bytes
```
lambda*a:min(a)*sorted(a)[2]
```
It's an anonymous function that when called returns the answer, like `func(2,8,9,5) -> 16` or `func(1,1,2,2) -> 2`.
Unless I'm totally misunderstanding my own problem, I believe it can be solved by sorting the 4 input numbers and taking the smallest times the second biggest, since those sides will be matched parallel with the second smallest and the biggest respectively.
Like if the sorted inputs are `a <= b <= c <= d` then the biggest rect you can make will have area `a * c`, where side `a` is parallel to `b` and `c` parallel to `d`, and some of the `b` and `d` fences may have to be wasted.
(I'm a new user here so I'd love to know if this Python can be shortened at all. Thanks!)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `g`, 27 bits[v1](https://github.com/Vyxal/Vyncode/blob/main/README.md), 3.375 bytes
```
sI÷*
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=1#WyJBZz0iLCIiLCJzScO3KiIsIiIsIlsyLCAyLCAxLCAxXVxuWzgsIDUsIDIsIDldXG5bMiwgOSwgOCwgNV1cblszLCAzLCAzLCAzXVxuWzEsIDIsIDEsIDJdIl0=)
What I was thinking is that the side lengths can be split into two groups: those likely to be the long side of the rectangle and those likely to be the short side.
The long side of the rectangle will be the second most longest side, as it's guaranteed to be smaller or equal to than the other longer side.
The short side of the rectangle will be the shortest side, as it's guaranteed to be smaller than or equal to the other short side.
For example:
```
[2, 5, 8, 9]
```
The side length of 9 can't be the long side because there's no matching 9. But the side length of 8 can be because it's got that length in the 9. Hence, the second smallest length is the long side.
The side length of 5 can't be the short side, because there's no matching 5. But the side length of 2 can be because it's got that length in 5. Hence the smallest length is the short side.
## Explained
```
sI÷*
s    # sort the list ascending. The idea here is that the sides that are more likely to be the longer sides go to the end of the list and the ones likely to be the shorter sides go to the front. 
 I    # split the list into two halves - [shorts, longs] 
  ÷*  # dump each item onto the stack and multiply each item in shorts by each item in long. 
# the g flag gets the smallest item of that list, which is also the first item. 
```
[Answer]
# [Ly](https://github.com/LyricLy/Ly), 7 bytes
```
&napfp*
```
[Try it online!](https://tio.run/##y6n8/18tL7EgrUDr/38TEy5TQy5TAy5jMwA "Ly – Try It Online")
Similar to other solutions, this sorts the numbers the messes with the stack to get the smallest and second largest. Then it multiples them to get the answer.
```
&n       - read in all the numbers
  a      - sort
   p     - discard top (largest)
    f    - flip two entries (pushes 2nd largest down)
     p   - discard top (3rd largest)
      *  - multiple what's left (smallest and 2nd largest)
         - exits and prints what's on the stack as a number
      
```
[Answer]
# Excel, 22 bytes
```
=MIN(A:A)*SMALL(A:A,3)
```
The `SMALL()` function finds the nth smallest number in a range.
[![ScreenshotA](https://i.stack.imgur.com/w2BI2.png)](https://i.stack.imgur.com/w2BI2.png)
[![ScreenshotB](https://i.stack.imgur.com/ak8u6.png)](https://i.stack.imgur.com/ak8u6.png)
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata), 4 bytes
```
o;*ṁ
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFZtJJurlLsgqWlJWm6FsvyrbUe7mxcUpyUXAwVWnCzONpQBwxjuYAsIx1jHRMgywRIG4HFLA10DKFMQx0wB8Q0MdExNdQxNdAxNgPyjHXAEM4yAbNM4GYhs4AwFmI3AA)
```
o;*ṁ
o       Sort
 ;      Nondeterministically split the list into two parts
  *     Multiply; fails if the two parts have different lengths
   ṁ    Take the minimum
```
[Answer]
# [Julia](https://julialang.org), 24 21 **bytes**
-3 bytes: by @MarcMush
```
!a=(b=sort(a))[1]b[3]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=fY9BCsIwEEXX5hQjbloZoWmiqBDxAp6gdJHWFCsSJWn1MG668QgewUN4G9Oo1YXILMJ7n_xhzpdtvStlc78VSudKJCSh6CcFsQCKLcfIkHtmjrmj-JW3PIuQdiL2H7z6NHCOY4rjCNnk6aZR5DRDP17NOuZfzDumsd_8Q_C3mCBJL3VVjKbXvhRBJuzeVIEMw4SmWcJe2f1U7A0EpT6g1DaEUoO_nPSW0lplKui7TAgXEqXXhAzgSOdQBBI_jSJzncO21MV5bYzS1XIlTb6q7WYOf9Y3zfN9AA)
[Answer]
# [Arturo](https://arturo-lang.io), 20 bytes
```
$->a[sort'a a\0*a\2]
```
[Try it](http://arturo-lang.io/playground?Vyx02s)
Sort the lengths then multiply the first by the third. Same algorithm as blaketyro arrived at independently.
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + Linux utilities, 19
```
sort -n|dc -e??k?*p
```
Reads input from lines of STDIN.
### Explanation
```
sort -n              # sort numerically
       |             # pipe to ...
        dc -e        # ... dc expression
             ??      # push [1] and [2]
               k     # pop [2] to precision register (unused)
                ?    # push [3]
                 *   # pop and multiply [1] and [3]
                  p  # print
```
[Try it online!](https://tio.run/##S0oszvj/vzi/qERBN68mJVlBN9XePtteq@D/fxMTLlNDLlMDLmMzAA "Bash – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
Ṣm2P
```
A monadic Link that accepts a list of the four fence lengths and yields the maximal yard area.
**[Try it online!](https://tio.run/##y0rNyan8///hzkW5RgH///@PNtKx0DHVsYwFAA "Jelly – Try It Online")**
### How?
```
Ṣm2P - Link: list of integers, F
Ṣ    - sort -> [a, b, c, d]
 m2  - modulo-2 slice -> [a, c]
   P - product -> a × c
```
[Answer]
# [R](https://www.r-project.org/), 28 bytes
```
function(l)min(l)*sort(l)[3]
```
[Try it online!](https://tio.run/##K/qfZqP7P600L7kkMz9PI0czNxNEahXnF5UA6Wjj2P9pGskaJjomOsY6JpqaXGkaJlaGmv8B "R – Try It Online")
-2 bytes thanks to pajonk.
# [R](https://www.r-project.org/), 30 bytes
```
function(l)prod(sort(l)[!0:1])
```
[Try it online!](https://tio.run/##K/qfZqP7P600L7kkMz9PI0ezoCg/RaM4v6gEyI5WNLAyjNX8n6aRrGGiY6JjrGOiqcmVpmFiZaj5HwA "R – Try It Online")
[Answer]
# [J](https://www.jsoftware.com), 8 bytes
```
]`*/@\:~
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70wa8FOJT31NAVbKwV1BR0FAwUrINbVU3AO8nFbWlqSpmuxIjZBS98hxqoOwr25RpMrNTkjXyFNwRACEVwjBWMFExjXBMgxQshaGoAVIKkGi8D5JiYKpoYKpgYKxmYwIWMIROWaILgmqNZhcIEQ4uYFCyA0AA)
Sort down, then reduce from the right by alternatingly taking the right value and multiplying:
```
    \:~2 8 5 9
9 8 5 2
    ]`*/9 8 5 2
9]8*5]2 -> 9]8*2 -> 9]16 -> 16
```
[Answer]
# [Factor](https://factorcode.org) + `math.unicode`, 19 bytes
```
[ sort <evens> Π ]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=bdBNDsFAFAfw2PYUfwdo048hvmIrNjZiJRZNPTR0WjNTIeIkNt1wAfdwAKdR0yoSeYv38nsfmcz5uvADFYvsUTMn4-Fo0IGMhQr5EpK2KfGApEV7JXyJyFcrK-VhEM8JaxKcNkgEKXVIRMjVZwFdwzgaRzhlnFCH2YejyYUH9iYvJ5aD-5l6UdvWg5W5elPrzzXG0HDQsOE1K27Zdt7xyii1XRH7JfZNjquf89_YlzWN0yVVC7N1m-rvQo92xGUf9wyzonOJ_ARWUWdZkZ8)
Sort the input, get the elements at even indices, then take the product.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 26 bytes
```
N`
.+¶.+¶(.+)¶.+
$.($&*$1*
```
[Try it online!](https://tio.run/##K0otycxLNPyvqhGcoPPfL4FLT/vQNhDW0NPWBLG4VPQ0VNS0VAy1/v831AFDLkMdIx1jHRMuEyBpBORbGugYghmGOmCmIZeJiY6poY6pgY6xGZexDhhCaRMgbQLVjaCBEAA "Retina – Try It Online") Takes input on separate lines but link is to test suite that splits on commas for convenience. Explanation: Port of @blaketyro's Python answer.
```
N`
```
Sort numerically.
```
.+¶.+¶(.+)¶.+
$.($&*$1*
```
Multiply the first number by the third.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 13 bytes
```
Ｉ×⌊θ⌈Φθ⁻κ⌕θ⌈θ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEIyQzN7VYwzczLzO3NFejUFNHwTexAsx2y8wpSS3SKASKZOaVFmtk6yi4ZealgAWgSgo1ocD6///oaBMTHVNDHVMDHWOz2Nj/umU5AA "Charcoal – Try It Online") Link is to verbose version of code. Takes input as a list of four elements. Explanation:
```
   θ            Input list
  ⌊             Take the minimum
 ×              Multiplied by
      θ         Input list
     Φ          Filtered where
        κ       Current index
       ⁻        Subtract i.e. is not equal to
            θ   Input list
           ⌈    Take the maximum
         ⌕      First index in
          θ     Input list
    ⌈           Take the maximum
Ｉ               Cast to string
                Implicitly print
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 5 bytes
```
*F%2S
```
[Try it online!](https://tio.run/##K6gsyfj/X8tN1Sj4//9oExMdU0MdUwMdY7NYAA "Pyth – Try It Online")
### Explanation
```
*F%2SQ    # implicitly add Q
          # implicitly assign Q = eval(input())
    SQ    # sort Q
  %2      # take every other element (so first and third)
*F        # reduce on multiplication
```
[Answer]
# [Scala](https://www.scala-lang.org/), 25 bytes
Saved bytes thanks to the comments of @corvus\_192 and @user
---
Golfed version (25 bytes). [Try it online!](https://tio.run/##fZJLa8MwDMfv@RRaycEOacmrZS1LoIwddhg7rPfhJu7IyBIvVsZg9LNnsps@V2aMXz/pLyFZ56ISfbN@lznCSmq8F1pqkN8o60LDUin4cb5EBZsFe6zR42lGW9qLNBOTj7L2xEQ3LcpigqKsWMh7AGOOB6kUnoRiDtB4kZ8s9GGYHMYZHU5J5EPsQ2JJfCSJfY72PidkHlitA4rO5Ab6J1JCglMCU@LxbEdvg@BoENuAZlo4v0KSKyQ5IWF0lv//KDmgGRHu0LJpWmCsrFWHPrVDUX9k8dwh3TncjY8F5tQgo2aq3krdVUgl3@w8F/DqcUuF1rJFtjdILyR90KOH4QXcS7buEN4aBHdwN7lZfXDtNjIxtiZr1ZY1VjUbLavdH4DcfgJl4hc3ZLh1@l8)
```
a=>a.min*a.sorted.tail(1)
```
Alternative:
```
//scala 3
import scala.util.chaining._
def f(a:Int*):Int = a.sorted.pipe(a=>a(0)*a(2))
```
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2) `M`, 4 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
Ṡz€p
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728JKM0Ly_faGm0kq9S7IKlpSVpuhYrHu5cUPWoaU3BkuKk5GKo4IK10SYmOqaGOqYGOsZmsRBBAA)
#### Explanation
```
Ṡz€p  # Implicit input
Ṡ     # Sort in ascending order
 z    # Uninterleave ([a, b, c, d] -> [[a, c], [b, d]])
  €p  # Product of each inner pair
      # Implicit output of minimum (M flag)
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 4 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
{ιPß
```
[Try it online](https://tio.run/##yy9OTMpM/f@/@tzOgMPz//@PNtIx1bHQsYwFAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/6nM7Aw7P/6/zPzraSMdUx0LHMlYn2lAHDMEsIx1jHRMgywRIG4HFLA10DKFMQx0wB8Q0MdExNdQxNdAxNgPyjHXAEM4yAbNM4GYhs4AwNhYA).
**Explanation:**
```
{     # Sort the (implicit) input-quartet from lowest to highest
 ι    # Uninterleave it into two parts: [a,b,c,d]→[[a,c],[b,d]]
  P   # Get the product of both inner lists
   ß  # Get the minimum of this pair
      # (which is output implicitly as result)
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-g`](https://codegolf.meta.stackexchange.com/a/14339/), 5 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
Íó Ë×
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LWc&code=zfMgy9c&input=WzQ0LDUxLDUwLDM2XQ) or [run all test cases](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=zfMgy9c&footer=Zw&input=WwpbMSwxLDEsMV0KWzEsMiwzLDRdCls0LDMsMiwxXQpbOTAsMSwyLDFdClsxLDkwLDEsMV0KWzQ0LDUxLDUwLDM2XQpbMywzLDMsM10KWzMsMywzLDRdClszLDQsMyw0XQpbNCw0LDMsNF0KWzQsNCw0LDRdCl0tbVI)
```
Íó Ë×     :Implicit input of array
Í         :Sort
 ó        :Uninterleave
   Ë      :Map
    ×     :  Reduce by multiplication
          :Implicit output of first element
```
[Answer]
# [Desmos](https://desmos.com/calculator), 19 bytes
```
f(l)=l.minl.sort[3]
```
[Try It On Desmos!](https://www.desmos.com/calculator/66pwlknqki)
Port of literally all the other answers here.
[Answer]
# [Perl 5](https://www.perl.org/) `-pa`, 30 bytes
```
$_=(@F=sort{$a-$b}@F)[0]*$F[2]
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3lbDwc22OL@opFolUVclqdbBTTPaIFZLxS3aKPb/fxMTBVNDBVMDBWOzf/kFJZn5ecX/dX19MotLrKxCSzJzbAuK8lNKk0uAgqZ6BoYG/3ULEnMA "Perl 5 – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 21 bytes
```
->*l{l.sort![2]*l[0]}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf104rpzpHrzi/qEQx2ihWKyfaILb2f4FCWrShjqGOkY5RLBeIY6ljoWMK5PwHAA "Ruby – Try It Online")
Nothing particularly original here.
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 7 bytes
```
×´0‿2⊏∧
```
[Try it](https://mlochbaum.github.io/BQN/try.html#code=RuKGkMOXwrQw4oC/MuKKj+KIpwoKRsKo4p+oMeKAvzHigL8x4oC/MSDii4QgMeKAvzLigL8z4oC/NCDii4QgNOKAvzPigL8y4oC/MSDii4QgOTDigL8x4oC/MuKAvzEg4ouEIDHigL85MOKAvzHigL8xIOKLhAogICA0NOKAvzUx4oC/NTDigL8zNiDii4QgM+KAvzPigL8z4oC/MyDii4QgM+KAvzPigL8z4oC/NCDii4QgM+KAvzTigL8z4oC/NCDii4QgNOKAvzTigL8z4oC/NCDii4QgNOKAvzTigL804oC/NCDin6k=)
```
      ∧ # ascending sort
  0‿2⊏  # select first and third elements
×´      # product
```
[Answer]
# C (gcc), 59 bytes
```
g(a,b)int*a,*b;{b=*a-*b;}f(int*l){qsort(l,4,4,g);*l*=l[2];}
```
[Try it online!](https://tio.run/##RYtBDsIgEEX3nILUmACZmqqtG6wXqV1QsJUEqbbohnB2pNHo/M3k//dkPkgZ40AEdFRbxwSwjvuuZiJPT@jJUhrqH/M4OWKgTBkoZ4bVptm1PMSVttI81QUfZ6f0uLmeEEoSvgltyWvUiiKP8PeWwejZNS2usS9LqLZQFbA/BP5jerIQ9F/cp6T1JFurs83g4xdtAkJ8Aw)
Takes a 4-element integer array as input and stores the result in the first element of that array. It can probably be shortened, but it's still one of my better submissions :)
Explanation:
```
// This will be used as a comparison function for qsort(), so that
// integers can be sorted in ascending order.
g(a,b)int*a,*b;
{
    b=*a-*b;
}
f(int*l)
{
    // Sort l, assuming it has 4 elements with element size 4 (which is usually 
    // the size of integers in bytes), and using g() as a comparator.
    qsort(l,4,4,g);
    
    // Stores the first (minimum) element of l times the second-largest element 
    // in the first element of l.
    *l*=l[2];
}
```
46-byte version using some complicated flag (`-zexecstack`), suggested by @ceilingcat:
```
f(int*l){qsort(l,4,4,"\x8b\7+\6ð");*l*=l[2];}
```
[Try it online!](https://tio.run/##RYxRDoIwAEP/OcWCMdlwGFRAE8SLMD5wY7g4h7JpiIQ7eQfv5YRotP1rX0v9ilJrORTKeBJ1F103BkocDnZJu9mT9YzEz4eLEk96qcyWedLbiVBUXlkJttowUc8PO8cZDsCpEAreasGQ0zngq7GQQpssBynowhBHCxwFeBX3yY/hcCTQPzg3w4xDd8qIcvFnH@QD0NsX5bKotPXvZVtSbQp6fAM)
[Answer]
# [Lua](https://www.lua.org/), 35 bytes
```
table.sort(arg)print(arg[1]*arg[3])
```
[Try it online!](https://tio.run/##yylN/P@/JDEpJ1WvOL@oRCOxKF2zoCgzD8yKNozVAlHGsZr///83Mflvavjf1OC/sRkA "Lua – Try It Online")
]