diff --git "a/data/cpp/data/humanevalpack.jsonl" "b/data/cpp/data/humanevalpack.jsonl" new file mode 100644--- /dev/null +++ "b/data/cpp/data/humanevalpack.jsonl" @@ -0,0 +1,164 @@ +{"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", "buggy_solution": " int i,j;\n \n for (i=0;i numbers, float threshold)", "docstring": "Check 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", "instruction": "Write a C++ function `bool has_close_elements(vector numbers, float threshold)` to solve the following problem:\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"} +{"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 all_parens;\n string current_paren;\n int level=0;\n char chr;\n int i;\n for (i=0;i separate_paren_groups(string paren_string)", "docstring": "Input 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{\"()\", \"(())\", \"(()())\"}", "instruction": "Write a C++ function `vector separate_paren_groups(string paren_string)` to solve the following problem:\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{\"()\", \"(())\", \"(()())\"}"} +{"task_id": "CPP/2", "prompt": "/*\nGiven a positive floating point number, it can be decomposed into\nand integer part (largest integer smaller than given number) and decimals\n(leftover part always smaller than 1).\n\nReturn the decimal part of the number.\n>>> 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", "buggy_solution": " return number-int(number)+1;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "truncate_number", "signature": "float truncate_number(float number)", "docstring": "Given a positive floating point number, it can be decomposed into\nand integer part (largest integer smaller than given number) and decimals\n(leftover part always smaller than 1).\nReturn the decimal part of the number.\n>>> truncate_number(3.5)\n0.5", "instruction": "Write a C++ function `float truncate_number(float number)` to solve the following problem:\nGiven a positive floating point number, it can be decomposed into\nand integer part (largest integer smaller than given number) and decimals\n(leftover part always smaller than 1).\nReturn the decimal part of the number.\n>>> truncate_number(3.5)\n0.5"} +{"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", "buggy_solution": " int num=0;\n for (int i=0;i operations)", "docstring": "You\"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", "instruction": "Write a C++ function `bool below_zero(vector operations)` to solve the following problem:\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"} +{"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", "buggy_solution": " float sum=0;\n float avg,msum,mavg;\n int i=0;\n for (i=0;i numbers)", "docstring": "For 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", "instruction": "Write a C++ function `float mean_absolute_deviation(vector numbers)` to solve the following problem:\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"} +{"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 out={};\n for (int i=1;i intersperse(vector numbers, int delimeter)", "docstring": "Insert 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}", "instruction": "Write a C++ function `vector intersperse(vector numbers, int delimeter)` to solve the following problem:\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}"} +{"task_id": "CPP/6", "prompt": "/*\nInput to this function is a string represented multiple groups for nested parentheses separated by spaces.\nFor each of the group, output the deepest level of nesting of parentheses.\nE.g. (()()) has maximum two levels of nesting while ((())) has three.\n\n>>> 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 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 max_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", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "parse_nested_parens", "signature": "vector parse_nested_parens(string paren_string)", "docstring": "Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\nFor each of the group, output the deepest level of nesting of parentheses.\nE.g. (()()) has maximum two levels of nesting while ((())) has three.\n>>> parse_nested_parens(\"(()()) ((())) () ((())()())\")\n{2, 3, 1, 3}", "instruction": "Write a C++ function `vector parse_nested_parens(string paren_string)` to solve the following problem:\nInput to this function is a string represented multiple groups for nested parentheses separated by spaces.\nFor each of the group, output the deepest level of nesting of parentheses.\nE.g. (()()) has maximum two levels of nesting while ((())) has three.\n>>> parse_nested_parens(\"(()()) ((())) () ((())()())\")\n{2, 3, 1, 3}"} +{"task_id": "CPP/7", "prompt": "/*\nFilter an input vector of strings only for ones that contain given substring\n>>> 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 out;\n for (int i=0;i filter_by_substring(vector strings, string substring)", "docstring": "Filter an input vector of strings only for ones that contain given substring\n>>> filter_by_substring({}, \"a\")\n{}\n>>> filter_by_substring({\"abc\", \"bacd\", \"cde\", \"vector\"}, \"a\")\n{\"abc\", \"bacd\", \"vector\"}", "instruction": "Write a C++ function `vector filter_by_substring(vector strings, string substring)` to solve the following problem:\nFilter an input vector of strings only for ones that contain given substring\n>>> filter_by_substring({}, \"a\")\n{}\n>>> filter_by_substring({\"abc\", \"bacd\", \"cde\", \"vector\"}, \"a\")\n{\"abc\", \"bacd\", \"vector\"}"} +{"task_id": "CPP/8", "prompt": "/*\nFor a given vector of integers, return a vector consisting of a sum and a product of all the integers in a vector.\nEmpty sum should be equal to 0 and empty product should be equal to 1.\n>>> 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 sum_product(vector numbers)", "docstring": "For a given vector of integers, return a vector consisting of a sum and a product of all the integers in a vector.\nEmpty sum should be equal to 0 and empty product should be equal to 1.\n>>> sum_product({})\n(0, 1)\n>>> sum_product({1, 2, 3, 4})\n(10, 24)", "instruction": "Write a C++ function `vector sum_product(vector numbers)` to solve the following problem:\nFor a given vector of integers, return a vector consisting of a sum and a product of all the integers in a vector.\nEmpty sum should be equal to 0 and empty product should be equal to 1.\n>>> sum_product({})\n(0, 1)\n>>> sum_product({1, 2, 3, 4})\n(10, 24)"} +{"task_id": "CPP/9", "prompt": "/*\nFrom a given vector of integers, generate a vector of rolling maximum element found until given moment\nin the sequence.\n>>> 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 out;\n int max=0;\n for (int i=0;imax) max=numbers[i];\n out.push_back(numbers[i]);\n }\n return out;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "rolling_max", "signature": "vector rolling_max(vector numbers)", "docstring": "From a given vector of integers, generate a vector of rolling maximum element found until given moment\nin the sequence.\n>>> rolling_max({1, 2, 3, 2, 3, 4, 2})\n{1, 2, 3, 3, 3, 4, 4}", "instruction": "Write a C++ function `vector rolling_max(vector numbers)` to solve the following problem:\nFrom a given vector of integers, generate a vector of rolling maximum element found until given moment\nin the sequence.\n>>> rolling_max({1, 2, 3, 2, 3, 4, 2})\n{1, 2, 3, 3, 3, 4, 4}"} +{"task_id": "CPP/10", "prompt": "#include\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", "buggy_solution": " int i;\n for (i=0;i>> make_palindrome(\"\")\n\"\"\n>>> make_palindrome(\"cat\")\n\"catac\"\n>>> make_palindrome(\"cata\")\n\"catac\"", "instruction": "Write a C++ function `string make_palindrome(string str)` to solve the following problem:\nFind the shortest palindrome that begins with a supplied string.\nAlgorithm 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\""} +{"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", "buggy_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", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "string_xor", "signature": "string string_xor(string a,string b)", "docstring": "Input 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\"", "instruction": "Write a C++ function `string string_xor(string a,string b)` to solve the following problem:\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\""} +{"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", "buggy_solution": " string out;\n for (int i=0;i strings)", "docstring": "Out 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>>> longest({\"a\", \"b\", \"c\"})\n\"a\"\n>>> longest({\"a\", \"bb\", \"ccc\"})\n\"ccc\"", "instruction": "Write a C++ function `string longest(vector strings)` to solve the following problem:\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>>> longest({\"a\", \"b\", \"c\"})\n\"a\"\n>>> longest({\"a\", \"bb\", \"ccc\"})\n\"ccc\""} +{"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", "buggy_solution": " int out,m;\n while (true){\n if (a>> greatest_common_divisor(3, 5)\n1\n>>> greatest_common_divisor(25, 15)\n5", "instruction": "Write a C++ function `int greatest_common_divisor(int a, int b)` to solve the following problem:\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"} +{"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 out;\n string current=\"\";\n for (int i=0;i all_prefixes(string str)", "docstring": "Return vector of all prefixes from shortest to longest of the input string\n>>> all_prefixes(\"abc\")\n{\"a\", \"ab\", \"abc\"}", "instruction": "Write a C++ function `vector all_prefixes(string str)` to solve the following problem:\nReturn vector of all prefixes from shortest to longest of the input string\n>>> all_prefixes(\"abc\")\n{\"a\", \"ab\", \"abc\"}"} +{"task_id": "CPP/15", "prompt": "/*\nReturn a string containing space-delimited numbers starting from 0 upto n inclusive.\n>>> 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", "buggy_solution": " string out=\"0\";\n for (int i=1;i>> string_sequence(0)\n\"0\"\n>>> string_sequence(5)\n\"0 1 2 3 4 5\"", "instruction": "Write a C++ function `string string_sequence(int n)` to solve the following problem:\nReturn a string containing space-delimited numbers starting from 0 upto n inclusive.\n>>> string_sequence(0)\n\"0\"\n>>> string_sequence(5)\n\"0 1 2 3 4 5\""} +{"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", "buggy_solution": " vector distinct={};\n for (int i=0;i>> count_distinct_characters(\"xyzXYZ\")\n3\n>>> count_distinct_characters(\"Jerry\")\n4", "instruction": "Write a C++ function `int count_distinct_characters(string str)` to solve the following problem:\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"} +{"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 out={};\n if (music_string.length()>0)\n music_string=music_string+' ';\n for (int i=0;i parse_music(string music_string)", "docstring": "Input 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.\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>>> parse_music(\"o o| .| o| o| .| .| .| .| o o\")\n{4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4}", "instruction": "Write a C++ function `vector parse_music(string music_string)` to solve the following problem:\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.\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>>> parse_music(\"o o| .| o| o| .| .| .| .| o o\")\n{4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4}"} +{"task_id": "CPP/18", "prompt": "/*\nFind how many times a given substring can be found in the original string. Count overlaping cases.\n>>> 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", "buggy_solution": " int out=0;\n if (str.length()==0) return 0;\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", "instruction": "Write a C++ function `int how_many_times(string str,string substring)` to solve the following problem:\nFind how many times a given substring can be found in the original string. Count overlaping cases.\n>>> how_many_times(\"\", \"a\")\n0\n>>> how_many_times(\"aaa\", \"a\")\n3\n>>> how_many_times(\"aaaa\", \"aa\")\n3"} +{"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", "buggy_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;i>> sort_numbers('three one five\")\n\"one three five\"", "instruction": "Write a C++ function `string sort_numbers(string numbers)` to solve the following problem:\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\""} +{"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", "buggy_solution": " vector out={};\n for (int i=0;iabs(out[0]-out[1]))\n out={numbers[i],numbers[j]};\n if (out[0]>out[1])\n out={out[1],out[0]};\n return out;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "find_closest_elements", "signature": "vector find_closest_elements(vector numbers)", "docstring": "From 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)", "instruction": "Write a C++ function `vector find_closest_elements(vector numbers)` to solve the following problem:\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)"} +{"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", "buggy_solution": " float min=100000,max=-100000;\n for (int i=0;imax) max=numbers[i];\n }\n for (int i=0;i rescale_to_unit(vector numbers)", "docstring": "Given 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}", "instruction": "Write a C++ function `vector rescale_to_unit(vector numbers)` to solve the following problem:\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}"} +{"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 out;\n for (it=values.begin();it!=values.end();it++)\n {\n anyone=*it;\n if( anyone.type() == typeid(int) )\n values.push_back(boost::any_cast(*it));\n }\n return out;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "filter_integers", "signature": "vector filter_integers(list_any values)", "docstring": "Filter 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}", "instruction": "Write a C++ function `vector filter_integers(list_any values)` to solve the following problem:\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}"} +{"task_id": "CPP/23", "prompt": "/*\nReturn length of given string\n>>> 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", "buggy_solution": " return str.length() - 1;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "strlen", "signature": "int strlen(string str)", "docstring": "Return length of given string\n>>> strlen(\"\")\n0\n>>> strlen(\"abc\")\n3", "instruction": "Write a C++ function `int strlen(string str)` to solve the following problem:\nReturn length of given string\n>>> strlen(\"\")\n0\n>>> strlen(\"abc\")\n3"} +{"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", "buggy_solution": " for (int i=2;i*i<=n;i++)\n if (n-i==0) return n/i;\n return 1;\n\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "largest_divisor", "signature": "int largest_divisor(int n)", "docstring": "For a given number n, find the largest number that divides n evenly, smaller than n\n>>> largest_divisor(15)\n5", "instruction": "Write a C++ function `int largest_divisor(int n)` to solve the following problem:\nFor a given number n, find the largest number that divides n evenly, smaller than n\n>>> largest_divisor(15)\n5"} +{"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 out={};\n for (int i=0;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", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "factorize", "signature": "vector factorize(int n)", "docstring": "Return 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}", "instruction": "Write a C++ function `vector factorize(int n)` to solve the following problem:\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}"} +{"task_id": "CPP/26", "prompt": "/*\nFrom a vector of integers, remove all elements that occur more than once.\nKeep order of elements left the same as in the input.\n>>> 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 out={};\n vector has1={};\n vector has2={};\n for (int i=0;i remove_duplicates(vector numbers)", "docstring": "From a vector of integers, remove all elements that occur more than once.\nKeep order of elements left the same as in the input.\n>>> remove_duplicates({1, 2, 3, 2, 4})\n{1, 3, 4}", "instruction": "Write a C++ function `vector remove_duplicates(vector numbers)` to solve the following problem:\nFrom a vector of integers, remove all elements that occur more than once.\nKeep order of elements left the same as in the input.\n>>> remove_duplicates({1, 2, 3, 2, 4})\n{1, 3, 4}"} +{"task_id": "CPP/27", "prompt": "/*\nFor a given string, flip lowercase characters to uppercase and uppercase to lowercase.\n>>> flip_case(\"Hello\")\n\"hELLO\"\n*/\n#include\n#include\nusing namespace std;\nstring flip_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 (flip_case(\"\") == \"\");\n assert (flip_case(\"Hello!\") == \"hELLO!\");\n assert (flip_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 flip_case(string str){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (flip_case(\"Hello\") == \"hELLO\");\n}\n", "buggy_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", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "flip_case", "signature": "string flip_case(string str)", "docstring": "For a given string, flip lowercase characters to uppercase and uppercase to lowercase.\n>>> flip_case(\"Hello\")\n\"hELLO\"", "instruction": "Write a C++ function `string flip_case(string str)` to solve the following problem:\nFor a given string, flip lowercase characters to uppercase and uppercase to lowercase.\n>>> flip_case(\"Hello\")\n\"hELLO\""} +{"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", "buggy_solution": " string out=\" \";\n for (int i=0;i strings)", "docstring": "Concatenate vector of strings into a single string\n>>> concatenate({})\n\"\"\n>>> concatenate({\"a\", \"b\", \"c\"})\n\"abc\"", "instruction": "Write a C++ function `string concatenate(vector strings)` to solve the following problem:\nConcatenate vector of strings into a single string\n>>> concatenate({})\n\"\"\n>>> concatenate({\"a\", \"b\", \"c\"})\n\"abc\""} +{"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 out={};\n for (int i=0;i filter_by_prefix(vector strings, string prefix)", "docstring": "Filter 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\"}", "instruction": "Write a C++ function `vector filter_by_prefix(vector strings, string prefix)` to solve the following problem:\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\"}"} +{"task_id": "CPP/30", "prompt": "/*\nReturn only positive numbers in the vector.\n>>> 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", "buggy_solution": " vector out={};\n for (int i=0;i get_positive(vector l)", "docstring": "Return only positive numbers in the vector.\n>>> 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}", "instruction": "Write a C++ function `vector get_positive(vector l)` to solve the following problem:\nReturn only positive numbers in the vector.\n>>> 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}"} +{"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", "buggy_solution": " if (n<1) return false;\n for (long long i=1;i*i<=n;i++)\n if (n%i==0) return false;\n return true;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_prime", "signature": "bool is_prime(long long n)", "docstring": "Return 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", "instruction": "Write a C++ function `bool is_prime(long long n)` to solve the following problem:\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"} +{"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", "buggy_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 xs)", "docstring": "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.\nMoreover, 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\n1.0", "instruction": "Write a C++ function `double find_zero(vector xs)` to solve the following problem:\nxs 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.\nMoreover, 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\n1.0"} +{"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 third={};\n int i;\n for (i=0;i*3 out={};\n for (i=0;i sort_third(vector l)", "docstring": "This 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}", "instruction": "Write a C++ function `vector sort_third(vector l)` to solve the following problem:\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}"} +{"task_id": "CPP/34", "prompt": "/*\nReturn sorted unique elements in a vector\n>>> 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 unique(vector l)", "docstring": "Return sorted unique elements in a vector\n>>> unique({5, 3, 5, 2, 3, 3, 9, 0, 123})\n{0, 2, 3, 5, 9, 123}", "instruction": "Write a C++ function `vector unique(vector l)` to solve the following problem:\nReturn sorted unique elements in a vector\n>>> unique({5, 3, 5, 2, 3, 3, 9, 0, 123})\n{0, 2, 3, 5, 9, 123}"} +{"task_id": "CPP/35", "prompt": "/*\nReturn maximum element in the vector.\n>>> 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", "buggy_solution": " float max=-10000;\n for (int i=0;il[i]) max=l[i];\n return max;\n\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "max_element", "signature": "float max_element(vector l)", "docstring": "Return maximum element in the vector.\n>>> max_element({1, 2, 3})\n3\n>>> max_element({5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10})\n123", "instruction": "Write a C++ function `float max_element(vector l)` to solve the following problem:\nReturn maximum element in the vector.\n>>> max_element({1, 2, 3})\n3\n>>> max_element({5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10})\n123"} +{"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", "buggy_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", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "fizz_buzz", "signature": "int fizz_buzz(int n)", "docstring": "Return 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", "instruction": "Write a C++ function `int fizz_buzz(int n)` to solve the following problem:\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"} +{"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", "buggy_solution": " vector out={};\n vector even={};\n for (int i=0;i*2 sort_even(vector l)", "docstring": "This 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}", "instruction": "Write a C++ function `vector sort_even(vector l)` to solve the following problem:\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}"} +{"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", "buggy_solution": " int f1,f2,m;\n f1=1;f2=2;\n int count=0;\n while (count>> prime_fib(1)\n2\n>>> prime_fib(2)\n3\n>>> prime_fib(3)\n5\n>>> prime_fib(4)\n13\n>>> prime_fib(5)\n89", "instruction": "Write a C++ function `int prime_fib(int n)` to solve the following problem:\nprime_fib returns n-th number that is a Fibonacci number and it's also prime.\n>>> prime_fib(1)\n2\n>>> prime_fib(2)\n3\n>>> prime_fib(3)\n5\n>>> prime_fib(4)\n13\n>>> prime_fib(5)\n89"} +{"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", "buggy_solution": " for (int i=1;i l)", "docstring": "triples_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>>> 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", "instruction": "Write a C++ function `bool triples_sum_to_zero(vector l)` to solve the following problem:\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>>> 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"} +{"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": "", "buggy_solution": " return n*n*n;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "car_race_collision", "signature": "int car_race_collision(int n)", "docstring": "Imagine 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.\nThis function outputs the number of such collisions.", "instruction": "Write a C++ function `int car_race_collision(int n)` to solve the following problem:\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.\nThis function outputs the number of such collisions."} +{"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 incr_list(vector l)", "docstring": "Return 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}", "instruction": "Write a C++ function `vector incr_list(vector l)` to solve the following problem:\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}"} +{"task_id": "CPP/43", "prompt": "/*\npairs_sum_to_zero takes a vector of integers as an input.\nit returns true if there are two distinct elements in the vector that\nsum to zero, and false otherwise.\n>>> 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", "buggy_solution": " for (int i=0;i l)", "docstring": "pairs_sum_to_zero takes a vector of integers as an input.\nit returns true if there are two distinct elements in the vector that\nsum to zero, and false otherwise.\n>>> 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", "instruction": "Write a C++ function `bool pairs_sum_to_zero(vector l)` to solve the following problem:\npairs_sum_to_zero takes a vector of integers as an input.\nit returns true if there are two distinct elements in the vector that\nsum to zero, and false otherwise.\n>>> 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"} +{"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", "buggy_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", "bug_type": "operator misuse", "failure_symptoms": "infinite loop", "entry_point": "change_base", "signature": "string change_base(int x,int base)", "docstring": "Change 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\"", "instruction": "Write a C++ function `string change_base(int x,int base)` to solve the following problem:\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\""} +{"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", "buggy_solution": "return (a*h)*2;\n\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "triangle_area", "signature": "float triangle_area(float a,float h)", "docstring": "Given length of a side and high return area for a triangle.\n>>> triangle_area(5, 3)\n7.5", "instruction": "Write a C++ function `float triangle_area(float a,float h)` to solve the following problem:\nGiven length of a side and high return area for a triangle.\n>>> triangle_area(5, 3)\n7.5"} +{"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", "buggy_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-2];\n }\n return f[n];\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fib4", "signature": "int fib4(int n)", "docstring": "The 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", "instruction": "Write a C++ function `int fib4(int n)` to solve the following problem:\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"} +{"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", "buggy_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()-1/2]);\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "median", "signature": "float median(vector l)", "docstring": "Return 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", "instruction": "Write a C++ function `float median(vector l)` to solve the following problem:\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"} +{"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", "buggy_solution": " string pr(text.rend(),text.rbegin());\n return pr==text;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_palindrome", "signature": "bool is_palindrome(string text)", "docstring": "Checks 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", "instruction": "Write a C++ function `bool is_palindrome(string text)` to solve the following problem:\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"} +{"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", "buggy_solution": " int out=0;\n for (int i=0;i>> modp(3, 5)\n3\n>>> modp(1101, 101)\n2\n>>> modp(0, 101)\n1\n>>> modp(3, 11)\n8\n>>> modp(100, 101)\n1", "instruction": "Write a C++ function `int modp(int n,int p)` to solve the following problem:\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"} +{"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", "buggy_solution": " string out=\"\";\n string vowels=\"AEIOUWYaeiouwy\";\n for (int 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\"", "instruction": "Write a C++ function `string remove_vowels(string text)` to solve the following problem:\nremove_vowels is a function that takes string and returns string without vowels.\n>>> 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\""} +{"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", "buggy_solution": " for (int i=0;i=t) return true;\n return false;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "below_threshold", "signature": "bool below_threshold(vectorl, int t)", "docstring": "Return 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", "instruction": "Write a C++ function `bool below_threshold(vectorl, int t)` to solve the following problem:\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"} +{"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", "buggy_solution": " return x+y+y+x;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "add", "signature": "int add(int x,int y)", "docstring": "Add two numbers x and y\n>>> add(2, 3)\n5\n>>> add(5, 7)\n12", "instruction": "Write a C++ function `int add(int x,int y)` to solve the following problem:\nAdd two numbers x and y\n>>> add(2, 3)\n5\n>>> add(5, 7)\n12"} +{"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", "buggy_solution": " for (int i=0;i>> 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", "instruction": "Write a C++ function `bool same_chars(string s0,string s1)` to solve the following problem:\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"} +{"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", "buggy_solution": " int f[1000];\n f[0]=0;f[1]=1;f[2]=2;\n for (int i=3;i<=n; i++)\n f[i]=f[i-1]+f[i-2];\n return f[n];\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "fib", "signature": "int fib(int n)", "docstring": "Return n-th Fibonacci number.\n>>> fib(10)\n55\n>>> fib(1)\n1\n>>> fib(8)\n21", "instruction": "Write a C++ function `int fib(int n)` to solve the following problem:\nReturn n-th Fibonacci number.\n>>> fib(10)\n55\n>>> fib(1)\n1\n>>> fib(8)\n21"} +{"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", "buggy_solution": " int level=0;\n for (int i=0;i') level+=1;\n if (brackets[i]=='<') level-=1;\n if (level<0) return false;\n }\n if (level!=0) return false;\n return true;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "correct_bracketing", "signature": "bool correct_bracketing(string brackets)", "docstring": "brackets is a string of '<' and '>'.\nreturn true if every opening bracket has a corresponding closing bracket.\n>>> correct_bracketing(\"<\")\nfalse\n>>> correct_bracketing(\"<>\")\ntrue\n>>> correct_bracketing(\"<<><>>\")\ntrue\n>>> correct_bracketing(\"><<>\")\nfalse", "instruction": "Write a C++ function `bool correct_bracketing(string brackets)` to solve the following problem:\nbrackets is a string of '<' and '>'.\nreturn true if every opening bracket has a corresponding closing bracket.\n>>> correct_bracketing(\"<\")\nfalse\n>>> correct_bracketing(\"<>\")\ntrue\n>>> correct_bracketing(\"<<><>>\")\ntrue\n>>> correct_bracketing(\"><<>\")\nfalse"} +{"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", "buggy_solution": " int incr,decr;\n incr=0;decr=0;\n for (int i=1;il[i-1]) incr=1;\n if (l[i] l)", "docstring": "Return 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", "instruction": "Write a C++ function `bool monotonic(vector l)` to solve the following problem:\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"} +{"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 out={};\n for (int i=0;i common(vector l1,vector l2)", "docstring": "Return 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}", "instruction": "Write a C++ function `vector common(vector l1,vector l2)` to solve the following problem:\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}"} +{"task_id": "CPP/59", "prompt": "/*\nReturn the largest prime factor of n. Assume n > 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", "buggy_solution": " for (int i=2;i*i<=n;i++)\n while (n%i==0 and n>i) n=i/n;\n return n;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "largest_prime_factor", "signature": "int largest_prime_factor(int n)", "docstring": "Return the largest prime factor of n. Assume n > 1 and is not a prime.\n>>> largest_prime_factor(13195)\n29\n>>> largest_prime_factor(2048)\n2", "instruction": "Write a C++ function `int largest_prime_factor(int n)` to solve the following problem:\nReturn the largest prime factor of n. Assume n > 1 and is not a prime.\n>>> largest_prime_factor(13195)\n29\n>>> largest_prime_factor(2048)\n2"} +{"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", "buggy_solution": " return n*n/2;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "sum_to_n", "signature": "int sum_to_n(int n)", "docstring": "sum_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", "instruction": "Write a C++ function `int sum_to_n(int n)` to solve the following problem:\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"} +{"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", "buggy_solution": " int level=0;\n for (int i=0;i>> correct_bracketing(\"(\")\nfalse\n>>> correct_bracketing(\"()\")\ntrue\n>>> correct_bracketing(\"(()())\")\ntrue\n>>> correct_bracketing(\")(()\")\nfalse", "instruction": "Write a C++ function `bool correct_bracketing(string brackets)` to solve the following problem:\nbrackets is a string of '(' and ')'.\nreturn true if every opening bracket has a corresponding closing bracket.\n>>> correct_bracketing(\"(\")\nfalse\n>>> correct_bracketing(\"()\")\ntrue\n>>> correct_bracketing(\"(()())\")\ntrue\n>>> correct_bracketing(\")(()\")\nfalse"} +{"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", "buggy_solution": " vector out={};\n for (int i=0;i derivative(vector xs)", "docstring": "xs represent coefficients of a polynomial.\nxs{0} + xs{1} * x + xs{2} * x^2 + ....\nReturn 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}", "instruction": "Write a C++ function `vector derivative(vector xs)` to solve the following problem:\nxs represent coefficients of a polynomial.\nxs{0} + xs{1} * x + xs{2} * x^2 + ....\nReturn 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}"} +{"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", "buggy_solution": " int ff[100];\n ff[0]=0;\n ff[1]=1;\n ff[2]=2;\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", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fibfib", "signature": "int fibfib(int n)", "docstring": "The 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", "instruction": "Write a C++ function `int fibfib(int n)` to solve the following problem:\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"} +{"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", "buggy_solution": " string vowels=\"aeiouyAEIOUY\";\n int count=0;\n for (int i=0;i>> vowels_count(\"abcde\")\n2\n>>> vowels_count(\"ACEDY\")\n3", "instruction": "Write a C++ function `int vowels_count(string s)` to solve the following problem:\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"} +{"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", "buggy_solution": " string xs;\n xs=to_string(x);\n if (xs.length() number of digits, return digits reversed.\n>>> circular_shift(12, 1)\n\"21\"\n>>> circular_shift(12, 2)\n\"12\"", "instruction": "Write a C++ function `string circular_shift(int x,int shift)` to solve the following problem:\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\""} +{"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", "buggy_solution": " int sum=0;\n for (int i=0;i=65 and s[i]<=100)\n sum+=s[i];\n return sum;\n}\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "digitSum", "signature": "int digitSum(string s)", "docstring": "Task\nWrite a function that takes a string as input and returns the sum of the upper characters only's\nASCII codes.\nExamples:\ndigitSum(\"\") => 0\ndigitSum(\"abAB\") => 131\ndigitSum(\"abcCd\") => 67\ndigitSum(\"helloE\") => 69\ndigitSum(\"woArBld\") => 131\ndigitSum(\"aAaaaXa\") => 153", "instruction": "Write a C++ function `int digitSum(string s)` to solve the following problem:\nTask\nWrite a function that takes a string as input and returns the sum of the upper characters only's\nASCII codes.\nExamples:\ndigitSum(\"\") => 0\ndigitSum(\"abAB\") => 131\ndigitSum(\"abcCd\") => 67\ndigitSum(\"helloE\") => 69\ndigitSum(\"woArBld\") => 131\ndigitSum(\"aAaaaXa\") => 153"} +{"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", "buggy_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-1-atoi(num1.c_str())-atoi(num2.c_str());\n\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "fruit_distribution", "signature": "int fruit_distribution(string s,int n)", "docstring": "In 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", "instruction": "Write a C++ function `int fruit_distribution(string s,int n)` to solve the following problem:\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"} +{"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 out={};\n for (int i=0;i pluck(vector arr)", "docstring": "Given 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.\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 {}.\nExample 1:\nInput: {4,2,3}\nOutput: {2, 1}\nExplanation: 2 has the smallest even value, and 2 has the smallest index.\nExample 2:\nInput: {1,2,3}\nOutput: {2, 1}\nExplanation: 2 has the smallest even value, and 2 has the smallest index.\nExample 3:\nInput: {}\nOutput: {}\nExample 4:\nInput: {5, 0, 3, 0, 4, 2}\nOutput: {0, 1}\nExplanation: 0 is the smallest value, but there are two zeros,\nso we will choose the first zero, which has the smallest index.\nConstraints:\n* 1 <= nodes.length <= 10000\n* 0 <= node.value", "instruction": "Write a C++ function `vector pluck(vector arr)` to solve the following problem:\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.\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 {}.\nExample 1:\nInput: {4,2,3}\nOutput: {2, 1}\nExplanation: 2 has the smallest even value, and 2 has the smallest index.\nExample 2:\nInput: {1,2,3}\nOutput: {2, 1}\nExplanation: 2 has the smallest even value, and 2 has the smallest index.\nExample 3:\nInput: {}\nOutput: {}\nExample 4:\nInput: {5, 0, 3, 0, 4, 2}\nOutput: {0, 1}\nExplanation: 0 is the smallest value, but there are two zeros,\nso we will choose the first zero, which has the smallest index.\nConstraints:\n* 1 <= nodes.length <= 10000\n* 0 <= node.value"} +{"task_id": "CPP/69", "prompt": "/*\nYou are given a non-empty vector of positive integers. Return the greatest integer that is greater than \nzero, and has a frequency greater than or equal to the value of the integer itself. \nThe frequency of an integer is the number of times it appears in the vector.\nIf no such a value exist, return -1.\nExamples:\n search({4, 1, 2, 2, 3, 1}) == 2\n search({1, 2, 2, 3, 3, 3, 4, 4, 4}) == 3\n search({5, 5, 4, 4, 4}) == -1\n*/\n#include\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", "buggy_solution": " vector> freq={};\n int max=0;\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", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "search", "signature": "int search(vector lst)", "docstring": "You are given a non-empty vector of positive integers. Return the greatest integer that is greater than\nzero, and has a frequency greater than or equal to the value of the integer itself.\nThe frequency of an integer is the number of times it appears in the vector.\nIf no such a value exist, return -1.\nExamples:\nsearch({4, 1, 2, 2, 3, 1}) == 2\nsearch({1, 2, 2, 3, 3, 3, 4, 4, 4}) == 3\nsearch({5, 5, 4, 4, 4}) == -1", "instruction": "Write a C++ function `int search(vector lst)` to solve the following problem:\nYou are given a non-empty vector of positive integers. Return the greatest integer that is greater than\nzero, and has a frequency greater than or equal to the value of the integer itself.\nThe frequency of an integer is the number of times it appears in the vector.\nIf no such a value exist, return -1.\nExamples:\nsearch({4, 1, 2, 2, 3, 1}) == 2\nsearch({1, 2, 2, 3, 3, 3, 4, 4, 4}) == 3\nsearch({5, 5, 4, 4, 4}) == -1"} +{"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 out={};\n sort(lst.begin(),lst.end());\n int l=0,r=lst.size()-1;\n while (l strange_sort_list(vector lst)", "docstring": "Given 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.\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({}) == {}", "instruction": "Write a C++ function `vector strange_sort_list(vector lst)` to solve the following problem:\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.\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({}) == {}"} +{"task_id": "CPP/71", "prompt": "/*\nGiven the lengths of the three sides of a triangle. Return the area of\nthe triangle rounded to 2 decimal points if the three sides form a valid triangle. \nOtherwise return -1\nThree sides make a valid triangle when the sum of any two sides is greater \nthan the third side.\nExample:\ntriangle_area(3, 4, 5) == 6.00\ntriangle_area(1, 2, 10) == -1\n*/\n#include\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", "buggy_solution": " if (a+b<=c or a+c<=b or b+c<=a) return -1;\n float h=(a+b+c);\n float area;\n area=pow(h*(h-a)*(h-b)*(h-c),0.5);\n return area;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "triangle_area", "signature": "float triangle_area(float a,float b,float c)", "docstring": "Given the lengths of the three sides of a triangle. Return the area of\nthe triangle rounded to 2 decimal points if the three sides form a valid triangle.\nOtherwise return -1\nThree sides make a valid triangle when the sum of any two sides is greater\nthan the third side.\nExample:\ntriangle_area(3, 4, 5) == 6.00\ntriangle_area(1, 2, 10) == -1", "instruction": "Write a C++ function `float triangle_area(float a,float b,float c)` to solve the following problem:\nGiven the lengths of the three sides of a triangle. Return the area of\nthe triangle rounded to 2 decimal points if the three sides form a valid triangle.\nOtherwise return -1\nThree sides make a valid triangle when the sum of any two sides is greater\nthan the third side.\nExample:\ntriangle_area(3, 4, 5) == 6.00\ntriangle_area(1, 2, 10) == -1"} +{"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", "buggy_solution": " int sum=0;\n for (int i=0;iw) return false;\n return true;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "will_it_fly", "signature": "bool will_it_fly(vector q,int w)", "docstring": "Write 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.\nExample:\nwill_it_fly({1, 2}, 5) \u279e false\n// 1+2 is less than the maximum possible weight, but it's unbalanced.\nwill_it_fly({3, 2, 3}, 1) \u279e false\n// it's balanced, but 3+2+3 is more than the maximum possible weight.\nwill_it_fly({3, 2, 3}, 9) \u279e true\n// 3+2+3 is less than the maximum possible weight, and it's balanced.\nwill_it_fly({3}, 5) \u279e true\n// 3 is less than the maximum possible weight, and it's balanced.", "instruction": "Write a C++ function `bool will_it_fly(vector q,int w)` to solve the following problem:\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.\nExample:\nwill_it_fly({1, 2}, 5) \u279e false\n// 1+2 is less than the maximum possible weight, but it's unbalanced.\nwill_it_fly({3, 2, 3}, 1) \u279e false\n// it's balanced, but 3+2+3 is more than the maximum possible weight.\nwill_it_fly({3, 2, 3}, 9) \u279e true\n// 3+2+3 is less than the maximum possible weight, and it's balanced.\nwill_it_fly({3}, 5) \u279e true\n// 3 is less than the maximum possible weight, and it's balanced."} +{"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", "buggy_solution": " int out=0;\n for (int i=0;i arr)", "docstring": "Given 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.\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", "instruction": "Write a C++ function `int smallest_change(vector arr)` to solve the following problem:\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.\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"} +{"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;inum2) return lst1;\n return lst2;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "total_match", "signature": "vector total_match(vector lst1,vector lst2)", "docstring": "Write 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.\nif the two vectors have the same number of chars, return the first vector.\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\"}", "instruction": "Write a C++ function `vector total_match(vector lst1,vector lst2)` to solve the following problem:\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.\nif the two vectors have the same number of chars, return the first vector.\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\"}"} +{"task_id": "CPP/75", "prompt": "/*\nWrite a function that returns true if the given number is the multiplication of 3 prime numbers\nand false otherwise.\nKnowing that (a) is less then 100. \nExample:\nis_multiply_prime(30) == true\n30 = 2 * 3 * 5\n*/\n#include\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", "buggy_solution": " int num=0;\n for (int i=0;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", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_multiply_prime", "signature": "bool is_multiply_prime(int a)", "docstring": "Write a function that returns true if the given number is the multiplication of 3 prime numbers\nand false otherwise.\nKnowing that (a) is less then 100.\nExample:\nis_multiply_prime(30) == true\n30 = 2 * 3 * 5", "instruction": "Write a C++ function `bool is_multiply_prime(int a)` to solve the following problem:\nWrite a function that returns true if the given number is the multiplication of 3 prime numbers\nand false otherwise.\nKnowing that (a) is less then 100.\nExample:\nis_multiply_prime(30) == true\n30 = 2 * 3 * 5"} +{"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", "buggy_solution": " int p=1,count=0;\n while (p<=x)\n {\n if (p==x) return true;\n count=p*n;x+=1;p+=1;\n }\n return false;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "infinite loop", "entry_point": "is_simple_power", "signature": "bool is_simple_power(int x,int n)", "docstring": "Your 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", "instruction": "Write a C++ function `bool is_simple_power(int x,int n)` to solve the following problem:\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"} +{"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 iscube(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 (iscube(1) == true);\n assert (iscube(2) == false);\n assert (iscube(-1) == true);\n assert (iscube(64) == true);\n assert (iscube(180) == false);\n assert (iscube(1000) == true);\n assert (iscube(0) == true);\n assert (iscube(1729) == false);\n}\n", "declaration": "#include\n#include\nusing namespace std;\n#include\n#include\nbool iscube(int a){\n", "example_test": "#undef NDEBUG\n#include\nint main(){\n assert (iscube(1) == true);\n assert (iscube(2) == false);\n assert (iscube(-1) == true);\n assert (iscube(64) == true);\n assert (iscube(180) == false);\n assert (iscube(0) == true);\n}\n", "buggy_solution": " for (int i=0;i*i*i<=abs(a);i++)\n if (i*i==abs(a)) return true;\n return false;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "iscube", "signature": "bool iscube(int a)", "docstring": "Write 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", "instruction": "Write a C++ function `bool iscube(int a)` to solve the following problem:\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"} +{"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", "buggy_solution": " string key=\"2357BD\";\n int out=1;\n for (int i=0;i\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", "buggy_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+\"d\";\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "decimal_to_binary", "signature": "string decimal_to_binary(int decimal)", "docstring": "You 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'.\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.\nExamples:\ndecimal_to_binary(15) // returns \"db1111db\"\ndecimal_to_binary(32) // returns \"db100000db\"", "instruction": "Write a C++ function `string decimal_to_binary(int decimal)` to solve the following problem:\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'.\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.\nExamples:\ndecimal_to_binary(15) // returns \"db1111db\"\ndecimal_to_binary(32) // returns \"db100000db\""} +{"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", "buggy_solution": " if (s.length()<3) return false;\n for (int i=2;i false\nis_happy(\"aa\") => false\nis_happy(\"abcd\") => true\nis_happy(\"aabb\") => false\nis_happy(\"adb\") => true\nis_happy(\"xyy\") => false", "instruction": "Write a C++ function `bool is_happy(string s)` to solve the following problem:\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"} +{"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 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", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "numerical_letter_grade", "signature": "vector numerical_letter_grade(vector grades)", "docstring": "It 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:\nGPA | Letter grade\n4.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-\n0.0 E\nExample:\ngrade_equation({4.0, 3, 1.7, 2, 3.5}) ==> {\"A+\", \"B\", \"C-\", \"C\", \"A-\"}", "instruction": "Write a C++ function `vector numerical_letter_grade(vector grades)` to solve the following problem:\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:\nGPA | Letter grade\n4.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-\n0.0 E\nExample:\ngrade_equation({4.0, 3, 1.7, 2, 3.5}) ==> {\"A+\", \"B\", \"C-\", \"C\", \"A-\"}"} +{"task_id": "CPP/82", "prompt": "/*\nWrite a function that takes a string and returns true if the string\nlength is a prime number or false otherwise\nExamples\nprime_length(\"Hello\") == true\nprime_length(\"abcdcba\") == true\nprime_length(\"kittens\") == true\nprime_length(\"orange\") == false\n*/\n#include\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", "buggy_solution": " int l,i;\n l=str.length();\n if (l<2) return false;\n for (i=3;i*i<=l;i++)\n if (l%i==0) return false;\n return true;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "prime_length", "signature": "bool prime_length(string str)", "docstring": "Write a function that takes a string and returns true if the string\nlength is a prime number or false otherwise\nExamples\nprime_length(\"Hello\") == true\nprime_length(\"abcdcba\") == true\nprime_length(\"kittens\") == true\nprime_length(\"orange\") == false", "instruction": "Write a C++ function `bool prime_length(string str)` to solve the following problem:\nWrite a function that takes a string and returns true if the string\nlength is a prime number or false otherwise\nExamples\nprime_length(\"Hello\") == true\nprime_length(\"abcdcba\") == true\nprime_length(\"kittens\") == true\nprime_length(\"orange\") == false"} +{"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": "", "buggy_solution": " if (n<1) return 0;\n if (n==1) return 1;\n int out=18;\n for (int i=2;i\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": "", "buggy_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", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "solve", "signature": "string solve(int N)", "docstring": "Given a positive integer N, return the total sum of its digits in binary.\nExample\nFor N = 1000, the sum of digits will be 1 the output should be \"1\".\nFor N = 150, the sum of digits will be 6 the output should be \"110\".\nFor N = 147, the sum of digits will be 12 the output should be \"1100\".\nVariables:\n@N integer\nConstraints: 0 \u2264 N \u2264 10000.\nOutput:\na string of binary number", "instruction": "Write a C++ function `string solve(int N)` to solve the following problem:\nGiven a positive integer N, return the total sum of its digits in binary.\nExample\nFor N = 1000, the sum of digits will be 1 the output should be \"1\".\nFor N = 150, the sum of digits will be 6 the output should be \"110\".\nFor N = 147, the sum of digits will be 12 the output should be \"1100\".\nVariables:\n@N integer\nConstraints: 0 \u2264 N \u2264 10000.\nOutput:\na string of binary number"} +{"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", "buggy_solution": " int sum=0;\n for (int i=0;i*2 lst)", "docstring": "Given a non-empty vector of integers lst. add the even elements that are at odd indices..\nExamples:\nadd({4, 2, 6, 7}) ==> 2", "instruction": "Write a C++ function `int add(vector lst)` to solve the following problem:\nGiven a non-empty vector of integers lst. add the even elements that are at odd indices..\nExamples:\nadd({4, 2, 6, 7}) ==> 2"} +{"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", "buggy_solution": " string out=\"\";\n string current=\"\";\n s=s+' ';\n for (int i=0;i\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> out={};\n for (int i=0;i=0;j-=1)\n if (lst[i][j]==x) out.push_back({j,i});\n return out;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "get_row", "signature": "vector> get_row(vector> lst, int x)", "docstring": "You 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.\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}}", "instruction": "Write a C++ function `vector> get_row(vector> lst, int x)` to solve the following problem:\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.\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}}"} +{"task_id": "CPP/88", "prompt": "/*\nGiven a vector of non-negative integers, return a copy of the given vector after sorting,\nyou will sort the given vector in ascending order if the sum( first index value, last index value) is odd,\nor sort it in descending order if the sum( first index value, last index value) is even.\n\nNote:\n* don't change the given vector.\n\nExamples:\n* sort_vector({}) => {}\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 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", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "sort_array", "signature": "vector sort_array(vector array)", "docstring": "Given a vector of non-negative integers, return a copy of the given vector after sorting,\nyou will sort the given vector in ascending order if the sum( first index value, last index value) is odd,\nor sort it in descending order if the sum( first index value, last index value) is even.\nNote:\n* don't change the given vector.\nExamples:\n* sort_vector({}) => {}\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}", "instruction": "Write a C++ function `vector sort_array(vector array)` to solve the following problem:\nGiven a vector of non-negative integers, return a copy of the given vector after sorting,\nyou will sort the given vector in ascending order if the sum( first index value, last index value) is odd,\nor sort it in descending order if the sum( first index value, last index value) is even.\nNote:\n* don't change the given vector.\nExamples:\n* sort_vector({}) => {}\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}"} +{"task_id": "CPP/89", "prompt": "/*\nCreate a function encrypt that takes a string as an argument and\nreturns a string encrypted with the alphabet being rotated. \nThe alphabet should be rotated in a manner such that the letters \nshift down by two multiplied to two places.\nFor example:\nencrypt(\"hi\") returns \"lm\"\nencrypt(\"asdfghjkl\") returns \"ewhjklnop\"\nencrypt(\"gf\") returns \"kj\"\nencrypt(\"et\") returns \"ix\"\n*/\n#include\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", "buggy_solution": " string out;\n int i;\n for (i=0;i\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", "buggy_solution": " sort(lst.begin(),lst.end());\n for (int i=2;i lst)", "docstring": "You 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.\nnext_smallest({1, 2, 3, 4, 5}) == 2\nnext_smallest({5, 1, 4, 3, 2}) == 2\nnext_smallest({}) == None\nnext_smallest({1, 1}) == None", "instruction": "Write a C++ function `int next_smallest(vector lst)` to solve the following problem:\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.\nnext_smallest({1, 2, 3, 4, 5}) == 2\nnext_smallest({5, 1, 4, 3, 2}) == 2\nnext_smallest({}) == None\nnext_smallest({1, 1}) == None"} +{"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", "buggy_solution": " bool isstart=true;\n bool isi=false;\n int sum=0;\n for (int i=0;i>> is_bored(\"Hello world\")\n0\n>>> is_bored(\"The sky is blue. The sun is shining. I love this weather\")\n1", "instruction": "Write a C++ function `int is_bored(string S)` to solve the following problem:\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 '!'.\nFor example:\n>>> is_bored(\"Hello world\")\n0\n>>> is_bored(\"The sky is blue. The sun is shining. I love this weather\")\n1"} +{"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", "buggy_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 b+c==a) return true;\n return false;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "any_int", "signature": "bool any_int(float a,float b,float c)", "docstring": "Create 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.\nExamples\nany_int(5, 2, 7) \u279e true\nany_int(3, 2, 2) \u279e false\nany_int(3, -2, 1) \u279e true\nany_int(3.6, -2.2, 2) \u279e false", "instruction": "Write a C++ function `bool any_int(float a,float b,float c)` to solve the following problem:\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.\nExamples\nany_int(5, 2, 7) \u279e true\nany_int(3, 2, 2) \u279e false\nany_int(3, -2, 1) \u279e true\nany_int(3.6, -2.2, 2) \u279e false"} +{"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", "buggy_solution": " string vowels=\"aeiou\";\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", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "encode", "signature": "string encode(string message)", "docstring": "Write 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.\nExamples:\n>>> encode('test\")\n\"TGST\"\n>>> encode(\"This is a message\")\n'tHKS KS C MGSSCGG\"", "instruction": "Write a C++ function `string encode(string message)` to solve the following problem:\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.\nExamples:\n>>> encode('test\")\n\"TGST\"\n>>> encode(\"This is a message\")\n'tHKS KS C MGSSCGG\""} +{"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", "buggy_solution": " int largest=0;\n for (int i=0;ilargest)\n {\n bool prime=false;\n for (int j=2;j*j<=lst[i];j++)\n if (lst[i]%j==0) prime=true;\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", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "skjkasdkd", "signature": "int skjkasdkd(vector lst)", "docstring": "You are given a vector of integers.\nYou need to find the largest prime value and return the sum of its digits.\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", "instruction": "Write a C++ function `int skjkasdkd(vector lst)` to solve the following problem:\nYou are given a vector of integers.\nYou need to find the largest prime value and return the sum of its digits.\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"} +{"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", "buggy_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", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "check_dict_case", "signature": "bool check_dict_case(map dict)", "docstring": "Given 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.", "instruction": "Write a C++ function `bool check_dict_case(map dict)` to solve the following problem:\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."} +{"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 out={};\n int i,j;\n for (i=2;i count_up_to(int n)", "docstring": "Implement 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}", "instruction": "Write a C++ function `vector count_up_to(int n)` to solve the following problem:\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}"} +{"task_id": "CPP/97", "prompt": "/*\nComplete the function that takes two integers and returns \nthe product of their unit digits.\nAssume the input is always valid.\nExamples:\nmultiply(148, 412) should return 16.\nmultiply(19, 28) should return 72.\nmultiply(2020, 1851) should return 0.\nmultiply(14,-15) should return 20.\n*/\n#include\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", "buggy_solution": " return (abs(a)%10)*(abs(b)%10)*a*b;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "multiply", "signature": "int multiply(int a,int b)", "docstring": "Complete the function that takes two integers and returns\nthe product of their unit digits.\nAssume the input is always valid.\nExamples:\nmultiply(148, 412) should return 16.\nmultiply(19, 28) should return 72.\nmultiply(2020, 1851) should return 0.\nmultiply(14,-15) should return 20.", "instruction": "Write a C++ function `int multiply(int a,int b)` to solve the following problem:\nComplete the function that takes two integers and returns\nthe product of their unit digits.\nAssume the input is always valid.\nExamples:\nmultiply(148, 412) should return 16.\nmultiply(19, 28) should return 72.\nmultiply(2020, 1851) should return 0.\nmultiply(14,-15) should return 20."} +{"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", "buggy_solution": " string uvowel=\"AEIOU\";\n int count=0;\n for (int i=0;i*2>> 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", "buggy_solution": " double w;\n w=atof(value.c_str());\n return floor(w);\n}\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "closest_integer", "signature": "int closest_integer(string value)", "docstring": "Create 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.\nExamples\n>>> closest_integer(\"10\")\n10\n>>> closest_integer(\"15.3\")\n15\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.", "instruction": "Write a C++ function `int closest_integer(string value)` to solve the following problem:\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.\nExamples\n>>> closest_integer(\"10\")\n10\n>>> closest_integer(\"15.3\")\n15\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."} +{"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 out={n};\n for (int i=1;i make_a_pile(int n)", "docstring": "Given 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).\nExamples:\n>>> make_a_pile(3)\n{3, 5, 7}", "instruction": "Write a C++ function `vector make_a_pile(int n)` to solve the following problem:\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).\nExamples:\n>>> make_a_pile(3)\n{3, 5, 7}"} +{"task_id": "CPP/101", "prompt": "/*\nYou will be given a string of words separated by commas or spaces. Your task is\nto split the string into words and return a vector of the words.\n\nFor example:\nwords_string(\"Hi, my name is John\") == {\"Hi\", \"my\", \"name\", \"is\", \"John\"}\nwords_string(\"One, two, three, four, five, six\") == {\"One\", 'two\", 'three\", \"four\", \"five\", 'six\"}\n*/\n#include\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 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", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "words_string", "signature": "vector words_string(string s)", "docstring": "You will be given a string of words separated by commas or spaces. Your task is\nto split the string into words and return a vector of the words.\nFor example:\nwords_string(\"Hi, my name is John\") == {\"Hi\", \"my\", \"name\", \"is\", \"John\"}\nwords_string(\"One, two, three, four, five, six\") == {\"One\", 'two\", 'three\", \"four\", \"five\", 'six\"}", "instruction": "Write a C++ function `vector words_string(string s)` to solve the following problem:\nYou will be given a string of words separated by commas or spaces. Your task is\nto split the string into words and return a vector of the words.\nFor example:\nwords_string(\"Hi, my name is John\") == {\"Hi\", \"my\", \"name\", \"is\", \"John\"}\nwords_string(\"One, two, three, four, five, six\") == {\"One\", 'two\", 'three\", \"four\", \"five\", 'six\"}"} +{"task_id": "CPP/102", "prompt": "/*\nThis function takes two positive numbers x and y and returns the\nbiggest even integer number that is in the range [x, y] inclusive. If \nthere's no such number, then the function should return -1.\n\nFor example:\nchoose_num(12, 15) = 14\nchoose_num(13, 12) = -1\n*/\n#include\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", "buggy_solution": " if (y \"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", "buggy_solution": " if (n>m) return \"-1\";\n int num=(m+n+1)/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", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "rounded_avg", "signature": "string rounded_avg(int n,int m)", "docstring": "You 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\"", "instruction": "Write a C++ function `string rounded_avg(int n,int m)` to solve the following problem:\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\""} +{"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 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 if (u) out.push_back(num);\n }\n sort(out.begin(),out.end());\n return out;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "unique_digits", "signature": "vector unique_digits(vector x)", "docstring": "Given a vector of positive integers x. return a sorted vector of all\nelements that hasn't any even digit.\nNote: Returned vector should be sorted in increasing order.\nFor example:\n>>> unique_digits({15, 33, 1422, 1})\n{1, 15, 33}\n>>> unique_digits({152, 323, 1422, 10})\n{}", "instruction": "Write a C++ function `vector unique_digits(vector x)` to solve the following problem:\nGiven a vector of positive integers x. return a sorted vector of all\nelements that hasn't any even digit.\nNote: Returned vector should be sorted in increasing order.\nFor example:\n>>> unique_digits({15, 33, 1422, 1})\n{1, 15, 33}\n>>> unique_digits({152, 323, 1422, 10})\n{}"} +{"task_id": "CPP/105", "prompt": "/*\nGiven a vector of integers, sort the integers that are between 1 and 9 inclusive,\nreverse the resulting vector, and then replace each digit by its corresponding name from\n\"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\".\n\nFor example:\n arr = {2, 1, 1, 4, 5, 8, 2, 3} \n -> 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 numto={{0,\"Zero\"},{1,\"One\"},{2,\"Two\"},{3,\"Three\"},{4,\"Four\"},{5,\"Five\"},{6,\"Six\"},{7,\"Seven\"},{8,\"Eight\"},{9,\"Nine\"}};\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", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "by_length", "signature": "vector by_length(vector arr)", "docstring": "Given a vector of integers, sort the integers that are between 1 and 9 inclusive,\nreverse the resulting vector, and then replace each digit by its corresponding name from\n\"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\".\nFor example:\narr = {2, 1, 1, 4, 5, 8, 2, 3}\n-> sort arr -> {1, 1, 2, 2, 3, 4, 5, 8}\n-> reverse arr -> {8, 5, 4, 3, 2, 2, 1, 1}\nreturn {\"Eight\", \"Five\", \"Four\", \"Three\", \"Two\", \"Two\", \"One\", \"One\"}\nIf the vector is empty, return an empty vector:\narr = {}\nreturn {}\nIf the vector has any strange number ignore it:\narr = {1, -1 , 55}\n-> sort arr -> {-1, 1, 55}\n-> reverse arr -> {55, 1, -1}\nreturn = {\"One\"}", "instruction": "Write a C++ function `vector by_length(vector arr)` to solve the following problem:\nGiven a vector of integers, sort the integers that are between 1 and 9 inclusive,\nreverse the resulting vector, and then replace each digit by its corresponding name from\n\"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\".\nFor example:\narr = {2, 1, 1, 4, 5, 8, 2, 3}\n-> sort arr -> {1, 1, 2, 2, 3, 4, 5, 8}\n-> reverse arr -> {8, 5, 4, 3, 2, 2, 1, 1}\nreturn {\"Eight\", \"Five\", \"Four\", \"Three\", \"Two\", \"Two\", \"One\", \"One\"}\nIf the vector is empty, return an empty vector:\narr = {}\nreturn {}\nIf the vector has any strange number ignore it:\narr = {1, -1 , 55}\n-> sort arr -> {-1, 1, 55}\n-> reverse arr -> {55, 1, -1}\nreturn = {\"One\"}"} +{"task_id": "CPP/106", "prompt": "/*\nImplement the function f that takes n as a parameter,\nand returns a vector of size n, such that the value of the element at index i is the factorial of i if i is even\nor the sum of numbers from 1 to i otherwise.\ni starts from 1.\nthe factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).\nExample:\nf(5) == {1, 2, 6, 24, 15}\n*/\n#include\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 out={};\n for (int i=1;i<=n;i++)\n {\n sum+=i;\n prod*=i;\n if (prod%2==0) out.push_back(prod);\n else out.push_back(sum);\n } \n return out;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "f", "signature": "vector f(int n)", "docstring": "Implement the function f that takes n as a parameter,\nand returns a vector of size n, such that the value of the element at index i is the factorial of i if i is even\nor the sum of numbers from 1 to i otherwise.\ni starts from 1.\nthe factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).\nExample:\nf(5) == {1, 2, 6, 24, 15}", "instruction": "Write a C++ function `vector f(int n)` to solve the following problem:\nImplement the function f that takes n as a parameter,\nand returns a vector of size n, such that the value of the element at index i is the factorial of i if i is even\nor the sum of numbers from 1 to i otherwise.\ni starts from 1.\nthe factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).\nExample:\nf(5) == {1, 2, 6, 24, 15}"} +{"task_id": "CPP/107", "prompt": "/*\nGiven a positive integer n, return a vector that has the number of even and odd\ninteger palindromes that fall within the range(1, n), inclusive.\n\nExample 1:\n\n Input: 3\n Output: (1, 2)\n Explanation:\n Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.\n\nExample 2:\n\n Input: 12\n Output: (4, 6)\n Explanation:\n Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\n\nNote:\n 1. 1 <= n <= 10^3\n 2. returned vector has the number of even and odd integer palindromes respectively.\n*/\n#include\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 even_odd_palindrome(int n)", "docstring": "Given a positive integer n, return a vector that has the number of even and odd\ninteger palindromes that fall within the range(1, n), inclusive.\nExample 1:\nInput: 3\nOutput: (1, 2)\nExplanation:\nInteger palindrome are 1, 2, 3. one of them is even, and two of them are odd.\nExample 2:\nInput: 12\nOutput: (4, 6)\nExplanation:\nInteger palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\nNote:\n1. 1 <= n <= 10^3\n2. returned vector has the number of even and odd integer palindromes respectively.", "instruction": "Write a C++ function `vector even_odd_palindrome(int n)` to solve the following problem:\nGiven a positive integer n, return a vector that has the number of even and odd\ninteger palindromes that fall within the range(1, n), inclusive.\nExample 1:\nInput: 3\nOutput: (1, 2)\nExplanation:\nInteger palindrome are 1, 2, 3. one of them is even, and two of them are odd.\nExample 2:\nInput: 12\nOutput: (4, 6)\nExplanation:\nInteger palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\nNote:\n1. 1 <= n <= 10^3\n2. returned vector has the number of even and odd integer palindromes respectively."} +{"task_id": "CPP/108", "prompt": "/*\nWrite a function count_nums which takes a vector of integers and returns\nthe number of elements which has a sum of digits > 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", "buggy_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*-1;\n if (sum>0) num+=1;\n }\n return num;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "count_nums", "signature": "int count_nums(vector n)", "docstring": "Write a function count_nums which takes a vector of integers and returns\nthe number of elements which has a sum of digits > 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", "instruction": "Write a C++ function `int count_nums(vector n)` to solve the following problem:\nWrite a function count_nums which takes a vector of integers and returns\nthe number of elements which has a sum of digits > 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"} +{"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", "buggy_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", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "move_one_ball", "signature": "bool move_one_ball(vector arr)", "docstring": "We 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:\nYou are allowed to perform right shift operation any number of times.\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.\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.\nNote: The given vector is guaranteed to have unique elements.\nFor Example:\nmove_one_ball({3, 4, 5, 1, 2})==>true\nExplanation: By performing 2 right shift operations, non-decreasing order can\nbe 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\nvector by performing any number of right shift operations.", "instruction": "Write a C++ function `bool move_one_ball(vector arr)` to solve the following problem:\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:\nYou are allowed to perform right shift operation any number of times.\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.\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.\nNote: The given vector is guaranteed to have unique elements.\nFor Example:\nmove_one_ball({3, 4, 5, 1, 2})==>true\nExplanation: By performing 2 right shift operations, non-decreasing order can\nbe 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\nvector by performing any number of right shift operations."} +{"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", "buggy_solution": " int num=0;\n for (int i=0;i lst1,vector lst2)", "docstring": "In 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.", "instruction": "Write a C++ function `string exchange(vector lst1,vector lst2)` to solve the following problem:\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."} +{"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", "buggy_solution": " map count={},out={};\n map ::iterator it;\n int max=0;\n for (int i=1;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", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "histogram", "signature": "map histogram(string test)", "docstring": "Given 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.\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(\"\") == {}", "instruction": "Write a C++ function `map histogram(string test)` to solve the following problem:\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.\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(\"\") == {}"} +{"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 reverse_delete(string s,string c)", "docstring": "Task\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\")", "instruction": "Write a C++ function `vector reverse_delete(string s,string c)` to solve the following problem:\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\")"} +{"task_id": "CPP/113", "prompt": "/*\nGiven a vector of strings, where each string consists of only digits, return a vector.\nEach element i of the output should be 'the number of odd elements in the\nstring i of the input.\" where all the i's should be replaced by the number\nof odd digits in the i'th string of the input.\n\n>>> 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 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 i the input.\";\n string s2=\"\";\n for (int j=0;j odd_count(vector lst)", "docstring": "Given a vector of strings, where each string consists of only digits, return a vector.\nEach element i of the output should be 'the number of odd elements in the\nstring i of the input.\" where all the i's should be replaced by the number\nof odd digits in the i'th string of the input.\n>>> 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.\"}", "instruction": "Write a C++ function `vector odd_count(vector lst)` to solve the following problem:\nGiven a vector of strings, where each string consists of only digits, return a vector.\nEach element i of the output should be 'the number of odd elements in the\nstring i of the input.\" where all the i's should be replaced by the number\nof odd digits in the i'th string of the input.\n>>> 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.\"}"} +{"task_id": "CPP/114", "prompt": "/*\nGiven a vector of integers nums, find the minimum sum of any non-empty sub-vector\nof nums.\nExample\nminSubArraySum({2, 3, 4, 1, 2, 4}) == 1\nminSubArraySum({-1, -2, -3}) == -6\n*/\n#include\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", "buggy_solution": " long long current,min;\n current=nums[0];\n min=nums[0];\n for (int i=1;i nums)", "docstring": "Given a vector of integers nums, find the minimum sum of any non-empty sub-vector\nof nums.\nExample\nminSubArraySum({2, 3, 4, 1, 2, 4}) == 1\nminSubArraySum({-1, -2, -3}) == -6", "instruction": "Write a C++ function `long long minSubArraySum(vector nums)` to solve the following problem:\nGiven a vector of integers nums, find the minimum sum of any non-empty sub-vector\nof nums.\nExample\nminSubArraySum({2, 3, 4, 1, 2, 4}) == 1\nminSubArraySum({-1, -2, -3}) == -6"} +{"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", "buggy_solution": " int out=0;\n for (int i=0;i0) out+=sum/capacity+1;\n }\n return out;\n}\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "max_fill", "signature": "int max_fill(vector> grid,int capacity)", "docstring": "You 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.\nExample 1:\nInput:\ngrid : {{0,0,1,0}, {0,1,0,0}, {1,1,1,1}}\nbucket_capacity : 1\nOutput: 6\nExample 2:\nInput:\ngrid : {{0,0,1,1}, {0,0,0,0}, {1,1,1,1}, {0,1,1,1}}\nbucket_capacity : 2\nOutput: 5\nExample 3:\nInput:\ngrid : {{0,0,0}, {0,0,0}}\nbucket_capacity : 5\nOutput: 0\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", "instruction": "Write a C++ function `int max_fill(vector> grid,int capacity)` to solve the following problem:\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.\nExample 1:\nInput:\ngrid : {{0,0,1,0}, {0,1,0,0}, {1,1,1,1}}\nbucket_capacity : 1\nOutput: 6\nExample 2:\nInput:\ngrid : {{0,0,1,1}, {0,0,0,0}, {1,1,1,1}, {0,1,1,1}}\nbucket_capacity : 2\nOutput: 5\nExample 3:\nInput:\ngrid : {{0,0,0}, {0,0,0}}\nbucket_capacity : 5\nOutput: 0\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"} +{"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 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 sort_array(vector arr)", "docstring": "In 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.\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}", "instruction": "Write a C++ function `vector sort_array(vector arr)` to solve the following problem:\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.\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}"} +{"task_id": "CPP/117", "prompt": "/*\nGiven a string s and a natural number n, you have been tasked to implement \na function that returns a vector of all words from string s that contain exactly \nn consonants, in order these words appear in the string s.\nIf the string s is empty then the function should return an empty vector.\nNote: you may assume the input string contains only letters and spaces.\nExamples:\nselect_words(\"Mary had a little lamb\", 4) ==> {\"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 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", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "select_words", "signature": "vector select_words(string s,int n)", "docstring": "Given a string s and a natural number n, you have been tasked to implement\na function that returns a vector of all words from string s that contain exactly\nn consonants, in order these words appear in the string s.\nIf the string s is empty then the function should return an empty vector.\nNote: you may assume the input string contains only letters and spaces.\nExamples:\nselect_words(\"Mary had a little lamb\", 4) ==> {\"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\"}", "instruction": "Write a C++ function `vector select_words(string s,int n)` to solve the following problem:\nGiven a string s and a natural number n, you have been tasked to implement\na function that returns a vector of all words from string s that contain exactly\nn consonants, in order these words appear in the string s.\nIf the string s is empty then the function should return an empty vector.\nNote: you may assume the input string contains only letters and spaces.\nExamples:\nselect_words(\"Mary had a little lamb\", 4) ==> {\"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\"}"} +{"task_id": "CPP/118", "prompt": "/*\nYou are given a word. Your task is to find the closest vowel that stands between \ntwo consonants from the right side of the word (case sensitive).\n\nVowels in the beginning and ending doesn't count. Return empty string if you didn't\nfind any vowel met the above condition. \n\nYou may assume that the given string contains English letter only.\n\nExample:\nget_closest_vowel(\"yogurt\") ==> \"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", "buggy_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", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "get_closest_vowel", "signature": "string get_closest_vowel(string word)", "docstring": "You are given a word. Your task is to find the closest vowel that stands between\ntwo consonants from the right side of the word (case sensitive).\nVowels in the beginning and ending doesn't count. Return empty string if you didn't\nfind any vowel met the above condition.\nYou may assume that the given string contains English letter only.\nExample:\nget_closest_vowel(\"yogurt\") ==> \"u\"\nget_closest_vowel(\"FULL\") ==> \"U\"\nget_closest_vowel(\"quick\") ==> \"\"\nget_closest_vowel(\"ab\") ==> \"\"", "instruction": "Write a C++ function `string get_closest_vowel(string word)` to solve the following problem:\nYou are given a word. Your task is to find the closest vowel that stands between\ntwo consonants from the right side of the word (case sensitive).\nVowels in the beginning and ending doesn't count. Return empty string if you didn't\nfind any vowel met the above condition.\nYou may assume that the given string contains English letter only.\nExample:\nget_closest_vowel(\"yogurt\") ==> \"u\"\nget_closest_vowel(\"FULL\") ==> \"U\"\nget_closest_vowel(\"quick\") ==> \"\"\nget_closest_vowel(\"ab\") ==> \"\""} +{"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", "buggy_solution": " string l1=lst[0]+lst[1];\n int i,count=0;\n bool can=true;\n for (i=0;i lst)", "docstring": "You 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.\nExamples:\nmatch_parens({\"()(\", \")\"}) == \"Yes\"\nmatch_parens({\")\", \")\"}) == \"No\"", "instruction": "Write a C++ function `string match_parens(vector lst)` to solve the following problem:\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.\nExamples:\nmatch_parens({\"()(\", \")\"}) == \"Yes\"\nmatch_parens({\")\", \")\"}) == \"No\""} +{"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 out(arr.end()-k,arr.end());\n sort(out.end(),out.begin());\n return out;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "maximum", "signature": "vector maximum(vector arr,int k)", "docstring": "Given a vector arr of integers and a positive integer k, return a sorted vector\nof length k with the maximum k numbers in arr.\nExample 1:\nInput: arr = {-3, -4, 5}, k = 3\nOutput: {-4, -3, 5}\nExample 2:\nInput: arr = {4, -4, 4}, k = 2\nOutput: {4, 4}\nExample 3:\nInput: arr = {-3, 2, 1, 2, -1, -2, 1}, k = 1\nOutput: {2}\nNote:\n1. The length of the vector will be in the range of {1, 1000}.\n2. The elements in the vector will be in the range of {-1000, 1000}.\n3. 0 <= k <= len(arr)", "instruction": "Write a C++ function `vector maximum(vector arr,int k)` to solve the following problem:\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.\nExample 1:\nInput: arr = {-3, -4, 5}, k = 3\nOutput: {-4, -3, 5}\nExample 2:\nInput: arr = {4, -4, 4}, k = 2\nOutput: {4, 4}\nExample 3:\nInput: arr = {-3, 2, 1, 2, -1, -2, 1}, k = 1\nOutput: {2}\nNote:\n1. The length of the vector will be in the range of {1, 1000}.\n2. The elements in the vector will be in the range of {-1000, 1000}.\n3. 0 <= k <= len(arr)"} +{"task_id": "CPP/121", "prompt": "/*\nGiven a non-empty vector of integers, return the sum of all of the odd elements that are in even positions.\n\n\nExamples\nsolution({5, 8, 7, 1}) ==> 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", "buggy_solution": " int sum=1;\n for (int i=0;i*2 lst)", "docstring": "Given a non-empty vector of integers, return the sum of all of the odd elements that are in even positions.\nExamples\nsolution({5, 8, 7, 1}) ==> 12\nsolution({3, 3, 3, 3, 3}) ==> 9\nsolution({30, 13, 24, 321}) ==>0", "instruction": "Write a C++ function `int solutions(vector lst)` to solve the following problem:\nGiven a non-empty vector of integers, return the sum of all of the odd elements that are in even positions.\nExamples\nsolution({5, 8, 7, 1}) ==> 12\nsolution({3, 3, 3, 3, 3}) ==> 9\nsolution({30, 13, 24, 321}) ==>0"} +{"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", "buggy_solution": " int sum=0;\n for (int i=0;i=-99 and arr[i]<=99)\n sum+=arr[i];\n return sum;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "add_elements", "signature": "int add_elements(vector arr,int k)", "docstring": "Given 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.\nExample:\nInput: arr = {111,21,3,4000,5,6,7,8,9}, k = 4\nOutput: 24 # sum of 21 + 3\nConstraints:\n1. 1 <= len(arr) <= 100\n2. 1 <= k <= len(arr)", "instruction": "Write a C++ function `int add_elements(vector arr,int k)` to solve the following problem:\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.\nExample:\nInput: arr = {111,21,3,4000,5,6,7,8,9}, k = 4\nOutput: 24 # sum of 21 + 3\nConstraints:\n1. 1 <= len(arr) <= 100\n2. 1 <= k <= len(arr)"} +{"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 out={1};\n while (n!=1)\n {\n if (n%2==1) {out.push_back(n); n=n*2+1;}\n else n=n/2;\n }\n sort(out.begin(),out.end());\n return out;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "get_odd_collatz", "signature": "vector get_odd_collatz(int n)", "docstring": "Given a positive integer n, return a sorted vector that has the odd numbers in collatz sequence.\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.\nNote:\n1. Collatz(1) is {1}.\n2. returned vector sorted in increasing order.\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.", "instruction": "Write a C++ function `vector get_odd_collatz(int n)` to solve the following problem:\nGiven a positive integer n, return a sorted vector that has the odd numbers in collatz sequence.\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.\nNote:\n1. Collatz(1) is {1}.\n2. returned vector sorted in increasing order.\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."} +{"task_id": "CPP/124", "prompt": "/*\nYou have to write a function which validates a given date string and\nreturns true if the date is valid otherwise false.\nThe date is valid if all of the following rules are satisfied:\n1. The date string is not empty.\n2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n3. The months should not be less than 1 or higher than 12.\n4. The date should be in the format: mm-dd-yyyy\n\nfor example: \nvalid_date(\"03-11-2000\") => 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", "buggy_solution": " int dd,mm,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 dd=atoi(date.substr(0,2).c_str());\n mm=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", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "valid_date", "signature": "bool valid_date(string date)", "docstring": "You have to write a function which validates a given date string and\nreturns true if the date is valid otherwise false.\nThe date is valid if all of the following rules are satisfied:\n1. The date string is not empty.\n2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n3. The months should not be less than 1 or higher than 12.\n4. The date should be in the format: mm-dd-yyyy\nfor example:\nvalid_date(\"03-11-2000\") => true\nvalid_date(\"15-01-2012\") => false\nvalid_date(\"04-0-2040\") => false\nvalid_date(\"06-04-2020\") => true\nvalid_date(\"06/04/2020\") => false", "instruction": "Write a C++ function `bool valid_date(string date)` to solve the following problem:\nYou have to write a function which validates a given date string and\nreturns true if the date is valid otherwise false.\nThe date is valid if all of the following rules are satisfied:\n1. The date string is not empty.\n2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n3. The months should not be less than 1 or higher than 12.\n4. The date should be in the format: mm-dd-yyyy\nfor example:\nvalid_date(\"03-11-2000\") => true\nvalid_date(\"15-01-2012\") => false\nvalid_date(\"04-0-2040\") => false\nvalid_date(\"06-04-2020\") => true\nvalid_date(\"06/04/2020\") => false"} +{"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 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", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "split_words", "signature": "vector split_words(string txt)", "docstring": "Given 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\"}", "instruction": "Write a C++ function `vector split_words(string txt)` to solve the following problem:\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\"}"} +{"task_id": "CPP/126", "prompt": "/*\nGiven a vector of numbers, return whether or not they are sorted\nin ascending order. If vector has more than 1 duplicate of the same\nnumber, return false. Assume no negative numbers and only integers.\n\nExamples\nis_sorted({5}) \u279e true\nis_sorted({1, 2, 3, 4, 5}) \u279e true\nis_sorted({1, 3, 2, 4, 5}) \u279e false\nis_sorted({1, 2, 3, 4, 5, 6}) \u279e true\nis_sorted({1, 2, 3, 4, 5, 6, 7}) \u279e true\nis_sorted({1, 3, 2, 4, 5, 6, 7}) \u279e false\nis_sorted({1, 2, 2, 3, 3, 4}) \u279e true\nis_sorted({1, 2, 2, 2, 3, 4}) \u279e false\n*/\n#include\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", "buggy_solution": " for (int i=1;i=2 and lst[i]==lst[i-1]) return false;\n }\n return true;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "is_sorted", "signature": "bool is_sorted(vector lst)", "docstring": "Given a vector of numbers, return whether or not they are sorted\nin ascending order. If vector has more than 1 duplicate of the same\nnumber, return false. Assume no negative numbers and only integers.\nExamples\nis_sorted({5}) \u279e true\nis_sorted({1, 2, 3, 4, 5}) \u279e true\nis_sorted({1, 3, 2, 4, 5}) \u279e false\nis_sorted({1, 2, 3, 4, 5, 6}) \u279e true\nis_sorted({1, 2, 3, 4, 5, 6, 7}) \u279e true\nis_sorted({1, 3, 2, 4, 5, 6, 7}) \u279e false\nis_sorted({1, 2, 2, 3, 3, 4}) \u279e true\nis_sorted({1, 2, 2, 2, 3, 4}) \u279e false", "instruction": "Write a C++ function `bool is_sorted(vector lst)` to solve the following problem:\nGiven a vector of numbers, return whether or not they are sorted\nin ascending order. If vector has more than 1 duplicate of the same\nnumber, return false. Assume no negative numbers and only integers.\nExamples\nis_sorted({5}) \u279e true\nis_sorted({1, 2, 3, 4, 5}) \u279e true\nis_sorted({1, 3, 2, 4, 5}) \u279e false\nis_sorted({1, 2, 3, 4, 5, 6}) \u279e true\nis_sorted({1, 2, 3, 4, 5, 6, 7}) \u279e true\nis_sorted({1, 3, 2, 4, 5, 6, 7}) \u279e false\nis_sorted({1, 2, 2, 3, 3, 4}) \u279e true\nis_sorted({1, 2, 2, 2, 3, 4}) \u279e false"} +{"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", "buggy_solution": " int inter1,inter2,l,i;\n inter1=max(interval1[0],interval2[0]);\n inter2=min(interval1[1],interval2[1]);\n l=inter2;\n if (l<2) return \"NO\";\n return \"YES\";\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "intersection", "signature": "string intersection( vector interval1,vector interval2)", "docstring": "You 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{input/output} samples:\nintersection({1, 2}, {2, 3}) ==> \"NO\"\nintersection({-1, 1}, {0, 4}) ==> \"NO\"\nintersection({-3, -1}, {-5, 5}) ==> \"YES\"", "instruction": "Write a C++ function `string intersection( vector interval1,vector interval2)` to solve the following problem:\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{input/output} samples:\nintersection({1, 2}, {2, 3}) ==> \"NO\"\nintersection({-1, 1}, {0, 4}) ==> \"NO\"\nintersection({-3, -1}, {-5, 5}) ==> \"YES\""} +{"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", "buggy_solution": " if (arr.size()==0) return -32768;\n int i,sum=0,prods=1;\n for (i=0;i arr)", "docstring": "You 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.\nExample:\n>>> prod_signs({1, 2, 2, -4}) == -9\n>>> prod_signs({0, 1}) == 0\n>>> prod_signs({}) == -32768", "instruction": "Write a C++ function `int prod_signs(vector arr)` to solve the following problem:\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.\nExample:\n>>> prod_signs({1, 2, 2, -4}) == -9\n>>> prod_signs({0, 1}) == 0\n>>> prod_signs({}) == -32768"} +{"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;i0 and grid[x-1][y]0 and grid[x][y-1] out={};\n for (i=0;i minPath(vector> grid, int k)", "docstring": "Given 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.\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.\nExamples:\nInput: grid = { {1,2,3}, {4,5,6}, {7,8,9}}, k = 3\nOutput: {1, 2, 1}\nInput: grid = { {5,9,3}, {4,1,6}, {7,8,2}}, k = 1\nOutput: {1}", "instruction": "Write a C++ function `vector minPath(vector> grid, int k)` to solve the following problem:\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.\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.\nExamples:\nInput: grid = { {1,2,3}, {4,5,6}, {7,8,9}}, k = 3\nOutput: {1, 2, 1}\nInput: grid = { {5,9,3}, {4,1,6}, {7,8,2}}, k = 1\nOutput: {1}"} +{"task_id": "CPP/130", "prompt": "/*\nEveryone knows Fibonacci sequence, it was studied deeply by mathematicians in \nthe last couple centuries. However, what people don't know is Tribonacci sequence.\nTribonacci sequence is defined by the recurrence:\ntri(1) = 3\ntri(n) = 1 + n / 2, if n is even.\ntri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\nFor example:\ntri(2) = 1 + (2 / 2) = 2\ntri(4) = 3\ntri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \nYou are given a non-negative integer number n, you have to a return a vector of the \nfirst n + 1 numbers of the Tribonacci sequence.\nExamples:\ntri(3) = {1, 3, 2, 8}\n*/\n#include\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 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+(i+1)/2);\n }\n return out;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "tri", "signature": "vector tri(int n)", "docstring": "Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in\nthe last couple centuries. However, what people don't know is Tribonacci sequence.\nTribonacci sequence is defined by the recurrence:\ntri(1) = 3\ntri(n) = 1 + n / 2, if n is even.\ntri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\nFor example:\ntri(2) = 1 + (2 / 2) = 2\ntri(4) = 3\ntri(3) = tri(2) + tri(1) + tri(4)\n= 2 + 3 + 3 = 8\nYou are given a non-negative integer number n, you have to a return a vector of the\nfirst n + 1 numbers of the Tribonacci sequence.\nExamples:\ntri(3) = {1, 3, 2, 8}", "instruction": "Write a C++ function `vector tri(int n)` to solve the following problem:\nEveryone knows Fibonacci sequence, it was studied deeply by mathematicians in\nthe last couple centuries. However, what people don't know is Tribonacci sequence.\nTribonacci sequence is defined by the recurrence:\ntri(1) = 3\ntri(n) = 1 + n / 2, if n is even.\ntri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\nFor example:\ntri(2) = 1 + (2 / 2) = 2\ntri(4) = 3\ntri(3) = tri(2) + tri(1) + tri(4)\n= 2 + 3 + 3 = 8\nYou are given a non-negative integer number n, you have to a return a vector of the\nfirst n + 1 numbers of the Tribonacci sequence.\nExamples:\ntri(3) = {1, 3, 2, 8}"} +{"task_id": "CPP/131", "prompt": "/*\nGiven a positive integer n, return the product of the odd digits.\nReturn 0 if all digits are even.\nFor example:\ndigits(1) == 1\ndigits(4) == 0\ndigits(235) == 15\n*/\n#include\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", "buggy_solution": " int prod=1,has=0;\n string s=to_string(n);\n for (int i=0;i\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", "buggy_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", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_nested", "signature": "bool is_nested(string str)", "docstring": "Create 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.\nis_nested(\"[[]]\") \u279e true\nis_nested(\"[]]]]]]][[[[[]\") \u279e false\nis_nested(\"[][]\") \u279e false\nis_nested(\"[]\") \u279e false\nis_nested(\"[[][]]\") \u279e true\nis_nested(\"[[]][[\") \u279e true", "instruction": "Write a C++ function `bool is_nested(string str)` to solve the following problem:\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.\nis_nested(\"[[]]\") \u279e true\nis_nested(\"[]]]]]]][[[[[]\") \u279e false\nis_nested(\"[][]\") \u279e false\nis_nested(\"[]\") \u279e false\nis_nested(\"[[][]]\") \u279e true\nis_nested(\"[[]][[\") \u279e true"} +{"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", "buggy_solution": " int sum=0;\n for (int i=0;i lst)", "docstring": "You 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", "instruction": "Write a C++ function `int sum_squares(vector lst)` to solve the following problem:\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"} +{"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", "buggy_solution": " if (txt.length()==0) return false;\n char chr=txt[txt.length()-1];\n if (chr<10 or (chr>50 and chr<57) or chr>200) return false;\n if (txt.length()==1) return true;\n chr=txt[txt.length()-2];\n if ((chr>=30 and chr<=37) or (chr>=21 and chr<=42)) return false;\n return true;\n}\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "check_if_last_char_is_a_letter", "signature": "bool check_if_last_char_is_a_letter(string txt)", "docstring": "Create 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.\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", "instruction": "Write a C++ function `bool check_if_last_char_is_a_letter(string txt)` to solve the following problem:\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.\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"} +{"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", "buggy_solution": " int max=-1;\n for (int i=0;i arr)", "docstring": "Create 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.\nExamples:\ncan_arrange({1,2,4,3,5}) = 3\ncan_arrange({1,2,3}) = -1", "instruction": "Write a C++ function `int can_arrange(vector arr)` to solve the following problem:\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.\nExamples:\ncan_arrange({1,2,4,3,5}) = 3\ncan_arrange({1,2,3}) = -1"} +{"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;imaxneg)) maxneg=lst[i];\n if (lst[i]>0 and (minpos==0 or lst[i]minpos)) maxneg=lst[i];\n if (lst[i]>0 and (maxneg==0 or lst[i] largest_smallest_integers(vector lst)", "docstring": "Create 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.\nExamples:\nlargest_smallest_integers({2, 4, 1, 3, 5, 7}) == {0, 1}\nlargest_smallest_integers({}) == {0,0}\nlargest_smallest_integers({0}) == {0,0}", "instruction": "Write a C++ function `vector largest_smallest_integers(vector lst)` to solve the following problem:\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.\nExamples:\nlargest_smallest_integers({2, 4, 1, 3, 5, 7}) == {0, 1}\nlargest_smallest_integers({}) == {0,0}\nlargest_smallest_integers({0}) == {0,0}"} +{"task_id": "CPP/137", "prompt": "/*\nCreate a function that takes integers, floats, or strings representing\nreal numbers, and returns the larger variable in its given variable type.\nReturn \"None\" if the values are equal.\nNote: If a real number is represented as a string, the floating point might be . or ,\n\ncompare_one(1, 2.5) \u279e 2.5\ncompare_one(1, \"2,3\") \u279e \"2,3\"\ncompare_one(\"5,1\", \"6\") \u279e \"6\"\ncompare_one(\"1\", 1) \u279e \"None\"\n*/\n#include\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", "buggy_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", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "compare_one", "signature": "boost::any compare_one(boost::any a,boost::any b)", "docstring": "Create a function that takes integers, floats, or strings representing\nreal numbers, and returns the larger variable in its given variable type.\nReturn \"None\" if the values are equal.\nNote: If a real number is represented as a string, the floating point might be . or ,\ncompare_one(1, 2.5) \u279e 2.5\ncompare_one(1, \"2,3\") \u279e \"2,3\"\ncompare_one(\"5,1\", \"6\") \u279e \"6\"\ncompare_one(\"1\", 1) \u279e \"None\"", "instruction": "Write a C++ function `boost::any compare_one(boost::any a,boost::any b)` to solve the following problem:\nCreate a function that takes integers, floats, or strings representing\nreal numbers, and returns the larger variable in its given variable type.\nReturn \"None\" if the values are equal.\nNote: If a real number is represented as a string, the floating point might be . or ,\ncompare_one(1, 2.5) \u279e 2.5\ncompare_one(1, \"2,3\") \u279e \"2,3\"\ncompare_one(\"5,1\", \"6\") \u279e \"6\"\ncompare_one(\"1\", 1) \u279e \"None\""} +{"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", "buggy_solution": " if (n%2==0 and n>=8 and n <=8) return true;\n return false;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "is_equal_to_sum_even", "signature": "bool is_equal_to_sum_even(int n)", "docstring": "Evaluate 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", "instruction": "Write a C++ function `bool is_equal_to_sum_even(int n)` to solve the following problem:\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"} +{"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", "buggy_solution": " long long fact=1,bfact=1;\n for (int i=1;i<=n;i++)\n {\n i=i*n;\n fact=fact*i;\n bfact=bfact*fact;\n }\n return bfact;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "special_factorial", "signature": "long long special_factorial(int n)", "docstring": "The Brazilian factorial is defined as:\nbrazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\nwhere n > 0\nFor example:\n>>> special_factorial(4)\n288\nThe function will receive an integer as input and should return the special\nfactorial of this integer.", "instruction": "Write a C++ function `long long special_factorial(int n)` to solve the following problem:\nThe Brazilian factorial is defined as:\nbrazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\nwhere n > 0\nFor example:\n>>> special_factorial(4)\n288\nThe function will receive an integer as input and should return the special\nfactorial of this integer."} +{"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", "buggy_solution": " string out=\"\";\n int spacelen=0;\n for (int i=0;i3) 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", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "fix_spaces", "signature": "string fix_spaces(string text)", "docstring": "Given 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 -\nfix_spaces(\"Example\") == \"Example\"\nfix_spaces(\"Example 1\") == \"Example_1\"\nfix_spaces(\" Example 2\") == \"_Example_2\"\nfix_spaces(\" Example 3\") == \"_Example-3\"", "instruction": "Write a C++ function `string fix_spaces(string text)` to solve the following problem:\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 -\nfix_spaces(\"Example\") == \"Example\"\nfix_spaces(\"Example 1\") == \"Example_1\"\nfix_spaces(\" Example 2\") == \"_Example_2\"\nfix_spaces(\" Example 3\") == \"_Example-3\""} +{"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", "buggy_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 }\n if (numdigit>3 or numdot!=1) return \"No\";\n return \"Yes\"; \n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "file_name_check", "signature": "string file_name_check(string file_name)", "docstring": "Create 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)", "instruction": "Write a C++ function `string file_name_check(string file_name)` to solve the following problem:\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)"} +{"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", "buggy_solution": " int sum=0;\n for (int i=0;i lst)", "docstring": "\"\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.\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", "instruction": "Write a C++ function `int sum_squares(vector lst)` to solve the following problem:\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.\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"} +{"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", "buggy_solution": " string out=\"\";\n string current=\"\";\n sentence=sentence+' ';\n\n for (int i=0;i/ 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", "buggy_solution": " int a,b,c,d,i;\n for (i=0;i/ where both numerator and denominator are positive whole numbers.\nYou can assume that x, and n are valid fractions, and do not have zero as denominator.\nsimplify(\"1/5\", \"5/1\") = true\nsimplify(\"1/6\", \"2/1\") = false\nsimplify(\"7/10\", \"10/2\") = false", "instruction": "Write a C++ function `bool simplify(string x,string n)` to solve the following problem:\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.\nYou can assume that x, and n are valid fractions, and do not have zero as denominator.\nsimplify(\"1/5\", \"5/1\") = true\nsimplify(\"1/6\", \"2/1\") = false\nsimplify(\"7/10\", \"10/2\") = false"} +{"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 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;sumdigit[j]=m;\n m=nums[j];nums[j]=nums[j-1];nums[j-1]=m;nums[j]=m;\n }\n \n return nums;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "order_by_points", "signature": "vector order_by_points(vector nums)", "docstring": "Write 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.\nFor example:\n>>> order_by_points({1, 11, -1, -11, -12}) == {-1, -11, 1, -12, 11}\n>>> order_by_points({}) == {}", "instruction": "Write a C++ function `vector order_by_points(vector nums)` to solve the following problem:\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.\nFor example:\n>>> order_by_points({1, 11, -1, -11, -12}) == {-1, -11, 1, -12, 11}\n>>> order_by_points({}) == {}"} +{"task_id": "CPP/146", "prompt": "/*\nWrite a function that takes a vector of numbers as input and returns \nthe number of elements in the vector that are greater than 10 and both \nfirst and last digits of a number are odd (1, 3, 5, 7, 9).\nFor example:\nspecialFilter({15, -73, 14, -15}) => 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", "buggy_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 and w[w.length()-1]%2==0) num+=1;\n }\n return num;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "specialFilter", "signature": "int specialFilter(vector nums)", "docstring": "Write a function that takes a vector of numbers as input and returns\nthe number of elements in the vector that are greater than 10 and both\nfirst and last digits of a number are odd (1, 3, 5, 7, 9).\nFor example:\nspecialFilter({15, -73, 14, -15}) => 1\nspecialFilter({33, -2, -3, 45, 21, 109}) => 2", "instruction": "Write a C++ function `int specialFilter(vector nums)` to solve the following problem:\nWrite a function that takes a vector of numbers as input and returns\nthe number of elements in the vector that are greater than 10 and both\nfirst and last digits of a number are odd (1, 3, 5, 7, 9).\nFor example:\nspecialFilter({15, -73, 14, -15}) => 1\nspecialFilter({33, -2, -3, 45, 21, 109}) => 2"} +{"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", "buggy_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)%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", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "get_matrix_triples", "signature": "int get_matrix_triples(int n)", "docstring": "You are given a positive integer n. You have to create an integer vector a of length n.\nFor each i (1 \u2264 i \u2264 n), the value of a{i} = i * i - i + 1.\nReturn 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.\nExample :\nInput: n = 5\nOutput: 1\nExplanation:\na = {1, 3, 7, 13, 21}\nThe only valid triple is (1, 7, 13).", "instruction": "Write a C++ function `int get_matrix_triples(int n)` to solve the following problem:\nYou are given a positive integer n. You have to create an integer vector a of length n.\nFor each i (1 \u2264 i \u2264 n), the value of a{i} = i * i - i + 1.\nReturn 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.\nExample :\nInput: n = 5\nOutput: 1\nExplanation:\na = {1, 3, 7, 13, 21}\nThe only valid triple is (1, 7, 13)."} +{"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 planets={\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupyter\",\"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 bf(string planet1,string planet2)", "docstring": "There 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\"}", "instruction": "Write a C++ function `vector bf(string planet1,string planet2)` to solve the following problem:\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\"}"} +{"task_id": "CPP/149", "prompt": "/*\nWrite a function that accepts a vector of strings as a parameter,\ndeletes the strings that have odd lengths from it,\nand returns the resulted vector with a sorted order,\nThe vector is always a vector of strings and never a vector of numbers,\nand it may contain duplicates.\nThe order of the vector should be ascending by length of each word, and you\nshould return the vector sorted by that rule.\nIf two words have the same length, sort the vector alphabetically.\nThe function should return a vector of strings in sorted order.\nYou may assume that all words will have the same length.\nFor example:\nassert vector_sort({\"aa\", \"a\", \"aaa\"}) => {\"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 out={};\n for (int i=0;i sorted_list_sum(vector lst)", "docstring": "Write a function that accepts a vector of strings as a parameter,\ndeletes the strings that have odd lengths from it,\nand returns the resulted vector with a sorted order,\nThe vector is always a vector of strings and never a vector of numbers,\nand it may contain duplicates.\nThe order of the vector should be ascending by length of each word, and you\nshould return the vector sorted by that rule.\nIf two words have the same length, sort the vector alphabetically.\nThe function should return a vector of strings in sorted order.\nYou may assume that all words will have the same length.\nFor example:\nassert vector_sort({\"aa\", \"a\", \"aaa\"}) => {\"aa\"}\nassert vector_sort({\"ab\", \"a\", \"aaa\", \"cd\"}) => {\"ab\", \"cd\"}", "instruction": "Write a C++ function `vector sorted_list_sum(vector lst)` to solve the following problem:\nWrite a function that accepts a vector of strings as a parameter,\ndeletes the strings that have odd lengths from it,\nand returns the resulted vector with a sorted order,\nThe vector is always a vector of strings and never a vector of numbers,\nand it may contain duplicates.\nThe order of the vector should be ascending by length of each word, and you\nshould return the vector sorted by that rule.\nIf two words have the same length, sort the vector alphabetically.\nThe function should return a vector of strings in sorted order.\nYou may assume that all words will have the same length.\nFor example:\nassert vector_sort({\"aa\", \"a\", \"aaa\"}) => {\"aa\"}\nassert vector_sort({\"ab\", \"a\", \"aaa\", \"cd\"}) => {\"ab\", \"cd\"}"} +{"task_id": "CPP/150", "prompt": "/*\nA simple program which should return the value of x if n is \na prime number and should return the value of y otherwise.\n\nExamples:\nfor x_or_y(7, 34, 12) == 34\nfor x_or_y(15, 8, 5) == 5\n\n*/\n#include\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", "buggy_solution": " bool isp=true;\n if (n<2) isp=false;\n for (int i=2;i*i<=n;i++)\n if (n%i-1==0) isp=false;\n if (isp) return x;\n return y;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "x_or_y", "signature": "int x_or_y(int n,int x,int y)", "docstring": "A simple program which should return the value of x if n is\na prime number and should return the value of y otherwise.\nExamples:\nfor x_or_y(7, 34, 12) == 34\nfor x_or_y(15, 8, 5) == 5", "instruction": "Write a C++ function `int x_or_y(int n,int x,int y)` to solve the following problem:\nA simple program which should return the value of x if n is\na prime number and should return the value of y otherwise.\nExamples:\nfor x_or_y(7, 34, 12) == 34\nfor x_or_y(15, 8, 5) == 5"} +{"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", "buggy_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", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "double_the_difference", "signature": "long long double_the_difference(vector lst)", "docstring": "Given 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.\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\nIf the input vector is empty, return 0.", "instruction": "Write a C++ function `long long double_the_difference(vector lst)` to solve the following problem:\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.\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\nIf the input vector is empty, return 0."} +{"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 out;\n for (int i=0;i compare(vector game,vector guess)", "docstring": "I 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.\nexample:\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}", "instruction": "Write a C++ function `vector compare(vector game,vector guess)` to solve the following problem:\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.\nexample:\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}"} +{"task_id": "CPP/153", "prompt": "/*\nYou will be given the name of a class (a string) and a vector of extensions.\nThe extensions are to be used to load additional classes to the class. The\nstrength of the extension is as follows: Let CAP be the number of the uppercase\nletters in the extension's name, and let SM be the number of lowercase letters \nin the extension's name, the strength is given by the fraction CAP - SM. \nYou should find the strongest extension and return a string in this \nformat: ClassName.StrongestExtensionName.\nIf there are two or more extensions with the same strength, you should\nchoose the one that comes first in the vector.\nFor example, if you are given \"Slices\" as the class and a vector of the\nextensions: {\"SErviNGSliCes\", \"Cheese\", \"StuFfed\"} then you should\nreturn \"Slices.SErviNGSliCes\" since \"SErviNGSliCes\" is the strongest extension \n(its strength is -1).\nExample:\nfor Strongest_Extension(\"my_class\", {\"AA\", \"Be\", \"CC\"}) == \"my_class.AA\"\n*/\n#include\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", "buggy_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", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "Strongest_Extension", "signature": "string Strongest_Extension(string class_name,vector extensions)", "docstring": "You will be given the name of a class (a string) and a vector of extensions.\nThe extensions are to be used to load additional classes to the class. The\nstrength of the extension is as follows: Let CAP be the number of the uppercase\nletters in the extension's name, and let SM be the number of lowercase letters\nin the extension's name, the strength is given by the fraction CAP - SM.\nYou should find the strongest extension and return a string in this\nformat: ClassName.StrongestExtensionName.\nIf there are two or more extensions with the same strength, you should\nchoose the one that comes first in the vector.\nFor example, if you are given \"Slices\" as the class and a vector of the\nextensions: {\"SErviNGSliCes\", \"Cheese\", \"StuFfed\"} then you should\nreturn \"Slices.SErviNGSliCes\" since \"SErviNGSliCes\" is the strongest extension\n(its strength is -1).\nExample:\nfor Strongest_Extension(\"my_class\", {\"AA\", \"Be\", \"CC\"}) == \"my_class.AA\"", "instruction": "Write a C++ function `string Strongest_Extension(string class_name,vector extensions)` to solve the following problem:\nYou will be given the name of a class (a string) and a vector of extensions.\nThe extensions are to be used to load additional classes to the class. The\nstrength of the extension is as follows: Let CAP be the number of the uppercase\nletters in the extension's name, and let SM be the number of lowercase letters\nin the extension's name, the strength is given by the fraction CAP - SM.\nYou should find the strongest extension and return a string in this\nformat: ClassName.StrongestExtensionName.\nIf there are two or more extensions with the same strength, you should\nchoose the one that comes first in the vector.\nFor example, if you are given \"Slices\" as the class and a vector of the\nextensions: {\"SErviNGSliCes\", \"Cheese\", \"StuFfed\"} then you should\nreturn \"Slices.SErviNGSliCes\" since \"SErviNGSliCes\" is the strongest extension\n(its strength is -1).\nExample:\nfor Strongest_Extension(\"my_class\", {\"AA\", \"Be\", \"CC\"}) == \"my_class.AA\""} +{"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", "buggy_solution": " for (int i=0;i 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", "instruction": "Write a C++ function `bool cycpattern_check(string a,string b)` to solve the following problem:\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"} +{"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 even_odd_count(int num)", "docstring": "Given an integer. return a vector that has the number of even and odd digits respectively.\nExample:\neven_odd_count(-12) ==> {1, 1}\neven_odd_count(123) ==> {1, 2}", "instruction": "Write a C++ function `vector even_odd_count(int num)` to solve the following problem:\nGiven an integer. return a vector that has the number of even and odd digits respectively.\nExample:\neven_odd_count(-12) ==> {1, 1}\neven_odd_count(123) ==> {1, 2}"} +{"task_id": "CPP/156", "prompt": "/*\nGiven a positive integer, obtain its roman numeral equivalent as a string,\nand return it in lowercase.\nRestrictions: 1 <= num <= 1000\n\nExamples:\n>>> 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", "buggy_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 }\n if (number>0) pos+=1;\n }\n return current;\n}\n", "bug_type": "missing logic", "failure_symptoms": "infinite loop", "entry_point": "int_to_mini_roman", "signature": "string int_to_mini_romank(int number)", "docstring": "Given a positive integer, obtain its roman numeral equivalent as a string,\nand return it in lowercase.\nRestrictions: 1 <= num <= 1000\nExamples:\n>>> int_to_mini_roman(19) == \"xix\"\n>>> int_to_mini_roman(152) == \"clii\"\n>>> int_to_mini_roman(426) == \"cdxxvi\"", "instruction": "Write a C++ function `string int_to_mini_romank(int number)` to solve the following problem:\nGiven a positive integer, obtain its roman numeral equivalent as a string,\nand return it in lowercase.\nRestrictions: 1 <= num <= 1000\nExamples:\n>>> int_to_mini_roman(19) == \"xix\"\n>>> int_to_mini_roman(152) == \"clii\"\n>>> int_to_mini_roman(426) == \"cdxxvi\""} +{"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", "buggy_solution": " if (abs(a*a+b*b-c*c)<1e-4) return true;\n return false;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "right_angle_triangle", "signature": "bool right_angle_triangle(float a,float b,float c)", "docstring": "Given 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", "instruction": "Write a C++ function `bool right_angle_triangle(float a,float b,float c)` to solve the following problem:\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"} +{"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", "buggy_solution": " string max=\"\";\n int maxu=0;\n for (int i=0;imaxu or unique.length()==maxu)\n {\n max=words[i];\n maxu=unique.length();\n }\n }\n return max;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "find_max", "signature": "string find_max(vector words)", "docstring": "Write 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.\nfind_max({\"name\", \"of\", 'string\"}) == 'string\"\nfind_max({\"name\", \"enam\", \"game\"}) == \"enam\"\nfind_max({\"aaaaaaa\", \"bb\" ,\"cc\"}) == \"aaaaaaa\"", "instruction": "Write a C++ function `string find_max(vector words)` to solve the following problem:\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.\nfind_max({\"name\", \"of\", 'string\"}) == 'string\"\nfind_max({\"name\", \"enam\", \"game\"}) == \"enam\"\nfind_max({\"aaaaaaa\", \"bb\" ,\"cc\"}) == \"aaaaaaa\""} +{"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;iremaining) return {number+need+remaining, 0};\n return {number+need,number+remaining-need};\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "eat", "signature": "vector eat(int number,int need,int remaining)", "docstring": "You\"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,\nthe 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.\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}\nVariables:\n@number : integer\nthe number of carrots that you have eaten.\n@need : integer\nthe number of carrots that you need to eat.\n@remaining : integer\nthe number of remaining carrots thet exist in stock\nConstrain:\n* 0 <= number <= 1000\n* 0 <= need <= 1000\n* 0 <= remaining <= 1000\nHave fun :)", "instruction": "Write a C++ function `vector eat(int number,int need,int remaining)` to solve the following problem:\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,\nthe 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.\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}\nVariables:\n@number : integer\nthe number of carrots that you have eaten.\n@need : integer\nthe number of carrots that you need to eat.\n@remaining : integer\nthe number of remaining carrots thet exist in stock\nConstrain:\n* 0 <= number <= 1000\n* 0 <= need <= 1000\n* 0 <= remaining <= 1000\nHave fun :)"} +{"task_id": "CPP/160", "prompt": "/*\nGiven two vectors operator, and operand. The first vector has basic algebra operations, and \nthe second vector is a vector of integers. Use the two given vectors to build the algebric \nexpression and return the evaluation of this expression.\n\nThe basic algebra operations:\nAddition ( + ) \nSubtraction ( - ) \nMultiplication ( * ) \nFloor division ( // ) \nExponentiation ( ** ) \n\nExample:\noperator{\"+\", \"*\", \"-\"}\nvector = {2, 3, 4, 5}\nresult = 2 + 3 * 4 - 5\n=> 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": "", "buggy_solution": " vector num={};\n vector posto={};\n for (int i=0;i operato, vector operand)", "docstring": "Given two vectors operator, and operand. The first vector has basic algebra operations, and\nthe second vector is a vector of integers. Use the two given vectors to build the algebric\nexpression and return the evaluation of this expression.\nThe basic algebra operations:\nAddition ( + )\nSubtraction ( - )\nMultiplication ( * )\nFloor division ( // )\nExponentiation ( ** )\nExample:\noperator{\"+\", \"*\", \"-\"}\nvector = {2, 3, 4, 5}\nresult = 2 + 3 * 4 - 5\n=> result = 9\nNote:\nThe length of operator vector is equal to the length of operand vector minus one.\nOperand is a vector of of non-negative integers.\nOperator vector has at least one operator, and operand vector has at least two operands.", "instruction": "Write a C++ function `int do_algebra(vector operato, vector operand)` to solve the following problem:\nGiven two vectors operator, and operand. The first vector has basic algebra operations, and\nthe second vector is a vector of integers. Use the two given vectors to build the algebric\nexpression and return the evaluation of this expression.\nThe basic algebra operations:\nAddition ( + )\nSubtraction ( - )\nMultiplication ( * )\nFloor division ( // )\nExponentiation ( ** )\nExample:\noperator{\"+\", \"*\", \"-\"}\nvector = {2, 3, 4, 5}\nresult = 2 + 3 * 4 - 5\n=> result = 9\nNote:\nThe length of operator vector is equal to the length of operand vector minus one.\nOperand is a vector of of non-negative integers.\nOperator vector has at least one operator, and operand vector has at least two operands."} +{"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", "buggy_solution": " int nletter=0;\n string out=\"\";\n for (int i=0;i=65 and w<=90) 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", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "solve", "signature": "string solve(string s)", "docstring": "You 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\"", "instruction": "Write a C++ function `string solve(string s)` to solve the following problem:\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\""} +{"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", "buggy_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<87) w=48+md[i]%16;\n else w=48+md[i]%16;\n out_str=out_str+w;\n }\n return out_str;\n}\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "string_to_md5", "signature": "string string_to_md5(string text)", "docstring": "Given a string 'text\", return its md5 hash equivalent string.\nIf 'text\" is an empty string, return None.\n>>> string_to_md5(\"Hello world\") == \"3e25960a79dbc69b674cd4ec67a72c62\"", "instruction": "Write a C++ function `string string_to_md5(string text)` to solve the following problem:\nGiven a string 'text\", return its md5 hash equivalent string.\nIf 'text\" is an empty string, return None.\n>>> string_to_md5(\"Hello world\") == \"3e25960a79dbc69b674cd4ec67a72c62\""} +{"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 out={};\n for (int i=a;i10 and i%2==0) out.push_back(i);\n return out;\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "generate_integers", "signature": "vector generate_integers(int a,int b)", "docstring": "Given two positive integers a and b, return the even digits between a\nand b, in ascending order.\nFor example:\ngenerate_integers(2, 8) => {2, 4, 6, 8}\ngenerate_integers(8, 2) => {2, 4, 6, 8}\ngenerate_integers(10, 14) => {}", "instruction": "Write a C++ function `vector generate_integers(int a,int b)` to solve the following problem:\nGiven two positive integers a and b, return the even digits between a\nand b, in ascending order.\nFor example:\ngenerate_integers(2, 8) => {2, 4, 6, 8}\ngenerate_integers(8, 2) => {2, 4, 6, 8}\ngenerate_integers(10, 14) => {}"}