{"task_id": "CPP/0", "prompt": "/*\nCheck if in given vector of numbers, are any two numbers closer to each other than\ngiven threshold.\n>>> has_close_elements({1.0, 2.0, 3.0}, 0.5)\nfalse\n>>> has_close_elements({1.0, 2.8, 3.0, 4.0, 5.0, 2.0}, 0.3)\ntrue\n*/\n#include\n#include\n#include\nusing namespace std;\nbool has_close_elements(vector numbers, float threshold){\n", "canonical_solution": " int i,j;\n \n for (i=0;i\nint main(){\n vector a={1.0, 2.0, 3.9, 4.0, 5.0, 2.2};\n assert (has_close_elements(a, 0.3)==true);\n assert (has_close_elements(a, 0.05) == false);\n\n assert (has_close_elements({1.0, 2.0, 5.9, 4.0, 5.0}, 0.95) == true);\n assert (has_close_elements({1.0, 2.0, 5.9, 4.0, 5.0}, 0.8) ==false);\n assert (has_close_elements({1.0, 2.0, 3.0, 4.0, 5.0}, 2.0) == true);\n assert (has_close_elements({1.1, 2.2, 3.1, 4.1, 5.1}, 1.0) == true);\n assert (has_close_elements({1.1, 2.2, 3.1, 4.1, 5.1}, 0.5) == false);\n \n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool has_close_elements(vector numbers, float threshold){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (has_close_elements({1.0, 2.0, 3.0}, 0.5) == false && \"failure 1\");\n assert (has_close_elements({1.0, 2.8, 3.0, 4.0, 5.0, 2.0}, 0.3) && \"failure 2\") ;\n}\n"} {"task_id": "CPP/1", "prompt": "/*\nInput to this function is a string containing multiple groups of nested parentheses. Your goal is to\nseparate those group into separate strings and return the vector of those.\nSeparate groups are balanced (each open brace is properly closed) and not nested within each other\nIgnore any spaces in the input string.\n>>> separate_paren_groups(\"( ) (( )) (( )( ))\")\n{\"()\", \"(())\", \"(()())\"}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector separate_paren_groups(string paren_string){\n", "canonical_solution": " vector all_parens;\n string current_paren;\n int level=0;\n char chr;\n int i;\n for (i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\n#include\nvector separate_paren_groups(string paren_string){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> truncate_number(3.5)\n0.5\n*/\n#include\n#include\nusing namespace std;\nfloat truncate_number(float number){\n", "canonical_solution": " return number-int(number);\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (truncate_number(3.5) == 0.5); \n assert (abs(truncate_number(1.33) - 0.33) < 1e-4);\n assert (abs(truncate_number(123.456) - 0.456) < 1e-4);\n}", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nfloat truncate_number(float number){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (truncate_number(3.5) == 0.5); \n}\n"} {"task_id": "CPP/3", "prompt": "/*\nYou\"re given a vector of deposit and withdrawal operations on a bank account that starts with\nzero balance. Your task is to detect if at any point the balance of account falls below zero, and\nat that point function should return true. Otherwise it should return false.\n>>> below_zero({1, 2, 3})\nfalse\n>>> below_zero({1, 2, -4, 5})\ntrue\n*/\n#include\n#include\nusing namespace std;\nbool below_zero(vector operations){\n", "canonical_solution": " int num=0;\n for (int i=0;i\nint main(){\n assert (below_zero({}) == false);\n assert (below_zero({1, 2, -3, 1, 2, -3}) == false);\n assert (below_zero({1, 2, -4, 5, 6}) == true);\n assert (below_zero({1, -1, 2, -2, 5, -5, 4, -4}) == false);\n assert (below_zero({1, -1, 2, -2, 5, -5, 4, -5}) == true);\n assert (below_zero({1, -2, 2, -2, 5, -5, 4, -4}) == true);\n}", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\n#include\nbool below_zero(vector operations){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (below_zero({1, 2, 3}) == false);\n assert (below_zero({1, 2, -4, 5}) == true);\n}\n"} {"task_id": "CPP/4", "prompt": "/*\nFor a given vector of input numbers, calculate Mean Absolute Deviation\naround the mean of this dataset.\nMean Absolute Deviation is the average absolute difference between each\nelement and a centerpoint (mean in this case):\nMAD = average | x - x_mean |\n>>> mean_absolute_deviation({1.0, 2.0, 3.0, 4.0})\n1.0\n*/\n#include\n#include\n#include\nusing namespace std;\nfloat mean_absolute_deviation(vector numbers){\n", "canonical_solution": " float sum=0;\n float avg,msum,mavg;\n int i=0;\n for (i=0;i\nint main(){\n assert (abs(mean_absolute_deviation({1.0, 2.0, 3.0}) - 2.0/3.0) < 1e-4);\n assert (abs(mean_absolute_deviation({1.0, 2.0, 3.0, 4.0}) - 1.0) < 1e-4);\n assert (abs(mean_absolute_deviation({1.0, 2.0, 3.0, 4.0, 5.0}) - 6.0/5.0) < 1e-4);\n}", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nfloat mean_absolute_deviation(vector numbers){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (abs(mean_absolute_deviation({1.0, 2.0, 3.0, 4.0}) - 1.0) < 1e-4);\n}\n"} {"task_id": "CPP/5", "prompt": "/*\nInsert a number \"delimeter\" between every two consecutive elements of input vector `numbers\"\n>>> intersperse({}, 4)\n{}\n>>> intersperse({1, 2, 3}, 4)\n{1, 4, 2, 4, 3}\n*/\n#include\n#include\nusing namespace std;\nvector intersperse(vector numbers, int delimeter){ \n", "canonical_solution": " vector out={};\n if (numbers.size()>0) out.push_back(numbers[0]);\n for (int i=1;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\n#include\n#include\n#include\nvector intersperse(vector numbers, int delimeter){ \n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> parse_nested_parens(\"(()()) ((())) () ((())()())\")\n{2, 3, 1, 3}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector parse_nested_parens(string paren_string){\n", "canonical_solution": " vector all_levels;\n string current_paren;\n int level=0,max_level=0;\n char chr;\n int i;\n for (i=0;imax_level) max_level=level;\n current_paren+=chr;\n }\n if (chr==')')\n {\n level-=1;\n current_paren+=chr;\n if (level==0){\n all_levels.push_back(max_level);\n current_paren=\"\";\n max_level=0;\n }\n }\n }\n return all_levels;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\n#include\nvector parse_nested_parens(string paren_string){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> filter_by_substring({}, \"a\")\n{}\n>>> filter_by_substring({\"abc\", \"bacd\", \"cde\", \"vector\"}, \"a\")\n{\"abc\", \"bacd\", \"vector\"}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector filter_by_substring(vector strings, string substring){\n", "canonical_solution": " vector out;\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\n#include\nvector filter_by_substring(vector strings, string substring){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> sum_product({})\n(0, 1)\n>>> sum_product({1, 2, 3, 4})\n(10, 24)\n*/\n#include\n#include\nusing namespace std;\nvector sum_product(vector numbers){\n", "canonical_solution": " int sum=0,product=1;\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\n#include\n#include\n#include\nvector sum_product(vector numbers){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> rolling_max({1, 2, 3, 2, 3, 4, 2})\n{1, 2, 3, 3, 3, 4, 4}\n*/\n#include\n#include\nusing namespace std;\nvector rolling_max(vector numbers){\n", "canonical_solution": " vector out;\n int max=0;\n for (int i=0;imax) max=numbers[i];\n out.push_back(max);\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\n#include\n#include\n#include\nvector rolling_max(vector numbers){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\nbool is_palindrome(string str){\n //Test if given string is a palindrome \n string s(str.rbegin(),str.rend());\n return s==str;\n}\nstring make_palindrome(string str){\n /*\n Find the shortest palindrome that begins with a supplied string. \n Algorithm idea is simple: - Find the longest postfix of supplied string that is a palindrome. \n - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.\n >>> make_palindrome(\"\") \n \"\" \n >>> make_palindrome(\"cat\") \n \"catac\" \n >>> make_palindrome(\"cata\") \n \"catac\" \n */\n", "canonical_solution": " int i;\n for (i=0;i\nint main(){\n assert (make_palindrome(\"\") == \"\");\n assert (make_palindrome(\"x\") == \"x\");\n assert (make_palindrome(\"xyz\") == \"xyzyx\");\n assert (make_palindrome(\"xyx\") == \"xyx\") ;\n assert (make_palindrome(\"jerry\") == \"jerryrrej\");\n}\n\n\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\n#include\nbool is_palindrome(string str){\n string s(str.rbegin(),str.rend());\n return s==str;\n}\nstring make_palindrome(string str){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (make_palindrome(\"\") == \"\");\n assert (make_palindrome(\"cat\") == \"catac\");\n assert (make_palindrome(\"cata\") == \"catac\");\n}\n"} {"task_id": "CPP/11", "prompt": "/*\nInput are two strings a and b consisting only of 1s and 0s.\nPerform binary XOR on these inputs and return result also as a string.\n>>> string_xor(\"010\", \"110\")\n\"100\"\n*/\n#include\n#include\nusing namespace std;\nstring string_xor(string a,string b){\n", "canonical_solution": " string output=\"\";\n for (int i=0;(i=a.length()) \n {\n output+=b[i];\n }\n else output+=a[i];\n }\n }\n return output;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (string_xor(\"111000\", \"101010\") == \"010010\");\n assert (string_xor(\"1\", \"1\") == \"0\");\n assert (string_xor(\"0101\", \"0000\") == \"0101\");\n\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\n#include\nstring string_xor(string a,string b){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (string_xor(\"010\", \"110\") == \"100\");\n}\n"} {"task_id": "CPP/12", "prompt": "/*\nOut of vector of strings, return the longest one. Return the first one in case of multiple\nstrings of the same length. Return None in case the input vector is empty.\n>>> longest({})\n\n>>> longest({\"a\", \"b\", \"c\"})\n\"a\"\n>>> longest({\"a\", \"bb\", \"ccc\"})\n\"ccc\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring longest(vector strings){\n", "canonical_solution": " string out;\n for (int i=0;iout.length()) out=strings[i];\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (longest({}) == \"\");\n assert (longest({\"x\", \"y\", \"z\"}) == \"x\");\n assert (longest({\"x\", \"yyy\", \"zzzz\", \"www\", \"kkkk\", \"abc\"}) == \"zzzz\");\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\n#include\nstring longest(vector strings){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (longest({}) == \"\");\n assert (longest({\"a\", \"b\", \"c\"}) == \"a\");\n assert (longest({\"a\", \"bb\", \"ccc\"}) == \"ccc\");\n}\n"} {"task_id": "CPP/13", "prompt": "/*\nReturn a greatest common divisor of two integers a and b\n>>> greatest_common_divisor(3, 5)\n1\n>>> greatest_common_divisor(25, 15)\n5\n*/\n#include\nusing namespace std;\nint greatest_common_divisor(int a, int b){\n", "canonical_solution": " int out,m;\n while (true){\n if (a\nint main(){\n assert (greatest_common_divisor(3, 7) == 1);\n assert (greatest_common_divisor(10, 15) == 5);\n assert (greatest_common_divisor(49, 14) == 7);\n assert (greatest_common_divisor(144, 60) == 12);\n}\n", "declaration": "#include\nusing namespace std;\n#include\n#include\n#include\nint greatest_common_divisor(int a, int b){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (greatest_common_divisor(3, 5) == 1);\n assert (greatest_common_divisor(25, 15) == 5);\n}\n"} {"task_id": "CPP/14", "prompt": "/*\nReturn vector of all prefixes from shortest to longest of the input string\n>>> all_prefixes(\"abc\")\n{\"a\", \"ab\", \"abc\"}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector all_prefixes(string str){\n", "canonical_solution": " vector out;\n string current=\"\";\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\n#include\nvector all_prefixes(string str){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> string_sequence(0)\n\"0\"\n>>> string_sequence(5)\n\"0 1 2 3 4 5\"\n*/\n#include\n#include\nusing namespace std;\nstring string_sequence(int n){\n", "canonical_solution": " string out=\"0\";\n for (int i=1;i<=n;i++)\n out=out+\" \"+to_string(i);\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (string_sequence(0) == \"0\");\n assert (string_sequence(3) == \"0 1 2 3\");\n assert (string_sequence(10) == \"0 1 2 3 4 5 6 7 8 9 10\");\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring string_sequence(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (string_sequence(0) == \"0\");\n assert (string_sequence(5) == \"0 1 2 3 4 5\");\n}\n"} {"task_id": "CPP/16", "prompt": "/*\nGiven a string, find out how many distinct characters (regardless of case) does it consist of\n>>> count_distinct_characters(\"xyzXYZ\")\n3\n>>> count_distinct_characters(\"Jerry\")\n4\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nint count_distinct_characters(string str){ \n", "canonical_solution": " vector distinct={};\n transform(str.begin(),str.end(),str.begin(),::tolower);\n for (int i=0;i\nint main(){\n assert (count_distinct_characters(\"\") == 0);\n assert (count_distinct_characters(\"abcde\") == 5);\n assert (count_distinct_characters(\"abcdecadeCADE\") == 5);\n assert (count_distinct_characters(\"aaaaAAAAaaaa\") == 1);\n assert (count_distinct_characters(\"Jerry jERRY JeRRRY\") == 5);\n}\n", "declaration": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nint count_distinct_characters(string str){ \n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (count_distinct_characters(\"xyzXYZ\") == 3);\n assert (count_distinct_characters(\"Jerry\") == 4);\n}\n"} {"task_id": "CPP/17", "prompt": "/*\nInput to this function is a string representing musical notes in a special ASCII format.\nYour task is to parse this string and return vector of integers corresponding to how many beats does each\nnot last.\n\nHere is a legend:\n\"o\" - whole note, lasts four beats\n\"o|\" - half note, lasts two beats\n\".|\" - quater note, lasts one beat\n\n>>> parse_music(\"o o| .| o| o| .| .| .| .| o o\")\n{4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector parse_music(string music_string){ \n", "canonical_solution": " string current=\"\";\n vector out={};\n if (music_string.length()>0)\n music_string=music_string+' ';\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector parse_music(string music_string){ \n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> how_many_times(\"\", \"a\")\n0\n>>> how_many_times(\"aaa\", \"a\")\n3\n>>> how_many_times(\"aaaa\", \"aa\")\n3\n*/\n#include\n#include\nusing namespace std;\nint how_many_times(string str,string substring){\n", "canonical_solution": " int out=0;\n if (str.length()==0) return 0;\n for (int i=0;i<=str.length()-substring.length();i++)\n if (str.substr(i,substring.length())==substring)\n out+=1;\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (how_many_times(\"\", \"x\") == 0);\n assert (how_many_times(\"xyxyxyx\", \"x\") == 4);\n assert (how_many_times(\"cacacacac\", \"cac\") == 4);\n assert (how_many_times(\"john doe\", \"john\") == 1);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint how_many_times(string str,string substring){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (how_many_times(\"\", \"a\") == 0);\n assert (how_many_times(\"aaa\", \"a\") == 3);\n assert (how_many_times(\"aaaa\", \"aa\") == 3);\n}\n"} {"task_id": "CPP/19", "prompt": "/*\nInput is a space-delimited string of numberals from \"zero\" to \"nine\".\nValid choices are \"zero\", \"one\", 'two\", 'three\", \"four\", \"five\", 'six\", 'seven\", \"eight\" and \"nine\".\nReturn the string with numbers sorted from smallest to largest\n>>> sort_numbers('three one five\")\n\"one three five\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring sort_numbers(string numbers){\n", "canonical_solution": " map tonum={{\"zero\",0},{\"one\",1},{\"two\",2},{\"three\",3},{\"four\",4},{\"five\",5},{\"six\",6},{\"seven\",7},{\"eight\",8},{\"nine\",9}};\n map numto={{0,\"zero\"},{1,\"one\"},{2,\"two\"},{3,\"three\"},{4,\"four\"},{5,\"five\"},{6,\"six\"},{7,\"seven\"},{8,\"eight\"},{9,\"nine\"}};\n int count[10];\n for (int i=0;i<10;i++)\n count[i]=0;\n string out=\"\",current=\"\";\n if (numbers.length()>0) numbers=numbers+' ';\n for (int i=0;i0) out.pop_back();\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (sort_numbers(\"\") == \"\");\n assert (sort_numbers(\"three\") == \"three\");\n assert (sort_numbers(\"three five nine\") == \"three five nine\");\n assert (sort_numbers(\"five zero four seven nine eight\") == \"zero four five seven eight nine\");\n assert (sort_numbers(\"six five four three two one zero\") == \"zero one two three four five six\");\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring sort_numbers(string numbers){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (sort_numbers(\"three one five\") == \"one three five\");\n}\n"} {"task_id": "CPP/20", "prompt": "/*\nFrom a supplied vector of numbers (of length at least two) select and return two that are the closest to each\nother and return them in order (smaller number, larger number).\n>>> find_closest_elements({1.0, 2.0, 3.0, 4.0, 5.0, 2.2})\n(2.0, 2.2)\n>>> find_closest_elements({1.0, 2.0, 3.0, 4.0, 5.0, 2.0})\n(2.0, 2.0)\n*/\n#include\n#include\n#include\nusing namespace std;\nvector find_closest_elements(vector numbers){\n", "canonical_solution": " vector out={};\n for (int i=0;iout[1])\n out={out[1],out[0]};\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i1e-4) return false;\n }\n return true;\n}\nint main(){\n assert (issame(find_closest_elements({1.0, 2.0, 3.9, 4.0, 5.0, 2.2}) , {3.9, 4.0}));\n assert (issame(find_closest_elements({1.0, 2.0, 5.9, 4.0, 5.0}) , {5.0, 5.9} ));\n assert (issame(find_closest_elements({1.0, 2.0, 3.0, 4.0, 5.0, 2.2}) ,{2.0, 2.2}));\n assert (issame(find_closest_elements({1.0, 2.0, 3.0, 4.0, 5.0, 2.0}) ,{2.0, 2.0}));\n assert (issame(find_closest_elements({1.1, 2.2, 3.1, 4.1, 5.1}) , {2.2, 3.1}));\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector find_closest_elements(vector numbers){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i1e-4) return false;\n }\n return true;\n}\nint main(){\n assert (issame(find_closest_elements({1.0, 2.0, 3.0, 4.0, 5.0, 2.2}) ,{2.0, 2.2}));\n assert (issame(find_closest_elements({1.0, 2.0, 3.0, 4.0, 5.0, 2.0}) ,{2.0, 2.0}));\n}\n"} {"task_id": "CPP/21", "prompt": "/*\nGiven vector of numbers (of at least two elements), apply a linear transform to that vector,\nsuch that the smallest number will become 0 and the largest will become 1\n>>> rescale_to_unit({1.0, 2.0, 3.0, 4.0, 5.0})\n{0.0, 0.25, 0.5, 0.75, 1.0}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector rescale_to_unit(vector numbers){ \n", "canonical_solution": " float min=100000,max=-100000;\n for (int i=0;imax) max=numbers[i];\n }\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i1e-4) return false;\n }\n return true;\n}\nint main(){\n assert (issame(rescale_to_unit({2.0, 49.9}) , {0.0, 1.0}));\n assert (issame(rescale_to_unit({100.0, 49.9}) ,{1.0, 0.0})); \n assert (issame(rescale_to_unit({1.0, 2.0, 3.0, 4.0, 5.0}) , {0.0, 0.25, 0.5, 0.75, 1.0}));\n assert (issame(rescale_to_unit({2.0, 1.0, 5.0, 3.0, 4.0}) , {0.25, 0.0, 1.0, 0.5, 0.75}));\n assert (issame(rescale_to_unit({12.0, 11.0, 15.0, 13.0, 14.0}) ,{0.25, 0.0, 1.0, 0.5, 0.75}));\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector rescale_to_unit(vector numbers){ \n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i1e-4) return false;\n }\n return true;\n}\nint main(){\n assert (issame(rescale_to_unit({1.0, 2.0, 3.0, 4.0, 5.0}) , {0.0, 0.25, 0.5, 0.75, 1.0}));\n}\n"} {"task_id": "CPP/22", "prompt": "/*\nFilter given vector of any python values only for integers\n>>> filter_integers({\"a\", 3.14, 5})\n{5}\n>>> filter_integers({1, 2, 3, \"abc\", {}, {}})\n{1, 2, 3}\n*/\n#include\n#include\n#include\n#include\n#include\ntypedef std::list list_any;\nusing namespace std;\nvector filter_integers(list_any values){\n", "canonical_solution": " list_any::iterator it;\n boost::any anyone;\n vector out;\n for (it=values.begin();it!=values.end();it++)\n {\n anyone=*it;\n if( anyone.type() == typeid(int) )\n out.push_back(boost::any_cast(*it));\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\n#include\n#include\ntypedef std::list list_any;\nusing namespace std;\n#include\n#include\nvector filter_integers(list_any values){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> strlen(\"\")\n0\n>>> strlen(\"abc\")\n3\n*/\n#include\n#include\nusing namespace std;\nint strlen(string str){\n", "canonical_solution": " return str.length();\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (strlen(\"\") == 0);\n assert (strlen(\"x\") == 1);\n assert (strlen(\"asdasnakj\") == 9);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint strlen(string str){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (strlen(\"\") == 0);\n assert (strlen(\"abc\") == 3);\n}\n"} {"task_id": "CPP/24", "prompt": "/*\nFor a given number n, find the largest number that divides n evenly, smaller than n\n>>> largest_divisor(15)\n5\n*/\n#include\nusing namespace std;\nint largest_divisor(int n){\n", "canonical_solution": " for (int i=2;i*i<=n;i++)\n if (n%i==0) return n/i;\n return 1;\n\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (largest_divisor(3) == 1);\n assert (largest_divisor(7) == 1);\n assert (largest_divisor(10) == 5);\n assert (largest_divisor(100) == 50);\n assert (largest_divisor(49) == 7);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint largest_divisor(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (largest_divisor(15) == 5);\n}\n"} {"task_id": "CPP/25", "prompt": "/*\nReturn vector of prime factors of given integer in the order from smallest to largest.\nEach of the factors should be vectored number of times corresponding to how many times it appeares in factorization.\nInput number should be equal to the product of all factors\n>>> factorize(8)\n{2, 2, 2}\n>>> factorize(25)\n{5, 5}\n>>> factorize(70)\n{2, 5, 7}\n*/\n#include\n#include\nusing namespace std;\nvector factorize(int n){\n", "canonical_solution": " vector out={};\n for (int i=2;i*i<=n;i++)\n if (n%i==0)\n {\n n=n/i;\n out.push_back(i);\n i-=1;\n }\n out.push_back(n);\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\nvector factorize(int n){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> remove_duplicates({1, 2, 3, 2, 4})\n{1, 3, 4}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector remove_duplicates(vector numbers){\n", "canonical_solution": " vector out={};\n vector has1={};\n vector has2={};\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector remove_duplicates(vector numbers){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> flip_case(\"Hello\")\n\"hELLO\"\n*/\n#include\n#include\nusing namespace std;\nstring filp_case(string str){\n", "canonical_solution": " string out=\"\";\n for (int i=0;i=97 and w<=122) {w-=32;}\n else\n if (w>=65 and w<=90){ w+=32;}\n out=out+w;\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (filp_case(\"\") == \"\");\n assert (filp_case(\"Hello!\") == \"hELLO!\");\n assert (filp_case(\"These violent delights have violent ends\") == \"tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS\");\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring filp_case(string str){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (filp_case(\"Hello\") == \"hELLO\");\n}\n"} {"task_id": "CPP/28", "prompt": "/*\nConcatenate vector of strings into a single string\n>>> concatenate({})\n\"\"\n>>> concatenate({\"a\", \"b\", \"c\"})\n\"abc\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring concatenate(vector strings){\n", "canonical_solution": " string out=\"\";\n for (int i=0;i\nint main(){\n assert (concatenate({}) == \"\");\n assert (concatenate({\"x\", \"y\", \"z\"}) == \"xyz\");\n assert (concatenate({\"x\", \"y\", \"z\", \"w\", \"k\"}) == \"xyzwk\");\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring concatenate(vector strings){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (concatenate({}) == \"\");\n assert (concatenate({\"a\", \"b\", \"c\"}) == \"abc\");\n}\n"} {"task_id": "CPP/29", "prompt": "/*\nFilter an input vector of strings only for ones that start with a given prefix.\n>>> filter_by_prefix({}, \"a\")\n{}\n>>> filter_by_prefix({\"abc\", \"bcd\", \"cde\", \"vector\"}, \"a\")\n{\"abc\", \"vector\"}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector filter_by_prefix(vector strings, string prefix){\n", "canonical_solution": " vector out={};\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector filter_by_prefix(vector strings, string prefix){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> get_positive({-1, 2, -4, 5, 6})\n{2, 5, 6}\n>>> get_positive({5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10})\n{5, 3, 2, 3, 9, 123, 1}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector get_positive(vector l){\n", "canonical_solution": " vector out={};\n for (int i=0;i0) out.push_back(l[i]);\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i1e-4) return false;\n }\n return true;\n}\nint main(){\n assert (issame(get_positive({-1, -2, 4, 5, 6}) , {4, 5, 6} ));\n assert (issame(get_positive({5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10}) , {5, 3, 2, 3, 3, 9, 123, 1}));\n assert (issame(get_positive({-1, -2}) , {} ));\n assert (issame(get_positive({}) , {}));\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector get_positive(vector l){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i1e-4) return false;\n }\n return true;\n}\nint main(){\n assert (issame(get_positive({-1, 2, -4, 5, 6}) , {2, 5, 6} ));\n assert (issame(get_positive({5, 3, -5, 2, -3,3, 9, 0, 123, 1, -10}) , {5, 3, 2, 3, 9, 123, 1}));\n}\n"} {"task_id": "CPP/31", "prompt": "/*\nReturn true if a given number is prime, and false otherwise.\n>>> is_prime(6)\nfalse\n>>> is_prime(101)\ntrue\n>>> is_prime(11)\ntrue\n>>> is_prime(13441)\ntrue\n>>> is_prime(61)\ntrue\n>>> is_prime(4)\nfalse\n>>> is_prime(1)\nfalse\n*/\n#include\nusing namespace std;\nbool is_prime(long long n){\n", "canonical_solution": " if (n<2) return false;\n for (long long i=2;i*i<=n;i++)\n if (n%i==0) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (is_prime(6) == false);\n assert (is_prime(101) == true);\n assert (is_prime(11) == true);\n assert (is_prime(13441) == true);\n assert (is_prime(61) == true);\n assert (is_prime(4) == false);\n assert (is_prime(1) == false);\n assert (is_prime(5) == true);\n assert (is_prime(11) == true);\n assert (is_prime(17) == true);\n assert (is_prime(5 * 17) == false);\n assert (is_prime(11 * 7) == false);\n assert (is_prime(13441 * 19) == false);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nbool is_prime(long long n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (is_prime(6) == false);\n assert (is_prime(101) == true);\n assert (is_prime(11) == true);\n assert (is_prime(13441) == true);\n assert (is_prime(61) == true);\n assert (is_prime(4) == false);\n assert (is_prime(1) == false);\n}\n"} {"task_id": "CPP/32", "prompt": "#include\n#include\n#include\nusing namespace std;\ndouble poly(vector xs, double x){\n /* \n Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n \n */\n double sum=0;\n int i;\n for (i=0;i xs){\n /*\n xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. \n Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution.\n >>> round(find_zero([1, 2]), 2) #f(x) = 1 + 2x \n -0.5 \n >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 \n 1.0\n */\n", "canonical_solution": " double ans=0;\n double value;\n value=poly(xs,ans);\n while (abs(value)>1e-6)\n {\n double driv=0;\n for (int i=1;i\nint main(){\n \n double solution;\n int ncoeff;\n for (int i=0;i<100;i++)\n {\n ncoeff = 2 * (1+rand()%4);\n vector coeffs = {};\n for (int j=0;j\n#include\n#include\nusing namespace std;\n#include\n#include\ndouble poly(vector xs, double x){\n double sum=0;\n int i;\n for (i=0;i xs){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (find_zero({1,2})+0.5<1e-4);\n assert (find_zero({-6,11,-6,1})-1<1e-4);\n}\n"} {"task_id": "CPP/33", "prompt": "/*\nThis function takes a vector l and returns a vector l' such that\nl' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\nto the values of the corresponding indicies of l, but sorted.\n>>> sort_third({1, 2, 3})\n{1, 2, 3}\n>>> sort_third({5, 6, 3, 4, 8, 9, 2})\n{2, 6, 3, 4, 8, 9, 5}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector sort_third(vector l){\n", "canonical_solution": " vector third={};\n int i;\n for (i=0;i*3 out={};\n for (i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector sort_third(vector l){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> unique({5, 3, 5, 2, 3, 3, 9, 0, 123})\n{0, 2, 3, 5, 9, 123}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector unique(vector l){\n", "canonical_solution": " vector out={};\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector unique(vector l){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> max_element({1, 2, 3})\n3\n>>> max_element({5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10})\n123\n*/\n#include\n#include\n#include\nusing namespace std;\nfloat max_element(vector l){\n", "canonical_solution": " float max=-10000;\n for (int i=0;i\nint main(){\n assert (abs(max_element({1, 2, 3})- 3)<1e-4);\n assert (abs(max_element({5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10})- 124)<1e-4);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nfloat max_element(vector l){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (abs(max_element({1, 2, 3})- 3)<1e-4);\n assert (abs(max_element({5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10})- 123)<1e-4);\n}\n"} {"task_id": "CPP/36", "prompt": "/*\nReturn the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n>>> fizz_buzz(50)\n0\n>>> fizz_buzz(78)\n2\n>>> fizz_buzz(79)\n3\n*/\n#include\nusing namespace std;\nint fizz_buzz(int n){\n", "canonical_solution": " int count=0;\n for (int i=0;i0)\n {\n if (q%10==7) count+=1;\n q=q/10;\n }\n } \n return count;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (fizz_buzz(50) == 0);\n assert (fizz_buzz(78) == 2);\n assert (fizz_buzz(79) == 3);\n assert (fizz_buzz(100) == 3);\n assert (fizz_buzz(200) == 6);\n assert (fizz_buzz(4000) == 192);\n assert (fizz_buzz(10000) == 639);\n assert (fizz_buzz(100000) == 8026);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint fizz_buzz(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (fizz_buzz(50) == 0);\n assert (fizz_buzz(78) == 2);\n assert (fizz_buzz(79) == 3);\n}\n"} {"task_id": "CPP/37", "prompt": "/*\nThis function takes a vector l and returns a vector l' such that\nl' is identical to l in the odd indicies, while its values at the even indicies are equal\nto the values of the even indicies of l, but sorted.\n>>> sort_even({1, 2, 3})\n{1, 2, 3}\n>>> sort_even({5, 6, 3, 4})\n{3, 6, 5, 4}\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nvector sort_even(vector l){\n", "canonical_solution": " vector out={};\n vector even={};\n for (int i=0;i*2\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i1e-4) return false;\n }\n return true;\n}\nint main(){\n assert (issame(sort_even({1, 2, 3}), {1, 2, 3}));\n assert (issame(sort_even({5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10}) , {-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123}));\n assert (issame(sort_even({5, 8, -12, 4, 23, 2, 3, 11, 12, -10}) , {-12, 8, 3, 4, 5, 2, 12, 11, 23, -10}));\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nvector sort_even(vector l){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i1e-4) return false;\n }\n return true;\n}\nint main(){\n assert (issame(sort_even({1, 2, 3}), {1, 2, 3}));\n assert (issame(sort_even({5, 6,3,4}) , {3,6,5,4}));\n}\n"} {"task_id": "CPP/38", "prompt": "#include\n#include\nusing namespace std;\nstring encode_cyclic(string s){ \n // returns encoded string by cycling groups of three characters. \n // split string to groups. Each of length 3.\n int l=s.length();\n int num=(l+2)/3;\n string x,output;\n int i;\n for (i=0;i*3\nint main(){\n \n for (int i=0;i<100;i++)\n {\n int l=10+rand()%11;\n string str=\"\";\n for (int j=0;j\n#include\n#include\nusing namespace std;\n#include\n#include\nstring encode_cyclic(string s){ \n int l=s.length();\n int num=(l+2)/3;\n string x,output;\n int i;\n for (i=0;i*3>> prime_fib(1)\n2\n>>> prime_fib(2)\n3\n>>> prime_fib(3)\n5\n>>> prime_fib(4)\n13\n>>> prime_fib(5)\n89\n*/\n#include\nusing namespace std;\nint prime_fib(int n){\n", "canonical_solution": " int f1,f2,m;\n f1=1;f2=2;\n int count=0;\n while (count\nint main(){\n assert (prime_fib(1) == 2);\n assert (prime_fib(2) == 3);\n assert (prime_fib(3) == 5);\n assert (prime_fib(4) == 13);\n assert (prime_fib(5) == 89);\n assert (prime_fib(6) == 233);\n assert (prime_fib(7) == 1597);\n assert (prime_fib(8) == 28657);\n assert (prime_fib(9) == 514229);\n assert (prime_fib(10) == 433494437);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint prime_fib(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (prime_fib(1) == 2);\n assert (prime_fib(2) == 3);\n assert (prime_fib(3) == 5);\n assert (prime_fib(4) == 13);\n assert (prime_fib(5) == 89);\n}\n"} {"task_id": "CPP/40", "prompt": "/*\ntriples_sum_to_zero takes a vector of integers as an input.\nit returns true if there are three distinct elements in the vector that\nsum to zero, and false otherwise.\n\n>>> triples_sum_to_zero({1, 3, 5, 0})\nfalse\n>>> triples_sum_to_zero({1, 3, -2, 1})\ntrue\n>>> triples_sum_to_zero({1, 2, 3, 7})\nfalse\n>>> triples_sum_to_zero({2, 4, -5, 3, 9, 7})\ntrue\n>>> triples_sum_to_zero({1})\nfalse\n*/\n#include\n#include\nusing namespace std;\nbool triples_sum_to_zero(vector l){\n", "canonical_solution": " for (int i=0;i\nint main(){\n assert (triples_sum_to_zero({1, 3, 5, 0}) == false);\n assert (triples_sum_to_zero({1, 3, 5, -1}) == false);\n assert (triples_sum_to_zero({1, 3, -2, 1}) == true);\n assert (triples_sum_to_zero({1, 2, 3, 7}) == false);\n assert (triples_sum_to_zero({1, 2, 5, 7}) == false);\n assert (triples_sum_to_zero({2, 4, -5, 3, 9, 7}) == true);\n assert (triples_sum_to_zero({1}) == false);\n assert (triples_sum_to_zero({1, 3, 5, -100}) == false);\n assert (triples_sum_to_zero({100, 3, 5, -100}) == false);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nbool triples_sum_to_zero(vector l){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (triples_sum_to_zero({1, 3, 5, 0}) == false);\n assert (triples_sum_to_zero({1, 3, -2, 1}) == true);\n assert (triples_sum_to_zero({1, 2, 3, 7}) == false);\n assert (triples_sum_to_zero({2, 4, -5, 3, 9, 7}) == true);\n}\n"} {"task_id": "CPP/41", "prompt": "/*\nImagine a road that's a perfectly straight infinitely long line.\nn cars are driving left to right; simultaneously, a different set of n cars\nare driving right to left. The two sets of cars start out being very far from\neach other. All cars move in the same speed. Two cars are said to collide\nwhen a car that's moving left to right hits a car that's moving right to left.\nHowever, the cars are infinitely sturdy and strong; as a result, they continue moving\nin their trajectory as if they did not collide.\n\nThis function outputs the number of such collisions.\n*/\n#include\nusing namespace std;\nint car_race_collision(int n){\n", "canonical_solution": " return n*n;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (car_race_collision(2) == 4);\n assert (car_race_collision(3) == 9);\n assert (car_race_collision(4) == 16);\n assert (car_race_collision(8) == 64);\n assert (car_race_collision(10) == 100);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint car_race_collision(int n){\n", "example_test": ""} {"task_id": "CPP/42", "prompt": "/*\nReturn vector with elements incremented by 1.\n>>> incr_vector({1, 2, 3})\n{2, 3, 4}\n>>> incr_vector({5, 3, 5, 2, 3, 3, 9, 0, 123})\n{6, 4, 6, 3, 4, 4, 10, 1, 124}\n*/\n#include\n#include\nusing namespace std;\nvector incr_list(vector l){\n", "canonical_solution": " for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\nvector incr_list(vector l){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> pairs_sum_to_zero({1, 3, 5, 0})\nfalse\n>>> pairs_sum_to_zero({1, 3, -2, 1})\nfalse\n>>> pairs_sum_to_zero({1, 2, 3, 7})\nfalse\n>>> pairs_sum_to_zero({2, 4, -5, 3, 5, 7})\ntrue\n>>> pairs_sum_to_zero({1})\nfalse\n*/\n#include\n#include\nusing namespace std;\nbool pairs_sum_to_zero(vector l){\n", "canonical_solution": " for (int i=0;i\nint main(){\n assert (pairs_sum_to_zero({1, 3, 5, 0}) == false);\n assert (pairs_sum_to_zero({1, 3, -2, 1}) == false);\n assert (pairs_sum_to_zero({1, 2, 3, 7}) == false);\n assert (pairs_sum_to_zero({2, 4, -5, 3, 5, 7}) == true);\n assert (pairs_sum_to_zero({1}) == false);\n assert (pairs_sum_to_zero({-3, 9, -1, 3, 2, 30}) == true);\n assert (pairs_sum_to_zero({-3, 9, -1, 3, 2, 31}) == true);\n assert (pairs_sum_to_zero({-3, 9, -1, 4, 2, 30}) == false);\n assert (pairs_sum_to_zero({-3, 9, -1, 4, 2, 31}) == false);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool pairs_sum_to_zero(vector l){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (pairs_sum_to_zero({1, 3, 5, 0}) == false);\n assert (pairs_sum_to_zero({1, 3, -2, 1}) == false);\n assert (pairs_sum_to_zero({1, 2, 3, 7}) == false);\n assert (pairs_sum_to_zero({2, 4, -5, 3, 5, 7}) == true);\n}\n"} {"task_id": "CPP/44", "prompt": "/*\nChange numerical base of input number x to base.\nreturn string representation after the conversion.\nbase numbers are less than 10.\n>>> change_base(8, 3)\n\"22\"\n>>> change_base(8, 2)\n\"1000\"\n>>> change_base(7, 2)\n\"111\"\n*/\n#include\n#include\nusing namespace std;\nstring change_base(int x,int base){\n", "canonical_solution": " string out=\"\";\n while (x>0)\n {\n out=to_string(x%base)+out;\n x=x/base;\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (change_base(8, 3) == \"22\");\n assert (change_base(9, 3) == \"100\");\n assert (change_base(234, 2) == \"11101010\");\n assert (change_base(16, 2) == \"10000\");\n assert (change_base(8, 2) == \"1000\");\n assert (change_base(7, 2) == \"111\");\n for (int x=2;x<8;x++)\n assert (change_base(x, x + 1) == to_string(x));\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring change_base(int x,int base){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (change_base(8, 3) == \"22\");\n assert (change_base(8, 2) == \"1000\");\n assert (change_base(7, 2) == \"111\");\n}\n"} {"task_id": "CPP/45", "prompt": "/*\nGiven length of a side and high return area for a triangle.\n>>> triangle_area(5, 3)\n7.5\n*/\n#include\n#include\nusing namespace std;\nfloat triangle_area(float a,float h){\n", "canonical_solution": "return (a*h)*0.5;\n\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (abs(triangle_area(5, 3) - 7.5)<1e-4);\n assert (abs(triangle_area(2, 2) - 2.0)<1e-4);\n assert (abs(triangle_area(10, 8) - 40.0)<1e-4);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nfloat triangle_area(float a,float h){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (abs(triangle_area(5, 3) - 7.5)<1e-4);\n}\n"} {"task_id": "CPP/46", "prompt": "/*\nThe Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\nfib4(0) -> 0\nfib4(1) -> 0\nfib4(2) -> 2\nfib4(3) -> 0\nfib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).\nPlease write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.\n>>> fib4(5)\n4\n>>> fib4(6)\n8\n>>> fib4(7)\n14\n*/\n#include\nusing namespace std;\nint fib4(int n){\n", "canonical_solution": " int f[100];\n f[0]=0;\n f[1]=0;\n f[2]=2;\n f[3]=0;\n for (int i=4;i<=n;i++)\n {\n f[i]=f[i-1]+f[i-2]+f[i-3]+f[i-4];\n }\n return f[n];\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (fib4(5) == 4);\n assert (fib4(8) == 28);\n assert (fib4(10) == 104);\n assert (fib4(12) == 386);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint fib4(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (fib4(5) == 4);\n assert (fib4(6) == 8);\n assert (fib4(7) == 14);\n}\n"} {"task_id": "CPP/47", "prompt": "/*\nReturn median of elements in the vector l.\n>>> median({3, 1, 2, 4, 5})\n3\n>>> median({-10, 4, 6, 1000, 10, 20})\n15.0\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nfloat median(vector l){\n", "canonical_solution": " sort(l.begin(),l.end());\n if (l.size()%2==1) return l[l.size()/2];\n return 0.5*(l[l.size()/2]+l[l.size()/2-1]);\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (abs(median({3, 1, 2, 4, 5}) - 3)<1e-4);\n assert (abs(median({-10, 4, 6, 1000, 10, 20}) -8.0)<1e-4);\n assert (abs(median({5}) - 5)<1e-4);\n assert (abs(median({6, 5}) - 5.5)<1e-4);\n assert (abs(median({8, 1, 3, 9, 9, 2, 7}) - 7)<1e-4 );\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nfloat median(vector l){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (abs(median({3, 1, 2, 4, 5}) - 3)<1e-4);\n assert (abs(median({-10, 4, 6, 1000, 10, 20}) -8.0)<1e-4);\n}\n"} {"task_id": "CPP/48", "prompt": "/*\nChecks if given string is a palindrome\n>>> is_palindrome(\"\")\ntrue\n>>> is_palindrome(\"aba\")\ntrue\n>>> is_palindrome(\"aaaaa\")\ntrue\n>>> is_palindrome(\"zbcd\")\nfalse\n*/\n#include\n#include\nusing namespace std;\nbool is_palindrome(string text){\n", "canonical_solution": " string pr(text.rbegin(),text.rend());\n return pr==text;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (is_palindrome(\"\") == true);\n assert (is_palindrome(\"aba\") == true);\n assert (is_palindrome(\"aaaaa\") == true);\n assert (is_palindrome(\"zbcd\") == false);\n assert (is_palindrome(\"xywyx\") == true);\n assert (is_palindrome(\"xywyz\") == false);\n assert (is_palindrome(\"xywzx\") == false);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool is_palindrome(string text){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (is_palindrome(\"\") == true);\n assert (is_palindrome(\"aba\") == true);\n assert (is_palindrome(\"aaaaa\") == true);\n assert (is_palindrome(\"zbcd\") == false);\n}\n"} {"task_id": "CPP/49", "prompt": "/*\nReturn 2^n modulo p (be aware of numerics).\n>>> modp(3, 5)\n3\n>>> modp(1101, 101)\n2\n>>> modp(0, 101)\n1\n>>> modp(3, 11)\n8\n>>> modp(100, 101)\n1\n*/\n#include\nusing namespace std;\nint modp(int n,int p){\n", "canonical_solution": " int out=1;\n for (int i=0;i\nint main(){\n assert (modp(3, 5) == 3);\n assert (modp(1101, 101) == 2);\n assert (modp(0, 101) == 1);\n assert (modp(3, 11) == 8);\n assert (modp(100, 101) == 1);\n assert (modp(30, 5) == 4);\n assert (modp(31, 5) == 3);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint modp(int n,int p){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (modp(3, 5) == 3);\n assert (modp(1101, 101) == 2);\n assert (modp(0, 101) == 1);\n assert (modp(3, 11) == 8);\n assert (modp(100, 101) == 1);\n}\n"} {"task_id": "CPP/50", "prompt": "#include\n#include\nusing namespace std;\nstring encode_shift(string s){\n // returns encoded string by shifting every character by 5 in the alphabet.\n string out;\n int i;\n for (i=0;i\nint main(){\n \n for (int i=0;i<100;i++)\n {\n int l=10+rand()%11;\n string str=\"\";\n for (int j=0;j\n#include\n#include\nusing namespace std;\n#include\n#include\nstring encode_shift(string s){\n string out;\n int i;\n for (i=0;i>> remove_vowels(\"\")\n\"\"\n>>> remove_vowels(\"abcdef\\nghijklm\")\n\"bcdf\\nghjklm\"\n>>> remove_vowels(\"abcdef\")\n\"bcdf\"\n>>> remove_vowels(\"aaaaa\")\n\"\"\n>>> remove_vowels(\"aaBAA\")\n\"B\"\n>>> remove_vowels(\"zbcd\")\n\"zbcd\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring remove_vowels(string text){\n", "canonical_solution": " string out=\"\";\n string vowels=\"AEIOUaeiou\";\n for (int i=0;i\nint main(){\n assert (remove_vowels(\"\") == \"\");\n assert (remove_vowels(\"abcdef\\nghijklm\") == \"bcdf\\nghjklm\");\n assert (remove_vowels(\"fedcba\") == \"fdcb\");\n assert (remove_vowels(\"eeeee\") == \"\");\n assert (remove_vowels(\"acBAA\") == \"cB\");\n assert (remove_vowels(\"EcBOO\") == \"cB\");\n assert (remove_vowels(\"ybcd\") == \"ybcd\");\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nstring remove_vowels(string text){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (remove_vowels(\"\") == \"\");\n assert (remove_vowels(\"abcdef\\nghijklm\") == \"bcdf\\nghjklm\");\n assert (remove_vowels(\"abcdef\") == \"bcdf\");\n assert (remove_vowels(\"aaaaa\") == \"\");\n assert (remove_vowels(\"aaBAA\") == \"B\");\n assert (remove_vowels(\"zbcd\") == \"zbcd\");\n}\n"} {"task_id": "CPP/52", "prompt": "/*\nReturn true if all numbers in the vector l are below threshold t.\n>>> below_threshold({1, 2, 4, 10}, 100)\ntrue\n>>> below_threshold({1, 20, 4, 10}, 5)\nfalse\n*/\n#include\n#include\nusing namespace std;\nbool below_threshold(vectorl, int t){\n", "canonical_solution": " for (int i=0;i=t) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (below_threshold({1, 2, 4, 10}, 100));\n assert (not(below_threshold({1, 20, 4, 10}, 5)));\n assert (below_threshold({1, 20, 4, 10}, 21));\n assert (below_threshold({1, 20, 4, 10}, 22));\n assert (below_threshold({1, 8, 4, 10}, 11));\n assert (not(below_threshold({1, 8, 4, 10}, 10)));\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool below_threshold(vectorl, int t){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (below_threshold({1, 2, 4, 10}, 100));\n assert (not(below_threshold({1, 20, 4, 10}, 5)));\n}\n"} {"task_id": "CPP/53", "prompt": "/*\nAdd two numbers x and y\n>>> add(2, 3)\n5\n>>> add(5, 7)\n12\n*/\n#include\n#include\nusing namespace std;\nint add(int x,int y){\n", "canonical_solution": " return x+y;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (add(0, 1) == 1);\n assert (add(1, 0) == 1);\n assert (add(2, 3) == 5);\n assert (add(5, 7) == 12);\n assert (add(7, 5) == 12);\n for (int i=0;i<100;i+=1)\n {\n int x=rand()%1000;\n int y=rand()%1000;\n assert (add(x, y) == x + y);\n }\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint add(int x,int y){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (add(2, 3) == 5);\n assert (add(5, 7) == 12);\n}\n"} {"task_id": "CPP/54", "prompt": "/*\nCheck if two words have the same characters.\n>>> same_chars(\"eabcdzzzz\", \"dddzzzzzzzddeddabc\")\ntrue\n>>> same_chars(\"abcd\", \"dddddddabc\")\ntrue\n>>> same_chars(\"dddddddabc\", \"abcd\")\ntrue\n>>> same_chars(\"eabcd\", \"dddddddabc\")\nfalse\n>>> same_chars(\"abcd\", \"dddddddabce\")\nfalse\n>>> same_chars(\"eabcdzzzz\", \"dddzzzzzzzddddabc\")\nfalse\n*/\n#include\n#include\n#include\nusing namespace std;\nbool same_chars(string s0,string s1){\n", "canonical_solution": " for (int i=0;i\nint main(){\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddeddabc\") == true);\n assert (same_chars(\"abcd\", \"dddddddabc\") == true);\n assert (same_chars(\"dddddddabc\", \"abcd\") == true);\n assert (same_chars(\"eabcd\", \"dddddddabc\") == false);\n assert (same_chars(\"abcd\", \"dddddddabcf\") == false);\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddddabc\") == false);\n assert (same_chars(\"aabb\", \"aaccc\") == false);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nbool same_chars(string s0,string s1){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddeddabc\") == true);\n assert (same_chars(\"abcd\", \"dddddddabc\") == true);\n assert (same_chars(\"dddddddabc\", \"abcd\") == true);\n assert (same_chars(\"eabcd\", \"dddddddabc\") == false);\n assert (same_chars(\"abcd\", \"dddddddabcf\") == false);\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddddabc\") == false);\n}\n"} {"task_id": "CPP/55", "prompt": "/*\nReturn n-th Fibonacci number.\n>>> fib(10)\n55\n>>> fib(1)\n1\n>>> fib(8)\n21\n*/\n#include\nusing namespace std;\nint fib(int n){\n", "canonical_solution": " int f[1000];\n f[0]=0;f[1]=1;\n for (int i=2;i<=n; i++)\n f[i]=f[i-1]+f[i-2];\n return f[n];\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (fib(10) == 55);\n assert (fib(1) == 1);\n assert (fib(8) == 21);\n assert (fib(11) == 89);\n assert (fib(12) == 144);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint fib(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (fib(10) == 55);\n assert (fib(1) == 1);\n assert (fib(8) == 21);\n}\n"} {"task_id": "CPP/56", "prompt": "/*\nbrackets is a string of '<' and '>'.\nreturn true if every opening bracket has a corresponding closing bracket.\n\n>>> correct_bracketing(\"<\")\nfalse\n>>> correct_bracketing(\"<>\")\ntrue\n>>> correct_bracketing(\"<<><>>\")\ntrue\n>>> correct_bracketing(\"><<>\")\nfalse\n*/\n#include\n#include\nusing namespace std;\nbool correct_bracketing(string brackets){\n", "canonical_solution": " int level=0;\n for (int i=0;i') level-=1;\n if (level<0) return false;\n }\n if (level!=0) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (correct_bracketing(\"<>\"));\n assert (correct_bracketing(\"<<><>>\"));\n assert (correct_bracketing(\"<><><<><>><>\"));\n assert (correct_bracketing(\"<><><<<><><>><>><<><><<>>>\"));\n assert (not (correct_bracketing(\"<<<><>>>>\")));\n assert (not (correct_bracketing(\"><<>\")));\n assert (not (correct_bracketing(\"<\")));\n assert (not (correct_bracketing(\"<<<<\")));\n assert (not (correct_bracketing(\">\")));\n assert (not (correct_bracketing(\"<<>\")));\n assert (not (correct_bracketing(\"<><><<><>><>><<>\")));\n assert (not (correct_bracketing(\"<><><<><>><>>><>\")));\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool correct_bracketing(string brackets){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (correct_bracketing(\"<>\"));\n assert (correct_bracketing(\"<<><>>\"));\n assert (not (correct_bracketing(\"><<>\")));\n assert (not (correct_bracketing(\"<\")));\n}\n"} {"task_id": "CPP/57", "prompt": "/*\nReturn true is vector elements are monotonically increasing or decreasing.\n>>> monotonic({1, 2, 4, 20})\ntrue\n>>> monotonic({1, 20, 4, 10})\nfalse\n>>> monotonic({4, 1, 0, -10})\ntrue\n*/\n#include\n#include\nusing namespace std;\nbool monotonic(vector l){\n", "canonical_solution": " int incr,decr;\n incr=0;decr=0;\n for (int i=1;il[i-1]) incr=1;\n if (l[i]\nint main(){\n assert (monotonic({1, 2, 4, 10}) == true);\n assert (monotonic({1, 2, 4, 20}) == true);\n assert (monotonic({1, 20, 4, 10}) == false);\n assert (monotonic({4, 1, 0, -10}) == true);\n assert (monotonic({4, 1, 1, 0}) == true);\n assert (monotonic({1, 2, 3, 2, 5, 60}) == false);\n assert (monotonic({1, 2, 3, 4, 5, 60}) == true);\n assert (monotonic({9, 9, 9, 9}) == true);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool monotonic(vector l){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (monotonic({1, 2, 4, 10}) == true);\n assert (monotonic({1, 20, 4, 10}) == false);\n assert (monotonic({4, 1, 0, -10}) == true);\n}\n"} {"task_id": "CPP/58", "prompt": "/*\nReturn sorted unique common elements for two vectors.\n>>> common({1, 4, 3, 34, 653, 2, 5}, {5, 7, 1, 5, 9, 653, 121})\n{1, 5, 653}\n>>> common({5, 3, 2, 8}, {3, 2})\n{2, 3}\n\n*/\n#include\n#include\n#include\nusing namespace std;\nvector common(vector l1,vector l2){\n", "canonical_solution": " vector out={};\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector common(vector l1,vector l2){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i 1 and is not a prime.\n>>> largest_prime_factor(13195)\n29\n>>> largest_prime_factor(2048)\n2\n*/\n#include\nusing namespace std;\nint largest_prime_factor(int n){\n", "canonical_solution": " for (int i=2;i*i<=n;i++)\n while (n%i==0 and n>i) n=n/i;\n return n;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (largest_prime_factor(15) == 5);\n assert (largest_prime_factor(27) == 3);\n assert (largest_prime_factor(63) == 7);\n assert (largest_prime_factor(330) == 11);\n assert (largest_prime_factor(13195) == 29);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint largest_prime_factor(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (largest_prime_factor(2048) == 2);\n assert (largest_prime_factor(13195) == 29);\n}\n"} {"task_id": "CPP/60", "prompt": "/*\nsum_to_n is a function that sums numbers from 1 to n.\n>>> sum_to_n(30)\n465\n>>> sum_to_n(100)\n5050\n>>> sum_to_n(5)\n15\n>>> sum_to_n(10)\n55\n>>> sum_to_n(1)\n1\n*/\n#include\nusing namespace std;\nint sum_to_n(int n){\n", "canonical_solution": " return n*(n+1)/2;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (sum_to_n(1) == 1);\n assert (sum_to_n(6) == 21);\n assert (sum_to_n(11) == 66);\n assert (sum_to_n(30) == 465);\n assert (sum_to_n(100) == 5050);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint sum_to_n(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (sum_to_n(1) == 1);\n assert (sum_to_n(5) == 15);\n assert (sum_to_n(10) == 55);\n assert (sum_to_n(30) == 465);\n assert (sum_to_n(100) == 5050);\n}\n"} {"task_id": "CPP/61", "prompt": "/*\nbrackets is a string of '(' and ')'.\nreturn true if every opening bracket has a corresponding closing bracket.\n\n>>> correct_bracketing(\"(\")\nfalse\n>>> correct_bracketing(\"()\")\ntrue\n>>> correct_bracketing(\"(()())\")\ntrue\n>>> correct_bracketing(\")(()\")\nfalse\n*/\n#include\n#include\nusing namespace std;\nbool correct_bracketing(string brackets){\n", "canonical_solution": " int level=0;\n for (int i=0;i\nint main(){\n assert (correct_bracketing(\"()\"));\n assert (correct_bracketing(\"(()())\"));\n assert (correct_bracketing(\"()()(()())()\"));\n assert (correct_bracketing(\"()()((()()())())(()()(()))\"));\n assert (not (correct_bracketing(\"((()())))\")));\n assert (not (correct_bracketing(\")(()\")));\n assert (not (correct_bracketing(\"(\")));\n assert (not (correct_bracketing(\"((((\")));\n assert (not (correct_bracketing(\")\")));\n assert (not (correct_bracketing(\"(()\")));\n assert (not (correct_bracketing(\"()()(()())())(()\")));\n assert (not (correct_bracketing(\"()()(()())()))()\")));\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool correct_bracketing(string brackets){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (correct_bracketing(\"()\"));\n assert (correct_bracketing(\"(()())\"));\n assert (not (correct_bracketing(\")(()\")));\n assert (not (correct_bracketing(\"(\")));\n}\n"} {"task_id": "CPP/62", "prompt": "/*\nxs represent coefficients of a polynomial.\nxs{0} + xs{1} * x + xs{2} * x^2 + ....\n Return derivative of this polynomial in the same form.\n>>> derivative({3, 1, 2, 4, 5})\n{1, 4, 12, 20}\n>>> derivative({1, 2, 3})\n{2, 6}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector derivative(vector xs){\n", "canonical_solution": " vector out={};\n for (int i=1;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i1e-4) return false;\n }\n return true;\n}\nint main(){\n assert (issame(derivative({3, 1, 2, 4, 5}) , {1, 4, 12, 20}));\n assert (issame(derivative({1, 2, 3}) , {2, 6}));\n assert (issame(derivative({3, 2, 1}) , {2, 2}));\n assert (issame(derivative({3, 2, 1, 0, 4}) , {2, 2, 0, 16}));\n assert (issame(derivative({1}) , {}));\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector derivative(vector xs){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i1e-4) return false;\n }\n return true;\n}\nint main(){\n assert (issame(derivative({3, 1, 2, 4, 5}) , {1, 4, 12, 20}));\n assert (issame(derivative({1, 2, 3}) , {2, 6}));\n}\n"} {"task_id": "CPP/63", "prompt": "/*\nThe FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\nfibfib(0) == 0\nfibfib(1) == 0\nfibfib(2) == 1\nfibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).\nPlease write a function to efficiently compute the n-th element of the fibfib number sequence.\n>>> fibfib(1)\n0\n>>> fibfib(5)\n4\n>>> fibfib(8)\n24\n*/\n#include\nusing namespace std;\nint fibfib(int n){\n", "canonical_solution": " int ff[100];\n ff[0]=0;\n ff[1]=0;\n ff[2]=1;\n for (int i=3;i<=n;i++)\n ff[i]=ff[i-1]+ff[i-2]+ff[i-3];\n return ff[n];\n\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (fibfib(2) == 1);\n assert (fibfib(1) == 0);\n assert (fibfib(5) == 4);\n assert (fibfib(8) == 24);\n assert (fibfib(10) == 81);\n assert (fibfib(12) == 274);\n assert (fibfib(14) == 927);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint fibfib(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (fibfib(1) == 0);\n assert (fibfib(5) == 4);\n assert (fibfib(8) == 24);\n}\n"} {"task_id": "CPP/64", "prompt": "/*\nWrite a function vowels_count which takes a string representing a word as input and returns the number of vowels in the string. Vowels in this case are 'a', 'e', 'i', 'o', 'u'. \nHere, 'y' is also a vowel, but only when it is at the end of the given word.\nExample: \n>>> vowels_count(\"abcde\") \n2 \n>>> vowels_count(\"ACEDY\") \n3\n*/\n#include\n#include\n#include\nusing namespace std;\nint vowels_count(string s){\n", "canonical_solution": " string vowels=\"aeiouAEIOU\";\n int count=0;\n for (int i=0;i\nint main(){\n assert (vowels_count(\"abcde\") == 2);\n assert (vowels_count(\"Alone\") == 3);\n assert (vowels_count(\"key\") == 2);\n assert (vowels_count(\"bye\") == 1);\n assert (vowels_count(\"keY\") == 2);\n assert (vowels_count(\"bYe\") == 1);\n assert (vowels_count(\"ACEDY\") == 3);\n \n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nint vowels_count(string s){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (vowels_count(\"abcde\") == 2);\n assert (vowels_count(\"ACEDY\") == 3);\n}\n"} {"task_id": "CPP/65", "prompt": "/*\nCircular shift the digits of the integer x, shift the digits right by shift\nand return the result as a string.\nIf shift > number of digits, return digits reversed.\n>>> circular_shift(12, 1)\n\"21\"\n>>> circular_shift(12, 2)\n\"12\"\n*/\n#include\n#include\nusing namespace std;\nstring circular_shift(int x,int shift){\n", "canonical_solution": " string xs;\n xs=to_string(x);\n if (xs.length()\nint main(){\n assert (circular_shift(100, 2) == \"001\");\n assert (circular_shift(12, 2) == \"12\");\n assert (circular_shift(97, 8) == \"79\");\n assert (circular_shift(12, 1) == \"21\");\n assert (circular_shift(11, 101) == \"11\");\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring circular_shift(int x,int shift){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (circular_shift(12, 2) == \"12\");\n assert (circular_shift(12, 1) == \"21\");\n}\n"} {"task_id": "CPP/66", "prompt": "/*\nTask\nWrite a function that takes a string as input and returns the sum of the upper characters only's\nASCII codes.\n\nExamples:\n digitSum(\"\") => 0\n digitSum(\"abAB\") => 131\n digitSum(\"abcCd\") => 67\n digitSum(\"helloE\") => 69\n digitSum(\"woArBld\") => 131\n digitSum(\"aAaaaXa\") => 153\n*/\n#include\n#include\nusing namespace std;\nint digitSum(string s){\n", "canonical_solution": " int sum=0;\n for (int i=0;i=65 and s[i]<=90)\n sum+=s[i];\n return sum;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (digitSum(\"\") == 0);\n assert (digitSum(\"abAB\") == 131);\n assert (digitSum(\"abcCd\") == 67);\n assert (digitSum(\"helloE\") == 69);\n assert (digitSum(\"woArBld\") == 131);\n assert (digitSum(\"aAaaaXa\") == 153);\n assert (digitSum(\" How are yOu?\") == 151);\n assert (digitSum(\"You arE Very Smart\") == 327);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint digitSum(string s){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (digitSum(\"\") == 0);\n assert (digitSum(\"abAB\") == 131);\n assert (digitSum(\"abcCd\") == 67);\n assert (digitSum(\"helloE\") == 69);\n assert (digitSum(\"woArBld\") == 131);\n assert (digitSum(\"aAaaaXa\") == 153);\n}\n"} {"task_id": "CPP/67", "prompt": "/*\nIn this task, you will be given a string that represents a number of apples and oranges \nthat are distributed in a basket of fruit this basket contains \napples, oranges, and mango fruits. Given the string that represents the total number of \nthe oranges and apples and an integer that represent the total number of the fruits \nin the basket return the number of the mango fruits in the basket.\nfor example:\nfruit_distribution(\"5 apples and 6 oranges\", 19) ->19 - 5 - 6 = 8\nfruit_distribution(\"0 apples and 1 oranges\",3) -> 3 - 0 - 1 = 2\nfruit_distribution(\"2 apples and 3 oranges\", 100) -> 100 - 2 - 3 = 95\nfruit_distribution(\"100 apples and 1 oranges\",120) -> 120 - 100 - 1 = 19\n*/\n#include\n#include\nusing namespace std;\nint fruit_distribution(string s,int n){\n", "canonical_solution": " string num1=\"\",num2=\"\";\n int is12;\n is12=0;\n for (int i=0;i=48 and s[i]<=57)\n {\n if (is12==0) num1=num1+s[i];\n if (is12==1) num2=num2+s[i];\n }\n else\n if (is12==0 and num1.length()>0) is12=1;\n return n-atoi(num1.c_str())-atoi(num2.c_str());\n\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (fruit_distribution(\"5 apples and 6 oranges\",19) == 8);\n assert (fruit_distribution(\"5 apples and 6 oranges\",21) == 10);\n assert (fruit_distribution(\"0 apples and 1 oranges\",3) == 2);\n assert (fruit_distribution(\"1 apples and 0 oranges\",3) == 2);\n assert (fruit_distribution(\"2 apples and 3 oranges\",100) == 95);\n assert (fruit_distribution(\"2 apples and 3 oranges\",5) == 0);\n assert (fruit_distribution(\"1 apples and 100 oranges\",120) == 19);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint fruit_distribution(string s,int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (fruit_distribution(\"5 apples and 6 oranges\",19) == 8);\n assert (fruit_distribution(\"0 apples and 1 oranges\",3) == 2);\n assert (fruit_distribution(\"2 apples and 3 oranges\",100) == 95);\n assert (fruit_distribution(\"1 apples and 100 oranges\",120) == 19);\n}\n"} {"task_id": "CPP/68", "prompt": "/*\nGiven a vector representing a branch of a tree that has non-negative integer nodes\nyour task is to pluck one of the nodes and return it.\nThe plucked node should be the node with the smallest even value.\nIf multiple nodes with the same smallest even value are found return the node that has smallest index.\n\nThe plucked node should be returned in a vector, { smalest_value, its index },\nIf there are no even values or the given vector is empty, return {}.\n\nExample 1:\n Input: {4,2,3}\n Output: {2, 1}\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\nExample 2:\n Input: {1,2,3}\n Output: {2, 1}\n Explanation: 2 has the smallest even value, and 2 has the smallest index. \n\nExample 3:\n Input: {}\n Output: {}\n\nExample 4:\n Input: {5, 0, 3, 0, 4, 2}\n Output: {0, 1}\n Explanation: 0 is the smallest value, but there are two zeros,\n so we will choose the first zero, which has the smallest index.\n\nConstraints:\n * 1 <= nodes.length <= 10000\n * 0 <= node.value\n*/\n#include\n#include\nusing namespace std;\nvector pluck(vector arr){\n", "canonical_solution": " vector out={};\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\nvector pluck(vector arr){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\nint search(vector lst){\n", "canonical_solution": " vector> freq={};\n int max=-1;\n for (int i=0;i=freq[j][0] and freq[j][0]>max) max=freq[j][0];\n }\n if (not(has)) \n {\n freq.push_back({lst[i],1});\n if (max==-1 and lst[i]==1) max=1;\n }\n }\n return max;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (search({5, 5, 5, 5, 1}) == 1);\n assert (search({4, 1, 4, 1, 4, 4}) == 4);\n assert (search({3, 3}) == -1);\n assert (search({8, 8, 8, 8, 8, 8, 8, 8}) == 8);\n assert (search({2, 3, 3, 2, 2}) == 2);\n assert (search({2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1}) == 1);\n assert (search({3, 2, 8, 2}) == 2);\n assert (search({6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10}) == 1);\n assert (search({8, 8, 3, 6, 5, 6, 4}) == -1);\n assert (search({6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9}) == 1);\n assert (search({1, 9, 10, 1, 3}) == 1);\n assert (search({6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10}) == 5);\n assert (search({1}) == 1);\n assert (search({8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5}) == 4);\n assert (search({2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10}) == 2);\n assert (search({1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3}) == 1);\n assert (search({9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4}) == 4);\n assert (search({2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7}) == 4);\n assert (search({9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1}) == 2);\n assert (search({5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8}) == -1);\n assert (search({10}) == -1);\n assert (search({9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2}) == 2);\n assert (search({5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8}) == 1);\n assert (search({7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6}) == 1);\n assert (search({3, 10, 10, 9, 2}) == -1);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint search(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (search({4, 1, 2, 2, 3, 1}) == 2);\n assert (search({1, 2, 2, 3, 3, 3, 4, 4, 4}) == 3);\n assert (search({5, 5, 4, 4, 4}) == -1);\n}\n"} {"task_id": "CPP/70", "prompt": "/*\nGiven vector of integers, return vector in strange order.\nStrange sorting, is when you start with the minimum value,\nthen maximum of the remaining integers, then minimum and so on.\n\nExamples:\nstrange_sort_vector({1, 2, 3, 4}) == {1, 4, 2, 3}\nstrange_sort_vector({5, 5, 5, 5}) == {5, 5, 5, 5}\nstrange_sort_vector({}) == {}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector strange_sort_list(vector lst){\n", "canonical_solution": " vector out={};\n sort(lst.begin(),lst.end());\n int l=0,r=lst.size()-1;\n while (l\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector strange_sort_list(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\nfloat triangle_area(float a,float b,float c){\n", "canonical_solution": " if (a+b<=c or a+c<=b or b+c<=a) return -1;\n float h=(a+b+c)/2;\n float area;\n area=pow(h*(h-a)*(h-b)*(h-c),0.5);\n return area;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (abs(triangle_area(3, 4, 5)-6.00)<0.01);\n assert (abs(triangle_area(1, 2, 10) +1)<0.01);\n assert (abs(triangle_area(4, 8, 5) -8.18)<0.01);\n assert (abs(triangle_area(2, 2, 2) -1.73)<0.01);\n assert (abs(triangle_area(1, 2, 3) +1)<0.01);\n assert (abs(triangle_area(10, 5, 7) - 16.25)<0.01);\n assert (abs(triangle_area(2, 6, 3) +1)<0.01);\n assert (abs(triangle_area(1, 1, 1) -0.43)<0.01);\n assert (abs(triangle_area(2, 2, 10) +1)<0.01);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nfloat triangle_area(float a,float b,float c){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (abs(triangle_area(3, 4, 5)-6.00)<0.01);\n assert (abs(triangle_area(1, 2, 10) +1)<0.01);\n}\n"} {"task_id": "CPP/72", "prompt": "/*\nWrite a function that returns true if the object q will fly, and false otherwise.\nThe object q will fly if it's balanced (it is a palindromic vector) and the sum of its elements is less than or equal the maximum possible weight w.\n\nExample:\nwill_it_fly({1, 2}, 5) \u279e false \n// 1+2 is less than the maximum possible weight, but it's unbalanced.\n\nwill_it_fly({3, 2, 3}, 1) \u279e false\n// it's balanced, but 3+2+3 is more than the maximum possible weight.\n\nwill_it_fly({3, 2, 3}, 9) \u279e true\n// 3+2+3 is less than the maximum possible weight, and it's balanced.\n\nwill_it_fly({3}, 5) \u279e true\n// 3 is less than the maximum possible weight, and it's balanced.\n*/\n#include\n#include\nusing namespace std;\nbool will_it_fly(vector q,int w){\n", "canonical_solution": " int sum=0;\n for (int i=0;iw) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (will_it_fly({3, 2, 3}, 9)==true);\n assert (will_it_fly({1, 2}, 5) == false);\n assert (will_it_fly({3}, 5) == true);\n assert (will_it_fly({3, 2, 3}, 1) == false);\n assert (will_it_fly({1, 2, 3}, 6) ==false);\n assert (will_it_fly({5}, 5) == true);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool will_it_fly(vector q,int w){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (will_it_fly({3, 2, 3}, 9)==true);\n assert (will_it_fly({1, 2}, 5) == false);\n assert (will_it_fly({3}, 5) == true);\n assert (will_it_fly({3, 2, 3}, 1) == false);\n}\n"} {"task_id": "CPP/73", "prompt": "/*\nGiven a vector arr of integers, find the minimum number of elements that\nneed to be changed to make the vector palindromic. A palindromic vector is a vector that\nis read the same backwards and forwards. In one change, you can change one element to any other element.\n\nFor example:\nsmallest_change({1,2,3,5,4,7,9,6}) == 4\nsmallest_change({1, 2, 3, 4, 3, 2, 2}) == 1\nsmallest_change({1, 2, 3, 2, 1}) == 0\n*/\n#include\n#include\nusing namespace std;\nint smallest_change(vector arr){\n", "canonical_solution": " int out=0;\n for (int i=0;i\nint main(){\n assert (smallest_change({1,2,3,5,4,7,9,6}) == 4);\n assert (smallest_change({1, 2, 3, 4, 3, 2, 2}) == 1);\n assert (smallest_change({1, 4, 2}) == 1);\n assert (smallest_change({1, 4, 4, 2}) == 1);\n assert (smallest_change({1, 2, 3, 2, 1}) == 0);\n assert (smallest_change({3, 1, 1, 3}) == 0);\n assert (smallest_change({1}) == 0);\n assert (smallest_change({0, 1}) == 1);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint smallest_change(vector arr){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (smallest_change({1,2,3,5,4,7,9,6}) == 4);\n assert (smallest_change({1, 2, 3, 4, 3, 2, 2}) == 1);\n assert (smallest_change({1, 2, 3, 2, 1}) == 0);\n assert (smallest_change({3, 1, 1, 3}) == 0);\n}\n"} {"task_id": "CPP/74", "prompt": "/*\nWrite a function that accepts two vectors of strings and returns the vector that has \ntotal number of chars in the all strings of the vector less than the other vector.\n\nif the two vectors have the same number of chars, return the first vector.\n\nExamples\ntotal_match({}, {}) \u279e {}\ntotal_match({\"hi\", \"admin\"}, {\"hI\", \"Hi\"}) \u279e {\"hI\", \"Hi\"}\ntotal_match({\"hi\", \"admin\"}, {\"hi\", \"hi\", \"admin\", \"project\"}) \u279e {\"hi\", \"admin\"}\ntotal_match({\"hi\", \"admin\"}, {\"hI\", \"hi\", \"hi\"}) \u279e {\"hI\", \"hi\", \"hi\"}\ntotal_match({\"4\"}, {\"1\", \"2\", \"3\", \"4\", \"5\"}) \u279e {\"4\"}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector total_match(vector lst1,vector lst2){\n", "canonical_solution": " int num1,num2,i;\n num1=0;num2=0;\n for (i=0;inum2) return lst2;\n return lst1;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nvector total_match(vector lst1,vector lst2){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\nusing namespace std;\nbool is_multiply_prime(int a){\n", "canonical_solution": " int num=0;\n for (int i=2;i*i<=a;i++)\n while (a%i==0 and a>i)\n {\n a=a/i;\n num+=1;\n }\n if (num==2) return true;\n return false; \n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (is_multiply_prime(5) == false);\n assert (is_multiply_prime(30) == true);\n assert (is_multiply_prime(8) == true);\n assert (is_multiply_prime(10) == false);\n assert (is_multiply_prime(125) == true);\n assert (is_multiply_prime(3 * 5 * 7) == true);\n assert (is_multiply_prime(3 * 6 * 7) == false);\n assert (is_multiply_prime(9 * 9 * 9) == false);\n assert (is_multiply_prime(11 * 9 * 9) == false);\n assert (is_multiply_prime(11 * 13 * 7) == true);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nbool is_multiply_prime(int a){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (is_multiply_prime(30) == true);\n}\n"} {"task_id": "CPP/76", "prompt": "/*\nYour task is to write a function that returns true if a number x is a simple\npower of n and false in other cases.\nx is a simple power of n if n**int=x\nFor example:\nis_simple_power(1, 4) => true\nis_simple_power(2, 2) => true\nis_simple_power(8, 2) => true\nis_simple_power(3, 2) => false\nis_simple_power(3, 1) => false\nis_simple_power(5, 3) => false\n*/\n#include\n#include\nusing namespace std;\nbool is_simple_power(int x,int n){\n", "canonical_solution": " int p=1,count=0;\n while (p<=x and count<100)\n {\n if (p==x) return true;\n p=p*n;count+=1;\n }\n return false;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (is_simple_power(1, 4)== true);\n assert (is_simple_power(2, 2)==true);\n assert (is_simple_power(8, 2)==true);\n assert (is_simple_power(3, 2)==false);\n assert (is_simple_power(3, 1)==false);\n assert (is_simple_power(5, 3)==false);\n assert (is_simple_power(16, 2)== true);\n assert (is_simple_power(143214, 16)== false);\n assert (is_simple_power(4, 2)==true);\n assert (is_simple_power(9, 3)==true);\n assert (is_simple_power(16, 4)==true);\n assert (is_simple_power(24, 2)==false);\n assert (is_simple_power(128, 4)==false);\n assert (is_simple_power(12, 6)==false);\n assert (is_simple_power(1, 1)==true);\n assert (is_simple_power(1, 12)==true);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nbool is_simple_power(int x,int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (is_simple_power(1, 4)== true);\n assert (is_simple_power(2, 2)==true);\n assert (is_simple_power(8, 2)==true);\n assert (is_simple_power(3, 2)==false);\n assert (is_simple_power(3, 1)==false);\n assert (is_simple_power(5, 3)==false);\n}\n"} {"task_id": "CPP/77", "prompt": "/*\nWrite a function that takes an integer a and returns true \nif this ingeger is a cube of some integer number.\nNote: you may assume the input is always valid.\nExamples:\niscube(1) ==> true\niscube(2) ==> false\niscube(-1) ==> true\niscube(64) ==> true\niscube(0) ==> true\niscube(180) ==> false\n*/\n#include\n#include\nusing namespace std;\nbool iscuber(int a){\n", "canonical_solution": " for (int i=0;i*i*i<=abs(a);i++)\n if (i*i*i==abs(a)) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (iscuber(1) == true);\n assert (iscuber(2) == false);\n assert (iscuber(-1) == true);\n assert (iscuber(64) == true);\n assert (iscuber(180) == false);\n assert (iscuber(1000) == true);\n assert (iscuber(0) == true);\n assert (iscuber(1729) == false);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nbool iscuber(int a){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (iscuber(1) == true);\n assert (iscuber(2) == false);\n assert (iscuber(-1) == true);\n assert (iscuber(64) == true);\n assert (iscuber(180) == false);\n assert (iscuber(0) == true);\n}\n"} {"task_id": "CPP/78", "prompt": "/*\nYou have been tasked to write a function that receives \na hexadecimal number as a string and counts the number of hexadecimal \ndigits that are primes (prime number, or a prime, is a natural number \ngreater than 1 that is not a product of two smaller natural numbers).\nHexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.\nPrime numbers are 2, 3, 5, 7, 11, 13, 17,...\nSo you have to determine a number of the following digits: 2, 3, 5, 7, \nB (=decimal 11), D (=decimal 13).\nNote: you may assume the input is always correct or empty string, \nand symbols A,B,C,D,E,F are always uppercase.\nExamples:\nFor num = \"AB\" the output should be 1.\nFor num = \"1077E\" the output should be 2.\nFor num = \"ABED1A33\" the output should be 4.\nFor num = \"123456789ABCDEF0\" the output should be 6.\nFor num = \"2020\" the output should be 2.\n*/\n#include\n#include\n#include\nusing namespace std;\nint hex_key(string num){\n", "canonical_solution": " string key=\"2357BD\";\n int out=0;\n for (int i=0;i\nint main(){\n assert (hex_key(\"AB\") == 1 );\n assert (hex_key(\"1077E\") == 2 );\n assert (hex_key(\"ABED1A33\") == 4 );\n assert (hex_key(\"2020\") == 2 );\n assert (hex_key(\"123456789ABCDEF0\") == 6 );\n assert (hex_key(\"112233445566778899AABBCCDDEEFF00\") == 12 );\n assert (hex_key(\"\") == 0);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nint hex_key(string num){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (hex_key(\"AB\") == 1 );\n assert (hex_key(\"1077E\") == 2 );\n assert (hex_key(\"ABED1A33\") == 4 );\n assert (hex_key(\"2020\") == 2 );\n assert (hex_key(\"123456789ABCDEF0\") == 6 );\n}\n"} {"task_id": "CPP/79", "prompt": "/*\nYou will be given a number in decimal form and your task is to convert it to\nbinary format. The function should return a string, with each character representing a binary\nnumber. Each character in the string will be '0' or '1'.\n\nThere will be an extra couple of characters \"db\" at the beginning and at the end of the string.\nThe extra characters are there to help with the format.\n\nExamples:\ndecimal_to_binary(15) // returns \"db1111db\"\ndecimal_to_binary(32) // returns \"db100000db\"\n*/\n#include\n#include\nusing namespace std;\nstring decimal_to_binary(int decimal){\n", "canonical_solution": " string out=\"\";\n if (decimal==0) return \"db0db\";\n while (decimal>0)\n {\n out=to_string(decimal%2)+out;\n decimal=decimal/2;\n }\n out=\"db\"+out+\"db\";\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (decimal_to_binary(0) == \"db0db\");\n assert (decimal_to_binary(32) == \"db100000db\");\n assert (decimal_to_binary(103) == \"db1100111db\");\n assert (decimal_to_binary(15) == \"db1111db\");\n\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring decimal_to_binary(int decimal){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (decimal_to_binary(32) == \"db100000db\");\n assert (decimal_to_binary(15) == \"db1111db\");\n}\n"} {"task_id": "CPP/80", "prompt": "/*\nYou are given a string s.\nYour task is to check if the string is happy or not.\nA string is happy if its length is at least 3 and every 3 consecutive letters are distinct\nFor example:\nis_happy(\"a\") => false\nis_happy(\"aa\") => false\nis_happy(\"abcd\") => true\nis_happy(\"aabb\") => false\nis_happy(\"adb\") => true\nis_happy(\"xyy\") => false\n*/\n#include\n#include\nusing namespace std;\nbool is_happy(string s){\n", "canonical_solution": " if (s.length()<3) return false;\n for (int i=2;i\nint main(){\n assert (is_happy(\"a\") == false );\n assert (is_happy(\"aa\") == false );\n assert (is_happy(\"abcd\") == true );\n assert (is_happy(\"aabb\") == false );\n assert (is_happy(\"adb\") == true );\n assert (is_happy(\"xyy\") == false );\n assert (is_happy(\"iopaxpoi\") == true );\n assert (is_happy(\"iopaxioi\") == false );\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool is_happy(string s){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (is_happy(\"a\") == false );\n assert (is_happy(\"aa\") == false );\n assert (is_happy(\"abcd\") == true );\n assert (is_happy(\"aabb\") == false );\n assert (is_happy(\"adb\") == true );\n assert (is_happy(\"xyy\") == false );\n}\n"} {"task_id": "CPP/81", "prompt": "/*\nIt is the last week of the semester and the teacher has to give the grades\nto students. The teacher has been making her own algorithm for grading.\nThe only problem is, she has lost the code she used for grading.\nShe has given you a vector of GPAs for some students and you have to write \na function that can output a vector of letter grades using the following table:\n GPA | Letter grade\n 4.0 A+\n > 3.7 A \n > 3.3 A- \n > 3.0 B+\n > 2.7 B \n > 2.3 B-\n > 2.0 C+\n > 1.7 C\n > 1.3 C-\n > 1.0 D+ \n > 0.7 D \n > 0.0 D-\n 0.0 E\n\n\nExample:\ngrade_equation({4.0, 3, 1.7, 2, 3.5}) ==> {\"A+\", \"B\", \"C-\", \"C\", \"A-\"}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector numerical_letter_grade(vector grades){\n", "canonical_solution": " vector out={};\n for (int i=0;i=3.9999) out.push_back(\"A+\");\n if (grades[i]>3.7001 and grades[i]<3.9999) out.push_back(\"A\");\n if (grades[i]>3.3001 and grades[i]<=3.7001) out.push_back(\"A-\");\n if (grades[i]>3.0001 and grades[i]<=3.3001) out.push_back(\"B+\");\n if (grades[i]>2.7001 and grades[i]<=3.0001) out.push_back(\"B\");\n if (grades[i]>2.3001 and grades[i]<=2.7001) out.push_back(\"B-\");\n if (grades[i]>2.0001 and grades[i]<=2.3001) out.push_back(\"C+\");\n if (grades[i]>1.7001 and grades[i]<=2.0001) out.push_back(\"C\");\n if (grades[i]>1.3001 and grades[i]<=1.7001) out.push_back(\"C-\");\n if (grades[i]>1.0001 and grades[i]<=1.3001) out.push_back(\"D+\");\n if (grades[i]>0.7001 and grades[i]<=1.0001) out.push_back(\"D\");\n if (grades[i]>0.0001 and grades[i]<=0.7001) out.push_back(\"D-\");\n if (grades[i]<=0.0001) out.push_back(\"E\");\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector numerical_letter_grade(vector grades){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\nbool prime_length(string str){\n", "canonical_solution": " int l,i;\n l=str.length();\n if (l<2) return false;\n for (i=2;i*i<=l;i++)\n if (l%i==0) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (prime_length(\"Hello\") == true);\n assert (prime_length(\"abcdcba\") == true);\n assert (prime_length(\"kittens\") == true);\n assert (prime_length(\"orange\") == false);\n assert (prime_length(\"wow\") == true);\n assert (prime_length(\"world\") == true);\n assert (prime_length(\"MadaM\") == true);\n assert (prime_length(\"Wow\") == true);\n assert (prime_length(\"\") == false);\n assert (prime_length(\"HI\") == true);\n assert (prime_length(\"go\") == true);\n assert (prime_length(\"gogo\") == false);\n assert (prime_length(\"aaaaaaaaaaaaaaa\") == false);\n assert (prime_length(\"Madam\") == true);\n assert (prime_length(\"M\") == false);\n assert (prime_length(\"0\") == false);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool prime_length(string str){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (prime_length(\"Hello\") == true);\n assert (prime_length(\"abcdcba\") == true);\n assert (prime_length(\"kittens\") == true);\n assert (prime_length(\"orange\") == false);\n}\n"} {"task_id": "CPP/83", "prompt": "/*\nGiven a positive integer n, return the count of the numbers of n-digit\npositive integers that start or end with 1.\n*/\n#include\nusing namespace std;\nint starts_one_ends(int n){\n", "canonical_solution": " if (n<1) return 0;\n if (n==1) return 1;\n int out=18;\n for (int i=2;i\nint main(){\n assert (starts_one_ends(1) == 1);\n assert (starts_one_ends(2) == 18);\n assert (starts_one_ends(3) == 180);\n assert (starts_one_ends(4) == 1800);\n assert (starts_one_ends(5) == 18000);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint starts_one_ends(int n){\n", "example_test": ""} {"task_id": "CPP/84", "prompt": "/*\nGiven a positive integer N, return the total sum of its digits in binary.\n\nExample\n For N = 1000, the sum of digits will be 1 the output should be \"1\".\n For N = 150, the sum of digits will be 6 the output should be \"110\".\n For N = 147, the sum of digits will be 12 the output should be \"1100\".\n\nVariables:\n @N integer\n Constraints: 0 \u2264 N \u2264 10000.\nOutput:\n a string of binary number\n*/\n#include\n#include\nusing namespace std;\nstring solve(int N){\n", "canonical_solution": " string str,bi=\"\";\n str=to_string(N);\n int i,sum=0;\n for (int i=0;i0)\n {\n bi=to_string(sum%2)+bi;\n sum=sum/2;\n }\n return bi;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (solve(1000) == \"1\");\n assert (solve(150) == \"110\");\n assert (solve(147) == \"1100\");\n assert (solve(333) == \"1001\");\n assert (solve(963) == \"10010\");\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring solve(int N){\n", "example_test": ""} {"task_id": "CPP/85", "prompt": "/*\nGiven a non-empty vector of integers lst. add the even elements that are at odd indices..\n\n\nExamples:\n add({4, 2, 6, 7}) ==> 2 \n*/\n#include\n#include\nusing namespace std;\nint add(vector lst){\n", "canonical_solution": " int sum=0;\n for (int i=0;i*2+1\nint main(){\n assert (add({4, 88}) == 88);\n assert (add({4, 5, 6, 7, 2, 122}) == 122);\n assert (add({4, 0, 6, 7}) == 0);\n assert (add({4, 4, 6, 8}) == 12);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint add(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (add({4, 2, 6, 7}) == 2);\n}\n"} {"task_id": "CPP/86", "prompt": "/*\nWrite a function that takes a string and returns an ordered version of it.\nOrdered version of string, is a string where all words (separated by space)\nare replaced by a new word where all the characters arranged in\nascending order based on ascii value.\nNote: You should keep the order of words and blank spaces in the sentence.\n\nFor example:\nanti_shuffle(\"Hi\") returns \"Hi\"\nanti_shuffle(\"hello\") returns \"ehllo\"\nanti_shuffle(\"Hello World!!!\") returns \"Hello !!!Wdlor\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring anti_shuffle(string s){\n", "canonical_solution": " string out=\"\";\n string current=\"\";\n s=s+' ';\n for (int i=0;i0) out=out+' ';\n out=out+current;\n current=\"\";\n }\n else current=current+s[i];\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (anti_shuffle(\"Hi\") == \"Hi\");\n assert (anti_shuffle(\"hello\") == \"ehllo\");\n assert (anti_shuffle(\"number\") == \"bemnru\");\n assert (anti_shuffle(\"abcd\") == \"abcd\");\n assert (anti_shuffle(\"Hello World!!!\") == \"Hello !!!Wdlor\");\n assert (anti_shuffle(\"\") == \"\");\n assert (anti_shuffle(\"Hi. My name is Mister Robot. How are you?\") == \".Hi My aemn is Meirst .Rboot How aer ?ouy\");\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nstring anti_shuffle(string s){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (anti_shuffle(\"Hi\") == \"Hi\");\n assert (anti_shuffle(\"hello\") == \"ehllo\");\n assert (anti_shuffle(\"Hello World!!!\") == \"Hello !!!Wdlor\");\n}\n"} {"task_id": "CPP/87", "prompt": "/*\nYou are given a 2 dimensional data, as a nested vectors,\nwhich is similar to matrix, however, unlike matrices,\neach row may contain a different number of columns.\nGiven lst, and integer x, find integers x in the vector,\nand return vector of vectors, {{x1, y1}, {x2, y2} ...} such that\neach vector is a coordinate - {row, columns}, starting with 0.\nSort coordinates initially by rows in ascending order.\nAlso, sort coordinates of the row by columns in descending order.\n\nExamples:\nget_row({\n {1,2,3,4,5,6},\n {1,2,3,4,1,6},\n {1,2,3,4,5,1}\n}, 1) == {{0, 0}, {1, 4}, {1, 0}, {2, 5}, {2, 0}}\nget_row({}, 1) == {}\nget_row({{}, {1}, {1, 2, 3}}, 3) == {{2, 2}}\n*/\n#include\n#include\nusing namespace std;\nvector> get_row(vector> lst, int x){\n", "canonical_solution": " vector> out={};\n for (int i=0;i=0;j-=1)\n if (lst[i][j]==x) out.push_back({i,j});\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector> a,vector> b){\n if (a.size()!=b.size()) return false;\n\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\nvector> get_row(vector> lst, int x){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector> a,vector> b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i {}\n* sort_vector({5}) => {5}\n* sort_vector({2, 4, 3, 0, 1, 5}) => {0, 1, 2, 3, 4, 5}\n* sort_vector({2, 4, 3, 0, 1, 5, 6}) => {6, 5, 4, 3, 2, 1, 0}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector sort_array(vector array){\n", "canonical_solution": " if (array.size()==0) return {};\n if ((array[0]+array[array.size()-1]) %2==1)\n {\n sort(array.begin(),array.end());\n return array;\n }\n else\n {\n sort(array.begin(),array.end());\n vector out={};\n for (int i=array.size()-1;i>=0;i-=1)\n out.push_back(array[i]);\n return out;\n }\n\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector sort_array(vector array){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\nstring encrypt(string s){\n", "canonical_solution": " string out;\n int i;\n for (i=0;i\nint main(){\n assert (encrypt(\"hi\") == \"lm\");\n assert (encrypt(\"asdfghjkl\") == \"ewhjklnop\");\n assert (encrypt(\"gf\") == \"kj\");\n assert (encrypt(\"et\") == \"ix\");\n assert (encrypt(\"faewfawefaewg\")==\"jeiajeaijeiak\");\n assert (encrypt(\"hellomyfriend\")==\"lippsqcjvmirh\");\n assert (encrypt(\"dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh\")==\"hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl\");\n assert (encrypt(\"a\")==\"e\");\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring encrypt(string s){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (encrypt(\"hi\") == \"lm\");\n assert (encrypt(\"asdfghjkl\") == \"ewhjklnop\");\n assert (encrypt(\"gf\") == \"kj\");\n assert (encrypt(\"et\") == \"ix\");\n}\n"} {"task_id": "CPP/90", "prompt": "/*\nYou are given a vector of integers.\nWrite a function next_smallest() that returns the 2nd smallest element of the vector.\nReturn None if there is no such element.\n\nnext_smallest({1, 2, 3, 4, 5}) == 2\nnext_smallest({5, 1, 4, 3, 2}) == 2\nnext_smallest({}) == None\nnext_smallest({1, 1}) == None\n*/\n#include\n#include\n#include\nusing namespace std;\nint next_smallest(vector lst){\n", "canonical_solution": " sort(lst.begin(),lst.end());\n for (int i=1;i\nint main(){\n assert (next_smallest({1, 2, 3, 4, 5}) == 2);\n assert (next_smallest({5, 1, 4, 3, 2}) == 2);\n assert (next_smallest({}) == -1);\n assert (next_smallest({1, 1}) == -1);\n assert (next_smallest({1,1,1,1,0}) == 1);\n assert (next_smallest({-35, 34, 12, -45}) == -35);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nint next_smallest(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (next_smallest({1, 2, 3, 4, 5}) == 2);\n assert (next_smallest({5, 1, 4, 3, 2}) == 2);\n assert (next_smallest({}) == -1);\n assert (next_smallest({1, 1}) == -1);\n}\n"} {"task_id": "CPP/91", "prompt": "/*\nYou'll be given a string of words, and your task is to count the number\nof boredoms. A boredom is a sentence that starts with the word \"I\".\nSentences are delimited by '.', '?' or '!'.\n\nFor example:\n>>> is_bored(\"Hello world\")\n0\n>>> is_bored(\"The sky is blue. The sun is shining. I love this weather\")\n1\n*/\n#include\n#include\nusing namespace std;\nint is_bored(string S){\n", "canonical_solution": " bool isstart=true;\n bool isi=false;\n int sum=0;\n for (int i=0;i\nint main(){\n assert (is_bored(\"Hello world\") == 0);\n assert (is_bored(\"Is the sky blue?\") == 0);\n assert (is_bored(\"I love It !\") == 1);\n assert (is_bored(\"bIt\") == 0);\n assert (is_bored(\"I feel good today. I will be productive. will kill It\") == 2);\n assert (is_bored(\"You and I are going for a walk\") == 0);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint is_bored(string S){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (is_bored(\"Hello world\") == 0);\n assert (is_bored(\"The sky is blue. The sun is shining. I love this weather\") == 1);\n}\n"} {"task_id": "CPP/92", "prompt": "/*\nCreate a function that takes 3 numbers.\nReturns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.\nReturns false in any other cases.\n\nExamples\nany_int(5, 2, 7) \u279e true\n\nany_int(3, 2, 2) \u279e false\n\nany_int(3, -2, 1) \u279e true\n\nany_int(3.6, -2.2, 2) \u279e false\n\n\n\n*/\n#include\n#include\nusing namespace std;\nbool any_int(float a,float b,float c){\n", "canonical_solution": " if (round(a)!=a) return false;\n if (round(b)!=b) return false;\n if (round(c)!=c) return false;\n if (a+b==c or a+c==b or b+c==a) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (any_int(2, 3, 1)==true);\n assert (any_int(2.5, 2, 3)==false);\n assert (any_int(1.5, 5, 3.5)==false);\n assert (any_int(2, 6, 2)==false);\n assert (any_int(4, 2, 2)==true);\n assert (any_int(2.2, 2.2, 2.2)==false);\n assert (any_int(-4, 6, 2)==true);\n assert (any_int(2,1,1)==true);\n assert (any_int(3,4,7)==true);\n assert (any_int(3.01,4,7)==false);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nbool any_int(float a,float b,float c){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (any_int(5, 2, 7)==true);\n assert (any_int(3, 2, 2)==false);\n assert (any_int(3, -2, 1)==true);\n assert (any_int(3.6, -2.2, 2)==false);\n}\n"} {"task_id": "CPP/93", "prompt": "/*\nWrite a function that takes a message, and encodes in such a \nway that it swaps case of all letters, replaces all vowels in \nthe message with the letter that appears 2 places ahead of that \nvowel in the english alphabet. \nAssume only letters. \n\nExamples:\n>>> encode('test\")\n\"TGST\"\n>>> encode(\"This is a message\")\n'tHKS KS C MGSSCGG\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring encode(string message){\n", "canonical_solution": " string vowels=\"aeiouAEIOU\";\n string out=\"\";\n for (int i=0;i=97 and w<=122){w=w-32;}\n else if (w>=65 and w<=90) w=w+32;\n if (find(vowels.begin(),vowels.end(),w)!=vowels.end()) w=w+2;\n out=out+w;\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (encode(\"TEST\") == \"tgst\");\n assert (encode(\"Mudasir\") == \"mWDCSKR\");\n assert (encode(\"YES\") == \"ygs\");\n assert (encode(\"This is a message\") == \"tHKS KS C MGSSCGG\");\n assert (encode(\"I DoNt KnOw WhAt tO WrItE\") == \"k dQnT kNqW wHcT Tq wRkTg\");\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nstring encode(string message){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (encode(\"test\") == \"TGST\");\n assert (encode(\"This is a message\") == \"tHKS KS C MGSSCGG\");\n}\n"} {"task_id": "CPP/94", "prompt": "/*\nYou are given a vector of integers.\nYou need to find the largest prime value and return the sum of its digits.\n\nExamples:\nFor lst = {0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3} the output should be 10\nFor lst = {1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1} the output should be 25\nFor lst = {1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3} the output should be 13\nFor lst = {0,724,32,71,99,32,6,0,5,91,83,0,5,6} the output should be 11\nFor lst = {0,81,12,3,1,21} the output should be 3\nFor lst = {0,8,1,2,1,7} the output should be 7\n*/\n#include\n#include\n#include\nusing namespace std;\nint skjkasdkd(vector lst){\n", "canonical_solution": " int largest=0;\n for (int i=0;ilargest)\n {\n bool prime=true;\n for (int j=2;j*j<=lst[i];j++)\n if (lst[i]%j==0) prime=false;\n if (prime) largest=lst[i];\n }\n int sum=0;\n string s;\n s=to_string(largest);\n for (int i=0;i\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (skjkasdkd({0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3}) == 10);\n assert (skjkasdkd({1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1}) == 25);\n assert (skjkasdkd({1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3}) == 13);\n assert (skjkasdkd({0,724,32,71,99,32,6,0,5,91,83,0,5,6}) == 11);\n assert (skjkasdkd({0,81,12,3,1,21}) == 3);\n assert (skjkasdkd({0,8,1,2,1,7}) == 7);\n assert (skjkasdkd({8191}) == 19);\n assert (skjkasdkd({8191, 123456, 127, 7}) == 19);\n assert (skjkasdkd({127, 97, 8192}) == 10);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint skjkasdkd(vector lst){\n", "example_test": "#undef NDEBUG\n#include\n#undef NDEBUG\n#include\n#undef NDEBUG\n#include\nint main(){\n assert (skjkasdkd({0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3}) == 10);\n assert (skjkasdkd({1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1}) == 25);\n assert (skjkasdkd({1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3}) == 13);\n assert (skjkasdkd({0,724,32,71,99,32,6,0,5,91,83,0,5,6}) == 11);\n assert (skjkasdkd({0,81,12,3,1,21}) == 3);\n assert (skjkasdkd({0,8,1,2,1,7}) == 7);\n}\n"} {"task_id": "CPP/95", "prompt": "/*\nGiven a map, return true if all keys are strings in lower \ncase or all keys are strings in upper case, else return false.\nThe function should return false is the given map is empty.\nExamples:\ncheck_map_case({{\"a\",\"apple\"}, {\"b\",\"banana\"}}) should return true.\ncheck_map_case({{\"a\",\"apple\"}, {\"A\",\"banana\"}, {\"B\",\"banana\"}}) should return false.\ncheck_map_case({{\"a\",\"apple\"}, {\"8\",\"banana\"}, {\"a\",\"apple\"}}) should return false.\ncheck_map_case({{\"Name\",\"John\"}, {\"Age\",\"36\"}, {\"City\",\"Houston\"}}) should return false.\ncheck_map_case({{\"STATE\",\"NC\"}, {\"ZIP\",\"12345\"} }) should return true.\n*/\n#include\n#include\n#include\nusing namespace std;\nbool check_dict_case(map dict){\n", "canonical_solution": " map::iterator it;\n int islower=0,isupper=0;\n if (dict.size()==0) return false;\n for (it=dict.begin();it!=dict.end();it++)\n {\n string key=it->first;\n \n for (int i=0;i90 and key[i]<97) or key[i]>122) return false;\n if (key[i]>=65 and key[i]<=90) isupper=1;\n if (key[i]>=97 and key[i]<=122) islower=1;\n if (isupper+islower==2) return false;\n }\n\n }\n return true;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (check_dict_case({{\"p\",\"pineapple\"}, {\"b\",\"banana\"}}) == true);\n assert (check_dict_case({{\"p\",\"pineapple\"}, {\"A\",\"banana\"}, {\"B\",\"banana\"}}) == false);\n assert (check_dict_case({{\"p\",\"pineapple\"}, {\"5\",\"banana\"}, {\"a\",\"apple\"}}) == false);\n assert (check_dict_case({{\"Name\",\"John\"}, {\"Age\",\"36\"}, {\"City\",\"Houston\"}}) == false);\n assert (check_dict_case({{\"STATE\",\"NC\"}, {\"ZIP\",\"12345\"} }) == true );\n assert (check_dict_case({{\"fruit\",\"Orange\"}, {\"taste\",\"Sweet\"} }) == true );\n assert (check_dict_case({}) == false);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool check_dict_case(map dict){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (check_dict_case({{\"p\",\"pineapple\"}, {\"b\",\"banana\"}}) == true);\n assert (check_dict_case({{\"p\",\"pineapple\"}, {\"A\",\"banana\"}, {\"B\",\"banana\"}}) == false);\n assert (check_dict_case({{\"p\",\"pineapple\"}, {\"5\",\"banana\"}, {\"a\",\"apple\"}}) == false);\n assert (check_dict_case({{\"Name\",\"John\"}, {\"Age\",\"36\"}, {\"City\",\"Houston\"}}) == false);\n assert (check_dict_case({{\"STATE\",\"NC\"}, {\"ZIP\",\"12345\"} }) == true );\n}\n"} {"task_id": "CPP/96", "prompt": "/*\nImplement a function that takes an non-negative integer and returns a vector of the first n\nintegers that are prime numbers and less than n.\nfor example:\ncount_up_to(5) => {2,3}\ncount_up_to(11) => {2,3,5,7}\ncount_up_to(0) => {}\ncount_up_to(20) => {2,3,5,7,11,13,17,19}\ncount_up_to(1) => {}\ncount_up_to(18) => {2,3,5,7,11,13,17}\n*/\n#include\n#include\nusing namespace std;\nvector count_up_to(int n){\n", "canonical_solution": " vector out={};\n int i,j;\n for (i=2;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\nvector count_up_to(int n){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\nint multiply(int a,int b){\n", "canonical_solution": " return (abs(a)%10)*(abs(b)%10);\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (multiply(148, 412) == 16 );\n assert (multiply(19, 28) == 72 );\n assert (multiply(2020, 1851) == 0);\n assert (multiply(14,-15) == 20 );\n assert (multiply(76, 67) == 42 );\n assert (multiply(17, 27) == 49 );\n assert (multiply(0, 1) == 0);\n assert (multiply(0, 0) == 0);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint multiply(int a,int b){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (multiply(148, 412) == 16 );\n assert (multiply(19, 28) == 72 );\n assert (multiply(2020, 1851) == 0);\n assert (multiply(14,-15) == 20 );\n}\n"} {"task_id": "CPP/98", "prompt": "/*\nGiven a string s, count the number of uppercase vowels in even indices.\n\nFor example:\ncount_upper(\"aBCdEf\") returns 1\ncount_upper(\"abcdefg\") returns 0\ncount_upper(\"dBBE\") returns 0\n*/\n#include\n#include\n#include\nusing namespace std;\nint count_upper(string s){\n", "canonical_solution": " string uvowel=\"AEIOU\";\n int count=0;\n for (int i=0;i*2\nint main(){\n assert (count_upper(\"aBCdEf\") == 1);\n assert (count_upper(\"abcdefg\") == 0);\n assert (count_upper(\"dBBE\") == 0);\n assert (count_upper(\"B\") == 0);\n assert (count_upper(\"U\") == 1);\n assert (count_upper(\"\") == 0);\n assert (count_upper(\"EEEE\") == 2);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nint count_upper(string s){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (count_upper(\"aBCdEf\") == 1);\n assert (count_upper(\"abcdefg\") == 0);\n assert (count_upper(\"dBBE\") == 0);\n}\n"} {"task_id": "CPP/99", "prompt": "/*\nCreate a function that takes a value (string) representing a number\nand returns the closest integer to it. If the number is equidistant\nfrom two integers, round it away from zero.\n\nExamples\n>>> closest_integer(\"10\")\n10\n>>> closest_integer(\"15.3\")\n15\n\nNote:\nRounding away from zero means that if the given number is equidistant\nfrom two integers, the one you should return is the one that is the\nfarthest from zero. For example closest_integer(\"14.5\") should\nreturn 15 and closest_integer(\"-14.5\") should return -15.\n*/\n#include\n#include\n#include\nusing namespace std;\nint closest_integer(string value){\n", "canonical_solution": " double w;\n w=atof(value.c_str());\n return round(w);\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (closest_integer(\"10\") == 10);\n assert (closest_integer(\"14.5\") == 15);\n assert (closest_integer(\"-15.5\") == -16);\n assert (closest_integer(\"15.3\") == 15);\n assert (closest_integer(\"0\") == 0);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint closest_integer(string value){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (closest_integer(\"10\") == 10);\n assert (closest_integer(\"15.3\") == 15);\n}\n"} {"task_id": "CPP/100", "prompt": "/*\nGiven a positive integer n, you have to make a pile of n levels of stones.\nThe first level has n stones.\nThe number of stones in the next level is:\n - the next odd number if n is odd.\n - the next even number if n is even.\nReturn the number of stones in each level in a vector, where element at index\ni represents the number of stones in the level (i+1).\n\nExamples:\n>>> make_a_pile(3)\n{3, 5, 7}\n*/\n#include\n#include\nusing namespace std;\nvector make_a_pile(int n){\n", "canonical_solution": " vector out={n};\n for (int i=1;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\nvector make_a_pile(int n){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\nvector words_string(string s){\n", "canonical_solution": " string current=\"\";\n vector out={};\n s=s+' ';\n for (int i=0;i0)\n {\n out.push_back(current);\n current=\"\";\n }\n }\n else current=current+s[i];\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector words_string(string s){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\nusing namespace std;\nint choose_num(int x,int y){\n", "canonical_solution": " if (y\nint main(){\n assert (choose_num(12, 15) == 14);\n assert (choose_num(13, 12) == -1);\n assert (choose_num(33, 12354) == 12354);\n assert (choose_num(5234, 5233) == -1);\n assert (choose_num(6, 29) == 28);\n assert (choose_num(27, 10) == -1);\n assert (choose_num(7, 7) == -1);\n assert (choose_num(546, 546) == 546);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nint choose_num(int x,int y){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (choose_num(12, 15) == 14);\n assert (choose_num(13, 12) == -1);\n}\n"} {"task_id": "CPP/103", "prompt": "/*\nYou are given two positive integers n and m, and your task is to compute the\naverage of the integers from n through m (including n and m). \nRound the answer to the nearest integer(smaller one) and convert that to binary.\nIf n is greater than m, return \"-1\".\nExample:\nrounded_avg(1, 5) => \"11\"\nrounded_avg(7, 5) => \"-1\"\nrounded_avg(10, 20) => \"1111\"\nrounded_avg(20, 33) => \"11010\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring rounded_avg(int n,int m){\n", "canonical_solution": " if (n>m) return \"-1\";\n int num=(m+n)/2;\n string out=\"\";\n while (num>0)\n {\n out=to_string(num%2)+out;\n num=num/2;\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (rounded_avg(1, 5) == \"11\");\n assert (rounded_avg(7, 13) == \"1010\");\n assert (rounded_avg(964,977) == \"1111001010\");\n assert (rounded_avg(996,997) == \"1111100100\");\n assert (rounded_avg(560,851) == \"1011000001\"); \n assert (rounded_avg(185,546) == \"101101101\");\n assert (rounded_avg(362,496) == \"110101101\");\n assert (rounded_avg(350,902) == \"1001110010\");\n assert (rounded_avg(197,233) == \"11010111\");\n assert (rounded_avg(7, 5) == \"-1\");\n assert (rounded_avg(5, 1) == \"-1\");\n assert (rounded_avg(5, 5) == \"101\");\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring rounded_avg(int n,int m){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (rounded_avg(1, 5) == \"11\");\n assert (rounded_avg(7, 5) == \"-1\");\n assert (rounded_avg(10,20) == \"1111\");\n assert (rounded_avg(20,33) == \"11010\");\n}\n"} {"task_id": "CPP/104", "prompt": "/*\nGiven a vector of positive integers x. return a sorted vector of all \nelements that hasn't any even digit.\n\nNote: Returned vector should be sorted in increasing order.\n\nFor example:\n>>> unique_digits({15, 33, 1422, 1})\n{1, 15, 33}\n>>> unique_digits({152, 323, 1422, 10})\n{}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector unique_digits(vector x){\n", "canonical_solution": " vector out={};\n for (int i=0;i0 and u)\n {\n if (num%2==0) u=false;\n num=num/10;\n }\n if (u) out.push_back(x[i]);\n }\n sort(out.begin(),out.end());\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector unique_digits(vector x){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i sort arr -> {1, 1, 2, 2, 3, 4, 5, 8} \n -> reverse arr -> {8, 5, 4, 3, 2, 2, 1, 1}\n return {\"Eight\", \"Five\", \"Four\", \"Three\", \"Two\", \"Two\", \"One\", \"One\"}\n\n If the vector is empty, return an empty vector:\n arr = {}\n return {}\n\n If the vector has any strange number ignore it:\n arr = {1, -1 , 55} \n -> sort arr -> {-1, 1, 55}\n -> reverse arr -> {55, 1, -1}\n return = {\"One\"}\n*/\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nvector by_length(vector arr){\n", "canonical_solution": " map numto={{0,\"Zero\"},{1,\"One\"},{2,\"Two\"},{3,\"Three\"},{4,\"Four\"},{5,\"Five\"},{6,\"Six\"},{7,\"Seven\"},{8,\"Eight\"},{9,\"Nine\"}};\n sort(arr.begin(),arr.end());\n vector out={};\n for (int i=arr.size()-1;i>=0;i-=1)\n if (arr[i]>=1 and arr[i]<=9)\n out.push_back(numto[arr[i]]);\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nvector by_length(vector arr){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\nvector f(int n){\n", "canonical_solution": " int sum=0,prod=1;\n vector out={};\n for (int i=1;i<=n;i++)\n {\n sum+=i;\n prod*=i;\n if (i%2==0) out.push_back(prod);\n else out.push_back(sum);\n } \n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\nvector f(int n){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\nvector even_odd_palindrome(int n){\n", "canonical_solution": " int num1=0,num2=0;\n for (int i=1;i<=n;i++)\n {\n string w=to_string(i);\n string p(w.rbegin(),w.rend());\n if (w==p and i%2==1) num1+=1;\n if (w==p and i%2==0) num2+=1;\n \n }\n return {num2,num1};\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector even_odd_palindrome(int n){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i 0.\nIf a number is negative, then its first signed digit will be negative:\ne.g. -123 has signed digits -1, 2, and 3.\n>>> count_nums({}) == 0\n>>> count_nums({-1, 11, -11}) == 1\n>>> count_nums({1, 1, 2}) == 3\n*/\n#include\n#include\n#include\nusing namespace std;\nint count_nums(vector n){\n", "canonical_solution": " int num=0;\n for (int i=0;i0) num+=1;\n else\n {\n int sum=0;\n int w;\n w=abs(n[i]);\n while (w>=10)\n {\n sum+=w%10;\n w=w/10;\n }\n sum-=w;\n if (sum>0) num+=1;\n }\n return num;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (count_nums({}) == 0);\n assert (count_nums({-1, -2, 0}) == 0);\n assert (count_nums({1, 1, 2, -2, 3, 4, 5}) == 6);\n assert (count_nums({1, 6, 9, -6, 0, 1, 5}) == 5);\n assert (count_nums({1, 100, 98, -7, 1, -1}) == 4);\n assert (count_nums({12, 23, 34, -45, -56, 0}) == 5);\n assert (count_nums({-0, 1}) == 1);\n assert (count_nums({1}) == 1);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint count_nums(vector n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (count_nums({}) == 0);\n assert (count_nums({-1, 11, -11}) == 1);\n assert (count_nums({1, 1, 2}) == 3);\n}\n"} {"task_id": "CPP/109", "prompt": "/*\nWe have a vector \"arr\" of N integers arr[1], arr[2], ..., arr[N].The\nnumbers in the vector will be randomly ordered. Your task is to determine if\nit is possible to get a vector sorted in non-decreasing order by performing \nthe following operation on the given vector:\n You are allowed to perform right shift operation any number of times.\n\nOne right shift operation means shifting all elements of the vector by one\nposition in the right direction. The last element of the vector will be moved to\nthe starting position in the vector i.e. 0th index. \n\nIf it is possible to obtain the sorted vector by performing the above operation\nthen return true else return false.\nIf the given vector is empty then return true.\n\nNote: The given vector is guaranteed to have unique elements.\n\nFor Example:\n\nmove_one_ball({3, 4, 5, 1, 2})==>true\nExplanation: By performing 2 right shift operations, non-decreasing order can\n be achieved for the given vector.\nmove_one_ball({3, 5, 4, 1, 2})==>false\nExplanation:It is not possible to get non-decreasing order for the given\n vector by performing any number of right shift operations.\n \n*/\n#include\n#include\nusing namespace std;\nbool move_one_ball(vector arr){\n", "canonical_solution": " int num=0;\n if (arr.size()==0) return true;\n for (int i=1;iarr[0]) num+=1;\n if (num<2) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (move_one_ball({3, 4, 5, 1, 2})==true);\n assert (move_one_ball({3, 5, 10, 1, 2})==true);\n assert (move_one_ball({4, 3, 1, 2})==false);\n assert (move_one_ball({3, 5, 4, 1, 2})==false);\n assert (move_one_ball({})==true);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool move_one_ball(vector arr){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (move_one_ball({3, 4, 5, 1, 2})==true);\n assert (move_one_ball({3, 5, 4, 1, 2})==false);\n}\n"} {"task_id": "CPP/110", "prompt": "/*\nIn this problem, you will implement a function that takes two vectors of numbers,\nand determines whether it is possible to perform an exchange of elements\nbetween them to make lst1 a vector of only even numbers.\nThere is no limit on the number of exchanged elements between lst1 and lst2.\nIf it is possible to exchange elements between the lst1 and lst2 to make\nall the elements of lst1 to be even, return \"YES\".\nOtherwise, return \"NO\".\nFor example:\nexchange({1, 2, 3, 4}, {1, 2, 3, 4}) => \"YES\"\nexchange({1, 2, 3, 4}, {1, 5, 3, 4}) => \"NO\"\nIt is assumed that the input vectors will be non-empty.\n*/\n#include\n#include\n#include\nusing namespace std;\nstring exchange(vector lst1,vector lst2){\n", "canonical_solution": " int num=0;\n for (int i=0;i=lst1.size()) return \"YES\";\n return \"NO\";\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (exchange({1, 2, 3, 4}, {1, 2, 3, 4}) == \"YES\");\n assert (exchange({1, 2, 3, 4}, {1, 5, 3, 4}) == \"NO\");\n assert (exchange({1, 2, 3, 4}, {2, 1, 4, 3}) == \"YES\" );\n assert (exchange({5, 7, 3}, {2, 6, 4}) == \"YES\");\n assert (exchange({5, 7, 3}, {2, 6, 3}) == \"NO\" );\n assert (exchange({3, 2, 6, 1, 8, 9}, {3, 5, 5, 1, 1, 1}) == \"NO\");\n assert (exchange({100, 200}, {200, 200}) == \"YES\");\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring exchange(vector lst1,vector lst2){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (exchange({1, 2, 3, 4}, {1, 2, 3, 4}) == \"YES\");\n assert (exchange({1, 2, 3, 4}, {1, 5, 3, 4}) == \"NO\");\n}\n"} {"task_id": "CPP/111", "prompt": "/*\nGiven a string representing a space separated lowercase letters, return a map\nof the letter with the most repetition and containing the corresponding count.\nIf several letters have the same occurrence, return all of them.\n\nExample:\nhistogram(\"a b c\") == {{\"a\", 1}, {\"b\", 1}, {\"c\", 1}}\nhistogram(\"a b b a\") == {{\"a\", 2}, {\"b\", 2}}\nhistogram(\"a b c a b\") == {{\"a\", 2}, {\"b\", 2}}\nhistogram(\"b b b b a\") == {{\"b\", 4}}\nhistogram(\"\") == {}\n\n*/\n#include\n#include\n#include\nusing namespace std;\nmap histogram(string test){\n", "canonical_solution": " map count={},out={};\n map ::iterator it;\n int max=0;\n for (int i=0;imax) max=count[test[i]];\n }\n for (it=count.begin();it!=count.end();it++)\n {\n char w1=it->first;\n int w2=it->second;\n if (w2==max) out[w1]=w2;\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(map a,map b){\n if (a.size()!=b.size()) return false;\n map ::iterator it;\n for (it=a.begin();it!=a.end();it++)\n {\n char w1=it->first;\n int w2=it->second;\n if (b.find(w1)==b.end()) return false;\n if (b[w1]!=w2) return false;\n }\n\n return true;\n}\nint main(){\n assert (issame(histogram(\"a b b a\") , {{'a',2},{'b', 2}}));\n assert (issame(histogram(\"a b c a b\") , {{'a', 2},{'b', 2}}));\n assert (issame(histogram(\"a b c d g\") , {{'a', 1}, {'b', 1}, {'c', 1}, {'d', 1}, {'g', 1}}));\n assert (issame(histogram(\"r t g\") , {{'r', 1},{'t', 1},{'g', 1}}));\n assert (issame(histogram(\"b b b b a\") , {{'b', 4}}));\n assert (issame(histogram(\"r t g\") , {{'r', 1},{'t', 1},{'g', 1}}));\n assert (issame(histogram(\"\") , {}));\n assert (issame(histogram(\"a\") , {{'a', 1}}));\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nmap histogram(string test){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(map a,map b){\n if (a.size()!=b.size()) return false;\n map ::iterator it;\n for (it=a.begin();it!=a.end();it++)\n {\n char w1=it->first;\n int w2=it->second;\n if (b.find(w1)==b.end()) return false;\n if (b[w1]!=w2) return false;\n }\n return true;\n}\nint main(){\n assert (issame(histogram(\"a b b a\") , {{'a',2},{'b', 2}}));\n assert (issame(histogram(\"a b c a b\") , {{'a', 2},{'b', 2}}));\n assert (issame(histogram(\"a b c\") , {{'a', 1},{'b', 1},{'c', 1}}));\n assert (issame(histogram(\"b b b b a\") , {{'b', 4}}));\n assert (issame(histogram(\"\") , {}));\n}\n"} {"task_id": "CPP/112", "prompt": "/*\nTask\nWe are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\nthen check if the result string is palindrome.\nA string is called palindrome if it reads the same backward as forward.\nYou should return a vector containing the result string and \"True\"/\"False\" for the check.\nExample\nFor s = \"abcde\", c = \"ae\", the result should be (\"bcd\",\"False\")\nFor s = \"abcdef\", c = \"b\" the result should be (\"acdef\",\"False\")\nFor s = \"abcdedcba\", c = \"ab\", the result should be (\"cdedc\",\"True\")\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nvector reverse_delete(string s,string c){\n", "canonical_solution": " string n=\"\";\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nvector reverse_delete(string s,string c){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> odd_count({\"1234567\"})\n{'the number of odd elements 4n the str4ng 4 of the 4nput.\"}\n>>> odd_count({\"3\",\"11111111\"})\n{'the number of odd elements 1n the str1ng 1 of the 1nput.\",\n 'the number of odd elements 8n the str8ng 8 of the 8nput.\"}\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nvector odd_count(vector lst){\n", "canonical_solution": " vector out={};\n for (int i=0;i=48 and lst[i][j]<=57 and lst[i][j]%2==1)\n sum+=1;\n string s=\"the number of odd elements in the string i of the input.\";\n string s2=\"\";\n for (int j=0;j\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector odd_count(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\nlong long minSubArraySum(vector nums){\n", "canonical_solution": " long long current,min;\n current=nums[0];\n min=nums[0];\n for (int i=1;i\nint main(){\n assert (minSubArraySum({2, 3, 4, 1, 2, 4}) == 1);\n assert (minSubArraySum({-1, -2, -3}) == -6);\n assert (minSubArraySum({-1, -2, -3, 2, -10}) == -14);\n assert (minSubArraySum({-9999999999999999}) == -9999999999999999);\n assert (minSubArraySum({0, 10, 20, 1000000}) == 0);\n assert (minSubArraySum({-1, -2, -3, 10, -5}) == -6);\n assert (minSubArraySum({100, -1, -2, -3, 10, -5}) == -6);\n assert (minSubArraySum({10, 11, 13, 8, 3, 4}) == 3);\n assert (minSubArraySum({100, -33, 32, -1, 0, -2}) == -33);\n assert (minSubArraySum({-10}) == -10);\n assert (minSubArraySum({7}) == 7);\n assert (minSubArraySum({1, -1}) == -1);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nlong long minSubArraySum(vector nums){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (minSubArraySum({2, 3, 4, 1, 2, 4}) == 1);\n assert (minSubArraySum({-1, -2, -3}) == -6);\n}\n"} {"task_id": "CPP/115", "prompt": "/*\nYou are given a rectangular grid of wells. Each row represents a single well,\nand each 1 in a row represents a single unit of water.\nEach well has a corresponding bucket that can be used to extract water from it, \nand all buckets have the same capacity.\nYour task is to use the buckets to empty the wells.\nOutput the number of times you need to lower the buckets.\n\nExample 1:\n Input: \n grid : {{0,0,1,0}, {0,1,0,0}, {1,1,1,1}}\n bucket_capacity : 1\n Output: 6\n\nExample 2:\n Input: \n grid : {{0,0,1,1}, {0,0,0,0}, {1,1,1,1}, {0,1,1,1}}\n bucket_capacity : 2\n Output: 5\n\nExample 3:\n Input: \n grid : {{0,0,0}, {0,0,0}}\n bucket_capacity : 5\n Output: 0\n\nConstraints:\n * all wells have the same length\n * 1 <= grid.length <= 10^2\n * 1 <= grid{:,1}.length <= 10^2\n * grid{i}{j} -> 0 | 1\n * 1 <= capacity <= 10\n*/\n#include\n#include\nusing namespace std;\nint max_fill(vector> grid,int capacity){\n", "canonical_solution": " int out=0;\n for (int i=0;i0) out+=(sum-1)/capacity+1;\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (max_fill({{0,0,1,0}, {0,1,0,0}, {1,1,1,1}}, 1) == 6);\n assert (max_fill({{0,0,1,1}, {0,0,0,0}, {1,1,1,1}, {0,1,1,1}}, 2) == 5);\n assert (max_fill({{0,0,0}, {0,0,0}}, 5) == 0);\n assert (max_fill({{1,1,1,1}, {1,1,1,1}}, 2) == 4);\n assert (max_fill({{1,1,1,1}, {1,1,1,1}}, 9) == 2);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint max_fill(vector> grid,int capacity){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (max_fill({{0,0,1,0}, {0,1,0,0}, {1,1,1,1}}, 1) == 6);\n assert (max_fill({{0,0,1,1}, {0,0,0,0}, {1,1,1,1}, {0,1,1,1}}, 2) == 5);\n assert (max_fill({{0,0,0}, {0,0,0}}, 5) == 0);\n}\n"} {"task_id": "CPP/116", "prompt": "/*\nIn this Kata, you have to sort a vector of non-negative integers according to\nnumber of ones in their binary representation in ascending order.\nFor similar number of ones, sort based on decimal value.\n\nIt must be implemented like this:\n>>> sort_vector({1, 5, 2, 3, 4}) == {1, 2, 3, 4, 5}\n>>> sort_vector({-2, -3, -4, -5, -6}) == {-6, -5, -4, -3, -2}\n>>> sort_vector({1, 0, 2, 3, 4}) == {0, 1, 2, 3, 4}\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nvector sort_array(vector arr){\n", "canonical_solution": " vector bin={};\n int m;\n\n for (int i=0;i0)\n {\n b+=n%2;n=n/2;\n }\n bin.push_back(b);\n }\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector sort_array(vector arr){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i {\"little\"}\nselect_words(\"Mary had a little lamb\", 3) ==> {\"Mary\", \"lamb\"}\nselect_words('simple white space\", 2) ==> {}\nselect_words(\"Hello world\", 4) ==> {\"world\"}\nselect_words(\"Uncle sam\", 3) ==> {\"Uncle\"}\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nvector select_words(string s,int n){\n", "canonical_solution": " string vowels=\"aeiouAEIOU\";\n string current=\"\";\n vector out={};\n int numc=0;\n s=s+' ';\n for (int i=0;i=65 and s[i]<=90) or (s[i]>=97 and s[i]<=122))\n if (find(vowels.begin(),vowels.end(),s[i])==vowels.end())\n numc+=1;\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nvector select_words(string s,int n){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i \"u\"\nget_closest_vowel(\"FULL\") ==> \"U\"\nget_closest_vowel(\"quick\") ==> \"\"\nget_closest_vowel(\"ab\") ==> \"\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring get_closest_vowel(string word){\n", "canonical_solution": " string out=\"\";\n string vowels=\"AEIOUaeiou\";\n for (int i=word.length()-2;i>=1;i-=1)\n if (find(vowels.begin(),vowels.end(),word[i])!=vowels.end())\n if (find(vowels.begin(),vowels.end(),word[i+1])==vowels.end())\n if (find(vowels.begin(),vowels.end(),word[i-1])==vowels.end())\n return out+word[i];\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (get_closest_vowel(\"yogurt\") == \"u\");\n assert (get_closest_vowel(\"full\") == \"u\");\n assert (get_closest_vowel(\"easy\") == \"\");\n assert (get_closest_vowel(\"eAsy\") == \"\");\n assert (get_closest_vowel(\"ali\") == \"\");\n assert (get_closest_vowel(\"bad\") == \"a\");\n assert (get_closest_vowel(\"most\") ==\"o\");\n assert (get_closest_vowel(\"ab\") == \"\");\n assert (get_closest_vowel(\"ba\") == \"\");\n assert (get_closest_vowel(\"quick\") == \"\");\n assert (get_closest_vowel(\"anime\") == \"i\");\n assert (get_closest_vowel(\"Asia\") == \"\");\n assert (get_closest_vowel(\"Above\") == \"o\");\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nstring get_closest_vowel(string word){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (get_closest_vowel(\"yogurt\") == \"u\");\n assert (get_closest_vowel(\"FULL\") == \"U\");\n assert (get_closest_vowel(\"ab\") == \"\");\n assert (get_closest_vowel(\"quick\") == \"\");\n}\n"} {"task_id": "CPP/119", "prompt": "/*\nYou are given a vector of two strings, both strings consist of open\nparentheses '(' or close parentheses ')' only.\nYour job is to check if it is possible to concatenate the two strings in\nsome order, that the resulting string will be good.\nA string S is considered to be good if and only if all parentheses in S\nare balanced. For example: the string \"(())()\" is good, while the string\n\"())\" is not.\nReturn \"Yes\" if there's a way to make a good string, and return \"No\" otherwise.\n\nExamples:\nmatch_parens({\"()(\", \")\"}) == \"Yes\"\nmatch_parens({\")\", \")\"}) == \"No\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring match_parens(vector lst){\n", "canonical_solution": " string l1=lst[0]+lst[1];\n int i,count=0;\n bool can=true;\n for (i=0;i\nint main(){\n assert (match_parens({\"()(\", \")\"}) == \"Yes\");\n assert (match_parens({\")\", \")\"}) == \"No\");\n assert (match_parens({\"(()(())\", \"())())\"}) == \"No\");\n assert (match_parens({\")())\", \"(()()(\"}) == \"Yes\");\n assert (match_parens({\"(())))\", \"(()())((\"}) == \"Yes\");\n assert (match_parens({\"()\", \"())\"}) == \"No\");\n assert (match_parens({\"(()(\", \"()))()\"}) == \"Yes\");\n assert (match_parens({\"((((\", \"((())\"}) == \"No\");\n assert (match_parens({\")(()\", \"(()(\"}) == \"No\");\n assert (match_parens({\")(\", \")(\"}) == \"No\");\n assert (match_parens({\"(\", \")\"}) == \"Yes\");\n assert (match_parens({\")\", \"(\"}) == \"Yes\" );\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring match_parens(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (match_parens({\"()(\", \")\"}) == \"Yes\");\n assert (match_parens({\")\", \")\"}) == \"No\");\n}\n"} {"task_id": "CPP/120", "prompt": "/*\nGiven a vector arr of integers and a positive integer k, return a sorted vector \nof length k with the maximum k numbers in arr.\n\nExample 1:\n\n Input: arr = {-3, -4, 5}, k = 3\n Output: {-4, -3, 5}\n\nExample 2:\n\n Input: arr = {4, -4, 4}, k = 2\n Output: {4, 4}\n\nExample 3:\n\n Input: arr = {-3, 2, 1, 2, -1, -2, 1}, k = 1\n Output: {2}\n\nNote:\n 1. The length of the vector will be in the range of {1, 1000}.\n 2. The elements in the vector will be in the range of {-1000, 1000}.\n 3. 0 <= k <= len(arr)\n*/\n#include\n#include\n#include\nusing namespace std;\nvector maximum(vector arr,int k){\n", "canonical_solution": " sort(arr.begin(),arr.end());\n vector out(arr.end()-k,arr.end());\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector maximum(vector arr,int k){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i 12\nsolution({3, 3, 3, 3, 3}) ==> 9\nsolution({30, 13, 24, 321}) ==>0\n*/\n#include\n#include\nusing namespace std;\nint solutions(vector lst){\n", "canonical_solution": " int sum=0;\n for (int i=0;i*2\nint main(){\n assert (solutions({5, 8, 7, 1}) == 12);\n assert (solutions({3, 3, 3, 3, 3}) == 9);\n assert (solutions({30, 13, 24, 321}) == 0);\n assert (solutions({5, 9}) == 5);\n assert (solutions({2, 4, 8}) == 0);\n assert (solutions({30, 13, 23, 32}) == 23);\n assert (solutions({3, 13, 2, 9}) == 3);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint solutions(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (solutions({5, 8, 7, 1}) == 12);\n assert (solutions({3, 3, 3, 3, 3}) == 9);\n assert (solutions({30, 13, 24, 321}) == 0);\n}\n"} {"task_id": "CPP/122", "prompt": "/*\nGiven a non-empty vector of integers arr and an integer k, return\nthe sum of the elements with at most two digits from the first k elements of arr.\n\nExample:\n\n Input: arr = {111,21,3,4000,5,6,7,8,9}, k = 4\n Output: 24 # sum of 21 + 3\n\nConstraints:\n 1. 1 <= len(arr) <= 100\n 2. 1 <= k <= len(arr)\n*/\n#include\n#include\nusing namespace std;\nint add_elements(vector arr,int k){\n", "canonical_solution": " int sum=0;\n for (int i=0;i=-99 and arr[i]<=99)\n sum+=arr[i];\n return sum;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (add_elements({1,-2,-3,41,57,76,87,88,99}, 3) == -4);\n assert (add_elements({111,121,3,4000,5,6}, 2) == 0);\n assert (add_elements({11,21,3,90,5,6,7,8,9}, 4) == 125);\n assert (add_elements({111,21,3,4000,5,6,7,8,9}, 4) == 24);\n assert (add_elements({1}, 1) == 1);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint add_elements(vector arr,int k){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (add_elements({111,21,3,4000,5,6,7,8,9}, 4) == 24);\n}\n"} {"task_id": "CPP/123", "prompt": "/*\nGiven a positive integer n, return a sorted vector that has the odd numbers in collatz sequence.\n\nThe Collatz conjecture is a conjecture in mathematics that concerns a sequence defined\nas follows: start with any positive integer n. Then each term is obtained from the \nprevious term as follows: if the previous term is even, the next term is one half of \nthe previous term. If the previous term is odd, the next term is 3 times the previous\nterm plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.\n\nNote: \n 1. Collatz(1) is {1}.\n 2. returned vector sorted in increasing order.\n\nFor example:\nget_odd_collatz(5) returns {1, 5} // The collatz sequence for 5 is {5, 16, 8, 4, 2, 1}, so the odd numbers are only 1, and 5.\n*/\n#include\n#include\n#include\nusing namespace std;\nvector get_odd_collatz(int n){\n", "canonical_solution": " vector out={1};\n while (n!=1)\n {\n if (n%2==1) {out.push_back(n); n=n*3+1;}\n else n=n/2;\n }\n sort(out.begin(),out.end());\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector get_odd_collatz(int n){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i true\n\nvalid_date(\"15-01-2012\") => false\n\nvalid_date(\"04-0-2040\") => false\n\nvalid_date(\"06-04-2020\") => true\n\nvalid_date(\"06/04/2020\") => false\n*/\n#include\n#include\nusing namespace std;\nbool valid_date(string date){\n", "canonical_solution": " int mm,dd,yy,i;\n if (date.length()!=10) return false;\n for (int i=0;i<10;i++)\n if (i==2 or i==5)\n {\n if (date[i]!='-') return false;\n }\n else\n if (date[i]<48 or date[i]>57) return false;\n\n mm=atoi(date.substr(0,2).c_str());\n dd=atoi(date.substr(3,2).c_str());\n yy=atoi(date.substr(6,4).c_str());\n if (mm<1 or mm>12) return false;\n if (dd<1 or dd>31) return false;\n if (dd==31 and (mm==4 or mm==6 or mm==9 or mm==11 or mm==2)) return false;\n if (dd==30 and mm==2) return false;\n return true;\n\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (valid_date(\"03-11-2000\") == true);\n assert (valid_date(\"15-01-2012\") == false);\n assert (valid_date(\"04-0-2040\") == false);\n assert (valid_date(\"06-04-2020\") == true);\n assert (valid_date(\"01-01-2007\") == true);\n assert (valid_date(\"03-32-2011\") == false);\n assert (valid_date(\"\") == false);\n assert (valid_date(\"04-31-3000\") == false);\n assert (valid_date(\"06-06-2005\") == true);\n assert (valid_date(\"21-31-2000\") == false);\n assert (valid_date(\"04-12-2003\") == true);\n assert (valid_date(\"04122003\") == false);\n assert (valid_date(\"20030412\") == false);\n assert (valid_date(\"2003-04\") == false);\n assert (valid_date(\"2003-04-12\") == false);\n assert (valid_date(\"04-2003\") == false);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nbool valid_date(string date){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (valid_date(\"03-11-2000\") == true);\n assert (valid_date(\"15-01-2012\") == false);\n assert (valid_date(\"04-0-2040\") == false);\n assert (valid_date(\"06-04-2020\") == true);\n assert (valid_date(\"06/04/2020\") == false);\n}\n"} {"task_id": "CPP/125", "prompt": "/*\nGiven a string of words, return a vector of words split on whitespace, if no whitespaces exists in the text you\nshould split on commas ',' if no commas exists you should return a vector with one element, the number of lower-case letters with odd order in the\nalphabet, ord(\"a\") = 0, ord(\"b\") = 1, ... ord(\"z\") = 25\nExamples\nsplit_words(\"Hello world!\") \u279e {\"Hello\", \"world!\"}\nsplit_words(\"Hello,world!\") \u279e {\"Hello\", \"world!\"}\nsplit_words(\"abcdef\") == {\"3\"} \n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nvector split_words(string txt){\n", "canonical_solution": " int i;\n string current=\"\";\n vector out={};\n if (find(txt.begin(),txt.end(),' ')!=txt.end())\n {\n txt=txt+' ';\n for (i=0;i0)out.push_back(current); \n current=\"\";\n }\n else current=current+txt[i];\n return out;\n }\n if (find(txt.begin(),txt.end(),',')!=txt.end())\n {\n txt=txt+',';\n for (i=0;i0)out.push_back(current); \n current=\"\";\n }\n else current=current+txt[i];\n return out;\n }\n int num=0;\n for (i=0;i=97 and txt[i]<=122 and txt[i]%2==0)\n num+=1;\n return {to_string(num)};\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nvector split_words(string txt){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\nbool is_sorted(vector lst){\n", "canonical_solution": " for (int i=1;i=2 and lst[i]==lst[i-1] and lst[i]==lst[i-2]) return false;\n }\n return true;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (is_sorted({5}) == true);\n assert (is_sorted({1, 2, 3, 4, 5}) == true);\n assert (is_sorted({1, 3, 2, 4, 5}) == false);\n assert (is_sorted({1, 2, 3, 4, 5, 6}) == true);\n assert (is_sorted({1, 2, 3, 4, 5, 6, 7}) == true);\n assert (is_sorted({1, 3, 2, 4, 5, 6, 7}) == false);\n assert (is_sorted({}) == true);\n assert (is_sorted({1}) == true);\n assert (is_sorted({3, 2, 1}) == false);\n assert (is_sorted({1, 2, 2, 2, 3, 4}) == false);\n assert (is_sorted({1, 2, 3, 3, 3, 4}) == false);\n assert (is_sorted({1, 2, 2, 3, 3, 4}) == true);\n assert (is_sorted({1, 2, 3, 4}) == true);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nbool is_sorted(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (is_sorted({5}) == true);\n assert (is_sorted({1, 2, 3, 4, 5}) == true);\n assert (is_sorted({1, 3, 2, 4, 5}) == false);\n assert (is_sorted({1, 2, 3, 4, 5, 6}) == true);\n assert (is_sorted({1, 2, 3, 4, 5, 6, 7}) == true);\n assert (is_sorted({1, 3, 2, 4, 5, 6, 7}) == false);\n assert (is_sorted({1, 2, 2, 2, 3, 4}) == false);\n assert (is_sorted({1, 2, 2, 3, 3, 4}) == true);\n}\n"} {"task_id": "CPP/127", "prompt": "/*\nYou are given two intervals,\nwhere each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\nThe given intervals are closed which means that the interval (start, end)\nincludes both start and end.\nFor each given interval, it is assumed that its start is less or equal its end.\nYour task is to determine whether the length of intersection of these two \nintervals is a prime number.\nExample, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\nwhich its length is 1, which not a prime number.\nIf the length of the intersection is a prime number, return \"YES\",\notherwise, return \"NO\".\nIf the two intervals don't intersect, return \"NO\".\n\n\n{input/output} samples:\nintersection({1, 2}, {2, 3}) ==> \"NO\"\nintersection({-1, 1}, {0, 4}) ==> \"NO\"\nintersection({-3, -1}, {-5, 5}) ==> \"YES\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring intersection( vector interval1,vector interval2){\n", "canonical_solution": " int inter1,inter2,l,i;\n inter1=max(interval1[0],interval2[0]);\n inter2=min(interval1[1],interval2[1]);\n l=inter2-inter1;\n if (l<2) return \"NO\";\n for (i=2;i*i<=l;i++)\n if (l%i==0) return \"NO\";\n return \"YES\";\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (intersection({1, 2}, {2, 3}) == \"NO\");\n assert (intersection({-1, 1}, {0, 4}) == \"NO\");\n assert (intersection({-3, -1}, {-5, 5}) == \"YES\");\n assert (intersection({-2, 2}, {-4, 0}) == \"YES\");\n assert (intersection({-11, 2}, {-1, -1}) == \"NO\");\n assert (intersection({1, 2}, {3, 5}) == \"NO\");\n assert (intersection({1, 2}, {1, 2}) == \"NO\");\n assert (intersection({-2, -2}, {-3, -2}) == \"NO\");\n}\n", "declaration": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nstring intersection( vector interval1,vector interval2){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (intersection({1, 2}, {2, 3}) == \"NO\");\n assert (intersection({-1, 1}, {0, 4}) == \"NO\");\n assert (intersection({-3, -1}, {-5, 5}) == \"YES\");\n}\n"} {"task_id": "CPP/128", "prompt": "/*\nYou are given a vector arr of integers and you need to return\nsum of magnitudes of integers multiplied by product of all signs\nof each number in the vector, represented by 1, -1 or 0.\nNote: return -32768 for empty arr.\n\nExample:\n>>> prod_signs({1, 2, 2, -4}) == -9\n>>> prod_signs({0, 1}) == 0\n>>> prod_signs({}) == -32768\n*/\n#include\n#include\n#include\nusing namespace std;\nint prod_signs(vector arr){\n", "canonical_solution": " if (arr.size()==0) return -32768;\n int i,sum=0,prods=1;\n for (i=0;i\nint main(){\n assert (prod_signs({1, 2, 2, -4}) == -9);\n assert (prod_signs({0, 1}) == 0);\n assert (prod_signs({1, 1, 1, 2, 3, -1, 1}) == -10);\n assert (prod_signs({}) == -32768);\n assert (prod_signs({2, 4,1, 2, -1, -1, 9}) == 20);\n assert (prod_signs({-1, 1, -1, 1}) == 4);\n assert (prod_signs({-1, 1, 1, 1}) == -4);\n assert (prod_signs({-1, 1, 1, 0}) == 0);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nint prod_signs(vector arr){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (prod_signs({1, 2, 2, -4}) == -9);\n assert (prod_signs({0, 1}) == 0);\n assert (prod_signs({}) == -32768);\n}\n"} {"task_id": "CPP/129", "prompt": "/*\nGiven a grid with N rows and N columns (N >= 2) and a positive integer k, \neach cell of the grid contains a value. Every integer in the range {1, N * N}\ninclusive appears exactly once on the cells of the grid.\n\nYou have to find the minimum path of length k in the grid. You can start\nfrom any cell, and in each step you can move to any of the neighbor cells,\nin other words, you can go to cells which share an edge with you current\ncell.\nPlease note that a path of length k means visiting exactly k cells (not\nnecessarily distinct).\nYou CANNOT go off the grid.\nA path A (of length k) is considered less than a path B (of length k) if\nafter making the ordered vectors of the values on the cells that A and B go\nthrough (let's call them lst_A and lst_B), lst_A is lexicographically less\nthan lst_B, in other words, there exist an integer index i (1 <= i <= k)\nsuch that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\nlst_A[j] = lst_B[j].\nIt is guaranteed that the answer is unique.\nReturn an ordered vector of the values on the cells that the minimum path go through.\n\nExamples:\n\n Input: grid = { {1,2,3}, {4,5,6}, {7,8,9}}, k = 3\n Output: {1, 2, 1}\n\n Input: grid = { {5,9,3}, {4,1,6}, {7,8,2}}, k = 1\n Output: {1}\n*/\n#include\n#include\nusing namespace std;\nvector minPath(vector> grid, int k){\n", "canonical_solution": " int i,j,x,y,min;\n for (i=0;i0 and grid[x-1][y]0 and grid[x][y-1] out={};\n for (i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector minPath(vector> grid, int k){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\nvector tri(int n){\n", "canonical_solution": " vector out={1,3};\n if (n==0) return {1};\n for (int i=2;i<=n;i++)\n {\n if (i%2==0) out.push_back(1+i/2);\n else out.push_back(out[i-1]+out[i-2]+1+(i+1)/2);\n }\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector tri(int n){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\nint digits(int n){\n", "canonical_solution": " int prod=1,has=0;\n string s=to_string(n);\n for (int i=0;i\nint main(){\n assert (digits(5) == 5);\n assert (digits(54) == 5);\n assert (digits(120) ==1);\n assert (digits(5014) == 5);\n assert (digits(98765) == 315);\n assert (digits(5576543) == 2625);\n assert (digits(2468) == 0);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nint digits(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (digits(1) == 1);\n assert (digits(4) == 0);\n assert (digits(235) ==15);\n}\n"} {"task_id": "CPP/132", "prompt": "/*\nCreate a function that takes a string as input which contains only square brackets.\nThe function should return true if and only if there is a valid subsequence of brackets\nwhere at least one bracket in the subsequence is nested.\n\nis_nested(\"[[]]\") \u279e true\nis_nested(\"[]]]]]]][[[[[]\") \u279e false\nis_nested(\"[][]\") \u279e false\nis_nested(\"[]\") \u279e false\nis_nested(\"[[][]]\") \u279e true\nis_nested(\"[[]][[\") \u279e true\n*/\n#include\n#include\nusing namespace std;\nbool is_nested(string str){\n", "canonical_solution": " int count=0,maxcount=0;\n for (int i=0;imaxcount) maxcount=count;\n if (count<=maxcount-2) return true;\n }\n return false;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (is_nested(\"[[]]\") == true);\n assert (is_nested(\"[]]]]]]][[[[[]\") == false);\n assert (is_nested(\"[][]\") == false);\n assert (is_nested((\"[]\")) == false);\n assert (is_nested(\"[[[[]]]]\") == true);\n assert (is_nested(\"[]]]]]]]]]]\") == false);\n assert (is_nested(\"[][][[]]\") == true);\n assert (is_nested(\"[[]\") == false);\n assert (is_nested(\"[]]\") == false);\n assert (is_nested(\"[[]][[\") == true);\n assert (is_nested(\"[[][]]\") == true);\n assert (is_nested(\"\") == false);\n assert (is_nested(\"[[[[[[[[\") == false);\n assert (is_nested(\"]]]]]]]]\") == false);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nbool is_nested(string str){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (is_nested(\"[[]]\") == true);\n assert (is_nested(\"[]]]]]]][[[[[]\") == false);\n assert (is_nested(\"[][]\") == false);\n assert (is_nested(\"[]\") == false);\n assert (is_nested(\"[[]][[\") == true);\n assert (is_nested(\"[[][]]\") == true);\n}\n"} {"task_id": "CPP/133", "prompt": "/*\nYou are given a vector of numbers.\nYou need to return the sum of squared numbers in the given vector,\nround each element in the vector to the upper int(Ceiling) first.\nExamples:\nFor lst = {1,2,3} the output should be 14\nFor lst = {1,4,9} the output should be 98\nFor lst = {1,3,5,7} the output should be 84\nFor lst = {1.4,4.2,0} the output should be 29\nFor lst = {-2.4,1,1} the output should be 6\n\n\n*/\n#include\n#include\n#include\nusing namespace std;\nint sum_squares(vector lst){\n", "canonical_solution": " int sum=0;\n for (int i=0;i\nint main(){\n assert (sum_squares({1,2,3})==14);\n assert (sum_squares({1.0,2,3})==14);\n assert (sum_squares({1,3,5,7})==84);\n assert (sum_squares({1.4,4.2,0})==29);\n assert (sum_squares({-2.4,1,1})==6);\n assert (sum_squares({100,1,15,2})==10230);\n assert (sum_squares({10000,10000})==200000000);\n assert (sum_squares({-1.4,4.6,6.3})==75);\n assert (sum_squares({-1.4,17.9,18.9,19.9})==1086);\n assert (sum_squares({0})==0);\n assert (sum_squares({-1})==1);\n assert (sum_squares({-1,1,0})==2);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nint sum_squares(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (sum_squares({1,2,3})==14);\n assert (sum_squares({1,4,9})==98);\n assert (sum_squares({1,3,5,7})==84);\n assert (sum_squares({1.4,4.2,0})==29);\n assert (sum_squares({-2.4,1,1})==6);\n}\n"} {"task_id": "CPP/134", "prompt": "/*\nCreate a function that returns true if the last character\nof a given string is an alphabetical character and is not\na part of a word, and false otherwise.\nNote: \"word\" is a group of characters separated by space.\n\nExamples:\ncheck_if_last_char_is_a_letter(\"apple pie\") \u279e false\ncheck_if_last_char_is_a_letter(\"apple pi e\") \u279e true\ncheck_if_last_char_is_a_letter(\"apple pi e \") \u279e false\ncheck_if_last_char_is_a_letter(\"\") \u279e false \n*/\n#include\n#include\nusing namespace std;\nbool check_if_last_char_is_a_letter(string txt){\n", "canonical_solution": " if (txt.length()==0) return false;\n char chr=txt[txt.length()-1];\n if (chr<65 or (chr>90 and chr<97) or chr>122) return false;\n if (txt.length()==1) return true;\n chr=txt[txt.length()-2];\n if ((chr>=65 and chr<=90) or (chr>=97 and chr<=122)) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (check_if_last_char_is_a_letter(\"apple\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pi e\") == true);\n assert (check_if_last_char_is_a_letter(\"eeeee\") == false);\n assert (check_if_last_char_is_a_letter(\"A\") == true);\n assert (check_if_last_char_is_a_letter(\"Pumpkin pie \") == false);\n assert (check_if_last_char_is_a_letter(\"Pumpkin pie 1\") == false);\n assert (check_if_last_char_is_a_letter(\"\") == false);\n assert (check_if_last_char_is_a_letter(\"eeeee e \") == false);\n assert (check_if_last_char_is_a_letter(\"apple pie\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pi e \") == false);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nbool check_if_last_char_is_a_letter(string txt){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (check_if_last_char_is_a_letter(\"apple pi e\") == true);\n assert (check_if_last_char_is_a_letter(\"\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pie\") == false);\n assert (check_if_last_char_is_a_letter(\"apple pi e \") == false);\n}\n"} {"task_id": "CPP/135", "prompt": "/*\nCreate a function which returns the largest index of an element which\nis not greater than or equal to the element immediately preceding it. If\nno such element exists then return -1. The given vector will not contain\nduplicate values.\n\nExamples:\ncan_arrange({1,2,4,3,5}) = 3\ncan_arrange({1,2,3}) = -1\n*/\n#include\n#include\nusing namespace std;\nint can_arrange(vector arr){\n", "canonical_solution": " int max=-1;\n for (int i=0;i\nint main(){\n assert (can_arrange({1,2,4,3,5})==3);\n assert (can_arrange({1,2,4,5})==-1);\n assert (can_arrange({1,4,2,5,6,7,8,9,10})==2);\n assert (can_arrange({4,8,5,7,3})==4);\n assert (can_arrange({})==-1);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nint can_arrange(vector arr){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (can_arrange({1,2,4,3,5})==3);\n assert (can_arrange({1,2,3})==-1);\n}\n"} {"task_id": "CPP/136", "prompt": "/*\nCreate a function that returns a vector (a, b), where \"a\" is\nthe largest of negative integers, and \"b\" is the smallest\nof positive integers in a vector.\nIf there is no negative or positive integers, return them as 0.\n\nExamples:\nlargest_smallest_integers({2, 4, 1, 3, 5, 7}) == {0, 1}\nlargest_smallest_integers({}) == {0,0}\nlargest_smallest_integers({0}) == {0,0}\n*/\n#include\n#include\nusing namespace std;\nvector largest_smallest_integers(vector lst){\n", "canonical_solution": " int maxneg=0,minpos=0;\n for (int i=0;imaxneg)) maxneg=lst[i];\n if (lst[i]>0 and (minpos==0 or lst[i]\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\nvector largest_smallest_integers(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\nboost::any compare_one(boost::any a,boost::any b){\n", "canonical_solution": " double numa,numb;\n boost::any out;\n \n if (a.type()==typeid(string))\n {\n string s;\n s=boost::any_cast(a);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i(a);\n if (a.type()==typeid(double)) numa=boost::any_cast(a);\n }\n if (b.type()==typeid(string))\n {\n string s;\n s=boost::any_cast(b);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i(b);\n if (b.type()==typeid(double)) numb=boost::any_cast(b);\n }\n\n if (numa==numb) return string(\"None\");\n if (numanumb) return a;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (boost::any_cast(compare_one(1, 2)) == 2);\n assert (boost::any_cast(compare_one(1, 2.5))== 2.5);\n assert (boost::any_cast(compare_one(2, 3)) == 3);\n assert (boost::any_cast(compare_one(5, 6)) == 6);\n assert (boost::any_cast(compare_one(1, string(\"2,3\")))== \"2,3\");\n assert (boost::any_cast(compare_one(string(\"5,1\"), string(\"6\"))) == \"6\");\n assert (boost::any_cast(compare_one(string(\"1\"), string(\"2\"))) == \"2\");\n assert (boost::any_cast(compare_one(string(\"1\"), 1)) == \"None\");\n}\n", "declaration": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nboost::any compare_one(boost::any a,boost::any b){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (boost::any_cast(compare_one(1, 2.5))== 2.5);\n assert (boost::any_cast(compare_one(1, string(\"2,3\")))== \"2,3\");\n assert (boost::any_cast(compare_one(string(\"5,1\"), string(\"6\"))) == \"6\");\n assert (boost::any_cast(compare_one(string(\"1\"), 1)) == \"None\");\n}\n"} {"task_id": "CPP/138", "prompt": "/*\nEvaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\nExample\nis_equal_to_sum_even(4) == false\nis_equal_to_sum_even(6) == false\nis_equal_to_sum_even(8) == true\n*/\n#include\nusing namespace std;\nbool is_equal_to_sum_even(int n){\n", "canonical_solution": " if (n%2==0 and n>=8) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (is_equal_to_sum_even(4) == false);\n assert (is_equal_to_sum_even(6) == false);\n assert (is_equal_to_sum_even(8) == true);\n assert (is_equal_to_sum_even(10) == true);\n assert (is_equal_to_sum_even(11) == false);\n assert (is_equal_to_sum_even(12) == true);\n assert (is_equal_to_sum_even(13) == false);\n assert (is_equal_to_sum_even(16) == true);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\nbool is_equal_to_sum_even(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (is_equal_to_sum_even(4) == false);\n assert (is_equal_to_sum_even(6) == false);\n assert (is_equal_to_sum_even(8) == true);\n}\n"} {"task_id": "CPP/139", "prompt": "/*\nThe Brazilian factorial is defined as:\nbrazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\nwhere n > 0\n\nFor example:\n>>> special_factorial(4)\n288\n\nThe function will receive an integer as input and should return the special\nfactorial of this integer.\n*/\n#include\nusing namespace std;\nlong long special_factorial(int n){\n", "canonical_solution": " long long fact=1,bfact=1;\n for (int i=1;i<=n;i++)\n {\n fact=fact*i;\n bfact=bfact*fact;\n }\n return bfact;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (special_factorial(4) == 288);\n assert (special_factorial(5) == 34560);\n assert (special_factorial(7) == 125411328000);\n assert (special_factorial(1) == 1);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\nlong long special_factorial(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (special_factorial(4) == 288);\n}\n"} {"task_id": "CPP/140", "prompt": "/*\nGiven a string text, replace all spaces in it with underscores, \nand if a string has more than 2 consecutive spaces, \nthen replace all consecutive spaces with - \n\nfix_spaces(\"Example\") == \"Example\"\nfix_spaces(\"Example 1\") == \"Example_1\"\nfix_spaces(\" Example 2\") == \"_Example_2\"\nfix_spaces(\" Example 3\") == \"_Example-3\"\n*/\n#include\n#include\nusing namespace std;\nstring fix_spaces(string text){\n", "canonical_solution": " string out=\"\";\n int spacelen=0;\n for (int i=0;i2) out=out+'-';\n spacelen=0;\n out=out+text[i];\n }\n if (spacelen==1) out=out+'_';\n if (spacelen==2) out=out+\"__\";\n if (spacelen>2) out=out+'-';\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (fix_spaces(\"Example\") == \"Example\");\n assert (fix_spaces(\"Mudasir Hanif \") == \"Mudasir_Hanif_\");\n assert (fix_spaces(\"Yellow Yellow Dirty Fellow\") == \"Yellow_Yellow__Dirty__Fellow\");\n assert (fix_spaces(\"Exa mple\") == \"Exa-mple\");\n assert (fix_spaces(\" Exa 1 2 2 mple\") == \"-Exa_1_2_2_mple\");\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\n#include\nstring fix_spaces(string text){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (fix_spaces(\"Example\") == \"Example\");\n assert (fix_spaces(\"Example 1\") == \"Example_1\");\n assert (fix_spaces(\" Example 2\") == \"_Example_2\");\n assert (fix_spaces(\" Example 3\") == \"_Example-3\");\n}\n"} {"task_id": "CPP/141", "prompt": "/*\nCreate a function which takes a string representing a file's name, and returns\n\"Yes\" if the the file's name is valid, and returns \"No\" otherwise.\nA file's name is considered to be valid if and only if all the following conditions \nare met:\n- There should not be more than three digits ('0'-'9') in the file's name.\n- The file's name contains exactly one dot \".\"\n- The substring before the dot should not be empty, and it starts with a letter from \nthe latin alphapet ('a'-'z' and 'A'-'Z').\n- The substring after the dot should be one of these: {'txt\", \"exe\", \"dll\"}\nExamples:\nfile_name_check(\"example.txt\") => \"Yes\"\nfile_name_check(\"1example.dll\") => \"No\" // (the name should start with a latin alphapet letter)\n*/\n#include\n#include\nusing namespace std;\nstring file_name_check(string file_name){\n", "canonical_solution": " int numdigit=0,numdot=0;\n if (file_name.length()<5) return \"No\";\n char w=file_name[0];\n if (w<65 or (w>90 and w<97) or w>122) return \"No\";\n string last=file_name.substr(file_name.length()-4,4);\n if (last!=\".txt\" and last!=\".exe\" and last!=\".dll\") return \"No\";\n for (int i=0;i=48 and file_name[i]<=57) numdigit+=1;\n if (file_name[i]=='.') numdot+=1;\n }\n if (numdigit>3 or numdot!=1) return \"No\";\n return \"Yes\"; \n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (file_name_check(\"example.txt\") == \"Yes\");\n assert (file_name_check(\"1example.dll\") == \"No\");\n assert (file_name_check(\"s1sdf3.asd\") == \"No\");\n assert (file_name_check(\"K.dll\") == \"Yes\");\n assert (file_name_check(\"MY16FILE3.exe\") == \"Yes\");\n assert (file_name_check(\"His12FILE94.exe\") == \"No\");\n assert (file_name_check(\"_Y.txt\") == \"No\");\n assert (file_name_check(\"?aREYA.exe\") == \"No\");\n assert (file_name_check(\"/this_is_valid.dll\") == \"No\");\n assert (file_name_check(\"this_is_valid.wow\") == \"No\");\n assert (file_name_check(\"this_is_valid.txt\") == \"Yes\");\n assert (file_name_check(\"this_is_valid.txtexe\") == \"No\");\n assert (file_name_check(\"#this2_i4s_5valid.ten\") == \"No\");\n assert (file_name_check(\"@this1_is6_valid.exe\") == \"No\");\n assert (file_name_check(\"this_is_12valid.6exe4.txt\") == \"No\");\n assert (file_name_check(\"all.exe.txt\") == \"No\");\n assert (file_name_check(\"I563_No.exe\") == \"Yes\");\n assert (file_name_check(\"Is3youfault.txt\") == \"Yes\");\n assert (file_name_check(\"no_one#knows.dll\") == \"Yes\");\n assert (file_name_check(\"1I563_Yes3.exe\") == \"No\");\n assert (file_name_check(\"I563_Yes3.txtt\") == \"No\");\n assert (file_name_check(\"final..txt\") == \"No\");\n assert (file_name_check(\"final132\") == \"No\");\n assert (file_name_check(\"_f4indsartal132.\") == \"No\");\n assert (file_name_check(\".txt\") == \"No\");\n assert (file_name_check(\"s.\") == \"No\");\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring file_name_check(string file_name){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (file_name_check(\"example.txt\") == \"Yes\");\n assert (file_name_check(\"1example.dll\") == \"No\");\n}\n"} {"task_id": "CPP/142", "prompt": "/*\n\"\nThis function will take a vector of integers. For all entries in the vector, the function shall square the integer entry if its index is a \nmultiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \nchange the entries in the vector whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n\nExamples:\nFor lst = {1,2,3} the output should be 6\nFor lst = {} the output should be 0\nFor lst = {-1,-5,2,-1,-5} the output should be -126\n*/\n#include\n#include\nusing namespace std;\nint sum_squares(vector lst){\n", "canonical_solution": " int sum=0;\n for (int i=0;i\nint main(){\n assert (sum_squares({1,2,3}) == 6);\n assert (sum_squares({1,4,9}) == 14);\n assert (sum_squares({}) == 0);\n assert (sum_squares({1,1,1,1,1,1,1,1,1}) == 9);\n assert (sum_squares({-1,-1,-1,-1,-1,-1,-1,-1,-1}) == -3);\n assert (sum_squares({0}) == 0);\n assert (sum_squares({-1,-5,2,-1,-5}) == -126);\n assert (sum_squares({-56,-99,1,0,-2}) == 3030);\n assert (sum_squares({-1,0,0,0,0,0,0,0,-1}) == 0);\n assert (sum_squares({-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37}) == -14196);\n assert (sum_squares({-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10}) == -1448);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nint sum_squares(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (sum_squares({1,2,3}) == 6);\n assert (sum_squares({}) == 0);\n assert (sum_squares({-1,-5,2,-1,-5}) == -126);\n}\n"} {"task_id": "CPP/143", "prompt": "/*\nYou are given a string representing a sentence,\nthe sentence contains some words separated by a space,\nand you have to return a string that contains the words from the original sentence,\nwhose lengths are prime numbers,\nthe order of the words in the new string should be the same as the original one.\n\nExample 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\nExample 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\nConstraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n*/\n#include\n#include\nusing namespace std;\nstring words_in_sentence(string sentence){\n", "canonical_solution": " string out=\"\";\n string current=\"\";\n sentence=sentence+' ';\n\n for (int i=0;i0)\n out.pop_back();\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (words_in_sentence(\"This is a test\") == \"is\");\n assert (words_in_sentence(\"lets go for swimming\") == \"go for\");\n assert (words_in_sentence(\"there is no place available here\") == \"there is no place\");\n assert (words_in_sentence(\"Hi I am Hussein\") == \"Hi am Hussein\");\n assert (words_in_sentence(\"go for it\") == \"go for it\");\n assert (words_in_sentence(\"here\") == \"\");\n assert (words_in_sentence(\"here is\") == \"is\");\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\n#include\nstring words_in_sentence(string sentence){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (words_in_sentence(\"This is a test\") == \"is\");\n assert (words_in_sentence(\"lets go for swimming\") == \"go for\");\n}\n"} {"task_id": "CPP/144", "prompt": "/*\nYour task is to implement a function that will simplify the expression\nx * n. The function returns true if x * n evaluates to a whole number and false\notherwise. Both x and n, are string representation of a fraction, and have the following format,\n/ where both numerator and denominator are positive whole numbers.\n\nYou can assume that x, and n are valid fractions, and do not have zero as denominator.\n\nsimplify(\"1/5\", \"5/1\") = true\nsimplify(\"1/6\", \"2/1\") = false\nsimplify(\"7/10\", \"10/2\") = false\n*/\n#include\n#include\nusing namespace std;\nbool simplify(string x,string n){\n", "canonical_solution": " int a,b,c,d,i;\n for (i=0;i\nint main(){\n assert (simplify(\"1/5\", \"5/1\") == true);\n assert (simplify(\"1/6\", \"2/1\") == false);\n assert (simplify(\"5/1\", \"3/1\") == true);\n assert (simplify(\"7/10\", \"10/2\") == false);\n assert (simplify(\"2/10\", \"50/10\") == true);\n assert (simplify(\"7/2\", \"4/2\") == true);\n assert (simplify(\"11/6\", \"6/1\") == true);\n assert (simplify(\"2/3\", \"5/2\") == false);\n assert (simplify(\"5/2\", \"3/5\") == false);\n assert (simplify(\"2/4\", \"8/4\") == true);\n assert (simplify(\"2/4\", \"4/2\") == true);\n assert (simplify(\"1/5\", \"5/1\") == true);\n assert (simplify(\"1/5\", \"1/5\") == false);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\nbool simplify(string x,string n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (simplify(\"1/5\", \"5/1\") == true);\n assert (simplify(\"1/6\", \"2/1\") == false);\n assert (simplify(\"7/10\", \"10/2\") == false);\n}\n"} {"task_id": "CPP/145", "prompt": "/*\nWrite a function which sorts the given vector of integers\nin ascending order according to the sum of their digits.\nNote: if there are several items with similar sum of their digits,\norder them based on their index in original vector.\n\nFor example:\n>>> order_by_points({1, 11, -1, -11, -12}) == {-1, -11, 1, -12, 11}\n>>> order_by_points({}) == {}\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nvector order_by_points(vector nums){\n", "canonical_solution": " vector sumdigit={};\n for (int i=0;i0) sum+=w[0]-48;\n else sum-=w[0]-48;\n sumdigit.push_back(sum);\n }\n int m;\n for (int i=0;isumdigit[j])\n {\n m=sumdigit[j];sumdigit[j]=sumdigit[j-1];sumdigit[j-1]=m;\n m=nums[j];nums[j]=nums[j-1];nums[j-1]=m;\n }\n \n return nums;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nvector order_by_points(vector nums){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i 1 \nspecialFilter({33, -2, -3, 45, 21, 109}) => 2\n*/\n#include\n#include\n#include\nusing namespace std;\nint specialFilter(vector nums){\n", "canonical_solution": " int num=0;\n for (int i=0;i10)\n {\n string w=to_string(nums[i]);\n if (w[0]%2==1 and w[w.length()-1]%2==1) num+=1;\n }\n return num;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (specialFilter({5, -2, 1, -5}) == 0 );\n assert (specialFilter({15, -73, 14, -15}) == 1);\n assert (specialFilter({33, -2, -3, 45, 21, 109}) == 2);\n assert (specialFilter({43, -12, 93, 125, 121, 109}) == 4);\n assert (specialFilter({71, -2, -33, 75, 21, 19}) == 3);\n assert (specialFilter({1}) == 0 );\n assert (specialFilter({}) == 0 );\n}\n", "declaration": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nint specialFilter(vector nums){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (specialFilter({15, -73, 14, -15}) == 1);\n assert (specialFilter({33, -2, -3, 45, 21, 109}) == 2);\n}\n"} {"task_id": "CPP/147", "prompt": "/*\nYou are given a positive integer n. You have to create an integer vector a of length n.\n For each i (1 \u2264 i \u2264 n), the value of a{i} = i * i - i + 1.\n Return the number of triples (a{i}, a{j}, a{k}) of a where i < j < k, \nand a[i] + a[j] + a[k] is a multiple of 3.\n\nExample :\n Input: n = 5\n Output: 1\n Explanation: \n a = {1, 3, 7, 13, 21}\n The only valid triple is (1, 7, 13).\n*/\n#include\n#include\nusing namespace std;\nint get_matrix_triples(int n){\n", "canonical_solution": " vector a;\n vector> sum={{0,0,0}};\n vector> sum2={{0,0,0}};\n for (int i=1;i<=n;i++)\n {\n a.push_back((i*i-i+1)%3);\n sum.push_back(sum[sum.size()-1]);\n sum[i][a[i-1]]+=1;\n }\n for (int times=1;times<3;times++)\n {\n for (int i=1;i<=n;i++)\n {\n sum2.push_back(sum2[sum2.size()-1]);\n if (i>=1)\n for (int j=0;j<=2;j++)\n sum2[i][(a[i-1]+j)%3]+=sum[i-1][j];\n }\n sum=sum2;\n sum2={{0,0,0}};\n }\n\n return sum[n][0];\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (get_matrix_triples(5) == 1);\n assert (get_matrix_triples(6) == 4);\n assert (get_matrix_triples(10) == 36);\n assert (get_matrix_triples(100) == 53361);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\n#include\nint get_matrix_triples(int n){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (get_matrix_triples(5) == 1);\n}\n"} {"task_id": "CPP/148", "prompt": "/*\nThere are eight planets in our solar system: the closerst to the Sun \nis Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, \nUranus, Neptune.\nWrite a function that takes two planet names as strings planet1 and planet2. \nThe function should return a vector containing all planets whose orbits are \nlocated between the orbit of planet1 and the orbit of planet2, sorted by \nthe proximity to the sun. \nThe function should return an empty vector if planet1 or planet2\nare not correct planet names. \nExamples\nbf(\"Jupiter\", \"Neptune\") ==> {\"Saturn\", \"Uranus\"}\nbf(\"Earth\", \"Mercury\") ==> {\"Venus\"}\nbf(\"Mercury\", \"Uranus\") ==> {\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\"}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector bf(string planet1,string planet2){\n", "canonical_solution": " vector planets={\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupiter\",\"Saturn\",\"Uranus\",\"Neptune\"};\n int pos1=-1,pos2=-1,m;\n for (m=0;mpos2) {m=pos1;pos1=pos2;pos2=m;}\n vector out={};\n for (m=pos1+1;m\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nvector bf(string planet1,string planet2){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i {\"aa\"}\nassert vector_sort({\"ab\", \"a\", \"aaa\", \"cd\"}) => {\"ab\", \"cd\"}\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nvector sorted_list_sum(vector lst){\n", "canonical_solution": " vector out={};\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector sorted_list_sum(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\nusing namespace std;\nint x_or_y(int n,int x,int y){\n", "canonical_solution": " bool isp=true;\n if (n<2) isp=false;\n for (int i=2;i*i<=n;i++)\n if (n%i==0) isp=false;\n if (isp) return x;\n return y;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (x_or_y(7, 34, 12) == 34);\n assert (x_or_y(15, 8, 5) == 5);\n assert (x_or_y(3, 33, 5212) == 33);\n assert (x_or_y(1259, 3, 52) == 3);\n assert (x_or_y(7919, -1, 12) == -1);\n assert (x_or_y(3609, 1245, 583) == 583);\n assert (x_or_y(91, 56, 129) == 129);\n assert (x_or_y(6, 34, 1234) == 1234);\n assert (x_or_y(1, 2, 0) == 0);\n assert (x_or_y(2, 2, 0) == 2);\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\nint x_or_y(int n,int x,int y){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (x_or_y(7, 34, 12) == 34);\n assert (x_or_y(15, 8, 5) == 5);\n}\n"} {"task_id": "CPP/151", "prompt": "/*\nGiven a vector of numbers, return the sum of squares of the numbers\nin the vector that are odd. Ignore numbers that are negative or not integers.\n\ndouble_the_difference({1, 3, 2, 0}) == 1 + 9 + 0 + 0 = 10\ndouble_the_difference({-1, -2, 0}) == 0\ndouble_the_difference({9, -2}) == 81\ndouble_the_difference({0}) == 0 \n\nIf the input vector is empty, return 0.\n*/\n#include\n#include\n#include\nusing namespace std;\nlong long double_the_difference(vector lst){\n", "canonical_solution": " long long sum=0;\n for (int i=0;i0 and (int)(round(lst[i]))%2==1) sum+=(int)(round(lst[i]))*(int)(round(lst[i]));\n return sum;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (double_the_difference({}) == 0);\n assert (double_the_difference({5, 4}) == 25);\n assert (double_the_difference({0.1, 0.2, 0.3}) == 0 );\n assert (double_the_difference({-10, -20, -30}) == 0 );\n assert (double_the_difference({-1, -2, 8}) == 0);\n assert (double_the_difference({0.2, 3, 5}) == 34);\n \n \n long long odd_sum=0;\n vector lst={};\n\n for (int i=-99;i<100;i+=2)\n {\n lst.push_back(i+0.0);\n if (i>0 and i%2==1) odd_sum+=i*i;\n }\n \n assert (double_the_difference(lst) == odd_sum );\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\nlong long double_the_difference(vector lst){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (double_the_difference({1, 3, 2, 0}) == 10);\n assert (double_the_difference({-1, -2, 0}) == 0);\n assert (double_the_difference({9, -2}) == 81 );\n assert (double_the_difference({0}) == 0 );\n}\n"} {"task_id": "CPP/152", "prompt": "/*\nI think we all remember that feeling when the result of some long-awaited\nevent is finally known. The feelings and thoughts you have at that moment are\ndefinitely worth noting down and comparing.\nYour task is to determine if a person correctly guessed the results of a number of matches.\nYou are given two vectors of scores and guesses of equal length, where each index shows a match. \nReturn a vector of the same length denoting how far off each guess was. If they have guessed correctly,\nthe value is 0, and if not, the value is the absolute difference between the guess and the score.\n\n\nexample:\n\ncompare({1,2,3,4,5,1},{1,2,3,4,2,-2}) -> {0,0,0,0,3,3}\ncompare({0,5,0,0,0,4},{4,1,1,0,0,-2}) -> {4,4,1,0,0,6}\n*/\n#include\n#include\n#include\nusing namespace std;\nvector compare(vector game,vector guess){\n", "canonical_solution": " vector out;\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\n#include\n#include\nvector compare(vector game,vector guess){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\nusing namespace std;\nstring Strongest_Extension(string class_name,vector extensions){\n", "canonical_solution": " string strongest=\"\";\n int max=-1000;\n for (int i=0;i=65 and chr<=90) strength+=1;\n if (chr>=97 and chr<=122) strength-=1;\n }\n if (strength>max) \n {\n max=strength;\n strongest=extensions[i];\n }\n }\n return class_name+'.'+strongest;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (Strongest_Extension(\"Watashi\", {\"tEN\", \"niNE\", \"eIGHt8OKe\"}) == \"Watashi.eIGHt8OKe\");\n assert (Strongest_Extension(\"Boku123\", {\"nani\", \"NazeDa\", \"YEs.WeCaNe\", \"32145tggg\"}) == \"Boku123.YEs.WeCaNe\");\n assert (Strongest_Extension(\"__YESIMHERE\", {\"t\", \"eMptY\", \"(nothing\", \"zeR00\", \"NuLl__\", \"123NoooneB321\"}) == \"__YESIMHERE.NuLl__\");\n assert (Strongest_Extension(\"K\", {\"Ta\", \"TAR\", \"t234An\", \"cosSo\"}) == \"K.TAR\");\n assert (Strongest_Extension(\"__HAHA\", {\"Tab\", \"123\", \"781345\", \"-_-\"}) == \"__HAHA.123\");\n assert (Strongest_Extension(\"YameRore\", {\"HhAas\", \"okIWILL123\", \"WorkOut\", \"Fails\", \"-_-\"}) == \"YameRore.okIWILL123\");\n assert (Strongest_Extension(\"finNNalLLly\", {\"Die\", \"NowW\", \"Wow\", \"WoW\"}) == \"finNNalLLly.WoW\");\n assert (Strongest_Extension(\"_\", {\"Bb\", \"91245\"}) == \"_.Bb\");\n assert (Strongest_Extension(\"Sp\", {\"671235\", \"Bb\"}) == \"Sp.671235\");\n}\n", "declaration": "#include\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\nstring Strongest_Extension(string class_name,vector extensions){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (Strongest_Extension(\"my_class\", {\"AA\", \"Be\", \"CC\"}) == \"my_class.AA\");\n}\n"} {"task_id": "CPP/154", "prompt": "/*\nYou are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\ncycpattern_check(\"abcd\",\"abd\") => false\ncycpattern_check(\"hello\",\"ell\") => true\ncycpattern_check(\"whassup\",\"psus\") => false\ncycpattern_check(\"abab\",\"baa\") => true\ncycpattern_check(\"efef\",\"eeff\") => false\ncycpattern_check(\"himenss\",'simen\") => true\n\n*/\n#include\n#include\nusing namespace std;\nbool cycpattern_check(string a,string b){\n", "canonical_solution": " for (int i=0;i\nint main(){\n assert (cycpattern_check(\"xyzw\",\"xyw\") == false );\n assert (cycpattern_check(\"yello\",\"ell\") == true );\n assert (cycpattern_check(\"whattup\",\"ptut\") == false );\n assert (cycpattern_check(\"efef\",\"fee\") == true );\n assert (cycpattern_check(\"abab\",\"aabb\") == false );\n assert (cycpattern_check(\"winemtt\",\"tinem\") == true );\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\n#include\nbool cycpattern_check(string a,string b){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (cycpattern_check(\"abcd\",\"abd\") == false );\n assert (cycpattern_check(\"hello\",\"ell\") == true );\n assert (cycpattern_check(\"whassup\",\"psus\") == false );\n assert (cycpattern_check(\"abab\",\"baa\") == true );\n assert (cycpattern_check(\"efef\",\"eeff\") == false );\n assert (cycpattern_check(\"himenss\",\"simen\") == true );\n}\n"} {"task_id": "CPP/155", "prompt": "/*\nGiven an integer. return a vector that has the number of even and odd digits respectively.\n\n Example:\n even_odd_count(-12) ==> {1, 1}\n even_odd_count(123) ==> {1, 2}\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nvector even_odd_count(int num){\n", "canonical_solution": " string w=to_string(abs(num));\n int n1=0,n2=0;\n for (int i=0;i\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nvector even_odd_count(int num){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i>> int_to_mini_roman(19) == \"xix\"\n>>> int_to_mini_roman(152) == \"clii\"\n>>> int_to_mini_roman(426) == \"cdxxvi\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring int_to_mini_romank(int number){\n", "canonical_solution": " string current=\"\";\n vector rep={\"m\",\"cm\",\"d\",\"cd\",\"c\",\"xc\",\"l\",\"xl\",\"x\",\"ix\",\"v\",\"iv\",\"i\"};\n vector num={1000,900,500,400,100,90,50,40,10,9,5,4,1};\n int pos=0;\n while(number>0)\n {\n while (number>=num[pos])\n {\n current=current+rep[pos];\n number-=num[pos];\n }\n if (number>0) pos+=1;\n }\n return current;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (int_to_mini_romank(19) == \"xix\");\n assert (int_to_mini_romank(152) == \"clii\");\n assert (int_to_mini_romank(251) == \"ccli\");\n assert (int_to_mini_romank(426) == \"cdxxvi\");\n assert (int_to_mini_romank(500) == \"d\");\n assert (int_to_mini_romank(1) == \"i\");\n assert (int_to_mini_romank(4) == \"iv\");\n assert (int_to_mini_romank(43) == \"xliii\");\n assert (int_to_mini_romank(90) == \"xc\");\n assert (int_to_mini_romank(94) == \"xciv\");\n assert (int_to_mini_romank(532) == \"dxxxii\");\n assert (int_to_mini_romank(900) == \"cm\");\n assert (int_to_mini_romank(994) == \"cmxciv\");\n assert (int_to_mini_romank(1000) == \"m\");\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\n#include\nstring int_to_mini_romank(int number){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (int_to_mini_romank(19) == \"xix\");\n assert (int_to_mini_romank(152) == \"clii\");\n assert (int_to_mini_romank(426) == \"cdxxvi\");\n}\n"} {"task_id": "CPP/157", "prompt": "/*\nGiven the lengths of the three sides of a triangle. Return true if the three\nsides form a right-angled triangle, false otherwise.\nA right-angled triangle is a triangle in which one angle is right angle or \n90 degree.\nExample:\nright_angle_triangle(3, 4, 5) == true\nright_angle_triangle(1, 2, 3) == false\n*/\n#include\n#include\nusing namespace std;\nbool right_angle_triangle(float a,float b,float c){\n", "canonical_solution": " if (abs(a*a+b*b-c*c)<1e-4 or abs(a*a+c*c-b*b)<1e-4 or abs(b*b+c*c-a*a)<1e-4) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (right_angle_triangle(3, 4, 5) == true);\n assert (right_angle_triangle(1, 2, 3) == false);\n assert (right_angle_triangle(10, 6, 8) == true);\n assert (right_angle_triangle(2, 2, 2) == false);\n assert (right_angle_triangle(7, 24, 25) == true);\n assert (right_angle_triangle(10, 5, 7) == false);\n assert (right_angle_triangle(5, 12, 13) == true);\n assert (right_angle_triangle(15, 8, 17) == true);\n assert (right_angle_triangle(48, 55, 73) == true);\n assert (right_angle_triangle(1, 1, 1) == false);\n assert (right_angle_triangle(2, 2, 10) == false);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nbool right_angle_triangle(float a,float b,float c){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (right_angle_triangle(3, 4, 5) == true);\n assert (right_angle_triangle(1, 2, 3) == false);\n}\n"} {"task_id": "CPP/158", "prompt": "/*\nWrite a function that accepts a vector of strings.\nThe vector contains different words. Return the word with maximum number\nof unique characters. If multiple strings have maximum number of unique\ncharacters, return the one which comes first in lexicographical order.\n\nfind_max({\"name\", \"of\", 'string\"}) == 'string\"\nfind_max({\"name\", \"enam\", \"game\"}) == \"enam\"\nfind_max({\"aaaaaaa\", \"bb\" ,\"cc\"}) == \"aaaaaaa\"\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\nstring find_max(vector words){\n", "canonical_solution": " string max=\"\";\n int maxu=0;\n for (int i=0;imaxu or (unique.length()==maxu and words[i]\nint main(){\n assert ((find_max({\"name\", \"of\", \"string\"}) == \"string\"));\n assert ((find_max({\"name\", \"enam\", \"game\"}) == \"enam\"));\n assert ((find_max({\"aaaaaaa\", \"bb\", \"cc\"}) == \"aaaaaaa\"));\n assert ((find_max({\"abc\", \"cba\"}) == \"abc\"));\n assert ((find_max({\"play\", \"this\", \"game\", \"of\",\"footbott\"}) == \"footbott\"));\n assert ((find_max({\"we\", \"are\", \"gonna\", \"rock\"}) == \"gonna\"));\n assert ((find_max({\"we\", \"are\", \"a\", \"mad\", \"nation\"}) == \"nation\"));\n assert ((find_max({\"this\", \"is\", \"a\", \"prrk\"}) == \"this\"));\n assert ((find_max({\"b\"}) == \"b\"));\n assert ((find_max({\"play\", \"play\", \"play\"}) == \"play\"));\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nstring find_max(vector words){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert ((find_max({\"name\", \"of\", \"string\"}) == \"string\"));\n assert ((find_max({\"name\", \"enam\", \"game\"}) == \"enam\"));\n assert ((find_max({\"aaaaaaa\", \"bb\", \"cc\"}) == \"aaaaaaa\"));\n}\n"} {"task_id": "CPP/159", "prompt": "/*\nYou\"re a hungry rabbit, and you already have eaten a certain number of carrots,\nbut now you need to eat more carrots to complete the day's meals.\nyou should return a vector of { total number of eaten carrots after your meals,\n the number of carrots left after your meals }\nif there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\n\nExample:\n* eat(5, 6, 10) -> {11, 4}\n* eat(4, 8, 9) -> {12, 1}\n* eat(1, 10, 10) -> {11, 0}\n* eat(2, 11, 5) -> {7, 0}\n\nVariables:\n@number : integer\n the number of carrots that you have eaten.\n@need : integer\n the number of carrots that you need to eat.\n@remaining : integer\n the number of remaining carrots thet exist in stock\n\nConstrain:\n* 0 <= number <= 1000\n* 0 <= need <= 1000\n* 0 <= remaining <= 1000\n\nHave fun :)\n*/\n#include\n#include\nusing namespace std;\nvector eat(int number,int need,int remaining){\n", "canonical_solution": " if (need>remaining) return {number+remaining, 0};\n return {number+need,remaining-need};\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\n#include\n#include\n#include\nvector eat(int number,int need,int remaining){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i result = 9\n\nNote:\n The length of operator vector is equal to the length of operand vector minus one.\n Operand is a vector of of non-negative integers.\n Operator vector has at least one operator, and operand vector has at least two operands.\n\n*/\n#include\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint do_algebra(vector operato, vector operand){\n", "canonical_solution": " vector num={};\n vector posto={};\n for (int i=0;i\nint main(){\n assert (do_algebra({\"**\", \"*\", \"+\"}, {2, 3, 4, 5}) == 37);\n assert (do_algebra({\"+\", \"*\", \"-\"}, {2, 3, 4, 5}) == 9);\n assert (do_algebra({\"//\", \"*\"}, {7, 3, 4}) == 8);\n}\n", "declaration": "#include\n#include\n#include\n#include\nusing namespace std;\n#include\n#include\nint do_algebra(vector operato, vector operand){\n", "example_test": ""} {"task_id": "CPP/161", "prompt": "/*\nYou are given a string s.\nif s[i] is a letter, reverse its case from lower to upper or vise versa, \notherwise keep it as it is.\nIf the string contains no letters, reverse the string.\nThe function should return the resulted string.\nExamples\nsolve(\"1234\") = \"4321\"\nsolve(\"ab\") = \"AB\"\nsolve(\"#a@C\") = \"#A@c\"\n*/\n#include\n#include\nusing namespace std;\nstring solve(string s){\n", "canonical_solution": " int nletter=0;\n string out=\"\";\n for (int i=0;i=65 and w<=90) w=w+32;\n else if (w>=97 and w<=122) w=w-32;\n else nletter+=1;\n out=out+w;\n }\n if (nletter==s.length())\n {\n string p(s.rbegin(),s.rend());\n return p;\n }\n else return out;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (solve(\"AsDf\") == \"aSdF\");\n assert (solve(\"1234\") == \"4321\");\n assert (solve(\"ab\") == \"AB\");\n assert (solve(\"#a@C\") == \"#A@c\");\n assert (solve(\"#AsdfW^45\") == \"#aSDFw^45\");\n assert (solve(\"#6@2\") == \"2@6#\");\n assert (solve(\"#$a^D\") == \"#$A^d\");\n assert (solve(\"#ccc\") == \"#CCC\");\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\n#include\nstring solve(string s){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (solve(\"1234\") == \"4321\");\n assert (solve(\"ab\") == \"AB\");\n assert (solve(\"#a@C\") == \"#A@c\");\n}\n"} {"task_id": "CPP/162", "prompt": "/*\nGiven a string 'text\", return its md5 hash equivalent string.\nIf 'text\" is an empty string, return None.\n\n>>> string_to_md5(\"Hello world\") == \"3e25960a79dbc69b674cd4ec67a72c62\"\n*/\n#include\n#include\n#include\nusing namespace std;\nstring string_to_md5(string text){\n", "canonical_solution": " unsigned char md[16];\n if (text.length()==0) return \"None\";\n MD5_CTX c;\n int i;\n MD5_Init(&c);\n MD5_Update(&c, (unsigned char*)text.c_str(), text.length());\n MD5_Final(md, &c);\n string out_str=\"\";\n for (int i=0;i<16;i++)\n {\n char w;\n if (md[i]<160) w=48+md[i]/16;\n else w=87+md[i]/16;\n out_str=out_str+w;\n if (md[i]%16<10) w=48+md[i]%16;\n else w=87+md[i]%16;\n out_str=out_str+w;\n }\n return out_str;\n}\n", "test": "#undef NDEBUG\n#include\nint main(){\n assert (string_to_md5(\"Hello world\") == \"3e25960a79dbc69b674cd4ec67a72c62\");\n assert (string_to_md5(\"\") == \"None\");\n assert (string_to_md5(\"A B C\") == \"0ef78513b0cb8cef12743f5aeb35f888\");\n assert (string_to_md5(\"password\") == \"5f4dcc3b5aa765d61d8327deb882cf99\");\n}\n", "declaration": "#include\n#include\n#include\nusing namespace std;\n#include\n#include\n#include\nstring string_to_md5(string text){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (string_to_md5(\"Hello world\") == \"3e25960a79dbc69b674cd4ec67a72c62\");\n}\n"} {"task_id": "CPP/163", "prompt": "/*\nGiven two positive integers a and b, return the even digits between a\nand b, in ascending order.\n\nFor example:\ngenerate_integers(2, 8) => {2, 4, 6, 8}\ngenerate_integers(8, 2) => {2, 4, 6, 8}\ngenerate_integers(10, 14) => {}\n*/\n#include\n#include\nusing namespace std;\nvector generate_integers(int a,int b){\n", "canonical_solution": " int m;\n if (b out={};\n for (int i=a;i<=b;i++)\n if (i<10 and i%2==0) out.push_back(i);\n return out;\n}\n", "test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i\n#include\nusing namespace std;\n#include\n#include\n#include\nvector generate_integers(int a,int b){\n", "example_test": "#undef NDEBUG\n#include\nbool issame(vector a,vectorb){\n if (a.size()!=b.size()) return false;\n for (int i=0;i