Language: C++

/*
 *                             UM.
 *                            J@B@1                                                                    iO@1
 *                           Y@@@B@BB.                                                              7B@B@B@
 *                          :@B@i,B@B@O                                                          ,Z@B@B@B@Br
 *                          @B@q   i@B@BS                                                      7@B@@@O5vMB@q
 *                         8@@B      LB@B@i                                                  FB@@@BNjYjLE@B@
 *                        ,B@B:        0@@@Z                                               P@B@BM1JJ125JPB@B
 *                        B@BB          :@B@B                                            XB@B@Z2LuU52F2u2@B@.
 *                       :@B@             @@@B:                                        v@B@B8uJj51F1525uUB@B7
 *                       @B@O              0@@B.               ..::ir7vvYUuU777r::.   B@B@OULU2F2F151F11Y@B@S
 *                       B@B,               8B@B  :ruXMB@B@B@B@B@B@B@B@B@B@@@B@B@B@B@B@B@5Jj1211F1F1F2FUJO@BB
 *                      U@B@                 @B@B@B@B@B@@@B@B@B@MMqPS5JuYL7rq@B@OBB@B@B8Yu211F1515251515YGB@@
 *                      @B@u                 v@@@@MSur:.                    LB@MvvjJuU5YU252F1F1F25251F2uX@@@
 *                      @@@.                                                N@BML2U2UUU12F15252525251515Jk@@B
 *                     r@B@                                                 YB@Bju52121252515252F15251F2u5@B@
 *                     PB@B                                                  @@@PYUF151F25151F152F2F1F15jF@@B
 *                     @@BS                                                  N@@@UJ2F25252F251525151F1F1u5@B@
 *                     @@@7                                                   B@B@5Yj12F152F1F1F25252515jFB@B
 *                     B@Bi                                                    M@B@O2Luu52525212F151121UY1@B@7
 *                    O@B@:                                                     v@B@BMSuYJJuuUu2u2uujjYJJXB@B@M
 *                  7B@B@,                                                        1B@@@B@GPF1uujuu21PNMB@B@B@B@@
 *                 qB@B2                                                            i8B@B@B@B@B@@@@@B@B@B@q: @@@B
 *                MB@B:                                                                 7SBB@B@B@B@B@Zu:      @B@B
 *               ZB@B.                                              ,v.                                        @B@L
 *              LB@B,                         Y7                    @B@Bu                                      7@B@
 *   :B@B@@B2:  @@B7                         @B@Z                   r@B@B@BP:                                   B@BE
 *    BB@@@B@B@B@BE                        r@B@B                       7@B@B@B@Ou:                              iB@B
 *         :uM@@B@@2.           :7::::ivk@B@B@0                           :5B@B@B@B@B@B@G.                       @B@i
 *            BB@@@B@@         :@B@B@@@B@B@@1                                 .i5M@B@B@@@5                       M@@2
 *            B@B ,@B1          L0EZZG0F7:                                            .:,                        uB@MrP@M7
 *           2@B@                                                                                               ,O@B@B@B@B
 *           @B@1                                                     :@B@@@r                                :@@@@B@BL:,,
 *           B@Bi                         :2ZS;                      :@B@B@B@r                               L@B@B@BU
 *           @B@.                        @@@B@B@                     vB@B@B@B5                                   @B@i
 *           B@B                        7B@B@B@BM                     OB@B@B@                                   ,B@B
 *           @B@                         @B@B@@@i                       rL7.                                    B@BM
 *           B@B7.:                       NB@@M.                                                               .@B@.
 *  .;JEB@@@B@B@B@B@.                                                                                       .  @B@u
 *@@@B@B@B@B@@@B@18U                                                                                      :B@B@B@BU,
 *7@BOui.    ,@@B                                                                                          SP@B@B@B@B@Or
 *            @@@U                                                                                           B@BJ.YO@B@B@i
 *            r@B@                                                                                         :B@Bk     .k@B@
 *             B@B@                                                                                       LB@@k         2i
 *              B@BM                                      .7jXEGqF7:                                     OB@@L
 *              .B@BM                                   .B@B@B@B@B@B@.                                 :@B@B:
 *               .B@B@                                   @@MYr::ivG@B                                .M@B@G
 *                 B@@@S                                                                           ,MB@B@,
 *                  v@@@BF                                                                      .1B@B@Br
 *                    2@@B@BL                                                                ,FB@@@B8,
 *                      r@B@B@BF,                                                        :YBB@B@B@B
 *                         L@B@B@B@P7,                                           .ivXB@B@B@B@B@M@B@
 *                            ,1B@B@B@B@@@BOP2L7i:,.              ..,:i7LSNB@@B@B@@@B@B@B@Z5v;.LB@@
 *                              @B@OEB@B@@@B@B@B@B@B@B@B@B@@@B@B@B@B@B@@@B@B@B@B@BM0SJ7i::::i:,u@B@
 *                              B@Bu ::i;7vu2XNGOMB@B@BMB@B@B@B@B@B@@@B1UFuj77ii:::::::iir;r;i.YB@B
 *                              @B@L.:i:i:i::::::::::..Y@B@BMYi:i;SB@B@N:.::i:iirir;r;rii::::ivO@B@
 *                              B@@X::,::::iirir;riri:E@B@1         ,@B@Br:;;r;rii:i::::i7JEB@@@@@B
 *                              @@@B@BBq5v7ii:::::::.2@@@i  ..,..     @B@@,,:::::irv2XMB@B@B@B@2@B@:
 *                             .B@BBB@@@B@B@B@BMNP5u7@B@1 .,,:,,  :.   @B@P50MB@B@B@B@B@@@BS:   @@B1
 *                             E@B@   ijGB@B@B@B@B@B@B@Bi .,:,,..@@B@7 B@B@B@B@B@B@BM57.        kB@B
 *                            .@B@:          .,ivu5Nq@B@u  ..,.. SB@B@@@B@PL7i,                 ,@B@
 *                            @@@8                   i@B@:    .     :B@B@@                       B@@2
 *                          i@@@@                     0@B@u          B@@B.                       vB@B
 *                         ,@B@G                       L@B@BOv:.:iFB@B@M                          @B@Bi
 *                          vNi                          S@@B@B@B@B@BM:                            MB@N
 *                                                          758BMqJ,
 *
 *                 .  YO.               vq                            :G       Z:
 *        SqOMBB@B@Br @@r rBE           @B     B@@@@@B@ONX8k    i::::.OB1.:::.u@O.::::i           @B@B@U:@@B@@BPEBu
 *        B@@NB@k.    5@i  uB@E.        BM     1U2uUJvirB@@Z   r@@B@B@@@B@B@B@B@B@@@B@Bi   LB@B@1 BX :@k uLLLvr@BJ:
 *            iB      iBi    7@     .@M8@BGMZZ         @@F            ,B       Pi          v@  Bq @i v@        B@
 *       vuL7r8@S7vJL7N@Z7LLri;72.   F7@Bvvv@@       @BX         @@@B@B@@@@@B@@@B@B@B      7@  @F Bi @q  @B@Bu @B
 *       N@B@G@@@8@BBOMB@G@BMNXG@,     B@   @@      .Bk          .:u;    i@:      Zv       7@  Bk @,;@  ,BY @B B@
 *            r@       @G     5.      ,@v   BZ :::,.r@E .::i,      @B     B@    .@BL       7@  @F B:i@. .@  @M @B
 *            7B: ,vO, @@   iB@:      @B   7@:MB@B@B@@@B@B@BM       @@.    B:  2@q         7@  BS @i 0@  B. @O B@
 *       ,r2EBB@B@B@Bi G@  @BB        B@   @B        @S              :    r@   ..          7B  @F @7  B7 @  @B @B
 *       E@B@UOBr       @B@Bi          L@0PB        .BZ        .@B@B@B@B@B@B@B@B@B@B@B@,   r@  BF @i  @G B@B@B B@
 *            7@,      kB@U    ;r        @@@.       .@Z                GBuL@iBBi           vB@B@q BP:5@7 @u,.  @B
 *            LBi   YB@BrB@    @@       @B:L@Br      BM             .M@B  rB  rB@J         v@. Pi @XZ8r  .     B@
 *        .   G@i B@BM.  ,B@,  @B    iB@B    N, 7r..q@k         ,LB@B8    J@,   i@B@B1r           Br           @@
 *        MB@B@B  ,i       B@B@B,    B@:        @B@B@F         .@BB:      P@i      :OBZ          .@U       B@B@B:
 *                          .ll                                           rB.                     :
 */



 /*
00000000000000000000000000000000000000000000*-----------*0000000000000000000000000000000000000----------*-*000000000000000000000000000
0000000000000000000000000000000000000000000000000000**----0000000000000000000000000000000000*----*000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000--*000000000000000000000000000000000--*000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000*-*000000000000000000000000000000000**0000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000**---*0000000000000000000000000000000000000000000000*----*00000000000000000000000000000000000000
0000000000000000000000000000000000000-------000000000000000000000000000000000000000000000--------0000000000000000000000000000000000000
00000000000000000000000000000000000000-----00000000000000000000000000000000000000000000000------00000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*00000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*00000000000
0000000000000000000000000000*000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*00000000000
0000000000000000000000000000*000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*00000000000
00000000000000000000000000000*00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000-00000000000
00000000000000000000000000000*000*0000**00000000000000000000000000000000000000000000000000000000000000000000000*000000000**00000000000
000000000000000000000000000000*00000000***00000000000000000000000000000000000000000000000000000000000000000000*000000000*-000000000000
000000000000000000000000000000**00000000*-*000000000000000000000000000000000000000000000000000000000000000000**000000000--000000000000
00000000000000000000000000000000*00000000*--*00000000000000000000000000000000000000000000000000000000000000*-*000000000*-0000000000000
00000000000000000000000000000000**00000000*--*00000000000000000000000000000000000000000000000000000000000*-*0000000000*-00000000000000
00000000000000000000000000000000**0000000000*--**000000000000000000000000000000000000000000000000000000*--*000000*000-**00000000000000
0000000000000000000000000000000000000000000000*---*000000000000000000000000000000000000000000000000**---000000000000*-0000000000000000
00000000000000000000000000000000000**00000000000**----*00000000000000000000000000000000000000000**---*000000000000*-*00000000000000000
0000000000000000000000000000000000000*00000000000000*----***0000000000000000000000000000000***----*00000000000000*-*000000000000000000
0000000000000000000000000000000000000***0000000000000000*---------****0000000000000***--------*0000000000000000*--*0000000000000000000
0000000000000000000000**0000000000000000***000000000000000000***------------------------**000000000000000000**-**000000000000000000000
00000000000000000000*--*000--000000000000***00000000000000000000000000*********0*00000000000000000000000000*-**00000000000000000000000
00000000000000000000--*000--*000000000000000--*000000000000000000000000000000000000000000000000000000000*--**0000000000000000000000000
0000000000000000000* -0000*-000000000000000*---**00000000000000000000000000000000000000000000000000000*0* -000000000000000000000000000
0000000000000000000* -0000*-000000000000000--00000***0000000000000000000000000000000000000000000000000000--*00000000000000000000000000
00000000000000000000--0000--0000000000000--*0000000000*****00000000000000000000000000000000*******0000000---00000000000000000000000000
00000000000000000000--0000* -0000000000*--0000*0000000000000******00000000000000000000*******0000000000000--00000000000000000000000000
00000000000000000000- 00000- 00000000*--*000** -000000000000000000*******************0*0000000000000000000--00000000000000000000000000
000000000000000000000--0000- 000000*--*000*-----*0000000000000000000000000000000000000000000000000000000000 -0000000000000000000000000
000000000000000000000*--*000--000*-*0000--*0000-*0000000000000000000000000000000000000000000000000000000000--0000000000000000000000000
00000000000000000000000-*0000*0*--000*---000000--0000000000000000000000000000000000000000000000000000000000--*000000000000000000000000
000000000000000000000000000000--000---000000000-*00000000000000000000000000000000000000000000000000000000000--000000000000000000000000
000000000000000000000000000*--*00--*00000000000- 00000000000000000000000000000000000000000000000000000000000--000000000000000000000000
000000000*---------------- -*0-----------------  -------------------------------*******---------------------  ------------------------
0000000*--00000000000000- --- *0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000- -
00000*--000000000000000- ---000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000--*0
000*--000000000--000000--0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000---000
0*--000000000000-*000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*--00000
--00000000000000*-00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000--*000000
000000000000000*--0**--0*--000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000--*0000000-
000000000000000000000* -*000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*--0000000*--
000000000000000000000*-*000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000--*0000000--00
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*--*0000000*---00
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000---0000000*--- -00
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*--00000000--000--00
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000--*0000000---000* -00
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000- -0000000* -00000* -00
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*--0000000*---000000- -00
*/



