using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeetCode.QuestionBank.Question0795
{
    public class Test0795
    {
        public void Test()
        {
            Interface0795 solution = new Solution0795_3();
            int[] nums; int left, right;
            int result, answer;
            int id = 0;

            // 1. 
            nums = new int[] { 2, 1, 4, 3 }; left = 2; right = 3;
            answer = 3; result = solution.NumSubarrayBoundedMax(nums, left, right);
            Console.WriteLine($"{++id,2}: {(result == answer) + ",",-6} result: {result}, answer: {answer}");

            // 2. 
            nums = new int[] { 2, 9, 2, 5, 6 }; left = 2; right = 8;
            answer = 7; result = solution.NumSubarrayBoundedMax(nums, left, right);
            Console.WriteLine($"{++id,2}: {(result == answer) + ",",-6} result: {result}, answer: {answer}");

            // 3. 
            nums = new int[] { 2, 9, 2, 5, 1, 6, 7 }; left = 2; right = 8;
            answer = 15; result = solution.NumSubarrayBoundedMax(nums, left, right);
            Console.WriteLine($"{++id,2}: {(result == answer) + ",",-6} result: {result}, answer: {answer}");

            // 4. 
            nums = new int[] { 9680, 7762, 6748, 6555, 62, 6498, 3278, 2153, 5309, 2940, 8942, 8660, 3614, 2717, 5032, 3387, 7013, 7711, 2811, 495, 676, 4695, 1637, 2016, 4831, 3614, 7844, 8354, 4372, 5118, 9024, 6257, 7617, 7267, 4621, 2295, 8649, 6911, 9119, 2453, 750, 9043, 4152, 8320, 2381, 8532, 1076, 9304, 8276, 2908, 6886, 2862, 2662, 610, 8943, 6517, 3923, 2845, 8553, 3979, 7040, 818, 7128, 7889, 9772, 7371, 6498, 4756, 6852, 7513, 960, 5392, 1142, 2470, 3430, 1902, 6669, 9288, 4382, 6362, 4278, 735, 1989, 1300, 8180, 2915, 1418, 7429, 7237, 4005, 6572, 4437, 9021, 9341, 2662, 1297, 3958, 7714, 8286, 8965, 4867, 9097, 4565, 2680, 452, 3844, 4255, 3249, 9646, 3939, 6880, 2697, 2718, 2927, 4054, 7907, 2508, 6842, 2497, 6504, 4893, 5388, 1670, 4028, 276, 9379, 4373, 5740, 4813, 433, 8497, 5332, 8348, 472, 6881, 3332, 6954, 9336, 2835, 3990, 5905, 4057, 5384, 8036, 2649, 2685, 7747, 2771, 9214, 7690, 2247, 3114, 372, 7971, 5498, 3275, 9982, 3449, 6732, 6706, 5340, 6365, 549, 2882, 4771, 969, 6549, 9685, 8438, 7992, 7151, 1145, 9114, 3515, 1379, 1125, 8222, 4200, 8360, 2226, 1987, 8978, 7836, 358, 4522, 9750, 2627, 6306, 8468, 4777, 5079, 6881, 6340, 8129, 3603, 3839, 6719, 7334, 5158, 3649, 8004, 6726, 1546, 2140, 5946, 435, 9495, 3131, 2461, 2964, 1835, 3258, 8653, 3439, 7232, 4258, 9741, 6412, 3279, 9127, 434, 9764, 8872, 2689, 783, 3386, 9694, 2811, 6364, 7407, 9449, 7463, 3182, 1075, 8408, 8226, 2316, 5703, 565, 3171, 8789, 5890, 771, 2553, 7916, 2326, 6814, 4987, 3551, 3921, 9441, 6201, 746, 4284, 4500, 8605, 8211, 9573, 1027, 1102, 4180, 5787, 807, 6594, 6860, 5293, 881, 4917, 3387, 7830, 5562, 8314, 6642, 51, 3826, 219, 2212, 6964, 1912, 9523, 5187, 9947, 2054, 261, 5045, 7687, 5416, 2056, 8720, 1562, 955, 1760, 8764, 3546, 9818, 8375, 7415, 9354, 7233, 8633, 6819, 7038, 8260, 3011, 2088, 1451, 9996, 5593, 2096, 5132, 9312, 4528, 3373, 3483, 4471, 525, 6180, 4137, 565, 6158, 1344, 2164, 3896, 82, 6310, 3677, 9617, 5114, 1091, 8169, 4155, 464, 9416, 3305, 9363, 1590, 9171, 1, 6197, 9770, 2170, 4053, 4773, 5828, 5572, 1636, 5724, 4651, 3387, 4793, 6873, 4572, 1532, 8780, 7178, 3110, 6473, 4005, 8362, 5038, 7791, 6845, 4462, 1433, 1870, 6932, 1171, 1415, 5424, 613, 889, 1095, 494, 9583, 9368, 5041, 3693, 1970, 7466, 9806, 7880, 4528, 8554, 1165, 4829, 4014, 344, 1804, 9457, 4276, 541, 9926, 7562, 853, 5597, 3739, 1469, 3212, 3676, 2099, 6268, 3103, 2479, 7498, 661, 663, 3094, 1935, 2032, 3505, 7203, 219, 3195, 2520, 8693, 7835, 4482, 8306, 3197, 4374, 9940, 7642, 4034, 9138, 2017, 8673, 5282, 7347, 7521, 1213, 3265, 8730, 6890, 5164, 7755, 6973, 7343, 3509, 2115, 4660, 6915, 1263, 6458, 4811, 3543, 6700, 3564, 1504, 3220, 9527, 574, 5555, 2266, 2824, 9848, 697, 4577, 7724, 3315, 7977, 7256, 8454, 641, 152, 1371, 1682, 7267, 2430, 9716, 5292, 5067, 7935, 4486, 5568, 1987, 7648, 8903, 4283, 9161, 1696, 271, 549, 9993, 9007, 8209, 7734, 5010, 4966, 2659, 7333, 5003, 7294, 7787, 5368, 9233, 7410, 3333, 6790, 8237, 55, 3072, 6800, 2237, 1116, 638, 5603, 7661, 2440, 6185, 5746, 1014, 9536, 9646, 6442, 1270, 5478, 228, 1324, 4417, 9367, 4848, 6480, 3669, 5056, 7472, 9551, 980, 904, 1215, 5680, 9391, 6286, 8268, 3862, 4272, 9049, 9903, 5094, 8129, 8699, 9824, 6525, 9837, 1655, 1800, 6494, 7699, 5472, 9835, 8991, 4273, 9646, 2701, 3962, 6911, 8593, 6920, 2290, 3907, 3983, 6710, 5968, 5071, 3245, 9245, 1579, 3702, 1474, 2046, 9614, 4031, 2360, 5485, 5324, 4509, 1575, 870, 9285, 9736, 5741, 8036, 7817, 6743, 8607, 2071, 2692, 5389, 1164, 3381, 3089, 8218, 1734, 7401, 2475, 9172, 5658, 7040, 7512, 6919, 5636, 7225, 984, 5202, 52, 9852, 708, 650, 112, 9153, 1940, 807, 448, 1593, 9465, 7503, 7371, 4871, 9883, 6148, 1973, 1223, 9208, 3805, 9608, 9504, 6793, 5459, 5893, 6254, 5961, 9364, 4527, 1283, 1482, 5372, 4285, 6407, 8894, 7391, 6626, 2598, 9208, 8257, 5285, 8476, 2001, 4414, 6311, 6397, 374, 9916, 9297, 1746, 1419, 265, 5888, 3362, 6025, 6903, 3241, 6638, 1200, 3726, 8209, 1297, 7174, 587, 466, 8873, 8093, 4613, 8604, 6668, 234, 8696, 9612, 8071, 5542, 5273, 1305, 2081, 6399, 4261, 3930, 6741, 7624, 1370, 2866, 1319, 9813, 8809, 7622, 3048, 830, 4590, 9612, 8494, 1452, 1259, 740, 6027, 9142, 125, 2679, 1648, 8490, 7140, 362, 6098, 6710, 9209, 7305, 5438, 2125, 1040, 2850, 2276, 560, 1908, 2644, 9413, 7818, 6656, 6890, 8493, 8867, 8740, 3949, 1959, 7291, 2020, 4408, 7107, 1118, 6197, 5447, 9054, 4438, 5994, 9377, 9761, 7654, 6262, 7486, 9046, 2783, 5729, 3197, 3763, 374, 6295, 3960, 9743, 999, 6914, 4097, 9127, 9550, 378, 3755, 3177, 3832, 7681, 1885, 3777, 969, 9799, 777, 8633, 4704, 9865, 5396, 5648, 245, 8033, 3702, 1332, 2522, 7263, 7794, 2260, 902, 6197, 5859, 2106, 5273, 9562, 4698, 7648, 139, 7345, 5075, 8781, 4971, 3929, 2270, 2242, 638, 3481, 6195, 4628, 6542, 5631, 1627, 3243, 444, 7517, 665, 9681, 4647, 227, 3513, 5794, 4496, 2369, 3133, 3766, 4671, 477, 9483, 4544, 5618, 8755, 3293, 2344, 5270, 766, 4336, 7305, 8520, 9565, 8883, 8748, 440, 8319, 1253, 5574, 8098, 3803, 5936, 493, 1134, 1062, 3842, 8626, 3339, 1558, 7186, 8546, 8696, 9563, 7361, 8125, 2238, 4348, 3627, 4446, 5911, 9845, 3820, 8656, 7560, 1701, 3490, 1288, 6361, 7086, 4849, 5476, 9325, 8037, 2047, 2530, 3194, 3285, 357, 5708, 3278, 7923, 1695, 3778, 216, 3526, 5425, 9874, 4767, 6762, 6417, 6567, 3542, 6646, 130, 6040, 4850, 1532, 4343, 2748, 9724, 8172, 5208, 6394, 3688, 275, 1170, 5641, 7915, 1679, 3886, 6273, 4934, 4888, 4019, 4611, 7629, 6071, 9596, 7337, 3433, 895, 5791, 5368, 418, 9926, 6945, 4493, 9957, 9169, 6516, 1587, 5885, 7898, 777, 9430, 1355, 5196, 7302, 4740, 5736, 9900, 4616, 2245, 3346, 3182, 1928, 1891, 3678, 551, 6876, 1712, 7652, 7766, 7117, 5746, 9598, 4868, 3749, 8290, 8651, 202, 8905, 4547, 3385, 188, 5527, 134, 726, 9016, 9663, 5892, 5441, 1009, 9810, 917, 6868, 5906, 1009, 6315, 8141, 7996, 6559, 3175, 1904, 6531, 601, 7522, 8139, 7703, 5839, 4961, 4183, 6723, 2100, 4188, 7372, 1966, 1170, 6956, 9184, 4870, 3885 };
            left = 500; right = 5000;
            answer = 905; result = solution.NumSubarrayBoundedMax(nums, left, right);
            Console.WriteLine($"{++id,2}: {(result == answer) + ",",-6} result: {result}, answer: {answer}");

            // 5. 
            nums = new int[] { 9680, 7762, 6748, 6555, 62, 6498, 3278, 2153, 5309, 2940, 8942, 8660, 3614, 2717, 5032, 3387, 7013, 7711, 2811, 495, 676, 4695, 1637, 2016, 4831, 3614, 7844, 8354, 4372, 5118, 9024, 6257, 7617, 7267, 4621, 2295, 8649, 6911, 9119, 2453, 750, 9043, 4152, 8320, 2381, 8532, 1076, 9304, 8276, 2908, 6886, 2862, 2662, 610, 8943, 6517, 3923, 2845, 8553, 3979, 7040, 818, 7128, 7889, 9772, 7371, 6498, 4756, 6852, 7513, 960, 5392, 1142, 2470, 3430, 1902, 6669, 9288, 4382, 6362, 4278, 735, 1989, 1300, 8180, 2915, 1418, 7429, 7237, 4005, 6572, 4437, 9021, 9341, 2662, 1297, 3958, 7714, 8286, 8965, 4867, 9097, 4565, 2680, 452, 3844, 4255, 3249, 9646, 3939, 6880, 2697, 2718, 2927, 4054, 7907, 2508, 6842, 2497, 6504, 4893, 5388, 1670, 4028, 276, 9379, 4373, 5740, 4813, 433, 8497, 5332, 8348, 472, 6881, 3332, 6954, 9336, 2835, 3990, 5905, 4057, 5384, 8036, 2649, 2685, 7747, 2771, 9214, 7690, 2247, 3114, 372, 7971, 5498, 3275, 9982, 3449, 6732, 6706, 5340, 6365, 549, 2882, 4771, 969, 6549, 9685, 8438, 7992, 7151, 1145, 9114, 3515, 1379, 1125, 8222, 4200, 8360, 2226, 1987, 8978, 7836, 358, 4522, 9750, 2627, 6306, 8468, 4777, 5079, 6881, 6340, 8129, 3603, 3839, 6719, 7334, 5158, 3649, 8004, 6726, 1546, 2140, 5946, 435, 9495, 3131, 2461, 2964, 1835, 3258, 8653, 3439, 7232, 4258, 9741, 6412, 3279, 9127, 434, 9764, 8872, 2689, 783, 3386, 9694, 2811, 6364, 7407, 9449, 7463, 3182, 1075, 8408, 8226, 2316, 5703, 565, 3171, 8789, 5890, 771, 2553, 7916, 2326, 6814, 4987, 3551, 3921, 9441, 6201, 746, 4284, 4500, 8605, 8211, 9573, 1027, 1102, 4180, 5787, 807, 6594, 6860, 5293, 881, 4917, 3387, 7830, 5562, 8314, 6642, 51, 3826, 219, 2212, 6964, 1912, 9523, 5187, 9947, 2054, 261, 5045, 7687, 5416, 2056, 8720, 1562, 955, 1760, 8764, 3546, 9818, 8375, 7415, 9354, 7233, 8633, 6819, 7038, 8260, 3011, 2088, 1451, 9996, 5593, 2096, 5132, 9312, 4528, 3373, 3483, 4471, 525, 6180, 4137, 565, 6158, 1344, 2164, 3896, 82, 6310, 3677, 9617, 5114, 1091, 8169, 4155, 464, 9416, 3305, 9363, 1590, 9171, 1, 6197, 9770, 2170, 4053, 4773, 5828, 5572, 1636, 5724, 4651, 3387, 4793, 6873, 4572, 1532, 8780, 7178, 3110, 6473, 4005, 8362, 5038, 7791, 6845, 4462, 1433, 1870, 6932, 1171, 1415, 5424, 613, 889, 1095, 494, 9583, 9368, 5041, 3693, 1970, 7466, 9806, 7880, 4528, 8554, 1165, 4829, 4014, 344, 1804, 9457, 4276, 541, 9926, 7562, 853, 5597, 3739, 1469, 3212, 3676, 2099, 6268, 3103, 2479, 7498, 661, 663, 3094, 1935, 2032, 3505, 7203, 219, 3195, 2520, 8693, 7835, 4482, 8306, 3197, 4374, 9940, 7642, 4034, 9138, 2017, 8673, 5282, 7347, 7521, 1213, 3265, 8730, 6890, 5164, 7755, 6973, 7343, 3509, 2115, 4660, 6915, 1263, 6458, 4811, 3543, 6700, 3564, 1504, 3220, 9527, 574, 5555, 2266, 2824, 9848, 697, 4577, 7724, 3315, 7977, 7256, 8454, 641, 152, 1371, 1682, 7267, 2430, 9716, 5292, 5067, 7935, 4486, 5568, 1987, 7648, 8903, 4283, 9161, 1696, 271, 549, 9993, 9007, 8209, 7734, 5010, 4966, 2659, 7333, 5003, 7294, 7787, 5368, 9233, 7410, 3333, 6790, 8237, 55, 3072, 6800, 2237, 1116, 638, 5603, 7661, 2440, 6185, 5746, 1014, 9536, 9646, 6442, 1270, 5478, 228, 1324, 4417, 9367, 4848, 6480, 3669, 5056, 7472, 9551, 980, 904, 1215, 5680, 9391, 6286, 8268, 3862, 4272, 9049, 9903, 5094, 8129, 8699, 9824, 6525, 9837, 1655, 1800, 6494, 7699, 5472, 9835, 8991, 4273, 9646, 2701, 3962, 6911, 8593, 6920, 2290, 3907, 3983, 6710, 5968, 5071, 3245, 9245, 1579, 3702, 1474, 2046, 9614, 4031, 2360, 5485, 5324, 4509, 1575, 870, 9285, 9736, 5741, 8036, 7817, 6743, 8607, 2071, 2692, 5389, 1164, 3381, 3089, 8218, 1734, 7401, 2475, 9172, 5658, 7040, 7512, 6919, 5636, 7225, 984, 5202, 52, 9852, 708, 650, 112, 9153, 1940, 807, 448, 1593, 9465, 7503, 7371, 4871, 9883, 6148, 1973, 1223, 9208, 3805, 9608, 9504, 6793, 5459, 5893, 6254, 5961, 9364, 4527, 1283, 1482, 5372, 4285, 6407, 8894, 7391, 6626, 2598, 9208, 8257, 5285, 8476, 2001, 4414, 6311, 6397, 374, 9916, 9297, 1746, 1419, 265, 5888, 3362, 6025, 6903, 3241, 6638, 1200, 3726, 8209, 1297, 7174, 587, 466, 8873, 8093, 4613, 8604, 6668, 234, 8696, 9612, 8071, 5542, 5273, 1305, 2081, 6399, 4261, 3930, 6741, 7624, 1370, 2866, 1319, 9813, 8809, 7622, 3048, 830, 4590, 9612, 8494, 1452, 1259, 740, 6027, 9142, 125, 2679, 1648, 8490, 7140, 362, 6098, 6710, 9209, 7305, 5438, 2125, 1040, 2850, 2276, 560, 1908, 2644, 9413, 7818, 6656, 6890, 8493, 8867, 8740, 3949, 1959, 7291, 2020, 4408, 7107, 1118, 6197, 5447, 9054, 4438, 5994, 9377, 9761, 7654, 6262, 7486, 9046, 2783, 5729, 3197, 3763, 374, 6295, 3960, 9743, 999, 6914, 4097, 9127, 9550, 378, 3755, 3177, 3832, 7681, 1885, 3777, 969, 9799, 777, 8633, 4704, 9865, 5396, 5648, 245, 8033, 3702, 1332, 2522, 7263, 7794, 2260, 902, 6197, 5859, 2106, 5273, 9562, 4698, 7648, 139, 7345, 5075, 8781, 4971, 3929, 2270, 2242, 638, 3481, 6195, 4628, 6542, 5631, 1627, 3243, 444, 7517, 665, 9681, 4647, 227, 3513, 5794, 4496, 2369, 3133, 3766, 4671, 477, 9483, 4544, 5618, 8755, 3293, 2344, 5270, 766, 4336, 7305, 8520, 9565, 8883, 8748, 440, 8319, 1253, 5574, 8098, 3803, 5936, 493, 1134, 1062, 3842, 8626, 3339, 1558, 7186, 8546, 8696, 9563, 7361, 8125, 2238, 4348, 3627, 4446, 5911, 9845, 3820, 8656, 7560, 1701, 3490, 1288, 6361, 7086, 4849, 5476, 9325, 8037, 2047, 2530, 3194, 3285, 357, 5708, 3278, 7923, 1695, 3778, 216, 3526, 5425, 9874, 4767, 6762, 6417, 6567, 3542, 6646, 130, 6040, 4850, 1532, 4343, 2748, 9724, 8172, 5208, 6394, 3688, 275, 1170, 5641, 7915, 1679, 3886, 6273, 4934, 4888, 4019, 4611, 7629, 6071, 9596, 7337, 3433, 895, 5791, 5368, 418, 9926, 6945, 4493, 9957, 9169, 6516, 1587, 5885, 7898, 777, 9430, 1355, 5196, 7302, 4740, 5736, 9900, 4616, 2245, 3346, 3182, 1928, 1891, 3678, 551, 6876, 1712, 7652, 7766, 7117, 5746, 9598, 4868, 3749, 8290, 8651, 202, 8905, 4547, 3385, 188, 5527, 134, 726, 9016, 9663, 5892, 5441, 1009, 9810, 917, 6868, 5906, 1009, 6315, 8141, 7996, 6559, 3175, 1904, 6531, 601, 7522, 8139, 7703, 5839, 4961, 4183, 6723, 2100, 4188, 7372, 1966, 1170, 6956, 9184, 4870, 3885 };
            left = 800; right = 8000;
            answer = 3577; result = solution.NumSubarrayBoundedMax(nums, left, right);
            Console.WriteLine($"{++id,2}: {(result == answer) + ",",-6} result: {result}, answer: {answer}");
        }
    }
}
