# Numbers, Sums, Products

Given a 20×20 grid of non-negative integers, find a 3×3 sub-grid where the product of the sums of the individual lines hits the maximum. Spoken in formulas:

Given the 3×3 sub-grid

$$\mathfrak{U} = \left(\begin{matrix} x_{11} & x_{12} & x_{13} \\ x_{21} & x_{22} & x_{23} \\ x_{31} & x_{32} & x_{33} \end{matrix}\right)$$

the function to maximize is

\begin{align} f(\mathfrak{U}) & = \left(\begin{matrix} \underbrace{(x_{11} + x_{12} + x_{13})}_\cdot \\ \overbrace{\underbrace{(x_{21} + x_{22} + x_{23})}}_\cdot \\ \overbrace{(x_{31} + x_{32} + x_{33})} \\ \end{matrix}\right) \\ & = (x_{11} + x_{12} + x_{13}) \cdot (x_{21} + x_{22} + x_{23}) \cdot (x_{31} + x_{32} + x_{33}) \end{align}

Per line the sum is calculated and the individual sums are then multiplied.

An example (only 5×5):

$$\begin{matrix} 40 & 30 & 42 & 22 & 74 \\ 294 & 97 & \color{red} {35} & \color{red}{272} & \color{red}{167} \\ 52 & 8 & \color{red}{163} & \color{red}{270} & \color{red}{242} \\ 247 & 130 & \color{red}{216} & \color{red} {68} & \color{red}{266} \\ 283 & 245 & 164 & 53 & 148 \\ \end{matrix}$$

The part highlighted in red is the part where the value of the function $$\f(\mathfrak{U})\$$ is largest for the entire grid:

$$\(35 + 272 + 167) ⋅ (163 + 270 + 242) ⋅ (216 + 68 + 266) = 175972500\$$

Input

Input is given on standard input and consists of 20 lines, each containing 20 numbers, separated by a space character (U+0020). The numbers are small enough that a 32-bit signed integer is sufficient to compute the result.

You may assume input to be given redirected from a file.

Output

Output is the result of the function $$\f(\mathfrak{U})\$$ for the 3×3 sub-grid that gives the largest result. In above example this would have been $$\175972500\$$.

Sample input 1

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 5 5 5 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 5 5 5 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 5 5 5 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1


Sample output 1

3375


Sample input 2

40 30 42 222 74 265 93 209 115 274 139 177 7 274 12 15 103 36 236 91
294 97 35 272 167 126 18 262 292 48 8 296 85 93 245 4 4 240 276 153
52 8 163 270 242 224 142 72 99 240 199 26 224 198 96 242 295 70 56 247
247 130 216 68 266 142 93 214 30 8 12 163 59 84 40 287 233 65 30 242
283 245 164 53 148 282 73 186 296 3 9 233 184 30 205 221 92 96 5 101
132 228 43 91 228 37 266 140 159 109 10 230 40 114 264 3 266 164 219 283
70 207 218 28 299 78 279 30 179 118 196 138 61 229 110 55 203 73 124 112
16 232 28 187 292 78 194 70 65 203 255 227 176 21 32 225 11 15 92 151
58 237 261 41 213 171 170 111 4 209 99 194 40 108 267 137 179 31 35 221
184 209 264 275 163 268 261 40 198 185 45 188 280 273 54 79 270 286 273 121
208 83 66 156 104 62 188 68 53 194 46 279 280 170 266 148 272 285 178 245
210 130 213 118 165 210 213 66 54 189 166 193 57 213 14 101 143 109 172 101
80 193 287 4 140 65 208 111 8 206 107 285 109 29 211 78 170 247 290 193
148 123 15 164 28 153 222 67 156 165 6 163 114 77 165 17 143 209 278 100
3 102 58 148 82 181 84 29 2 236 231 195 118 278 252 257 179 123 276 287
143 141 254 142 200 243 171 32 164 195 235 260 269 191 190 46 65 166 82 146
69 194 65 220 234 110 45 135 125 208 138 20 233 291 256 162 148 216 247 138
10 53 164 107 2 270 226 227 88 206 193 13 41 130 218 249 76 35 207 91
199 36 207 256 58 215 28 277 234 29 198 148 219 244 136 16 30 258 219 264
183 118 48 218 15 125 279 103 73 8 86 113 9 157 239 273 146 208 50 86