/*
                 .::                                                       ,,         .:                    :,         :.
          :LuqL  5B@   :v             77L21F5F5F5F1F5S15Uv7,              :@B         0@U                  .B@        L@P
 B@B@@@B@B@B@@B  L@B   B@B@,          @BB2XSPSPkPXPkPXPF2B@B     .@B@B@B@B@@@B@B@B@B@@@B@B@B@B@B@ :@@@@BBMOB@BGM@B@BME@@@EMB@B@B@r
 ,Yi:  @B2       iB@     2@@@7        B@,                8Bq      vriii:.:0@@:ii::,:::B@B::iiii77 ,E1uJuJJ7GB@7LUk2ULvB@B7LjJjjSq:
       B@7        @B       i7         @B@B@B@B@B@B@B@B@B@B@k          @B  .BZ    u@.   :                   ,@N        7B2
0EqEqX2@B@1N0Z0ZSqB@qX0ZNPUYLSZ8      B@                 NBP          :@B       1@BMX0uj2EEZN15,    8@B@B@@@GGB@7 5@B@BOM@B@B@B.
@B@B@B@@@B@B@B@B@B@B@B@B@B@B@B@B      @B@B@B@B@B@B@B@B@B@B@q      @B@B@B@B@@@u S@B2qOOMOMM@BMB@L              @@7            B@.
       @Bv        @@v       .         B@:                k@v      :i;.,...q5::B@k            @Bi     8@@B@B@B@B@v  BB@B@B@B@@@B.
       B@L   .,7  0B@     SB@S   :5jj7vi::iiiii:..,:iii::;77LY25   B@     @B u@20B@B@B@B@N   @@:     B@       .:   B@        ::
 .:v28P@B@@@B@B@, ,@@   u@B@.    YB@B@ME0OB@B@@@B@BMB@B@BBOBB@B@.  L@@   OBS    B@:    JB@   @B.    v@BLuXP0qXvL: 1@B7ukXE00SYvL
@@@B@B@B@Z.        B@kLB@B:            7Ei      @@;                 @B:  B@     @B     .@O   B@      LO1i   , @B0  ;BX7.  ,..P@B
       @Bu         1B@B5     ::       :@B       B@@@B@B@@@B@B@      7@@ U@u     B@i,::.PB@   @B      .7OBGu   Z@v   rNBOFi   7B8
       B@5      7B@B@B@      B@B     i@B@7      @BN.::i:i:i:ii       17 @B      @B@B@B@MMY   B@          u@OBUMBi      :@BNBYv@F
       @B0  u@B@B@L  kB@;    @@;    0@B.J@@O:   B@i               ,:ii7@B@B@@@u SZ          i@B    LB@@@B@5Y, B@, 5@@@B@GFY: ZBu
 :5rr:5B@J  MBM:      iB@@k:@@@  ,NB@E    k@@B@B@B@qEZMMBM@MBB@Br @B@B@OY77:,      :MSUjuukB@Br    iBvUr.   .8@B  i5::r     YB@
 .B@B@BZ:                0B@B8   @BO         .:i:77uU5uFSkFkFXXq                    B@B@@@GU.         ,@B@B@BM:       B@B@B@B7
          .:7kq  ;@B,   ,                   @B.    i@M                .B@,      N@@       .BO       :,.            .:..
 LB@@@B@B@B@B@@  :B@,  EB@O,                B@i    U@@                 ,q@BX    1@B    ,q@B0:      ,B@B@B@B@B@B@1  @B@B@B@B@B@B@
  kri. M@@        @B:    u@B@J    @B@B@B@B@@@Bi    J@@@B@B@B@B@B   irrvi:u@BjLJ7@B@7YYLB@Bj::rir              @Bj            i@B
       EBO        @@:      :1     iiii:i::,:B@:    uB@.::i:i:iii   @B@qquvrLu1127rrUU5Uvrrv5q@B@.    .,iiiii::B@L   .,:iiiii:E@@
YLLvv7iB@Bi7YLYL7r@@ErLLL7r::iYU            @@i    Y@@             B@k      . .     ...       @B,    B@B@B@B@B@BF   @B@B@B@B@@@B
@@B@B@B@B@@@B@B@B@B@B@B@B@B@B@B@.           B@i    uB@             r7. ,B@MMMBMBMBMBMBMMG@B@  7v    r@M            LB8
       E@O        PBM       .     vB@B@B@@@B@Bi    J@B@B@B@B@@@7       .@B               P@8        @BX.::i:i:     B@2,:::i:i.  .
       Z@M     ;  ;@B     i@@@    ,ULYLJLL77@@i    uB@ivLYLJLJu:       ,B@B@B@B@B@B@B@B@B@B@        BOEOB@B@B@B@q  BZNO@B@B@B@B@@
  ,:i7JB@B@B@B@@u  B@:  :B@Bv               @Bi    J@B                  2J      uB@      :u:         @@r      @BL  7@X:       8BZ
B@B@B@B@B@,i.      kBBi@B@L                 B@i    j@@               uYjvJ2kSk1jM@@u2kFS1uLuJUi      iu@B@O   B@i  .iNB@Bj    B@u
 .     Z@M         :@B@Mi     :  rEXqXXXPS5U@Bi    Y@Bj1XXqkXXN07    B@Bq088OOGk@B@SE8OZZNq5@B@          i7:, @@,       ::i2r @B7
       MB@      ,8B@B@B      kB@ Y@@B@B@BBOGB@i    uB@EMB@B@B@B@j    @Bi        7@B         G@8    ukBB@@@B@P B@  .75BB@@@B@: B@:
       O@B  7u@B@BO, v@@v    B@G            @Bi    J@B               B@Y        uB@    7:,.i@BS   ,B@B1:     .@B  N@@BL       @B.
  5ri:r@B@  k@BL.     ,@B@q:5@B             B@r    1@@               @B7        F@B    @B@B@Or        .i.,,:1@B8       r,:::u@B@
  @B@B@B1               .q@B@B:             @Br    L@B                          5B@                   kB@B@@@5.       r@@@@B@Z;
           ,ijN   B@L   .             B@5                          .:...,:,:,.     ,,:.......                  ... .
 :@B@B@@@B@B@@@i  @B1  j@B@.         .@B      .B@B@B@@@B@B@B@B@B   G@B@B@B@B@B@B  .B@B@B@@@B@B@v    7;L7ri. @@@B@B@@ B@B@B@@@B@B@@
  NLrr:0B@        B@2    YB@@N       UBB       ... .      .@B@Bi              B@             @Br    B@BBB@8 B@   JBE         :B@
       :@B        BBk      .O:   E@B@B@B@B@B@P          .M@BS        ..,:,:,.7@@    ,.:,:::.,B@i    @B  :BS BB   B@           @B
:L77rr:E@@ir7vvvr:B@B:rv7ri:::rJ :7ij@Biir:@BM        :@B@i         v@B@@@B@B@@@   UB@B@B@B@B@BL    B@  i@5 M@  S@v  UB@B@@M  B@
8B@B@B@B@B@B@B@B@B@@@B@B@@@B@B@@L   JBM    @@i        5B@           @B.            @@               @B  ;@F BB  @B   O@L .@B  @B
       7B@        i@B               @@,    @B         L@B          ,B@..,:,,..    :@B..,,:,:.  .    B@  i@5 M@ .B@   NB.  B@  @@
       ;@B     ,,  B@      @@B.    U@B    0BE @B@B@B@B@B@B@B@B@B@  LBEOB@@@B@B@B  UO0G@B@B@B@B@Bi   @B  rBS MB. :@@  X@,  @B  @B
    ,;7B@@B@B@B@B  @B5   MB@q      @B7    B@          Y@B           :@5.      B@   OOv        @@    B@  i@5 M@.  jB5 kB.  B@  B@
7B@B@B@B@@1r:      ;@B.Z@@O        iB@@r B@j          vB@           ,1@B@B;  :@B   i0B@B@     @B    @B  ,BF MB.   @B 2@5i7@B  @B
 ::    7B@          B@B@u             7@B@B           Y@@                j , r@@        i :0 ,B@    B@LLG@F M@    @@ 0@@B@MZ  B@
       L@B       v@B@@@:     :@B:      B@B@B1.        jB@         :LLkBB@B@B 7@B  :7L0@B@@@B :@@    @@MO@BO BB2B@B@7 Y@       @@
       7B@  .7B@B@B7 :B@u    qB@    .@B@  .@B@:       7@B         O@@B7,     BBO  B@BMi      SB@    B@   :  B@.:i:            B@
  u::.,B@B  LB@Gi     .B@B2.:B@i  uB@B7         rL::,:@B@             :.   ,P@@:      :,  .:uB@r            @B.         .:.  U@@
  B@B@BBS                5B@BM:   MB            v@@@@@Mv              @@B@B@Bv        B@@@B@Bu              M@          .@B@B@X
*/
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1<<30;
vector<int>v1,v2,v3,v4;
signed main(){
	int n,w;
	cin>>n>>w;
	int we,vl;
	cin>>we>>vl;
	int cmp=we;v1.push_back(vl);
	for(int i=1;i<n;i++){
		int we,vl;
		cin>>we>>vl;
		if(we==cmp)v1.push_back(vl);
		if(we==cmp+1)v2.push_back(vl);
		if(we==cmp+2)v3.push_back(vl);
		if(we==cmp+4)v4.push_back(vl);
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	sort(v3.begin(),v3.end());
	sort(v4.begin(),v4.end());
	int ans=0;
	for(int sum=1;sum<=n;sum++)
		for(int i=0;i<=v1.size();i++)
			for(int j=0;j<=v2.size();j++){
				int k=sum-i-j;
				int w1=w;
				if(k<0)continue;
				if(k>v3.size())continue;
				w1-=i*cmp;
				w1-=j*(cmp+1);
				w1-=k*(cmp+2);
				if(w1<0)continue;
				int l=w1/(cmp+3);
				if(l>v4.size())l=v4.size();
				int gt=0;
				for(int g=0;g<i;g++)gt+=max(0,v1[g]);
				for(int g=0;g<j;g++)gt+=max(0,v2[g]);
				for(int g=0;g<k;g++)gt+=max(0,v3[g]);
				for(int g=0;g<l;g++)gt+=max(0,v4[g]);
				ans=max(ans,gt);
			}
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:236:60: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
  236 |                                 for(int g=0;g<i;g++)gt+=max(0,v1[g]);
      |                                                         ~~~^~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:198:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:236:60: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  236 |                                 for(int g=0;g<i;g++)gt+=max(0,v1[g]);
      |                                                         ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:236:60: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  236 |                                 for(int g=0;g<i;g++)gt+=max(0,v1[g]);
      |                                                         ~~~^~~~~~~~~
a.cc:237:60: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
  237 |                                 for(int g=0;g<j;g++)gt+=max(0,v2[g]);
      |                                                         ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:237:60: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  237 |                                 for(int g=0;g<j;g++)gt+=max(0,v2[g]);
      |                                                         ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:237:60: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  237 |                                 for(int g=0;g<j;g++)gt+=max(0,v2[g]);
      |                                                         ~~~^~~~~~~~~
a.cc:238:60: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
  238 |                                 for(int g=0;g<k;g++)gt+=max(0,v3[g]);
      |                                                         ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:238:60: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  238 |                                 for(int g=0;g<k;g++)gt+=max(0,v3[g]);
      |                                                         ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:238:60: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  238 |                                 for(int g=0;g<k;g++)gt+=max(0,v3[g]);
      |                                                         ~~~^~~~~~~~~
a.cc:239:60: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
  239 |                                 for(int g=0;g<l;g++)gt+=max(0,v4[g]);
      |                                                         ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:239:60: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  239 |                                 for(int g=0;g<l;g++)gt+=max(0,v4[g]);
      |                                                         ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:239:60: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  239 |                                 for(int g=0;g<l;g++)gt+=max(0,v4[g]);
      |                                                         ~~~^~~~~~~~~