diff --git a/labs/12_stacks_and_queues/README.md b/labs/11_stacks_and_queues/README.md similarity index 98% rename from labs/12_stacks_and_queues/README.md rename to labs/11_stacks_and_queues/README.md index bd58cf2..2cc6188 100644 --- a/labs/12_stacks_and_queues/README.md +++ b/labs/11_stacks_and_queues/README.md @@ -1,4 +1,4 @@ -# Lab 12 — Stacks and Queues +# Lab 11 — Stacks and Queues In this lab, you will implement queues in different ways, and then fix memory leaks in the provided program. Start by downloading the provided program [levelOrder.cpp](levelOrder.cpp). The provided program [levelOrder.cpp](levelOrder.cpp) traverses a binary tree by level order. It prints the following message to STDOUT: diff --git a/labs/11_stacks_and_queues/a.out b/labs/11_stacks_and_queues/a.out new file mode 100755 index 0000000..913db9a Binary files /dev/null and b/labs/11_stacks_and_queues/a.out differ diff --git a/labs/12_stacks_and_queues/levelOrder.cpp b/labs/11_stacks_and_queues/levelOrder.cpp similarity index 100% rename from labs/12_stacks_and_queues/levelOrder.cpp rename to labs/11_stacks_and_queues/levelOrder.cpp diff --git a/labs/11_stacks_and_queues/levelOrder_sol1.cpp b/labs/11_stacks_and_queues/levelOrder_sol1.cpp new file mode 100644 index 0000000..3645190 --- /dev/null +++ b/labs/11_stacks_and_queues/levelOrder_sol1.cpp @@ -0,0 +1,153 @@ +#include +#include +#include + +// Definition for a binary tree node. +class TreeNode { +public: + int val; + TreeNode* left; + TreeNode* right; + TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} +}; + +class MyQueue { +public: + MyQueue() { + + } + + void push(TreeNode* x) { + int size = myStack1.size(); + // move everything in stack1 to stack2 + for(int i=0;i myStack1; + std::stack myStack2; +}; + +std::vector> levelOrderTraversal(TreeNode* root) { + std::vector> result; + + if (root == nullptr) { + return result; + } + + MyQueue myQueue; + myQueue.push(root); + + while (!myQueue.empty()) { + int size = myQueue.size(); + std::vector current_level; + + for (int i = 0; i < size; i++) { + TreeNode* current = myQueue.front(); + myQueue.pop(); + std::cout << current->val << " "; + + if (current != nullptr) { + current_level.push_back(current->val); + + if (current->left != nullptr) { + myQueue.push(current->left); + } + if (current->right != nullptr) { + myQueue.push(current->right); + } + } + } + + result.push_back(current_level); + } + + return result; +} + +int main() { + /* test case 1 + * 1 + * 2 3 + * 4 5 6 7 + */ + TreeNode* root1 = new TreeNode(1); + root1->left = new TreeNode(2); + root1->right = new TreeNode(3); + root1->left->left = new TreeNode(4); + root1->left->right = new TreeNode(5); + root1->right->left = new TreeNode(6); + root1->right->right = new TreeNode(7); + + std::cout << "Level Order Traversal: "; + levelOrderTraversal(root1); + std::cout << std::endl; + + /* test case 2 + * 1 + * 2 3 + * 4 5 6 7 + * 8 9 + */ + TreeNode* root2 = new TreeNode(1); + root2->left = new TreeNode(2); + root2->right = new TreeNode(3); + root2->left->left = new TreeNode(4); + root2->left->right = new TreeNode(5); + root2->right->left = new TreeNode(6); + root2->right->right = new TreeNode(7); + root2->right->right->left = new TreeNode(8); + root2->right->right->right = new TreeNode(9); + + std::cout << "Level Order Traversal: "; + levelOrderTraversal(root2); + std::cout << std::endl; + + /* test case 3 + * 1 + * 2 3 + * 4 5 6 7 + * 8 + */ + TreeNode* root3 = new TreeNode(1); + root3->left = new TreeNode(2); + root3->right = new TreeNode(3); + root3->left->left = new TreeNode(4); + root3->left->right = new TreeNode(5); + root3->right->left = new TreeNode(6); + root3->right->right = new TreeNode(7); + root3->left->left->left = new TreeNode(8); + + std::cout << "Level Order Traversal: "; + levelOrderTraversal(root3); + std::cout << std::endl; + + return 0; +} + diff --git a/labs/11_stacks_and_queues/levelOrder_sol2.cpp b/labs/11_stacks_and_queues/levelOrder_sol2.cpp new file mode 100644 index 0000000..70bfd54 --- /dev/null +++ b/labs/11_stacks_and_queues/levelOrder_sol2.cpp @@ -0,0 +1,140 @@ +#include +#include +#include + +// Definition for a binary tree node. +class TreeNode { +public: + int val; + TreeNode* left; + TreeNode* right; + TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} +}; + +class MyQueue { +public: + MyQueue() { + + } + + void push(TreeNode* node) { + myList.push_back(node); + } + + void pop() { + myList.pop_front(); + } + + TreeNode* front() { + return myList.front(); + } + + bool empty() { + return myList.empty(); + } + + int size() { + return myList.size(); + } + +private: + std::list myList; +}; + +std::vector> levelOrderTraversal(TreeNode* root) { + std::vector> result; + + if (root == nullptr) { + return result; + } + + MyQueue myQueue; + myQueue.push(root); + + while (!myQueue.empty()) { + int size = myQueue.size(); + std::vector current_level; + + for (int i = 0; i < size; i++) { + TreeNode* current = myQueue.front(); + myQueue.pop(); + std::cout << current->val << " "; + + if (current != nullptr) { + current_level.push_back(current->val); + + if (current->left != nullptr) { + myQueue.push(current->left); + } + if (current->right != nullptr) { + myQueue.push(current->right); + } + } + } + + result.push_back(current_level); + } + + return result; +} + +int main() { + /* test case 1 + * 1 + * 2 3 + * 4 5 6 7 + */ + TreeNode* root1 = new TreeNode(1); + root1->left = new TreeNode(2); + root1->right = new TreeNode(3); + root1->left->left = new TreeNode(4); + root1->left->right = new TreeNode(5); + root1->right->left = new TreeNode(6); + root1->right->right = new TreeNode(7); + + std::cout << "Level Order Traversal: "; + levelOrderTraversal(root1); + std::cout << std::endl; + + /* test case 2 + * 1 + * 2 3 + * 4 5 6 7 + * 8 9 + */ + TreeNode* root2 = new TreeNode(1); + root2->left = new TreeNode(2); + root2->right = new TreeNode(3); + root2->left->left = new TreeNode(4); + root2->left->right = new TreeNode(5); + root2->right->left = new TreeNode(6); + root2->right->right = new TreeNode(7); + root2->right->right->left = new TreeNode(8); + root2->right->right->right = new TreeNode(9); + + std::cout << "Level Order Traversal: "; + levelOrderTraversal(root2); + std::cout << std::endl; + + /* test case 3 + * 1 + * 2 3 + * 4 5 6 7 + * 8 + */ + TreeNode* root3 = new TreeNode(1); + root3->left = new TreeNode(2); + root3->right = new TreeNode(3); + root3->left->left = new TreeNode(4); + root3->left->right = new TreeNode(5); + root3->right->left = new TreeNode(6); + root3->right->right = new TreeNode(7); + root3->left->left->left = new TreeNode(8); + + std::cout << "Level Order Traversal: "; + levelOrderTraversal(root3); + std::cout << std::endl; + + return 0; +} + diff --git a/labs/11_stacks_and_queues/levelOrder_sol3.cpp b/labs/11_stacks_and_queues/levelOrder_sol3.cpp new file mode 100644 index 0000000..5d8dae5 --- /dev/null +++ b/labs/11_stacks_and_queues/levelOrder_sol3.cpp @@ -0,0 +1,126 @@ +#include +#include +#include + +// Definition for a binary tree node. +class TreeNode { +public: + int val; + TreeNode* left; + TreeNode* right; + TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} +}; + +std::vector> levelOrderTraversal(TreeNode* root) { + std::vector> result; + + if (root == nullptr) { + return result; + } + + std::queue myQueue; + myQueue.push(root); + + while (!myQueue.empty()) { + int size = myQueue.size(); + std::vector current_level; + + for (int i = 0; i < size; i++) { + TreeNode* current = myQueue.front(); + myQueue.pop(); + std::cout << current->val << " "; + + if (current != nullptr) { + current_level.push_back(current->val); + + if (current->left != nullptr) { + myQueue.push(current->left); + } + if (current->right != nullptr) { + myQueue.push(current->right); + } + } + } + + result.push_back(current_level); + } + + return result; +} + +void deleteTree(TreeNode* root){ + if(root==nullptr){ + return; + } + if(root->left!=nullptr){ + deleteTree(root->left); + } + if(root->right!=nullptr){ + deleteTree(root->right); + } + delete root; +} + +int main() { + /* test case 1 + * 1 + * 2 3 + * 4 5 6 7 + */ + TreeNode* root1 = new TreeNode(1); + root1->left = new TreeNode(2); + root1->right = new TreeNode(3); + root1->left->left = new TreeNode(4); + root1->left->right = new TreeNode(5); + root1->right->left = new TreeNode(6); + root1->right->right = new TreeNode(7); + + std::cout << "Level Order Traversal: "; + levelOrderTraversal(root1); + std::cout << std::endl; + + /* test case 2 + * 1 + * 2 3 + * 4 5 6 7 + * 8 9 + */ + TreeNode* root2 = new TreeNode(1); + root2->left = new TreeNode(2); + root2->right = new TreeNode(3); + root2->left->left = new TreeNode(4); + root2->left->right = new TreeNode(5); + root2->right->left = new TreeNode(6); + root2->right->right = new TreeNode(7); + root2->right->right->left = new TreeNode(8); + root2->right->right->right = new TreeNode(9); + + std::cout << "Level Order Traversal: "; + levelOrderTraversal(root2); + std::cout << std::endl; + + /* test case 3 + * 1 + * 2 3 + * 4 5 6 7 + * 8 + */ + TreeNode* root3 = new TreeNode(1); + root3->left = new TreeNode(2); + root3->right = new TreeNode(3); + root3->left->left = new TreeNode(4); + root3->left->right = new TreeNode(5); + root3->right->left = new TreeNode(6); + root3->right->right = new TreeNode(7); + root3->left->left->left = new TreeNode(8); + + std::cout << "Level Order Traversal: "; + levelOrderTraversal(root3); + std::cout << std::endl; + + deleteTree(root1); + deleteTree(root2); + deleteTree(root3); + return 0; +} + diff --git a/labs/11_hash_tables/README.md b/labs/12_hash_tables/README.md similarity index 99% rename from labs/11_hash_tables/README.md rename to labs/12_hash_tables/README.md index 5a35b2f..7cc6357 100644 --- a/labs/11_hash_tables/README.md +++ b/labs/12_hash_tables/README.md @@ -1,4 +1,4 @@ -# Lab 11 — Hash Tables +# Lab 12 — Hash Tables diff --git a/labs/12_hash_tables/a.out b/labs/12_hash_tables/a.out new file mode 100755 index 0000000..de6db89 Binary files /dev/null and b/labs/12_hash_tables/a.out differ diff --git a/labs/12_hash_tables/find_max_average.cpp b/labs/12_hash_tables/find_max_average.cpp new file mode 100644 index 0000000..a947f79 --- /dev/null +++ b/labs/12_hash_tables/find_max_average.cpp @@ -0,0 +1,90 @@ +#include +#include +#include // For the assert function +#include + +double findMaxAverage(std::vector& nums, int k) { + double result = INT_MIN; + double average = 0.00; + int size = nums.size(); + if(k>=size){ + for(int i=0;i result){ + result = average; + } + } + return result; +} + +int main() { + // Sample input data + std::vector nums1 = {1, 12, -5, -6, 50, 3}; + int k = 4; + + // Calculate the maximum average value + double result = findMaxAverage(nums1, k); + + // Expected result (you can calculate this manually) + double expected = 12.75; + + // Compare the result with the expected value + assert(abs(result-expected) < 0.0001); + + if (abs(result - expected) < 0.0001) { + std::cout << "Test case 1 passed. Maximum average value is " << result << std::endl; + } else { + std::cout << "Test case 1 failed. Maximum average value is " << result << std::endl; + } + + std::vector nums2 = {5}; + k = 1; + + // Calculate the maximum average value + result = findMaxAverage(nums2, k); + + // Expected result (you can calculate this manually) + expected = 5.0000; + + // Compare the result with the expected value + assert(abs(result-expected) < 0.0001); + + if (abs(result - expected) < 0.0001) { + std::cout << "Test case 2 passed. Maximum average value is " << result << std::endl; + } else { + std::cout << "Test case 2 failed. Maximum average value is " << result << std::endl; + } + + std::vector nums3 = {6367,7359,6636,-7632,-1837,8671,-120,5528,-6733,9942,-1645,6728,-8842,-3094,-4176,-1847,-7154,6727,8100,3499,-1405,9549,2182,-6982,-5991,8426,2386,1766,4634,-3853,4256,4317,3218,7265,-718,-4970,-7607,-681,-9271,3802,-4154,9127,-4683,-9447,8960,-92,-5367,5523,3959,-9499,-3988,3885,-4833,1937,3642,-1247,8612,-7064,-7463,-160,5813,3945,8240,-7738,9004,8126,5122,-3742,-4623,8624,254,5379,-6462,-2755,2072,8906,-474,4945,659,-2501,7944,-569,8630,2351,7266,7688,-1847,6691,-912,6486,7679,-9886,5018,3109,3047,-2827,-8058,4829,-181,3910,5892,2650,-5304,6275,2366,-9294,-3150,-4963,-5204,9810,8976,-9576,-6255,3840,-7034,-7209,-7626,4386,4260,-1590,3296,-7576,761,-2779,-464,7013,-5937,-9744,9626,4455,3806,-9253,6002,5544,9320,8123,5798,6177,-2259,6133,4423,-4002,7308,4975,-9908,-7345,4317,6300,2827,-5471,-5018,-5081,-8863,-5704,9931,5518,-5326,-8039,6144,-1255,876,-8377,595,9482,4650,9795,-807,8198,-3745,5686,-641,4151,-4824,-8493,3189,8268,-4142,-5511,9638,7891,-7972,7366,3378,-1639,8996,3299,-8189,4047,-7873,5861,9264,6289,-7305,-3178,1946,1369,4107,9106,9482,6322,4691,-7415,-776,9773,-6435,55,-8745,3926,1956,-9243,-6655,2393,-3927,5690,4643,4913,-8828,7389,-6980,8272,-5054,801,-8791,-4928,6837,3897,327,-9632,-7504,9129,-1157,1411,8873,3692,5212,3813,-3051,-7528,4430,-8301,-8967,2249,-40,8289,-6822,-1374,5829,-6224,8626,2408,874,7423,2290,-2957,3446,-9939,4138,-4899,3223,-8787,-849,7523,-6895,4590,8537,-9893,5561,4199,6351,8247,2668,1928,5102,-5384,5234,7036,-2637,6552,-5917,-2154,6325,-1962,2216,5542,7811,-3784,-8934,5623,1406,-2211,1091,3877,7245,-4354,386,-8516,9235,-5117,2110,5949,7268,126,4547,7318,3422,-1943,-1719,-4234,-7173,5303,6472,-1774,285,-3081,6090,-4378,-5739,6481,6733,-726,3229,8918,-4346,5148,-5558,-1330,-2078,-3763,-569,-7356,1133,626,9697,8501,-1573,-1746,-6810,-8247,5137,-7223,-9274,-2408,-2781,6232,-5005,-3637,4793,8605,8198,-2449,-7110,-6492,-3113,5666,6894,-2938,-4651,9134,8592,6177,-6860,8148,1432,871,35,1438,8713,-3406,-9444,7889,9854,1701,-9538,-7729,-28,9086,3917,-1334,9871,-6885,5748,3451,9075,7439,3308,-3874,310,-649,6384,-4685,6913,-5504,5471,8843,995,-1704,4195,-170,3271,5610,-8154,5693,-2738,-8565,5264,-9282,-9559,6541,4935,8069,2715,9698,-3412,8840,755,-7438,-5785,-3567,-1634,-7517,1939,-6574,1925,-3910,-1427,-8132,6721,-5655,623,7122,-6952,7246,-5941,571,-6191,5005,-9494,-4467,7141,3931,-5846,706,-3300,-2872,-9525,6576,9407,-9476,6274,6190,7272,7312,-6321,-8279,1822,7889,1596,5572,408,558,427,6599,-2892,-7629,-9621,9803,-1742,-1790,4306,-1480,-5905,-6379,-8941,-7137,-1754,-8663,599,-4667,-2835,-1970,-407,-7003,-9156,-1413,-7845,1182,-1555,-4069,535,-85,714,6509,5909,-29,6800,6887,-7316,-3764,5202,3909,-3465,-2427,6630,9726,8787,7154,-3611,-1991,-583,8466,-3964,2122,4724,9032,-6711,-7207,1277,8583,-8005,-2159,1141,-5477,887,6947,6032,-7801,6380,2308,2083,366,5769,9561,-1515,4577,2877,-8691,-3555,8004,-2741,5080,-4237,-1461,8250,-6114,-9523,2731,-5694,7674,5486,8530,-4296,-8324,-9333,-4094,-8846,-5704,-608,9422,2897,-3995,7829,-6495,9170,-9683,9271,-5529,1153,-8330,-5193,751,6387,-2616,-8293,-7220,-4172,-3513,4849,-4308,5062,-3485,8220,-8727,8187,-4552,3842,-9289,-9344,3923,839,-6484,-3127,-3544,3101,2703,4014,-5937,-616,-2949,-7999,-5505,-2117,2308,-5532,-9775,-6464,8565,4395,3824,-1708,5569,2472,-7145,7508,-2613,1928,-1332,6263,-5570,104,6962,1194,-631,-2205,-777,8166,1686,6942,3803,-6671,1608,5323,-2135,-9349,4109,7714,-9802,-8484,-9911,4001,7950,160,836,-5583,-9809,-4840,-506,2649,3585,-4016,-3174,6063,8555,2470,-8797,-7612,8910,-1240,8077,4902,-7179,8623,8633,-579,708,1486,9872,-7130,1087,1787,-8936,-6772,2386,-4502,4355,-605,-9803,-3844,-8704,1796,5846,6034,-8443,2430,3378,-5541,-3645,-2926,-8004,-581,-8478,1944,-4133,-3806,4305,4225,-6677,-2803,6422,3971,6657,-5626,8538,-2822,12,-5155,-6637,2864,3013,3478,3524,-2232,-345,5056,8427,2627,-6556,-3344,-7226,-7895,-6514,8382,890,5611,5846,-4790,-8011,-9610,4941,-6062,7897,1002,-8429,-9747,-4271,-9257,5064,7993,-5259,-1760,6557,-5149,-8899,1114,-4889,2763,-6369,-476,9150,8950,4202,5286,3568,-9527,3849,7251,2846,1372,5632,7313,-8315,3263,-4289,8672,-8609,-5113,-2345,-7327,6660,-2011,5457,1622,2530,8809,-9874,8160,-6310,2957,1489,275,6771,-3835,-1452,6565,-9960,2159,-3322,7202,-599,7988,-6111,3907,1964,-2482,-6316,-5030,-3758,-8786,7678,-3681,973,-9776,-5030,5936,8269,-519,-7950,9352,-4032,-6739,9940,8260,-5823,-5565,-3930,797,7618,-8210,4254,2903,7350,-7191,3924,5706,-6211,-5538,-5726,-7754,-631,8684,-5530,-2491,5096,9230,-7148,-7764,-9226,-9306,-2816,551,9316,-7228,-7762,3987,-8150,4967,6439,-2520,7746,-4769,-8373,2346,-1337,50,-4220,-9014,8647,-8486,-2126,7042,-3241,-2471,2656,-3927,-5140,-1174,-5170,9853,2470,6793,-8713,-6593,-9430,7308,1125,-6021,5039,8840,3761,7608,8187,-4279,5086,2048,-6394,4801,-2620,-8525,8211,-9791,1026,8492,-5024,-9991,5313,-4575,-9714,-2093,3654,-4225,368,-4246,-5071,-1747,-6083,9689,3839,-5277,2561,-8033,-370,-7664,600,-2528,-7903,-5359,9726,-9751,6105,9273,-2340,-7108,9660,1865,6912,-8206,7941,8271,-92,-5436,5939,7867,-3297,-9389,3186,-6477,-7337,2349,7883,-7249,2958,1178,4742,856,5274,7656,7497,-2059,-5161,3197,-3925,1136,7589,-7713,-4813,-1481,4510,-4748,9195,-8696,-518,5591,1412,9722,6299,6597,8031,5960,7988,-7294,4234,-445,-5281,2574,-2839,-3860,6934,-7804,-4328,-673,-7294,-3728,-6449,-7666,-1147,-3225,-623,899,7881,776,8596,7819,-8184,-6369,-7653,-8052,-9355,-7793,-9604,-3255,-5718,-7031,8116,3435,-5340,-5567,5169,-6284,-2732,9680,5864,5243,2283,6390,9591,8703,-4503,9482,-7633,-9275,5623,-300,-5110,8500,-9472,-8966,-1046,-8323,6164,-7420,-4103,6664,3624,-6896,9877,5961,9357,-4008,3369,5333,-1237,-4790,1374,-750,6010,8509,-3510,3336,-7909,-2468,3711,-3687,-1393,-3705,-1977,-3665,-3458,-3461,135,-7542,2807,-3365,-2488,-6166,2833,9948,3912,-3823,3111,2489,4390,-9996,-5215,9345,-3118,-4347,-7024,4874,-2780,-1552,-1657,7957,9281,-1444,8465,-9289,-7803,9448,7861,927,-5952,6720,-8321,-6287,8827,5230,-3943,-8534,2235,6735,7833,-2979,8867,-4435,7078,8973,9804,8809,-9668,-3464,-8894,2653,-7650,135,4071,1292,7197,-5121,1727,-4433,7533,1100,4363,-6788,-2975,3741,-2194,-3552,1671,7220,3717,516,3249,-7953,9035,-9174,3835,-734,-8932,-6972,3421,-9210,-8267,8583,2384,-3445,-6881,-7589,7646,4675,-6508,-6108,-9592,-2737,-4677,-2885,-3248,3057,-1741,-3280,9272,2493,8565,9508,-373,-5431,4030,2765,4359,-4523,3813,1185,-3597,-8797,5377,2201,5379,2151,-5703,-5872,3217,3693,5148,1583,6772,9698,-5529,6915,5377,-2123,-9838,7759,-1773,5760,2971,-1343,-6149,-1528,-2315,-8198,8961,-5476,-1368,-8028,4728,5248,-4675,-6953,4301,5229,-9916,-6148,-1663,6535,3550,9346,-4925,9356,8697,161,-1281,5169,-2904,-5389,5703,4773,-1427,2802,8814,402,6801,1038,7950,-7465,-7952,-7222,3332,4528,-4599,8939,7385,-4225,-5886,-6030,-1309,-9059,7045,-8208,-2562,-9100,-2010,-3323,-4914,-8613,6999,8123,4619,-1813,5048,-3106,-9879,8543,8983,-699,-572,2851,-5288,878,-8546,-6009,-5227,-9116,-5867,-69,-4466,-1281,-7881,-2737,9725,9854,591,1610,1410,835,-6051,-4156,-9825,7795,-7872,-1745,-5556,-9952,-8324,-7429,-1018,-2441,7286,1878,7206,-465,8547,-380,-5148,7646,-3772,-6009,8946,-5161,6176,-122,-3088,7784,1514,9894,722,2636,-958,-9405,-7431,9774,5703,1632,-1152,3689,-8032,6073,-9131,-420,3576,7931,4566,-2952,-9024,88,9035,-4260,-6556,5726,7421,9949,-8137,7934,9856,5018,4139,8752,-3494,-3483,-2716,-1356,7896,-4715,-7732,-5021,-188,6637,3368,-9539,-9979,171,6155,1053,5155,6251,3480,966,8306,-853,-3154,-8030,-9331,-3329,8594,-4543,3798,3223,9987,5284,-5586,501,-4040,-5972,4204,-2211,6862,-6047,-5568,-1088,-5669,5428,9201,6475,-6269,-8104,-4847,-9754,-8445,-5533,5258,7604,385,1445,1800,8853,2558,4881,-4513,9152,-1352,1146,6289,3718,-8761,1545,-4161,-469,-1988,239,-8524,8862,-9740,1125,-1801,-223,-2349,6419,2890,112,-8606,-7073,1968,8510,-4286,4977,-8264,-6789,-6813,-4021,6007,-647,-7061,-4734,-593,-986,7921,9388,1158,6132,-317,-3514,-5032,-8734,-4648,3124,-6727,-4453,7557,3407,6074,9700,-3204,-8699,-376,8028,-2307,127,4499,-2771,9605,-8154,5185,2175,3672,-8167,-5683,-6143,8246,2633,312,5332,-9316,-3345,3962,3158,1975,-7001,-5548,3434,2035,-5922,-3617,5035,-4650,9485,-1506,3301,-4651,-3890,8509,-2120,5049,-1683,2055,-759,6225,-5640,1721,-2238,-1010,-6530,-6845,-4674,-2142,-9086,6148,-7536,3037,9334,4415,-9565,-5962,-7090,-1892,-6186,1304,163,7233,-9909,-1342,5112,-9940,-1182,-9145,-5544,-6667,570,-4388,-5560,-7571,9406,-3290,1825,-4923,2396,1311,2867,-5671,-9730,-264,-961,-4337,3385,-8769,8515,9278,5085,-3095,7156,7003,-7245,3304,-1171,-192,598,-3084,-6799,-2275,-892,-8730,5540,-1142,-4757,5696,289,9651,9995,4616,7714,-1016,7160,6524,-9524,-2207,3579,8506,-4156,-3284,-50,9076,-7443,-7507,-1315,4902,-9229,-3892,-3679,1352,-4392,-3736,8021,-6299,7065,-1982,-6956,-7559,-222,-1235,-476,2083,-78,9126,4500,-5780,7447,-9734,-5891,9423,8501,-6099,2045,-2423,6830,74,-1248,-9661,4486,8759,6428,-7030,-2436,9836,2623,5196,7658,6988,738,1526,-4678,-325,7189,-4424,9376,-3153,1284,-9366,6801,1418,-9786,-6089,2880,9345,-4703,-3050,-7859,2706,9503,-3968,-6364,5006,5846,-294,-696,-816,-316,-4561,-147,-4889,-7840,3961,-4489,-1931,-2498,5484,8278,-7933,7493,682,6159,7406,-422,-7328,-3778,7494,-5747,5830,1773,-546,6552,6140,2722,6974,-3225,9110,1989,-6027,-7503,4897,-9583,-2146,8463,-4016,-8615,-5896,1437,-3183,4299,4502,7671,6461,-655,4858,-2755,8975,2634,7102,-106,-3177,1726,2868,-364,-8758,4532,6574,-6910,6249,9542,7047,-2800,-7888,-1804,3157,-7347,-1153,8055,3515,7754,-1204,3222,-5585,11,-9755,2050,2177,6718,9779,-1878,7349,6190,980,-7579,7614,-4597,2347,8603,-7953,6776,1646,-6985,584,2101,9037,8596,9436,6697,6856,7497,9322,4402,-4511,7508,9206,3287,2217,1954,314,-2267,8620,-6988,692,-7775,9347,3031,2433,-2619,-4937,-2575,-9839,-2209,4505,7686,1806,7251,-5475,4627,-9692,-3901,6733,-2744,-2880,-6691,-6137,-8688,7636,-8087,8017,8438,-6660,5255,9397,2151,-8372,5632,9288,-624,-4360,6351,715,-449,2819,6360,294,-4806,395,-847,-7679,121,-8119,6928,-580,6474,-5473,-1167,-6706,-2099,1198,2795,2922,-2378,-8731,-1411,-7635,8069,-8597,5604,1278,782,1638,-8404,-6492,-7554,-7716,-4360,7790,6323,4217,3199,-7081,-5037,-1683,1510,-2944,6918,828,-5724,4682,7169,5205,6931,1335,-3908,6938,5151,4246,-1546,2711,7860,-4923,-3328,-5061,-7750,9298,-8563,2665,7842,-5454,-2264,5514,3631,-8110,643,-3661,-1907,1625,-7396,2038,7123,6051,-2358,3861,8264,7425,-1574,-5342,7816,-2384,-3763,-6192,-2151,-3514,6901,-5381,395,-5214,-9689,-5984,-8005,-4772,3082,-3218,5702,-7593,-7102,818,-6256,-7707,6864,-5234,3666,-5131,-80,9577,-1794,-7786,8292,-7312,6068,4618,-4010,1911,-2466,-8165,2238,7041,8641,-9919,-5761,5619,-5980,-1880,-2641,4392,8449,-208,-825,6981,-8062,-5160,3281,2385,3116,-909,5617,19,5274,8685,1264,-9776,9261,1639,2805,7656,-5900,-4479,3811,-2375,4018,-1368,-3506,-7225,8058,-1089,-6484,-7286,-6505,-2372,955,-4938,-2608,8493,5466,1198,-4057,3207,9735,9458,115,-681,-7862,-416,6412,5492,-9308,-1166,-8657,-5668,-8542,-3298,6867,-7737,8661,9256,-8941,-5658,-4813,-3702,9143,1404,-424,-3076,382,-1393,-9575,-4608,-3656,5380,-6405,-7681,-8505,-1088,5059,925,-89,3690,1656,-8603,5215,7051,-8274,-5378,-1625,-1611,9376,7785,-9647,-2376,7898,-820,3418,7309,-1787,9830,1390,-7642,-792,-4953,-3959,-4887,6169,-8707,-7925,3891,-9141,1462,-9425,-727,-2988,-4291,8933,7496,8070,9399,2191,-2029,5021,-239,3602,297,8769,4913,-9728,-1723,-1571,-857,-9102,-3802,-5171,-7502,4097,-2677,4896,-1956,-8885,-2359,7454,4159,-4327,-3564,-1725,5530,-6970,3314,2826,5860,9282,-8948,-7643,-6165,5269,1111,-5212,7477,8243,-9366,-5985,7753,8603,8453,8190,-3164,-6565,3779,2678,-6163,6701,3878,-8038,-3743,5799,-9320,915,-1625,8676,6518,8042,8026,5942,-9729,-3589,2849,-9943,9898,-5934,-9421,-3073,591,-3918,-8391,-871,-2897,-3663,2566,-4947,-1887,-6528,-9027,4372,3016,7013,-6019,6900,2014,-9685,2098,-9652,8626,-3304,-1396,4243,7248,1677,-1492,-3301,-8854,7786,-3793,3109,3390,7482,-3955,-5231,-85,6006,-9549,5573,646,8215,5068,2277,6221,-9507,7567,7584,5275,7047,5246,-6364,786,-8936,1032,-3451,930,-743,-5314,5269,-6042,8467,-1269,2721,-2182,5675,-167,1553,-4437,685,-7831,3433,-1762,1235,-4789,9608,542,8701,-1935,-8679,-956,4558,9366,6543,-1175,8938,-6627,-3639,-7201,2678,3198,-3983,7227,-3746,6338,1861,-5965,7001,2781,-7950,-8372,1733,-4673,-6987,-6771,3346,-8839,-4146,-906,-4623,2843,6950,5201,-9286,-4528,3207,2810,7203,-3229,615,7602,-8722,-34,2162,-3420,-8990,2670,5892,-3127,-4036,-9416,-3310,1073,4812,5985,8643,8087,-3339,-927,-3342,-6558,-1359,368,3643,6097,5754,5135,-2515,-8563,-770,-7799,42,1644,-7851,7602,8959,-3003,-5226,-3497,-3199,1978,-3283,6640,4940,-642,-9597,6931,-6529,-4966,-512,-8133,4740,9132,-3028,-4551,7033,-6240,-1574,7820,-8801,-1231,-3670,-3072,-7612,6529,4728,6995,-4417,-8721,-2412,540,6743,3831,1791,9116,-9239,-1835,4708,9477,-9176,6288,-8223,9473,-2828,-880,1464,-4329,9816,-5985,-6371,2459,4373,1978,6560,9923,4388,4798,4635,-2558,1578,5923,-7912,-9518,-3483,4487,-3407,8329,2939,-6378,-3590,-6931,7100,-892,6761,-1895,-8885,4006,1390,-6489,61,-612,-388,2995,5910,4877,7355,-3716,1745,-6326,-1197,9983,-9220,4890,3282,-1861,-6431,8345,-4914,1630,-7053,3551,7386,9254,768,-4904,4645,2365,7735,-8807,2353,-9048,2784,-7744,4543,590,-210,-4788,5176,-1689,2107,-5270,-3757,-1153,9590,972,-7984,5039,1668,2100,-8207,774,-617,1029,3902,5363,-8621,-8605,-4912,-8534,-8935,-1327,-7732,1654,7766,-8443,8415,-8943,-9455,5431,-9336,-9009,8480,1497,8226,-2012,6483,2722,102,201,5942,4893,2564,2273,-6591,-3925,-343,3303,-595,-263,4895,-4566,-1458,-9565,9213,-1559,-9633,-6039,-9552,-1130,-5725,1816,5864,5238,-62,4099,-2590,1023,5171,-5720,-2421,-8052,3834,8807,4614,-5205,-3852,-8341,353,-9549,7904,4269,-1515,-630,-7140,1432,-3563,1064,2587,-1139,-9825,-1328,-3758,6830,6713,9029,6663,3421,4678,-3856,4916,-7270,-1739,5208,7244,-7131,5859,4040,-6929,76,-9681,-3473,-2590,9565,-5924,-6587,-2334,3918,3999,-5646,-6783,8384,-2091,162,8481,-6233,7845,-6668,2239,6047,8198,7342,-84,-7002,-2371,-128,2517,3728,-3911,3153,-4760,5864,7711,-1524,1980,6023,5181,-595,-495,-8071,1648,1172,8980,9012,-4909,-3524,7765,7832,-9726,-3809,-8241,504,8739,3058,-8892,-7951,2545,-4716,9978,-7215,-2693,-9739,145,1705,3180,7602,-9109,-3575,-7784,1212,1737,1314,7409,2345,9046,-5178,-523,-2291,1010,-9261,-4151,-7496,-8344,9806,-8355,2541,-5343,-5173,6534,-5435,1272,5906,8752,6171,-9652,-1527,8493,-495,-8121,258,1013,-8530,4489,1342,6143,4213,9625,-7063,5370,1315,-3773,-891,-7321,5375,-44,-9476,-5725,-2364,9021,-9086,7787,-3491,-6795,-323,4195,-4771,-1734,9943,5609,-7338,4239,-2604,-8018,-1324,7979,-2203,6019,-711,3789,-4544,8255,-9644,-9186,8841,-2762,3215,2060,4958,-5002,-6514,3597,2839,6964,-1959,5438,5898,-3873,3927,516,3412,6853,-8950,-7284,-3385,-119,7094,753,-4792,3046,7019,1328,-9422,-7253,986,-4279,6177,-121,2990,4237,-1461,-8868,9098,2880,-2544,4863,-3759,4065,2159,-710,-5432,1416,9435,6302,-7064,9662,9906,-4845,2578,1206,9578,-3812,8267,-207,5840,-3650,-7082,-9064,7389,-2582,4697,-7031,-135,-2782,770,-4029,-3363,-6907,-7903,-8572,804,-9003,2299,746,9473,5839,-5234,-1423,9785,-5927,-5299,6723,1704,-3135,-3734,9751,-7101,9580,5182,6118,9080,-4798,-1497,4987,-5415,8869,1416,6951,-3351,9629,-3063,-2840,7782,-3826,-3636,-3968,9777,1166,765,-3395,-9919,-869,-8535,-9247,3939,7342,2585,-1355,-6001,7681,-3727,-1728,-4696,1078,-7523,-9,8282,2469,-8162,1685,-1351,-1124,5691,3642,-1682,4683,7003,2710,-100,1732,5312,-3604,-1356,-5870,6350,1377,-8452,7150,-5463,-5785,-1647,-3428,-9172,5232,1218,2173,-808,-6706,-9304,-6919,1662,-6040,-1335,-5929,4833,-5271,-4937,-8158,3929,4615,1266,1306,9516,-1145,-1600,-8860,-3833,-465,1861,2291,1173,5955,-393,-6830,9887,-9830,9284,5790,-2737,-9064,5794,-6241,-6822,4924,-7520,-3473,-9927,5919,9807,4282,-8998,-1256,864,8879,5889,-8133,-7393,3746,915,-8171,9947,8068,-8413,1171,-8498,-1559,229,-7382,-2789,15,-7164,2299,6424,-2012,-331,-7988,-1614,2618,-1539,29,-4946,-3592,-4479,-8947,1447,-8528,-5019,1693,-1912,9665,-9891,-3356,7224,4014,-9409,-6683,-7277,-9709,-1376,2970,6502,-4430,-5598,-7322,-4874,6813,9694,-9683,-8585,-9405,-6577,-6344,3332,-9607,-361,8742,-3755,7601,-8920,427,-3015,-1714,-8584,-8637,-4263,-4579,7393,-5177,3249,5946,7200,6447,4458,5825,-9166,-3857,-5091,4143,-1917,7336,-2574,8694,-9617,-4208,2238,6141,-2018,-7723,-7510,2768,6620,1578,850,9060,-3190,5482,-8561,-9059,-351,839,-3291,9834,5175,6884,-6918,6436,8718,2291,3252,7958,3382,-7420,3409,-9427,-374,-8892,8683,5671,156,-4416,9014,8342,8630,9553,-9609,7630,3488,1534,-4937,-2123,493,3770,-7280,-6923,-617,-2233,-6676,-5861,4877,-8139,7181,-2929,-3160,1416,8595,-1598,-7451,9253,1912,-6042,8015,-3025,-4509,-5082,2886,4424,-2794,-1812,430,4488,-8212,-8109,-6541,2650,2245,618,-2392,-4808,-8792,2925,2,1061,6189,-7958,-7614,7679,6623,3666,-9477,-5020,7335,8175,-9004,6553,3608,-6617,-7489,-697,-9767,210,-8123,7457,-2792,6279,-8672,-4245,-1427,-4946,1079,8529,-4718,1566,-799,16,4688,255,-9942,3092,-1635,-9161,-1669,-7606,1788,9784,-2936,-6472,-3834,-1146,3884,9498,-6773,-8156,-3100,5428,-8077,928,4004,-3344,1236,8111,4944,9820,-7137,2246,-8513,-2746,-3966,-755,6755,-6121,-4476,7109,5312,2276,2801,-7174,9421,-3060,-3785,-2634,-9296,-7351,-408,596,-3389,-4480,6181,-6488,8824,3491,8180,4762,7557,-2191,-475,-2224,996,-3644,-7356,-8379,7714,7846,-4087,-554,-5740,-1561,-7182,-8858,3321,-439,3435,8213,-8986,5374,-4706,-6033,-278,2259,-436,-4784,9983,910,9878,6594,3488,-2685,-2502,2369,9670,-7605,-6629,1282,-7825,-8078,8117,-7149,-3863,-3826,-2312,-5864,-4092,6364,7896,8448,9421,-7779,-357,-5953,1042,-2501,-8758,9613,3166,1010,3399,6729,-9848,-237,9691,-2602,9577,-3688,-2683,-1428,-2896,6010,3845,-9107,-5822,-7073,-9648,9816,8886,6708,1815,-6614,149,-6995,-783,3082,-2808,-1443,-6091,-6577,-5274,-4234,5025,2636,-8329,-3213,5647,-462,-684,8787,5463,7690,6842,5467,-4487,2398,3807,-9607,-7958,7886,-3086,-7059,-8438,-863,-9345,7835,-1906,752,-8769,2199,6056,1445,-822,-4823,-4692,-1541,-9533,1611,6291,6033,-5354,2529,-213,117,9581,-9435,-455,-8069,1397,-5697,-1196,-7150,-9754,2474,-9302,5050,5137,-1199,-1546,807,1322,-4152,-6015,-3046,1812,-3390,-493,3139,-121,-6099,-9847,-8446,9446,6337,-3341,2313,8182,-9351,-8145,9495,-6110,2285,9643,2546,-9514,-7264,-4640,2332,3138,-2789,-3428,9859,-6779,-6116,1580,-6131,1445,4048,-5666,419,-7562,-5521,9929,827,-4071,4766,-7750,817,7610,9581,4716,9483,-2564,-9429,-1979,-7624,-3070,6856,-1953,-8278,-7756,1731,7668,-1316,1730,5920,1115,-9951,7345,-8193,-4817,-2379,3733,5114,-4982,7448,-5501,9187,6461,-4404,2417,720,820,8015,-9872,4677,-75,2994,-1583,5424,8679,-7712,-5625,-6281,2656,-924,-3117,5186,-9953,9267,-9361,-6815,-4344,2,-4792,2581,-3565,4714,-3218,-6645,6501,5067,-976,4885,-9032,-9512,-8726,-2316,9327,6630,-7782,-1568,-7684,1177,3128,-1180,-8949,-4754,5604,-4268,-6527,250,4820,-8684,-6713,-8495,-2248,-6142,-2740,-7102,7944,854,538,-7468,4835,4965,-4316,-3941,7381,6130,2876,-5882,-734,-1222,-3344,-6904,-4119,1114,-4157,-2952,-6846,1380,7152,-8455,-3818,8282,9422,2250,935,9092,-8735,-8349,-2835,-7706,-1509,5382,-6614,-5231,468,7580,5842,4171,-7482,3260,-9930,491,8192,-9959,-2381,4504,-6462,1612,-2713,8729,-5639,5051,6565,8460,9245,-8499,-2695,7516,720,-592,-3937,7883,-7542,-3360,-5028,7059,-5720,-2094,-36,4270,-1712,-5882,-5001,6180,9037,7952,3611,378,6911,-3816,-9880,-3790,-2209,2257,1026,-759,1566,-6545,-3075,3914,-6621,5648,5710,1789,5650,-6357,-6930,-5607,2920,2570,-7791,7203,7389,6809,-6565,-5352,5456,225,5648,-5005,-3007,4998,1778,2187,-249,5253,9185,5189,-6098,-4871,7819,2989,7993,4749,-6128,4422,-9019,9290,-1232,869,-9914,1354,3909,-5650,2804,9899,158,3521,5835,-5246,-9927,-5951,1817,9262,-5639,2385,-663,882,1021,-224,1772,-4247,-5879,1449,8680,3078,9418,2019,8426,1673,-7134,8175,-3920,143,-2407,-8654,5025,-5021,-923,-8109,-6987,-5448,4952,3846,-1277,1110,2026,-5627,-6992,-5537,1732,4402,2901,-2308,8880,3999,9608,-9882,-7339,-4237,-8170,-380,-3864,-4083,-1296,-5639,7347,-2598,-3977,-4910,-5807,912,-4980,1260,2827,5763,5174,-623,-2458,-7129,-5967,2643,9721,-2187,7329,-3722,3236,-6062,-4860,-4558,-3724,9073,-5422,8123,-7343,8613,-8148,6858,-7906,-7325,6050,-6466,-3458,9863,-3136,2588,7722,6660,6752,5879,1222,-3050,-5016,4251,-3900,2947,489,4671,231,4794,9015,6038,-572,2331,297,9495,-8597,4576,-9713,8851,-6555,2541,1475,5198,9576,8588,-3545,9925,4257,-1184,-405,-9233,-7409,-1681,-269,9845,9822,-3268,9123,6758,-5552,-8854,-9884,-4412,-5452,727,-8304,840,1512,452,6494,6542,7545,5186,6929,-9257,-8154,3744,691,4530,-691,395,4994,-7979,9611,2271,8577,-3756,-9701,-9943,-8758,-3376,-7145,1604,-925,-4224,-2833,9499,-2333,-4182,-114,-1435,-7576,-779,-587,354,-6673,-6550,-9151,-9989,-5778,-5094,5913,5442,-1800,3505,-1606,4385,2568,-2254,5470,6981,7028,-8156,405,-7485,9626,-3163,3602,-7459,-8997,3900,-5021,-7329,558,1372,4030,2257,-9748,-4282,-4931,-2793,8475,-5885,2150,2601,7090,1086,-1440,7267,92,-237,6027,-3230,-6061,3490,-4886,-4992,-7581,-4318,9630,-4619,5512,5997,-5406,6629,-9180,-5788,138,-1669,636,-5506,-9503,184,-9052,8164,-4340,-6808,-2763,9721,4544,6131,751,-2361,-7396,4267,344,-4472,-6149,-7414,-8753,-771,3429,-3182,-6470,9363,-9117,9977,3128,7406,-311,-4476,4383,-6247,-1258,-1085,7551,3716,-9616,2541,-810,9436,9350,6328,-1773,2279,4083,-6998,3661,2265,-9796,-9025,1219,6428,1340,-5709,8855,-6183,-6311,-6428,-7500,6524,-4454,-6858,-3928,-6564,8411,2754,6952,-187,2214,-8005,-1086,1268,6283,9707,-4445,335,-4167,-3106,6019,-406,7487,2092,9804,1524,4092,8305,3320,-4667,5614,-8439,-4270,1405,7593,-2892,2414,-7342,2946,-3842,5769,2015,-7464,-4321,-7767,-6799,9158,-3130,7937,-8818,-9827,1642,1053,7401,9576,-2902,-3274,-7547,-1980,-7722,-9271,8068,-5740,-8853,-3425,-8649,4388,-5938,8984,-8612,5678,-2333,6935,-8381,-8965,7686,1325,3422,6992,1914,-6043,6036,5274,-4047,-4096,-7685,3494,-132,1081,8766,9524,4704,-4220,-4724,-4293,-6275,2517,-5219,9405,5186,333,-970,3240,-7642,2846,-6306,4524,-8182,3792,1046,5185,6642,-900,624,1842,5328,8324,-2446,-7221,-342,-3037,-3541,2359,9098,8895,-469,246,-613,-809,-3816,5986,9061,8423,6174,9658,2308,5642,-1241,6310,-3475,-2727,1092,6026,-4548,-5706,-2405,963,-7642,-8001,1756,-9585,2879,-8023,7794,-2877,3004,-98,-7019,4111,4692,-3718,9208,-241,6744,7260,-9242,705,9456,-7385,-5232,-9693,-6650,4249,-745,4098,4617,5055,2757,6237,3362,3749,7451,-9080,-231,-4151,7285,-570,-6161,-1004,8053,924,-494,9761,3124,-7032,-9717,8799,4564,-7793,2712,-5867,-3835,4430,7420,-4550,-1936,-4967,-9762,-8968,7517,-5276,-5923,-197,-6318,-5413,-836,3022,8398,-740,-2547,-8910,-665,538,-8148,56,6367,7432,8873,-7390,8236,-7720,5682,-9159,7289,9918,1288,4526,-5552,2248,-9745,5340,4391,-4033,-1360,5741,3627,-2797,-7205,7616,-3179,-9451,-1208,-3850,9101,7657,-4647,946,6247,-3011,-6038,5989,-6670,-9104,-4049,3817,-9585,8805,4397,6205,-5358,9664,-92,-7493,-9852,4290,6116,4100,-5660,6598,360,5115,5674,8088,6117,5277,1782,3428,7392,8735,2846,8422,7847,5762,203,1502,-3755,-4215,5727,4197,-8640,-5209,-6510,-6739,-1299,2033,-8097,2641,6804,5726,203,4909,-7582,-1508,-4304,-4038,-6707,-4942,-7791,5658,-4484,-8011,-2362,-3485,4072,4124,2148,7485,6115,6668,9625,6606,8358,9048,7181,9900,3135,3055,-9083,-6268,2464,8020,5997,-4618,1093,6202,868,-2836,6918,3160,-7408,7343,5236,-8510,3915,7202,-4910,-1373,8833,-2484,-6385,-8081,-1119,8566,-1599,2155,-526,-8690,-7729,-4801,-3400,-8484,7762,1674,-4177,-5435,-7749,-9677,-1687,7413,5986,9109,-8621,-7143,-4696,-3227,-3410,7480,-9812,-5861,-375,4967,2158,7606,1956,8188,-2198,8682,-7779,5670,-6152,-797,3975,-3819,7725,-1835,7771,-1287,7401,-8403,2845,3061,8850,-1542,-8247,7444,6948,9736,1376,9604,-3273,5027,-2765,-9564,-3533,-1926,-5454,8396,-4087,-5940,5237,8133,4612,2586,-2065,6487,-778,-4595,-1918,-4615,6948,-406,-4983,4818,-2184,-9297,-8267,-7184,9730,-8296,-4640,-7650,-6189,-6328,3664,-9939,-6710,-2010,4209,2131,-375,9882,-9048,6870,7058,7051,-4015,1507,-6765,-3088,-4430,7119,9970,2770,5227,-1523,5032,-1811,6028,-8873,3077,-3375,-6715,-5654,-9426,9527,421,-3654,4537,-3779,6197,-5357,-7886,-3868,-8221,1261,3886,7315,4715,1709,-1282,-9101,-6884,1229,2977,-7979,-2081,-6012,7641,-4931,-9717,1150,33,3455,1842,-1920,6998,-6005,6055,-8034,-3252,2077,2161,5578,-1142,6675,8431,5761,948,-2928,-1112,-3953,-5271,3996,6230,-278,-9226,3579,-9639,1328,-4410,758,2499,6163,3453,6819,-701,-2253,9622,-645,7650,-2313,275,-8049,-8781,5340,-1820,-2306,601,-8014,4476,-6600,-9497,-8873,5532,9546,-4301,-1250,-3010,2182,6619,-1920,195,2273,9292,-270,-2146,-319,-2138,1079,4375,-9165,5995,5813,2350,-4623,-1202,1473,3542,-6176,-314,3245,-202,-9179,-7470,-1802,-9234,-4103,5390,-4185,1759,2638,-5790,-8323,-4264,1716,-8427,7564,1861,7555,1692,8186,7079,-7050,2007,-2400,9646,6927,-215,-9357,7634,994,9283,6489,9129,7980,-5931,-5495,4906,2584,-3875,6231,-7730,-8153,4614,-9922,-2036,1431,9711,2688,-3321,1251,-2822,-4119,8041,-3030,9765,846,-3499,-5691,-599,-2009,-4126,-7799,9689,5531,-8896,-9993,7877,2653,-312,-9220,-8058,-3845,7898,2805,6994,9131,2337,-5587,3755,-972,3068,-9042,-6458,2716,8704,-3917,2594,-9989,5870,9248,-509,4655,-8975,-7619,-1738,-6158,-4713,-1357,-4259,-68,8225,-9706,-2997,-1578,-6196,1647,947,386,-3362,-1721,-3428,-311,8326,-7225,283,4212,-5375,4925,-6580,4545,-5690,3575,6163,-3428,9203,9073,343,1329,-5126,8138,1591,2076,3497,1452,8746,-6262,2291,1331,7578,-3875,-7705,3831,4237,8871,3574,6493,-592,-5923,6616,-799,-181,4920,8361,-6100,7580,-8712,1878,-4879,9458,9924,2251,-7145,4287,8396,1897,-3473,9734,270,-986,5501,8138,-2707,7984,7568,-7170,-7504,9706,-654,9491,1301,5322,-6146,-7206,-9446,3875,-6052,-3735,-7146,-6443,-2309,-9040,-933,-4290,6982,-4522,4793,319,-7841,-4542,-2309,1347,-3348,2735,-6895,-3354,1601,-1224,-5483,9966,-539,8562,-9436,8488,-5028,5125,-3524,6519,9036,-7489,7275,410,1485,-3328,5819,-9487,-1596,-3171,6839,3404,-4639,5209,-319,-4317,-7006,956,-6796,-320,6114,-6844,4767,1501,1518,-7169,-7418,-9814,-9165,-7786,4687,-6790,-6122,-7917,9294,-714,1781,-6410,-6321,6232,-1842,6974,4856,2187,-8356,3471,-4683,-9093,-1907,7366,9737,1807,3086,-9326,-7507,4684,6736,-9588,1561,-9611,-5287,-3478,-639,-1186,4251,-2590,-4051,1529,-4806,3309,3252,-5918,-2855,949,8155,1713,-8234,5145,-9927,7428,-103,-3351,-4914,3186,9293,864,1815,-8532,7344,2064,9195,1205,9364,-8702,7638,-9325,1424,-8861,6899,7352,-8327,-1098,1102,1349,-16,-8409,6017,1072,-3207,-734,-3195,4594,9408,1586,-6378,-5296,1165,-1872,-1306,-2514,8867,1528,5222,2482,4777,3271,-6185,-3205,2094,-8005,4757,7337,998,8967,-5730,-313,-9390,-3709,-6977,351,-4267,3426,7407,752,-350,8559,7407,5027,1868,334,-5137,8535,3495,611,8865,1057,6763,5111,-1827,9953,4449,-1612,-9818,-5014,-3156,2878,3003,1883,-7410,-5507,962,3761,-6977,7632,-4584,9851,-6108,-1719,418,4758,6520,-5681,-6283,9374,963,-5927,2392,8872,4742,-8708,6759,-401,-5894,2666,-1961,-2985,5865,-1376,7234,7161,-6483,-2646,2926,3743,548,-4691,-1538,-7034,7597,2478,6682,-8367,7529,5087,2183,1499,3786,-4092,-5987,1221,2290,1674,3552,1006,2266,-436,-6088,3051,-7040,-7339,-6876,9660,-6928,-8057,-5288,1668,-283,-6320,-605,-3138,4442,-5406,4208,8762,6430,-5911,1076,-6781,-1927,4272,9802,1482,3496,6452,-1036,-7998,-1063,2909,-4268,-1936,-2225,5377,6378,6856,-8145,-8903,-2207,2763,-9967,-5864,-2370,900,2940,-927,5582,5050,8059,957,8114,-2862,-7002,-4785,-8115,1045,-3974,-7434,-305,-6092,-8224,8549,3453,34,1098,-8163,-9079,6136,2146,27,-6103,-1796,-329,5009,-4467,4613,-264,107,9855,-1659,-6974,-244,336,8249,5409,-6662,1734,8431,-7914,1886,7910,8189,1686,5181,-2687,7652,-1781,1423,9601,1851,8605,3065,5397,7436,-4029,-7627,-1250,-6385,3642,-240,-2054,-5316,-5631,-6309,-7302,7173,1555,-7207,-5862,-6234,-5918,2236,-1985,3458,1391,396,-8205,-2078,-9351,-35,9941,-930,1773,-5438,-867,-8106,4975,-8069,768,3628,-5465,515,-1191,4038,-6739,9522,1913,-4745,-5215,9144,3183,2084,-1796,-9127,6114,-7626,6264,-5143,-105,4196,2191,-6307,-3407,-677,3944,6238,4532,5951,-697,6609,-3445,6127,6196,-5893,-629,-6649,2618,-9900,4838,6855,-4885,-4315,-1175,6466,-2130,-4262,-6889,-1286,-8390,3379,428,-5919,-7108,6004,1193,-7793,-2352,-3518,-7649,9166,8389,-8040,133,4490,4968,-7569,-6830,-9800,-2299,-1406,8735,9094,-3142,-2955,-7864,-9987,2551,811,8701,4840,9787,-7722,6866,9941,-7731,542,5970,2449,4704,1952,8912,-8158,5005,-4511,-5981,1879,671,-525,5791,-715,-6645,-8780,-2062,-3390,-2709,-1762,9144,6610,-3426,-6123,786,9217,-1221,7275,7797,4910,-5776,-7276,9286,-930,-3424,-8229,-7701,-8762,-4122,-2792,-6896,6769,-641,-5702,8345,-2444,8609,2440,-1013,-6761,-1962,-7703,-6196,-1602,-8932,-1957,4019,6956,-9752,-3944,-3530,8008,-6863,-386,7268,4507,9619,-8953,3093,-724,-2054,-3545,-8345,6609,-9537,5937,714,9616,8658,-7268,2967,-2051,6861,-3508,-5759,-1852,-3966,9610,5100,4438,5939,5292,9809,3074,9837,7655,8854,8683,-427,7368,4450,8956,9909,-7590,5370,4692,1039,-6846,1321,-5066,3423,3026,1384,-3387,4933,8524,-915,-6425,5464,-2730,3857,-8486,384,-8091,294,-6598,6139,-6936,-5624,-2738,8734,-237,6946,-8421,-6385,-5637,-6213,-7907,2901,5167,-2657,7614,-5194,-9476,-2357,1676,-9715,-5699,-291,2992,-2982,1246,4957,2488,1916,-2787,-8985,3099,-3317,-8566,-5379,-2262,4125,5365,5060,9216,-3366,-5629,-5552,-5082,-8239,2618,5824,-8664,9675,652,-5843,-9360,8848,4633,-4703,-4459,4901,4105,-7430,151,-1167,-4546,6789,69,-7763,4516,-4544,-3650,-3756,-5096,-5875,-7313,9372,9062,532,7877,-5511,267,-4993,9959,7435,-72,9138,7346,6686,511,-9883,1005,-9896,3394,-2559,7430,-7465,-8962,-9742,2389,-7464,583,5421,-2949,1582,1602,585,7535,-7394,-8586,-6736,-1149,-3631,-1657,-7414,-5613,-9718,-7271,-7702,-3900,3675,-36,-9646,8370,8153,-3428,-7288,1772,1075,-950,-5018,7196,6345,-5655,-6343,-5999,-6932,-3111,-9431,-8504,4911,-6493,6471,-3665,9048,951,1509,-6774,-7569,-9392,3279,7788,5089,-1462,-7466,68,-2735,2647,4105,2615,-3736,-8316,1086,6497,-29,-5281,8412,-4289,-4343,-5371,-2127,-7762,-5979,3965,-8649,-174,598,9564,-4077,1764,372,-5619,2438,-3183,-7026,-1319,9196,68,-6136,543,-2719,644,1659,9135,3661,-7628,-240,-2834,-8397,-8638,-6464,-5535,7496,1211,-4335,-2691,-2690,5571,4153,24,-989,-1967,8626,3054,1532,-1939,-4326,-2227,-7492,-7032,8750,854,-1182,8914,-5791,1239,9256,-6718,9234,-6850,3307,-6103,-2774,3022,7002,2277,-7046,-2217,-9039,-969,-7154,7759,-3727,6655,8902,1129,-1601,-4935,882,-3190,7179,6565,-6159,-7927,-8106,-1073,-51,7534,-6498,-9060,-1871,-1002,8911,-6637,5658,8960,-9864,-770,-8955,8603,-2199,-6534,5177,-5778,-1684,-939,3037,-1665,2853,9432,9034,8237,1749,-2309,-1006,-6239,9859,-3284,7443,-1415,52,-2281,1729,-9113,-4489,-7452,-6302,-4235,2654,7538,-5770,-4276,3999,-5940,8794,-1540,-3966,-7182,9728,-4484,5914,-4073,5887,1756,-4368,9993,1752,-2891,-3399,-777,7824,-3853,-7282,762,-696,-5484,-7979,1930,-4971,-7899,-6368,-2196,8581,3138,-9884,-6623,6696,-5878,-4401,1719,3882,2283,777,-2790,-3021,5208,4422,6200,9596,5847,6827,-8446,6035,-7954,4430,8640,-1504,3365,4996,7801,-4916,9063,389,6081,-5234,-2050,-7894,3044,7931,3401,5319,-6135,8980,8591,-8549,-1461,-8017,-1697,4579,5462,5906,3171,387,-1646,-241,7391,2990,-8366,9659,-9452,5222,-6605,-7810,9993,5688,-846,-1980,-6435,-623,1776,-6193,6065,-8911,3666,6665,-9378,-1596,5472,306,-5101,-5257,-6252,-9239,-2065,8551,3875,-5910,6055,8735,-6722,4574,-1938,-9077,-3559,-9585,2691,-9387,6678,-8860,6295,7077,-8283,558,2819,2282,2012,8529,-4415,-5716,-1931,1425,-7567,8537,-7601,-9489,-4897,3176,8280,1758,-7178,-7848,-2949,-2716,-7714,-5770,7948,8491,-8746,-1950,7470,6741,-6637,9781,8188,-3796,3185,7703,7115,-8161,-1244,9880,9663,4075,9329,-23,-7571,2424,3769,7605,4012,8298,6803,8348,-1524,2245,-9500,-4338,4008,-9983,7379,-5966,8851,6144,-739,-1727,8121,-3960,-8499,685,1007,-2741,-4333,-7373,-9068,-1994,9885,508,-4143,8214,-221,211,1952,1973,3572,2732,6171,6478,-1684,1463,2149,-2410,2034,6381,2823,-6342,6781,72,-3865,-8630,-3366,265,-3202,328,3978,-6515,1874,4995,2237,8337,-8997,1279,-4800,387,-4131,-2581,-7192,8363,3925,-2422,4466,3460,-6763,343,7073,1117,-1399,10000,6515,1728,-4575,-9553,-4147,1667,-9119,2977,-6008,-4136,-2776,3207,1525,5648,6719,-9913,92,1772,11,-3689,-9461,-1520,2194,-7287,7921,-4122,-2213,616,-9697,3993,3660,-9789,875,-2429,9439,-539,7047,-8758,3740,-1956,-5393,-2323,-4671,1408,-3367,-3262,-8569,2880,773,7198,-3785,-3103,5643,1407,8521,9506,-742,4273,-4910,-6413,-5819,-1053,-5600,-9477,-6622,7964,-8311,4123,2246,6476,-2473,269,-2520,8587,-2286,-5001,-5861,122,678,1328,87,-3429,-9343,-7796,654,-4336,8255,-1344,9934,-9551,5962,-3557,-4341,9032,-6239,-3603,5897,-1838,2653,-2042,-9897,1272,6174,8716,4481,7174,-3000,1598,-6508,-6171,-1491,2566,-3988,-9445,-3388,261,-9798,7598,-130,6991,-5073,5306,-981,-6743,-478,-2893,-2134,-7762,8925,9056,4063,2676,1955,-2866,3975,-5899,-7010,289,-9330,1615,-1965,-4271,2919,-2485,-2175,-4475,-540,5726,3792,-893,398,2320,-419,-4505,8587,7154,-3483,1362,-1554,8173,-8093,-8258,8142,1604,927,-1635,-9725,-848,-1481,6460,-395,3427,9393,-3445,-1878,1983,-9029,5338,-7472,-9900,8720,-9319,-610,-1588,4567,5817,-5319,-3741,5471,7385,-2098,-1306,301,-6320,-4646,-4517,1002,-7455,-8280,-5645,-6023,9220,-4490,-2621,-3869,-2600,-822,8800,636,5131,-6645,2573,9497,-7683,-6144,556,-4643,7353,-4248,-848,-2889,-5079,857,1542,-5463,-42,4065,5684,8145,8101,-7611,-4152,6076,-7706,-7645,4713,7112,6154,4951,7611,-8211,687,-6916,-5496,-5786,5554,-7805,-3384,-4118,234,-1479,4424,2698,9347,123,-550,83,-3269,9043,1159,4488,1106,-7429,3832,652,1640,-4585,1371,-6220,-1092,-7521,9270,2617,5671,-2641,8039,-9981,457,-704,8411,7079,-4817,-7433,1142,8780,9126,9802,-3676,8437,-2656,2155,4756,2827,-742,-4839,-6737,3873,-6836,346,2274,-7116,-8175,-6532,-4409,1825,7155,-6753,7828,9851,-4385,-9222,3885,3955,4887,4639,3240,-4635,-8969,9363,7671,7889,861,-9718,-381,-3224,1012,-8578,-5147,1190,-2886,-1365,-6391,-1739,-3791,-20,5731,-6121,8964,-1040,-2088,-742,9754,4352,7314,9029,2514,8618,-941,925,-9732,1999,-9381,-1335,7272,5231,7485,5379,4135,-5099,1077,-7514,7673,-8505,2436,8906,9373,-2769,7169,-8871,880,-5362,7772,-6298,-8784,-3626,-8308,1046,5446,3002,-9701,7809,9048,2736,-8709,6861,-218,3713,620,-1899,-5956,-3779,-5566,-7194,-1294,1147,8644,2592,5455,-7959,8765,9701,-7551,5989,-5760,8898,-2055,-1084,1042,-2616,5759,-8634,9339,3573,-9287,50,-9695,-472,245,3485,2352,7574,-2063,354,-1099,4533,8866,2154,35,-6729,-274,-5862,-9055,-8991,-8977,6035,2556,4158,8610,5372,9981,-7366,-395,-8571,2046,687,6295,-757,465,-6155,-240,4876,2306,-4345,6183,5525,-73,8133,4372,7484,-7279,262,8479,-7970,9747,8297,6154,2688,1383,-2475,8359,857,7770,-6449,-8893,4313,-5321,3707,6090,-1559,8753,2853,-2456,-3566,3062,-9817,5051,-7844,-2856,3006,0,-6477,-5422,-507,-5943,6607,-4751,2733,-4735,-6931,-5343,8778,-2915,6076,2488,-6002,-3989,2015,9449,-4180,2441,-7633,9720,578,3908,246,4748,2578,3221,-8108,-1953,-3804,-2977,-3679,8473,4732,2135,-8631,3231,8467,5106,-2601,-748,8748,-5685,132,1358,-1664,-2878,4686,-1719,-4440,1607,-8823,5982,-5233,6125,5323,8481,7563,6051,-9863,-2945,-5247,8299,9241,9711,-1263,-4365,-3629,2780,-8975,-8217,797,-7892,89,6999,-8305,-5843,9732,-7546,-3910,7205,-1499,7881,9409,8676,-5998,6096,-8812,-2700,3871,6779,-1561,5573,9757,-140,2056,-9574,6319,-5355,-9003,-2512,-8242,3491,-5894,5622,-7445,3269,6387,-4022,-3241,-5338,9973,2345,-7826,7356,-2074,7257,1150,8467,2417,6274,1956,-9032,-4392,8375,-9282,4920,-7374,1412,6428,-6949,6295,5394,5094,-2010,-7815,-4493,724,2675,-7818,-2556,-7025,9211,12,-1795,7482,-3419,-8281,9435,-4838,991,5184,5871,-8766,-5867,-7994,-6159,-4972,8245,-5954,-7509,-1654,-1986,1949,-7520,-4927,5999,8321,6797,-8913,-9627,2907,-305,-1239,2247,1035,-5348,-9819,-2597,-7038,-8732,-5747,-7315,7889,4456,-3110,-2937,-129,-1353,8138,8432,7494,6193,7527,-1583,6046,4167,-2823,-5764,-2688,1611,8040,-5514,5702,5913,-2585,-8545,-9809,5761,2655,4183,-2307,2262,6346,344,-7633,6202,3043,8639,7281,3697,-9007,-6409,-1562,8810,135,-257,-5994,-9061,-8792,3811,-4774,1566,3667,8910,4165,-2535,-9393,3490,-7607,837,2732,-5875,8354,-9831,-9605,-6714,9870,5340,7343,-9355,-8681,6331,-5035,9495,8750,-6962,-4280,1094,-7977,7314,-2653,7935,9165,-8722,8016,-3460,-424,1358,4939,-1030,8242,-1272,-7969,3771,9155,7590,-4024,-628,216,-5290,6514,4196,-518,-7331,6585,-7019,-1857,5614,-4537,6542,5850,2843,-6932,-6198,7607,1936,-1473,-4346,-7912,5887,-876,-1615,6346,-734,554,-236,4931,615,-9538,-9630,-3258,-9667,-6070,-9612,-211,3183,-5517,7627,3283,1877,-854,-1362,9513,8553,-3725,-3208,-2715,2666,-9619,9846,-3217,5126,5420,2262,7531,9898,-3879,-8634,-5931,-4021,8559,7399,5833,1830,9568,525,7667,7729,837,-1195,-6757,-6034,-3637,4278,9370,5763,6483,9506,3326,602,4346,7096,-4181,7590,-3755,3372,4330,-1650,3956,9761,-9595,1732,-2967,4071,-5700,2903,-3992,3938,7974,4158,8467,7829,-1633,8945,1532,1512,-9552,839,8375,4577,-5660,4221,-5371,6818,2162,-6747,-5977,-2882,679,9340,9662,-3580,8183,-9397,8609,-2843,-6111,2571,378,1722,4302,4347,-9339,-9121,8900,3405,2742,-5762,-7121,7686,-2609,-481,-4601,6408,-9845,5169,2747,6496,-5718,2860,1245,-6020,237,849,-1814,-4377,1243,-2951,-5428,-573,-5353,-1712,2354,-7203,1098,3584,-2503,-5751,8431,4414,7444,8728,9858,-9398,5201,-5570,-9075,9948,4930,-2290,8304,4834,2578,-1595,481,9438,-3659,5303,7360,5387,-2289,-3431,-4023,5267,-8602,7,7238,-9937,6516,-808,2315,-4192,6167,9768,6120,-611,1285,4261,6118,9232,2686,5270,-3362,-5422,144,3757,4799,5585,-8615,6639,-9695,5650,-4619,5360,7719,-5102,-5466,-4105,-1156,7526,7958,1039,-5823,-2276,5783,-3235,-402,-8873,2397,-6960,-8252,-615,-5525,615,-4261,3953,-6209,9373,5330,-9229,-9874,-8918,5379,4641,1300,-8729,4946,3540,-4394,-5970,-8119,1241,3559,-4516,979,1125,5644,4297,4320,-5355,7112,9112,4592,-4174,1345,3878,3358,-6183,-1696,1148,2958,2637,1889,-7777,3204,8564,4370,-7036,1763,6107,-2319,7759,-9009,-1694,4112,-8759,-3455,1673,-8606,-4856,-9411,-9955,-884,7829,-5274,1966,5709,-6262,-8886,4846,-3739,6494,-2525,1236,4498,4421,-7454,-8405,-1373,4178,5402,8599,-1269,8387,-4546,41,-1464,3702,7193,9609,6781,8939,-9747,8812,7371,-5958,-7949,-8552,-688,4653,-1239,933,6904,5212,5786,-8864,-1223,8774,2639,-580,1360,7389,-5507,7650,-9716,9069,-1179,-9783,-3762,-1945,-4251,-1245,4745,3706,-2267,-5222,-5272,-2264,-3755,2392,-4038,-2936,-353,-9745,1548,4923,-9652,-8665,7798,3860,115,8065,3609,-7937,8587,2985,-408,3456,-7812,9286,6653,-3818,9867,3771,37,-3933,-5751,-1840,3756,-6817,-3139,-2620,-4476,-3550,-5154,26,7562,-142,1223,9224,-1184,5833,6909,-4391,-2834,7898,2345,9622,-3117,-2428,-11,-8646,6288,-7065,-7272,9890,960,-2883,4509,-3756,3922,4466,9840,-3642,-7640,-3792,3519,4397,7245,9099,3293,-5684,5454,-9740,9941,-5375,621,-6564,4468,-6193,9354,4689,7431,-5587,3613,5896,7676,5010,6136,3773,-2416,7005,7489,9279,-3366,-7097,3068,-6262,-6929,-3249,9974,7027,-4686,-2624,-7052,3248,7780,-5479,476,5674,2600,5404,5780,-6708,-8210,-7521,-6337,9278,-4357,5828,7950,-6968,3151,4250,7018,-2720,-9542,-5455,-3342,9137,985,-6423,-1986,7294,-4309,-7273,-8492,-5404,-368,-7127,849,-2726,9173,-4745,-1000,6200,6152,9589,3677,6600,6546,-5714,-8247,-3034,2749,-4354,-8517,4684,-7274,9057,-9791,1259,-6417,6086,-4566,-5133,-7052,2937,8507,9764,-409,3493,9016,-4444,-2027,-7551,2766,3631,-7239,-7995,-9113,-5599,-7532,-5099,-9447,-7840,-6006,-9224,-1745,-2201,-9543,5717,3677,-3612,-8537,-259,4284,-4417,1270,9510,3132,3763,-7545,-1343,752,-3544,-2146,-4109,8654,-7299,9110,-2427,6282,-9684,-2078,-3233,2654,1739,-9444,-3885,4987,8011,6794,-7984,159,3212,4594,5818,3829,-5145,-2780,-796,8148,7950,-2095,1308,-5073,6087,-5345,1737,7758,-7065,6520,9165,8155,-8733,7769,-1874,252,-5906,-4615,3435,2883,950,-7448,-6510,-909,-3759,-3596,4724,-5713,8416,2761,-8463,-7962,-9276,-1857,6655,7048,425,8743,-1691,-279,-9940,9991,-426,-2843,9821,-6521,-8239,-9804,-1863,2387,-1331,-4474,-706,-6061,-5953,4893,8781,3318,2786,-4115,-9912,-4500,6524,-9674,-9537,-9326,-7396,-8508,4035,-4556,784,1759,-9397,9807,4768,-2220,461,9272,-2254,8640,-8566,7589,4164,5914,3400,2552,-3460,-1852,-9512,5113,5231,7618,-8295,-6152,-7118,2222,-5006,8916,1687,-5200,-7416,8813,4438,5868,-1662,-1883,-597,-1580,-2297,4445,-685,-2749,9236,5917,915,-376,-9649,-9550,-1155,4660,7111,9511,8489,-7171,2481,-6038,-6011,9933,-3126,-3148,7999,-2696,3123,9027,6874,4317,-8820,2407,2129,-4128,7956,7878,5356,634,-1199,-1899,1783,5308,9844,-700,6999,-4370,1119,-7729,5079,-6565,4179,-4319,4449,-6737,-9126,-5078,-1458,5387,-9153,-4382,9281,2308,7556,-2217,-8312,8206,9284,-9171,-4445,-1942,4883,8641,6149,6411,985,2681,-1730,8176,-8545,2284,1277,-2142,2352,-9892,6157,-5730,8982,-1758,-6033,7708,-7172,4430,7096,-3817,-2393,262,375,-2195,-6590,166,6150,4885,-8496,4500,9377,-3117,9218,8412,9404,-7108,-5135,5068,-9950,-2019,5847,6,-7720,-2618,4510,1176,5692,2274,-7588,5786,3761,-518,-7467,6938,-5266,-1542,-2221,3140,2191,7480,-2947,-1001,-165,-3132,-6481,-9921,-2233,2583,4036,-454,5799,7090,7566,-9604,-5190,-9245,-9908,-9476,-4032,5382,-7354,-6457,-7786,300,2906,1976,5346,4854,-8947,6825,1874,7087,5697,-5987,7288,2673,1881,-5407,-3560,-3657,-4810,1287,-2327,1710,-1680,982,-1797,-7410,-9998,-6355,9022,-7414,1029,-8998,-164,1398,-5152,9806,-4984,-5004,4811,-6496,-6906,-4226,-3324,-5321,-2147,-7029,4877,3506,-3707,-8136,-5554,-8301,-912,-4130,9139,-3392,-1381,-3672,2318,4522,-8763,-9281,9945,2185,-215,8641,-4157,164,-250,-709,9976,-6675,1250,4097,-8084,3176,-5046,1754,3383,-7034,4421,-2693,-5935,-5303,8484,-5580,-2623,-9892,-8708,3188,-7416,-1848,-5186,-9560,-9792,-4552,-4059,-7022,-6646,-2850,-1907,-7242,5511,-1428,226,-2568,-5530,5947,575,2176,9033,5440,-7922,9982,8673,3311,-9378,-4449,-7749,-5920,-488,7563,-4090,2479,-7985,-1554,8137,7185,-1095,4288,-9603,7477,169,-6268,9053,-5196,-8759,-8327,-5342,4435,-4845,5259,-5622,-424,6260,-873,-6354,-9403,6477,-7259,-3893,3854,2055,-5730,5700,-3628,-9387,-9052,4621,-1403,2363,-453,2605,-9437,-2775,9960,7523,-7086,-5793,9429,-6087,-9928,-4921,632,-8275,467,-2887,1819,-8274,9739,2971,-5888,-9560,3918,-7782,-2775,9845,-7862,-8645,3217,-2667,-4347,9649,3484,-7800,-4472,6558,1722,3093,8461,1117,-5088,-6260,-3743,4454,-7027,-4506,-375,-8244,9278,-8297,5896,8039,-7905,-351,542,-495,-3626,9321,1294,-9177,8275,5929,4323,-2340,3267,-1823,-987,6035,8944,7441,-5345,-9984,-7434,5568,8612,7143,-459,-1481,-2444,7828,-5636,-3465,-662,-8776,3003,341,-887,-83,8984,-9507,4959,8001,-8564,-160,3233,1535,-7343,6134,-8129,769,2584,8773,-3798,9218,7868,-3651,-3722,3124,-9453,-2269,2210,-4545,-9952,7465,-2457,-592,5236,-8773,-7653,-8743,949,4501,-4624,7942,7667,-3294,-6537,-7728,3648,-9788,-1852,-2043,4795,-914,9175,3638,-2403,8090,8645,-8643,3100,-7284,-8730,-3129,6042,-3828,-4261,-3925,-2095,7333,9229,5854,-1825,-3972,-3448,9813,9742,-6014,1679,-3100,5998,-6888,5060,4211,2525,9048,-703,-2057,4763,2470,-3587,4628,-4311,989,2705,-6770,2875,-3129,602,9654,-1583,8649,-8253,9501,-6337,-5294,-7877,-3157,-8564,8835,4442,6670,8776,5429,-1424,5108,8720,-1575,2828,26,222,-6628,8216,-7243,-9252,-4250,2634,-3399,-8837,-8797,8916,-8620,6921,-9962,8990,-6042,-7282,3238,-182,-2635,6930,-7574,3323,7335,728,-511,8556,4259,-1127,-8310,-942,3298,-9829,-8150,3292,6028,8097,3079,4492,-6738,-6214,6493,9043,-7594,3520,-102,-9772,-7876,5821,-6597,9465,-4030,-5800,9840,2970,-216,1867,-9791,-126,9218,8310,9396,-5532,8185,-9987,8358,-9668,-7127,-3851,-6777,-3777,4944,-6810,9970,6717,-5160,-7879,4218,-3196,-2944,-9498,-4008,-5549,5602,-5876,-8670,3607,3333,6932,5170,-4715,-7120,9632,2955,9951,5955,-9964,-8929,-3414,-3490,4945,-8394,1215,-563,-4311,4880,-6091,-5376,9271,582,-7411,2967,9464,-9945,-7997,-3323,-7140,7837,-7781,-4061,7129,9435,-2876,4372,-275,-454,995,4034,737,-7936,-8379,2122,-2810,5200,-3452,-9582,7111,-9492,5162,2551,-7005,-7302,-8762,-3804,9598,8386,2632,2811,-8188,558,-7556,-6050,-2997,-7993,2638,-3599,7802,-2831,-199,6579,-3400,-8052,6479,-8741,-8418,-7120,-928,-6004,1886,3790,6169,5825,1269,-4071,-1244,-1277,-2293,-6821,-1318,815,544,1575,-792,-1137,-8345,-7038,-5784,-4199,1683,9950,6342,6962,-8510,-762,-1773,-4802,557,2780,7895,-82,4647,-5266,7518,-3731,7852,-6908,3807,-3824,333,9689,-7349,925,2627,1739,6624,-3119,-5052,-7423,5819,-4388,-6227,1316,-9846,-9613,-8331,-5749,3198,-3254,-6921,-5343,9501,4375,-1465,-8540,577,162,-4039,3821,-2452,-8547,5849,-5823,-8957,-9761,6902,1319,-780,5267,8144,2426,-1095,6238,4985,-5133,-4942,6543,-5687,6803,-4442,5573,1437,4834,1773,-2198,8221,-391,-403,-359,-9477,-820,9501,-3643,-6136,5756,-2293,1060,-1030,-3967,-4087,4528,9778,964,-8915,-9932,-4317,-6800,698,-5280,1972,-1893,2946,3468,-3028,-9202,-783,-3976,50,-2777,-1858,-7057,-8678,4664,-4277,-8139,4563,-5507,5350,-3983,6945,-3210,-5943,-5305,-9355,3229,3929,2326,-3464,9568,5409,9657,3344,6740,4899,7077,1691,3707,-719,7163,-1574,-6310,6767,-5044,8657,-9061,9151,-7909,-5814,669,4518,-6041,-7829,2937,3220,1709,2557,2460,5758,8044,7410,-633,14,3100,952,8138,-6878,191,4067,9903,7383,4984,-3052,6847,2810,-5042,-1961,2689,-9319,-1601,-3414,5251,715,-4269,2482,2235,1855,1271,-6066,1922,-7707,369,-7702,-1333,5590,9506,237,1765,3166,5231,9050,-8691,8404,3116,3979,7685,9404,-3444,8852,-3177,-2679,4507,-5129,-5578,-5137,4546,5996,903,5722,-4106,8724,-8169,-2305,-787,-1739,4255,-4440,-1677,-6394,513,-9440,-4859,2637,9656,-2324,-4630,-618,-782,9858,-5486,4478,3355,728,-6996,-5701,4215,-4182,-8308,-3036,5576,7364,105,9900,8135,6923,8246,8816,-9020,3022,-3466,-4371,2220,9323,4569,8686,2728,-9096,8543,4429,-480,671,9185,-9845,454,1439,6612,-5188,-2854,-7728,-4399,2751,-7328,-3334,-8533,-6303,-2481,-3610,4787,-1130,5918,-9071,-4465,5017,4936,-4699,3154,6720,-118,4813,-400,-3919,4771,-8192,-3644,-3824,2962,3870,-5884,926,-5338,-5812,-6149,1490,4100,4749,2517,-5284,-4696,-4204,-1777,8149,-3249,3496,-2844,-4178,6737,6282,5277,8487,-3009,8817,8009,9983,-7298,5281,-8378,257,-4725,3218,-9722,5598,-4207,1941,6434,9218,9251,-514,-361,-849,-4889,-4416,3088,9942,4962,-6134,-1898,-6088,2637,5045,-7280,266,4194,3538,-3609,-6762,7488,-1849,-6262,6610,-6812,-1239,-6096,-2258,-2872,5903,-8201,-80,-4552,-5654,5474,-4171,8187,-6945,1377,-3935,-7534,-4516,8016,5981,-8235,-8422,2542,-4394,-7877,-2551,-2926,-6880,-7136,6260,2350,-6861,4553,-380,6843,1619,1866,2235,5068,-4602,6698,6803,4787,-8743,7783,-8136,4697,-5393,-4923,-4209,-3132,8510,-7230,5418,-4467,-2528,-9627,-8244,-8824,-493,8637,48,-4713,4311,-3342,4151,706,2789,-7721,7204,-1194,1972,-1135,-4098,6918,3836,-829,-772,1734,8478,9486,-699,-9929,658,7525,5401,-4184,6114,-8301,3556,2185,8763,7361,-1395,7626,7288,5289,241,-8592,-8502,941,-8335,-2461,4199,-4811,-1596,-4685,-8339,-590,-4041,3363,-3391,9570,-8267,404,2924,-4712,7631,-2673,-5416,-8527,-6334,-7082,-597,-7432,7129,-50,-733,-5690,-8451,1047,2927,-1250,-9803,7990,8537,9633,-6038,2911,-7505,7693,5425,4223,-9962,-2765,-2330,-7195,5745,7579,4283,-4075,-605,-6916,7365,5059,6132,7587,1302,1492,3645,6663,4497,2415,1056,-678,7832,-598,6865,573,-7976,7354,-1423,-8229,-3355,1339,9563,-8324,9800,-3996,-1993,-4174,915,-2370,-266,-4783,-914,-3668,-3022,-3532,-2708,-1405,7838,1576,-2341,1915,-4516,8257,-2954,-5862,-6971,-8896,7738,3794,-3547,1694,-1328,4687,2085,-1517,3830,-1202,-610,-853,4025,7847,9895,-974,-8685,1492,3065,-5456,6774,-136,3897,-275,-1468,5746,-6862,2664,8341,5454,3108,-5787,7620,-7693,2067,-8535,-5488,1675,691,5458,6359,-5084,-6627,-8935,-4150,-9850,-2983,-448,-9158,773,4421,8685,813,-9795,6278,-9846,-9912,8164,4606,7950,-8337,7675,7630,3712,9607,7584,-5559,7404,-547,1836,3859,8608,-7161,-6525,-6870,-8428,-1531,2511,-4813,-1641,-582,4010,-2264,-9834,5809,7609,-6169,7763,3182,1801,6125,-7503,945,9016,-4286,1917,2846,9799,-5206,6476,3793,2939,-8850,-5312,-374,3673,7238,-3933,1240,9274,-4616,-7601,-9394,-4102,5562,-3424,-6619,9694,9528,-9853,-1815,-1862,2064,5297,5825,2755,-7525,8488,1004,-5413,2958,-6003,9964,-4097,1265,-6605,2770,9829,1060,7765,73,5451,518,-2414,-5445,-8329,5682,1381,2556,8208,2279,1180,3580,-1407,6571,-1817,6448,8406,1269,-1653,-998,-7571,8741,7068,-5176,-3682,-8363,2282,6852,-189,-2037,-5198,-9129,-107,561,-9259,8155,-5554,-1013,-6436,8637,8772,-6458,-1,4562,7984,-1649,-6681,-6700,-3413,2453,-1149,-7603,-3004,-6090,-9140,-5160,2171,1372,-7302,7426,9819,3971,-5082,-1237,1301,-6657,-7743,-2368,-1030,-9011,548,5840,-4517,5289,5339,3775,9826,-8190,-2496,-6622,9670,2908,-6646,-9754,2872,-2878,6782,-9514,6312,2213,-4624,9585,-6422,-7317,-2535,8640,-5896,-424,-8864,5579,-7377,-8062,1281,-6622,6078,3749,-9622,5807,6467,-4656,9057,-2877,-8708,-6666,-6312,-4864,9124,-139,-4308,-7950,-9035,-9591,-1080,1036,-2525,9563,-977,-3571,-6068,-8690,-6046,-534,-2847,-3485,-7960,-3412,-9333,2540,-1970,-9066,604,-4211,733,2663,9492,763,4729,8022,8766,-730,5852,-2593,5500,3876,-6250,-8924,9682,5319,3355,-248,4570,7433,3619,8983,-6267,-1125,736,1032,-7286,-8436,6403,-8562,-2636,5023,-6002,5324,-5367,4821,-5365,-3839,5043,-6434,1878,-9464,2110,-6659,-6182,-8138,-699,-6181,-1567,-6383,9506,-2025,1200,397,-2705,-5634,-7360,-915,-4349,-4428,73,-3095,-1347,9212,-1965,3382,2137,2819,-7323,720,-9820,-5646,3948,-9040,-2069,-4522,6057,5771,3918,-8693,3885,3359,2831,-3563,464,-2123,-6590,-2698,-3620,-1496,3324,5709,7842,-5603,5577,2635,-6569,-5353,6098,-6526,2609,-1707,-6761,-3234,-8556,5731,1059,5999,6731,-2738,9839,467,6046,7071,285,-6257,5813,-7531,5403,-7789,4070,3756,-9506,1527,8982,4983,-1909,-531,2401,8252,7902,-7958,-4414,-9745,531,7979,3002,-7242,3876,403,-3807,-2583,1428,-6618,-3340,4837,-6138,-1845,-7642,8602,8791,-871,8571,-299,-3794,-1342,7420,-6433,1795,5900,-6674,3265,-3538,-6,-8986,6849,-9104,-8302,-5256,1613,-5331,5094,-7808,-6826,-7881,-6577,8110,-5511,-5889,1560,-9408,6055,-7428,-8780,9135,9960,5611,1679,-5380,-2514,-7371,-9658,8101,-3584,-1293,-2768,-2252,-2885,8448,-3959,-7431,-5881,49,1092,-783,5750,-9666,5528,274,-9632,-1154,2597,-4936,5218,4872,-8194,-661,-3406,-6427,7811,7359,-4567,6987,9217,9133,7665,-2953,2438,949,9704,4974,-4092,-920,377,9232,3024,-9686,-6104,6466,4269,9333,5477,4489,7311,-8257,3584,-9416,5593,4208,2973,-2590,-9290,-3683,3916,3215,-9496,-9539,-4123,2747,-7766,8135,-3561,-3096,-7570,-4159,5841,-2016,1239,2015,4404,8889,-9039,-5280,-4594,-5809,-1421,5487,1701,-1209,9210,-5781,-7687,3075,-6067,-1413,-5680,4141,-531,-3922,-733,9024,8346,3098,-2707,4906,-4693,9078,-7602,1420,-8203,5695,-6755,3846,1327,5288,2623,-2090,-7968,1694,-9320,-7180,3522,9587,-7534,7492,-8738,-7239,9836,5017,5374,-1323,807,-6676,3384,-6582,4791,3436,7982,2304,-1725,-6345,-4650,-8912,704,89,-3704,4139,8629,-5237,-2074,3513,1945,5470,-2553,5325,-6611,1836,55,-2828,-4138,270,8538,-455,-1370,-7528,-5021,9644,5539,3375,712,9165,5240,6958,4946,6289,-9865,-1646,-5389,-8611,5487,1094,-8113,-1690,3583,-6004,-6419,4902,-6145,-317,380,-3150,9618,-2069,5907,4919,-8223,-6761,-3323,-6320,-2921,2538,-2294,4645,8112,-2253,-5999,-4315,-7036,-318,-3444,2539,6572,-3680,-429,924,3350,-4882,1090,9869,535,-9430,-737,9841,-1523,5108,-3901,-6415,-2672,7179,-972,-5782,1691,-1181,-87,6614,-5626,-2898,-1636,-581,7416,881,8636,1739,2558,-5074,5081,-4869,6400,634,8916,-2490,8059,2647,5799,-1619,7000,-69,4896,-1950,1857,1618,5641,-7474,1740,-8610,5776,-9742,4796,9996,-5989,-4116,-5435,2509,-2415,6655,5938,-6733,-538,-5827,4077,-6656,802,1923,8939,4104,-3754,8891,-5322,-7419,-4822,-8826,8971,5887,-7456,-603,-4889,-9176,2033,-1525,-7285,-6825,2164,-6830,461,4054,1029,1057,5075,-9457,-1245,-894,-2274,2176,-1474,-9149,8681,-5993,-6024,-3882,-4821,-7227,6215,-9664,747,6306,6832,4519,607,-5385,-5059,-1374,-2684,-6052,-8933,2083,-2188,7952,-5340,-7934,2687,3583,-4150,9523,1900,-5994,-6573,-8352,4594,-6075,2843,1728,9747,-7476,3942,-6248,-6273,-7874,5342,1371,-5193,-5758,7601,-7703,-9767,2,9003,-2947,1929,-1057,-1950,7338,5903,2744,2094,9543,-7198,9798,-5482,4097,3290,813,-6487,-8354,5389,-2917,-4649,669,-8431,2792,6878,-6155,-6382,8630,-8979,-6960,-6392,-4172,-86,-784,-5545,-2858,5808,3334,348,4885,5727,8927,608,-8551,-5806,-6582,55,7124,5750,7159,3582,9518,4163,6233,4259,391,183,-6066,-4685,3634,7236,2539,-3485,-4860,7845,6288,4375,2132,-6447,-7587,6739,-6626,9781,-7195,4195,6984,-686,-2599,7302,4419,9300,-5763,3894,9546,-3594,-4737,4652,-2257,-4878,-5602,5003,-5764,7042,2976,-5469,-3416,-148,1025,-5630,803,-147,-3326,3657,-4981,-3650,-8860,-9487,-59,-7295,-8369,6612,-5937,758,363,-5801,9862,-9649,8325,5634,3653,1832,835,-6299,-4675,-3187,-9894,-9416,4976,1974,4390,-2684,7335,-5435,-7075,-8817,520,-5012,-8610,-3770,-9841,188,7545,-2109,-3138,-8369,5744,7627,-6953,-9787,-6075,1035,6181,6939,-3827,1538,-4116,4173,2220,7404,-5288,-3067,-7587,-5583,8641,7664,-7085,-1334,9137,1985,8046,-466,-8585,-2997,4,4238,-9173,-1523,9347,9045,5684,-7324,-5098,5493,-692,-6554,3374,-3885,5762,-307,2677,-1043,-4852,8498,-4434,-6348,4557,7952,-8094,1297,-4436,-1286,-6446,2780,-9143,-7937,-1123,9216,9875,-5213,3300,-1140,9805,7677,-2902,-8478,-197,9660,3522,-472,-546,-6986,6788,-2398,-119,1,-9189,-7878,8911,5786,-6907,-1436,-4425,3683,8305,-2803,838,1330,9369,-8532,-8368,-8981,-1975,5538,5351,1084,-7042,-5543,-2627,7847,4544,5931,-2376,-932,-9925,2286,5849,3545,9790,-2315,-53,3409,4501,-8337,8737,8569,7425,-7946,-241,-4815,-6926,-675,-6273,3924,-4139,7193,-2386,4354,-9095,-747,-3938,-876,-4202,-5517,-4428,9786,3596,-3233,1545,-7141,-4991,1572,1121,9304,-3195,-6735,-1204,6137,-5384,-680,3431,-5643,967,-9781,8557,4709,-6043,2318,-4379,146,697,-1470,-8713,-1011,4632,7308,-7013,-2772,4081,-1036,6196,4839,-2414,-2740,-4173,728,-3799,936,9078,-1958,8544,-6893,-2510,-2329,1993,-3601,2315,-2630,2771,-9305,-887,2124,-359,-2658,9332,5166,4114,-686,-7309,-8288,3382,-9994,9155,6172,51,3111,3470,-5054,3120,-6459,1475,-2711,-6388,-2366,-7574,-3829,-5986,1410,-8,-7450,6582,4810,-9088,8928,1827,2143,-8808,7058,-9054,-6728,7454,6839,-2667,3437,6178,-9356,9607,4540,7024,-453,-986,-9625,5475,9236,3627,1526,-743,-935,7483,-5320,4742,-1537,7980,6044,1042,6935,-9001,1215,-2423,7277,-9823,4857,2354,-5294,-497,9308,-952,-6545,-8398,-4436,-9512,1744,-632,6406,5988,-4096,1374,8193,-7685,3702,1434,6573,441,4115,-3699,-5469,-8615,-2147,-4889,-8296,-2486,-6761,8664,-3860,-6158,-285,-2826,8942,-1683,-1871,-7942,-7480,9696,5049,9546,5118,3439,-828,-1867,-8085,-2607,8517,-1708,-4564,5334,8250,4793,-3485,-3418,1227,-8642,260,7731,-2655,6747,-5949,3529,-3692,-8665,-7831,-656,-1661,7893,9835,-4799,-4555,-329,-3023,-8168,4582,7041,-8445,6751,-4277,3092,-6496,4455,6980,-3480,6972,-1217,5575,-8684,8587,1418,-10,6451,-6376,10,-7251,-2170,-9662,5489,9405,-5423,698,-1874,-2129,998,9036,-164,-1011,-2052,6520,-5949,6824,-6237,-8039,4790,9604,5819,3217,-2245,-1167,2569,-553,3256,-667,-9388,-1632,-1350,-7762,8657,-283,-9303,-4385,-6975,9714,-2008,5350,6136,-9306,-2633,-9468,5410,-1185,-6397,2029,6968,3388,-4552,2175,7603,-6497,7826,-887,5702}; + k = 6514; + + // Calculate the maximum average value + result = findMaxAverage(nums3, k); + std::cout << nums3.size() << std::endl; + + // Expected result (you can calculate this manually) + expected = -25.14477; + + // Compare the result with the expected value + assert(abs(result-expected) < 0.0001); + + if (abs(result - expected) < 0.0001) { + std::cout << "Test case 3 passed. Maximum average value is " << result << std::endl; + } else { + std::cout << "Test case 3 failed. Maximum average value is " << result << std::endl; + } + + return 0; +} + diff --git a/labs/11_hash_tables/happy_number.cpp b/labs/12_hash_tables/happy_number.cpp similarity index 100% rename from labs/11_hash_tables/happy_number.cpp rename to labs/12_hash_tables/happy_number.cpp diff --git a/labs/12_hash_tables/happy_number_separate_chaining_sol.cpp b/labs/12_hash_tables/happy_number_separate_chaining_sol.cpp new file mode 100644 index 0000000..ff0c950 --- /dev/null +++ b/labs/12_hash_tables/happy_number_separate_chaining_sol.cpp @@ -0,0 +1,95 @@ +// Solve the problem using separate chaining. + +#include + +// this table can have at most 1024 keys +#define TABLE_SIZE 1024 + +class Node { +public: + int number; + Node* next; +}; + +// search the hash table and see if we can find this num. +bool identify(int num, Node** table){ + int key = abs(num%TABLE_SIZE); + // search num in table[key]; + Node* node = table[key]; + while(node!=NULL){ + if(node->number == num){ + return true; + } + node = node->next; + } + // if not found, return false; + return false; +} + +// add num into the hash table +void add(int num, Node** table){ + int key = abs(num%TABLE_SIZE); + Node* node = new Node; + // insert num and index into table[key] + // if this is the first node + if(table[key]==NULL){ + node->number = num; + node->next = NULL; + table[key] = node; + }else{ + // if this is not the first node + node->number = num; + node->next = table[key]; + table[key] = node; + } +} + +int replace(int n){ + int digit; + int result=0; + while(n>0){ + digit = (n%10); + result += digit * digit; + n = n/10; + } + return result; +} + +bool isHappy(int n) { + int newN = n; + Node* hash_table[TABLE_SIZE]; + for(int i=0;i +#include + +int replace(int n){ + int digit; + int result=0; + while(n>0){ + digit = (n%10); + result += digit * digit; + n = n/10; + } + return result; +} + +bool isHappy(int n) { + int newN = n; + std::unordered_set set1; + while(1){ + newN = replace(newN); + if(newN==1){ + return true; + }else{ + // if we can find it, this is going to be an infinite loop + if(set1.find(newN)!=set1.end()){ + return false; + } + // can't find it, insert it in the set first + set1.insert(newN); + } + } +} + +int main() { + // Test cases + // 2, 4, 5, 6, 17, 18, 20 are not happy numbers. + // 1, 7, 10, 13, 19, 23, 28, 68 are not happy numbers. + + int testCases[] = {2,4,5,6,17,18,20,1,7,10,13,19,23,28,68}; + + for (int n : testCases) { + if (isHappy(n)) { + std::cout << n << " is a happy number." << std::endl; + } else { + std::cout << n << " is not a happy number." << std::endl; + } + } + + return 0; +} + diff --git a/labs/12_hash_tables/test/ds_hashset.h b/labs/12_hash_tables/test/ds_hashset.h new file mode 100644 index 0000000..fe25a38 --- /dev/null +++ b/labs/12_hash_tables/test/ds_hashset.h @@ -0,0 +1,260 @@ +#ifndef ds_hashset_h_ +#define ds_hashset_h_ +// The set class as a hash table instead of a binary search tree. The +// primary external difference between ds_set and ds_hashset is that +// the iterators do not step through the hashset in any meaningful +// order. It is just the order imposed by the hash function. +#include +#include +#include +#include +#include + +// The ds_hashset is templated over both the type of key and the type +// of the hash function, a function object. +template < class KeyType, class HashFunc > +class ds_hashset { +private: + typedef typename std::list::iterator hash_list_itr; + +public: + // ================================================================= + // THE ITERATOR CLASS + // Defined as a nested class and thus is not separately templated. + + class iterator { + public: + friend class ds_hashset; // allows access to private variables + private: + + // ITERATOR REPRESENTATION + ds_hashset* m_hs; + int m_index; // current index in the hash table + hash_list_itr m_list_itr; // current iterator at the current index + + private: + // private constructors for use by the ds_hashset only + iterator(ds_hashset * hs) : m_hs(hs), m_index(-1) {} + iterator(ds_hashset* hs, int index, hash_list_itr loc) + : m_hs(hs), m_index(index), m_list_itr(loc) {} + + public: + // Ordinary constructors & assignment operator + iterator() : m_hs(0), m_index(-1) {} + iterator(iterator const& itr) + : m_hs(itr.m_hs), m_index(itr.m_index), m_list_itr(itr.m_list_itr) {} + iterator& operator=(const iterator& old) { + m_hs = old.m_hs; + m_index = old.m_index; + m_list_itr = old.m_list_itr; + return *this; + } + + // The dereference operator need only worry about the current + // list iterator, and does not need to check the current index. + const KeyType& operator*() const { return *m_list_itr; } + + // The comparison operators must account for the list iterators + // being unassigned at the end. + friend bool operator== (const iterator& lft, const iterator& rgt) + { return lft.m_hs == rgt.m_hs && lft.m_index == rgt.m_index && + (lft.m_index == -1 || lft.m_list_itr == rgt.m_list_itr); } + friend bool operator!= (const iterator& lft, const iterator& rgt) + { return lft.m_hs != rgt.m_hs || lft.m_index != rgt.m_index || + (lft.m_index != -1 && lft.m_list_itr != rgt.m_list_itr); } + // increment and decrement + iterator& operator++() { + this->next(); + return *this; + } + iterator operator++(int) { + iterator temp(*this); + this->next(); + return temp; + } + iterator & operator--() { + this->prev(); + return *this; + } + iterator operator--(int) { + iterator temp(*this); + this->prev(); + return temp; + } + + private: + // Find the next entry in the table + void next() { + ++ m_list_itr; // next item in the list + + // If we are at the end of this list + if (m_list_itr == m_hs->m_table[m_index].end()) { + // Find the next non-empty list in the table + for (++m_index; + m_index < int(m_hs->m_table.size()) && m_hs->m_table[m_index].empty(); + ++m_index) {} + + // If one is found, assign the m_list_itr to the start + if (m_index != int(m_hs->m_table.size())) + m_list_itr = m_hs->m_table[m_index].begin(); + + // Otherwise, we are at the end + else + m_index = -1; + } + } + + // Find the previous entry in the table + void prev() { + // If we aren't at the start of the current list, just decrement + // the list iterator + if (m_list_itr != m_hs->m_table[m_index].begin()) + m_list_itr -- ; + + else { + // Otherwise, back down the table until the previous + // non-empty list in the table is found + for (--m_index; m_index >= 0 && m_hs->m_table[m_index].empty(); --m_index) {} + + // Go to the last entry in the list. + m_list_itr = m_hs->m_table[m_index].begin(); + hash_list_itr p = m_list_itr; ++p; + for (; p != m_hs->m_table[m_index].end(); ++p, ++m_list_itr) {} + } + } + }; + // end of ITERATOR CLASS + // ================================================================= +private: + // ================================================================= + // HASH SET REPRESENTATION + std::vector< std::list > m_table; // actual table + HashFunc m_hash; // hash function + unsigned int m_size; // number of keys + +public: + // ================================================================= + // HASH SET IMPLEMENTATION + + // Constructor for the table accepts the size of the table. Default + // constructor for the hash function object is implicitly used. + ds_hashset(unsigned int init_size = 10) : m_table(init_size), m_size(0) {} + + // Copy constructor just uses the member function copy constructors. + ds_hashset(const ds_hashset& old) + : m_table(old.m_table), m_size(old.m_size) {} + + ~ds_hashset() {} + + ds_hashset& operator=(const ds_hashset& old) { + if (&old != this) { + this->m_table = old.m_table; + this->m_size = old.m_size; + this->m_hash = old.m_hash; + } + return *this; + } + + unsigned int size() const { return m_size; } + + + // Insert the key if it is not already there. + std::pair< iterator, bool > insert(KeyType const& key) { + const float LOAD_FRACTION_FOR_RESIZE = 1.25; + + if (m_size >= LOAD_FRACTION_FOR_RESIZE * m_table.size()) + this->resize_table(2*m_table.size()+1); + + // Implement this function for Lab 11, Checkpoint 1 + + + + + + + + + + + + + + } + + // Find the key, using hash function, indexing and list find + iterator find(const KeyType& key) { + unsigned int hash_value = m_hash(key); + unsigned int index = hash_value % m_table.size(); + hash_list_itr p = std::find(m_table[index].begin(), + m_table[index].end(), key); + if (p == m_table[index].end()) + return this->end(); + else + return iterator(this, index, p); + } + // Erase the key + int erase(const KeyType& key) { + // Find the key and use the erase iterator function. + iterator p = find(key); + if (p == end()) + return 0; + else { + erase(p); + return 1; + } + } + + // Erase at the iterator + void erase(iterator p) { + m_table[ p.m_index ].erase(p.m_list_itr); + } + + // Find the first entry in the table and create an associated iterator + iterator begin() { + + // Implement this function for Lab 11, Checkpoint 2, Part 1 + + + + + + + + } + + // Create an end iterator. + iterator end() { + iterator p(this); + p.m_index = -1; + return p; + } + + // A public print utility. + void print(std::ostream & ostr) { + for (unsigned int i=0; i +#include +#include +#include + +#include "ds_hashset.h" + + +// Wrapping a class around a function turns a function into a functor +// (We'll talk about this more in Lecture 21. You can just ignore +// this wrapper part for now.) +class hash_string_obj { +public: + + // ---------------------------------------------------------- + // EXPERIMENT WITH THE HASH FUNCTION FOR CHECKPOINT 1, PART 2 + + unsigned int operator() ( const std::string& key ) const { + // This implementation comes from + // http://www.partow.net/programming/hashfunctions/ + // + // This is a general-purpose, very good hash function for strings. + unsigned int hash = 1315423911; + for(unsigned int i = 0; i < key.length(); i++) + hash ^= ((hash << 5) + key[i] + (hash >> 2)); + return hash; + } + +}; + + +typedef ds_hashset ds_hashset_type; + + +int main() { + + // --------------------------------- + // CODE TO TEST CHECKPOINT 1, PART 1 + ds_hashset_type a; + ds_hashset_type set1; + std::pair< ds_hashset_type::iterator, bool > insert_result; + + std::string to_insert = std::string("hello"); + insert_result = set1.insert( to_insert ); + assert( insert_result.second ); + + insert_result = set1.insert( std::string("good-bye") ); + assert( insert_result.second ); + + insert_result = set1.insert( std::string("friend") ); + assert( insert_result.second ); + + insert_result = set1.insert( std::string("abc") ); + assert( insert_result.second ); + + insert_result = set1.insert( std::string("puppy") ); + assert( insert_result.second ); + + insert_result = set1.insert( std::string("zebra") ); + assert( insert_result.second ); + + insert_result = set1.insert( std::string("daddy") ); + assert( insert_result.second ); + + insert_result = set1.insert( std::string("puppy") ); + assert( !insert_result.second && * insert_result.first == std::string("puppy") ); + + std::cout << "The set size is " << set1.size() << '\n' + << "Here is the table: \n"; + set1.print( std::cout ); + + ds_hashset_type::iterator p; + p = set1.find( "foo" ); + if ( p == set1.end() ) + std::cout << "\"foo\" is not in the set\n"; + else + std::cout << "\"foo\" is in the set\n" + << "The iterator points to " << *p << std::endl; + + p = set1.find("puppy"); + if ( p == set1.end() ) + std::cout << "\"puppy\" is not in the set\n"; + else + std::cout << "\"puppy\" is in the set\n" + << "The iterator points to " << *p << std::endl; + + p = set1.find("daddy"); + if ( p == set1.end() ) + std::cout << "\"daddy\" is not in the set\n"; + else + std::cout << "\"daddy\" is in the set\n" + << "The iterator points to " << *p << std::endl; + + + // --------------------------------- + // CODE TO TEST CHECKPOINT 2, PART 1 + /* + p = set1.begin(); + std::cout << "\nHere is the result of iterating: \n"; + for ( p = set1.begin(); p != set1.end(); ++p ) + std::cout << *p << '\n'; + */ + + + // --------------------------------- + // CODE TO TEST CHECKPOINT 2, PART 2 + /* + ds_hashset_type set2( set1 ); + std::cout << "set1.size() = " << set1.size() << ", set2.size() = " << set2.size() << std::endl; + + // Now add more stuff to set2. This should trigger a resize given the default settings. + insert_result = set2.insert( std::string("ardvark") ); + assert( insert_result.second ); + insert_result = set2.insert( std::string("baseball") ); + assert( insert_result.second ); + insert_result = set2.insert( std::string("football") ); + assert( insert_result.second ); + insert_result = set2.insert( std::string("gymnastics") ); + assert( insert_result.second ); + insert_result = set2.insert( std::string("dance") ); + assert( insert_result.second ); + insert_result = set2.insert( std::string("swimming") ); + assert( insert_result.second ); + insert_result = set2.insert( std::string("track") ); + assert( insert_result.second ); + + std::cout << "\nAfter seven more inserts:\n" + << "set1.size() = " << set1.size() << ", set2.size() = " << set2.size() << "\n" + << "\nThe contents of set2:" << std::endl; + set2.print(std::cout); + std::cout << "The results of iterating:\n"; + for ( p = set2.begin(); p != set2.end(); ++p ) + std::cout << *p << '\n'; + */ + + // --------------- + // OTHER TEST CODE + /* + // Now test erase + int num = set2.erase( std::string("hello") ); + std::cout << "Tried erase \"hello\" and got num (should be 1) = " << num << std::endl; + num = set2.erase( std::string("abc") ); + std::cout << "Tried erase \"abc\" and got num (should be 1) = " << num << std::endl; + num = set2.erase( std::string("hello") ); + std::cout << "Tried erase \"hello\" and got num (should be 0) = " << num << std::endl; + num = set2.erase( std::string("football") ); + std::cout << "Tried erase \"football\" and got num (should be 1) = " << num << std::endl; + num = set2.erase( std::string("friend") ); + std::cout << "Tried erase \"friend\" and got num (should be 1) = " << num + << "\nHere are the final contents of set2:" << std::endl; + set2.print(std::cout); + */ + + return 0; +} diff --git a/labs/12_hash_tables/test2/a.out b/labs/12_hash_tables/test2/a.out new file mode 100755 index 0000000..f7961d2 Binary files /dev/null and b/labs/12_hash_tables/test2/a.out differ diff --git a/labs/12_hash_tables/test2/happy_number_separate_chaining.cpp b/labs/12_hash_tables/test2/happy_number_separate_chaining.cpp new file mode 100644 index 0000000..ff0c950 --- /dev/null +++ b/labs/12_hash_tables/test2/happy_number_separate_chaining.cpp @@ -0,0 +1,95 @@ +// Solve the problem using separate chaining. + +#include + +// this table can have at most 1024 keys +#define TABLE_SIZE 1024 + +class Node { +public: + int number; + Node* next; +}; + +// search the hash table and see if we can find this num. +bool identify(int num, Node** table){ + int key = abs(num%TABLE_SIZE); + // search num in table[key]; + Node* node = table[key]; + while(node!=NULL){ + if(node->number == num){ + return true; + } + node = node->next; + } + // if not found, return false; + return false; +} + +// add num into the hash table +void add(int num, Node** table){ + int key = abs(num%TABLE_SIZE); + Node* node = new Node; + // insert num and index into table[key] + // if this is the first node + if(table[key]==NULL){ + node->number = num; + node->next = NULL; + table[key] = node; + }else{ + // if this is not the first node + node->number = num; + node->next = table[key]; + table[key] = node; + } +} + +int replace(int n){ + int digit; + int result=0; + while(n>0){ + digit = (n%10); + result += digit * digit; + n = n/10; + } + return result; +} + +bool isHappy(int n) { + int newN = n; + Node* hash_table[TABLE_SIZE]; + for(int i=0;i +#include + +int replace(int n){ + int digit; + int result=0; + while(n>0){ + digit = (n%10); + result += digit * digit; + n = n/10; + } + return result; +} + +bool isHappy(int n) { + int newN = n; + std::unordered_set set1; + while(1){ + newN = replace(newN); + if(newN==1){ + return true; + }else{ + // if we can find it, this is going to be an infinite loop + if(set1.find(newN)!=set1.end()){ + return false; + } + // can't find it, insert it in the set first + set1.insert(newN); + } + } +} + +int main() { + // Test cases + // 2, 4, 5, 6, 17, 18, 20 are not happy numbers. + // 1, 7, 10, 13, 19, 23, 28, 68 are not happy numbers. + + int testCases[] = {2,4,5,6,17,18,20,1,7,10,13,19,23,28,68}; + + for (int n : testCases) { + if (isHappy(n)) { + std::cout << n << " is a happy number." << std::endl; + } else { + std::cout << n << " is not a happy number." << std::endl; + } + } + + return 0; +} + diff --git a/labs/12_hash_tables/test4/a.out b/labs/12_hash_tables/test4/a.out new file mode 100755 index 0000000..3a2f665 Binary files /dev/null and b/labs/12_hash_tables/test4/a.out differ diff --git a/labs/12_hash_tables/test4/test_longest_consecutive_sequence.cpp b/labs/12_hash_tables/test4/test_longest_consecutive_sequence.cpp new file mode 100644 index 0000000..7dfd688 --- /dev/null +++ b/labs/12_hash_tables/test4/test_longest_consecutive_sequence.cpp @@ -0,0 +1,117 @@ +#include +#include + +#define TABLE_SIZE 1024 + +class Node{ +public: + int number; + Node* next; +}; + +// insert num into table +void insert(int num, Node** table){ + int key; + key = abs(num%TABLE_SIZE); // key will be something in between 0 and (TABLE_SIZE-1); num can be negative + if(table[key] == nullptr){ + // create the first node for this linked list + Node* node; + node = new Node; + node->number = num; + node->next = nullptr; + table[key] = node; + }else{ + // insert a node to the beginning of this linked list + Node* node; + node = new Node; + node->number = num; + node->next = table[key]; + table[key] = node; + } +} + +// search the hash table and see if we can find this num. +bool identify(int num, Node** table){ + int key = abs(num%TABLE_SIZE); + // search num in table[key]; + Node* node = table[key]; + while(node != nullptr){ + if(node->number == num){ + return true; + } + node = node->next; + } + // if not found, return false; + return false; +} + +// Question: why is this an O(n) solution when we have a nested loop? Because the inner while loop will only be used if *itr1 is the beginning of the sequence, which means each element will only be visited 2 or 3 times. +int longestConsecutive(std::vector& nums) { + int len=0; + Node* hash_table[TABLE_SIZE]; + // initialize the table + for(int i=0;inum-1) can't be found + if(identify(current->number - 1, hash_table)){ + int x = current->number + 1; + // now that current->num is the beginning of a sequence, how about current->num + 1? + while(identify(x, hash_table)){ + x++; + } + // when we get out of the above while loop, it's time to update len, if needed. + if( (x - current->number) > len){ + len = x - current->number; + } + } + current = current->next; + // we still need a while here, rather than an if. + // so that we can find the next non-empty bucket. + while(current == nullptr){ + i++; + if(i nums = {100, 4, 200, 1, 3, 2}; + std::vector nums = {0,3,7,2,5,8,4,6,0,1}; + //std::vector nums = {100, 4, 200, 201, 202, 203, 205, 204, 1, 3, 2}; + int size = nums.size(); + std::cout<< "for vector {"; + for(int i=0;i +#include +#include + + // Question: why is this an O(n) solution when we have a nested loop? Because the inner while loop will only be used if *itr1 is the beginning of the sequence, which means each element will only be visited 2 or 3 times. + int longestConsecutive(std::vector& nums) { + int len=0; + std::unordered_set set1; + int size = nums.size(); + // store unique elements in nums in set1 + for(int i=0;i::iterator itr1 = set1.begin(); + while(itr1!=set1.end()){ + // clearly *itr1 is in the set, because that's the meaning of iteration; and if *itr1-1 is not in the set, then we know *itr1 is the beginning of a sequence. + if(!set1.count(*itr1-1)){ + int x = *itr1+1; + // now that *itr1 is the beginning of a sequence, how about *itr1+1? + while(set1.count(x)){ + x++; + } + if(x-*itr1>len){ + len = x-*itr1; + } + } + itr1++; + } + return len; + } + +int main() { + //std::vector nums = {100, 4, 200, 1, 3, 2}; + std::vector nums = {0,3,7,2,5,8,4,6,0,1}; + //std::vector nums = {100, 4, 200, 201, 202, 203, 205, 204, 1, 3, 2}; + int size = nums.size(); + std::cout<< "for vector {"; + for(int i=0;i +#include + +#define TABLE_SIZE 1024 + +class Node{ +public: + int number; + Node* next; +}; + +// insert num into table +void insert(int num, Node** table){ + int key; + key = abs(num%TABLE_SIZE); // key will be something in between 0 and (TABLE_SIZE-1); num can be negative + if(table[key] == nullptr){ + // create the first node for this linked list + Node* node; + node = new Node; + node->number = num; + node->next = nullptr; + table[key] = node; + }else{ + // insert a node to the beginning of this linked list + Node* node; + node = new Node; + node->number = num; + node->next = table[key]; + table[key] = node; + } +} + +// search the hash table and see if we can find this num. +bool identify(int num, Node** table){ + int key = abs(num%TABLE_SIZE); + // search num in table[key]; + Node* node = table[key]; + while(node != nullptr){ + if(node->number == num){ + return true; + } + node = node->next; + } + // if not found, return false; + return false; +} + +// Question: why is this an O(n) solution when we have a nested loop? Because the inner while loop will only be used if *itr1 is the beginning of the sequence, which means each element will only be visited 2 or 3 times. +int longestConsecutive(std::vector& nums) { + int len=0; + Node* hash_table[TABLE_SIZE]; + // initialize the table + for(int i=0;inum-1) can't be found + if(!identify(current->number - 1, hash_table)){ + int x = current->number + 1; + // now that current->num is the beginning of a sequence, how about current->num + 1? + while(identify(x, hash_table)){ + x++; + } + // when we get out of the above while loop, it's time to update len, if needed. + if( (x - current->number) > len){ + len = x - current->number; + } + } + current = current->next; + // we still need a while here, rather than an if. + // so that we can find the next non-empty bucket. + while(current == nullptr){ + i++; + if(i nums = {100, 4, 200, 1, 3, 2}; + std::vector nums = {100, 4, 200, 1, 3, 2, 2, 2, 2, 3}; + //std::vector nums = {100, 4, 200, 1, 3, 2, 5, 6}; + //std::vector nums = {0,3,7,2,5,8,4,6,0,1}; + //std::vector nums = {100, 4, 200, 201, 202, 203, 205, 204, 1, 3, 2}; + int size = nums.size(); + std::cout<< "for vector {"; + for(int i=0;i +#include + +#define TABLE_SIZE 1024 + +class Node{ +public: + int number; + Node* next; +}; + +// insert num into table +void insert(int num, Node** table){ + int key; + key = abs(num%TABLE_SIZE); // key will be something in between 0 and (TABLE_SIZE-1); num can be negative + if(table[key] == nullptr){ + // create the first node for this linked list + Node* node; + node = new Node; + node->number = num; + node->next = nullptr; + table[key] = node; + }else{ + // insert a node to the beginning of this linked list + Node* node; + node = new Node; + node->number = num; + node->next = table[key]; + table[key] = node; + } +} + +// search the hash table and see if we can find this num. +bool identify(int num, Node** table){ + int key = abs(num%TABLE_SIZE); + // search num in table[key]; + Node* node = table[key]; + while(node != nullptr){ + if(node->number == num){ + return true; + } + node = node->next; + } + // if not found, return false; + return false; +} + +// Question: why is this an O(n) solution when we have a nested loop? Because the inner while loop will only be used if *itr1 is the beginning of the sequence, which means each element will only be visited 2 or 3 times. +int longestConsecutive(std::vector& nums) { + int len=0; + Node* hash_table[TABLE_SIZE]; + // initialize the table + for(int i=0;inum-1) can't be found + if(!identify(current->number - 1, hash_table)){ + int x = current->number + 1; + // now that current->num is the beginning of a sequence, how about current->num + 1? + while(identify(x, hash_table)){ + x++; + } + // when we get out of the above while loop, it's time to update len, if needed. + if( (x - current->number) > len){ + len = x - current->number; + } + } + current = current->next; + // we still need a while here, rather than an if. + // so that we can find the next non-empty bucket. + while(current == nullptr){ + i++; + if(i nums = {100, 4, 200, 1, 3, 2}; + //std::vector nums = {100, 4, 200, 1, 3, 2, 2, 2, 2, 3}; + //std::vector nums = {100, 4, 200, 1, 3, 2, 5, 6}; + //std::vector nums = {0,3,7,2,5,8,4,6,0,1}; + //std::vector nums = {100, 4, 200, 201, 202, 203, 205, 204, 1, 3, 2}; + std::vector nums = {-3,0,1,2,3,-2,-1,-5}; + int size = nums.size(); + std::cout<< "for vector {"; + for(int i=0;i