Sample output 2

328536000


Sample input 3

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20


Sample output 3

185193


Sample input 4

242 248 292 60 9 45 94 97 294 202 219 118 115 243 207 81 288 289 241 232
236 225 205 227 242 85 139 63 5 162 170 121 208 133 22 235 125 288 209 270
31 182 108 170 88 268 297 66 249 158 285 157 267 117 150 18 44 66 117 223
205 32 93 132 33 99 209 282 222 272 255 1 80 270 202 54 117 35 139 273
87 74 113 146 177 14 154 92 282 4 192 60 171 286 66 299 89 276 138 289
60 16 143 277 202 284 77 296 215 96 200 10 226 143 136 131 218 246 254 20
244 118 299 218 81 195 129 93 205 202 264 141 196 150 214 72 231 136 243 192
236 157 176 187 104 182 134 29 151 234 81 143 22 119 45 241 17 225 197 7
156 284 92 13 131 60 113 77 228 65 200 83 3 63 83 88 241 113 115 198
62 101 242 270 121 122 119 78 105 273 55 7 239 236 37 252 66 164 56 44
70 57 100 87 34 298 140 259 36 257 1 204 110 299 245 56 43 121 192 10
240 36 272 255 10 194 143 66 27 131 22 78 57 71 128 5 1 155 236 122
281 160 42 147 272 151 196 240 291 280 209 245 271 46 103 35 85 145 78 140
155 74 232 205 235 223 147 39 171 240 56 187 184 70 28 81 293 125 283 159
297 203 75 46 221 77 106 12 268 94 220 156 78 97 266 208 228 137 212 49
4 157 69 51 225 23 61 202 19 23 41 260 161 218 142 251 299 187 283 158
118 136 71 77 21 199 110 87 103 120 153 157 213 234 155 141 135 24 120 199
16 204 292 245 54 260 294 159 254 15 209 41 154 54 231 167 87 291 31 26
212 274 99 199 170 184 47 227 64 2 117 275 67 84 143 214 143 125 24 61
205 250 133 88 210 112 4 160 3 287 54 143 293 94 287 42 105 94 76 169


Sample output 4

311042813


For the interested, the lengths of the submissions we got in our contest:

120 – AWK
124 – C
174 – C
270 – VB.NET

And our own (unranked) solutions:

55 – Golfscript
118 – Ruby
192 – PowerShell

# Python - 146 characters

g=[map(int,raw_input().split(' '))for i in' '*20]
r=range(18)
print max(reduce(int.__mul__,[sum(v[j:j+3])for v in g[i:i+3]])for j in r for i in r)

• The argument to split is unnecessary, and can save you three bytes. An even shorter way of reading input is g=eval('map(int,raw_input().split()),'*20), saving another four bytes for a total of 139. Mar 30 '11 at 8:37

## J, 38

":@(>./@,@(3*/\3+/\"1".;._2))&.stdin''


Sample use:

