# Generación de la pila a
from random import sample, seed
seed()
n = 500 # número de elementos de la pila
a = sample(range(1, n+1), n)
print('a:', a)
#https://stackoverflow.com/questions/40732489/how-to-print-the-actual-longest-increasing-subsequence-not-just-length
# Dynamic programming Python implementation of LIS problem
# lis returns length of the longest increasing subsequence
# in arr of size n
def lis(arr):
n = len(arr)
# Declare the list (array) for LIS and initialize LIS
# values for all indexes
lis = [1]*n
prev = [0]*n
for i in range(0, n):
prev[i] = i
# Compute optimized LIS values in bottom up manner
for i in range (1 , n):
for j in range(0 , i):
if arr[i] > arr[j] and lis[i]< lis[j] + 1:
lis[i] = lis[j]+1
prev[i] = j
# Initialize maximum to 0 to get the maximum of all
# LIS
maximum = 0
idx = 0
# Pick maximum of all LIS values
for i in range(n):
if maximum < lis[i]:
maximum = lis[i]
idx = i
seq = [arr[idx]]
while idx != prev[idx]:
idx = prev[idx]
seq.append(arr[idx])
return (maximum, reversed(seq))
# end of lis function
# Driver program to test above function
#arr = [10, 22, 9, 33, 21, 50, 41, 60]
a = [175, 38, 151, 167, 17, 168, 26, 244, 229, 364, 137, 54, 55, 245, 403, 319, 402, 67, 51, 479, 362, 224, 482, 63, 237, 277, 268, 201, 335, 490, 239, 307, 324, 387, 34, 274, 280, 365, 162, 372, 214, 261, 27, 376, 144, 337, 248, 363, 117, 70, 193, 200, 84, 284, 108, 410, 438, 81, 177, 104, 236, 174, 264, 145, 316, 430, 71, 487, 243, 425, 19, 183, 417, 57, 406, 282, 169, 392, 266, 20, 455, 356, 291, 209, 462, 48, 346, 257, 309, 64, 59, 32, 2, 153, 303, 115, 445, 269, 196, 77, 199, 208, 333, 166, 259, 413, 344, 468, 176, 95, 400, 8, 206, 469, 381, 310, 304, 139, 379, 132, 1, 428, 110, 179, 453, 123, 442, 188, 72, 101, 475, 477, 99, 427, 447, 382, 270, 96, 407, 255, 191, 408, 133, 273, 370, 343, 112, 74, 467, 56, 149, 249, 73, 189, 138, 234, 367, 198, 212, 279, 136, 124, 491, 478, 82, 496, 287, 262, 331, 434, 79, 24, 494, 374, 106, 61, 13, 401, 290, 474, 247, 242, 298, 296, 473, 352, 397, 223, 65, 360, 495, 230, 369, 465, 97, 69, 422, 492, 122, 454, 155, 321, 353, 121, 211, 357, 21, 165, 30, 336, 318, 171, 271, 254, 451, 143, 295, 131, 500, 233, 358, 16, 449, 231, 156, 240, 493, 466, 172, 164, 405, 263, 160, 253, 202, 476, 415, 302, 210, 464, 359, 23, 481, 332, 11, 347, 39, 418, 361, 260, 246, 42, 119, 440, 10, 44, 341, 293, 94, 312, 14, 85, 299, 68, 238, 256, 301, 354, 472, 107, 486, 157, 148, 125, 329, 424, 89, 311, 380, 36, 431, 154, 215, 393, 265, 109, 334, 102, 228, 159, 22, 52, 126, 459, 75, 272, 275, 432, 116, 141, 373, 135, 60, 294, 326, 426, 53, 5, 134, 297, 29, 267, 289, 389, 18, 391, 460, 484, 340, 180, 111, 195, 173, 470, 128, 92, 207, 366, 204, 350, 441, 58, 182, 120, 25, 377, 130, 147, 411, 163, 384, 305, 281, 190, 43, 222, 375, 203, 142, 300, 93, 320, 497, 439, 194, 338, 184, 140, 308, 12, 241, 323, 216, 150, 197, 456, 258, 88, 31, 409, 420, 435, 15, 219, 100, 317, 461, 429, 419, 3, 187, 46, 414, 66, 178, 444, 226, 416, 252, 87, 383, 181, 443, 345, 83, 342, 80, 62, 90, 385, 457, 448, 483, 49, 485, 50, 35, 152, 315, 386, 161, 251, 325, 227, 205, 45, 313, 185, 114, 446, 371, 330, 437, 37, 452, 327, 186, 76, 158, 368, 129, 118, 292, 232, 218, 398, 396, 423, 170, 314, 421, 6, 488, 235, 127, 286, 480, 433, 47, 28, 250, 322, 276, 489, 394, 349, 436, 33, 217, 463, 306, 471, 450, 404, 278, 225, 339, 399, 355, 351, 213, 9, 285, 98, 458, 146, 113, 103, 328, 221, 78, 91, 499, 220, 4, 498, 390, 388, 40, 412, 348, 378, 41, 288, 86, 7, 283, 192, 395, 105]
arr = a
ans = lis(arr)
print("Length of lis is", ans[0])
print("The longest sequence is", ", ".join(str(x) for x in ans[1]))
a: [175, 38, 151, 167, 17, 168, 26, 244, 229, 364, 137, 54, 55, 245, 403, 319, 402, 67, 51, 479, 362, 224, 482, 63, 237, 277, 268, 201, 335, 490, 239, 307, 324, 387, 34, 274, 280, 365, 162, 372, 214, 261, 27, 376, 144, 337, 248, 363, 117, 70, 193, 200, 84, 284, 108, 410, 438, 81, 177, 104, 236, 174, 264, 145, 316, 430, 71, 487, 243, 425, 19, 183, 417, 57, 406, 282, 169, 392, 266, 20, 455, 356, 291, 209, 462, 48, 346, 257, 309, 64, 59, 32, 2, 153, 303, 115, 445, 269, 196, 77, 199, 208, 333, 166, 259, 413, 344, 468, 176, 95, 400, 8, 206, 469, 381, 310, 304, 139, 379, 132, 1, 428, 110, 179, 453, 123, 442, 188, 72, 101, 475, 477, 99, 427, 447, 382, 270, 96, 407, 255, 191, 408, 133, 273, 370, 343, 112, 74, 467, 56, 149, 249, 73, 189, 138, 234, 367, 198, 212, 279, 136, 124, 491, 478, 82, 496, 287, 262, 331, 434, 79, 24, 494, 374, 106, 61, 13, 401, 290, 474, 247, 242, 298, 296, 473, 352, 397, 223, 65, 360, 495, 230, 369, 465, 97, 69, 422, 492, 122, 454, 155, 321, 353, 121, 211, 357, 21, 165, 30, 336, 318, 171, 271, 254, 451, 143, 295, 131, 500, 233, 358, 16, 449, 231, 156, 240, 493, 466, 172, 164, 405, 263, 160, 253, 202, 476, 415, 302, 210, 464, 359, 23, 481, 332, 11, 347, 39, 418, 361, 260, 246, 42, 119, 440, 10, 44, 341, 293, 94, 312, 14, 85, 299, 68, 238, 256, 301, 354, 472, 107, 486, 157, 148, 125, 329, 424, 89, 311, 380, 36, 431, 154, 215, 393, 265, 109, 334, 102, 228, 159, 22, 52, 126, 459, 75, 272, 275, 432, 116, 141, 373, 135, 60, 294, 326, 426, 53, 5, 134, 297, 29, 267, 289, 389, 18, 391, 460, 484, 340, 180, 111, 195, 173, 470, 128, 92, 207, 366, 204, 350, 441, 58, 182, 120, 25, 377, 130, 147, 411, 163, 384, 305, 281, 190, 43, 222, 375, 203, 142, 300, 93, 320, 497, 439, 194, 338, 184, 140, 308, 12, 241, 323, 216, 150, 197, 456, 258, 88, 31, 409, 420, 435, 15, 219, 100, 317, 461, 429, 419, 3, 187, 46, 414, 66, 178, 444, 226, 416, 252, 87, 383, 181, 443, 345, 83, 342, 80, 62, 90, 385, 457, 448, 483, 49, 485, 50, 35, 152, 315, 386, 161, 251, 325, 227, 205, 45, 313, 185, 114, 446, 371, 330, 437, 37, 452, 327, 186, 76, 158, 368, 129, 118, 292, 232, 218, 398, 396, 423, 170, 314, 421, 6, 488, 235, 127, 286, 480, 433, 47, 28, 250, 322, 276, 489, 394, 349, 436, 33, 217, 463, 306, 471, 450, 404, 278, 225, 339, 399, 355, 351, 213, 9, 285, 98, 458, 146, 113, 103, 328, 221, 78, 91, 499, 220, 4, 498, 390, 388, 40, 412, 348, 378, 41, 288, 86, 7, 283, 192, 395, 105] Length of lis is 42 The longest sequence is 17, 26, 54, 55, 67, 70, 84, 108, 145, 153, 166, 176, 179, 188, 191, 198, 212, 223, 230, 233, 240, 253, 260, 293, 299, 301, 329, 334, 340, 366, 377, 384, 409, 420, 435, 444, 457, 483, 485, 488, 489, 499 Otra posible LIS: [2, 6, 9, 11, 15]
def lengthOfLIS(nums):
if not nums:
return 0
dp = [1] * len(nums)
for i in range(1, len(nums)):
for j in range(i):
if nums[i] > nums[j]:
dp[i] = max(dp[i], dp[j] + 1)
return dp #max(dp)
#a = [8,4,12,2,10,6,14,9,5,13,11,7,15]
a = [175, 38, 151, 167, 17, 168, 26, 244, 229, 364, 137, 54, 55, 245, 403, 319, 402, 67, 51, 479, 362, 224, 482, 63, 237, 277, 268, 201, 335, 490, 239, 307, 324, 387, 34, 274, 280, 365, 162, 372, 214, 261, 27, 376, 144, 337, 248, 363, 117, 70, 193, 200, 84, 284, 108, 410, 438, 81, 177, 104, 236, 174, 264, 145, 316, 430, 71, 487, 243, 425, 19, 183, 417, 57, 406, 282, 169, 392, 266, 20, 455, 356, 291, 209, 462, 48, 346, 257, 309, 64, 59, 32, 2, 153, 303, 115, 445, 269, 196, 77, 199, 208, 333, 166, 259, 413, 344, 468, 176, 95, 400, 8, 206, 469, 381, 310, 304, 139, 379, 132, 1, 428, 110, 179, 453, 123, 442, 188, 72, 101, 475, 477, 99, 427, 447, 382, 270, 96, 407, 255, 191, 408, 133, 273, 370, 343, 112, 74, 467, 56, 149, 249, 73, 189, 138, 234, 367, 198, 212, 279, 136, 124, 491, 478, 82, 496, 287, 262, 331, 434, 79, 24, 494, 374, 106, 61, 13, 401, 290, 474, 247, 242, 298, 296, 473, 352, 397, 223, 65, 360, 495, 230, 369, 465, 97, 69, 422, 492, 122, 454, 155, 321, 353, 121, 211, 357, 21, 165, 30, 336, 318, 171, 271, 254, 451, 143, 295, 131, 500, 233, 358, 16, 449, 231, 156, 240, 493, 466, 172, 164, 405, 263, 160, 253, 202, 476, 415, 302, 210, 464, 359, 23, 481, 332, 11, 347, 39, 418, 361, 260, 246, 42, 119, 440, 10, 44, 341, 293, 94, 312, 14, 85, 299, 68, 238, 256, 301, 354, 472, 107, 486, 157, 148, 125, 329, 424, 89, 311, 380, 36, 431, 154, 215, 393, 265, 109, 334, 102, 228, 159, 22, 52, 126, 459, 75, 272, 275, 432, 116, 141, 373, 135, 60, 294, 326, 426, 53, 5, 134, 297, 29, 267, 289, 389, 18, 391, 460, 484, 340, 180, 111, 195, 173, 470, 128, 92, 207, 366, 204, 350, 441, 58, 182, 120, 25, 377, 130, 147, 411, 163, 384, 305, 281, 190, 43, 222, 375, 203, 142, 300, 93, 320, 497, 439, 194, 338, 184, 140, 308, 12, 241, 323, 216, 150, 197, 456, 258, 88, 31, 409, 420, 435, 15, 219, 100, 317, 461, 429, 419, 3, 187, 46, 414, 66, 178, 444, 226, 416, 252, 87, 383, 181, 443, 345, 83, 342, 80, 62, 90, 385, 457, 448, 483, 49, 485, 50, 35, 152, 315, 386, 161, 251, 325, 227, 205, 45, 313, 185, 114, 446, 371, 330, 437, 37, 452, 327, 186, 76, 158, 368, 129, 118, 292, 232, 218, 398, 396, 423, 170, 314, 421, 6, 488, 235, 127, 286, 480, 433, 47, 28, 250, 322, 276, 489, 394, 349, 436, 33, 217, 463, 306, 471, 450, 404, 278, 225, 339, 399, 355, 351, 213, 9, 285, 98, 458, 146, 113, 103, 328, 221, 78, 91, 499, 220, 4, 498, 390, 388, 40, 412, 348, 378, 41, 288, 86, 7, 283, 192, 395, 105]
dp = lengthOfLIS(a)
print(dp)
print(f"La subsecuencia creciente más larga tiene {max(dp)} elementos.")
[1, 1, 2, 3, 1, 4, 2, 5, 5, 6, 3, 3, 4, 6, 7, 7, 8, 5, 3, 9, 8, 6, 10, 5, 7, 8, 8, 6, 9, 11, 8, 9, 10, 11, 3, 9, 10, 11, 6, 12, 7, 9, 3, 13, 6, 11, 9, 12, 6, 6, 7, 8, 7, 11, 8, 14, 15, 7, 9, 8, 10, 9, 11, 9, 12, 15, 7, 16, 11, 15, 2, 10, 15, 5, 14, 12, 10, 14, 12, 3, 16, 13, 13, 11, 17, 4, 14, 12, 14, 6, 6, 4, 1, 10, 14, 9, 16, 13, 11, 8, 12, 13, 15, 11, 14, 16, 16, 18, 12, 9, 17, 2, 13, 19, 17, 15, 15, 10, 17, 10, 1, 18, 10, 13, 19, 11, 19, 14, 8, 10, 20, 21, 10, 18, 20, 18, 15, 10, 19, 15, 15, 20, 12, 16, 17, 17, 11, 9, 21, 5, 13, 16, 9, 15, 13, 16, 18, 16, 17, 18, 13, 12, 22, 22, 10, 23, 19, 18, 20, 21, 10, 4, 23, 21, 11, 7, 3, 22, 20, 23, 18, 18, 21, 21, 23, 22, 23, 18, 8, 23, 24, 19, 24, 25, 11, 9, 25, 26, 12, 26, 14, 22, 23, 12, 17, 24, 4, 15, 5, 23, 22, 16, 20, 20, 26, 14, 21, 13, 27, 20, 25, 4, 26, 20, 15, 21, 27, 27, 17, 16, 26, 22, 16, 22, 18, 28, 27, 23, 19, 28, 26, 5, 29, 24, 3, 25, 6, 28, 27, 23, 22, 7, 12, 29, 3, 8, 25, 24, 11, 25, 4, 11, 25, 9, 21, 23, 26, 27, 30, 12, 31, 16, 15, 13, 27, 29, 12, 27, 28, 6, 30, 16, 20, 29, 24, 13, 28, 13, 21, 17, 5, 9, 14, 31, 10, 25, 26, 31, 14, 15, 29, 15, 10, 27, 28, 30, 10, 2, 15, 28, 6, 25, 27, 30, 5, 31, 32, 33, 29, 18, 14, 19, 18, 33, 15, 13, 20, 30, 20, 30, 32, 11, 19, 15, 6, 31, 16, 17, 32, 18, 32, 29, 27, 20, 8, 21, 31, 21, 17, 29, 14, 30, 34, 33, 21, 31, 20, 17, 30, 4, 22, 31, 22, 18, 22, 34, 24, 12, 7, 33, 34, 35, 5, 23, 15, 31, 36, 35, 34, 2, 21, 9, 34, 12, 19, 36, 24, 35, 25, 13, 32, 20, 36, 32, 13, 32, 13, 12, 14, 33, 37, 37, 38, 10, 39, 11, 8, 19, 31, 34, 20, 25, 32, 25, 23, 9, 31, 21, 16, 37, 33, 33, 36, 9, 38, 33, 22, 13, 20, 34, 17, 17, 28, 26, 24, 35, 35, 36, 21, 32, 36, 3, 40, 27, 18, 28, 39, 37, 10, 7, 28, 33, 29, 41, 35, 34, 38, 8, 24, 39, 30, 40, 39, 36, 30, 25, 34, 36, 35, 35, 24, 4, 31, 15, 40, 19, 16, 16, 34, 25, 14, 15, 42, 25, 3, 42, 36, 36, 10, 37, 35, 36, 11, 32, 15, 4, 31, 23, 37, 17] La subsecuencia creciente más larga tiene 42 elementos.
def function(arr):
n = len(arr)
print("n:", n)
# Declare the list (array) for LIS and initialize LIS
# values for all indexes
lis = [1]*n
prev = list(range(n)) # una lista con los index
# Compute optimized LIS values in bottom up manner
for i in range (1, n):
for j in range(i):
if arr[i] > arr[j] and lis[i] < lis[j] + 1:
lis[i] = lis[j]+1
prev[i] = j
# Initialize maximum to 0 to get the maximum of all
# LIS
maximum = 0
idx = 0
# Pick maximum of all LIS values
for i in range(n):
if maximum < lis[i]:
maximum = lis[i]
idx = i
seq = [arr[idx]]
while idx != prev[idx]:
idx = prev[idx]
seq.append(arr[idx])
return (maximum, reversed(seq))
a = [175, 38, 151, 167, 17, 168, 26, 244, 229, 364, 137, 54, 55, 245, 403, 319, 402, 67, 51, 479, 362, 224, 482, 63, 237, 277, 268, 201, 335, 490, 239, 307, 324, 387, 34, 274, 280, 365, 162, 372, 214, 261, 27, 376, 144, 337, 248, 363, 117, 70, 193, 200, 84, 284, 108, 410, 438, 81, 177, 104, 236, 174, 264, 145, 316, 430, 71, 487, 243, 425, 19, 183, 417, 57, 406, 282, 169, 392, 266, 20, 455, 356, 291, 209, 462, 48, 346, 257, 309, 64, 59, 32, 2, 153, 303, 115, 445, 269, 196, 77, 199, 208, 333, 166, 259, 413, 344, 468, 176, 95, 400, 8, 206, 469, 381, 310, 304, 139, 379, 132, 1, 428, 110, 179, 453, 123, 442, 188, 72, 101, 475, 477, 99, 427, 447, 382, 270, 96, 407, 255, 191, 408, 133, 273, 370, 343, 112, 74, 467, 56, 149, 249, 73, 189, 138, 234, 367, 198, 212, 279, 136, 124, 491, 478, 82, 496, 287, 262, 331, 434, 79, 24, 494, 374, 106, 61, 13, 401, 290, 474, 247, 242, 298, 296, 473, 352, 397, 223, 65, 360, 495, 230, 369, 465, 97, 69, 422, 492, 122, 454, 155, 321, 353, 121, 211, 357, 21, 165, 30, 336, 318, 171, 271, 254, 451, 143, 295, 131, 500, 233, 358, 16, 449, 231, 156, 240, 493, 466, 172, 164, 405, 263, 160, 253, 202, 476, 415, 302, 210, 464, 359, 23, 481, 332, 11, 347, 39, 418, 361, 260, 246, 42, 119, 440, 10, 44, 341, 293, 94, 312, 14, 85, 299, 68, 238, 256, 301, 354, 472, 107, 486, 157, 148, 125, 329, 424, 89, 311, 380, 36, 431, 154, 215, 393, 265, 109, 334, 102, 228, 159, 22, 52, 126, 459, 75, 272, 275, 432, 116, 141, 373, 135, 60, 294, 326, 426, 53, 5, 134, 297, 29, 267, 289, 389, 18, 391, 460, 484, 340, 180, 111, 195, 173, 470, 128, 92, 207, 366, 204, 350, 441, 58, 182, 120, 25, 377, 130, 147, 411, 163, 384, 305, 281, 190, 43, 222, 375, 203, 142, 300, 93, 320, 497, 439, 194, 338, 184, 140, 308, 12, 241, 323, 216, 150, 197, 456, 258, 88, 31, 409, 420, 435, 15, 219, 100, 317, 461, 429, 419, 3, 187, 46, 414, 66, 178, 444, 226, 416, 252, 87, 383, 181, 443, 345, 83, 342, 80, 62, 90, 385, 457, 448, 483, 49, 485, 50, 35, 152, 315, 386, 161, 251, 325, 227, 205, 45, 313, 185, 114, 446, 371, 330, 437, 37, 452, 327, 186, 76, 158, 368, 129, 118, 292, 232, 218, 398, 396, 423, 170, 314, 421, 6, 488, 235, 127, 286, 480, 433, 47, 28, 250, 322, 276, 489, 394, 349, 436, 33, 217, 463, 306, 471, 450, 404, 278, 225, 339, 399, 355, 351, 213, 9, 285, 98, 458, 146, 113, 103, 328, 221, 78, 91, 499, 220, 4, 498, 390, 388, 40, 412, 348, 378, 41, 288, 86, 7, 283, 192, 395, 105]
arr = a
ans = function(arr)
print("Length of lis is", ans[0])
print("The longest sequence is", ", ".join(str(x) for x in ans[1]))
n: 500 lis: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] prev: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499] Length of lis is 42 The longest sequence is 17, 26, 54, 55, 67, 70, 84, 108, 145, 153, 166, 176, 179, 188, 191, 198, 212, 223, 230, 233, 240, 253, 260, 293, 299, 301, 329, 334, 340, 366, 377, 384, 409, 420, 435, 444, 457, 483, 485, 488, 489, 499