#include #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,2, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 0 {1,2, 0, 1, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 1 {2,2, 0, 2, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 2 {2,2, 1, 3, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 3 {2,2, 2, 4, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 4 {2,2, 3, 5, 0,1, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 5 {2,2, 4, 6, 0,1, 0, 1, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 6 {2,2, 4, 7, 0,1, 0, 2, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 7 {2,2, 5, 7, 0,1, 0, 2, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 8 {2,2, 5, 8, 0,1, 0, 2, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 9 {2,2, 5, 9, 0,1, 0, 3, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 10 {2,2, 6,10, 1,1, 0, 3, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 11 {2,2, 6,10, 1,1, 0, 4, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 12 {2,3, 7,10, 1,1, 0, 4, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 13 {2,3, 7,10, 1,1, 1, 5, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 14 {2,3, 8,11, 1,1, 2, 6, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 15 {2,3, 8,11, 1,1, 2, 6, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 16 {2,3, 8,11, 1,1, 3, 6, 0,1, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 17 {2,3, 9,12, 1,1, 3, 7, 0,1, 0, 1, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 18 {2,3, 9,12, 1,1, 4, 7, 0,1, 0, 1, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 19 {2,3, 9,12, 1,1, 4, 8, 0,1, 0, 2, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 20 {2,3, 9,13, 1,1, 5, 8, 0,1, 0, 2, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 21 {2,3, 9,13, 1,1, 5, 9, 0,1, 0, 2, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 22 {2,3, 10,13, 1,1, 5, 9, 0,1, 0, 3, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 23 {2,3, 10,13, 1,1, 5, 9, 0,1, 0, 3, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 24 {2,3, 10,13, 1,1, 6, 9, 0,1, 0, 4, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 25 {2,3, 10,14, 1,1, 7,10, 0,1, 0, 4, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 26 {3,3, 10,14, 1,2, 7,10, 0,1, 0, 5, 0,0, 0, 0, 0,0, 0, 0, 0,0, }, // 27 {3,3, 10,15, 1,2, 7,10, 1,1, 1, 5, 0,1, 0, 0, 0,0, 0, 0, 0,0, }, // 28 {3,3, 10,15, 1,2, 7,10, 1,1, 1, 6, 0,1, 0, 0, 0,0, 0, 0, 0,0, }, // 29 {3,3, 10,15, 1,2, 8,10, 1,1, 1, 6, 0,1, 0, 0, 0,0, 0, 0, 0,0, }, // 30 {3,3, 11,16, 1,2, 8,10, 1,1, 1, 7, 0,1, 0, 0, 0,0, 0, 0, 0,0, }, // 31 {3,3, 11,16, 1,2, 9,10, 1,1, 2, 7, 0,1, 0, 0, 0,0, 0, 0, 0,0, }, // 32 {3,3, 11,16, 1,2, 9,11, 1,1, 2, 7, 0,1, 0, 0, 0,0, 0, 0, 0,0, }, // 33 {3,3, 12,16, 1,2, 9,11, 1,1, 2, 8, 0,1, 0, 0, 0,0, 0, 0, 0,0, }, // 34 {3,3, 12,17, 1,2, 9,11, 1,1, 2, 8, 0,1, 0, 0, 0,0, 0, 0, 0,0, }, // 35 {3,3, 12,17, 1,2, 9,12, 1,1, 3, 8, 0,1, 0, 0, 0,0, 0, 0, 0,0, }, // 36 {3,3, 12,18, 1,2, 9,12, 1,1, 3, 8, 0,1, 0, 0, 0,0, 0, 0, 0,0, }, // 37 {3,3, 13,18, 1,2, 9,12, 1,1, 4, 8, 0,1, 0, 1, 0,0, 0, 0, 0,0, }, // 38 {3,3, 14,18, 1,2, 9,12, 1,1, 4, 9, 0,1, 0, 1, 0,0, 0, 0, 0,0, }, // 39 {3,3, 14,19, 2,2, 9,13, 1,1, 4, 9, 0,1, 0, 2, 0,0, 0, 0, 0,0, }, // 40 {3,3, 14,19, 2,2, 9,13, 1,1, 5, 9, 0,1, 0, 2, 0,0, 0, 0, 0,0, }, // 41 {3,3, 14,19, 2,2, 10,13, 1,1, 5, 9, 0,1, 0, 3, 0,0, 0, 0, 0,0, }, // 42 {3,3, 15,19, 2,2, 10,13, 1,1, 5,10, 0,1, 0, 3, 0,0, 0, 0, 0,0, }, // 43 {3,3, 15,19, 2,2, 10,14, 1,1, 6,10, 0,1, 0, 4, 0,0, 0, 0, 0,0, }, // 44 {3,3, 16,19, 2,2, 10,14, 1,2, 7,10, 0,1, 0, 4, 0,0, 0, 0, 0,0, }, // 45 {3,3, 16,19, 2,2, 10,14, 1,2, 7,10, 1,1, 0, 4, 0,0, 0, 0, 0,0, }, // 46 {3,3, 16,20, 2,2, 10,14, 1,2, 7,10, 1,1, 0, 5, 0,0, 0, 0, 0,0, }, // 47 {3,3, 16,20, 2,2, 10,14, 1,2, 8,10, 1,1, 0, 5, 0,0, 0, 0, 0,0, }, // 48 {3,3, 16,20, 2,2, 10,14, 1,2, 8,11, 1,1, 0, 5, 0,0, 0, 0, 0,0, }, // 49 {3,3, 16,20, 2,2, 10,15, 1,2, 8,11, 1,1, 0, 6, 0,0, 0, 0, 0,0, }, // 50 {3,3, 16,21, 2,2, 11,16, 1,2, 8,11, 1,1, 1, 6, 0,1, 0, 0, 0,0, }, // 51 {3,3, 16,21, 2,2, 11,16, 1,2, 8,12, 1,1, 1, 7, 0,1, 0, 0, 0,0, }, // 52 {3,3, 16,21, 2,2, 12,16, 1,2, 8,12, 1,1, 1, 8, 0,1, 0, 0, 0,0, }, // 53 {3,3, 17,21, 2,2, 12,17, 1,2, 8,12, 1,1, 2, 8, 0,1, 0, 0, 0,0, }, // 54 {3,3, 17,21, 2,2, 12,17, 1,2, 9,12, 1,1, 2, 8, 0,1, 0, 1, 0,0, }, // 55 {3,3, 17,21, 2,2, 12,17, 1,2, 9,12, 1,1, 2, 9, 0,1, 0, 1, 0,0, }, // 56 {3,3, 17,21, 2,2, 12,17, 1,2, 9,12, 1,1, 3, 9, 0,1, 0, 1, 0,0, }, // 57 {3,3, 17,21, 2,2, 13,17, 1,2, 9,13, 1,1, 3, 9, 0,1, 0, 1, 0,0, }, // 58 {3,3, 17,22, 2,2, 13,17, 1,2, 9,13, 1,1, 3, 9, 0,1, 0, 2, 0,0, }, // 59 {3,3, 17,22, 2,2, 13,18, 1,2, 9,13, 1,1, 3, 9, 0,1, 0, 2, 0,0, }, // 60 {3,3, 18,22, 2,2, 13,18, 1,2, 9,13, 1,1, 4, 9, 0,1, 0, 2, 0,0, }, // 61 {3,3, 18,22, 2,2, 13,18, 1,2, 9,13, 1,1, 4, 9, 0,1, 0, 2, 0,0, }, // 62 {3,3, 18,22, 2,2, 13,18, 1,2, 9,13, 1,1, 5,10, 0,1, 0, 3, 0,0, }, // 63 {3,3, 19,23, 2,2, 14,18, 1,2, 9,13, 1,1, 5,10, 0,1, 0, 3, 0,0, }, // 64 {3,3, 19,23, 2,2, 14,19, 1,2, 9,14, 1,1, 5,10, 0,1, 0, 4, 0,0, }, // 65 {3,3, 19,23, 2,2, 14,19, 2,2, 9,14, 1,1, 5,10, 0,1, 0, 4, 0,0, }, // 66 {3,3, 19,24, 2,2, 14,19, 2,2, 10,14, 1,1, 5,10, 0,1, 0, 4, 0,0, }, // 67 {3,3, 19,24, 2,2, 14,19, 2,2, 10,15, 1,1, 6,11, 0,1, 0, 4, 0,0, }, // 68 {3,3, 19,24, 2,2, 14,19, 2,2, 10,15, 1,2, 6,11, 0,1, 0, 5, 0,0, }, // 69 {3,3, 19,24, 2,2, 15,20, 2,2, 10,16, 1,2, 6,11, 0,1, 0, 5, 0,0, }, // 70 {3,3, 19,24, 2,2, 15,20, 2,2, 10,16, 1,2, 7,11, 1,1, 0, 5, 0,0, }, // 71 {3,3, 19,24, 2,2, 15,20, 2,2, 10,16, 1,2, 7,11, 1,1, 0, 6, 0,0, }, // 72 {3,3, 19,24, 2,2, 15,20, 2,2, 11,16, 1,2, 8,11, 1,1, 0, 6, 0,0, }, // 73 {3,3, 19,24, 2,2, 15,21, 2,2, 11,16, 1,2, 8,11, 1,1, 0, 6, 0,0, }, // 74 {3,3, 19,24, 2,2, 15,21, 2,2, 11,17, 1,2, 8,11, 1,1, 0, 6, 0,1, }, // 75 {3,3, 19,24, 2,2, 15,21, 2,2, 11,17, 1,2, 8,11, 1,1, 1, 6, 0,1, }, // 76 {3,3, 19,24, 2,2, 16,21, 2,2, 11,17, 1,2, 8,12, 1,1, 1, 6, 0,1, }, // 77 {3,3, 19,24, 2,2, 16,21, 2,2, 11,17, 1,2, 8,12, 1,1, 1, 7, 0,1, }, // 78 {3,3, 19,24, 2,3, 16,21, 2,2, 12,18, 1,2, 9,12, 1,1, 1, 7, 0,1, }, // 79 {3,3, 19,24, 2,3, 16,21, 2,2, 12,18, 1,2, 9,12, 1,1, 2, 8, 0,1, }, // 80 {3,3, 19,24, 2,3, 16,21, 2,2, 13,18, 1,2, 9,13, 1,1, 2, 9, 0,1, }, // 81 {3,3, 19,24, 2,3, 16,22, 2,2, 13,18, 1,2, 9,13, 1,1, 2, 9, 0,1, }, // 82 {3,3, 19,24, 2,3, 16,22, 2,2, 13,19, 1,2, 9,13, 1,1, 3, 9, 0,1, }, // 83 {3,3, 19,24, 2,3, 17,22, 2,2, 13,19, 1,2, 10,14, 1,1, 3, 9, 0,1, }, // 84 {3,3, 19,25, 2,3, 17,22, 2,2, 13,19, 1,2, 10,14, 1,1, 3, 9, 0,1, }, // 85 {3,3, 19,25, 2,3, 18,22, 2,2, 14,19, 1,2, 10,14, 1,2, 3,10, 0,1, }, // 86 {3,4, 20,25, 2,3, 18,22, 2,2, 14,19, 1,2, 10,14, 1,2, 3,10, 0,1, }, // 87 {3,4, 21,26, 2,3, 18,22, 2,2, 14,19, 1,2, 10,14, 1,2, 3,10, 0,1, }, // 88 {3,4, 21,26, 2,3, 18,22, 2,2, 14,19, 1,2, 10,14, 1,2, 4,10, 0,1, }, // 89 {3,4, 21,26, 2,3, 18,22, 2,2, 14,19, 1,2, 11,15, 1,2, 4,10, 0,1, }, // 90 {3,4, 21,26, 2,3, 18,23, 2,2, 15,19, 2,2, 11,15, 1,2, 5,10, 0,1, }, // 91 {3,4, 21,27, 2,3, 18,23, 2,2, 15,19, 2,2, 11,15, 1,2, 5,10, 0,1, }, // 92 {3,4, 21,27, 2,3, 18,23, 2,2, 15,19, 2,2, 11,16, 1,2, 5,10, 0,1, }, // 93 {3,4, 21,27, 2,3, 19,23, 2,2, 15,19, 2,2, 11,16, 1,2, 5,10, 0,1, }, // 94 {3,4, 21,27, 2,3, 19,23, 2,2, 15,19, 2,2, 11,16, 1,2, 6,10, 0,1, }, // 95 {3,4, 21,27, 2,3, 19,23, 2,2, 16,19, 2,2, 11,16, 1,2, 6,11, 0,1, }, // 96 {3,4, 21,27, 2,3, 19,23, 2,2, 16,19, 2,2, 11,17, 1,2, 7,11, 0,1, }, // 97 {3,4, 21,27, 2,3, 19,24, 2,2, 16,19, 2,2, 11,17, 1,2, 7,11, 0,1, }, // 98 {3,4, 21,27, 2,3, 19,24, 2,2, 16,19, 2,2, 11,17, 1,2, 7,12, 0,1, }, // 99 {3,4, 21,27, 2,3, 19,24, 2,2, 16,19, 2,2, 11,18, 1,2, 7,12, 0,1, }, // 100 {3,4, 21,27, 2,3, 19,24, 2,2, 16,20, 2,2, 11,18, 1,2, 7,12, 1,1, }, // 101 {3,4, 22,27, 2,3, 19,24, 2,2, 16,20, 2,2, 12,19, 1,2, 8,13, 1,1, }, // 102 {3,4, 22,28, 2,3, 19,24, 2,3, 16,20, 2,2, 12,19, 1,2, 8,14, 1,1, }, // 103 {3,4, 22,28, 2,3, 20,24, 2,3, 17,20, 2,2, 13,19, 1,2, 8,14, 1,1, }, // 104 {3,4, 22,28, 2,3, 20,24, 2,3, 17,21, 2,2, 13,19, 1,2, 9,14, 1,1, }, // 105 {3,4, 22,29, 2,3, 20,24, 2,3, 17,21, 2,2, 13,20, 1,2, 9,14, 1,1, }, // 106 {3,4, 22,29, 2,3, 20,25, 2,3, 17,21, 2,2, 13,20, 2,2, 9,15, 1,1, }, // 107 {3,4, 22,29, 2,3, 20,25, 2,3, 17,22, 2,2, 13,20, 2,2, 9,15, 1,1, }, // 108 {3,4, 22,29, 2,3, 20,25, 2,3, 17,22, 2,2, 14,20, 2,2, 10,16, 1,1, }, // 109 {3,4, 22,29, 2,3, 20,25, 2,3, 17,22, 2,2, 15,20, 2,2, 10,16, 1,1, }, // 110 {3,4, 22,29, 2,3, 20,25, 2,3, 17,22, 2,2, 15,20, 2,2, 10,16, 1,1, }, // 111 {3,4, 22,30, 2,3, 20,26, 2,3, 17,22, 2,3, 16,21, 2,2, 10,16, 1,1, }, // 112 {3,4, 22,30, 2,3, 20,27, 2,3, 18,22, 2,3, 16,21, 2,2, 11,16, 1,2, }, // 113 {3,4, 22,30, 2,3, 20,27, 2,3, 18,23, 2,3, 16,21, 2,2, 11,16, 1,2, }, // 114 {3,4, 23,30, 2,3, 20,27, 2,3, 18,23, 2,3, 17,21, 2,2, 11,17, 1,2, }, // 115 {3,4, 23,30, 2,3, 20,27, 2,3, 18,24, 2,3, 17,21, 2,2, 11,17, 1,2, }, // 116 {3,4, 23,30, 2,3, 20,28, 2,3, 18,24, 2,3, 17,21, 2,2, 12,17, 1,2, }, // 117 {3,4, 23,30, 2,3, 20,28, 2,3, 18,25, 2,3, 17,21, 2,2, 12,17, 1,2, }, // 118 {3,4, 23,30, 2,3, 20,28, 2,3, 18,25, 2,3, 18,21, 2,2, 12,17, 1,2, }, // 119 {3,4, 23,30, 2,3, 20,28, 2,3, 19,25, 2,3, 18,21, 2,2, 12,18, 1,2, }, // 120 {3,4, 23,30, 2,3, 21,28, 2,3, 19,25, 2,3, 18,22, 2,2, 12,18, 1,2, }, // 121 {3,4, 23,30, 2,3, 21,29, 2,3, 19,26, 2,3, 18,22, 2,2, 12,18, 1,2, }, // 122 {3,4, 23,30, 2,3, 21,30, 2,3, 19,26, 2,3, 18,22, 2,2, 12,18, 1,2, }, // 123 {3,4, 23,30, 2,3, 22,30, 2,3, 19,27, 2,3, 18,22, 2,2, 12,19, 1,2, }, // 124 {3,4, 23,31, 2,3, 22,30, 2,3, 19,27, 2,3, 18,22, 2,2, 12,20, 1,2, }, // 125 {3,4, 23,31, 2,3, 22,30, 2,3, 19,27, 2,3, 18,22, 2,2, 12,20, 1,2, }, // 126 {3,4, 23,31, 2,3, 22,30, 2,3, 19,27, 2,3, 18,22, 2,2, 12,20, 1,2, }, // 127 {3,4, 23,31, 2,4, 22,30, 2,3, 19,27, 2,3, 18,22, 2,2, 12,20, 1,2, }, // 128 {3,4, 23,32, 2,4, 22,31, 2,3, 20,28, 2,3, 18,23, 2,3, 12,20, 1,2, }, // 129 {3,4, 23,33, 2,4, 22,31, 2,3, 20,28, 2,3, 18,23, 2,3, 12,20, 1,2, }, // 130 {3,4, 23,34, 2,4, 23,31, 2,3, 20,28, 2,3, 18,23, 2,3, 12,20, 1,2, }, // 131 {3,4, 23,34, 3,4, 24,31, 3,3, 20,28, 2,3, 19,24, 2,3, 13,20, 1,2, }, // 132 {3,4, 23,34, 3,4, 24,31, 3,3, 20,28, 2,3, 19,24, 2,3, 13,20, 1,2, }, // 133 {3,4, 24,34, 3,4, 24,31, 3,3, 20,28, 2,3, 19,24, 2,3, 13,20, 1,2, }, // 134 {3,4, 24,34, 3,4, 24,31, 3,3, 21,28, 2,3, 19,24, 2,3, 13,21, 1,2, }, // 135 {3,4, 24,34, 3,4, 24,31, 3,3, 21,28, 2,3, 19,24, 2,3, 13,21, 1,2, }, // 136 {3,4, 25,34, 3,4, 25,31, 3,3, 22,28, 2,3, 19,24, 2,3, 13,21, 1,2, }, // 137 {3,4, 26,34, 3,4, 25,31, 3,3, 22,28, 2,3, 19,24, 2,3, 14,21, 1,2, }, // 138 {3,4, 26,34, 3,4, 25,31, 3,3, 22,29, 2,3, 19,25, 2,3, 14,21, 1,2, }, // 139 {3,4, 26,34, 3,4, 25,31, 3,3, 23,30, 2,3, 19,25, 2,3, 14,21, 1,2, }, // 140 {3,4, 26,34, 3,4, 25,31, 3,3, 23,30, 2,3, 19,26, 2,3, 14,21, 1,2, }, // 141 {3,4, 26,34, 3,4, 25,31, 3,3, 23,30, 2,3, 19,26, 2,3, 15,21, 1,2, }, // 142 {3,4, 26,34, 3,4, 25,31, 3,3, 23,30, 2,3, 19,27, 2,3, 15,21, 1,2, }, // 143 {3,4, 27,34, 3,4, 25,31, 3,3, 24,30, 2,3, 20,27, 2,3, 15,21, 1,2, }, // 144 {3,5, 27,34, 3,4, 25,31, 3,3, 24,30, 2,3, 20,27, 2,3, 16,21, 1,2, }, // 145 {3,5, 27,34, 3,4, 25,31, 3,3, 25,30, 2,3, 20,27, 2,3, 16,22, 1,2, }, // 146 {3,5, 27,34, 3,4, 25,31, 3,3, 25,30, 3,3, 21,27, 2,3, 17,22, 2,2, }, // 147 {3,5, 28,34, 3,4, 26,31, 3,3, 25,30, 3,3, 21,27, 2,3, 17,22, 2,2, }, // 148 {3,5, 29,34, 3,4, 26,31, 3,3, 25,30, 3,3, 21,27, 2,3, 18,22, 2,2, }, // 149 {3,5, 29,34, 3,4, 27,31, 3,3, 25,30, 3,3, 22,27, 2,3, 18,22, 2,2, }, // 150 {3,5, 29,34, 3,4, 27,31, 3,3, 25,30, 3,3, 22,27, 2,3, 19,22, 2,2, }, // 151 {3,5, 29,34, 3,4, 27,31, 3,3, 25,30, 3,3, 22,27, 2,3, 19,22, 2,2, }, // 152 {3,5, 29,34, 3,4, 28,31, 3,3, 26,30, 3,3, 23,28, 2,3, 19,22, 2,2, }, // 153 {3,5, 29,34, 3,4, 28,31, 3,3, 26,30, 3,3, 24,28, 2,3, 19,22, 2,2, }, // 154 {4,5, 30,35, 3,4, 28,31, 3,3, 26,30, 3,3, 24,28, 3,3, 19,22, 2,2, }, // 155 {4,5, 30,35, 3,4, 28,31, 3,3, 27,30, 3,3, 25,28, 3,3, 19,23, 2,2, }, // 156 {4,5, 30,35, 3,4, 29,31, 3,3, 27,30, 3,3, 25,28, 3,3, 20,23, 2,2, }, // 157 {4,5, 31,35, 3,4, 29,31, 3,3, 27,30, 3,3, 26,28, 3,3, 21,23, 2,2, }, // 158 {4,5, 31,35, 3,4, 29,31, 3,3, 27,30, 3,3, 26,28, 3,3, 21,23, 2,2, }, // 159 {4,5, 31,35, 3,4, 29,31, 3,3, 28,29, 3,3, 27,28, 3,3, 21,23, 2,2, }, // 160 {4,5, 32,35, 3,4, 29,31, 3,3, 28,29, 3,3, 27,28, 3,3, 21,23, 2,2, }, // 161 {5,5, 32,33, 3,3, 29,30, 3,3, 28,29, 3,3, 27,28, 3,3, 21,23, 2,2, }, // 162 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 163 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 164 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 165 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 166 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 167 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 168 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 169 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 170 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 171 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 172 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 173 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 174 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 175 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 176 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 177 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 178 {5,5, 33,33, 3,3, 30,30, 3,3, 29,29, 3,3, 28,28, 3,3, 23,23, 2,2, }, // 179 }; 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 { bool final=false; char history[200]; cookie_t cookie=0; cookie_t speed=0; cookie_t refundsum=0; cookie_t value=0; //double value=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; cookie+=(akoma[turn]-akoma[turn+d])*speedall; turn+=d; break; }else{ cookie+=(akoma[turn]-akoma[turn+d])*speedall; turn+=d; 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; value=cookie+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.value<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.value