$jconsole nsp.ijs <g1 3375$ jconsole nsp.ijs <g2
328536000
$jconsole nsp.ijs <g3 185193  Rough explanations: • ".;._2 converts raw input to matrix, ": converts the result to raw output • 3+/\"1 sums column-wise, 3 by 3 • 3*/\ multiplies row-wise, 3 by 3 • , flattens the result • >./ extracts the maximum • &.stdin'' makes a filter out of it • cool__________! – YOU Feb 25 '11 at 17:27 • Great J golfing! Mar 8 '11 at 5:05 • @S.Mark __________! Mar 11 '11 at 4:27 # C#, 324321 308 chars using System;using System.Linq;class X{static void Main(){int m=0,v,x=0,y;Func<int[],int>f=t=>t[x]+t[x+1]+t[x+2];var a=Console.In.ReadToEnd().Trim().Split('\n').Select(l=>l.Split(' ').Select(int.Parse).ToArray()).ToList();for(;x<18;x++)for(y=0;y<18;m=m>v?m:v)v=f(a[y])*f(a[++y])*f(a[y+1]);Console.Write(m);}}  ## Readable: using System; using System.Linq; class X { static void Main() { int m = 0, v, x = 0, y; Func<int[], int> f = t => t[x] + t[x + 1] + t[x + 2]; var a = Console.In.ReadToEnd().Trim().Split('\n').Select(l => l.Split(' ').Select(int.Parse).ToArray()).ToList(); for (; x < 18; x++) for (y = 0; y < 18; m = m > v ? m : v) v = f(a[y]) * f(a[++y]) * f(a[y + 1]); Console.Write(m); } }  14 characters could be shaved off by removing both calls to .Trim() if you can guarantee that the input will only use \n (no \r) and there is no newline after the last row of numbers. ### Edits • (333 → 324 chars) Realised I could add x, y to the declaration at the top instead of declaring each in the for statement; that I could change one of the ToArrays to ToList; that I could increment y inside the call to f and thus get rid of it in the for. • (324 → 321 chars) Move the assignment to m into the for statement, getting rid of a semicolon and two curlies. • (321 → 308 chars) Joey’s suggestions in the comments. Thanks! • I am tempted to -1 for using technology completely inappropriate for codegolfing... :) Feb 25 '11 at 15:13 • The Trim() within the int.Parse call can indeed be dropped (it ignores trailing whitespace) (314). You can then also call Select with just int.Parse as argument; no need for a lambda there anymore (308). I think this could be made shorter by working on a 400-item 1D array instead of the list of arrays as you have it now, but I'm unable to adapt it right now ;-) – Joey Apr 15 '11 at 9:51 • @Joey: Wow... you make me feel noob :) Thanks! Apr 15 '11 at 13:25 # Java, 299 Chars  class M{public static void main(String[]a){java.util.Scanner s=new java.util.Scanner(System.in);int i,j,k,p,m,t=20,x[][]=new int[t][t];for(i=m=0;i<t*t;i++)x[i/t][i%t]=s.nextInt();for(i=0;i<18;i++)for(j=0;j<18;j++,m=p>m?p:m)for(p=1,k=i;k<i+3;k++)p*=x[k][j]+x[k][j+1]+x[k][j+2];System.out.print(m);}}  • Am I doing something wrong? The given code weighs in at 318 bytes here. In any case, the class does not need to be public, you can pull the array declaration of x into the previous line with x[][]=new int[t][t]. You can use a one-dimensional array which simplifies access greatly. You can remove the import and just inline the java.util. twice which is 5 bytes shorter. You can inline e which saves 3 bytes. With all that I got it down to 290 bytes. – Joey Feb 24 '11 at 16:40 • @Joey, sorry about that, was using Notepad++, mistakenly read Char Count (no spaces). Will do most of those changes. The code will prolly change a lot if i used a 1D array. Feb 25 '11 at 5:08 • Well, it changes declaration to x[]=new int[t*t], initialization to x[i]=s.nextInt(); and the update of p to p*=x[t*k+j]+x[t*k+j+1]+x[t*k+j+2];. Nothing too magic, I think :-) – Joey Feb 25 '11 at 11:07 • enum M{M;{code;}}, and you can probably merge the increment and loop conditionals. – Nabb Feb 27 '11 at 0:50 • With class M{static{java.util.Scanner s=... you come to 271. Improvement 10%. :) You get an errormessage after the output, but you may silently ignore it. :) Apr 16 '11 at 1:21 ## Python (202) import sys;g=map(lambda l:map(int,l.split()),sys.stdin.readlines()) r=range(18) for j in range(20):l=g[j];g[j]=[sum(l[i:i+3])for i in r] g=[g[i][j]*g[i+1][j]*g[i+2][j]for i in r for j in r] print max(g)  Edit: Fixed r to be range(18) instead of 17. # Ruby - 78 chars g=*$<
p (0..324).map{|i|eval g[i/18,3].map{|r|eval r.split[i%18,3]*?+}*?*}.max


