#include #include #include #include #include typedef long long cookie_t; char const fnames[][16]={"hand","lily","factory","casino","grimoire"}; cookie_t const bspeeds[]={1,10,120,2000,25000}; cookie_t const bprices[]={150,2000,30000,600000,10000000}; cookie_t pricess[11][64]; char range[][22]={ {1,1, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 1, 1, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 2, 2, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 3, 3, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 4, 4, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 4, 5, 0,1, 0, 1, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 4, 6, 0,1, 0, 1, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 5, 7, 0,1, 0, 1, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 6, 7, 1,1, 0, 1, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 6, 8, 1,1, 0, 2, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 7, 9, 1,1, 0, 2, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 8, 9, 1,1, 1, 2, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 8, 9, 1,1, 2, 3, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, {2,2, 8,10, 1,1, 2, 4, 0,0, 0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8,10, 1,1, 0, 5, 0,0, 0, 0, 0,0, }, {2,3, 16,21, 2,2, 11,14, 1,1, 8,10, 1,1, 0, 6, 0,0, 0, 0, 0,0, }, {2,3, 17,21, 2,2, 11,14, 1,1, 8,11, 1,1, 1, 6, 0,0, 0, 0, 0,0, }, {2,3, 17,21, 2,2, 11,14, 1,2, 8,11, 1,1, 1, 6, 0,1, 0, 0, 0,0, }, {2,3, 17,22, 2,2, 11,14, 1,2, 9,11, 1,1, 2, 7, 0,1, 0, 0, 0,0, }, {2,3, 17,22, 2,2, 12,14, 1,2, 9,11, 1,1, 3, 8, 0,1, 0, 0, 0,0, }, {2,3, 17,22, 2,2, 12,14, 1,2, 9,12, 1,1, 3, 8, 0,1, 0, 0, 0,0, }, {2,3, 17,22, 2,2, 12,14, 1,2, 9,12, 1,1, 4, 8, 0,1, 0, 1, 0,0, }, {2,3, 17,22, 2,2, 12,14, 1,2, 9,12, 1,1, 5, 9, 0,1, 0, 1, 0,0, }, {2,3, 17,22, 2,2, 12,15, 1,2, 9,12, 1,1, 5, 9, 0,1, 0, 2, 0,0, }, {2,3, 17,22, 2,2, 12,16, 1,2, 9,12, 1,1, 5,10, 0,1, 0, 2, 0,0, }, {2,3, 17,22, 2,2, 12,16, 1,2, 9,12, 1,1, 5,10, 0,1, 0, 3, 0,0, }, {2,3, 17,22, 2,2, 12,16, 1,2, 10,12, 1,1, 5,10, 0,1, 0, 3, 0,0, }, {2,3, 17,22, 2,2, 13,17, 1,2, 10,12, 1,1, 6,10, 0,1, 0, 3, 0,0, }, {2,3, 17,22, 2,2, 13,17, 1,2, 10,13, 1,1, 6,10, 0,1, 0, 3, 0,0, }, {2,3, 17,22, 2,2, 13,17, 1,2, 10,13, 1,1, 6,10, 0,1, 0, 3, 0,0, }, {2,3, 17,22, 2,2, 13,17, 1,2, 10,14, 1,1, 7,11, 1,1, 0, 3, 0,0, }, {2,3, 17,22, 2,2, 13,17, 1,2, 10,14, 1,1, 7,11, 1,1, 0, 4, 0,0, }, {2,3, 17,22, 2,2, 13,17, 1,2, 10,14, 1,1, 8,11, 1,1, 0, 4, 0,0, }, {2,3, 17,23, 2,2, 14,18, 1,2, 10,14, 1,1, 8,11, 1,1, 0, 5, 0,0, }, {2,3, 17,23, 2,2, 14,18, 1,2, 10,14, 1,1, 8,11, 1,1, 0, 5, 0,0, }, {2,3, 18,23, 2,2, 14,18, 1,2, 11,14, 1,1, 8,12, 1,1, 0, 5, 0,0, }, {2,3, 18,23, 2,2, 14,18, 1,2, 11,14, 1,2, 8,12, 1,1, 0, 5, 0,0, }, {2,3, 18,23, 2,2, 14,18, 1,2, 11,14, 1,2, 8,12, 1,1, 0, 5, 0,1, }, {2,3, 18,23, 2,2, 15,19, 1,2, 11,15, 1,2, 8,12, 1,1, 1, 6, 0,1, }, {2,3, 18,24, 2,2, 15,19, 2,2, 11,15, 1,2, 8,12, 1,1, 2, 7, 0,1, }, {2,3, 18,24, 2,2, 16,19, 2,2, 11,16, 1,2, 9,12, 1,1, 2, 7, 0,1, }, {2,3, 18,24, 2,2, 16,19, 2,2, 11,16, 1,2, 9,12, 1,1, 2, 7, 0,1, }, {2,3, 18,24, 2,2, 16,19, 2,2, 12,16, 1,2, 9,12, 1,1, 2, 7, 0,1, }, {2,3, 18,24, 2,2, 16,20, 2,2, 12,16, 1,2, 9,12, 1,1, 2, 7, 0,1, }, {2,3, 18,24, 2,2, 16,21, 2,2, 13,16, 1,2, 9,12, 1,1, 2, 7, 0,1, }, {2,3, 18,24, 2,2, 16,21, 2,2, 13,16, 1,2, 9,12, 1,1, 3, 8, 0,1, }, {2,3, 18,24, 2,2, 17,21, 2,2, 13,17, 1,2, 10,12, 1,1, 3, 9, 0,1, }, {2,3, 18,24, 2,2, 17,21, 2,2, 13,17, 1,2, 10,12, 1,1, 3, 9, 0,1, }, {2,3, 18,24, 2,2, 17,21, 2,2, 13,17, 1,2, 10,12, 1,1, 3,10, 0,1, }, {2,3, 18,24, 2,2, 17,21, 2,2, 14,17, 1,2, 11,12, 1,1, 4,10, 0,1, }, {2,3, 18,24, 2,2, 17,22, 2,2, 14,17, 1,2, 11,12, 1,1, 5,10, 0,1, }, {2,3, 18,24, 2,3, 18,23, 2,2, 14,18, 1,2, 11,13, 1,1, 5,10, 0,1, }, {2,3, 18,24, 2,3, 18,23, 2,2, 14,18, 1,2, 11,13, 1,1, 5,10, 0,1, }, {2,3, 18,24, 2,3, 18,23, 2,2, 14,18, 1,2, 11,13, 1,1, 5,10, 0,1, }, {2,3, 18,24, 2,3, 18,23, 2,2, 14,18, 1,2, 11,13, 1,2, 6,10, 0,1, }, {2,3, 19,24, 2,3, 18,23, 2,2, 15,19, 1,2, 11,13, 1,2, 6,10, 0,1, }, {2,3, 20,24, 2,3, 18,23, 2,2, 16,19, 1,2, 11,14, 1,2, 7,11, 0,1, }, {2,3, 20,24, 2,3, 18,23, 2,2, 16,19, 1,2, 11,14, 1,2, 7,11, 0,1, }, {2,3, 20,25, 2,3, 18,24, 2,2, 16,19, 1,2, 11,15, 1,2, 7,11, 0,1, }, {2,3, 20,26, 2,3, 18,24, 2,2, 16,19, 1,2, 11,16, 1,2, 7,11, 0,1, }, {2,4, 20,26, 2,3, 18,24, 2,2, 16,19, 2,2, 11,16, 1,2, 7,11, 0,1, }, {2,4, 20,26, 2,3, 18,24, 2,2, 16,19, 2,2, 12,16, 1,2, 7,12, 1,1, }, {2,4, 20,27, 2,3, 19,24, 2,2, 16,19, 2,2, 12,17, 1,2, 8,12, 1,1, }, {2,4, 20,27, 2,3, 19,24, 2,2, 17,20, 2,2, 12,17, 1,2, 8,12, 1,1, }, {2,4, 20,27, 2,3, 19,24, 2,2, 17,20, 2,2, 12,17, 1,2, 9,12, 1,1, }, {2,4, 20,27, 2,3, 19,24, 2,2, 17,20, 2,2, 12,18, 1,2, 9,12, 1,1, }, {2,4, 20,27, 2,3, 19,24, 2,2, 17,20, 2,2, 12,18, 1,2, 9,12, 1,1, }, {2,4, 20,27, 2,3, 19,24, 2,2, 17,20, 2,2, 12,18, 1,2, 9,12, 1,1, }, {2,4, 21,27, 2,3, 20,24, 2,2, 17,20, 2,2, 13,18, 1,2, 9,12, 1,1, }, {2,4, 22,27, 2,3, 20,24, 2,3, 17,20, 2,2, 13,18, 1,2, 9,13, 1,1, }, {2,4, 22,27, 2,3, 20,25, 2,3, 17,20, 2,2, 13,19, 1,2, 9,14, 1,1, }, {2,4, 22,27, 2,3, 20,25, 2,3, 17,21, 2,2, 14,19, 1,2, 9,15, 1,1, }, {2,4, 22,27, 2,3, 20,26, 2,3, 17,21, 2,2, 15,19, 1,2, 9,15, 1,1, }, {2,4, 22,27, 2,3, 20,26, 2,3, 18,21, 2,2, 15,20, 1,2, 10,15, 1,1, }, {2,4, 22,28, 2,3, 20,26, 2,3, 18,21, 2,2, 15,20, 2,2, 10,15, 1,1, }, {2,4, 22,29, 2,3, 20,26, 2,3, 18,21, 2,2, 15,20, 2,2, 10,16, 1,1, }, {2,4, 23,29, 2,3, 20,26, 2,3, 18,21, 2,2, 15,20, 2,2, 10,16, 1,2, }, {2,4, 23,29, 2,3, 20,26, 2,3, 18,21, 2,2, 15,20, 2,2, 11,16, 1,2, }, {2,4, 23,30, 2,3, 20,27, 2,3, 18,21, 2,2, 15,20, 2,2, 11,16, 1,2, }, {2,4, 23,30, 2,3, 20,27, 2,3, 18,22, 2,2, 16,20, 2,2, 11,16, 1,2, }, {2,4, 23,30, 2,3, 20,28, 2,3, 18,22, 2,2, 16,20, 2,2, 11,16, 1,2, }, {2,4, 23,30, 2,3, 20,28, 2,3, 19,22, 2,2, 16,20, 2,2, 12,17, 1,2, }, {2,4, 23,30, 2,3, 20,28, 2,3, 19,22, 2,2, 17,20, 2,2, 12,18, 1,2, }, {2,4, 23,30, 2,3, 20,28, 2,3, 19,22, 2,2, 18,20, 2,2, 12,19, 1,2, }, {2,4, 23,30, 2,3, 20,28, 2,3, 19,22, 2,2, 18,20, 2,2, 12,19, 1,2, }, {2,4, 23,30, 2,3, 20,28, 2,3, 19,22, 2,3, 18,21, 2,2, 12,19, 1,2, }, {2,4, 23,30, 2,3, 21,28, 2,3, 19,22, 2,3, 18,21, 2,2, 12,19, 1,2, }, {2,4, 23,30, 2,3, 21,28, 2,3, 19,23, 2,3, 18,21, 2,2, 12,19, 1,2, }, {2,4, 23,30, 2,3, 21,28, 2,3, 20,23, 2,3, 18,22, 2,2, 12,19, 1,2, }, {2,4, 23,30, 2,3, 21,28, 2,3, 20,24, 2,3, 18,22, 2,2, 12,19, 1,2, }, {2,4, 23,30, 2,3, 21,28, 2,3, 20,25, 2,3, 18,22, 2,2, 12,19, 1,2, }, {2,4, 23,30, 3,3, 21,28, 2,3, 20,25, 2,3, 19,22, 2,2, 12,19, 1,2, }, {2,4, 23,30, 3,3, 21,28, 2,3, 20,25, 2,3, 19,22, 2,2, 13,19, 1,2, }, {2,4, 23,30, 3,3, 21,29, 2,3, 20,25, 2,3, 19,22, 2,2, 13,20, 1,2, }, {2,4, 23,30, 3,3, 22,30, 2,3, 21,25, 2,3, 19,22, 2,2, 13,20, 1,2, }, {2,4, 23,30, 3,3, 22,30, 3,3, 21,26, 2,3, 19,23, 2,2, 13,20, 1,2, }, {2,4, 23,30, 3,3, 22,30, 3,3, 21,27, 2,3, 19,24, 2,2, 13,20, 1,2, }, {2,4, 23,30, 3,3, 22,30, 3,3, 22,27, 2,3, 19,24, 2,3, 13,21, 1,2, }, {2,4, 24,31, 3,3, 22,30, 3,3, 22,27, 2,3, 19,25, 2,3, 13,21, 1,2, }, {3,4, 25,31, 3,3, 22,30, 3,3, 22,27, 2,3, 19,25, 2,3, 13,21, 1,2, }, {3,4, 25,31, 3,3, 22,30, 3,3, 22,27, 2,3, 19,25, 2,3, 14,21, 1,2, }, {3,4, 25,31, 3,3, 22,30, 3,3, 22,27, 2,3, 19,25, 2,3, 14,21, 1,2, }, {3,4, 25,32, 3,3, 23,30, 3,3, 23,28, 2,3, 19,25, 2,3, 14,21, 1,2, }, {3,4, 25,32, 3,3, 24,30, 3,3, 24,28, 2,3, 20,25, 2,3, 15,21, 1,2, }, {3,4, 26,32, 3,3, 24,30, 3,3, 24,28, 2,3, 20,25, 2,3, 15,21, 1,2, }, {3,4, 26,32, 3,3, 24,30, 3,3, 25,28, 2,3, 20,25, 2,3, 16,21, 1,2, }, {3,4, 26,32, 3,3, 25,30, 3,3, 25,28, 2,3, 21,25, 2,3, 16,21, 2,2, }, {3,4, 26,32, 3,3, 25,30, 3,3, 25,28, 2,3, 21,25, 2,3, 17,21, 2,2, }, {3,4, 26,32, 3,3, 25,30, 3,3, 25,28, 2,3, 21,25, 2,3, 18,21, 2,2, }, {3,4, 26,32, 3,3, 26,30, 3,3, 25,28, 2,3, 21,26, 2,3, 18,21, 2,2, }, {3,4, 26,32, 3,3, 26,30, 3,3, 25,28, 3,3, 21,26, 2,3, 19,21, 2,2, }, {3,4, 26,32, 3,3, 26,30, 3,3, 25,28, 3,3, 21,26, 2,3, 19,21, 2,2, }, {3,4, 27,32, 3,3, 26,30, 3,3, 25,29, 3,3, 21,26, 2,3, 19,21, 2,2, }, {3,4, 27,32, 3,3, 26,30, 3,3, 25,29, 3,3, 22,27, 2,3, 19,22, 2,2, }, {3,4, 27,32, 3,3, 26,30, 3,3, 25,29, 3,3, 22,27, 2,3, 19,22, 2,2, }, {3,4, 27,33, 3,3, 26,30, 3,4, 26,29, 3,3, 22,27, 2,3, 19,22, 2,2, }, {3,4, 27,33, 3,3, 26,31, 3,4, 26,29, 3,3, 23,27, 2,4, 19,22, 2,2, }, {3,5, 28,33, 3,3, 26,31, 3,4, 26,29, 3,3, 23,28, 2,4, 20,22, 2,2, }, {3,5, 28,33, 3,3, 26,32, 3,4, 26,29, 3,3, 23,28, 2,4, 20,22, 2,2, }, {3,5, 28,33, 3,3, 27,33, 3,4, 26,29, 3,3, 23,29, 2,4, 20,23, 2,3, }, {3,5, 28,34, 3,3, 27,33, 3,4, 26,29, 3,3, 24,29, 2,4, 20,23, 2,3, }, {3,5, 28,34, 3,3, 27,33, 3,4, 26,29, 3,4, 24,30, 2,4, 21,23, 2,3, }, {3,5, 29,34, 3,3, 27,33, 3,4, 26,30, 3,4, 24,30, 2,4, 21,24, 2,3, }, {3,5, 29,34, 3,3, 27,33, 3,4, 26,30, 3,4, 24,31, 2,4, 21,24, 2,3, }, {3,5, 29,34, 3,3, 27,33, 3,4, 27,31, 3,4, 24,31, 2,4, 21,24, 2,3, }, {3,5, 29,34, 3,3, 27,33, 3,4, 27,32, 3,4, 24,31, 2,4, 21,25, 2,3, }, {3,5, 29,35, 3,3, 27,34, 3,4, 27,32, 3,4, 24,31, 2,4, 21,25, 2,3, }, {3,5, 29,35, 3,3, 28,35, 3,4, 27,32, 3,4, 24,32, 2,4, 21,25, 2,3, }, {3,5, 29,35, 3,3, 28,36, 3,4, 27,32, 3,4, 24,32, 2,4, 21,26, 2,3, }, {3,5, 29,36, 3,3, 28,36, 3,4, 28,32, 3,4, 24,32, 2,4, 21,26, 2,3, }, {3,5, 30,36, 3,3, 28,36, 3,4, 28,32, 3,4, 24,32, 2,4, 21,26, 2,3, }, {3,5, 30,36, 3,4, 28,36, 3,4, 28,32, 3,4, 24,32, 2,4, 22,26, 2,3, }, {3,5, 30,36, 3,4, 28,36, 3,4, 29,32, 3,4, 25,32, 2,4, 22,26, 2,3, }, {3,5, 31,36, 3,4, 28,36, 3,4, 29,33, 3,4, 25,32, 2,4, 22,27, 2,3, }, {3,5, 31,37, 3,4, 28,37, 3,4, 29,33, 3,4, 25,33, 2,4, 22,27, 2,3, }, {3,5, 32,38, 3,4, 28,37, 3,4, 29,33, 3,4, 25,33, 3,4, 22,27, 2,3, }, {3,5, 32,39, 3,4, 28,37, 3,4, 29,33, 3,4, 26,33, 3,4, 22,27, 2,3, }, {3,5, 32,39, 3,4, 29,37, 3,4, 29,33, 3,4, 27,33, 3,4, 22,27, 2,3, }, {3,5, 32,39, 3,4, 29,37, 3,4, 30,33, 3,4, 28,33, 3,4, 22,28, 2,3, }, {3,5, 33,39, 3,4, 29,37, 3,4, 30,33, 3,4, 28,33, 3,4, 23,28, 2,3, }, {3,5, 33,40, 3,4, 29,37, 3,4, 30,33, 3,4, 28,33, 3,4, 23,28, 2,3, }, {3,5, 33,40, 3,4, 29,37, 3,4, 30,33, 3,4, 28,33, 3,4, 23,28, 2,3, }, {3,5, 34,40, 3,4, 30,37, 3,4, 30,34, 3,4, 29,33, 3,4, 23,28, 2,3, }, {3,5, 34,40, 3,4, 30,37, 3,4, 30,34, 3,4, 29,33, 3,4, 24,29, 2,3, }, {3,5, 34,41, 3,4, 30,37, 3,4, 31,34, 3,4, 29,34, 3,4, 24,29, 2,3, }, {3,5, 34,41, 3,4, 30,37, 3,4, 31,34, 3,4, 29,34, 3,4, 24,29, 2,3, }, {3,5, 35,41, 3,4, 30,37, 3,4, 31,34, 3,4, 29,34, 3,4, 24,29, 2,3, }, {3,5, 35,41, 3,4, 30,37, 3,4, 31,35, 3,4, 29,34, 3,4, 24,29, 2,3, }, {3,5, 35,41, 3,4, 31,38, 3,4, 31,35, 3,4, 29,34, 3,4, 24,29, 2,3, }, {3,5, 35,42, 3,4, 31,38, 3,4, 31,35, 3,4, 30,34, 3,4, 24,29, 2,3, }, {3,5, 36,42, 3,4, 31,38, 3,4, 31,36, 3,4, 30,34, 3,4, 24,29, 2,3, }, {3,5, 36,42, 3,4, 31,38, 3,4, 31,36, 3,4, 30,34, 3,4, 24,29, 2,3, }, {3,5, 36,42, 3,4, 31,39, 3,4, 31,36, 3,4, 30,34, 3,4, 24,29, 2,3, }, {3,5, 37,43, 3,4, 32,39, 3,4, 31,36, 3,4, 30,34, 3,4, 24,30, 3,3, }, {3,5, 37,43, 3,4, 32,39, 3,4, 32,36, 3,4, 30,35, 3,4, 25,30, 3,3, }, {3,5, 38,43, 3,4, 32,39, 3,4, 32,36, 3,4, 30,35, 3,4, 25,30, 3,3, }, {3,5, 38,43, 3,4, 32,39, 3,4, 32,37, 3,4, 30,35, 3,4, 25,30, 3,3, }, {3,5, 38,44, 3,4, 33,39, 3,4, 32,37, 3,4, 31,35, 3,4, 26,30, 3,3, }, {3,5, 38,44, 3,4, 33,39, 3,4, 33,37, 3,4, 31,35, 3,4, 27,30, 3,3, }, {3,5, 38,44, 3,4, 34,39, 3,4, 33,37, 3,4, 31,35, 3,4, 27,30, 3,3, }, {3,5, 38,44, 3,4, 34,40, 3,4, 33,37, 3,4, 31,35, 3,4, 28,30, 3,3, }, {3,5, 39,44, 3,4, 34,40, 3,4, 33,37, 3,4, 31,35, 3,4, 28,30, 3,3, }, {3,5, 39,44, 3,4, 34,40, 3,4, 33,38, 3,4, 31,35, 3,4, 28,30, 3,3, }, {3,5, 40,44, 3,4, 34,40, 3,4, 34,38, 3,4, 31,35, 3,4, 28,30, 3,3, }, {4,5, 40,45, 3,4, 34,40, 3,4, 34,38, 3,4, 32,35, 3,4, 28,30, 3,3, }, {4,5, 41,46, 3,4, 35,40, 3,4, 35,38, 3,4, 32,35, 3,4, 28,30, 3,3, }, }; int n10000; char events[10010]; int asale[10010]; int akoma[10010]; int abonus[10010]; struct N{ char n[11]={0}; char & operator[](int i){ return n[i]; } }; bool operator<(N const & a, N const & b){ return memcmp(a.n,b.n,11)<0; } struct Solver { char const * acts=0; int acti=0; bool final=false; char history[200]; cookie_t cookie=0; cookie_t speed=0; cookie_t refundsum=0; cookie_t eval=0; N n; int nsum=0; int nowsale=0; int nowfever=0; int turn=0; void output(char const * cmd, char const * arg=0){ if(arg){ dprintf(1,"%s %s\n",cmd,arg); }else{ dprintf(1,"%s\n",cmd); } } bool runto(int to){ assert(to<=n10000); assert(turn<=to); cookie_t speedall=speed+(cookie_t(1)<to-turn){ d=to-turn; b=false; } cookie+=(akoma[turn]-akoma[turn+d])*speedall; turn+=d; if(b){ cookie+=(cookie+99)/100; } } assert(turn==to); } bool step(int a){ assert(a>=0&&a<11); bool finished=false; char const * cmd; char const * arg; cookie_t price1,price2,refund,delta; price1=pricess[a][n[a]]; if(a==0){ // enhclick refund=0; delta=cookie_t(1)<>1; if(a&1){ // buy refund=(price1+3)/4; delta=bspeeds[i]<=n10000){ buyturn1=n10000-1; } if(akoma[turn]-akoma[buyturn1]-needkoma1>0){ buyturn1-=(akoma[turn]-akoma[buyturn1]-needkoma1)*20; if(buyturn1=n10000){ buyturn2=n10000-1; } if(akoma[turn]-akoma[buyturn2]-needkoma2>0){ buyturn2-=(akoma[turn]-akoma[buyturn2]-needkoma2)*20; if(buyturn2=gain2?buyturn1:buyturn2; if(final){ for(int i=turn;i=0); n[a]+=1; if(a){ nsum+=a&1; speed+=delta; refundsum+=refund; } cookie+=(akoma[turn]-akoma[turn+1])*speed; if(events[turn]=='B'){ cookie+=(cookie+99)/100; } turn+=1; eval=cookie+refundsum+akoma[turn]*(speed+(cookie_t(1)<>1]:pricess[a-1][0]*10; for(int j=1;j<64;++j){ pricess[a][j]=c=a&1?c+(c+4)/5:c*10; } } scanf("%d ",&n10000); gets(events); int koma=0; int fever=0; int nextsale=n10000*2; int nextbonus=n10000*2; for(int turn=n10000;turn--;){ if(events[turn]=='S'){ nextsale=turn+1; } asale[turn]=nextsale-turn; if(events[turn]=='B'){ nextbonus=turn; } abonus[turn]=nextbonus-turn; koma+=events[turn]=='F'?121:1; } for(int turn=0;turn map0,map1; { Solver s; map0[s.n]=s; } cookie_t best_cookie=0; Solver best_s; int acti=0; while(!map0.empty()){ for(auto x:map0){ assert(x.second.eval<19000000000ll); for(int a=0;a<11;++a){ Solver s=x.second; bool ok=true; s.n[a]+=1; for(int b=0;b<11;++b){ if(s.n[b]range[acti][b*2+1]){ ok=false; break; } } if(!s.n[1]&&s.n[2])ok=false; if(!s.n[3]&&s.n[4])ok=false; if(!s.n[5]&&s.n[6])ok=false; if(!s.n[7]&&s.n[8])ok=false; if(!s.n[9]&&s.n[10])ok=false; s.n[a]-=1; if(ok){ s.history[acti]=a; if(!s.step(a)){ auto it=map1.find(s.n); if(it==map1.end() || it->second.eval