(
(let $1 (DataType 'Int32))
(let $2 (OptionalType $1))
(let $3 (ListType $2))
(let $4 (OptionalType (TupleType $3 $1)))
(let $5 (OptionalType (TupleType $1 $1)))
(let $6 (Bool 'false))
(let $7 (Uint64 '2))
(let $8 (DataType 'String))
(let $9 (TupleType $3 (DataType 'Uint32)))
(let $10 (StructType '('_yql_agg_0 (TupleType $8 $1)) '('_yql_agg_1 $4) '('_yql_agg_2 $5) '('_yql_agg_3 $9) '('_yql_agg_4 $9)))
(let $11 '('('"_logical_id" '11099) '('"_id" '"e482ae8c-f8c428b6-d809265f-101bee1a") '('"_wide_channels" $10)))
(let $12 (DqPhyStage '() (lambda '() (block '(
  (let $23 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $24 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $23)))
  (let $25 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" 'false)))))
  (let $26 (YtStat '('Id '"Input") '('RecordsCount '"4") '('DataSize '"166") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $27 (YtTable '"Input" $24 $25 $26 '() (Void) (Void) '"/Root/plato"))
  (let $28 '('"key" '"subkey" '"value"))
  (let $29 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $27 $28 (Void) (Void))) '()))))
  (let $30 (Nothing $4))
  (let $31 (Nothing $5))
  (let $32 (lambda '($36 $37 $38) (block '(
    (let $39 (Unwrap (SafeCast $37 $2)))
    (let $40 (SafeCast $38 $2))
    (let $41 (SafeCast $36 $2))
    (let $42 (AsList $41))
    (let $43 (If (Exists $40) (Just '($42 (Unwrap $40))) $30))
    (let $44 (If (Exists $41) (Just '($39 (Unwrap $41))) $31))
    (let $45 (Size $39))
    (return $38 $39 $43 $44 $42 $45 (AsList $40) $45)
  ))))
  (let $33 (lambda '($57 $58 $59 $60 $61 $62 $63 $64 $65 $66 $67) (block '(
    (let $68 (Unwrap (SafeCast $58 $2)))
    (let $69 (If (AggrLess $61 $68) '($59 $68) '($60 $61)))
    (let $70 (SafeCast $59 $2))
    (let $71 (Exists $70))
    (let $72 (Unwrap $70))
    (let $73 (SafeCast $57 $2))
    (let $74 (AsList $73))
    (let $75 '($74 $72))
    (let $76 (If $71 (Just $75) $30))
    (let $77 (IfPresent $62 (lambda '($88) (block '(
      (let $89 (Nth $88 '1))
      (let $90 (If (AggrLess $89 $72) $75 $88))
      (let $91 (If (AggrEquals $72 $89) '((Take (Insert (Nth $88 '0) $73) $7) $89) $90))
      (return (Just (If $71 $91 $88)))
    ))) $76))
    (let $78 (Exists $73))
    (let $79 (Unwrap $73))
    (let $80 '($68 $79))
    (let $81 (If $78 (Just $80) $31))
    (let $82 (IfPresent $63 (lambda '($92) (block '(
      (let $93 (If (AggrLess $79 (Nth $92 '1)) $80 $92))
      (return (Just (If $78 $93 $92)))
    ))) $81))
    (let $83 (Size $68))
    (let $84 (If (AggrLess $83 $65) '($74 $83) '($64 $65)))
    (let $85 (If (AggrEquals $83 $65) '((Take (Insert $64 $73) $7) $65) $84))
    (let $86 (If (AggrLess $83 $67) '((AsList $70) $83) '($66 $67)))
    (let $87 (If (AggrEquals $83 $67) '((Take (Insert $66 $70) $7) $67) $86))
    (return (Nth $69 '0) (Nth $69 '1) $77 $82 (Nth $85 '0) (Nth $85 '1) (Nth $87 '0) (Nth $87 '1))
  ))))
  (let $34 (WideCondense1 (DqReadWideWrap $29 '()) $32 (lambda '($46 $47 $48 $49 $50 $51 $52 $53 $54 $55 $56) $6) $33))
  (let $35 (lambda '($94 $95 $96 $97 $98 $99 $100 $101) '($94 $95) $96 $97 '($98 $99) '($100 $101)))
  (return (FromFlow (WideMap $34 $35)))
))) $11))
(let $13 (DqCnUnionAll (TDqOutput $12 '0)))
(let $14 (OptionalType $3))
(let $15 (StructType '('MaxBy0 $8) '('MaxBy1 $14) '('MinBy0 $2) '('MinBy1 $3) '('MinBy2 $3)))
(let $16 '('('"_logical_id" '13001) '('"_id" '"798bc680-dbd5f2b5-e84359bf-b573b1d1") '('"_partition_mode" '"aggregate") '('"_wide_channels" $15)))
(let $17 (DqPhyStage '($13) (lambda '($102) (block '(
  (let $103 (lambda '($107 $108 $109 $110 $111) (Nth $107 '0) (Nth $107 '1) $108 $109 (Nth $110 '0) (Nth $110 '1) (Nth $111 '0) (Nth $111 '1)))
  (let $104 (lambda '($125 $126 $127 $128 $129 $130 $131 $132 $133 $134 $135 $136 $137) (block '(
    (let $138 (If (AggrLess $131 (Nth $125 '1)) $125 '($130 $131)))
    (let $139 (IfPresent $126 (lambda '($147) (IfPresent $132 (lambda '($148) (block '(
      (let $149 (Nth $147 '1))
      (let $150 (Nth $148 '1))
      (let $151 (If (AggrLess $150 $149) $147 $148))
      (return (Just (If (AggrEquals $149 $150) '((Take (Extend (Nth $147 '0) (Nth $148 '0)) $7) $149) $151)))
    ))) $126)) $132))
    (let $140 (IfPresent $127 (lambda '($152) (IfPresent $133 (lambda '($153) (Just (If (AggrLess (Nth $152 '1) (Nth $153 '1)) $152 $153))) $127)) $133))
    (let $141 (Nth $128 '1))
    (let $142 (If (AggrLess $141 $135) $128 '($134 $135)))
    (let $143 (If (AggrEquals $141 $135) '((Take (Extend (Nth $128 '0) $134) $7) $141) $142))
    (let $144 (Nth $129 '1))
    (let $145 (If (AggrLess $144 $137) $129 '($136 $137)))
    (let $146 (If (AggrEquals $144 $137) '((Take (Extend (Nth $129 '0) $136) $7) $144) $145))
    (return (Nth $138 '0) (Nth $138 '1) $139 $140 (Nth $143 '0) (Nth $143 '1) (Nth $146 '0) (Nth $146 '1))
  ))))
  (let $105 (WideCondense1 (ToFlow $102) $103 (lambda '($112 $113 $114 $115 $116 $117 $118 $119 $120 $121 $122 $123 $124) $6) $104))
  (let $106 (lambda '($154 $155 $156 $157 $158 $159 $160 $161) (block '(
    (let $162 (IfPresent $156 (lambda '($164) (Just (Nth $164 '0))) (Nothing $14)))
    (let $163 (IfPresent $157 (lambda '($165) (Just (Nth $165 '0))) (Nothing $2)))
    (return $154 $162 $163 $158 $160)
  ))))
  (return (FromFlow (WideMap $105 $106)))
))) $16))
(let $18 (DqCnUnionAll (TDqOutput $17 '0)))
(let $19 (DqPhyStage '($18) (lambda '($166) (block '(
  (let $167 (Condense (NarrowMap (ToFlow $166) (lambda '($168 $169 $170 $171 $172) (AsStruct '('MaxBy0 $168) '('MaxBy1 $169) '('MinBy0 $170) '('MinBy1 $171) '('MinBy2 $172)))) (List (ListType $15)) (lambda '($173 $174) $6) (lambda '($175 $176) (AsList $175))))
  (return (FromFlow (Map $167 (lambda '($177) (block '(
    (let $178 (ToOptional $177))
    (return (AsStruct '('"empty_by" (Member $178 'MaxBy1)) '('"empty_result" (Member $178 'MinBy2)) '('"max" (Member $178 'MaxBy0)) '('"min" (Member $178 'MinBy0)) '('"min_list" (Member $178 'MinBy1))))
  ))))))
))) '('('"_logical_id" '13079) '('"_id" '"3815deef-91417dd9-d000df5a-14c19d63"))))
(let $20 '($12 $17 $19))
(let $21 '('"min" '"max" '"min_list" '"empty_result" '"empty_by"))
(let $22 (DqCnResult (TDqOutput $19 '0) $21))
(return (KqpPhysicalQuery '((KqpPhysicalTx $20 '($22) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType (StructType '('"empty_by" $14) '('"empty_result" $14) '('"max" (OptionalType $8)) '('"min" $2) '('"min_list" $14))) '0 '0)) '('('"type" '"query"))))
)