k=$<.read.split.map &:to_i;p (0..358).map{|a|a%20>17?0:(0..2).map{|i|k[20*i+a,3].inject:+}.inject(:*)}.max  Yet another straightforward solution. • Edit: Previous solution produced incorrect results for some edge cases. • Edit: (114 -> 106) Use a flat array, check index%20 to prevent overflows into the next row. # Windows PowerShell, 116 117124152170 $g=-split$input (0..359|?{$_%20-le17}|%{$i=$_
(0..2|%{$g[($a=$i+20*$_)..($a+2)]-join'+'|iex})-join'*'|iex}|sort)[-1]  Fairly straightforward, actually. # C 184 171 Characters #define f(i,b)for(i=0;i<b;i++) i,j,k,l,m,M,s,a[400];main(){f(i,400)scanf("%d",a+i);f(i,18)f(j,18){m=1;f(k,3){s=0;f(l,3)s+=a[(i+k)*20+j+l];m*=s;}M=m>M?m:M;}printf("%d",M);}  • You could squeeze out a few more characters by using #define f(i,b)for(i=0;i<b;i++) and removing 0, from the invocations. Feb 25 '11 at 1:59 • @Joey Oh Ya! I completely missed that. Thanks Feb 25 '11 at 3:18 • Can you use #define f(i,b)for(i=b;--i;) instead? – Nabb Feb 27 '11 at 0:52 # APL (Dyalog Unicode), 22 bytesSBCS Complete program. ⌈/,{×/+/⍵}⌺3 3↑⍎20⍴'⎕'  Try it online! 20⍴'⎕' reshape the character ⎕ (which stands for evaluated input from stdin) to length 20 ⍎ execute that (gives use 20 lists) ↑ mix the lists into a matrix {}⌺3 3 on each 3-by-3 sub-matrix: +/⍵ sum the rows ×/ multiply the sums , flatten the matrix of sums ⌈/ find the maximum • 16 bytes: ⌈/∊3×/{3+/⎕}¨⍳20 Jan 22 at 2:02 ## J+tr, 84+10 y=:20 20$".(1!:1)3
s=:3 :'(y&((][;.0~3 3,:~[)~))"1(,."0/~i.18)'
>./,([:*/+/"1)"2 s y


runs like this < golfdata tr \\n ' '| ./test.ijs so I consider the tr \\n ' ' part as part of the program.

y=: 40 30 43 ...
>./,([:*/+/"1)"2 s y
328536000

z =: 20 20 $>:i.20 >./,([:*/+/"1)"2 s z 185193  • What's the easiest way to run J answers? Feb 24 '11 at 3:30 • @gnibbler: the only way I know (unfortunately) is to download and install J. Feb 24 '11 at 3:34 • @gnibbler ...which is being open sourced. Yay. – J B Mar 2 '11 at 16:42 ## Haskell, 129 characters import List t f z@(_:y@(_:x))=zipWith3((f.).f)z y x main=interact$show.maximum.(t(*)=<<).transpose.map(t(+).map read.words).lines


## Golfscript, 48 chars

n%"{~}%:^,,{^>3<}%":|~{{+}*}%20/zip|~{{*}*}%$)p;  previous one n%{' '%"{~}%:^,,{^>3<}%":|~{{+}*}%}%zip|~{{*}*}%$)p;


Some explanations, but I am still newbie in golfscript, some might not be correct, please correct me, if you see something wrong.

n%                 #.lines
{                  #.each
' '%               #.split ' '
"                  #"... literal string start
{~}%               #.flatten
:^                 #assign to variable ^
,                  #.size
,                  #.times
{                  #.each
^>                 #^[n:]
3<                 #[:3]
}%                 #.map end
"                  #..." literal string end
:|                 #assign literal string to variable | to reuse later
~                  #eval
{                  #.each
{+}                #sum
*                  #.fold
}%                 #.map end
}%                 #.map end
zip                #.zip
|~                 #eval variable | against result of .zip
{                  #.each
{*}                #product
*                  #.fold
}%                 #.map end
$#.sort ) #uncons / .pop p #puts ; #discard top item from stack  Tests $ cat sample-1159-1.txt | golfscript codegolf-1159.gs
3375

$cat sample-1159-2.txt | golfscript codegolf-1159.gs 328536000$ cat sample-1159-3.txt | golfscript codegolf-1159.gs
185193


# Jelly, 18 bytes

ƈLÐ¿ḊỴḲ€V+3\€×3\FṀ


Try it online!

Takes input from STDIN, space and newline separated

# Jelly, 9 bytes

+3\€×3\FṀ


Try it online!

Takes a 20x20 matrix of integers as input. +4 bytes to input as a space and newline separated grid

## How it works

+3\€×3\FṀ - Main link. Takes a matrix M on the left
€      - Over each row r:
3\       -   Over each overlapping triple:
+         -     Take the sum
3\   - Over each overlapping triple:
×     -   Take the product
F  - Flatten
Ṁ - Take the maximum

• The challenge requires to take input from 20 lines of stdin specifically. Jan 22 at 1:59
• @Bubbler God, I hate older challenges sometimes :/ Jan 22 at 2:05

# Powershell, 103 bytes

(($x=-split($args-replace'(\d+)(?= (\d+) (\d+))','$1+$2+$3')|iex)|%{$_*$x[$j+20]*$x[$j+++40]}|sort)[-1]


Explanation:

• The regexp transforms each string like 1 2 3 4 5 6 to the string like 1+2+3 2+3+4 3+4+5 5 6;
• Then the script splits the string 1+2+3 2+3+4 3+4+5 5 6 by spaces and evaluates each element by iex (alias for Invoke-Expression). A result is an array like 6,9,11,5,6;
• Finally, the script concatenates all arrays to one, calulates a products and returns a maximum.

It is essential that we need a maximum of products of sum of non-negative integers. So we don't need to filter out the last 2 values in each row and last 2 rows.

## Less golfed test script

$f = {$x=-split($args-replace'(\d+)(?= (\d+) (\d+))','$1+$2+$3')|iex
($x|%{$_*$x[$j+20]*$x[$j+++40]}|sort)[-1]

}

@(
,(  3375,
"1 2 3 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"4 3 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"4 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 5 5 5 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 5 5 5 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 5 5 5 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1")
,(  328536000,
"40 30 42 222 74 265 93 209 115 274 139 177 7 274 12 15 103 36 236 91",
"294 97 35 272 167 126 18 262 292 48 8 296 85 93 245 4 4 240 276 153",
"52 8 163 270 242 224 142 72 99 240 199 26 224 198 96 242 295 70 56 247",
"247 130 216 68 266 142 93 214 30 8 12 163 59 84 40 287 233 65 30 242",
"283 245 164 53 148 282 73 186 296 3 9 233 184 30 205 221 92 96 5 101",
"132 228 43 91 228 37 266 140 159 109 10 230 40 114 264 3 266 164 219 283",
"70 207 218 28 299 78 279 30 179 118 196 138 61 229 110 55 203 73 124 112",
"16 232 28 187 292 78 194 70 65 203 255 227 176 21 32 225 11 15 92 151",
"58 237 261 41 213 171 170 111 4 209 99 194 40 108 267 137 179 31 35 221",
"184 209 264 275 163 268 261 40 198 185 45 188 280 273 54 79 270 286 273 121",
"208 83 66 156 104 62 188 68 53 194 46 279 280 170 266 148 272 285 178 245",
"210 130 213 118 165 210 213 66 54 189 166 193 57 213 14 101 143 109 172 101",
"80 193 287 4 140 65 208 111 8 206 107 285 109 29 211 78 170 247 290 193",
"148 123 15 164 28 153 222 67 156 165 6 163 114 77 165 17 143 209 278 100",
"3 102 58 148 82 181 84 29 2 236 231 195 118 278 252 257 179 123 276 287",
"143 141 254 142 200 243 171 32 164 195 235 260 269 191 190 46 65 166 82 146",
"69 194 65 220 234 110 45 135 125 208 138 20 233 291 256 162 148 216 247 138",
"10 53 164 107 2 270 226 227 88 206 193 13 41 130 218 249 76 35 207 91",
"199 36 207 256 58 215 28 277 234 29 198 148 219 244 136 16 30 258 219 264",
"183 118 48 218 15 125 279 103 73 8 86 113 9 157 239 273 146 208 50 86")
,(  185193,
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20")
,(  311042813,
"242 248 292 60 9 45 94 97 294 202 219 118 115 243 207 81 288 289 241 232",
"236 225 205 227 242 85 139 63 5 162 170 121 208 133 22 235 125 288 209 270",
"31 182 108 170 88 268 297 66 249 158 285 157 267 117 150 18 44 66 117 223",
"205 32 93 132 33 99 209 282 222 272 255 1 80 270 202 54 117 35 139 273",
"87 74 113 146 177 14 154 92 282 4 192 60 171 286 66 299 89 276 138 289",
"60 16 143 277 202 284 77 296 215 96 200 10 226 143 136 131 218 246 254 20",
"244 118 299 218 81 195 129 93 205 202 264 141 196 150 214 72 231 136 243 192",
"236 157 176 187 104 182 134 29 151 234 81 143 22 119 45 241 17 225 197 7",
"156 284 92 13 131 60 113 77 228 65 200 83 3 63 83 88 241 113 115 198",
"62 101 242 270 121 122 119 78 105 273 55 7 239 236 37 252 66 164 56 44",
"70 57 100 87 34 298 140 259 36 257 1 204 110 299 245 56 43 121 192 10",
"240 36 272 255 10 194 143 66 27 131 22 78 57 71 128 5 1 155 236 122",
"281 160 42 147 272 151 196 240 291 280 209 245 271 46 103 35 85 145 78 140",
"155 74 232 205 235 223 147 39 171 240 56 187 184 70 28 81 293 125 283 159",
"297 203 75 46 221 77 106 12 268 94 220 156 78 97 266 208 228 137 212 49",
"4 157 69 51 225 23 61 202 19 23 41 260 161 218 142 251 299 187 283 158",
"118 136 71 77 21 199 110 87 103 120 153 157 213 234 155 141 135 24 120 199",
"16 204 292 245 54 260 294 159 254 15 209 41 154 54 231 167 87 291 31 26",
"212 274 99 199 170 184 47 227 64 2 117 275 67 84 143 214 143 125 24 61",
"205 250 133 88 210 112 4 160 3 287 54 143 293 94 287 42 105 94 76 169")
) | % {

(($x=($y=-split$args)|?{$i++%20-le17}|%{+$y[$i-1]+$y[$i]+$y[$i+1]})|%{$_*$x[$j+18]*$x[$j+++36]}|sort)[-1]  • This does not follow the input specification. – Joey Nov 24 '18 at 21:34 • why? .......... Nov 25 '18 at 7:38 • Your script is taking the input as arguments instead of on stdin. – Joey Nov 25 '18 at 12:09 • Why do you think the 'standard input' is 'stdin' only? Nov 25 '18 at 16:56 # Stax, 19 bytes ┬░╩íΩ{\ë╔B_m♦½─Γe╧¼  Run and debug it Input is given directly, no quotes. ## Explanation L{eL3B{|+mmM{3B{:*mm$|M Input: STDIN, auto split on newlines, pushed to stack
L                       listify the stack
{        m             map each line to:
{e       m             evaluate it
L                    listify the stack
3B                  overlapping slices of length 3
{|+m              map those to their sums
M            transpose
{      m    map to:
3B         overlapping slices of length 3
{:*m     mapped to products
\$   flatten
|M maximum