这道题目本身很简单,倒推回去,第K个是最优时,K+1时必然包含它.所以就从最后面的股票开始贪心法用最优解生成最优解.
难点1是去重,我直接用了个价格表去过滤,如果多个价格相等的同级最优解,就用他们中可能性最大的那个累加,其余的忽略.
难点2是大数计算.可能性可能有几十位的数字,所以封装了一个大数类.现在还不支持符号,只支持正数.后面需要用到负数的时候再说.
题目:
Buy Low, Buy Lower
The advice to "buy low" is half the formula to success in the stock market. But to be considered a great investor you must also follow this problems‘ advice:
"Buy low, buy lower"
That is, each time you buy a stock, you must purchase more at a lower price than the previous time you bought it. The more times you buy at a lower price than before, the better! Your goal is to see how many times you can continue purchasing at ever lower
prices.
You will be given the daily selling prices of a stock over a period of time. You can choose to buy stock on any of the days. Each time you choose to buy, the price must be lower than the previous time you bought stock. Write a program which identifies which
days you should buy stock in order to maximize the number of times you buy.
By way of example, suppose on successive days stock is selling like this:
Day 1 2 3 4 5 6 7 8 9 10 11 12 Price 68 69 54 64 68 64 70 67 78 62 98 87
In the example above, the best investor (by this problem, anyway) can buy at most four times if they purchase at a lower price each time. One four day sequence (there might be others) of acceptable buys is:
Day 2 5 6 10 Price 69 68 64 62
PROGRAM NAME: buylow
INPUT FORMAT
Line 1: | N (1 <= N <= 5000), the number of days for which stock prices are available. |
Line 2..etc: | A series of N positive space-separated integers (which may require more than one line of data) that tell the price for that day. The integers will fit into 32 bits quite nicely. |
SAMPLE INPUT (file buylow.in)
12 68 69 54 64 68 64 70 67 78 62 98 87
OUTPUT FORMAT
Two integers on a single line:
- the length of the longest sequence of decreasing prices
- the number of sequences that have this length
In counting the number of solutions, two potential solutions are considered the same (and would only count as one solution) if they repeat the same string of decreasing prices, that is, if they "look the same" when the successive prices are compared. Thus,
two different sequence of "buy" days could produce the same string of decreasing prices and be counted as only a single solution.
SAMPLE OUTPUT (file buylow.out)
4 2
代码:
/* ID: thinkin6 PROG: buylow LANG: C++ */ /** USA CO 4.3.1 : Buy Low, Buy Lower The advice to "buy low" is half the formula to success in the stock market. But to be considered a great investor you must also follow this problems' advice: "Buy low, buy lower" That is, each time you buy a stock, you must purchase more at a lower price than the previous time you bought it. The more times you buy at a lower price than before, the better! Your goal is to see how many times you can continue purchasing at ever lower prices. You will be given the daily selling prices of a stock over a period of time. You can choose to buy stock on any of the days. Each time you choose to buy, the price must be lower than the previous time you bought stock. Write a program which identifies which days you should buy stock in order to maximize the number of times you buy. By way of example, suppose on successive days stock is selling like this: Day 1 2 3 4 5 6 7 8 9 10 11 12 Price 68 69 54 64 68 64 70 67 78 62 98 87 In the example above, the best investor (by this problem, anyway) can buy at most four times if they purchase at a lower price each time. One four day sequence (there might be others) of acceptable buys is: Day 2 5 6 10 Price 69 68 64 62 PROGRAM NAME: buylow INPUT FORMAT Line 1: N (1 <= N <= 5000), the number of days for which stock prices are available. Line 2..etc: A series of N positive space-separated integers (which may require more than one line of data) that tell the price for that day. The integers will fit into 32 bits quite nicely. SAMPLE INPUT (file buylow.in) 12 68 69 54 64 68 64 70 67 78 62 98 87 OUTPUT FORMAT Two integers on a single line: ? the length of the longest sequence of decreasing prices ? the number of sequences that have this length In counting the number of solutions, two potential solutions are considered the same (and would only count as one solution) if they repeat the same string of decreasing prices, that is, if they "look the same" when the successive prices are compared. Thus, two different sequence of "buy" days could produce the same string of decreasing prices and be counted as only a single solution. SAMPLE OUTPUT (file buylow.out) 4 2 */ /** * */ #include <stdio.h> #include <stdlib.h> #include <iostream> #include <fstream> #include <string> #include <map> #include <vector> #include <list> #include <math.h> #include <set> #include <sstream> #include <algorithm> #include <memory.h> #include <complex> #include <queue> #include <stack> #ifdef _WIN32 #include <time.h> #endif using namespace std; #ifdef _WIN32 typedef __int64 n64; typedef unsigned __int64 u64; #else typedef long long n64; typedef unsigned long long u64; #endif typedef unsigned long u32; #ifdef _WIN32 #define THINKINGL 1 #endif const int IFINITE = 0xFFFFFFF; class CBigInt { public: typedef std::vector<int> IntVector; enum{ MAX_DIGITS = 100, }; CBigInt() { m_data.resize( MAX_DIGITS ); } CBigInt( int num ) { m_data.resize( MAX_DIGITS ); m_data[0] = num; Check(); } string ToString() { string str; bool notZero = false; for ( size_t i=0; i<m_data.size(); ++i ) { int index = m_data.size() - 1 - i; if ( !notZero && m_data[index] != 0 ) { notZero = true; } if ( notZero ) { str.push_back( m_data[index] + '0' ); } } return str; } CBigInt& operator ++() { m_data[0] ++; this->Check(); } CBigInt& operator +( const CBigInt& another ) { for ( int i=0; i<MAX_DIGITS; ++i ) { m_data[i] += another.m_data[i]; } Check(); return *this; } CBigInt& operator +=( const CBigInt& another ) { *this = *this + another; return *this; } bool operator <( const CBigInt& another) const { for ( int i=MAX_DIGITS-1; i>=0; --i ) { if ( m_data[i] < another.m_data[i] ) { return true; } else if( m_data[i] > another.m_data[i] ) { return false; } } return false; } bool operator ==( const CBigInt& another ) const { return !( *this < another ) && !( another < *this ); } private: void Check() { for ( size_t i=0; i<m_data.size(); ++i ) { while ( m_data[i] >= 10 ) { m_data[i] -= 10; m_data[i+1] ++; } } } private: IntVector m_data; }; int main() { string strProblemName = "buylow"; string strInFile = strProblemName + ".in"; string strOutFile = strProblemName + ".out"; ofstream fout ( strOutFile.c_str() ); ifstream fin ( strInFile.c_str() ); if( !fin ) { cout << "open input file fail!" << endl; return 0; } /* 12 68 69 54 64 68 64 70 67 78 62 98 87 */ int number; fin >> number; // int* pzPrice = new int[ number ]; vector<int> priceList; priceList.resize( number ); for ( int i=0; i<number; ++i ) { fin >> priceList[i]; } // 反着来,倒着计算每个股价的最大可买次数。 vector<int> maxBuyNumList; maxBuyNumList.resize( number, 1 ); for ( int i=number-1; i>=0; --i ) { // 向后找比这个小的最大可买次数,+1. int maxBuyNum = 0; for ( int k=i+1; k<number; ++k ) { if( priceList[i] > priceList[k] ) { if( maxBuyNumList[k] > maxBuyNum ) { maxBuyNum = maxBuyNumList[k]; maxBuyNumList[i] = maxBuyNum+1; } } } } // 遍历来获取可能的组合数目. vector< CBigInt > sequnceNum; sequnceNum.resize( number, 0 ); for ( int i=number-1; i>=0; --i ) { // 后面最大的可买次数是它本身的次数 -1. int maxBuyNumAfter = maxBuyNumList[i]-1; // 去重,如果买的股票价格是一样的,算作一个序列. typedef std::map<int,CBigInt> CPriceSequnceNumTable; CPriceSequnceNumTable priceSequnceNumTable; for ( int k=i+1; k<number; ++k ) { if ( priceList[k] < priceList[i] && maxBuyNumAfter == maxBuyNumList[k] ) { int price = priceList[k]; if ( priceSequnceNumTable[price] < sequnceNum[k] ) { priceSequnceNumTable[price] = sequnceNum[k]; } } } for ( CPriceSequnceNumTable::iterator it = priceSequnceNumTable.begin(); it != priceSequnceNumTable.end(); ++it ) { sequnceNum[i] += it->second; } if ( sequnceNum[i] == 0 ) { sequnceNum[i] = 1; } } // 找到最大的,输出。 int maxBuyNum = 0; CBigInt totalSequnceNum = 0; // 去重,如果买的股票价格是一样的,算作一个序列. typedef std::map<int,CBigInt> CPriceSequnceNumTable; CPriceSequnceNumTable priceSequnceNumTable; // for ( int i=0; i<number; ++i ) { if ( maxBuyNumList[i] > maxBuyNum ) { maxBuyNum = maxBuyNumList[i]; priceSequnceNumTable.clear(); priceSequnceNumTable[ priceList[i] ] = sequnceNum[i]; } else if( maxBuyNumList[i] == maxBuyNum ) { priceSequnceNumTable[ priceList[i] ] = sequnceNum[ i ]; } } for ( CPriceSequnceNumTable::iterator it = priceSequnceNumTable.begin(); it != priceSequnceNumTable.end(); ++it ) { totalSequnceNum += it->second; } fout << maxBuyNum << " " << totalSequnceNum.ToString() << endl; #ifdef THINKINGL cout << "use clock: " << clock() << " / " << CLOCKS_PER_SEC << endl; cout << "-----------begin--dump--output--file----------------" << endl << endl; system( ( string( "type " ) + strOutFile ).c_str() ); cout << endl; system( "pause" ); #endif return 0; }
结果:
USER: Zinsser Lee [thinkin6] TASK: buylow LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [0.005 secs, 3512 KB] Test 2: TEST OK [0.005 secs, 3512 KB] Test 3: TEST OK [0.008 secs, 3512 KB] Test 4: TEST OK [0.011 secs, 3512 KB] Test 5: TEST OK [0.014 secs, 3512 KB] Test 6: TEST OK [0.041 secs, 3512 KB] Test 7: TEST OK [0.024 secs, 3512 KB] Test 8: TEST OK [0.005 secs, 3512 KB] Test 9: TEST OK [0.059 secs, 3512 KB] Test 10: TEST OK [0.275 secs, 3512 KB] All tests OK. Your program ('buylow') produced all correct answers! This is your submission #9 for this problem. Congratulations! Here are the test data inputs: ------- test 1 ---- 1 3 ------- test 2 ---- 10 1 2 3 4 5 6 7 8 9 10 ------- test 3 ---- 12 68 69 54 64 68 64 70 67 78 62 98 87 ------- test 4 ---- 20 1 16 17 18 20 10 22 22 8 17 26 14 3 24 8 1 2 21 2 17 ------- test 5 ---- 500 26 8 50 59 2 43 24 2 28 38 42 6 47 36 59 59 15 22 17 53 3 55 8 58 12 56 2 38 60 29 1 25 36 51 23 37 33 47 39 1 24 20 6 11 56 4 10 10 26 27 3 28 21 11 26 33 6 27 10 6 55 11 30 30 1 53 6 34 39 45 35 3 4 40 13 60 44 23 10 9 49 12 37 9 22 2 42 28 28 52 33 22 2 2 52 3 55 57 37 33 41 11 36 45 51 48 45 34 11 54 43 59 6 20 8 28 22 50 55 49 41 27 11 43 29 2 46 24 59 23 56 40 33 31 25 24 19 9 57 29 3 40 28 8 59 36 35 20 25 30 9 5 56 20 48 25 22 33 48 21 55 44 60 28 15 25 51 33 33 48 2 36 28 29 43 27 4 18 46 29 47 55 34 42 15 21 7 37 54 55 57 49 38 57 17 53 21 8 25 54 55 26 29 22 55 12 48 59 29 34 28 15 29 1 57 44 22 3 20 15 58 16 4 36 12 20 28 33 27 53 26 22 19 55 44 13 6 32 12 34 5 39 49 34 40 45 17 1 48 36 15 45 52 19 21 4 38 48 36 4 41 2 25 59 56 8 12 2 39 24 35 44 2 23 18 42 8 35 42 55 11 57 40 2 15 60 5 52 48 40 56 28 42 21 27 37 29 38 38 8 1 13 51 3 36 9 44 43 43 25 37 53 22 17 55 36 16 60 28 4 40 24 32 21 44 58 57 12 35 35 19 36 47 10 38 22 19 21 5 2 46 42 55 7 58 49 43 13 48 10 17 27 33 48 47 17 45 44 29 19 18 47 54 5 57 32 27 16 52 31 17 38 12 11 44 9 59 27 22 47 36 38 14 9 25 60 25 9 44 53 28 1 40 22 6 37 53 32 53 45 2 9 23 14 20 7 23 19 33 44 5 9 22 18 17 46 18 42 55 1 35 23 2 15 45 7 51 38 38 44 23 40 52 45 53 11 51 15 29 23 59 34 31 20 52 48 6 9 29 60 9 4 23 11 18 7 17 9 44 54 52 6 33 44 50 26 55 41 41 24 3 39 57 34 59 48 21 4 57 50 3 6 54 26 16 11 32 32 20 16 26 12 21 59 55 11 25 49 51 5 ------- test 6 ---- 1000 13 1 12 17 19 11 3 5 13 18 13 20 9 18 5 9 9 2 4 4 2 13 6 6 1 4 4 4 11 20 14 3 1 6 20 20 16 2 4 9 20 17 8 8 14 13 16 3 15 19 6 16 12 12 2 13 15 5 16 5 5 10 7 5 15 6 4 11 8 8 20 7 4 7 14 17 20 9 20 14 8 6 9 20 17 10 12 11 15 8 15 19 18 2 4 13 8 8 4 15 15 3 1 18 10 15 15 9 3 14 2 11 19 10 10 16 20 2 6 15 9 1 13 7 2 17 19 10 4 2 4 18 5 5 16 14 20 10 2 2 4 3 13 3 13 3 18 13 4 4 7 13 4 20 19 6 16 18 15 19 19 19 17 4 4 12 17 3 2 18 5 6 1 17 8 13 19 6 5 3 10 11 15 13 10 14 19 5 11 13 4 10 12 20 13 15 12 9 17 13 7 2 18 7 19 6 19 18 12 4 20 1 14 15 13 4 8 11 9 19 4 12 8 15 12 1 10 3 10 7 16 16 8 14 2 6 19 1 3 10 4 3 10 18 17 3 1 5 14 9 3 17 1 11 12 12 12 1 15 1 8 10 16 15 3 18 1 2 18 3 12 2 6 1 19 2 4 19 7 18 8 10 14 8 20 6 19 11 7 14 11 14 4 7 9 7 4 9 8 2 11 19 3 17 20 2 18 3 20 5 20 7 14 14 15 13 20 14 4 6 7 15 20 10 2 8 16 6 16 3 7 7 2 10 3 1 11 1 4 11 5 4 17 18 18 11 11 17 4 14 3 11 9 3 20 10 10 16 15 6 19 2 12 20 12 15 1 2 15 5 12 20 8 9 17 6 20 8 2 4 2 5 14 10 7 14 20 17 10 15 2 8 16 14 8 7 9 9 9 3 13 1 3 1 9 19 6 9 7 8 12 8 13 6 17 20 20 17 16 9 11 18 17 7 12 5 14 20 13 2 3 6 2 5 7 11 4 12 19 10 20 11 17 12 16 14 11 15 11 6 3 1 4 19 8 15 4 1 14 16 2 16 2 3 20 8 14 4 20 12 13 19 2 10 10 17 3 20 12 14 6 14 14 9 13 1 4 16 1 17 12 3 13 14 6 13 2 19 16 1 10 9 19 12 18 8 8 1 8 19 14 14 13 8 2 6 9 6 2 9 2 14 12 15 8 17 7 9 15 3 9 5 11 7 16 9 15 4 9 3 3 3 16 15 10 18 1 18 3 3 7 5 16 18 19 3 14 6 11 9 8 20 13 19 6 8 7 1 11 16 3 13 18 19 8 8 16 9 6 19 11 12 3 7 10 2 9 4 8 20 12 16 19 4 14 5 12 1 6 3 17 9 15 14 7 3 2 3 11 7 1 2 19 4 8 8 6 17 11 13 16 2 9 15 6 2 20 17 3 6 19 19 14 14 13 1 17 14 3 7 20 4 8 19 8 16 6 14 12 16 7 8 18 15 2 3 16 2 20 19 7 19 17 1 13 9 1 9 2 4 16 2 7 4 20 15 19 6 8 10 1 14 17 18 9 19 1 5 20 20 3 7 19 19 7 11 7 7 19 9 10 15 11 17 18 10 11 16 15 19 6 16 13 2 14 1 20 14 5 20 14 8 6 12 6 13 3 13 19 2 1 9 16 11 5 13 1 16 8 16 14 14 11 7 15 5 8 15 19 12 15 12 20 1 4 5 13 7 17 11 8 18 19 3 8 4 15 9 19 3 4 13 16 15 19 11 19 6 5 17 18 19 9 17 19 13 2 12 19 18 2 6 16 1 8 4 5 2 12 3 5 16 15 20 10 14 10 9 19 15 6 17 13 14 14 12 7 15 4 5 13 6 11 8 6 18 11 11 20 3 13 4 18 8 4 8 1 13 16 20 7 1 17 20 15 10 12 2 4 15 7 16 20 17 4 6 14 14 16 14 16 9 17 14 16 20 1 17 13 17 17 19 17 13 19 12 3 10 14 6 5 20 2 4 16 6 10 10 20 5 3 16 14 20 9 9 20 9 6 12 5 3 11 2 16 9 14 18 19 7 4 3 7 6 6 2 11 15 11 10 20 14 5 13 13 14 2 12 3 8 3 7 10 14 9 6 2 3 3 20 10 7 2 16 12 8 18 3 3 8 13 3 2 18 15 14 11 17 6 13 4 8 20 14 1 9 19 3 11 2 2 1 8 4 16 20 12 13 3 14 1 15 16 2 12 11 16 3 7 1 15 11 9 15 5 10 3 3 12 14 ------- test 7 ---- 800 771 777 686 725 854 670 423 625 665 119 154 960 471 718 837 811 157 627 891 235 649 507 509 642 275 672 252 491 710 929 321 478 703 5 202 558 677 628 186 347 752 346 315 232 73 163 54 242 803 9 492 469 484 20 130 779 714 405 294 448 359 642 16 90 677 186 679 387 848 899 769 637 282 123 908 396 327 5 682 175 10 221 692 542 290 873 373 56 331 722 560 746 421 572 896 158 820 638 608 733 602 444 437 56 636 416 421 36 494 177 287 581 475 57 203 846 11 658 104 426 465 632 260 98 294 246 224 207 105 56 35 676 468 571 729 205 88 252 344 686 535 737 375 118 48 688 75 27 460 175 569 42 77 100 136 339 315 483 669 417 535 831 220 132 531 80 468 751 466 116 573 137 822 86 395 41 92 612 37 520 113 752 709 6 33 180 497 316 632 321 78 323 309 267 615 1 508 246 114 139 358 655 443 349 115 8 387 206 2 599 695 114 528 582 89 558 759 769 57 575 275 131 86 773 588 116 192 289 330 76 623 116 161 264 433 41 474 23 243 473 67 145 583 564 180 128 333 155 114 604 698 358 205 2 351 17 114 539 274 668 100 123 42 261 617 444 270 324 701 17 32 35 130 127 568 307 255 143 458 89 273 402 694 195 653 295 209 20 88 26 234 184 118 276 442 291 689 271 583 654 287 183 686 386 5 524 270 257 249 5 621 211 375 594 686 309 171 177 613 543 199 164 14 606 116 72 219 97 14 100 46 298 282 31 317 256 192 249 154 102 251 85 620 277 647 616 555 130 107 483 338 623 643 321 548 79 389 121 500 87 220 234 353 139 233 32 93 421 250 246 229 208 331 190 111 321 151 8 420 226 216 136 197 211 426 95 259 168 213 113 251 429 344 356 322 332 387 17 120 4 260 348 211 587 133 290 311 281 80 108 293 296 244 458 92 53 351 151 189 532 233 248 349 388 179 92 293 563 77 409 563 164 186 204 154 287 463 27 410 539 132 261 274 372 129 335 421 476 482 25 424 132 270 191 516 325 280 232 314 241 67 307 404 249 46 93 434 409 21 374 387 121 73 187 406 118 439 273 41 369 267 433 470 468 74 436 306 293 122 106 43 137 412 444 354 427 494 281 330 16 124 215 106 166 376 7 281 308 276 318 183 20 229 135 485 298 55 273 73 146 376 123 279 307 60 124 228 27 401 29 68 53 274 173 188 114 148 508 464 468 334 105 456 74 236 451 372 288 238 413 500 130 84 301 434 144 393 215 139 319 213 203 368 46 372 87 129 53 159 158 87 492 232 85 566 9 81 360 419 287 318 338 547 399 219 534 125 167 161 233 44 521 585 381 567 521 29 262 140 185 420 227 276 223 311 236 201 392 170 226 257 65 144 191 44 362 337 166 529 85 604 573 606 189 546 173 83 171 434 220 324 223 75 229 76 386 70 246 139 209 108 34 523 251 193 180 613 173 315 141 258 566 61 211 100 259 37 463 429 471 311 383 324 385 612 399 104 15 281 547 529 389 580 51 639 416 231 251 589 193 391 166 77 104 26 513 362 60 287 102 217 285 174 540 670 90 243 440 466 220 286 294 608 565 45 246 275 276 497 570 469 177 416 227 277 126 24 352 154 714 143 88 277 316 628 668 101 566 107 567 55 92 561 392 657 606 638 638 143 134 207 350 21 622 577 12 1 316 364 619 29 506 707 27 68 334 695 165 141 42 489 684 130 49 76 549 654 713 186 535 77 392 112 95 14 460 103 761 775 242 379 23 748 86 47 569 419 525 491 318 325 188 1 217 27 76 766 681 789 152 ------- test 8 ---- 400 3992 4000 3972 3980 3952 3960 3932 3940 3912 3920 3892 3900 3872 3880 3852 3860 3832 3840 3812 3820 3792 3800 3772 3780 3752 3760 3732 3740 3712 3720 3692 3700 3672 3680 3652 3660 3632 3640 3612 3620 3592 3600 3572 3580 3552 3560 3532 3540 3512 3520 3492 3500 3472 3480 3452 3460 3432 3440 3412 3420 3392 3400 3372 3380 3352 3360 3332 3340 3312 3320 3292 3300 3272 3280 3252 3260 3232 3240 3212 3220 3192 3200 3172 3180 3152 3160 3132 3140 3112 3120 3092 3100 3072 3080 3052 3060 3032 3040 3012 3020 2992 3000 2972 2980 2952 2960 2932 2940 2912 2920 2892 2900 2872 2880 2852 2860 2832 2840 2812 2820 2792 2800 2772 2780 2752 2760 2732 2740 2712 2720 2692 2700 2672 2680 2652 2660 2632 2640 2612 2620 2592 2600 2572 2580 2552 2560 2532 2540 2512 2520 2492 2500 2472 2480 2452 2460 2432 2440 2412 2420 2392 2400 2372 2380 2352 2360 2332 2340 2312 2320 2292 2300 2272 2280 2252 2260 2232 2240 2212 2220 2192 2200 2172 2180 2152 2160 2132 2140 2112 2120 2092 2100 2072 2080 2052 2060 2032 2040 2012 2020 1992 2000 1972 1980 1952 1960 1932 1940 1912 1920 1892 1900 1872 1880 1852 1860 1832 1840 1812 1820 1792 1800 1772 1780 1752 1760 1732 1740 1712 1720 1692 1700 1672 1680 1652 1660 1632 1640 1612 1620 1592 1600 1572 1580 1552 1560 1532 1540 1512 1520 1492 1500 1472 1480 1452 1460 1432 1440 1412 1420 1392 1400 1372 1380 1352 1360 1332 1340 1312 1320 1292 1300 1272 1280 1252 1260 1232 1240 1212 1220 1192 1200 1172 1180 1152 1160 1132 1140 1112 1120 1092 1100 1072 1080 1052 1060 1032 1040 1012 1020 992 1000 972 980 952 960 932 940 912 920 892 900 872 880 852 860 832 840 812 820 792 800 772 780 752 760 732 740 712 720 692 700 672 680 652 660 632 640 612 620 592 600 572 580 552 560 532 540 512 520 492 500 472 480 452 460 432 440 412 420 392 400 372 380 352 360 332 340 312 320 292 300 272 280 252 260 232 240 212 220 192 200 172 180 152 160 132 140 112 120 92 100 72 80 52 60 32 40 12 20 ------- test 9 ---- 2000 1061 746 503 758 1195 1080 1057 85 144 792 318 36 1095 404 1062 201 671 895 503 655 402 476 822 226 225 1166 1 369 1126 896 1045 984 439 346 542 435 228 401 523 376 39 847 419 1102 61 292 115 745 48 633 215 418 1127 1055 664 172 1043 687 564 994 408 436 805 876 812 177 142 1072 611 699 284 646 384 742 588 485 1075 746 73 1120 224 335 386 200 240 1100 423 135 641 1042 74 1106 335 848 841 8 1086 1046 42 562 610 294 76 1062 10 735 419 1054 354 566 1049 655 979 313 934 99 295 240 317 1021 167 388 1014 591 126 746 690 105 685 728 762 192 52 937 154 62 573 675 22 1032 147 1039 595 34 262 439 244 670 793 676 606 28 134 539 587 228 206 200 456 1015 14 145 135 66 11 419 127 717 27 148 684 311 128 217 484 359 798 871 150 535 493 724 559 623 212 97 1003 571 451 413 542 462 715 835 525 887 215 649 567 407 794 217 885 918 604 340 248 374 185 395 95 854 97 623 457 490 902 442 44 337 61 772 9 745 597 502 623 32 144 184 408 166 599 292 86 204 833 303 781 22 904 873 126 9 505 551 710 419 6 17 22 64 758 31 82 376 502 673 404 871 143 100 95 710 360 181 211 225 452 30 483 392 872 605 641 417 198 393 158 449 407 180 760 214 211 838 842 681 564 300 607 703 397 699 473 112 876 680 306 393 707 156 155 647 730 764 136 307 231 291 725 25 467 563 208 674 482 132 439 130 718 132 243 203 244 684 311 215 458 40 577 262 196 728 8 30 593 447 337 267 183 171 292 618 702 468 404 297 61 306 743 747 407 135 70 648 788 703 18 371 740 563 122 96 420 99 125 145 47 92 409 229 260 697 816 102 307 363 742 364 665 632 259 221 763 679 20 704 536 34 230 433 146 348 525 535 5 647 242 51 305 619 280 533 486 270 213 372 601 133 705 443 733 142 257 677 3 245 564 142 665 401 544 31 718 259 534 719 99 2 767 400 590 276 133 276 109 342 645 353 471 556 6 412 352 263 300 323 477 79 462 358 476 224 385 414 161 142 357 229 141 350 318 422 622 419 666 431 463 546 314 173 340 317 554 688 576 97 255 297 622 445 384 346 638 23 12 82 134 112 279 22 431 594 443 314 275 375 39 33 189 321 206 498 411 34 457 262 100 496 528 509 428 221 138 347 244 119 425 347 227 512 365 470 399 130 78 643 505 116 3 163 406 209 494 149 242 256 411 311 212 248 159 492 469 297 153 166 384 547 378 479 408 65 394 251 194 468 217 139 581 216 191 316 421 119 461 27 372 238 307 491 485 463 408 379 132 558 466 485 450 262 342 237 324 90 456 514 527 28 9 465 194 197 140 583 274 561 5 14 198 281 504 82 113 286 430 242 220 301 102 50 532 441 286 236 528 128 134 439 125 150 292 315 315 447 290 13 380 292 26 605 602 530 53 118 179 522 329 396 182 479 443 123 333 170 416 276 298 518 134 391 116 394 126 400 294 495 410 101 215 432 44 153 422 192 268 37 46 32 402 335 507 283 426 311 450 316 587 224 282 40 65 398 567 159 253 174 139 120 272 353 12 467 475 433 658 206 470 171 403 341 506 382 97 406 693 22 13 79 245 292 88 310 200 167 438 452 309 92 571 67 445 583 55 413 290 713 116 285 154 518 626 189 166 722 595 392 5 116 471 247 376 70 97 118 236 50 570 63 142 390 99 586 523 150 243 339 417 355 623 100 432 48 289 131 3 116 522 312 229 222 100 144 289 196 258 98 246 403 161 387 344 228 189 82 715 771 5 343 684 627 31 322 675 320 46 243 3 568 555 200 360 654 717 222 44 551 320 287 144 480 283 97 290 55 147 188 7 148 116 309 394 144 224 243 86 269 111 88 6 665 257 363 119 605 217 131 317 537 24 67 174 303 160 106 354 767 263 825 534 846 282 74 613 157 794 699 426 46 786 62 370 674 57 488 79 274 256 33 810 248 69 626 190 745 731 187 311 641 689 845 287 622 571 15 778 165 398 4 180 293 65 239 658 121 727 736 394 84 769 4 902 510 629 765 54 159 629 365 800 117 9 174 738 580 786 316 745 264 319 614 244 384 852 623 504 379 159 898 161 928 902 129 237 330 627 291 489 55 656 89 172 665 231 910 44 760 26 789 742 345 202 708 728 99 131 32 232 290 930 392 17 631 253 254 961 879 544 249 934 229 338 133 664 312 815 708 93 840 296 613 202 497 120 711 350 251 743 582 540 472 973 557 108 26 810 863 905 154 112 639 153 249 544 817 560 159 324 431 998 620 31 982 102 148 493 266 214 35 847 753 506 620 109 408 646 919 70 350 43 150 988 26 230 332 842 789 490 127 19 287 585 19 69 500 1025 561 766 38 596 413 790 49 1033 899 310 478 618 379 827 490 360 615 515 589 946 157 178 235 122 196 522 706 58 591 6 5 74 772 39 547 102 709 448 1017 407 757 294 1025 46 30 314 296 536 829 885 282 986 1062 517 6 58 1039 613 115 429 618 88 380 190 4 927 174 623 175 74 1029 932 284 854 868 205 45 39 740 797 847 1022 582 708 338 489 766 176 1101 880 605 519 876 984 708 790 711 882 212 885 871 41 617 5 894 284 159 861 247 899 457 1093 720 1039 601 1057 327 166 33 227 1046 637 746 721 421 254 311 1131 1135 522 816 805 562 232 760 256 515 918 1117 762 616 373 654 136 211 55 1193 538 221 25 764 67 661 310 787 1082 563 1098 1012 497 419 627 102 981 859 861 36 174 578 1152 935 1194 325 388 130 536 443 122 1073 664 146 637 730 807 946 317 688 308 214 500 804 633 1127 905 413 785 565 449 958 1142 400 692 1136 725 1080 65 60 322 186 1132 986 332 568 516 1139 313 833 627 620 1046 1126 224 479 1052 1128 891 636 492 139 394 434 539 1085 370 63 964 434 122 86 620 54 1072 952 622 387 891 934 19 317 354 1065 243 578 343 95 505 33 731 997 172 1124 231 710 1008 600 772 772 1034 894 857 454 947 729 206 368 1115 1096 102 1133 213 456 997 455 1033 139 549 338 172 79 134 343 3 364 1052 1011 964 624 582 798 317 239 52 64 967 257 432 881 152 533 814 364 989 611 819 821 750 168 1158 921 247 92 64 249 455 1116 59 219 539 641 1017 856 879 1068 919 646 124 150 327 276 683 1140 640 471 550 258 92 99 425 49 1020 672 140 1083 920 595 998 978 814 336 419 630 1192 97 497 910 742 620 1060 1068 896 543 1008 335 1013 357 593 1104 456 1017 1153 275 489 93 158 208 687 1155 1186 301 291 404 930 282 501 227 1192 42 846 1051 1110 542 394 918 876 206 75 268 110 530 85 62 805 573 155 962 780 842 917 766 1142 7 1169 872 288 469 1098 280 511 744 131 421 85 524 138 960 729 212 27 839 742 112 901 347 684 1055 109 264 696 1025 1029 638 1031 998 309 119 267 206 398 778 949 528 1198 1033 1051 136 792 580 348 819 219 1090 931 1119 236 414 974 345 678 469 169 506 1106 1199 304 215 118 570 420 515 148 168 1042 145 1200 893 281 792 272 629 411 490 518 141 409 754 555 182 1098 32 651 66 538 557 65 841 771 182 211 1190 697 358 158 538 503 158 231 784 949 502 212 160 992 730 300 201 284 854 382 181 886 1033 247 223 389 312 1064 1160 494 74 1149 1190 432 107 528 935 264 758 519 13 60 731 172 1051 260 472 52 543 125 433 724 1010 266 971 33 654 83 1096 613 576 1170 562 565 402 668 1092 137 932 649 655 944 708 185 1115 559 445 386 610 987 511 1043 511 321 108 282 353 762 364 249 175 939 218 736 304 620 204 195 756 1135 844 210 879 352 395 793 910 839 1179 320 626 489 162 1136 809 270 217 1162 1031 581 210 5 320 428 741 623 1047 945 818 602 880 461 812 558 813 6 151 523 844 129 842 269 618 1004 205 226 74 422 188 1104 1002 397 1109 121 825 650 744 671 394 361 73 74 822 884 631 434 890 782 956 534 910 598 802 327 402 1007 553 475 228 741 379 30 1138 288 151 762 937 894 233 131 54 305 204 876 1189 835 109 879 416 1065 212 126 463 1014 453 864 820 1006 139 1048 546 517 1078 484 805 28 45 541 922 277 672 976 582 875 651 571 510 759 249 926 624 460 1051 1086 273 304 750 1093 109 888 941 655 205 818 1138 1009 846 1183 350 567 259 1021 342 841 695 992 211 5 551 459 930 1174 919 781 1060 1192 1084 609 1084 1193 297 824 647 501 442 585 310 87 567 659 654 826 479 995 467 1174 787 677 1179 137 1136 908 111 854 488 1170 845 372 579 729 364 875 353 1011 176 794 395 485 881 962 1144 334 587 423 129 1053 397 915 530 375 1052 465 82 1162 119 570 1132 964 941 511 492 104 185 845 1114 361 439 309 846 119 70 789 453 657 11 581 510 407 296 1039 781 147 304 863 108 423 232 40 186 1172 550 678 76 735 322 1190 1095 761 298 741 879 367 329 132 1024 340 713 333 747 1008 172 328 1155 476 1190 63 898 222 102 1084 194 652 561 269 186 883 258 81 443 555 821 122 922 1150 253 746 290 966 1079 1036 773 50 164 728 525 153 790 223 375 891 106 568 342 667 836 528 349 1094 609 791 449 229 913 171 179 ------- test 10 ---- 5000 4718 18 19887 17551 9375 3376 7966 5372 5230 15044 16023 5255 15160 8877 11961 15814 13865 2128 4785 9055 18223 19393 11291 1343 7697 6945 1423 6721 2520 7650 14203 7235 7666 14088 4785 17042 17466 12754 2417 2700 7803 18447 7963 2971 7334 19934 18797 1212 2076 3597 10282 316 3007 1591 1679 10724 8558 3124 17469 11102 10800 11698 18365 18494 5816 3180 15567 3314 15967 18019 6050 3807 16504 14052 6817 3878 14028 5657 5133 16148 9299 15462 16512 12354 17102 18241 3130 5713 1418 654 16871 12274 12410 15294 10828 18286 18535 6458 1664 14567 4543 7781 18441 1115 1902 5329 5065 16002 11059 10273 12226 434 5812 8817 12868 2995 7139 16081 8791 8642 16820 5748 1003 9319 1132 11922 7697 19759 18473 9455 14421 3112 17334 12961 4327 19337 18391 9494 15443 9554 13 7776 10096 5793 16702 3075 8900 3953 19269 17806 12710 16206 3672 13832 5644 4924 5875 13463 4807 4473 3044 19354 7712 506 12445 12169 141 10968 1797 15552 658 1806 3465 10892 7739 307 14108 16782 4404 13522 14733 17260 9875 18553 11242 15669 3629 17270 9285 8590 1898 12486 8102 9768 13151 707 2099 13288 11839 4060 9006 12663 6034 12639 3725 13943 13117 18005 10898 17695 11702 5808 15133 1756 4541 6556 17606 8352 4009 7076 17127 6093 19749 5418 16051 13091 6316 18342 6573 18349 2598 15775 11210 8830 8613 15135 2975 1933 13344 14078 74 5252 93 15176 7218 4844 1943 5036 13410 6166 12328 10754 12477 12296 16391 8748 5608 2930 7314 12406 1505 10138 8408 12943 19197 17252 8309 2405 19419 1887 16718 19490 7377 17049 14905 14835 2135 17090 115 15789 3502 12690 6790 16227 5235 3432 5227 11096 6615 12795 3757 8376 3190 12424 1578 2648 9937 10150 5317 9621 12303 2301 9378 252 19620 4553 15056 2028 1917 15445 18092 5696 8412 5161 2202 13928 8875 7712 5307 15774 792 9350 4438 4271 2063 6307 7211 12293 16750 12822 2210 9350 15420 11886 9598 15341 16741 4956 17672 18963 707 16071 4966 9428 1542 7479 3667 10729 15504 9288 6818 16613 18956 11574 1203 1340 18203 8737 13957 15277 1884 16493 4955 17633 8708 14883 13305 5782 172 11312 5080 1215 7720 10384 10982 9602 18205 14992 674 14053 4626 7839 11013 3930 147 12567 5622 18318 1657 322 13951 3897 16783 19264 1890 5852 14508 15557 11997 15045 7234 17444 16628 15323 8198 7981 5296 6775 3346 6345 1203 8348 14562 12595 12658 14705 5543 18662 13407 7585 18981 7744 11869 16152 7397 14149 2396 2298 10100 14787 17739 17731 12628 14765 13453 1226 3148 19152 8405 6898 5903 10015 15654 873 3019 8723 15989 8975 7799 9810 16975 7196 17972 9263 3768 5790 3834 6586 8512 14358 1798 6677 12517 14855 1871 6401 16513 5452 5986 5352 12786 12325 15805 8878 13637 19264 18043 10069 8683 6286 325 6105 13930 18746 15817 18148 4987 103 5187 13953 14917 7441 1087 7892 2756 3419 14754 229 9334 1205 5549 2586 13997 1823 11934 8105 1559 10450 18648 10716 17211 19449 17298 11620 18674 13596 10249 4144 14183 15920 18582 9586 3849 158 17968 7095 4069 13215 7321 13898 14915 13367 16982 9411 15689 9417 18018 17750 370 17170 8972 18088 17127 6778 10217 16312 886 978 969 15583 17413 68 5687 1781 746 4175 9398 5337 17913 17243 321 13355 11137 17271 3296 7356 7219 1846 5639 8123 121 15147 6748 17217 2465 17505 14070 3894 19026 15583 22 16986 16199 6258 19316 17495 10984 9266 3386 9452 7065 3703 3365 18760 1533 7221 6677 9314 9630 12881 18003 9748 8596 5319 7534 11631 3396 2177 16099 2997 18336 16697 561 15113 3534 458 13189 15101 10308 17160 5139 17959 1450 9092 17308 3573 16904 4578 13481 7129 18054 12081 17474 7248 18000 5609 117 1998 8389 16184 5601 7332 13489 6770 3054 17634 7839 16856 13349 18761 14631 19104 17338 16699 8815 15266 894 6342 467 15000 14096 19148 7708 12199 7026 6338 18440 7139 8970 7463 3959 15207 15433 18087 2617 19127 16362 11098 16626 10355 10505 11904 10107 8491 9253 257 4409 10799 6567 5530 6455 1320 5336 14821 14178 13022 1820 13281 825 11454 1410 5450 7329 17511 4207 10616 17309 1241 2388 14610 12272 13570 7192 3057 2740 17125 3311 7832 8608 10563 14047 15749 12570 72 11259 7439 13785 13772 1413 15304 5922 3520 1452 13949 1730 6360 5267 478 8304 8359 15057 1283 2636 2957 5050 6087 793 9073 14632 10115 351 9396 6582 13640 10187 18561 1801 4695 13057 3939 725 466 8186 2906 14384 10646 9997 384 11121 19036 9478 6914 1056 12853 10611 6846 458 12147 16663 15058 3008 17761 5202 10338 12151 16140 9651 14704 1588 3462 189 3070 3925 8344 6735 19070 547 17494 217 11637 17295 10462 121 19120 4084 10700 6738 4538 3620 4175 372 7404 2714 6353 18521 15645 3274 8955 11133 5647 13202 11318 9504 17916 451 17030 17777 995 15317 18788 13427 13409 10047 13545 13329 14932 5046 870 274 9471 5851 1452 17682 9373 8614 17014 5829 12701 6782 17776 13 801 9912 9486 390 11183 7337 18135 13002 3478 17749 7255 17715 8624 1630 11875 4387 7508 13578 5495 17814 265 7785 16335 10477 17240 14191 17149 10784 1818 15770 10794 3466 6530 1129 3853 18565 9318 2841 12421 13652 1446 534 12226 10930 3024 4962 16180 11396 304 2541 10077 537 11194 7281 11885 9306 2345 9907 965 5038 6553 12636 9383 13963 14645 14118 13411 4847 17843 6717 306 177 8140 12501 11998 12056 18356 9072 4346 18656 12509 15320 91 4603 3502 12877 14811 6751 3688 16681 12696 11149 10226 2988 6023 5783 18018 347 11544 16777 7981 11847 17873 17041 5268 10793 10019 4547 789 15290 4130 14225 11539 5150 724 15973 18960 15503 3658 3583 13121 17291 15671 4287 1220 2635 11012 182 3927 3501 17906 12855 16297 16728 10846 2517 8473 1819 8019 10218 18066 13106 5401 10565 212 6121 7500 138 2589 12124 3689 16678 10383 330 1935 12575 3937 13920 13731 8840 18398 12614 2674 15675 10323 14501 192 797 17305 8179 10984 16358 2274 17374 7913 2482 4488 16407 2616 8073 9527 7303 5749 910 8633 8686 14487 13574 3610 9223 3421 3016 2845 7104 746 14180 2617 938 14973 938 9085 6974 18315 12378 5369 7249 15883 10881 4681 585 1041 15235 7856 6759 17175 17521 16477 12695 12130 1123 2955 16588 5177 6840 4732 5920 2062 8393 6854 18081 10377 16987 6104 9741 10416 12525 18043 7352 4460 3779 7934 5498 73 16849 13317 18309 15433 10857 12069 8629 13046 16091 6285 397 4002 12089 6286 7137 1557 14215 6294 13012 12281 13477 3834 3778 7084 2961 12215 12630 7826 1236 339 8989 301 13624 8391 15703 5576 1555 5428 852 18745 12813 114 3849 6005 7503 12090 8667 2825 634 2787 16215 14080 7732 1106 2278 11807 14436 16024 751 16791 16360 10861 17088 11107 375 13915 17808 3057 471 18657 2932 14414 1068 7913 1552 8539 1139 11356 12502 1769 15282 9857 16990 4157 12107 412 17110 7689 17584 193 5630 15094 11023 3870 7354 12552 131 6319 16767 570 6135 859 16146 7200 9936 62 16905 12241 11386 10575 15180 7839 1604 13342 13169 14885 14930 11456 3752 13693 11646 10562 9968 3851 15616 18506 17589 15743 6013 15544 17503 13338 17595 14841 1731 8725 14899 1064 2164 7483 11607 18544 16523 14414 13090 10897 10504 9227 3561 15465 4129 16418 7239 15309 1482 4069 15031 288 1029 2262 17051 1008 16822 15869 15817 1037 5820 11943 838 9212 655 13676 8988 18411 9323 3313 10544 1064 13777 15344 17769 422 13003 6250 15700 15730 11564 11977 17265 13842 15489 15567 14846 13564 12689 11918 14598 1056 5118 16694 10237 7034 11632 487 6709 2220 5065 18520 4552 111 15133 3591 529 9409 11114 17503 6414 3955 10758 4958 391 7527 1806 15206 2375 15780 8409 18259 16832 14816 16243 8359 3141 9167 10140 11144 12683 16502 10961 18533 17912 7395 3426 1080 18107 15845 18551 5828 1107 10618 12096 1495 802 15214 18014 3146 12310 7739 2722 10460 3874 285 141 8338 10776 11606 807 4786 9435 13097 4648 8678 1824 9406 9754 1266 6586 9642 8431 9032 1599 1867 11868 2398 18425 11226 6889 12081 313 10960 3891 5538 12597 5385 15229 4728 18347 17393 10871 9140 11850 16879 576 15036 7649 10298 17667 15602 1308 7467 6004 4278 10706 651 8049 10505 11846 16315 3964 13538 8655 9236 458 2634 16005 17071 8747 15738 15852 1007 6268 9092 704 6840 5522 8321 18534 4585 5321 1240 13452 12725 6920 5560 13373 16373 17471 6625 14096 2843 1573 4161 13491 3443 8209 10910 1930 18373 8065 653 799 15754 9714 1499 4017 16660 11246 3977 2673 17995 6647 17555 12151 14999 4549 6958 12808 3456 15021 8343 7739 18035 13946 2672 2921 3600 15027 6298 3420 4541 6947 5669 1746 18113 8622 7218 16228 1324 12652 359 778 760 872 14392 17223 5389 2816 11498 10313 808 1310 1027 318 16729 3667 3208 1804 171 10983 6702 6192 925 13853 9421 524 3959 18124 16721 6771 12265 94 9040 14516 966 4925 13234 6323 9238 6229 18134 10043 9039 694 10357 7271 4330 15070 10581 6008 7561 337 13711 8482 14158 4645 9003 1183 4285 7242 7923 18069 7333 40 14108 8295 4934 8867 16145 15699 16624 15808 7273 7195 16499 731 16001 2364 15770 8120 9911 4870 8453 5163 14895 4155 11352 5444 5335 17185 14235 14807 16804 3119 14843 12465 12968 1333 2889 10670 184 1072 8039 7425 9830 6101 8153 7396 10031 5490 17084 1511 11930 7108 8247 8399 12838 1174 15419 1362 1550 11233 16137 18323 15935 12564 12373 10488 15483 16849 2747 15664 1137 12377 4681 10935 73 14429 1559 11701 1518 245 14813 15049 7322 4663 5053 1765 7444 2080 3124 8991 14924 872 8926 12472 15050 2914 4576 12151 1382 8943 9436 2516 2942 15740 15076 4641 11796 16631 17971 14943 16873 14415 11625 5828 713 18313 9230 9795 2031 13993 426 273 16508 10995 12713 13204 15556 619 7004 272 9530 18091 2756 14126 15485 1178 423 8939 17777 53 5543 16311 16131 529 3804 210 512 14701 9973 2512 10365 12070 2781 8546 4740 17169 3426 1974 17784 12109 2242 8996 11883 6682 4806 9053 7856 6917 1404 7323 8660 6915 5327 6485 7441 10826 6691 7949 7226 97 12162 1028 12136 16646 9543 321 15522 14677 2264 15016 8497 6217 5724 2093 14614 12246 12863 4188 881 14263 13232 11263 2901 282 1231 12067 12835 7891 1745 1790 7985 15638 2815 1854 14018 14093 2172 11277 10509 6175 8033 747 14135 15501 4585 10495 9493 977 16431 12124 15209 11414 5139 1651 13451 6367 13687 8043 16016 17191 11593 5763 14592 16172 9381 10375 12032 13321 3421 4310 1266 13226 6830 17175 10502 13190 9446 1772 14164 7656 15677 11154 853 2599 12802 16090 10753 8276 5921 8558 7258 1132 16114 3643 17272 7290 15815 11101 2410 1036 17212 5477 16065 5845 4456 8372 842 15709 11953 16815 5176 9441 9781 7843 13855 4399 5749 6425 14493 13489 16804 3573 14618 14741 9041 13715 3858 6683 6645 8097 9550 5689 15407 7448 13369 1699 17657 16048 1120 11450 14703 6264 2734 6328 15951 314 12573 3548 6708 8916 772 5364 14341 15359 1959 5237 10931 7675 13779 1329 17633 5191 6987 14903 14504 2221 370 14028 137 1489 7349 16712 7722 11956 4915 5549 12267 1277 10975 854 10162 11744 8100 6387 8987 11945 13511 1805 1509 9179 3131 1033 16263 12011 17831 12662 16128 129 8589 99 1618 17839 16780 9308 11699 3600 16763 5873 4874 9648 8638 16947 3304 599 5248 14206 12513 676 17929 15941 11776 2981 854 9962 16916 613 4551 14972 742 15069 15068 394 14840 13781 11636 8474 1289 10337 16286 6131 1925 6865 5020 7173 7461 12214 3325 1921 14839 3203 1798 8567 8137 663 484 7009 1273 6992 3940 2012 4021 969 4368 825 16715 17970 11265 2 10276 9521 6102 14173 365 13095 3320 7794 7286 8622 11694 4105 13806 13488 14654 3927 16136 17123 12922 1419 6104 875 3399 12116 1813 9761 14936 523 9727 8199 522 2003 1755 8625 215 81 3725 3503 9882 13018 14134 3586 1179 9951 1134 15801 15892 17239 14940 10831 707 3064 11703 4074 17202 15539 15860 14164 150 7614 4391 641 11647 6142 11298 11859 8258 17058 17398 178 12115 13571 5804 13290 5565 6935 11136 3502 6220 8124 16382 6923 13238 10137 13050 12494 7731 10965 8714 7878 638 15164 10579 14347 3368 3940 8270 13691 3065 7736 15937 17249 3377 3813 12612 11016 12822 5823 16594 1119 16025 15056 10123 11344 7276 5256 5922 17092 428 16723 7058 1034 13978 1854 17473 1567 5763 7839 15227 10925 17673 13264 10275 3152 1316 4991 16272 14107 12921 14974 17335 11056 12140 9569 4512 1530 16939 12550 738 17363 11392 9916 518 7491 11766 115 9055 1815 10081 6409 12708 9883 1804 5115 15167 3116 12240 13575 1531 7299 10687 1008 495 4969 10545 7150 8643 9630 1847 11529 9142 15389 3595 11811 5033 17515 14081 16244 1517 6319 4811 14194 558 8776 1471 15693 14057 15877 11435 15585 5344 4291 16589 8010 11433 9308 17335 2252 1115 1360 15959 12436 1145 1735 6430 6146 1434 2696 4576 2947 11204 11577 1556 11758 2546 2996 9646 1029 1070 3278 16582 8613 9770 15373 1063 3407 6886 607 7865 10208 1936 6033 4855 3077 9980 13498 11438 13630 661 484 1049 11834 12029 349 5814 16799 5569 17685 86 8867 3192 16637 1976 15193 14242 770 835 3364 1374 10937 15811 5549 1485 2907 10868 11434 928 4551 7311 1589 5031 8356 13391 1598 10957 1458 654 1072 1400 739 9907 6851 17344 11879 4307 13850 14913 7407 1782 856 613 17562 6374 2095 2741 1823 15803 3666 6343 5391 5251 13653 16027 924 15248 9268 4667 15898 10336 8354 16634 2532 17496 16270 16703 4097 12415 13912 13801 14194 14765 16713 14056 3440 1110 1439 5259 1559 5073 13910 6919 12634 9873 5258 15870 7434 16840 2852 5649 9493 13525 4603 14345 13342 3196 13372 2122 297 9610 15892 14459 6704 14935 10847 12477 746 12282 72 2305 2064 16320 9192 14666 8535 16792 12880 692 15977 459 6310 7819 13952 13264 4516 9647 1201 242 11765 1498 12210 10015 15926 1275 7312 9135 16115 8055 3782 954 10356 5843 17242 1918 2881 8149 1083 544 8838 1848 1003 17527 9635 14923 13172 16533 6954 14370 1580 1105 15864 13759 13510 14180 17425 3215 5709 15934 13665 11887 16884 6420 130 16527 10739 5413 7080 14227 5954 766 16071 6953 705 8117 4288 13846 7063 13656 10632 8640 17179 8915 4818 13110 5517 4665 1207 13650 3025 14840 7965 2338 3689 10525 1296 16861 840 10811 13523 6763 11574 12033 16155 12276 2592 2886 8565 12100 1468 1644 3187 1099 13008 10456 14178 977 63 15381 17083 3056 12678 7506 7853 1323 493 11612 650 1329 4889 14142 10559 1434 8645 9185 13678 13709 14545 4718 8284 16010 8839 13950 17105 4328 6888 13765 7788 6947 11632 7357 12491 6799 17353 2835 8118 338 16940 8765 4163 4326 5405 17221 5756 16550 8908 1937 12763 5957 9160 3554 4475 508 13 4091 7347 9413 369 198 1426 14518 7524 13885 3836 7398 1797 14476 10259 1265 5767 16948 5559 13700 16699 13846 12782 8139 884 8079 16632 10013 14171 3645 13060 16724 10277 2949 8681 13191 3144 10103 10256 13217 6538 16643 3166 8332 13673 15980 9594 1996 15486 304 850 14745 14119 13600 5447 15000 4245 4646 7580 984 10860 3211 280 3710 8733 11535 2087 14454 4216 12312 10251 13335 11536 16000 4250 7793 14565 16430 12376 12639 16731 13223 9976 13443 9416 647 11038 16257 5261 1216 2475 1357 7028 2723 5035 1005 16864 7119 15428 3689 2040 8289 2281 16188 6902 6500 6597 4084 5548 1592 1996 4899 92 11941 965 9476 12584 14630 8361 473 1139 10833 1826 8136 16190 9496 9137 15690 1924 7204 2018 3932 810 4296 2764 7681 13441 12008 14412 1637 16249 16405 9188 16337 10999 12808 8469 6239 10095 2182 9371 11231 12984 13860 2030 11838 6021 13834 10195 7942 3707 14884 14546 4514 1853 2694 14870 682 14670 11960 2287 13600 11046 14158 12620 4730 9651 3776 13656 2435 5955 5718 16357 1631 2272 1082 16165 10990 345 9058 1631 4021 6644 1616 11238 11202 1569 8814 11880 1691 3484 16878 15259 17243 13749 10594 4688 6117 17088 1063 11271 5763 9502 10350 10118 14499 14158 9009 8216 14499 797 12577 1252 10173 14190 15224 4111 1267 6776 1502 183 13000 1124 961 12986 14842 11523 421 3706 11359 4233 512 2660 16488 10831 12747 13742 7745 4513 4716 5004 8070 54 9018 1007 17009 7008 7884 1074 16552 9383 1225 12323 10504 2183 8084 8121 16483 11282 14605 10622 1110 15114 13278 384 8730 8810 14094 2085 16112 1600 7057 6974 4447 1697 10776 4251 8673 1458 5321 8024 13641 9347 3149 6948 14335 14039 717 13625 8129 15290 7057 9235 13217 3149 9616 4762 14776 6528 6843 13707 10948 16722 3504 1076 1274 17105 5295 9915 1391 13446 769 730 5626 6752 7647 2796 3628 8360 2132 14596 6490 9158 6674 2551 15151 2016 10159 12774 8512 2736 9332 2312 2313 15689 3385 696 15651 11538 13470 2795 7844 17101 628 16333 6717 11140 1996 13213 2368 4124 10679 11730 16155 227 64 14181 2239 10192 9834 13631 12924 2047 1742 15233 621 5095 1737 2081 2444 15175 1951 10257 15168 5472 9485 4781 2439 14378 892 4775 1403 14473 2344 461 543 2408 490 2750 12568 10292 2237 8403 15252 1030 6551 1738 9042 8284 866 11483 6379 5738 4662 4471 14134 32 12178 16569 14378 16000 4275 1678 13405 6615 2108 13945 9019 2594 2607 4527 15826 1867 15872 14021 5842 5368 15756 813 16600 2555 12265 5931 8261 2868 13357 5351 2900 8492 4878 241 7453 12114 1919 3822 1694 3995 733 13681 9557 3336 1178 8355 8175 24 5351 3 8368 4084 815 7948 6636 13048 16862 899 15913 13204 6218 1831 4685 14086 2071 15129 9193 962 1945 13883 7953 5675 10562 509 12012 14742 11867 3191 809 223 3190 9146 7316 4002 105 9 62 3028 908 2041 16200 7095 818 3905 4201 2886 2056 16418 6872 7027 13327 915 15731 6919 1393 10774 4694 16293 69 5499 2623 3227 757 9908 10269 830 9914 13375 3854 10818 15412 3102 961 2364 10058 8214 5219 15167 7686 15147 5251 4071 16058 4041 14050 512 975 1807 2969 1043 10373 2490 4239 11127 15468 685 15029 8456 14028 1959 2350 12518 8140 6391 14879 1279 805 3181 2650 8460 1415 7869 15619 562 15001 12761 4167 15973 792 7133 143 11134 12721 4350 5361 11291 5032 3494 2851 2166 8559 8309 936 2953 955 15783 4201 1760 2079 6847 10188 6611 988 8926 10294 15958 4810 742 15055 5598 7843 15195 3023 3694 2676 8352 1284 10841 14980 4103 16144 6677 15550 250 9627 16502 16001 149 1437 1225 6965 11593 10984 7950 3670 4429 7060 11633 5168 5271 388 16169 3624 3407 3023 9462 14922 4303 3467 13067 11573 2779 2913 10292 3025 15712 9966 2199 15857 11400 6601 6000 6171 765 345 13023 8377 7374 7841 16730 15831 11416 16088 2645 1238 2302 15300 16128 9800 1962 12392 4570 7940 1739 1297 14166 656 11232 2809 16482 5838 9378 5690 15219 13354 6032 11455 4944 16620 2511 4891 15669 398 4198 1535 1636 9723 58 991 2748 5247 13352 10547 16416 15087 11841 13815 15740 6307 16620 15458 15383 9237 4388 13843 5832 13662 8541 14021 13528 14298 2160 12446 14692 9608 518 16324 2584 545 602 8589 9050 13922 2395 8726 12271 795 5805 11275 7071 5691 10001 5723 1502 964 2837 7303 14595 14652 4599 11399 12228 10037 7124 10201 2927 7639 9809 8796 11470 10407 672 3808 7619 6358 15826 3183 7150 4925 1084 849 13914 11053 6540 15412 12014 12680 6018 9913 10638 13924 4620 6174 7270 15055 3032 13510 6007 12810 5621 794 6535 9612 7921 829 2648 7070 3981 9766 15320 5061 10611 12562 2808 482 11305 14791 16496 658 8039 10470 1291 15998 3357 8530 14394 3012 5383 3746 2547 14351 7887 9050 7312 2544 9876 9956 9582 601 3078 8258 5631 441 4180 8436 891 2245 6590 751 2871 1397 14589 4158 767 1347 16060 15129 4328 4817 2251 6871 2545 13516 2715 13238 16056 12560 6577 9023 13157 13041 668 2176 13479 8239 14003 1189 10480 3988 1909 178 5381 3329 4305 6144 1240 3767 4677 8972 11990 10334 2693 1387 7260 1963 14593 6729 1385 4585 2617 14510 1044 3254 106 1398 14914 989 2587 8818 4946 4465 8992 13755 7791 193 3331 12463 3929 11443 4871 2826 5215 7561 738 15915 12966 2251 6087 14347 6805 8701 12305 11298 15404 15862 12692 13770 335 15276 6043 5249 3198 1987 2464 14449 2180 9257 10376 6077 4165 2214 8899 12849 9744 13108 12235 6182 15356 1797 4005 5637 13975 3301 414 12860 2647 106 10113 2982 15350 3164 8200 2036 1626 14154 3503 3802 6905 13847 13375 14567 16058 5772 10915 9302 2382 6652 2526 1242 11955 6499 10386 9439 9796 14311 5810 12439 14413 2986 15417 13280 2598 7135 2390 7744 4811 2335 15070 15240 3268 11971 13334 2857 1273 7779 12128 7187 1533 14650 11965 13457 4686 5889 6435 1597 3742 15788 14005 1700 2350 12969 2109 4916 3654 914 16212 12017 6803 14837 10813 10067 10366 7706 12920 15200 2642 8611 5950 576 6826 1481 1203 15080 10940 7606 280 1862 6968 14254 3530 9314 10801 5636 1424 1650 10131 1222 13636 518 16028 8035 14173 9982 2954 10684 8773 1969 2888 1947 6141 13310 3397 7341 11990 1572 2184 12267 3434 9121 10126 6932 2042 4535 16178 3463 6182 9922 4682 3432 14056 4326 15085 11847 1582 1691 6153 10323 3629 12665 12267 13397 9603 2955 4367 5224 861 6548 1124 4291 2974 14887 14861 4985 3062 14679 12089 12886 8245 415 3644 5947 8389 2381 1444 9967 385 11249 3944 7669 7570 3559 4723 832 2819 12750 9717 7343 2961 14505 15299 5931 13060 13829 14585 3498 12179 10347 61 4099 14438 3704 13724 6505 2371 2563 154 6439 13781 7783 1513 5038 11338 6205 9559 1573 2646 2968 8884 9301 1169 7879 2662 1661 5407 951 1422 1289 11266 1479 9094 9410 5180 6526 3369 11261 9086 3491 1414 6582 14990 2923 15337 10046 12847 8617 11615 2973 15308 4223 12243 204 15830 14901 1861 4968 15848 7016 9991 10849 12230 2821 3996 1149 13087 7362 16151 5915 14597 1310 22 13333 7981 15328 7128 4579 7696 2496 7548 6759 10475 3547 10720 10064 2208 137 2589 1819 7121 12549 233 3118 2940 4198 8036 15995 15331 7960 5684 13703 13045 5703 10813 4804 4810 1722 13164 106 8001 4497 6833 2262 11832 1342 16115 1655 1476 2528 3443 12392 15045 3673 3139 1814 11670 11144 1614 10804 2907 7266 8312 3600 618 2934 8373 5397 8467 5350 5499 283 13662 16149 6363 9313 1310 6299 10965 6609 8823 2091 2826 7695 5732 5961 9506 1233 937 11117 15871 7679 2218 8020 11275 2832 14793 3489 12070 7103 12682 1414 11231 10191 1410 1442 3353 6571 11593 2057 921 4271 258 3716 15823 9848 13537 9190 14943 2233 4170 14678 9880 10255 6566 5024 860 5229 12384 12899 114 8941 2099 11313 3009 3477 549 10243 13930 12111 12297 14848 267 363 2451 3901 10180 3803 13060 9015 2107 1125 7589 15884 15277 1986 4807 69 7184 1093 12937 7294 13939 15032 2515 857 2419 3061 15012 261 3033 11224 2975 3268 11583 5394 7166 5683 9193 4149 2580 15225 9199 10137 15036 8404 12120 3774 8470 3236 8800 5341 14465 6676 4311 919 11473 10670 7921 10427 14875 10951 5597 1827 2148 1129 7189 9283 10763 335 1373 13340 3506 10540 7434 2504 2904 3514 6246 15337 10714 3009 4643 9146 9654 12923 14034 5097 7564 5928 3506 6414 854 9072 8238 2999 14180 3422 279 8925 3726 1652 6251 7228 12160 1697 9728 3080 5180 3994 2413 3917 2972 7025 13031 658 3948 11066 5724 15515 998 9226 5934 5859 2305 2223 12867 496 1599 13143 13434 9340 14791 3702 586 10970 5395 14335 14046 14597 2383 515 2570 5324 7509 15570 5978 15488 10668 15734 15036 15700 8996 5006 5596 15340 7226 2503 3953 12868 3768 1435 6253 2608 5105 10887 13546 14550 9273 11645 13201 11652 12157 15767 1033 3725 15397 11072 3274 10127 10869 2374 9892 3932 11448 3659 3341 2745 6131 7290 3794 9895 8722 10015 12500 2018 4982 10126 653 2454 5855 13822 14075 2098 13677 3319 9913 13164 14360 1406 7384 9323 3749 1373 1485 3429 5028 4794 6142 15262 326 9933 9263 9017 4056 5871 11032 13148 108 11681 15599 10077 9619 13790 445 7414 1260 10326 4699 15588 11729 367 9037 3766 1708 10518 3030 10867 3610 13305 10263 3936 7373 3662 12921 15568 13672 8093 12857 2100 3918 12601 12146 1864 10539 12588 9246 11795 7065 2285 11537 2949 2652 4731 6711 4329 3603 13901 3554 3015 11369 13785 6948 2909 1615 4038 2646 3662 508 3883 1554 4395 662 2087 6255 11169 14643 3897 7146 5891 1964 2868 13025 4612 11786 3925 13130 15385 2017 908 2594 1810 14661 13738 4688 475 1975 11534 4133 2480 15414 9892 11080 313 11975 1543 11451 10829 5436 2810 933 11614 9893 2426 444 5897 6319 2050 5503 12559 2957 12321 14365 1848 10286 3282 2291 757 3313 10657 3205 2965 4784 2792 3277 998 4303 14697 344 13982 1750 1246 9842 170 3668 14535 6035 14238 867 78 11050 3824 12367 9672 1380 6912 1507 7931 7666 522 2852 15135 3483 11902 2225 6757 1473 6497 5726 1817 4753 11750 3031 3183 11917 10978 2000 2233 9497 2867 2307 4831 2370 3282 3112 8038 10163 293 261 2121 5109 7407 1551 12889 3606 3773 3946 5076 14571 13974 6890 3629 10030 14227 6808 6255 9514 8804 12800 3324 11667 3770 12470 2704 2700 15579 10711 1538 194 15294 3627 9627 7026 9505 6844 14961 1971 15121 4369 878 13429 15593 4476 7795 14158 15622 2764 8013 8767 15532 58 4779 3679 12497 7480 6347 12425 2541 7882 1358 2189 253 10954 13572 9726 2157 12892 11694 1639 1623 12569 3831 1582 1411 11595 108 1402 14355 12492 14542 14261 12546 3696 2348 9420 15555 8663 6226 2477 928 7580 9050 1177 2921 7009 15292 9467 4292 11377 15499 10309 8341 3756 718 14150 15320 794 4387 14077 2126 3336 12742 14640 7001 15086 8469 6965 8160 3552 13855 13501 11101 7320 3545 2891 3201 3259 12327 7462 14605 12249 2195 7372 463 2910 5950 215 8135 10334 14261 10257 13666 11438 9334 5104 10963 2243 985 3565 5791 14808 1510 1338 6575 5052 4225 9773 8308 1004 1687 7366 2196 8338 3685 2659 200 9604 2874 8303 4400 1601 3025 2531 13008 1329 12104 8440 3540 13086 985 13805 12368 2463 4130 3420 11993 8324 2188 4783 13810 3844 1152 523 1189 315 3182 1389 14409 1530 9661 3303 3127 1711 10331 633 3040 6935 13574 6549 4523 14555 4859 1396 1524 8986 9324 2571 1820 11509 7322 144 4416 8471 664 1053 13305 3843 2438 12236 9895 1181 63 2108 2891 14921 2709 1367 6387 814 12448 11 4472 1843 1375 5965 15367 15239 8533 1729 11291 398 6418 284 13416 11629 1305 11270 23 8295 8058 14471 9472 12677 1166 12360 12157 3844 2883 3105 9220 15300 3112 13689 1709 9055 4223 1645 8865 1933 7946 4729 2300 3550 5009 293 15147 10894 759 4368 3772 8786 3426 2449 6049 4592 14778 2796 8404 2283 10493 2218 2180 2831 504 3858 11854 9326 10103 5321 11256 2653 14654 2801 6199 4271 3063 5956 4421 3818 10320 8161 1868 13743 10607 7885 2985 10004 15302 11358 12284 10418 2859 14461 13246 3332 2947 9730 1954 2348 4350 13178 4969 3643 646 478 7882 3678 6403 12300 12138 1366 5105 14003 4437 359 6536 2737 15014 6490 3434 11951 1562 1603 11069 4157 9593 3369 13856 11543 1019 2900 9386 10654 1841 10029 11129 14393 3082 2203 11365 15189 8244 1146 13868 12677 6183 5084 94 5878 973 3525 2514 2504 9814 2992 6658 4097 1636 5205 333 7349 8101 14414 2699 14640 9141 3261 13734 12220 5433 9802 12113 3122 395 10689 510 6547 483 573 1885 1453 8813 4368 8673 3344 7356 50 12162 13714 9977 1976 5787 2804 1120 13214 2173 10230 1237 638 7182 6638 15174 4031 9757 338 4231 10264 6854 4683 357 8735 10880 9138 2630 4300 2013 9955 9100 14143 8421 3831 905 3754 11392 2024 1729 3118 12222 2966 3724 4167 9572 3664 12965 4097 3999 1996 3936 430 6648 4292 9134 2303 13398 11760 11381 222 6496 5263 14334 4519 13879 55 3451 10058 2078 5177 13173 14269 8140 1690 3231 2508 10151 993 11403 3783 2986 171 4213 14437 4463 13315 1546 2671 9884 2581 2892 1192 7813 2043 5707 6508 2097 13976 1384 4175 3974 4235 3269 1795 5894 6469 4271 872 12290 503 4651 108 671 8861 4248 5130 7012 5763 7797 1736 8341 10686 7770 998 12725 3202 12352 14819 2029 3470 3875 5972 2817 2256 7763 13566 13581 1783 4189 10731 2254 8809 598 7789 2534 4846 2686 14414 10578 10451 1020 3791 6010 13663 9663 3611 1773 6892 3308 3802 10359 7180 9742 2977 14320 2390 1433 12789 4170 698 8410 11315 14399 9005 3998 1829 13848 6681 1142 9326 2032 7063 2956 12946 5631 12588 1463 7401 4389 9680 11199 4605 1772 5854 2633 1008 13161 4062 3668 2250 9680 12047 3445 9003 5977 7412 719 4752 3984 1829 3973 5985 13825 1961 3865 4391 4456 10266 1703 8813 4886 12871 13415 11602 3670 993 2538 1778 10003 1222 8979 4635 3209 12420 3581 9154 4788 4300 3858 8769 6097 2835 4713 4886 9760 Keep up the good work! Thanks for your submission!
算法练习 - Buy Low, Buy Lower - USACO