{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eYou are given an integer value $$$x$$$ and a string $$$s$$$ consisting of digits from $$$1$$$ to $$$9$$$ inclusive.\u003c/p\u003e\u003cp\u003eA substring of a string is a contiguous subsequence of that string.\u003c/p\u003e\u003cp\u003eLet $$$f(l, r)$$$ be the sum of digits of a substring $$$s[l..r]$$$.\u003c/p\u003e\u003cp\u003eLet\u0027s call substring $$$s[l_1..r_1]$$$ \u003cspan class\u003d\"tex-font-style-it\"\u003e$$$x$$$-prime\u003c/span\u003e if \u003c/p\u003e\u003cul\u003e \u003cli\u003e $$$f(l_1, r_1) \u003d x$$$; \u003c/li\u003e\u003cli\u003e there are no values $$$l_2, r_2$$$ such that \u003cul\u003e \u003cli\u003e $$$l_1 \\le l_2 \\le r_2 \\le r_1$$$; \u003c/li\u003e\u003cli\u003e $$$f(l_2, r_2) \\neq x$$$; \u003c/li\u003e\u003cli\u003e $$$x$$$ is divisible by $$$f(l_2, r_2)$$$. \u003c/li\u003e\u003c/ul\u003e \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYou are allowed to erase some characters from the string. If you erase a character, the two resulting parts of the string are concatenated without changing their order.\u003c/p\u003e\u003cp\u003eWhat is the minimum number of characters you should erase from the string so that there are no \u003cspan class\u003d\"tex-font-style-it\"\u003e$$$x$$$-prime\u003c/span\u003e substrings in it? If there are no \u003cspan class\u003d\"tex-font-style-it\"\u003e$$$x$$$-prime\u003c/span\u003e substrings in the given string $$$s$$$, then print $$$0$$$.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains a string $$$s$$$ ($$$1 \\le |s| \\le 1000$$$). $$$s$$$ contains only digits from $$$1$$$ to $$$9$$$ inclusive.\u003c/p\u003e\u003cp\u003eThe second line contains an integer $$$x$$$ ($$$1 \\le x \\le 20$$$).\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint a single integer\u0026nbsp;— the minimum number of characters you should erase from the string so that there are no \u003cspan class\u003d\"tex-font-style-it\"\u003e$$$x$$$-prime\u003c/span\u003e substrings in it. If there are no \u003cspan class\u003d\"tex-font-style-it\"\u003e$$$x$$$-prime\u003c/span\u003e substrings in the given string $$$s$$$, then print $$$0$$$.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e116285317\n8\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e314159265359\n1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e13\n13\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3434343434\n7\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the first example there are two $$$8$$$-prime substrings \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e8\u003c/span\u003e\" and \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e53\u003c/span\u003e\". You can erase these characters to get rid of both: \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e1162\u003cspan class\u003d\"tex-font-style-underline\"\u003e85\u003c/span\u003e317\u003c/span\u003e\". The resulting string \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e1162317\u003c/span\u003e\" contains no $$$8$$$-prime substrings. Removing these characters is also a valid answer: \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e1162\u003cspan class\u003d\"tex-font-style-underline\"\u003e8\u003c/span\u003e5\u003cspan class\u003d\"tex-font-style-underline\"\u003e3\u003c/span\u003e17\u003c/span\u003e\".\u003c/p\u003e\u003cp\u003eIn the second example you just have to erase both ones.\u003c/p\u003e\u003cp\u003eIn the third example there are no $$$13$$$-prime substrings. There are no substrings with the sum of digits equal to $$$13$$$ at all.\u003c/p\u003e\u003cp\u003eIn the fourth example you can have neither \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e34\u003c/span\u003e\", nor \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e43\u003c/span\u003e\" in a string. Thus, you have to erase either all threes or all fours. There are $$$5$$$ of each of them, so it doesn\u0027t matter which.\u003c/p\u003e"}}]}