{"id":300735,"date":"2020-03-25T15:00:46","date_gmt":"2020-03-25T15:00:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=300735"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=300735","title":{"rendered":"\u0413\u0434\u0435 \u043f\u043e\u0440\u0435\u0448\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043b\u044f \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432 \u0432\u00a0\u042f\u043d\u0434\u0435\u043ac: \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430 \u043d\u0430\u00a0Codeforces \u0438\u00a0\u0440\u0430\u0437\u0431\u043e\u0440"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/yandex\/blog\/493966\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/5d\/rh\/fo\/5drhfost9i2nmn9onzzyiy_ixli.jpeg\" align=\"right\" width=\"30%\">\u0425\u0430\u0431\u0440, \u044d\u0442\u043e \u0441\u043d\u043e\u0432\u0430 \u044f, \u0410\u043b\u0435\u043a\u0441\u0435\u0439 \u0420\u0430\u043a (\u0444\u043e\u0442\u043e \u043d\u0435 \u043c\u043e\u0435). \u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0433\u043e\u0434\u0443, \u043f\u043e\u043c\u0438\u043c\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u043c\u043d\u0435 \u0434\u043e\u0432\u0435\u043b\u043e\u0441\u044c \u0441\u0442\u0430\u0442\u044c \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0430\u0432\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u0434\u0430\u0447 \u0434\u043b\u044f \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432 \u0432 \u042f\u043d\u0434\u0435\u043a\u0441. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043d\u0430\u0448\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0437\u0430 \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e. \u042d\u0442\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u043e \u0444\u0435\u0432\u0440\u0430\u043b\u044f 2020 \u0433\u043e\u0434\u0430 \u043f\u0440\u0438 \u043e\u0442\u0431\u043e\u0440\u0435 \u043d\u0430 \u0441\u0442\u0430\u0436\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u0431\u044d\u043a\u0435\u043d\u0434\u0435\u0440\u043e\u0432. \u0420\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440. \u0421\u0435\u0439\u0447\u0430\u0441 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u0420\u0430\u0437\u0431\u043e\u0440\u044b \u0438 \u043a\u043e\u0434 \u0441\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043f\u0440\u044f\u0442\u0430\u043d\u044b \u0432 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u044b. \u0415\u0441\u043b\u0438 \u0432\u044b \u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u0441\u044c \u043a \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f\u043c \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 IT-\u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0440\u0435\u0448\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u0447, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0440\u0430\u0437\u0431\u043e\u0440. \u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430 Codeforces \u2014 \u043e\u0442\u0432\u0435\u0442 \u043f\u0440\u0438\u0434\u0451\u0442 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 (<a href=\"https:\/\/codeforces.com\/gym\/102558\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 Codeforces<\/a> \u0438 <abbr title=\"\u041d\u0430 Codeforces \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u0430\u043c \u044d\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0437\u0430\u0434\u0430\u0447 \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435.\">\u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/abbr>). \u041a\u043e\u0434 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043d\u0430 Python, C++ \u0438 Java.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0410\u0432\u0442\u043e\u0440\u044b \u0438 \u043c\u043e\u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0438: \u0437\u0430\u0434\u0430\u0447\u0430 A \u2014 \u041f\u0430\u0432\u0435\u043b \u0414\u043e\u0440\u043e\u0448\u043a\u0435\u0432\u0438\u0447, B \u0438 F \u2014 \u0415\u0433\u043e\u0440 \u0427\u0443\u043d\u0430\u0435\u0432, E \u2014 \u0410\u043d\u0434\u0440\u0435\u0439 \u0425\u0430\u043b\u044f\u0432\u0438\u043d, C \u0438 D \u2014 \u044f. <\/p>\n<p>  <a href=\"#a\">A. \u0414\u0435\u043d\u044c \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0412\u0430\u0441\u0438<\/a><br \/>  \u3000<a href=\"#ar\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043a\u043e\u0434<\/a><\/p>\n<p>  <a href=\"#b\">B. \u0417\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447<\/a><br \/>  \u3000<a href=\"#br\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043a\u043e\u0434<\/a><\/p>\n<p>  <a href=\"#c\">C. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043d\u0430 \u043f\u043b\u044f\u0436\u0435<\/a><br \/>  \u3000<a href=\"#cr\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043a\u043e\u0434<\/a><\/p>\n<p>  <a href=\"#d\">D. \u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432<\/a><br \/>  \u3000<a href=\"#dr\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043a\u043e\u0434<\/a><\/p>\n<p>  <a href=\"#e\">E. \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0430<\/a><br \/>  \u3000<a href=\"#er\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043a\u043e\u0434<\/a><\/p>\n<p>  <a href=\"#f\">F. \u041f\u043e\u0438\u0441\u043a<\/a><br \/>  \u3000<a href=\"#fr\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043a\u043e\u0434<\/a><\/p>\n<p>  <a name=\"a\"><\/a><\/p>\n<h2>A. \u0414\u0435\u043d\u044c \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0412\u0430\u0441\u0438<\/h2>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td>3 \u0441<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td>256 \u041c\u0411<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0432\u043e\u0434<\/td>\n<td>\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u0432\u043e\u0434 <\/td>\n<\/tr>\n<tr>\n<td>\u0412\u044b\u0432\u043e\u0434<\/td>\n<td>\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 <\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p>\u0412\u0430\u0441\u044f \u0438 \u0435\u0433\u043e \u0434\u0440\u0443\u0437\u044c\u044f \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u044f\u0442 \u0432\u043a\u0443\u0441\u043d\u043e \u043f\u043e\u0435\u0441\u0442\u044c. \u041d\u0430 \u0441\u0432\u043e\u0439 \u0434\u0435\u043d\u044c \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044f\u0437\u0430\u043d \u0443\u0434\u0438\u0432\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0445, \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u0438\u0432 \u043d\u043e\u0432\u044b\u0435 \u0432\u043a\u0443\u0441\u043d\u044b\u0435 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0431\u043b\u044e\u0434\u0430.<\/p>\n<p>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0443 \u0412\u0430\u0441\u0438 \u0434\u0435\u043d\u044c \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f, \u0438 \u043e\u043d \u043f\u043e\u0437\u0432\u0430\u043b \u0441\u0432\u043e\u0438\u0445 \u0434\u0440\u0443\u0437\u0435\u0439 \u043e\u0442\u0432\u0435\u0434\u0430\u0442\u044c n \u0441\u0432\u043e\u0438\u0445 \u0441\u0430\u043c\u044b\u0445 \u043b\u0443\u0447\u0448\u0438\u0445 \u0431\u043b\u044e\u0434. \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 \u0431\u0443\u043a\u0432 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430, \u0446\u0438\u0444\u0440 \u0438 \u0437\u043d\u0430\u043a\u0430 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u043b\u044e\u0434\u0430 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c i \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f z<sub>i<\/sub> \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0435\u0433\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0440\u0446\u0438\u0438 \u0431\u043b\u044e\u0434\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u0430 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u0434\u0430\u043d\u043e. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, \u0412\u0430\u0441\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e i-\u0439 \u043a\u0443\u043b\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0448\u0435\u0434\u0435\u0432\u0440 \u0437\u0430\u0445\u043e\u0442\u044f\u0442 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c c<sub>i<\/sub> \u0434\u0440\u0443\u0437\u0435\u0439.<\/p>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>g, kg \u2014 \u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u043a\u0438\u043b\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e;<\/li>\n<li>l, ml \u2014 \u043b\u0438\u0442\u0440\u044b \u0438 \u043c\u0438\u043b\u043b\u0438\u043b\u0438\u0442\u0440\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e;<\/li>\n<li>cnt, tens \u2014 \u043e\u0434\u043d\u0430 \u0448\u0442\u0443\u043a\u0430 \u0438 \u0434\u0435\u0441\u044f\u0442\u044c \u0448\u0442\u0443\u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/li>\n<\/ul>\n<p>  \u0412 \u043e\u0434\u043d\u043e\u043c \u043a\u0438\u043b\u043e\u0433\u0440\u0430\u043c\u043c\u0435 1000 \u0433\u0440\u0430\u043c\u043c \u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u043b\u0438\u0442\u0440\u0435 1000 \u043c\u0438\u043b\u043b\u0438\u043b\u0438\u0442\u0440\u043e\u0432. \u0414\u0435\u043b\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0432 \u0434\u0440\u0443\u0433\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u0438\u043b\u0438 \u043c\u0430\u0441\u0441\u0443, \u0438\u043b\u0438 \u043e\u0431\u044a\u0435\u043c, \u0438\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e.<\/p>\n<p>  \u0423 \u0412\u0430\u0441\u0438 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u0430 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432. \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0435 \u0438 \u0446\u0435\u043d\u0430 \u0437\u0430 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0443. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0431\u0435\u043b\u043a\u043e\u0432, \u0436\u0438\u0440\u043e\u0432, \u0443\u0433\u043b\u0435\u0432\u043e\u0434\u043e\u0432 \u0438 \u044d\u043d\u0435\u0440\u0433\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430.<\/p>\n<p>  \u0412\u0430\u0441\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u0431\u043b\u044e\u0434\u0430, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u043a\u0443\u043f\u0438\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u044b \u0438 \u0432 \u043a\u0430\u043a\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0441\u0442\u0438 \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0435.<\/p>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u0434\u0440\u0443\u0437\u044c\u044f \u0438\u043c\u0435\u043d\u0438\u043d\u043d\u0438\u043a\u0430 \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u0435\u0434\u044f\u0442 \u0437\u0430 \u043f\u0438\u0442\u0430\u043d\u0438\u0435\u043c, \u0442\u043e \u043e\u043d\u0438, \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0412\u0430\u0441\u0438\u043d\u044b \u0431\u043b\u044e\u0434\u0430, \u0437\u0430\u0445\u043e\u0442\u044f\u0442 \u0443\u0437\u043d\u0430\u0442\u044c \u0432\u0441\u0451: \u043a\u0430\u043a \u0412\u0430\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u0438\u043b \u0431\u043b\u044e\u0434\u0430, \u0438\u0445 \u044d\u043d\u0435\u0440\u0433\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0431\u0435\u043b\u043a\u043e\u0432, \u0436\u0438\u0440\u043e\u0432 \u0438 \u0443\u0433\u043b\u0435\u0432\u043e\u0434\u043e\u0432. \u0412\u0430\u0441\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<p>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043c\u043e\u0447\u044c \u0438\u043c\u0435\u043d\u0438\u043d\u043d\u0438\u043a\u0443 \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0434\u0435\u043d\u0435\u0433 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0435, \u043a\u0430\u043a\u0438\u0435 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u044b \u0438 \u0432 \u043a\u0430\u043a\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0443\u0436\u043d\u043e \u043a\u0443\u043f\u0438\u0442\u044c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u044e\u0434\u0430 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0431\u0435\u043b\u043a\u043e\u0432, \u0436\u0438\u0440\u043e\u0432, \u0443\u0433\u043b\u0435\u0432\u043e\u0434\u043e\u0432 \u0438 \u044d\u043d\u0435\u0440\u0433\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0441\u044a\u0435\u0441\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<h4>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e n (1 \u2a7d n \u2a7d 1000) \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u043b\u044e\u0434, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0435\u0448\u0438\u043b \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0412\u0430\u0441\u044f.<\/p>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 n \u0431\u043b\u044e\u0434. \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 d<sub>i<\/sub> \u0438 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0441<sub>i<\/sub>, z<sub>i<\/sub> (1 \u2a7d \u0441<sub>i<\/sub>, z<sub>i<\/sub> \u2a7d 100) \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u043b\u044e\u0434\u0430, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0440\u0443\u0437\u0435\u0439, \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u043e\u0442\u0432\u0435\u0434\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u043e\u0435 \u0431\u043b\u044e\u0434\u043e, \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f. \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u043b\u044e\u0434\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 \u0431\u0443\u043a\u0432 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430, \u0446\u0438\u0444\u0440 \u0438 \u0437\u043d\u0430\u043a\u0430 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f. \u0415\u0433\u043e \u0434\u043b\u0438\u043d\u0430 \u043d\u0435 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u0438\u0442 20 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 z<sub>i<\/sub> \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432. \u0412 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c j \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 s<sub>i, j<\/sub> \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430, \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e a<sub>i, j<\/sub> (1 \u2a7d a<sub>i, j<\/sub> \u2a7d 1000) \u2014 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u0438 \u0441\u0442\u0440\u043e\u043a\u0430 u<sub>i, j<\/sub> \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430. \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 \u0431\u0443\u043a\u0432 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430, \u0446\u0438\u0444\u0440 \u0438 \u0437\u043d\u0430\u043a\u0430 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f. \u0414\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u0438\u0442 20 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e k (1 \u2a7d k \u2a7d 1000) \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0446\u0435\u043d.<\/p>\n<p>  \u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 k \u0441\u0442\u0440\u043e\u043a \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0447\u0435\u0442\u044b\u0440\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f t<sub>i<\/sub> p<sub>i<\/sub> a<sub>i<\/sub> u<sub>i<\/sub>, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442.<\/p>\n<ul>\n<li>t<sub>i<\/sub> \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0438\u0437 \u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 \u0431\u0443\u043a\u0432 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430, \u0446\u0438\u0444\u0440 \u0438 \u0437\u043d\u0430\u043a\u0430 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f. \u0414\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u0438\u0442 20 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432;<\/li>\n<li>p<sub>i<\/sub> \u2014 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430, \u0437\u0430\u0434\u0430\u043d\u043d\u0430\u044f \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c (1 \u2a7d p<sub>i<\/sub> \u2a7d 1000);<\/li>\n<li>a<sub>i<\/sub> \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u0432 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0435 \u0432 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445, \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c (1 \u2a7d a<sub>i<\/sub> \u2a7d 1000);<\/li>\n<li>u<sub>i<\/sub> \u2014 \u0435\u0434\u0438\u043d\u0438\u0446\u0430 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 (l, ml, g, kg, cnt \u0438\u043b\u0438 tens). <\/li>\n<\/ul>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0447\u0438\u0441\u043b\u043e m (1 \u2a7d m \u2a7d 1000) \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0435\u0434\u044b.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b m \u0441\u0442\u0440\u043e\u043a, \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0441\u0435\u043c\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 t<sub>i<\/sub> a<sub>i<\/sub> u<sub>i<\/sub> pr<sub>i<\/sub> f<sub>i<\/sub> ch<sub>i<\/sub> fv<sub>i<\/sub>, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442.<\/p>\n<ul>\n<li>t<sub>i<\/sub> \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0438\u0437 \u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 \u0431\u0443\u043a\u0432 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430, \u0446\u0438\u0444\u0440 \u0438 \u0437\u043d\u0430\u043a\u0430 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f. \u0414\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u0438\u0442 20 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432;<\/li>\n<li>a<sub>i<\/sub> \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430, \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c (1 \u2a7d a<sub>i<\/sub> \u2a7d 1000);<\/li>\n<li>u<sub>i<\/sub> \u2014 \u0435\u0434\u0438\u043d\u0438\u0446\u0430 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f (l, ml, g, kg, cnt \u0438\u043b\u0438 tens);<\/li>\n<li>pr<sub>i<\/sub> f<sub>i<\/sub> ch<sub>i<\/sub> fv<sub>i<\/sub> \u2014 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0431\u0435\u043b\u043a\u043e\u0432, \u0436\u0438\u0440\u043e\u0432, \u0443\u0433\u043b\u0435\u0432\u043e\u0434\u043e\u0432 \u0438 \u044d\u043d\u0435\u0440\u0433\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u0441 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0448\u0435\u0441\u0442\u044c\u044e \u0437\u043d\u0430\u043a\u0430\u043c\u0438 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u044f\u0442\u043e\u0439 (0 \u2a7d pr<sub>i<\/sub>, f<sub>i<\/sub>, ch<sub>i<\/sub> \u2a7d 1000, 0 \u2a7d fv<sub>i<\/sub> \u2a7d 10 000).<\/li>\n<\/ul>\n<p>  \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e:<\/p>\n<ul>\n<li>\u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430\u0445 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u0432\u0441\u0435 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u044b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u043b\u044e\u0434;<\/li>\n<li>\u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0443\u0445 \u0431\u043b\u044e\u0434 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c;<\/li>\n<li>\u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0443\u0445 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c;<\/li>\n<li>\u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0443\u0445 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u043e\u0434\u043d\u043e\u043c \u0431\u043b\u044e\u0434\u0435 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c;<\/li>\n<li>\u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0434\u0432\u0443\u0445 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0439 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0434\u0430\u043d\u044b \u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0434\u0440\u0443\u0433 \u0432 \u0434\u0440\u0443\u0433\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043e\u0434\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e: \u0441\u0443\u043c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0412\u0430\u0441\u0435 \u043d\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0443 \u043a \u043f\u0440\u0430\u0437\u0434\u043d\u0438\u043a\u0443.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c k \u0441\u0442\u0440\u043e\u043a, \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u0438 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e\u00a0\u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u043f\u0430\u043a\u043e\u0432\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043a\u0443\u043f\u0438\u0442\u044c. \u0418\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u044b, \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0432 \u044d\u0442\u0438\u0445 k \u0441\u0442\u0440\u043e\u043a\u0430\u0445, \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430\u043c, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u0435.<\/p>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 n \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u043b\u044e\u0434\u0430 \u0438 \u0435\u0433\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438: \u0431\u0435\u043b\u043a\u0438, \u0436\u0438\u0440\u044b, \u0443\u0433\u043b\u0435\u0432\u043e\u0434\u044b \u0438 \u044d\u043d\u0435\u0440\u0433\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  \u0418\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u044b \u0438 \u0431\u043b\u044e\u0434\u0430 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<p>  \u0412\u0430\u0448 \u043e\u0442\u0432\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0436\u044e\u0440\u0438, \u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0438\u0445 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u0438\u043b\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u0438\u0442 10<sup>-3<\/sup>. \u0411\u043e\u043b\u0435\u0435 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u043f\u0443\u0441\u0442\u044c \u0432\u0435\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0432 \u0432\u0430\u0448\u0435\u043c \u043e\u0442\u0432\u0435\u0442\u0435 \u0440\u0430\u0432\u043d\u043e A, \u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0436\u044e\u0440\u0438 \u0440\u0430\u0432\u043d\u043e B. \u0422\u043e\u0433\u0434\u0430 \u0447\u0438\u0441\u043b\u043e A \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c, \u0435\u0441\u043b\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/338\/394\/dde\/338394dde73e843636b06187fb287a0b.svg\" alt=\"$\\frac{|A - B|}{max(1,B)}\u2a7d10^{-3}$\" data-tex=\"inline\"><\/math>.<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440<\/h4>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<td><b>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/b><\/td>\n<td><b>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/b><\/td>\n<\/tr>\n<tr>\n<td><code>2<br \/>  sandwich 7 3<br \/>  butter 10 g<br \/>  toasted_bread 2 cnt<br \/>  sausage 30 g<br \/>  omelet 9 4<br \/>  egg 4 cnt<br \/>  milk 120 ml<br \/>  salt 1 g<br \/>  sausage 50 g<br \/>  7<br \/>  egg 61 1 tens<br \/>  milk 58 1 l<br \/>  sausage 100 480 g<br \/>  butter 120 180 g<br \/>  cream 100 350 g<br \/>  salt 14 1000 g<br \/>  toasted_bread 40 20 cnt<br \/>  8<br \/>  egg 1 cnt 13 12 1 16.4<br \/>  milk 1 l 3 4.5 4.7 60<br \/>  chocolate 90 g 6.8 36.3 47.1 546<br \/>  salt 1 kg 0 0 0 0<br \/>  strawberry 100 g 0.4 0.1 7 35<br \/>  sausage 100 g 10 18 1.5 210<br \/>  toasted_bread 5 cnt 7.3 1.6 52.3 248<br \/>  butter 100 g 0.8 72.5 1.3 661<\/code><\/td>\n<td><code>734<br \/>  egg 4<br \/>  milk 2<br \/>  sausage 2<br \/>  butter 1<br \/>  cream 0<br \/>  salt 1<br \/>  toasted_bread 1<br \/>  sandwich 6.00 13.29 21.50 228.3<br \/>  omelet 57.360 57.540 5.314 177.800<\/code><\/td>\n<\/tr>\n<\/table>\n<\/div>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/h4>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0412\u0430\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c 7 \u0431\u0443\u0442\u0435\u0440\u0431\u0440\u043e\u0434\u043e\u0432 \u0438 9 \u043e\u043c\u043b\u0435\u0442\u043e\u0432.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0435\u0440\u0432\u044b\u0445 \u0431\u043b\u044e\u0434 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e 10 \u22c5 7 \u0433\u0440\u0430\u043c\u043c \u043c\u0430\u0441\u043b\u0430, 2 1 7 \u043a\u0443\u0441\u043e\u0447\u043a\u043e\u0432 \u0445\u043b\u0435\u0431\u0430 \u0438 30 \u22c5 7 \u0433\u0440\u0430\u043c\u043c \u043a\u043e\u043b\u0431\u0430\u0441\u044b. \u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0431\u0443\u0442\u0435\u0440\u0431\u0440\u043e\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9b6\/b5e\/933\/9b6b5e9332644b6b3050a60769601a9b.svg\" alt=\"$0.8 \u22c5 \\frac {10}{100} + 7.3 \u22c5 \\frac {2}{5} + 10 \u22c5 \\frac {30}{100} =6$\" data-tex=\"inline\"><\/math> \u0433\u0440\u0430\u043c\u043c \u0431\u0435\u043b\u043a\u043e\u0432, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/f0d\/fc2\/16df0dfc2305bff874be8bbf7ca069fd.svg\" alt=\"$72.5 \u22c5 \\frac {10}{100} + 1.6 \u22c5 \\frac {2}{5} + 18 \u22c5 \\frac {30}{100} =13.29$\" data-tex=\"inline\"><\/math> \u0433\u0440\u0430\u043c\u043c \u0436\u0438\u0440\u043e\u0432 \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2df\/864\/fd2\/2df864fd2a24b7e0a1791e770eac9848.svg\" alt=\"$1.3 \u22c5 \\frac {10}{100} + 52.3 \u22c5 \\frac {2}{5} + 1.5 \u22c5 \\frac {30}{100} =21.5$\" data-tex=\"inline\"><\/math> \u0433\u0440\u0430\u043c\u043c \u0443\u0433\u043b\u0435\u0432\u043e\u0434\u043e\u0432. \u042d\u043d\u0435\u0440\u0433\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u0430\u044f \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/ac6\/dfe\/301\/ac6dfe301989eab9dedaefe53572fc2e.svg\" alt=\"$661 \u22c5 \\frac {10}{100} + 248 \u22c5 \\frac {2}{5} + 210 \u22c5 \\frac {30}{100} =228.3 \u043a\u043a\u0430\u043b$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0432\u0442\u043e\u0440\u044b\u0445 \u0431\u043b\u044e\u0434 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e 4 \u22c5 9 = 36 \u044f\u0438\u0446, 120 \u22c5 9 = 1080 \u043c\u0438\u043b\u043b\u0438\u043b\u0438\u0442\u0440\u043e\u0432 \u043c\u043e\u043b\u043e\u043a\u0430, 9 \u0433\u0440\u0430\u043c\u043c \u0441\u043e\u043b\u0438, 50 \u22c5 9 = 450 \u0433\u0440\u0430\u043c\u043c \u043a\u043e\u043b\u0431\u0430\u0441\u044b. \u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u043e\u043c\u043b\u0435\u0442\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2b3\/f2d\/7e0\/2b3f2d7e08795c316f6f1faa63adefc1.svg\" alt=\"$13 \u22c5 4+ 3 \u22c5 \\frac {120}{1000} + 10 \u22c5 \\frac {50}{100} =57.36$\" data-tex=\"inline\"><\/math> \u0433\u0440\u0430\u043c\u043c \u0431\u0435\u043b\u043a\u043e\u0432, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8a1\/7c9\/035\/8a17c903525fc3495fb1cc382fae6e7a.svg\" alt=\"$12 \u22c5 4+ 4.5 \u22c5 \\frac {120}{1000} + 18 \u22c5 \\frac {50}{100} =57,54 \u0436\u0438\u0440\u043e\u0432$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/75e\/b58\/46f\/75eb5846f6480a6c143d2cef82e017d0.svg\" alt=\"$1 \u22c5 4+ 4.7 \u22c5 \\frac {120}{1000} + 1.5 \u22c5 \\frac {50}{100} =5.314$\" data-tex=\"inline\"><\/math> \u0443\u0433\u043b\u0435\u0432\u043e\u0434\u043e\u0432. \u042d\u043d\u0435\u0440\u0433\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d4a\/f51\/fcd\/d4af51fcdd408a23d2ae7df8ae8e5322.svg\" alt=\"$16 \u22c5 4+ 60 \u22c5 \\frac {120}{1000} + 210 \u22c5 \\frac {50}{100} =177.8$\" data-tex=\"inline\"><\/math> \u043a\u043a\u0430\u043b.<\/p>\n<p>  \u0412\u0441\u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e 70 \u0433\u0440\u0430\u043c\u043c \u043c\u0430\u0441\u043b\u0430, 36 \u044f\u0438\u0446, 1080 \u043b\u0438\u0442\u0440\u043e\u0432 \u043c\u043e\u043b\u043e\u043a\u0430, 9 \u0433\u0440\u0430\u043c\u043c \u0441\u043e\u043b\u0438, 210 + 450 = 660 \u0433\u0440\u0430\u043c\u043c \u043a\u043e\u043b\u0431\u0430\u0441\u044b \u0438 14 \u043a\u0443\u0441\u043e\u0447\u043a\u043e\u0432 \u0442\u043e\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0445\u043b\u0435\u0431\u0430.<\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043a\u0443\u043f\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0443 \u043c\u0430\u0441\u043b\u0430, 4 \u0434\u0435\u0441\u044f\u0442\u043a\u0430 \u044f\u0438\u0446, 2 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u043a\u043e\u043b\u0431\u0430\u0441\u044b \u0438 \u043c\u043e\u043b\u043e\u043a\u0430, \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0435 \u0441\u043e\u043b\u0438 \u0438 \u0442\u043e\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0445\u043b\u0435\u0431\u0430, \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0432 120 + 61 \u22c5 4 + 100 \u22c5 2 + 58 \u22c5 2 + 14 + 40 = 734 \u0440\u0443\u0431\u043b\u044f.<\/p>\n<p>  <a name=\"ar\"><\/a><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\u0418\u0442\u0430\u043a, \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 \u0434\u0430\u043d\u044b \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f n \u0431\u043b\u044e\u0434 dishes, \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0446\u0435\u043d prices \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 k \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 catalog, \u0433\u0434\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0431\u0435\u043b\u043a\u043e\u0432, \u0436\u0438\u0440\u043e\u0432 \u0438 \u0443\u0433\u043b\u0435\u0432\u043e\u0434\u043e\u0432 \u0434\u043b\u044f m \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0443\u0436\u043d\u043e:<\/p>\n<p>  1. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0434\u0435\u043d\u0435\u0433 \u043d\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u044b, \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445.<br \/>  2. \u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0435\u043b\u043a\u043e\u0432, \u0436\u0438\u0440\u043e\u0432, \u0443\u0433\u043b\u0435\u0432\u043e\u0434\u043e\u0432 \u0438 \u044d\u043d\u0435\u0440\u0433\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u044e\u0434\u0430.<\/p>\n<p>  \u042d\u0442\u0438 \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e.<\/p>\n<p>  \u041e\u043f\u0438\u0448\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0438. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0431\u043b\u044e\u0434\u0430 dishes \u0438 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0446\u0435\u043d prices.<\/p>\n<p>  1. \u0417\u0430\u0432\u0435\u0434\u0435\u043c \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 inredients, \u0433\u0434\u0435 \u043a\u043b\u044e\u0447 \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e (\u0432 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f).<br \/>  2. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u044e\u0434\u0430 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u0435\u0433\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432.<br \/>  3. \u0417\u043d\u0430\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u043b\u044e\u0434 \u0438 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u0431\u043b\u044e\u0434\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 ingredients \u043f\u043e \u043a\u043b\u044e\u0447\u0443 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u044d\u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<br \/>  4. \u041a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u0431\u043b\u044e\u0434\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e \u0432\u0441\u0435\u043c \u0431\u043b\u044e\u0434\u0430\u043c \u0434\u0435\u043b\u0438\u043c \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u0435 \u0446\u0435\u043d prices \u0441 \u043e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u0435\u043c \u0432\u0432\u0435\u0440\u0445.<br \/>  5. \u0417\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432, \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0439\u0442\u0438 \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0443\u043c\u043c\u0443. \u0421\u0442\u043e\u0438\u0442 \u0438\u043c\u0435\u0442\u044c \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u0435\u043d\u0435\u0433 32-\u0431\u0438\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e.<br \/>  6. \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0435\u043d\u0435\u0433, \u0430 \u0437\u0430\u0442\u0435\u043c k \u0441\u0442\u0440\u043e\u043a \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430 \u0438 \u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430.<\/p>\n<p>  \u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0438\u0437 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u043d\u0435 \u0431\u044b\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043d\u0438 \u0440\u0430\u0437\u0443, \u0435\u0433\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e 0.<\/p>\n<p>  \u041e\u043f\u0438\u0448\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0434\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0438. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0431\u043b\u044e\u0434\u0430 dishes \u0438 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432 catalog:<\/p>\n<p>  1. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u044e\u0434\u0430 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432.<br \/>  2. \u0411\u0435\u0440\u0435\u043c \u0438\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0435, \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u043c \u043d\u0430 \u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432 \u0431\u043b\u044e\u0434\u0435 \u0438 \u0434\u0435\u043b\u0438\u043c \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435.<br \/>  3. \u041f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u043e\u0442\u0432\u0435\u0442\u0443.<br \/>  4. \u041f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0441\u0435\u0445 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u0431\u043b\u044e\u0434\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d.<\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u0441\u043e\u0431\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c \u0432\u0435\u043b\u0438\u0447\u0438\u043d. \u0422\u0430\u043a \u043a\u0430\u043a \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0434\u043d\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u043a\u0440\u0430\u0442\u043d\u044b 10 \u0438\u043b 1000, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f Decimal \u0438\u043b\u0438 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430. \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0443\u043c\u043d\u043e\u0436\u0438\u0442\u044c \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b \u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0431\u043b\u044e\u0434 \u043d\u0430 1000, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0438\u0437 \u0433\u0440\u0430\u043c\u043c\u043e\u0432 \u0432 \u043a\u0438\u043b\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u0438\u0437 \u043c\u0438\u043b\u043b\u0438\u043b\u0438\u0442\u0440\u043e\u0432 \u0432 \u043b\u0438\u0442\u0440\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u0435\u043b\u0435\u043d\u0438\u0435. \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0432\u0435\u043b\u0438\u0447\u0438\u043d \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445, \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>  \u0422\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 float \u043f\u043b\u043e\u0445\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u043c\u0435\u0435\u0442 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0432 6-7 \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u0445 \u0437\u043d\u0430\u043a\u043e\u0432 \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u044f. \u0422\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 double \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u0432\u044b\u0432\u043e\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u0410\u0441\u0438\u043c\u043f\u0442\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446 \u0434\u043b\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0438 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u0430: <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/926\/584\/d98\/926584d9857acd5a8ca62ffcc3370286.svg\" alt=\"$O(\\sum_{i=1}^{n}z_i)$\" data-tex=\"inline\"><\/math>, \u0433\u0434\u0435 z<sub>i<\/sub> \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 i-\u043c \u0431\u043b\u044e\u0434\u0435. <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Python<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import collections import math import typing from decimal import Decimal   class Amount(object):     def __init__(self, count: Decimal, unit: str):         self.count = count         self.unit = unit      def convert_to(self, unit: str):         multipliers_dict = {             'g': 1,             'kg': 1000,             'ml': 1,             'l': 1000,             'cnt': 1,             'tens': 10         }         assert self.is_compatible(self.unit, unit)          return Amount(self.count * multipliers_dict[self.unit] \/ multipliers_dict[unit], unit)      @staticmethod     def is_compatible(unit1, unit2):         unit_classes = [             ('g', 'kg'),             ('ml', 'l'),             ('cnt', 'tens')         ]          for unit_class in unit_classes:             if unit1 in unit_class:                 return unit2 in unit_class         return False   class FoodInfo(object):     def __init__(self, proteins: Decimal = Decimal(0), fats: Decimal = Decimal(0), carbohydrates: Decimal = Decimal(0), food_value: Decimal = Decimal(0)):         self.proteins = proteins         self.fats = fats         self.carbohydrates = carbohydrates         self.food_value = food_value      def __mul__(self, other: Decimal):         assert isinstance(other, Decimal)          return FoodInfo(self.proteins * other, self.fats * other, self.carbohydrates * other, self.food_value * other)      def __add__(self, other):         assert isinstance(other, FoodInfo)          return FoodInfo(             self.proteins + other.proteins,             self.fats + other.fats,             self.carbohydrates + other.carbohydrates,             self.food_value + other.food_value         )   class AmountFoodInfo(object):     def __init__(self, amount, food_info):         self.amount = amount         self.food_info = food_info   class Ingredient(object):     def __init__(self, name: str, amount: Amount):         self.name = name         self.amount = amount   class CatalogIngredientInfo(object):     def __init__(self, name: str, price: int, amount: Amount):         self.name = name         self.price = price         self.amount = amount   class Dish(object):     def __init__(self, name: str, count: int, ingredients: typing.List[Ingredient]):         self.name = name         self.count = count         self.ingredients = ingredients   def read_dishes():     dish_count = int(input())      dishes = []     for _ in range(dish_count):         dish_name, dish_count, ingredient_count = input().split(' ')         ingredient_count = int(ingredient_count)          ingredients = []         for _ in range(ingredient_count):             ingredient_name, amount, unit = input().split(' ')             ingredients.append(Ingredient(name=ingredient_name, amount=Amount(Decimal(amount), unit)))          dishes.append(Dish(name=dish_name, ingredients=ingredients, count=int(dish_count)))      return dishes   def read_catalog():     ingredient_count = int(input())      catalog = {}     for _ in range(ingredient_count):         name, price, amount, unit = input().split(' ')         catalog[name] = CatalogIngredientInfo(             name=name,             price=int(price),             amount=Amount(Decimal(amount), unit)         )      return catalog   def read_food_info():     info_count = int(input())      food_info = {}     for _ in range(info_count):         name, amount, unit, proteins, fats, carbohydrates, food_value = input().split(' ')         food_info[name] = AmountFoodInfo(             amount=Amount(                 count=Decimal(amount),                 unit=unit             ),             food_info=FoodInfo(                 proteins=Decimal(proteins),                 fats=Decimal(fats),                 carbohydrates=Decimal(carbohydrates),                 food_value=Decimal(food_value)             )         )      return food_info   def main():     dishes = read_dishes()     catalog = read_catalog()     food_info = read_food_info()      need_ingredients = collections.defaultdict(Decimal)     need_ingredients_count = collections.defaultdict(int)     dish_info = collections.defaultdict(FoodInfo)     for dish in dishes:         for ingredient in dish.ingredients:             converted_amount = ingredient.amount.convert_to(catalog[ingredient.name].amount.unit)             converted_food_info_amount = food_info[ingredient.name].amount.convert_to(catalog[ingredient.name].amount.unit)             need_ingredients[ingredient.name] += converted_amount.count * dish.count             dish_info[dish.name] += food_info[ingredient.name].food_info * (converted_amount.count \/ converted_food_info_amount.count)      total_price = Decimal(0)     for ingredient_name, need_ingredient in need_ingredients.items():         need_count = need_ingredient \/\/ catalog[ingredient_name].amount.count         if need_count * catalog[ingredient_name].amount.count &lt; need_ingredient:             need_count += 1          need_ingredients_count[ingredient_name] = need_count         total_price += catalog[ingredient_name].price * need_count      print(total_price)     for name in catalog.keys():         print(name, need_ingredients_count[name])      for name, info in dish_info.items():         print(name, info.proteins, info.fats, info.carbohydrates, info.food_value)   if __name__ == '__main__':     main()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 C++<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;stdio.h&gt; #include &lt;iostream&gt; #include &lt;stdlib.h&gt; #include &lt;string&gt; #include &lt;string.h&gt; #include &lt;vector&gt; #include &lt;stack&gt; #include &lt;queue&gt; #include &lt;deque&gt; #include &lt;set&gt; #include &lt;map&gt; #include &lt;assert.h&gt; #include &lt;algorithm&gt; #include &lt;iomanip&gt; #include &lt;time.h&gt; #include &lt;math.h&gt; #include &lt;bitset&gt; #include &lt;unordered_map&gt;  #pragma comment(linker, &quot;\/STACK:256000000&quot;)  using namespace std;  typedef long long int ll; typedef long double ld;  const int INF = 1000 * 1000 * 1000 + 21; const ll LLINF = (1ll &lt;&lt; 60) + 5; const int MOD = 1000 * 1000 * 1000 + 7;  const int MAX_N = 10 * 1000 + 227; const int MAX_LEN = 35;  struct ig_info {     ll cost = 0;     ll cnt = 0;     ll buy_cnt = 0;     ll eg_cnt = 0;     ld arr[4] = {0.0, 0.0, 0.0, 0.0}; };  struct rs {     string name;     ll mult = 0;     vector&lt;pair&lt;string, ll&gt;&gt; igs;     ld arr[4] = {0.0, 0.0, 0.0, 0.0}; };  int n, k, m; char buf[MAX_LEN]; char buf_cnt[MAX_LEN]; rs arr[MAX_N]; unordered_map&lt;string, ig_info&gt; info;  ll get_cnt() {     ll cnt;     scanf(&quot;%lld %s&quot;, &amp;cnt, buf_cnt);     if (!strcmp(buf_cnt, &quot;kg&quot;) || !strcmp(buf_cnt, &quot;l&quot;)) {         return 1000 * cnt;     }     if (!strcmp(buf_cnt, &quot;tens&quot;)) {         return 10 * cnt;     }     return cnt; }  int main() { #ifdef CH_EGOR     freopen(&quot;input.txt&quot;, &quot;r&quot;, stdin);     \/\/freopen(&quot;output.txt&quot;, &quot;w&quot;, stdout); #else     \/\/freopen(&quot;&quot;, &quot;r&quot;, stdin);     \/\/freopen(&quot;&quot;, &quot;w&quot;, stdout); #endif      scanf(&quot;%d&quot;, &amp;n);     for (int i = 0; i &lt; n; ++i) {         int sz;         scanf(&quot;%s%lld%d&quot;, buf, &amp;arr[i].mult, &amp;sz);         arr[i].name = buf;         arr[i].igs.resize(sz);         for (int j = 0; j &lt; sz; ++j) {             scanf(&quot;%s&quot;, buf);             arr[i].igs[j].first = buf;             arr[i].igs[j].second = get_cnt();         }     }      scanf(&quot;%d&quot;, &amp;k);     for (int i = 0; i &lt; k; ++i) {         ll cost;         scanf(&quot;%s%lld&quot;, buf, &amp;cost);         ig_info&amp; cur_info = info[buf];         cur_info.cost = cost;         cur_info.cnt = get_cnt();     }      scanf(&quot;%d&quot;, &amp;m);     for (int i = 0; i &lt; m; ++i) {         scanf(&quot;%s&quot;, buf);         ig_info&amp; cur_info = info[buf];         cur_info.eg_cnt = get_cnt();         for (int j = 0; j &lt; 4; ++j) {             double x;             scanf(&quot;%lf&quot;, &amp;x);             cur_info.arr[j] = x;         }         if (cur_info.cnt == 0) {             info.erase(buf);         }     }      for (int i = 0; i &lt; n; ++i) {         for (int j = 0; j &lt; (int)arr[i].igs.size(); ++j) {             ig_info&amp; cur_info = info[arr[i].igs[j].first];             cur_info.buy_cnt += arr[i].mult * arr[i].igs[j].second;             for (int k = 0; k &lt; 4; ++k) {                 arr[i].arr[k] += ((double)arr[i].igs[j].second \/ (double)cur_info.eg_cnt) * cur_info.arr[k];             }         }     }      ll ans = 0;     for (auto&amp; cur_info : info) {         cur_info.second.buy_cnt = (cur_info.second.buy_cnt + cur_info.second.cnt - 1) \/ cur_info.second.cnt;         ans += cur_info.second.buy_cnt * cur_info.second.cost;     }      printf(&quot;%lld\\n&quot;, ans);      for (const auto&amp; cur_info : info) {         printf(&quot;%s %lld\\n&quot;, cur_info.first.c_str(), cur_info.second.buy_cnt);     }      for (int i = 0; i &lt; n; ++i) {         printf(&quot;%s &quot;, arr[i].name.c_str());         for (int j = 0; j &lt; 4; ++j) {             printf(&quot;%.20lf%c&quot;, (double)arr[i].arr[j], &quot; \\n&quot;[j == 3]);         }     }      return 0; }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.HashMap; import java.io.IOException; import java.util.Map.Entry; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream;  \/**  * Built using CHelper plug-in  * Actual solution is at the top  *  * @author ch_egor  *\/ public class Main {     public static void main(String[] args) {         InputStream inputStream = System.in;         OutputStream outputStream = System.out;         InputReader in = new InputReader(inputStream);         OutputWriter out = new OutputWriter(outputStream);         Recipes solver = new Recipes();         solver.solve(1, in, out);         out.close();     }      static class Recipes {         static final int CNT_ENERGY = 4;          public void solve(int testNumber, InputReader in, OutputWriter out) {             int n = in.nextInt();              Recipes.Recipe[] recipes = new Recipes.Recipe[n];             for (int i = 0; i &lt; n; ++i) {                 recipes[i] = new Recipes.Recipe();                 recipes[i].name = in.nextString();                 recipes[i].mult = in.nextLong();                  int ingredientsSize = in.nextInt();                 recipes[i].ingredients = new Recipes.Ingredient[ingredientsSize];                 for (int j = 0; j &lt; recipes[i].ingredients.length; ++j) {                     recipes[i].ingredients[j] = new Recipes.Ingredient();                     recipes[i].ingredients[j].name = in.nextString();                     recipes[i].ingredients[j].cnt = readCnt(in);                 }             }              int k = in.nextInt();             HashMap&lt;String, Recipes.IngredientBuyInfo&gt; ingredientBuyInfo = new HashMap&lt;&gt;();             for (int i = 0; i &lt; k; ++i) {                 String name = in.nextString();                  Recipes.IngredientBuyInfo curBuyInfo = new Recipes.IngredientBuyInfo();                 curBuyInfo.cost = in.nextLong();                 curBuyInfo.cnt = readCnt(in);                  ingredientBuyInfo.put(name, curBuyInfo);             }              int m = in.nextInt();             HashMap&lt;String, Recipes.IngredientEnergyInfo&gt; ingredientEnergyInfo = new HashMap&lt;&gt;();             for (int i = 0; i &lt; m; ++i) {                 String name = in.nextString();                  Recipes.IngredientEnergyInfo curEnergyInfo = new Recipes.IngredientEnergyInfo();                 curEnergyInfo.cnt = readCnt(in);                 for (int j = 0; j &lt; CNT_ENERGY; ++j) {                     curEnergyInfo.energyArr[j] = in.nextDouble();                 }                  ingredientEnergyInfo.put(name, curEnergyInfo);             }              for (int i = 0; i &lt; n; ++i) {                 for (int j = 0; j &lt; recipes[i].ingredients.length; ++j) {                     Recipes.IngredientBuyInfo curBuyInfo = ingredientBuyInfo.get(recipes[i].ingredients[j].name);                     curBuyInfo.buyCnt += recipes[i].mult * recipes[i].ingredients[j].cnt;                      Recipes.IngredientEnergyInfo curEnergyInfo = ingredientEnergyInfo.get(recipes[i].ingredients[j].name);                     for (int p = 0; p &lt; CNT_ENERGY; ++p) {                         recipes[i].energyArr[p] += ((double) recipes[i].ingredients[j].cnt \/ (double) curEnergyInfo.cnt) * curEnergyInfo.energyArr[p];                     }                 }             }              long totalCost = 0;             for (HashMap.Entry&lt;String, Recipes.IngredientBuyInfo&gt; entry : ingredientBuyInfo.entrySet()) {                 totalCost += entry.getValue().cost * ((entry.getValue().buyCnt + entry.getValue().cnt - 1) \/ entry.getValue().cnt);             }              out.println(totalCost);              for (HashMap.Entry&lt;String, Recipes.IngredientBuyInfo&gt; entry : ingredientBuyInfo.entrySet()) {                 out.println(entry.getKey() + &quot; &quot; + ((entry.getValue().buyCnt + entry.getValue().cnt - 1) \/ entry.getValue().cnt));             }              for (int i = 0; i &lt; n; ++i) {                 out.print(recipes[i].name + &quot; &quot;);                 for (int j = 0; j &lt; CNT_ENERGY; ++j) {                     out.print(String.format(&quot;%.20f&quot;, recipes[i].energyArr[j]) + (j == CNT_ENERGY - 1 ? &quot;\\n&quot; : &quot; &quot;));                 }             }         }          private long readCnt(InputReader in) {             int cnt = in.nextInt();             String type = in.nextString();             if (type.compareTo(&quot;kg&quot;) == 0 || type.compareTo(&quot;l&quot;) == 0) {                 return 1000 * cnt;             }             if (type.compareTo(&quot;tens&quot;) == 0) {                 return 10 * cnt;             }             return cnt;         }          static class Ingredient {             String name;             long cnt;          }          static class IngredientBuyInfo {             long cost;             long cnt;             long buyCnt;          }          static class IngredientEnergyInfo {             long cnt;             double[] energyArr;              IngredientEnergyInfo() {                 energyArr = new double[CNT_ENERGY];                 for (int i = 0; i &lt; CNT_ENERGY; ++i) {                     energyArr[i] = 0.0;                 }             }          }          static class Recipe {             String name;             long mult;             Recipes.Ingredient[] ingredients;             double[] energyArr;              Recipe() {                 energyArr = new double[CNT_ENERGY];                 for (int i = 0; i &lt; CNT_ENERGY; ++i) {                     energyArr[i] = 0.0;                 }             }          }      }      static class InputReader {         private InputStream stream;         private byte[] buf = new byte[1024];         private int curChar;         private int numChars;         private InputReader.SpaceCharFilter filter;          public InputReader(InputStream stream) {             this.stream = stream;         }          public int read() {             if (numChars == -1) {                 throw new UnknownError();             }             if (curChar &gt;= numChars) {                 curChar = 0;                 try {                     numChars = stream.read(buf);                 } catch (IOException e) {                     throw new UnknownError();                 }                 if (numChars &lt;= 0) {                     return -1;                 }             }             return buf[curChar++];         }          public int nextInt() {             int c = read();             while (isSpaceChar(c)) {                 c = read();             }             int sgn = 1;             if (c == '-') {                 sgn = -1;                 c = read();             }             int res = 0;             do {                 if (c &lt; '0' || c &gt; '9') {                     throw new UnknownError();                 }                 res *= 10;                 res += c - '0';                 c = read();             } while (!isSpaceChar(c));             return res * sgn;         }          public long nextLong() {             int c = read();             while (isSpaceChar(c)) {                 c = read();             }             int sgn = 1;             if (c == '-') {                 sgn = -1;                 c = read();             }             long res = 0;             do {                 if (c &lt; '0' || c &gt; '9') {                     throw new UnknownError();                 }                 res *= 10;                 res += c - '0';                 c = read();             } while (!isSpaceChar(c));             return res * sgn;         }          public String nextString() {             int c = read();             while (isSpaceChar(c)) {                 c = read();             }             StringBuilder res = new StringBuilder();             do {                 if (Character.isValidCodePoint(c)) {                     res.appendCodePoint(c);                 }                 c = read();             } while (!isSpaceChar(c));             return res.toString();         }          public boolean isSpaceChar(int c) {             if (filter != null) {                 return filter.isSpaceChar(c);             }             return isWhitespace(c);         }          public static boolean isWhitespace(int c) {             return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;         }          public double nextDouble() {             int c = read();             while (isSpaceChar(c)) {                 c = read();             }             int sgn = 1;             if (c == '-') {                 sgn = -1;                 c = read();             }             double res = 0;             while (!isSpaceChar(c) &amp;&amp; c != '.') {                 if (c == 'e' || c == 'E') {                     return res * Math.pow(10, nextInt());                 }                 if (c &lt; '0' || c &gt; '9') {                     throw new UnknownError();                 }                 res *= 10;                 res += c - '0';                 c = read();             }             if (c == '.') {                 c = read();                 double m = 1;                 while (!isSpaceChar(c)) {                     if (c == 'e' || c == 'E') {                         return res * Math.pow(10, nextInt());                     }                     if (c &lt; '0' || c &gt; '9') {                         throw new UnknownError();                     }                     m \/= 10;                     res += (c - '0') * m;                     c = read();                 }             }             return res * sgn;         }          public interface SpaceCharFilter {             public boolean isSpaceChar(int ch);          }      }      static class OutputWriter {         private final PrintWriter writer;          public OutputWriter(OutputStream outputStream) {             writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));         }          public OutputWriter(Writer writer) {             this.writer = new PrintWriter(writer);         }          public void print(Object... objects) {             for (int i = 0; i &lt; objects.length; i++) {                 if (i != 0) {                     writer.print(' ');                 }                 writer.print(objects[i]);             }         }          public void println(Object... objects) {             print(objects);             writer.println();         }          public void close() {             writer.close();         }          public void println(long i) {             writer.println(i);         }      } }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <a name=\"b\"><\/a><\/p>\n<h2>B. \u0417\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447<\/h2>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td>2 \u0441<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td>256 \u041c\u0411<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0432\u043e\u0434<\/td>\n<td>\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u0432\u043e\u0434 <\/td>\n<\/tr>\n<tr>\n<td>\u0412\u044b\u0432\u043e\u0434<\/td>\n<td>\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 <\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p>\u0412\u043e \u0432\u0441\u0435\u0445 \u043a\u0440\u0443\u043f\u043d\u044b\u0445 IT-\u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f\u0445 \u043d\u0435\u043c\u0430\u043b\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0443\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u0438 \u042f\u043d\u0434\u0435\u043a\u0441 &nbsp;&mdash; \u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u0414\u0438\u043c\u0430 \u0438 \u0415\u0433\u043e\u0440 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u043d\u043e\u0432\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 YD (Yandex Dorogi) \u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442 \u0430\u0443\u0434\u0438\u0442 \u0435\u0433\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u0414\u043b\u044f \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 YD \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c YS (Yandex Shifrovatel).<\/p>\n<p>  <\/p>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b YS \u0442\u0430\u043a\u043e\u0432\u0430: \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447 (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6fe\/f16\/813\/6fef16813dcf881cb6c1aa95c79388e4.svg\" alt=\"$p, q$\" data-tex=\"inline\"><\/math>), \u0433\u0434\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/839\/f25\/c27\/839f25c2746382debd4f08ea25ad5ecf.svg\" alt=\"$p$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d68\/cc4\/926\/d68cc4926bf74bae8fa3b51ca4a09ec8.svg\" alt=\"$q$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430. \u041f\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u0443 (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6fe\/f16\/813\/6fef16813dcf881cb6c1aa95c79388e4.svg\" alt=\"$p, q$\" data-tex=\"inline\"><\/math>) \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447 (\u041d\u041e\u0414(<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6fe\/f16\/813\/6fef16813dcf881cb6c1aa95c79388e4.svg\" alt=\"$p, q$\" data-tex=\"inline\"><\/math>), \u041d\u041e\u041a(<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6fe\/f16\/813\/6fef16813dcf881cb6c1aa95c79388e4.svg\" alt=\"$p, q$\" data-tex=\"inline\"><\/math>)), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432\u0441\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c. \u0415\u0441\u043b\u0438 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447, \u0442\u043e \u043e\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e \u0432\u0441\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u043c YD \u0438 \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 \u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u043d\u0435\u043f\u043e\u043f\u0440\u0430\u0432\u0438\u043c\u044b\u0439 \u0432\u0440\u0435\u0434. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u0415\u0433\u043e\u0440 \u0438 \u0414\u0438\u043c\u0430 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u0445\u043e\u0442\u044f\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0443 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043e\u043d \u0441\u043c\u043e\u0436\u0435\u0442 \u0435\u0433\u043e \u0443\u0433\u0430\u0434\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0414\u0438\u043c\u0430 \u0443\u0436\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447 \u0434\u043b\u044f YD \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043d\u0430 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447 (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/ca5\/685\/9a9\/ca56859a9c0a213789bc5f4b3a866965.svg\" alt=\"$x, y$\" data-tex=\"inline\"><\/math>). \u0415\u0433\u043e\u0440\u0443 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0441\u0442\u0430\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0442\u044c \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0443 \u0434\u043b\u044f \u0432\u0437\u043b\u043e\u043c\u0430 YD \u0432 \u0445\u0443\u0434\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0438\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6fe\/f16\/813\/6fef16813dcf881cb6c1aa95c79388e4.svg\" alt=\"$p, q$\" data-tex=\"inline\"><\/math>) \u0442\u0430\u043a\u0438\u0445, \u0447\u0442\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c \u0434\u043b\u044f \u043d\u0438\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/ca5\/685\/9a9\/ca56859a9c0a213789bc5f4b3a866965.svg\" alt=\"$x, y$\" data-tex=\"inline\"><\/math>). \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0443 \u0415\u0433\u043e\u0440\u0430 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u0434\u0430\u0447, \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u044b\u0445 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 YD, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d \u043f\u0440\u043e\u0441\u0438\u0442 \u0432\u0430\u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430 \u043d\u0435\u0433\u043e.<\/p>\n<p>  <\/p>\n<h4>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0434\u0432\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9b3\/4c4\/da5\/9b34c4da5c757d4982bbd1b6f2e8998a.svg\" alt=\"$y$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2cd\/0f2\/614\/2cd0f261487ff6566304d2c3a3968eee.svg\" alt=\"$1 \\leq x \\leq y \\leq 10^{12}$\" data-tex=\"inline\"><\/math>)&nbsp;&mdash; \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430.<\/p>\n<p>  <\/p>\n<h4>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  <\/p>\n<p>\u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043e\u0434\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e&nbsp;&mdash; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c.<\/p>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b<\/h4>\n<p>  <\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 5 10 <\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 2  <\/pre>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 10 11 <\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 0  <\/pre>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 527 9486 <\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 4 <\/pre>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/h4>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0430 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0445 \u043a\u043b\u044e\u0447\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/693\/c8e\/0a3\/693c8e0a335da1266ebbc86e87ad1421.svg\" alt=\"$5, 10$\" data-tex=\"inline\"><\/math>) \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c: (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/693\/c8e\/0a3\/693c8e0a335da1266ebbc86e87ad1421.svg\" alt=\"$5, 10$\" data-tex=\"inline\"><\/math>) \u0438 (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8fe\/7e5\/9e8\/8fe7e59e81a2f9d3bcbe28832475e5d4.svg\" alt=\"$10, 5$\" data-tex=\"inline\"><\/math>).<\/p>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0414\u0438\u043c\u0430 \u043e\u0448\u0438\u0431\u0441\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0438 \u043e\u0434\u0438\u043d \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447 \u043d\u0435 \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u043b\u044e\u0447 (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f88\/395\/26d\/f8839526d0658c5efe55c22359ac116c.svg\" alt=\"$10, 11$\" data-tex=\"inline\"><\/math>).<\/p>\n<p>  <\/p>\n<p>\u0412 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u043c\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5ec\/2a9\/087\/5ec2a90871be5fe341da92e379b127c7.svg\" alt=\"$527, 9486$\" data-tex=\"inline\"><\/math>), (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/369\/130\/557\/369130557faaaa01be79bdf388fac2bd.svg\" alt=\"$1054, 4743$\" data-tex=\"inline\"><\/math>), (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c67\/69c\/b11\/c6769cb11aca76da9ff2d4b28bef069c.svg\" alt=\"$4743, 1054$\" data-tex=\"inline\"><\/math>), (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/550\/2ef\/25a\/5502ef25a74348f97d0fba12475cf9ee.svg\" alt=\"$9486, 527$\" data-tex=\"inline\"><\/math>).<\/p>\n<p>  <\/p>\n<p>\u041d\u041e\u0414 (\u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u0431\u0449\u0438\u043c \u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u043c) \u0434\u0432\u0443\u0445 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/839\/f25\/c27\/839f25c2746382debd4f08ea25ad5ecf.svg\" alt=\"$p$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d68\/cc4\/926\/d68cc4926bf74bae8fa3b51ca4a09ec8.svg\" alt=\"$q$\" data-tex=\"inline\"><\/math> \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0447\u0438\u0441\u043b\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math> \u0442\u0430\u043a\u043e\u0435, \u0447\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/839\/f25\/c27\/839f25c2746382debd4f08ea25ad5ecf.svg\" alt=\"$p$\" data-tex=\"inline\"><\/math> \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d68\/cc4\/926\/d68cc4926bf74bae8fa3b51ca4a09ec8.svg\" alt=\"$q$\" data-tex=\"inline\"><\/math> \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u041d\u041e\u0414(<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/62d\/771\/be0\/62d771be0f50d3a019c5a4889b22d326.svg\" alt=\"$6, 15$\" data-tex=\"inline\"><\/math>) \u0440\u0430\u0432\u0435\u043d <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math>, \u0430 \u041d\u041e\u0414(<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/ff7\/b47\/ee1\/ff7b47ee1bad37c9f279aa36bba97d01.svg\" alt=\"$16, 8$\" data-tex=\"inline\"><\/math>) \u0440\u0430\u0432\u0435\u043d <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dc0\/537\/0a7\/dc05370a7a9b97e8f4723f5a23022461.svg\" alt=\"$8$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u041d\u041e\u041a (\u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u043c \u043e\u0431\u0449\u0438\u043c \u043a\u0440\u0430\u0442\u043d\u044b\u043c) \u0434\u0432\u0443\u0445 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/839\/f25\/c27\/839f25c2746382debd4f08ea25ad5ecf.svg\" alt=\"$p$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d68\/cc4\/926\/d68cc4926bf74bae8fa3b51ca4a09ec8.svg\" alt=\"$q$\" data-tex=\"inline\"><\/math> \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u0447\u0438\u0441\u043b\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math> \u0442\u0430\u043a\u043e\u0435, \u0447\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math> \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/839\/f25\/c27\/839f25c2746382debd4f08ea25ad5ecf.svg\" alt=\"$p$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math> \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d68\/cc4\/926\/d68cc4926bf74bae8fa3b51ca4a09ec8.svg\" alt=\"$q$\" data-tex=\"inline\"><\/math>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u041d\u041e\u041a(<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/fdb\/286\/93f\/fdb28693faa2ecf3ab9469020660bbd1.svg\" alt=\"$2, 3$\" data-tex=\"inline\"><\/math>) \u0440\u0430\u0432\u0435\u043d <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a98\/05b\/342\/a9805b3422e51c726fc4b1931f2d51aa.svg\" alt=\"$6$\" data-tex=\"inline\"><\/math>, \u0430 \u041d\u041e\u041a(<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5c2\/471\/c62\/5c2471c627e32c5d89b242973880ec27.svg\" alt=\"$10, 20$\" data-tex=\"inline\"><\/math>) \u0440\u0430\u0432\u0435\u043d 20.<\/p>\n<p>  <a name=\"br\"><\/a><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<p>\u0415\u0441\u043b\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9b3\/4c4\/da5\/9b34c4da5c757d4982bbd1b6f2e8998a.svg\" alt=\"$y$\" data-tex=\"inline\"><\/math> \u043d\u0435 \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math>, \u0442\u043e \u043e\u0442\u0432\u0435\u0442, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e. <\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u0430\u0447\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043f\u0430\u0440\u0443 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/839\/f25\/c27\/839f25c2746382debd4f08ea25ad5ecf.svg\" alt=\"$p$\" data-tex=\"inline\"><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d68\/cc4\/926\/d68cc4926bf74bae8fa3b51ca4a09ec8.svg\" alt=\"$q$\" data-tex=\"inline\"><\/math>, \u0447\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/136\/557\/593\/13655759335015ef41160b1dd5e5adca.svg\" alt=\"$gcd(p, q) = x$\" data-tex=\"inline\"><\/math>, \u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/888\/06a\/4bb\/88806a4bb2e94edbf0367579bb539cfd.svg\" alt=\"$lcm(p, q) = y$\" data-tex=\"inline\"><\/math>. \u0421 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u043a\u043e\u0439 \u043f\u0430\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0432\u0430 \u0447\u0438\u0441\u043b\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e48\/3f4\/ca9\/e483f4ca9756a62cab32a18394afb4a0.svg\" alt=\"$p' = \\frac{p}{x}$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1c7\/d11\/aae\/1c7d11aae113f2634be259b7e8800705.svg\" alt=\"$q' = \\frac{q}{x}$\" data-tex=\"inline\"><\/math> \u0442\u0430\u043a\u0438\u0435, \u0447\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/91a\/27e\/a70\/91a27ea70021f12e4aea2993abb6f3eb.svg\" alt=\"$gcd(p', q') = 1$\" data-tex=\"inline\"><\/math>, \u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/152\/30d\/180\/15230d180523b930e29ecd95102977de.svg\" alt=\"$lcm(p', q') = \\frac{y}{x}$\" data-tex=\"inline\"><\/math>. <\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u0432\u0435\u0441\u0442\u0438 \u043a \u0437\u0430\u0434\u0430\u0447\u0435 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0430\u0440 \u0432\u0437\u0430\u0438\u043c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0447\u0438\u0441\u0435\u043b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/826\/cec\/efe\/826cecefefae504f9e79954dc80e110d.svg\" alt=\"$p'$\" data-tex=\"inline\"><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/126\/f7d\/a4a\/126f7da4aefaf17991f550dcd9be0ede.svg\" alt=\"$q'$\" data-tex=\"inline\"><\/math> \u0442\u0430\u043a\u0438\u0445, \u0447\u0442\u043e \u0438\u0445 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1d4\/b37\/d59\/1d4b37d590fb86008d4cbe27e3dfec70.svg\" alt=\"$lcm$\" data-tex=\"inline\"><\/math> \u0440\u0430\u0432\u0435\u043d <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5b4\/2e4\/e2f\/5b42e4e2f0ce4fac883639e09af6a8d5.svg\" alt=\"$\\frac{y}{x}$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c \u0447\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0b2\/996\/3b0\/0b29963b000c32b3e30f3a9b7dab1fac.svg\" alt=\"$x = 1$\" data-tex=\"inline\"><\/math>, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u0442\u043e \u0441\u0432\u043e\u0434\u0438\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043a \u0437\u0430\u0434\u0430\u0447\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c4e\/49f\/82d\/c4e49f82da32be126993ed787af15df0.svg\" alt=\"$x' = 1$\" data-tex=\"inline\"><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4fe\/21d\/2b7\/4fe21d2b75439a9f947a090f106c0519.svg\" alt=\"$y' = \\frac{y}{x}$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <b>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/b><\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f60\/8bb\/b88\/f608bbb88837f81b681dad8c59b8992e.svg\" alt=\"$O(factor(y) + number\\_of\\_divisors(y) \\cdot \\log{(y}))$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/826\/cec\/efe\/826cecefefae504f9e79954dc80e110d.svg\" alt=\"$p'$\" data-tex=\"inline\"><\/math>, \u0442\u043e\u0433\u0434\u0430 \u0435\u043c\u0443 \u0432 \u043f\u0430\u0440\u0443 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043e\u0439\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/256\/7c4\/ae9\/2567c4ae9006d493d48cd8b031bf9e41.svg\" alt=\"$q' = \\frac{y'}{p'}$\" data-tex=\"inline\"><\/math>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/06c\/018\/7a7\/06c0187a7dc26e48c03f1c31f17daa32.svg\" alt=\"$y' = lcm(p', q') = \\frac{p' \\cdot q'}{gcd(p', q')} = \\frac{p' \\cdot q'}{1} = p' \\cdot q'$\" data-tex=\"inline\"><\/math>. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u044d\u0442\u043e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e6d\/aef\/9b9\/e6daef9b906808ad0afd7500a1f81a4a.svg\" alt=\"$gcd(p', \\frac{y'}{p'}) = 1$\" data-tex=\"inline\"><\/math>, \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u0415\u0432\u043a\u043b\u0438\u0434\u0430 \u0437\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/523\/f9e\/021\/523f9e0213b24efa3fbb6e0a3115cc97.svg\" alt=\"$O(\\log{(y')})$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0434 \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u044e\u0431\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439. \u0421 \u0443\u0447\u0435\u0442\u043e\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0432\u0441\u0435\u0445 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math> \u0434\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/fbb\/323\/86f\/fbb32386fe31a5d9e08e01e8c0447ae4.svg\" alt=\"$\\sqrt{y'}$\" data-tex=\"inline\"><\/math>, \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f3b\/f89\/6ef\/f3bf896ef4ec462d2632527fca3328f8.svg\" alt=\"$O(\\sqrt{y'})$\" data-tex=\"inline\"><\/math>. \u0418\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439 \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u0438\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d40\/c38\/5b0\/d40c385b0face6a2027a26f0999125bf.svg\" alt=\"$2 \\cdot \\sqrt{y'}$\" data-tex=\"inline\"><\/math>, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443, \u0447\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e6d\/aef\/9b9\/e6daef9b906808ad0afd7500a1f81a4a.svg\" alt=\"$gcd(p', \\frac{y'}{p'}) = 1$\" data-tex=\"inline\"><\/math>, \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d40\/c38\/5b0\/d40c385b0face6a2027a26f0999125bf.svg\" alt=\"$2 \\cdot \\sqrt{y'}$\" data-tex=\"inline\"><\/math> \u0440\u0430\u0437, \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/599\/aca\/102\/599aca1022ad5433c1ba4d24f6c675fb.svg\" alt=\"$O(\\sqrt{y'}\\log{y'})$\" data-tex=\"inline\"><\/math>. <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08c\/70b\/215\/08c70b215c0c2b9431a1cd46523a8104.svg\" alt=\"$O(\\sqrt{y} \\log{(y)})$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 \u0421++<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;stdio.h&gt; #include &lt;iostream&gt; #include &lt;stdlib.h&gt; #include &lt;string&gt; #include &lt;string.h&gt; #include &lt;vector&gt; #include &lt;stack&gt; #include &lt;queue&gt; #include &lt;deque&gt; #include &lt;set&gt; #include &lt;map&gt; #include &lt;assert.h&gt; #include &lt;algorithm&gt; #include &lt;iomanip&gt; #include &lt;time.h&gt; #include &lt;math.h&gt; #include &lt;bitset&gt;  #pragma comment(linker, &quot;\/STACK:256000000&quot;)  using namespace std;  typedef long long int ll; typedef long double ld;  const int INF = 1000 * 1000 * 1000 + 21; const ll LLINF = (1ll &lt;&lt; 60) + 5; const int MOD = 1000 * 1000 * 1000 + 7;  ll gcd(ll a, ll b) {     return b ? gcd(b, a % b) : a; }  ll x, y;  int main() { #ifdef CH_EGOR     freopen(&quot;input.txt&quot;, &quot;r&quot;, stdin);     \/\/freopen(&quot;output.txt&quot;, &quot;w&quot;, stdout); #else     \/\/freopen(&quot;&quot;, &quot;r&quot;, stdin);     \/\/freopen(&quot;&quot;, &quot;w&quot;, stdout); #endif      scanf(&quot;%lld%lld&quot;, &amp;x, &amp;y);      if (y % x != 0) {         return 0 * printf(&quot;0\\n&quot;);     }      y \/= x;      ll ans = 0;     for (ll i = 1; i * i &lt;= y; ++i) {         if (y % i == 0) {             if (gcd(i, y \/ i) == 1) {                 ans += 1 + (i * i != y);             }         }     }      printf(&quot;%lld\\n&quot;, ans);      return 0; }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <b>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/b><\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/52a\/b7c\/4b3\/52ab7c4b32a33cd884d957018caad7ca.svg\" alt=\"$O(factor(y))$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4ec\/3e2\/363\/4ec3e23638b6073b649999485c251c94.svg\" alt=\"$z$\" data-tex=\"inline\"><\/math>, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u0435\u043b\u0438\u0442\u0441\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8f0\/1ce\/c44\/8f01cec44bfb67a87f4cbee549b21420.svg\" alt=\"$y'$\" data-tex=\"inline\"><\/math>. \u0415\u0441\u043b\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/046\/ac3\/653\/046ac36539ed958df0f9578605aa6fb0.svg\" alt=\"$lcm(p', q') = y'$\" data-tex=\"inline\"><\/math>, \u0442\u043e \u043b\u0438\u0431\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/826\/cec\/efe\/826cecefefae504f9e79954dc80e110d.svg\" alt=\"$p'$\" data-tex=\"inline\"><\/math>, \u043b\u0438\u0431\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/126\/f7d\/a4a\/126f7da4aefaf17991f550dcd9be0ede.svg\" alt=\"$q'$\" data-tex=\"inline\"><\/math> \u0434\u043e\u043b\u0436\u043d\u043e \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7e5\/1c3\/57f\/7e51c357f3ada0c7683156fb6df630e3.svg\" alt=\"$z^{\\alpha}$\" data-tex=\"inline\"><\/math>, \u0433\u0434\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/723\/4a5\/2ba\/7234a52ba041cdb09b9328a047048fb2.svg\" alt=\"$\\alpha$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0435\u043f\u0435\u043d\u044c, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4ec\/3e2\/363\/4ec3e23638b6073b649999485c251c94.svg\" alt=\"$z$\" data-tex=\"inline\"><\/math> \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8f0\/1ce\/c44\/8f01cec44bfb67a87f4cbee549b21420.svg\" alt=\"$y'$\" data-tex=\"inline\"><\/math>. \u0427\u0442\u043e\u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u043e\u0441\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/91a\/27e\/a70\/91a27ea70021f12e4aea2993abb6f3eb.svg\" alt=\"$gcd(p', q') = 1$\" data-tex=\"inline\"><\/math>, \u043e\u0434\u043d\u043e \u0438\u0437 \u044d\u0442\u0438\u0445 \u0447\u0438\u0441\u0435\u043b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4ec\/3e2\/363\/4ec3e23638b6073b649999485c251c94.svg\" alt=\"$z$\" data-tex=\"inline\"><\/math>. <\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u0435\u043b\u0438\u0442\u0441\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8f0\/1ce\/c44\/8f01cec44bfb67a87f4cbee549b21420.svg\" alt=\"$y'$\" data-tex=\"inline\"><\/math>, \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c, \u043f\u043e\u0439\u0434\u0435\u0442 \u043e\u043d\u043e \u0432 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/826\/cec\/efe\/826cecefefae504f9e79954dc80e110d.svg\" alt=\"$p'$\" data-tex=\"inline\"><\/math> \u0438\u043b\u0438 \u0432 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/126\/f7d\/a4a\/126f7da4aefaf17991f550dcd9be0ede.svg\" alt=\"$q'$\" data-tex=\"inline\"><\/math>. \u0422\u043e\u0433\u0434\u0430 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0430\u0432\u0435\u043d <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2c8\/127\/9e9\/2c81279e920ba54597c20e0cf5f1efde.svg\" alt=\"$2^{number\\_of\\_distinct\\_prime\\_divisors(y')}$\" data-tex=\"inline\"><\/math>.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Python<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">x, y = map(int, input().split())  if y % x != 0:     print(0) else:     y \/\/= x      i = 2     ans = 0     while i * i &lt;= y:         if y % i == 0:             ans += 1             while y % i == 0:                 y \/\/= i         i += 1      if y != 1:         ans += 1      print(2 ** ans)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 C++<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;stdio.h&gt; #include &lt;iostream&gt; #include &lt;stdlib.h&gt; #include &lt;string&gt; #include &lt;string.h&gt; #include &lt;vector&gt; #include &lt;stack&gt; #include &lt;queue&gt; #include &lt;deque&gt; #include &lt;set&gt; #include &lt;map&gt; #include &lt;assert.h&gt; #include &lt;algorithm&gt; #include &lt;iomanip&gt; #include &lt;time.h&gt; #include &lt;math.h&gt; #include &lt;bitset&gt;  #pragma comment(linker, &quot;\/STACK:256000000&quot;)  using namespace std;  typedef long long int ll; typedef long double ld;  const int INF = 1000 * 1000 * 1000 + 21; const ll LLINF = (1ll &lt;&lt; 60) + 5; const int MOD = 1000 * 1000 * 1000 + 7;  ll x, y;  int main() { #ifdef CH_EGOR     freopen(&quot;input.txt&quot;, &quot;r&quot;, stdin);     \/\/freopen(&quot;output.txt&quot;, &quot;w&quot;, stdout); #else     \/\/freopen(&quot;&quot;, &quot;r&quot;, stdin);     \/\/freopen(&quot;&quot;, &quot;w&quot;, stdout); #endif      scanf(&quot;%lld%lld&quot;, &amp;x, &amp;y);      if (y % x != 0) {         return 0 * printf(&quot;0\\n&quot;);     }      y \/= x;      ll ans = 0;     for (ll i = 2; i * i &lt;= y; ++i) {         if (y % i == 0) {             ++ans;             while (y % i == 0) {                 y \/= i;             }         }     }     ans += (y != 1);      printf(&quot;%lld\\n&quot;, (1ll &lt;&lt; ans));      return 0; }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.IOException; import java.io.InputStream;  \/**  * Built using CHelper plug-in  * Actual solution is at the top  *  * @author ch_egor  *\/ public class Main {     public static void main(String[] args) {         InputStream inputStream = System.in;         OutputStream outputStream = System.out;         InputReader in = new InputReader(inputStream);         OutputWriter out = new OutputWriter(outputStream);         GcdAndLcm solver = new GcdAndLcm();         solver.solve(1, in, out);         out.close();     }      static class GcdAndLcm {         public void solve(int testNumber, InputReader in, OutputWriter out) {             long x = in.nextLong();             long y = in.nextLong();              if (y % x != 0) {                 out.println(0);                 return;             }             y \/= x;              long ans = 0;             for (long i = 2; i * i &lt;= y; ++i) {                 if (y % i == 0) {                     ++ans;                     while (y % i == 0) {                         y \/= i;                     }                 }             }             if (y != 1) {                 ++ans;             }              out.println(1L &lt;&lt; ans);         }      }      static class InputReader {         private InputStream stream;         private byte[] buf = new byte[1024];         private int curChar;         private int numChars;         private InputReader.SpaceCharFilter filter;          public InputReader(InputStream stream) {             this.stream = stream;         }          public int read() {             if (numChars == -1) {                 throw new UnknownError();             }             if (curChar &gt;= numChars) {                 curChar = 0;                 try {                     numChars = stream.read(buf);                 } catch (IOException e) {                     throw new UnknownError();                 }                 if (numChars &lt;= 0) {                     return -1;                 }             }             return buf[curChar++];         }          public long nextLong() {             int c = read();             while (isSpaceChar(c)) {                 c = read();             }             int sgn = 1;             if (c == '-') {                 sgn = -1;                 c = read();             }             long res = 0;             do {                 if (c &lt; '0' || c &gt; '9') {                     throw new UnknownError();                 }                 res *= 10;                 res += c - '0';                 c = read();             } while (!isSpaceChar(c));             return res * sgn;         }          public boolean isSpaceChar(int c) {             if (filter != null) {                 return filter.isSpaceChar(c);             }             return isWhitespace(c);         }          public static boolean isWhitespace(int c) {             return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;         }          public interface SpaceCharFilter {             public boolean isSpaceChar(int ch);          }      }      static class OutputWriter {         private final PrintWriter writer;          public OutputWriter(OutputStream outputStream) {             writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));         }          public OutputWriter(Writer writer) {             this.writer = new PrintWriter(writer);         }          public void close() {             writer.close();         }          public void println(long i) {             writer.println(i);         }          public void println(int i) {             writer.println(i);         }      } }<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>  <a name=\"c\"><\/a><\/p>\n<h2>C. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u043d\u0430 \u043f\u043b\u044f\u0436\u0435<\/h2>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<td> <\/td>\n<td>\u0412\u0441\u0435 \u044f\u0437\u044b\u043a\u0438<\/td>\n<td>Python<\/td>\n<td>Java<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td>2 \u0441<\/td>\n<td colspan=\"2\">3 c<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td colspan=\"3\">256 \u041c\u0411<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0432\u043e\u0434<\/td>\n<td colspan=\"3\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u0432\u043e\u0434 <\/td>\n<\/tr>\n<tr>\n<td>\u0412\u044b\u0432\u043e\u0434<\/td>\n<td colspan=\"3\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 <\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p>\u041e\u0434\u043d\u0430\u0436\u0434\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0410\u043b\u0435\u043a\u0441\u0435\u0439 \u0438\u0437 \u042f\u043d\u0434\u0435\u043a\u0441\u0430 \u0432\u0437\u044f\u043b \u043e\u0442\u043f\u0443\u0441\u043a \u0438 \u0443\u0435\u0445\u0430\u043b \u043e\u0442\u0434\u044b\u0445\u0430\u0442\u044c \u043d\u0430 \u043c\u043e\u0440\u0435. \u0412 \u043e\u0434\u0438\u043d \u0438\u0437 \u0434\u043d\u0435\u0439 \u043e\u043d \u043f\u043e\u0448\u0435\u043b \u043d\u0430 \u043f\u043b\u044f\u0436, \u043f\u0440\u0438\u0447\u0435\u043c \u043f\u043e\u0448\u0435\u043b \u0442\u0443\u0434\u0430 \u043d\u0435 \u043e\u0434\u0438\u043d. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043e\u043d \u043f\u043e\u0448\u0435\u043b \u0442\u0443\u0434\u0430 \u0441 \u043c\u0430\u043c\u043e\u0439, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441 \u0431\u0430\u0431\u0443\u0448\u043a\u043e\u0439, \u0430, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441 \u0434\u0440\u0443\u0433\u043e\u043c \u0438\u043b\u0438 \u043f\u043e\u0434\u0440\u0443\u0433\u043e\u0439. \u0412\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u0448\u0435\u043b \u043e\u043d \u0442\u0443\u0434\u0430 \u043d\u0435 \u043e\u0434\u0438\u043d.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u043f\u043b\u044f\u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0410\u043b\u0435\u043a\u0441\u0435\u0439 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0435\u0433\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e0\/7ac\/f28\/3e07acf28d2303dfc70b16d918594082.svg\" alt=\"$2 \\leq n \\leq 10^6$\" data-tex=\"inline\"><\/math>) \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0445 \u043b\u0435\u0436\u0430\u043a\u043e\u0432. \u041d\u043e \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043b\u0435\u0436\u0430\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u0410\u043b\u0435\u043a\u0441\u0435\u044e \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c 2: \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e (\u0438\u043b\u0438 \u0442\u043e\u0439), \u0441 \u043a\u0435\u043c \u043e\u043d \u043f\u0440\u0438\u0448\u0435\u043b. \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0410\u043b\u0435\u043a\u0441\u0435\u0439 \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u043b \u043f\u043e\u0440\u044f\u0434\u043e\u043a, \u0442\u043e \u043e\u043d \u0445\u043e\u0442\u0435\u043b, \u0447\u0442\u043e\u0431\u044b \u043b\u0435\u0436\u0430\u043a\u0438 \u0431\u044b\u043b\u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0445\u043e\u0436\u0438 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430. \u041f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u044c \u043b\u0435\u0436\u0430\u043a\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<ul>\n<li> \u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u043b\u0435\u0436\u0430\u043a\u0443 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e \u0435\u0433\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0447\u0438\u0441\u043b\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/122\/b00\/691\/122b006916bcacd39b883735fa907bfa.svg\" alt=\"$a_i$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8e4\/cdd\/edf\/8e4cddedfead9717a26ada96e2b87c48.svg\" alt=\"$1 \\leq i \\leq n$\" data-tex=\"inline\"><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f94\/6d8\/092\/f946d809292e8e74cbb8f52b35fca3d0.svg\" alt=\"$0 \\leq a_i \\leq 10^9$\" data-tex=\"inline\"><\/math>). <\/li>\n<li> \u0417\u0430\u0442\u0435\u043c \u043d\u0435\u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u044c \u0434\u0432\u0443\u0445 \u043b\u0435\u0436\u0430\u043a\u043e\u0432 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a XOR (\u043f\u043e\u0431\u0438\u0442\u043e\u0432\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0435 \u0418\u041b\u0418) \u0447\u0438\u0441\u0435\u043b \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u044d\u0442\u0438\u043c \u043b\u0435\u0436\u0430\u043a\u0430\u043c. \u0427\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u0438 \u043c\u0435\u043d\u044c\u0448\u0435, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0445\u043e\u0436\u0438 \u043b\u0435\u0436\u0430\u043a\u0438. <\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u043e\u0433\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u0410\u043b\u0435\u043a\u0441\u0435\u044e \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u043e\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u0438 \u043b\u0435\u0436\u0430\u043a\u043e\u0432 \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0447\u044c, \u0441\u0440\u0430\u0432\u043d\u0438\u0432 \u043f\u043e\u043f\u0430\u0440\u043d\u043e \u0432\u0441\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0435 \u043b\u0435\u0436\u0430\u043a\u0438.<\/p>\n<p>  <\/p>\n<h4>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u0434\u0430\u043d\u043e \u0447\u0438\u0441\u043b\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/175\/f98\/839\/175f98839ab732db76d5f20cd6ce2ce9.svg\" alt=\"$T$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9f2\/474\/bcb\/9f2474bcb0bfe3fbf43e0e0fe84eb984.svg\" alt=\"$1 \\leq T \\leq 1000$\" data-tex=\"inline\"><\/math>) &ndash; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0435\u0441\u0442\u043e\u0432. \u041a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u0441\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u0442\u0440\u043e\u043a.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0437\u0430\u0434\u0430\u043d\u043e \u0447\u0438\u0441\u043b\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e0\/7ac\/f28\/3e07acf28d2303dfc70b16d918594082.svg\" alt=\"$2 \\leq n \\leq 10^6$\" data-tex=\"inline\"><\/math>) &ndash; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043b\u0435\u0436\u0430\u043a\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0437\u0430\u0434\u0430\u043d\u044b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> \u0447\u0438\u0441\u0435\u043b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/122\/b00\/691\/122b006916bcacd39b883735fa907bfa.svg\" alt=\"$a_i$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8e4\/cdd\/edf\/8e4cddedfead9717a26ada96e2b87c48.svg\" alt=\"$1 \\leq i \\leq n$\" data-tex=\"inline\"><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f94\/6d8\/092\/f946d809292e8e74cbb8f52b35fca3d0.svg\" alt=\"$0 \\leq a_i \\leq 10^9$\" data-tex=\"inline\"><\/math>) &ndash; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043b\u0435\u0436\u0430\u043a\u0430\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c.<\/p>\n<p>  <\/p>\n<p>\u0421\u0443\u043c\u043c\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> \u043f\u043e \u0432\u0441\u0435\u043c \u0442\u0435\u0441\u0442\u0430\u043c \u043d\u0435 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u0438\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8cb\/24f\/fc6\/8cb24ffc65f3fb246529ff336caaab93.svg\" alt=\"$10^6$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<h4>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e &ndash; \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u0438.<\/p>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b<\/h4>\n<p>  <\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 1 5 1 2 4 8 16 <\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 3  <\/pre>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 2 2 2 4 4 2 4 6 8 <\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 6 2 <\/pre>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/h4>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0410\u043b\u0435\u043a\u0441\u0435\u0439 \u0432\u044b\u0431\u0435\u0440\u0435\u0442 \u043b\u0435\u0436\u0430\u043a\u0438 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 1 \u0438 2.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0410\u043b\u0435\u043a\u0441\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u0436\u0430\u043a\u0438 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 2 \u0438 4. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043e\u043d \u0432\u044b\u0431\u0435\u0440\u0435\u0442 \u043b\u0435\u0436\u0430\u043a\u0438 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 4 \u0438 6.<\/p>\n<p>  <a name=\"cr\"><\/a><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\n<p>\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0432\u0441\u0435 \u0447\u0438\u0441\u043b\u0430 \u0432 \u0438\u0445 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0432 \u0432\u0435\u0434\u0443\u0449\u0438\u043c\u0438 \u043d\u0443\u043b\u044f\u043c\u0438 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u0434\u043b\u0438\u043d\u044b \u0431\u044b\u043b\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b. \u0414\u0430\u043b\u0435\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u043d\u0430 \u044d\u0442\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 \u0431\u043e\u0440, \u0433\u0434\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u043e\u0442 \u043a\u043e\u0440\u043d\u044f \u0440\u0435\u0431\u0440\u043e \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0440\u0448\u0438\u043c \u0440\u0430\u0437\u0440\u044f\u0434\u043e\u043c: \u0441\u043f\u0443\u0441\u043a\u0430\u044f\u0441\u044c \u0432\u0433\u043b\u0443\u0431\u044c \u0434\u0435\u0440\u0435\u0432\u0430, \u0432\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u0435 \u043e\u0442 \u0441\u0442\u0430\u0440\u0448\u0438\u0445 \u0440\u0430\u0437\u0440\u044f\u0434\u043e\u0432 \u043a \u043c\u043b\u0430\u0434\u0448\u0438\u043c. <\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u0439\u0434\u0435\u043c \u0432\u0441\u0435 \u0441\u0430\u043c\u044b\u0435 \u043e\u0442\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0435 \u043e\u0442 \u043a\u043e\u0440\u043d\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0440\u043e\u0432\u043d\u043e 2 \u0447\u0438\u0441\u043b\u0430. \u041a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u043a\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0447\u0438\u0441\u043b\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4ec\/3e2\/363\/4ec3e23638b6073b649999485c251c94.svg\" alt=\"$z$\" data-tex=\"inline\"><\/math>, \u0440\u0430\u0432\u043d\u043e\u0435 XOR \u043c\u0435\u0436\u0434\u0443 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u044d\u0442\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u0430. \u0422\u043e\u0433\u0434\u0430 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443 &ndash; \u044d\u0442\u043e \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0432\u0441\u0435\u0445 \u0447\u0438\u0441\u0435\u043b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4ec\/3e2\/363\/4ec3e23638b6073b649999485c251c94.svg\" alt=\"$z$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0438 \u043f\u0440\u0430\u0432\u0434\u0430 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443. \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 \u0432\u0441\u0435\u0445 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0432\u0435\u0440\u0448\u0438\u043d \u0434\u043e \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u043b\u0438\u0441\u0442\u044c\u0435\u0432 \u0447\u0438\u0441\u043b\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math> &ndash; \u043e\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0441\u0430\u043c\u044b\u0439 \u0441\u0442\u0430\u0440\u0448\u0438\u0439 \u0440\u0430\u0437\u0440\u044f\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0447\u0438\u0441\u043b\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f (\u0435\u0441\u043b\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4a0\/aa6\/3ea\/4a0aa63ea24c30df62d0d98999c6486f.svg\" alt=\"$k=0$\" data-tex=\"inline\"><\/math>, \u0442\u043e \u0447\u0438\u0441\u043b\u0430 \u0440\u0430\u0432\u043d\u044b). \u0422\u043e\u0433\u0434\u0430 XOR \u043c\u0435\u0436\u0434\u0443 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u043c\u0438 \u0440\u0430\u0437\u043d\u044b\u043c \u0441\u044b\u043d\u043e\u0432\u044c\u044f\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u043b\u0435\u0436\u0430\u0449\u0435\u0439 \u043d\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math> \u043e\u0442 \u043b\u0438\u0441\u0442\u044c\u0435\u0432, \u0431\u0443\u0434\u0435\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u0432 \u043e\u0442\u0440\u0435\u0437\u043a\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3ed\/7ba\/4c5\/3ed7ba4c557613b306d6de94edbac4df.svg\" alt=\"$[2^{x-1}, 2^x - 1]$\" data-tex=\"inline\"><\/math> (\u0434\u043b\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5b4\/098\/5e9\/5b40985e97972b4df8fab6b79bb2197d.svg\" alt=\"$x = 0$\" data-tex=\"inline\"><\/math> \u043e\u0442\u0432\u0435\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f9c\/3c8\/e48\/f9c3c8e488ead4696749012f5ece6d13.svg\" alt=\"$0$\" data-tex=\"inline\"><\/math>, \u0438\u0431\u043e \u0447\u0438\u0441\u043b\u0430 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442, \u0434\u043b\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0b2\/996\/3b0\/0b29963b000c32b3e30f3a9b7dab1fac.svg\" alt=\"$x=1$\" data-tex=\"inline\"><\/math> \u043e\u0442\u0432\u0435\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math>, \u0438\u0431\u043e \u0447\u0438\u0441\u043b\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0440\u0430\u0437\u0440\u044f\u0434\u0435, \u0434\u043b\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/de1\/136\/3fe\/de11363fe5cd6d7abcc8f21cc2315897.svg\" alt=\"$x=2$\" data-tex=\"inline\"><\/math> \u043e\u0442\u0432\u0435\u0442 \u043b\u0438\u0431\u043e 2, \u043b\u0438\u0431\u043e 3 \u0438 \u0442. \u0434.). \u0415\u0441\u043b\u0438 \u0436\u0435 \u043e\u0442\u0432\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u043d\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u0445, \u0442\u043e \u043f\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043d\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u0440\u0430\u0437\u0440\u044f\u0434\u0435, \u0441\u0442\u0430\u0440\u0448\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math>. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0447\u0438\u0441\u043b\u0430 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0445\u043e\u0442\u044f \u0431\u044b \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/629\/49c\/c28\/62949cc2886126a1d03b7c9a0a24c515.svg\" alt=\"$2^k$\" data-tex=\"inline\"><\/math>. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0435, \u0438\u0431\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u043f\u0430\u0440\u043d\u044b\u0439 XOR \u043c\u0435\u043d\u044c\u0448\u0435.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0431\u0435\u0437 \u043f\u043e\u043c\u043e\u0449\u0438 \u0431\u043e\u0440\u0430, \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0432 \u0432\u0441\u0435 \u0447\u0438\u0441\u043b\u0430 \u0438 \u0432\u0437\u044f\u0432 \u043f\u043e\u043f\u0430\u0440\u043d\u044b\u0439 XOR \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u043c\u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438. \u0412\u0435\u0434\u044c \u0432\u0441\u0435 \u0447\u0438\u0441\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u043b\u0438 \u0432 \u0441\u0430\u043c\u044b\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0440\u043e\u0432\u043d\u043e 2 \u0447\u0438\u0441\u043b\u0430, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438. \u042d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u0431\u043e\u0440\u0430 \u043d\u0438 \u043e\u0434\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0442\u0440\u0435\u0437\u043a\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/58b\/7f7\/be8\/58b7f7be8c846796f6af0f80072b3431.svg\" alt=\"$[a, b]$\" data-tex=\"inline\"><\/math>, \u0433\u0434\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/372\/e18\/546\/372e18546a3b7abb94c2672708bc5dfe.svg\" alt=\"$a$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/302\/c72\/04e\/302c7204ea9987e698a70307646abd71.svg\" alt=\"$b$\" data-tex=\"inline\"><\/math> &ndash; \u0447\u0438\u0441\u043b\u0430 \u0438\u0437 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u043d\u0430\u043c\u0438 \u0432\u0435\u0440\u0448\u0438\u043d\u044b.<\/p>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Python<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import sys   def read_int():     return int(sys.stdin.readline())       def read_ints():     return list(map(int, sys.stdin.readline().split()))           def main():     t = read_int()     for _ in range(t):         n = read_int()         a = sorted(read_ints())         r = a[0] ^ a[1]         for i in range(1, n):             r = min(r, a[i-1] ^ a[i])                      print(r)                   if __name__ == '__main__':     main()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 C++<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;algorithm&gt; #include &lt;cstdint&gt; #include &lt;cstdio&gt;  using namespace std;  int main() {   int t;   scanf(&quot;%d&quot;, &amp;t);   while (t--) {     int n;     scanf(&quot;%d&quot;, &amp;n);     int* v = (int*) malloc(sizeof(int) * n);     for (int i = 0; i &lt; n; ++i) {       scanf(&quot;%d&quot;, &amp;v[i]);     }     sort(v, v + n);     int ans = INT32_MAX;     for (int i = 1; i &lt; n; ++i) {       ans = min(ans, v[i] ^ v[i - 1]);     }     printf(&quot;%d\\n&quot;, ans);   }   return 0; }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.Arrays; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.lang.Math; import java.util.Scanner;   public class Main {     public static void main(String[] args) {         InputStream inputStream = System.in;         OutputStream outputStream = System.out;         Scanner in = new Scanner(inputStream);         PrintWriter out = new PrintWriter(outputStream);         PairwiseXor solver = new PairwiseXor();         int n = in.nextInt();         for (int i = 1; i &lt;= n; ++i) {             solver.solve(n, in, out);         }         out.close();     }          static class PairwiseXor {         public void solve(int testNumber, Scanner in, PrintWriter out) {             int n = in.nextInt();             int[] a = new int[n];             for (int i = 0; i &lt; n; ++i) {                 a[i] = in.nextInt();             }             Arrays.sort(a);             int answer = 2000000000;             for (int i = 1; i &lt; n; ++i) {                 answer = Math.min(answer, a[i - 1] ^ a[i]);             }             out.println(answer);         }     }       static class InputReader {         public BufferedReader reader;         public StringTokenizer tokenizer;           public InputReader(InputStream stream) {             reader = new BufferedReader(new InputStreamReader(stream), 32768);             tokenizer = null;         }           public String next() {             while (tokenizer == null || !tokenizer.hasMoreTokens()) {                 try {                     tokenizer = new StringTokenizer(reader.readLine());                 } catch (IOException e) {                     throw new RuntimeException(e);                 }             }             return tokenizer.nextToken();         }           public int nextInt() {             return Integer.parseInt(next());         }       } }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <a name=\"d\"><\/a><\/p>\n<h2>D. \u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432<\/h2>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<td> <\/td>\n<td>\u0412\u0441\u0435 \u044f\u0437\u044b\u043a\u0438<\/td>\n<td>Python<\/td>\n<td>Java<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td>1 \u0441<\/td>\n<td>5 c<\/td>\n<td>1 \u0441<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td colspan=\"3\">256 \u041c\u0411<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0432\u043e\u0434<\/td>\n<td colspan=\"3\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u0432\u043e\u0434 <\/td>\n<\/tr>\n<tr>\n<td>\u0412\u044b\u0432\u043e\u0434<\/td>\n<td colspan=\"3\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 <\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p>\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439, \u043e\u0434\u043d\u0430\u043a\u043e \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u044b \u042f\u043d\u0434\u0435\u043a\u0441\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441 \u043d\u0435\u0439 \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e2e\/33f\/15a\/e2e33f15a96008ca33579599483c4531.svg\" alt=\"$m$\" data-tex=\"inline\"><\/math> \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u0440\u0430\u0437\u0431\u0438\u0442\u044b\u0435 \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> \u0447\u0430\u043d\u043a\u043e\u0432. \u0414\u043b\u044f \u0434\u0435\u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u0447\u0430\u043d\u043a\u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438. \u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044e\u0442 \u0433\u0440\u0443\u043f\u043f\u0430\u043c\u0438. \u0417\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u0447\u0438\u0441\u043b\u0430\u043c\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/83a\/dca\/e30\/83adcae30344fad5003d3a4a185bdbac.svg\" alt=\"$a, b, l, r$\" data-tex=\"inline\"><\/math> \u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0437\u0430\u043a\u0430\u0437 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0447\u0430\u043d\u043a\u043e\u0432 \u0441 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u043e\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/30f\/b68\/14e\/30fb6814eea0091044df0e5de33dfbc2.svg\" alt=\"$l$\" data-tex=\"inline\"><\/math> \u0434\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/066\/939\/a33\/066939a33475dd671b845469b6526972.svg\" alt=\"$r$\" data-tex=\"inline\"><\/math> \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/372\/e18\/546\/372e18546a3b7abb94c2672708bc5dfe.svg\" alt=\"$a$\" data-tex=\"inline\"><\/math> \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/302\/c72\/04e\/302c7204ea9987e698a70307646abd71.svg\" alt=\"$b$\" data-tex=\"inline\"><\/math>. \u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0447\u0430\u043d\u043a\u0438 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/372\/e18\/546\/372e18546a3b7abb94c2672708bc5dfe.svg\" alt=\"$a$\" data-tex=\"inline\"><\/math> \u0441\u0442\u0438\u0440\u0430\u044e\u0442\u0441\u044f. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0430\u043d\u043a \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u043e\u0432\u043d\u043e \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435. \u041f\u0435\u0440\u0435\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u0447\u0430\u043d\u043a\u0438, \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435, \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/83a\/dca\/e30\/83adcae30344fad5003d3a4a185bdbac.svg\" alt=\"$a, b, l, r$\" data-tex=\"inline\"><\/math>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u0447\u0430\u043d\u043a\u0438 \u0441 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u043e\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/30f\/b68\/14e\/30fb6814eea0091044df0e5de33dfbc2.svg\" alt=\"$l$\" data-tex=\"inline\"><\/math> \u0434\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/066\/939\/a33\/066939a33475dd671b845469b6526972.svg\" alt=\"$r$\" data-tex=\"inline\"><\/math> \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/372\/e18\/546\/372e18546a3b7abb94c2672708bc5dfe.svg\" alt=\"$a$\" data-tex=\"inline\"><\/math>. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u043e, \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0415\u0441\u043b\u0438 \u0436\u0435 \u044d\u0442\u043e \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438 \u0432\u0441\u0435 \u0447\u0430\u043d\u043a\u0438 \u043e\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/30f\/b68\/14e\/30fb6814eea0091044df0e5de33dfbc2.svg\" alt=\"$l$\" data-tex=\"inline\"><\/math> \u0434\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/066\/939\/a33\/066939a33475dd671b845469b6526972.svg\" alt=\"$r$\" data-tex=\"inline\"><\/math> \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/372\/e18\/546\/372e18546a3b7abb94c2672708bc5dfe.svg\" alt=\"$a$\" data-tex=\"inline\"><\/math> \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/302\/c72\/04e\/302c7204ea9987e698a70307646abd71.svg\" alt=\"$b$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u0441\u043f\u0438\u0441\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0447\u0430\u043d\u043a\u043e\u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435, \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b.<\/p>\n<p>  <\/p>\n<h4>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u0434\u0430\u043d\u044b \u0442\u0440\u0438 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c3b\/824\/360\/c3b8243605784cac510b0db7e98e8563.svg\" alt=\"$n, m$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d68\/cc4\/926\/d68cc4926bf74bae8fa3b51ca4a09ec8.svg\" alt=\"$q$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/58b\/42f\/bae\/58b42fbae9394ddcd92665fcbb5a5dbe.svg\" alt=\"$1 \\leq n, q \\leq 100\\,000, 2 \\leq m \\leq 100\\,000$\" data-tex=\"inline\"><\/math>)&nbsp;&mdash; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0430\u043d\u043a\u043e\u0432 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0447\u0430\u043d\u043a\u0438, \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> \u0447\u0438\u0441\u0435\u043b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08b\/a9c\/561\/08ba9c56140cf603308f9b84a26dc818.svg\" alt=\"$p_i$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e22\/329\/888\/e22329888b33a87a8e38bb869ac904f7.svg\" alt=\"$1 \\leq p_i \\leq m$\" data-tex=\"inline\"><\/math>), <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/bf8\/3b5\/32c\/bf83b532cd867d34004f8eded8c5c79a.svg\" alt=\"$i$\" data-tex=\"inline\"><\/math>-\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043d\u043e\u043c\u0435\u0440 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0433\u0434\u0435 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0447\u0430\u043d\u043a \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/bf8\/3b5\/32c\/bf83b532cd867d34004f8eded8c5c79a.svg\" alt=\"$i$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d68\/cc4\/926\/d68cc4926bf74bae8fa3b51ca4a09ec8.svg\" alt=\"$q$\" data-tex=\"inline\"><\/math> \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0447\u0430\u043d\u043a\u043e\u0432 \u0432 \u0445\u0440\u043e\u043d\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0442\u0432\u0435\u0440\u043a\u043e\u0439 \u0447\u0438\u0441\u0435\u043b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f60\/32b\/58f\/f6032b58fe0a2ed1707e4e3a60cd0ef3.svg\" alt=\"$a_i, b_i, l_i, r_i$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/cb1\/d39\/023\/cb1d390236126607211a530efc0b0f20.svg\" alt=\"$1 \\leq a_i, b_i \\leq m, a_i \\neq b_i, 1 \\leq l_i \\leq r_i \\leq n$\" data-tex=\"inline\"><\/math>) \u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0437\u0430\u043a\u0430\u0437 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432 \u0441 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u0441 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/cdb\/d0f\/65b\/cdbd0f65bf0a1ff4171f268a95ec44c5.svg\" alt=\"$l_i$\" data-tex=\"inline\"><\/math> \u043f\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/300\/742\/edf\/300742edf17955ccd51dad394dde8966.svg\" alt=\"$r_i$\" data-tex=\"inline\"><\/math> (\u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e) \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/122\/b00\/691\/122b006916bcacd39b883735fa907bfa.svg\" alt=\"$a_i$\" data-tex=\"inline\"><\/math> \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/efc\/54b\/d54\/efc54bd547b1a0f308a2ae4281e7d6ed.svg\" alt=\"$b_i$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<h4>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  <\/p>\n<p>\u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d68\/cc4\/926\/d68cc4926bf74bae8fa3b51ca4a09ec8.svg\" alt=\"$q$\" data-tex=\"inline\"><\/math> \u0441\u0442\u0440\u043e\u043a. \u0412 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/bf8\/3b5\/32c\/bf83b532cd867d34004f8eded8c5c79a.svg\" alt=\"$i$\" data-tex=\"inline\"><\/math> \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math>, \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/bf8\/3b5\/32c\/bf83b532cd867d34004f8eded8c5c79a.svg\" alt=\"$i$\" data-tex=\"inline\"><\/math> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d, \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f9c\/3c8\/e48\/f9c3c8e488ead4696749012f5ece6d13.svg\" alt=\"$0$\" data-tex=\"inline\"><\/math>, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442. <\/p>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b<\/h4>\n<p>  <\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 1 2 1 1 1 2 1 1 <\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 1  <\/pre>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 1 2 1 1 2 1 1 1 <\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 0  <\/pre>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 5 5 6 1 2 3 4 5 1 2 1 1 2 3 1 3 4 2 4 4 2 5 1 4 3 2 2 3 3 2 3 3 <\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 1 0 1 0 0 1 <\/pre>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/h4>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0440\u0435\u0442\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440. \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/07c\/4b2\/7fe\/07c4b27fe2e03880114beb0f122587ce.svg\" alt=\"$[1, 2, 3, 4, 5]$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0447\u0430\u043d\u043a \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math> \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math> \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math>. \u0427\u0430\u043d\u043a \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043e. \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/598\/bfc\/da1\/598bfcda1cfac3e3d9610046de7ab1d3.svg\" alt=\"$[2, 2, 3, 4, 5]$\" data-tex=\"inline\"><\/math>. <\/p>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0447\u0430\u043d\u043a\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/db8\/e9d\/3f9\/db8e9d3f9d1d96507ff64a09084c5085.svg\" alt=\"$1, 2$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math> \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math> \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math>. \u0427\u0430\u043d\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math> \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043d\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math>, \u0430 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430. \u0420\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0438\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0447\u0430\u043d\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/578\/281\/d89\/578281d8997e0a562a02dd61422d408e.svg\" alt=\"$4$\" data-tex=\"inline\"><\/math> \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/578\/281\/d89\/578281d8997e0a562a02dd61422d408e.svg\" alt=\"$4$\" data-tex=\"inline\"><\/math> \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math>. \u0427\u0430\u043d\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/578\/281\/d89\/578281d8997e0a562a02dd61422d408e.svg\" alt=\"$4$\" data-tex=\"inline\"><\/math> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/578\/281\/d89\/578281d8997e0a562a02dd61422d408e.svg\" alt=\"$4$\" data-tex=\"inline\"><\/math>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043e. \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e51\/c9c\/4da\/e51c9c4da7e9602a2f1bb1c3218e1868.svg\" alt=\"$[2, 2, 3, 2, 5]$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0447\u0430\u043d\u043a\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/911\/24c\/f2f\/91124cf2f32311e6e4dcf85d89f6f55a.svg\" alt=\"$1, 2, 3$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/578\/281\/d89\/578281d8997e0a562a02dd61422d408e.svg\" alt=\"$4$\" data-tex=\"inline\"><\/math> \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math> \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/480\/820\/0cb\/4808200cb3668866f25a2e4437a6b74e.svg\" alt=\"$5$\" data-tex=\"inline\"><\/math>. \u0422\u0430\u043a \u043a\u0430\u043a \u0447\u0430\u043d\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math> \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math>, \u0430 \u043d\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math>, \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0438\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u044f\u0442\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0447\u0430\u043d\u043a\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math> \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math> \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math>, \u043d\u043e \u0447\u0430\u043d\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math> \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0438\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0448\u0435\u0441\u0442\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0447\u0430\u043d\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math> \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math> \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math>. \u0427\u0430\u043d\u043a \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043e \u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0430\u043d\u043a\u043e\u0432 \u0441\u0442\u0430\u043d\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/954\/21b\/e4c\/95421be4c06df1bb415c3f04d64ef80a.svg\" alt=\"$[2, 2, 2, 2, 5]$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <a name=\"dr\"><\/a><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\"><b>\u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431<\/b><\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0434\u0435\u043a\u0430\u0440\u0442\u043e\u0432\u0443 \u0434\u0435\u0440\u0435\u0432\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u043c\u0443 \u0432\u0441\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u043d\u0435\u043c \u0447\u0430\u043d\u043a\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438\u0437 \u0434\u0435\u043a\u0430\u0440\u0442\u043e\u0432\u0430 \u0434\u0435\u0440\u0435\u0432\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0435\u0440\u0448\u0438\u043d\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/372\/e18\/546\/372e18546a3b7abb94c2672708bc5dfe.svg\" alt=\"$a$\" data-tex=\"inline\"><\/math>, \u0432\u0441\u0435 \u0447\u0430\u043d\u043a\u0438 \u043e\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/30f\/b68\/14e\/30fb6814eea0091044df0e5de33dfbc2.svg\" alt=\"$l$\" data-tex=\"inline\"><\/math> \u0434\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/066\/939\/a33\/066939a33475dd671b845469b6526972.svg\" alt=\"$r$\" data-tex=\"inline\"><\/math>. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430 2 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 Split \u0438 \u043e\u0434\u043d\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e Merge, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/214\/875\/38a\/21487538a6dbcc06fa5704effedb4282.svg\" alt=\"$O(\\log n)$\" data-tex=\"inline\"><\/math>. \u0414\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0430\u043d\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0415\u0441\u043b\u0438 \u0438\u0445 \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c28\/ac5\/2be\/c28ac52be0596e962b6b618e6aa15c3e.svg\" alt=\"$r - l + 1$\" data-tex=\"inline\"><\/math>, \u0442\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u0430 \u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math>, \u0435\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u0442, \u0442\u043e \u043e\u0442\u0432\u0435\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f9c\/3c8\/e48\/f9c3c8e488ead4696749012f5ece6d13.svg\" alt=\"$0$\" data-tex=\"inline\"><\/math>. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0430\u043d\u043a\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0437\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/655\/b80\/5d6\/655b805d68b4b00a4e90f64eefbc6f1c.svg\" alt=\"$O(1)$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u0432\u044b\u0440\u0435\u0437\u0430\u043d\u043d\u044b\u0435 \u0447\u0430\u043d\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043b\u0438\u0431\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/372\/e18\/546\/372e18546a3b7abb94c2672708bc5dfe.svg\" alt=\"$a$\" data-tex=\"inline\"><\/math>, \u043b\u0438\u0431\u043e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/302\/c72\/04e\/302c7204ea9987e698a70307646abd71.svg\" alt=\"$b$\" data-tex=\"inline\"><\/math>. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0434\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 Split \u0438 \u0434\u0432\u0443\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 Merge, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u0430 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/214\/875\/38a\/21487538a6dbcc06fa5704effedb4282.svg\" alt=\"$O(\\log n)$\" data-tex=\"inline\"><\/math>. \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/015\/882\/5e4\/0158825e490e9d922aa7f1233f2ab89b.svg\" alt=\"$O(q \\log n)$\" data-tex=\"inline\"><\/math>. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f9c\/3c8\/e48\/f9c3c8e488ead4696749012f5ece6d13.svg\" alt=\"$0$\" data-tex=\"inline\"><\/math>, \u043d\u043e \u0430\u0441\u0438\u043c\u043f\u0442\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u043e \u043d\u0435 \u0443\u043b\u0443\u0447\u0448\u0438\u0442.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Python<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import sys import random  INF = 10**9 + 21  random.seed(227)   class Node(object):     def __init__(self, x, value):         self.x = x         self.value = value         self.y = random.randint(1, 10**9)          self.l = None         self.r = None  def merge(t1, t2):     if t1 is None:         return t2     if t2 is None:         return t1      if t1.y &lt; t2.y:         t1.r = merge(t1.r, t2)         return t1     else:         t2.l = merge(t1, t2.l)         return t2  def split(t, x):     if t is None:         return None, None      if t.x &lt; x:         t1, t2 = split(t.r, x)         t.r = t1         return t, t2     else:         t1, t2 = split(t.l, x)         t.l = t2         return t1, t  def add(t, nd):     if t is None:         return nd      if nd.y &lt; t.y:         nd.l, nd.r = split(t, nd.x)         return nd      root = t;      p = None     last_l = False     while t is not None and t.y &lt; nd.y:         p = t         if t.x &lt; nd.x:             last_l = False             t = t.r         else:             last_l = True             t = t.l      if last_l:         p.l = nd     else:         p.r = nd      nd.l, nd.r = split(t, nd.x)      return root  def remove(t, x):     if t.x == x:         return merge(t.l, t.r)      root = t      p = None     last_l = False     while t is not None and t.x != x:         p = t         if t.x &lt; x:             last_l = False             t = t.r         else:             last_l = True             t = t.l      if last_l:         p.l = merge(t.l, t.r)     else:         p.r = merge(t.l, t.r)      return root  def get_up(t, x):     cur = None     while t is not None:         if t.x &gt;= x and (cur is None or cur.x &gt; t.x):             cur = t          if t.x &gt;= x:             t = t.l         else:             t = t.r      return cur  def get_down(t, x):     cur = None     while t is not None:         if t.x &lt;= x and (cur is None or cur.x &lt; t.x):             cur = t          if t.x &gt;= x:             t = t.l         else:             t = t.r      return cur  def main():     n, m, q = map(int, sys.stdin.readline().split())     arr = list(map(int, sys.stdin.readline().split()))      tree = None      tree = add(tree, Node(0, INF))     tree = add(tree, Node(n + 1, INF))      for i in range(n):         if i == n - 1 or arr[i] != arr[i + 1]:             tree = add(tree, Node(i + 1, arr[i]))      ans = [&quot;0&quot; for i in range(q)]     for i in range(q):         a, b, l, r = map(int, sys.stdin.readline().split())          ptr1 = get_up(tree, l)         ptr2 = get_up(tree, r)          if ptr1 is ptr2 and ptr1.value == a:             pr = get_down(tree, l - 1)             if pr.x + 1 != l:                 tree = add(tree, Node(l - 1, a))              if pr.x + 1 == l and pr.value == b:                 tree = remove(tree, pr.x)              need_add = True             if r == ptr1.x:                 nx = get_up(tree, r + 1)                 if nx.value == b:                     need_add = False                 tree = remove(tree, r)              if need_add:                 tree = add(tree, Node(r, b))              ans[i] = &quot;1&quot;      sys.stdout.write(&quot;\\n&quot;.join(ans) + &quot;\\n&quot;)  main()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <b>\u0412\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431<\/b><\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0432\u0443\u043c\u044f \u0434\u0435\u0440\u0435\u0432\u044c\u044f\u043c\u0438 \u043e\u0442\u0440\u0435\u0437\u043a\u043e\u0432 c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c: \u043d\u0430 \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c. \u041a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u043e\u0442\u0440\u0435\u0437\u043a\u043e\u0432 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u043e\u043c\u0435\u0440\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0447\u0430\u043d\u043a\u043e\u0432. \u041f\u0440\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0438 \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043d\u0430 \u043e\u0442\u0440\u0435\u0437\u043a\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/ec2\/75c\/afd\/ec275cafd7fab68acbc29e53b1c7e5b4.svg\" alt=\"$[l, r]$\" data-tex=\"inline\"><\/math> \u0440\u0430\u0432\u043d\u044b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/372\/e18\/546\/372e18546a3b7abb94c2672708bc5dfe.svg\" alt=\"$a$\" data-tex=\"inline\"><\/math> &ndash; \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0432\u0435\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math>, \u0438\u043d\u0430\u0447\u0435 \u043e\u0442\u0432\u0435\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f9c\/3c8\/e48\/f9c3c8e488ead4696749012f5ece6d13.svg\" alt=\"$0$\" data-tex=\"inline\"><\/math>. \u0415\u0441\u043b\u0438 \u043e\u0442\u0432\u0435\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math>, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u044d\u0442\u043e\u043c \u043e\u0442\u0440\u0435\u0437\u043a\u0435 \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/302\/c72\/04e\/302c7204ea9987e698a70307646abd71.svg\" alt=\"$b$\" data-tex=\"inline\"><\/math>. \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u0430\u044f \u0436\u0435: <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/015\/882\/5e4\/0158825e490e9d922aa7f1233f2ab89b.svg\" alt=\"$O(q \\log n)$\" data-tex=\"inline\"><\/math>.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 C++<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;iostream&gt; #include &lt;vector&gt;  using namespace std;  vector&lt;int&gt; min_t; vector&lt;int&gt; max_t; vector&lt;int&gt; u; int p;  inline void update(int i) {   if (u[i]) {     int l = i &lt;&lt; 1;     int r = l ^ 1;     min_t[l] = u[i];     min_t[r] = u[i];     max_t[l] = u[i];     max_t[r] = u[i];     u[l] = u[i];     u[r] = u[i];     u[i] = 0;   } }  pair&lt;int, int&gt; get(int i, int l, int r, int ll, int rr) {   if (r &lt;= ll || rr &lt;= l) {     return make_pair(INT32_MAX, -1);   }   if (ll &lt;= l &amp;&amp; r &lt;= rr) {     return make_pair(min_t[i], max_t[i]);   }   update(i);   int m = (l + r) &gt;&gt; 1;   auto a = get(i &lt;&lt; 1, l, m, ll, rr);   auto b = get((i &lt;&lt; 1) ^ 1, m, r, ll, rr);   return make_pair(min(a.first, b.first), max(a.second, b.second)); }  void set(int i, int l, int r, int ll, int rr, int v) {   if (r &lt;= ll || rr &lt;= l) {     return;   }   if (ll &lt;= l &amp;&amp; r &lt;= rr) {     min_t[i] = v;     max_t[i] = v;     u[i] = v;     return;   }   update(i);   int m = (l + r) &gt;&gt; 1;   int a = i &lt;&lt; 1;   int b = (i &lt;&lt; 1) ^ 1;   set(a, l, m, ll, rr, v);   set(b, m, r, ll, rr, v);   min_t[i] = min(min_t[a], min_t[b]);   max_t[i] = max(max_t[a], max_t[b]); }  int main() {   ios_base::sync_with_stdio(false);   int n, m, q;   cin &gt;&gt; n &gt;&gt; m &gt;&gt; q;   p = 1;   while (p &lt; n) {     p &lt;&lt;= 1;   }   min_t.resize(p &lt;&lt; 1);   max_t.resize(p &lt;&lt; 1);   u.resize(p &lt;&lt; 1);   for (int i = 0; i &lt; n; ++i) {     cin &gt;&gt; min_t[i + p];     max_t[i + p] = min_t[i + p];   }   for (int i = p - 1; i &gt; 0; --i) {     min_t[i] = min(min_t[i &lt;&lt; 1], min_t[(i &lt;&lt; 1) ^ 1]);     max_t[i] = max(max_t[i &lt;&lt; 1], max_t[(i &lt;&lt; 1) ^ 1]);   }   while (q--) {     int a, b, l, r;     cin &gt;&gt; a &gt;&gt; b &gt;&gt; l &gt;&gt; r;     auto t = get(1, 0, p, --l, r);     if (t.first == a &amp;&amp; t.second == a) {       set(1, 0, p, l, r, b);       cout &lt;&lt; 1 &lt;&lt; endl;     } else {       cout &lt;&lt; 0 &lt;&lt; endl;     }   }   return 0; }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Python<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">MAX = 1000000000  n, m, q = map(int, input().split()) v = list(map(int, input().split()))  p = 1 while p &lt; n:     p *= 2  min_t = [0] * (p * 2) max_t = [0] * (p * 2) u = [0] * (p * 2) min_t[p:p+n] = v max_t[p:p+n] = v for i in range(p - 1, 0, -1):     min_t[i] = min(min_t[2 * i], min_t[2 * i + 1]);     max_t[i] = max(max_t[2 * i], max_t[2 * i + 1]);  def update(i):     if u[i] != 0 and i &lt; p:         a = i * 2         b = a + 1         min_t[a] = u[i]         min_t[b] = u[i]         max_t[a] = u[i]         max_t[b] = u[i]         u[a] = u[i]         u[b] = u[i]         u[i] = 0  def get(i, l, r, ll, rr):     if rr &lt;= l or r &lt;= ll:         return MAX, -1     if ll &lt;= l and r &lt;= rr:         return min_t[i], max_t[i]     update(i)     m = (l + r) \/ 2     a, b = get(i * 2, l, m, ll, rr);     c, d = get(i * 2 + 1, m, r, ll, rr);     return min(a, c), max(b, d)  def set(i, l, r, ll, rr, v):     if rr &lt;= l or r &lt;= ll:         return     if ll &lt;= l and r &lt;= rr:         min_t[i] = max_t[i] = u[i] = v         return     update(i)     m = (l + r) \/ 2     set(i * 2, l, m, ll, rr, v)     set(i * 2 + 1, m, r, ll, rr, v)     min_t[i] = min(min_t[i * 2], min_t[i * 2 + 1])     max_t[i] = max(max_t[i * 2], max_t[i * 2 + 1])  while q &gt; 0:     q -= 1     a, b, l, r = map(int, input().split())     l -= 1     c, d = get(1, 0, p, l, r)     if a == c == d:         print(1)         set(1, 0, p, l, r, b)     else:         print(0)<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>  <a name=\"e\"><\/a><\/p>\n<h2>E. \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0430<\/h2>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<td><\/td>\n<td>\u0412\u0441\u0435 \u044f\u0437\u044b\u043a\u0438<\/td>\n<td>Python<\/td>\n<td>Java<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td>1 \u0441<\/td>\n<td>3 c<\/td>\n<td>2 \u0441<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td colspan=\"3\">256 \u041c\u0411<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0432\u043e\u0434<\/td>\n<td colspan=\"3\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u0432\u043e\u0434 <\/td>\n<\/tr>\n<tr>\n<td>\u0412\u044b\u0432\u043e\u0434<\/td>\n<td colspan=\"3\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 <\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p>\u0414\u0430\u043d \u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u0439 \u043d\u0435\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0433\u0440\u0430\u0444 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/560\/bd9\/7f2\/560bd97f235311a36dff00db005e6ab5.svg\" alt=\"$G$\" data-tex=\"inline\"><\/math>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> \u0432\u0435\u0440\u0448\u0438\u043d \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e2e\/33f\/15a\/e2e33f15a96008ca33579599483c4531.svg\" alt=\"$m$\" data-tex=\"inline\"><\/math> \u0440\u0435\u0431\u0435\u0440. <\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0431\u0435\u0439\u0442\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0433\u0440\u0430\u0444\u0430 \u043d\u0430 \u0434\u0432\u0430 \u043d\u0435 \u043f\u0443\u0441\u0442\u044b\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0431\u0440\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0435\u0441\u0430, \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0435\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u0438\u043c\u0435\u043b\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0435\u0441. <\/p>\n<p>  <\/p>\n<p>\u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0433\u0440\u0430\u0444 \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u0435\u0442\u0435\u043b\u044c \u0438 \u0435\u0433\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0431\u0440\u0430 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u043e.<\/p>\n<p>  <\/p>\n<h4>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u0434\u0430\u043d\u043e \u0447\u0438\u0441\u043b\u043e \u0432\u0435\u0440\u0448\u0438\u043d <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0f2\/e5d\/68f\/0f2e5d68ff8a1961d6eec47b044610e4.svg\" alt=\"$3 \\leq n \\leq 10^5$\" data-tex=\"inline\"><\/math>) \u0438 \u0447\u0438\u0441\u043b\u043e \u0440\u0435\u0431\u0435\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e2e\/33f\/15a\/e2e33f15a96008ca33579599483c4531.svg\" alt=\"$m$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/250\/795\/4c6\/2507954c64d8e1c64f8f34dc9c076d67.svg\" alt=\"$3\\leq m \\leq 10^5$\" data-tex=\"inline\"><\/math>) \u0433\u0440\u0430\u0444\u0430. <\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e2e\/33f\/15a\/e2e33f15a96008ca33579599483c4531.svg\" alt=\"$m$\" data-tex=\"inline\"><\/math> \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0437\u0430\u0434\u0430\u043d\u044b \u0440\u0435\u0431\u0440\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/784\/f98\/db3\/784f98db37a499162c1479600e8465ed.svg\" alt=\"$u$\" data-tex=\"inline\"><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1c1\/778\/187\/1c1778187263268cc347012d16da61e2.svg\" alt=\"$v$\" data-tex=\"inline\"><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1d0\/034\/a09\/1d0034a09108db7af7cf42ea23a91ecd.svg\" alt=\"$w$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5a3\/9b9\/30c\/5a39b930cc1a4653783ccaea20a0749d.svg\" alt=\"$1\\leq u, v \\leq n$\" data-tex=\"inline\"><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e4b\/109\/5aa\/e4b1095aaf618e528bc003e1224057ea.svg\" alt=\"$u\\neq v$\" data-tex=\"inline\"><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b82\/87c\/e12\/b8287ce12fc0cc3e4c466adeddf6c5b5.svg\" alt=\"$1 \\leq w \\leq 10^5$\" data-tex=\"inline\"><\/math>), \u0433\u0434\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/784\/f98\/db3\/784f98db37a499162c1479600e8465ed.svg\" alt=\"$u$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1c1\/778\/187\/1c1778187263268cc347012d16da61e2.svg\" alt=\"$v$\" data-tex=\"inline\"><\/math> \u0437\u0430\u0434\u0430\u044e\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u0443\u044e \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0440\u0435\u0431\u0440\u0430, \u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1d0\/034\/a09\/1d0034a09108db7af7cf42ea23a91ecd.svg\" alt=\"$w$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u0435\u0433\u043e \u0432\u0435\u0441.<\/p>\n<p>  <\/p>\n<h4>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  <\/p>\n<p>\u0412 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0432\u0435\u0441 \u0440\u0435\u0431\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u043c\u0435\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0435\u0441 \u0441\u0440\u0435\u0434\u0438 \u0442\u0435\u0445, \u0447\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0442 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u043e\u0434\u043d\u043e\u043c\u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443.<\/p>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b<\/h4>\n<p>  <\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 3 4 1 2 1 1 2 2 1 3 3 3 2 4 <\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 4  <\/pre>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 4 5 1 2 1 2 3 1 3 4 1 4 1 1 2 4 2 <\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 2 <\/pre>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/h4>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0443\u0441\u043b\u043e\u0432\u0438\u044f. \u0412 \u043d\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e 3 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044e, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u043d\u0438\u0445: <\/p>\n<ul>\n<li> <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/72c\/ef0\/e99\/72cef0e99a9c7ac968b44cbc2128d8a5.svg\" alt=\"$\\{\\{1, 2\\}, \\{3\\}\\}$\" data-tex=\"inline\"><\/math>, \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0435\u0431\u0440\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfd\/8a0\/d2f\/dfd8a0d2fe6ea30b4cde7f570eca349b.svg\" alt=\"$2$\" data-tex=\"inline\"><\/math> \u0431\u0443\u0434\u0443\u0442 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0442\u0432\u0435\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math>; <\/li>\n<li> <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b25\/9fa\/bc5\/b259fabc50724b5c30686509a4fc8eb4.svg\" alt=\"$\\{\\{1, 3\\}, \\{2\\}\\}$\" data-tex=\"inline\"><\/math>, \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0431\u0440\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math> \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0442\u0432\u0435\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e3\/28e\/c65\/3e328ec6538d48db0bbd8e0859e6d10a.svg\" alt=\"$3$\" data-tex=\"inline\"><\/math>; <\/li>\n<li> <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/23f\/317\/c03\/23f317c03cf3edd8894f4434a188ddcc.svg\" alt=\"$\\{\\{2, 3\\}, \\{1\\}\\}$\" data-tex=\"inline\"><\/math>, \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0431\u0440\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/578\/281\/d89\/578281d8997e0a562a02dd61422d408e.svg\" alt=\"$4$\" data-tex=\"inline\"><\/math> \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0442\u0432\u0435\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/578\/281\/d89\/578281d8997e0a562a02dd61422d408e.svg\" alt=\"$4$\" data-tex=\"inline\"><\/math>. <\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c, \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0442\u0435\u0441\u0442 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0442\u0435\u0441\u0442\u0435 \u043e\u0442\u0432\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0ff\/493\/e72\/0ff493e7228743bd0202ca0b6e5c28ea.svg\" alt=\"$\\{\\{1, 3\\}, \\{2, 4\\}\\}$\" data-tex=\"inline\"><\/math>. \u041b\u0435\u0433\u043a\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u0432 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0442\u0432\u0435\u0442 \u0431\u044b\u043b \u0431\u044b \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n<p>  <a name=\"er\"><\/a><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\n<p>\u0420\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u043e\u0442\u0432\u0435\u0442\u0443.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0442 \u2014 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math>. \u0422\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u0440\u0435\u0431\u0440\u0430, \u0432\u0435\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u0435\u043d\u044c\u0448\u0435 \u043b\u0438\u0431\u043e \u0440\u0430\u0432\u0435\u043d <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math>, \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0443\u0434\u043e\u043b\u044c\u043d\u044b\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u0440\u0430\u0444, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u0440\u0435\u0431\u0440\u0430\u0445 \u0441 \u0432\u0435\u0441\u043e\u043c, \u043c\u0435\u043d\u044c\u0448\u0438\u043c \u043b\u0438\u0431\u043e \u0440\u0430\u0432\u043d\u044b\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math>. \u041f\u043e\u043a\u0430\u0436\u0435\u043c \u043c\u043e\u043d\u043e\u0442\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math>. \u0422\u0430\u043a, \u0435\u0441\u043b\u0438 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math> \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0433\u0440\u0430\u0444, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0439 \u0443\u0441\u043b\u043e\u0432\u0438\u044e, \u0442\u043e \u0433\u0440\u0430\u0444 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5bc\/8dd\/688\/5bc8dd68843cfe22ca2dbb2ecd151e70.svg\" alt=\"$y &lt; x$\" data-tex=\"inline\"><\/math>. \u042d\u0442\u043e \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u043b\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9b3\/4c4\/da5\/9b34c4da5c757d4982bbd1b6f2e8998a.svg\" alt=\"$y$\" data-tex=\"inline\"><\/math> \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u043a\u0430\u043a \u0438 \u0434\u043b\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math>, \u0430 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0435\u0431\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c\u0438 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0435\u0441, \u0431\u043e\u043b\u044c\u0448\u0435 \u043b\u0438\u0431\u043e \u0440\u0430\u0432\u043d\u044b\u0439 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f8d\/9ee\/6d0\/f8d9ee6d05400fc8c5f5d1133a54f633.svg\" alt=\"$x &gt; y$\" data-tex=\"inline\"><\/math>. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math> \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0433\u0440\u0430\u0444, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0439 \u0443\u0441\u043b\u043e\u0432\u0438\u044e, \u0442\u043e \u0435\u0433\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438 \u0434\u043b\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c5d\/234\/99a\/c5d23499afbb088b22ecbe70168d281b.svg\" alt=\"$z &gt; x$\" data-tex=\"inline\"><\/math>, \u0442\u0430\u043a \u043a\u0430\u043a \u0433\u0440\u0430\u0444, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u0440\u0435\u0431\u0440\u0430\u0445 \u0432\u0435\u0441\u043e\u043c \u043c\u0435\u043d\u044c\u0448\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math>, \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0432\u0443\u0434\u043e\u043b\u044c\u043d\u044b\u043c (\u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0435\u0431\u0440\u043e \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c\u0438 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430), \u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0440\u0435\u0431\u0435\u0440 \u043d\u0435\u043b\u044c\u0437\u044f \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u0432\u0443\u0434\u043e\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0433\u0440\u0430\u0444\u0430.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0433\u0440\u0430\u0444 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044e, \u0442\u043e \u0435\u0441\u0442\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0432\u0443\u0434\u043e\u043b\u044c\u043d\u044b\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043e\u0431\u0445\u043e\u0434 \u0432\u0441\u0435\u0445 \u0432\u0435\u0440\u0448\u0438\u043d (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u043b\u0438\u0431\u043e \u0432 \u0448\u0438\u0440\u0438\u043d\u0443) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u0438. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0445\u043e\u0434\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f9c\/3c8\/e48\/f9c3c8e488ead4696749012f5ece6d13.svg\" alt=\"$0$\" data-tex=\"inline\"><\/math> \u043b\u0438\u0431\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math>. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a: <\/p>\n<ul>\n<li> \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043e\u0431\u0445\u043e\u0434 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f9c\/3c8\/e48\/f9c3c8e488ead4696749012f5ece6d13.svg\" alt=\"$0$\" data-tex=\"inline\"><\/math>. <\/li>\n<li> \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043f\u043e \u0440\u0435\u0431\u0440\u0443 \u043e\u0442 \u0432\u0435\u0440\u0448\u0438\u043d\u044b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/372\/e18\/546\/372e18546a3b7abb94c2672708bc5dfe.svg\" alt=\"$a$\" data-tex=\"inline\"><\/math> \u043a \u0432\u0435\u0440\u0448\u0438\u043d\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/302\/c72\/04e\/302c7204ea9987e698a70307646abd71.svg\" alt=\"$b$\" data-tex=\"inline\"><\/math> \u0432\u0435\u0440\u0448\u0438\u043d\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/302\/c72\/04e\/302c7204ea9987e698a70307646abd71.svg\" alt=\"$b$\" data-tex=\"inline\"><\/math> \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0447\u0438\u0441\u043b\u043e, \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u043e\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/372\/e18\/546\/372e18546a3b7abb94c2672708bc5dfe.svg\" alt=\"$a$\" data-tex=\"inline\"><\/math> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e79\/65d\/da4\/e7965dda46f482d032134743ea711648.svg\" alt=\"$val[a] = 0$\" data-tex=\"inline\"><\/math>, \u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e30\/ea7\/e1b\/e30ea7e1b769c35875162f055e4c7320.svg\" alt=\"$val[b] = 1$\" data-tex=\"inline\"><\/math>, \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442). <\/li>\n<\/ul>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043e\u0431\u0445\u043e\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0435\u0431\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0447\u0438\u0441\u043b\u043e. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u0442\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0433\u0440\u0430\u0444 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0432\u0443\u0434\u043e\u043b\u044c\u043d\u044b\u043c.  <\/p>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0434\u043d\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0430\u0432\u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8fe\/7b7\/c62\/8fe7b7c623744e5a9e0847cbbb8937bf.svg\" alt=\"$O(n + m)$\" data-tex=\"inline\"><\/math>, \u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/ce1\/396\/f31\/ce1396f3153c7754948c70b53eb80699.svg\" alt=\"$O((n + m) \\log \\max w)$\" data-tex=\"inline\"><\/math>.<\/p>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Python<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import sys  def bfs(g, cl, m, v):     qu = [v]     cl[v] = 1      l = 0     while l != len(qu):         v = qu[l]         l += 1          for u, w in g[v]:             if w &gt; m:                 continue             if cl[u] == 0:                 cl[u] = 3 - cl[v]                 qu.append(u)             elif cl[v] == cl[u]:                 return False      return True  def check(g, m):     cl = [0 for i in range(len(g))]      for i in range(len(g)):         if cl[i] == 0 and not bfs(g, cl, m, i):             return False      return True  def main():     n, m = map(int, sys.stdin.readline().split())     ed = [tuple(map(int, sys.stdin.readline().split())) for i in range(m)]      g = [[] for i in range(n)]     mx = 0     for v, u, w in ed:         g[v - 1].append((u - 1, w))         g[u - 1].append((v - 1, w))         mx = max(mx, w)      if check(g, mx):         sys.stdout.write(str(mx) + &quot;\\n&quot;)         return      l = 0     r = mx + 1      while r - l &gt; 1:         m = (l + r) \/\/ 2         if check(g, m):             l = m         else:             r = m      sys.stdout.write(str(r) + &quot;\\n&quot;)  main()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 C++<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;algorithm&gt; #include &lt;string&gt; #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;utility&gt;  struct Solution {     int n, m;     std::vector&lt;std::vector&lt;std::pair&lt;int, int&gt;&gt;&gt; graph;     std::vector&lt;int&gt; colors;      bool dfs(int v, int color, int bound) {         colors[v] = color;         for (const auto &amp;edge : graph[v]) {             if (edge.second &gt;= bound) {                 continue;             }             if (colors[edge.first] == color) {                 return false;             }             if (colors[edge.first] == -1) {                 if (!dfs(edge.first, 1 - color, bound)) {                     return false;                 }             }         }         return true;     }      bool check(int bound) {         for (int i = 0; i &lt; n; i++) {             if (colors[i] == -1) {                 if (!dfs(i, 0, bound)) {                     return false;                 }             }         }         return true;     }      void run(std::istream &amp;in, std::ostream &amp;out) {         in &gt;&gt; n &gt;&gt; m;         graph.assign(n, std::vector&lt;std::pair&lt;int, int&gt;&gt;());         for (int i = 0; i &lt; m; i++) {             int u, v, w;             in &gt;&gt; u &gt;&gt; v &gt;&gt; w;             u--;             v--;             graph[u].emplace_back(v, w);             graph[v].emplace_back(u, w);         }         int l = 0;         int r = 1000000001;         while (r - l &gt; 1) {             int m = (l + r) \/ 2;             colors.assign(n, -1);             if (!check(m)) {                 r = m;             } else {                 l = m;             }         }         out &lt;&lt; l &lt;&lt; &quot;\\n&quot;;     } };  int main() {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     Solution().run(std::cin, std::cout);     return 0; }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream;  \/**  * Built using CHelper plug-in  * Actual solution is at the top  *\/ public class Graph_AD_Correct {     public static void main(String[] args) {         InputStream inputStream = System.in;         OutputStream outputStream = System.out;         InputReader in = new InputReader(inputStream);         OutputWriter out = new OutputWriter(outputStream);         Graph solver = new Graph();         solver.solve(1, in, out);         out.close();     }      static class Graph {         public void solve(int testNumber, InputReader in, OutputWriter out) {             int n = in.readInt();             int m = in.readInt();             \/\/noinspection unchecked             List&lt;Graph.Edge&gt;[] g = new List[n];             for (int i = 0; i &lt; n; i++) {                 g[i] = new ArrayList&lt;&gt;();             }             int left = Integer.MAX_VALUE;             int right = Integer.MIN_VALUE;             for (int i = 0; i &lt; m; i++) {                 int x = in.readInt() - 1;                 int y = in.readInt() - 1;                 int w = in.readInt();                 g[x].add(new Graph.Edge(y, w));                 g[y].add(new Graph.Edge(x, w));                 left = Math.min(left, w);                 right = Math.max(right, w);             }             int[] color = new int[n];             int ans = -1;             while (left &lt;= right) {                 int mid = (left + right) \/ 2;                 if (isBipartite(n, color, g, mid)) {                     ans = mid;                     left = mid + 1;                 } else {                     right = mid - 1;                 }             }             if (ans == -1) {                 throw new AssertionError();             }             out.printLine(ans);         }          private boolean isBipartite(int n, int[] color, List&lt;Graph.Edge&gt;[] g, int mid) {             Arrays.fill(color, -1);             for (int i = 0; i &lt; n; i++) {                 if (color[i] == -1) {                     if (!dfs(i, -1, 0, color, g, mid)) {                         return false;                     }                 }             }             return true;         }          private boolean dfs(int x, int p, int curColor, int[] color, List&lt;Graph.Edge&gt;[] g, int mid) {             color[x] = curColor;             for (Graph.Edge e : g[x]) {                 if (e.w &gt;= mid) {                     continue;                 }                 int y = e.to;                 if (y == p) {                     continue;                 }                 if (color[y] == color[x]) {                     return false;                 }                 if (color[y] == -1 &amp;&amp; !dfs(y, x, 1 - curColor, color, g, mid)) {                     return false;                 }             }             return true;         }          static class Edge {             int to;             int w;              Edge(int to, int w) {                 this.to = to;                 this.w = w;             }          }      }      static class OutputWriter {         private final PrintWriter writer;          public OutputWriter(OutputStream outputStream) {             writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));         }          public OutputWriter(Writer writer) {             this.writer = new PrintWriter(writer);         }          public void close() {             writer.close();         }          public void printLine(int i) {             writer.println(i);         }      }      static class InputReader {         private InputStream stream;         private byte[] buf = new byte[1024];         private int curChar;         private int numChars;         private InputReader.SpaceCharFilter filter;          public InputReader(InputStream stream) {             this.stream = stream;         }          public int read() {             if (numChars == -1) {                 throw new InputMismatchException();             }             if (curChar &gt;= numChars) {                 curChar = 0;                 try {                     numChars = stream.read(buf);                 } catch (IOException e) {                     throw new InputMismatchException();                 }                 if (numChars &lt;= 0) {                     return -1;                 }             }             return buf[curChar++];         }          public int readInt() {             int c = read();             while (isSpaceChar(c)) {                 c = read();             }             int sgn = 1;             if (c == '-') {                 sgn = -1;                 c = read();             }             int res = 0;             do {                 if (c &lt; '0' || c &gt; '9') {                     throw new InputMismatchException();                 }                 res *= 10;                 res += c - '0';                 c = read();             } while (!isSpaceChar(c));             return res * sgn;         }          public boolean isSpaceChar(int c) {             if (filter != null) {                 return filter.isSpaceChar(c);             }             return isWhitespace(c);         }          public static boolean isWhitespace(int c) {             return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;         }          public interface SpaceCharFilter {             public boolean isSpaceChar(int ch);          }      } }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <a name=\"f\"><\/a><\/p>\n<h2>F. \u041f\u043e\u0438\u0441\u043a<\/h2>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<td><\/td>\n<td>\u0412\u0441\u0435 \u044f\u0437\u044b\u043a\u0438<\/td>\n<td>Python<\/td>\n<td>Java<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td>2 \u0441<\/td>\n<td>4 c<\/td>\n<td>2 c<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442<\/td>\n<td colspan=\"3\">512 \u041c\u0411<\/td>\n<\/tr>\n<tr>\n<td>\u0412\u0432\u043e\u0434<\/td>\n<td colspan=\"3\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u0432\u043e\u0434 <\/td>\n<\/tr>\n<tr>\n<td>\u0412\u044b\u0432\u043e\u0434<\/td>\n<td colspan=\"3\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 <\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u042f\u043d\u0434\u0435\u043a\u0441.\u041f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043d\u0430\u0434 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0440\u0430\u043d\u0436\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0434\u0438\u043d \u0438\u0437 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u043e\u0442\u044f\u0442 \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c, \u0442\u0430\u043a\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0442\u0440\u0435\u0445 \u044d\u0442\u0430\u043f\u043e\u0432: \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0431\u0430\u0437\u0435, \u043e\u0442\u0431\u043e\u0440 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0431\u0430\u0437\u0435 \u043e\u0442\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432-\u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u043a\u0430\u0437\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e. \u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0443 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e&nbsp;&mdash; \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e. \u0427\u0435\u043c \u0432\u044b\u0448\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c, \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0430\u0436\u0435 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0443. <\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u043d\u0436\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0445\u0440\u0430\u043d\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0437\u0430\u043a\u043e\u043b\u044c\u0446\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e\u0441\u043b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/bf8\/3b5\/32c\/bf83b532cd867d34004f8eded8c5c79a.svg\" alt=\"$i$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/48f\/8eb\/986\/48f8eb986179e96ba18449a97cf92914.svg\" alt=\"$i &lt; n$\" data-tex=\"inline\"><\/math>) \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b2d\/781\/41c\/b2d78141c2233ba9627a56bf0e895287.svg\" alt=\"$i + 1$\" data-tex=\"inline\"><\/math>, \u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u043e\u0441\u043b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math>. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u0431\u043e\u0440\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u044b\u0431\u0435\u0440\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c) \u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u043d\u0430 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u043e\u0442\u0431\u043e\u0440\u0435, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u0430\u043b\u0435\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u043e \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math>. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u0441\u043b\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442. \u041e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<p>  <\/p>\n<p>\u0420\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u0432\u044b\u0434\u0430\u0447\u0438 \u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0441\u0443\u043c\u043c\u0443 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043d\u0435\u0439. \u041f\u043e \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044f\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0438\u0441\u043a\u0430, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435, \u043a\u0430\u043a\u0443\u044e \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0434\u0430\u0447\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430.<\/p>\n<p>  <\/p>\n<h4>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u0434\u0430\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9b0\/012\/4e4\/9b00124e411362185d05b841bc32695f.svg\" alt=\"$t$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432. \u0414\u0430\u043b\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<p>  <\/p>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0441\u0442\u0440\u043e\u043a. <\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u0434\u0430\u043d\u043e \u0434\u0432\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a2d\/9c9\/397\/a2d9c9397ad8e55e5b45eb061cb6cc04.svg\" alt=\"$1 \\leq n \\leq 100\\,000$\" data-tex=\"inline\"><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/abf\/9c4\/410\/abf9c441055c46f6b3a3a36d45056cc8.svg\" alt=\"$0 \\leq k \\leq min(n - 1, 100)$\" data-tex=\"inline\"><\/math>)&nbsp;&mdash; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0438\u0441\u043a\u0430, \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u0430\u043b\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. <\/p>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/122\/b00\/691\/122b006916bcacd39b883735fa907bfa.svg\" alt=\"$a_i$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4e8\/5b0\/be4\/4e85b0be4b78bbb4483d9184c312ef65.svg\" alt=\"$-10^9 \\leq a_i \\leq 10^9$\" data-tex=\"inline\"><\/math>)&nbsp;&mdash; \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0447\u0442\u043e \u0441\u0443\u043c\u043c\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/08d\/9fa\/efb\/08d9faefbe272bdf8fbb80773542e343.svg\" alt=\"$n$\" data-tex=\"inline\"><\/math> \u043f\u043e \u0432\u0441\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c \u0441\u043b\u0443\u0447\u0430\u044f\u043c \u043d\u0435 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u0438\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a34\/61b\/e79\/a3461be79386363ec88a5d7c86f01446.svg\" alt=\"$100\\,000$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<h4>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h4>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043e\u0434\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e&nbsp;&mdash; \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440<\/h4>\n<p>  <\/p>\n<p>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 6 4 0 1 -2 9 10 6 1 5 -5 5 -5 5 -5 6 2 5 -5 5 -5 5 -5 4 3 5 -5 5 -5 8 1 -3 -1 5 6 -200 -200 5 -1 3 1 -1 -2 -3 <\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<pre> 20 10 15 10 14 -1 <\/pre>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/h4>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0433\u043e\u0434\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/87f\/b66\/6e5\/87fb666e57e51cf3d068c23b82f29915.svg\" alt=\"$9$\" data-tex=\"inline\"><\/math> \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u0435\u0433\u043e \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 2 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430. \u041d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0433\u043e\u0434\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043b\u044e\u0431\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/480\/820\/0cb\/4808200cb3668866f25a2e4437a6b74e.svg\" alt=\"$5$\" data-tex=\"inline\"><\/math>, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u044e \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0435\u0433\u043e \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430 \u043d\u0438\u043c 2 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430. \u041d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/430\/944\/48d\/43094448d117ab9ec8fd3c835032e6a4.svg\" alt=\"$-5$\" data-tex=\"inline\"><\/math>, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430 \u0432\u044b\u0434\u0430\u0447\u0443 \u043f\u043e\u043f\u0430\u0434\u0443\u0442 \u0434\u0432\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0441 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/480\/820\/0cb\/4808200cb3668866f25a2e4437a6b74e.svg\" alt=\"$5$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u044f\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0433\u043e\u0434\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5e9\/2dc\/5f0\/5e92dc5f04c55425625802c3067c2176.svg\" alt=\"$7$\" data-tex=\"inline\"><\/math> \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u044e \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0435\u0433\u043e \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/480\/820\/0cb\/4808200cb3668866f25a2e4437a6b74e.svg\" alt=\"$5$\" data-tex=\"inline\"><\/math> \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u044e \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u043f\u0430\u0434\u0443\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044f\u043c\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a36\/fe6\/612\/a36fe66122f1421402b8abe93a4095f1.svg\" alt=\"$[5, -1, -3, -1, 5, 6]$\" data-tex=\"inline\"><\/math>. \u041d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u0433\u043e\u0434\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0441 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a70\/6f3\/6ac\/a706f36acf5c63e519154281c0055576.svg\" alt=\"$-3$\" data-tex=\"inline\"><\/math>, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e \u043d\u0430 \u0432\u044b\u0434\u0430\u0447\u0443 \u043f\u043e\u043f\u0430\u0434\u0443\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044f\u043c\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6eb\/77a\/e86\/6eb77ae866af71713f1d73e2abc9dc13.svg\" alt=\"$[5, -1, -1, 5, 6]$\" data-tex=\"inline\"><\/math> \u0441 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0439 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7e6\/475\/4f3\/7e64754f39d4bceb16dab3949096bcf6.svg\" alt=\"$14$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0434\u0430\u0447\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442.<\/p>\n<p>  <a name=\"fr\"><\/a><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b, \u0442\u043e \u043e\u0442\u0432\u0435\u0442&nbsp;&mdash; \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043f\u043e \u0432\u0441\u0435\u043c \u0447\u0438\u0441\u043b\u0430\u043c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u043c \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043e \u0431\u0440\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u043b\u0443\u0447\u0448\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u0412\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043e\u0442\u0440\u0435\u0437\u043a\u0443 \u0441 \u0441\u0443\u043c\u043c\u043e\u0439 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f9c\/3c8\/e48\/f9c3c8e488ead4696749012f5ece6d13.svg\" alt=\"$0$\" data-tex=\"inline\"><\/math>, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0443\u043b\u0443\u0447\u0448\u0438\u0442 \u043e\u0442\u0432\u0435\u0442, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u043c \u0432\u0437\u044f\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043e\u0434\u0438\u043d \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0445\u0443\u0436\u0435.<\/p>\n<p>  <\/p>\n<p>\u0420\u0435\u0448\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0443, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u0446\u0438\u043a\u043b\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430. <\/p>\n<p>  <\/p>\n<p>\u041f\u0443\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d01\/909\/b96\/d01909b96646300e052f062e2fe6aec6.svg\" alt=\"$dp_{i, j}$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u043f\u043e\u0434\u043e\u0442\u0440\u0435\u0437\u043a\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6f6\/7fb\/4b2\/6f67fb4b2a0f2c5a674ca19db8739927.svg\" alt=\"$[l; i]$\" data-tex=\"inline\"><\/math> (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/30f\/b68\/14e\/30fb6814eea0091044df0e5de33dfbc2.svg\" alt=\"$l$\" data-tex=\"inline\"><\/math> \u0442\u0443\u0442 \u043d\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0432\u0435\u0442 \u0431\u044b\u043b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u0435\u043d), \u0435\u0441\u043b\u0438 \u0438\u0437 \u043d\u0435\u0433\u043e \u0443\u0434\u0430\u043b\u0438\u043b\u0438 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math> \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. <\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0441\u0447\u0435\u0442: <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d53\/d06\/5e9\/d53d065e9e01cf1e9be467729380ef84.svg\" alt=\"$dp_{i, j} = \\max({0, dp_{i - 1, j} + a_i, dp_{i - 1, j - 1}})$\" data-tex=\"inline\"><\/math>, \u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442:<\/p>\n<p>  <\/p>\n<ol>\n<li> <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f9c\/3c8\/e48\/f9c3c8e488ead4696749012f5ece6d13.svg\" alt=\"$0$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u00ab\u043f\u0443\u0441\u0442\u043e\u0439\u00bb \u043e\u0442\u0440\u0435\u0437\u043e\u043a \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435.<\/li>\n<li> <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4fd\/8a4\/e41\/4fd8a4e41eb3b06425c68f900254df56.svg\" alt=\"$dp_{i - 1, j} + a_i$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0440\u0435\u0437\u043e\u043a, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0432 \u043d\u0435\u0433\u043e i-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/li>\n<li> <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c10\/2df\/636\/c102df636db691c854ab510a5185a624.svg\" alt=\"$dp_{i - 1, j - 1}$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0440\u0435\u0437\u043e\u043a, \u0443\u0434\u0430\u043b\u0438\u0432 \u0438\u0437 \u043d\u0435\u0433\u043e i-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0430\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0430 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e83\/b4c\/0f0\/e83b4c0f0af0f78e8e3fd01111d3d8ad.svg\" alt=\"$O(nk)$\" data-tex=\"inline\"><\/math>, \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/ddb\/173\/26f\/ddb17326fc9913a7ab7045a04a567463.svg\" alt=\"$\\max\\limits_{\\substack{1 \\leq i \\leq n \\\\ 0 \\leq j \\leq k}}{dp_{i, j}}$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0443\u0447\u043b\u0438 \u0432\u0441\u0435 \u043f\u043e\u0434\u043e\u0442\u0440\u0435\u0437\u043a\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0447\u0435\u0440\u0435\u0437 \u0441\u0442\u044b\u043a \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438 n-\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430. <\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443\u0447\u0442\u0435\u043c \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u043e\u0442\u0440\u0435\u0437\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u041f\u0443\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f33\/a53\/b89\/f33a53b89c82eaf6d7c4cf7162b3bcc6.svg\" alt=\"$dpl_{i, j}$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0434\u043e\u0442\u0440\u0435\u0437\u043a\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d46\/8e8\/e10\/d468e8e107866a25fec673e22cc6f1a4.svg\" alt=\"$[1; i]$\" data-tex=\"inline\"><\/math>, \u0435\u0441\u043b\u0438 \u0438\u0437 \u043d\u0435\u0433\u043e \u0443\u0434\u0430\u043b\u0438\u043b\u0438 \u0440\u043e\u0432\u043d\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math> \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. <\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0441\u0447\u0435\u0442: <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/644\/2e0\/61f\/6442e061fdbd73d016fc411dc4af43e0.svg\" alt=\"$dpl_{i, j} = \\max({dpl_{i - 1, j} + a_i, dpl_{i - 1, j - 1}})$\" data-tex=\"inline\"><\/math>, \u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442: <\/p>\n<p>  <\/p>\n<ol>\n<li> <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/686\/381\/63e\/68638163e70f54ebbe7dd70037d7f6f5.svg\" alt=\"$dpl_{i - 1, j} + a_i$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043e\u0442\u0440\u0435\u0437\u043e\u043a, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0432 \u043d\u0435\u0433\u043e i-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442. <\/li>\n<li> <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2e5\/a46\/ac8\/2e5a46ac800c179e80a408af9d0b2b37.svg\" alt=\"$dpl_{i - 1, j - 1}$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043e\u0442\u0440\u0435\u0437\u043e\u043a, \u0443\u0434\u0430\u043b\u0438\u0432 \u0438\u0437 \u043d\u0435\u0433\u043e i-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442. <\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0439 \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0438, \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043e\u0442\u0440\u0435\u0437\u043e\u043a, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043b\u0435\u0432\u0430\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0430.<\/p>\n<p>  <\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b7b\/170\/6c5\/b7b1706c57be09888aa2756a2300729d.svg\" alt=\"$dpr_{i, j}$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0434\u043e\u0442\u0440\u0435\u0437\u043a\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/bdd\/e99\/682\/bdde996825a73fdb765c241b884efa8a.svg\" alt=\"$[i; n]$\" data-tex=\"inline\"><\/math>, \u0435\u0441\u043b\u0438 \u0438\u0437 \u043d\u0435\u0433\u043e \u0443\u0434\u0430\u043b\u0438\u043b\u0438 \u0440\u043e\u0432\u043d\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/16d\/a50\/7b2\/16da507b2fc389688ef0659939dcc647.svg\" alt=\"$k$\" data-tex=\"inline\"><\/math> \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. <\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0441\u0447\u0435\u0442: <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/bf0\/c5c\/ccd\/bf0c5cccd51bcf4ffd386b9700b0fbd9.svg\" alt=\"$dpr_{i, j} = \\max({dpr_{i + 1, j} + a_i, dpr_{i + 1, j - 1}})$\" data-tex=\"inline\"><\/math>, \u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442: <\/p>\n<p>  <\/p>\n<ol>\n<li> <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e1d\/848\/ff4\/e1d848ff4b1198399f03fe5adbdcf2fa.svg\" alt=\"$dpr_{i +1, j} + a_i$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043e\u0442\u0440\u0435\u0437\u043e\u043a, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0432 \u043d\u0435\u0433\u043e i-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/li>\n<li> <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5bd\/e74\/2d4\/5bde742d4ada395dbc70b3533717829f.svg\" alt=\"$dpr_{i + 1, j - 1}$\" data-tex=\"inline\"><\/math>&nbsp;&mdash; \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043e\u0442\u0440\u0435\u0437\u043e\u043a, \u0443\u0434\u0430\u043b\u0438\u0432 \u0438\u0437 \u043d\u0435\u0433\u043e i-\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041e\u0431\u0435 \u044d\u0442\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0437\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e83\/b4c\/0f0\/e83b4c0f0af0f78e8e3fd01111d3d8ad.svg\" alt=\"$O(nk)$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u0443\u0447\u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u043e\u0442\u0440\u0435\u0437\u043a\u0438, \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 \u0441\u0442\u044b\u043a \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438 n-\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430? \u041f\u0435\u0440\u0435\u0431\u0435\u0440\u0435\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/839\/f25\/c27\/839f25c2746382debd4f08ea25ad5ecf.svg\" alt=\"$p$\" data-tex=\"inline\"><\/math>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0439\u0434\u0435\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d68\/cc4\/926\/d68cc4926bf74bae8fa3b51ca4a09ec8.svg\" alt=\"$q$\" data-tex=\"inline\"><\/math>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0443\u0434\u0430\u043b\u0438\u043b\u0438 \u043d\u0430 \u044d\u0442\u043e\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0435. \u0421\u0430\u043c\u043e\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435&nbsp;&mdash; \u044d\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/166\/41d\/342\/16641d342791dd29195256db021a8091.svg\" alt=\"$dpl_{p, q}$\" data-tex=\"inline\"><\/math>. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0435\u0434\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441 \u0441\u0430\u043c\u044b\u043c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u0443\u0444\u0444\u0438\u043a\u0441\u043e\u043c \u2014 \u0435\u0441\u043b\u0438 \u0442\u043e\u0447\u043d\u0435\u0435, \u0441 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/804\/cbc\/96e\/804cbc96ec7712e7f46f4e12061ef94b.svg\" alt=\"$\\max\\limits_{\\substack{p &lt; i \\leq n \\\\ 0 \\leq j \\leq k - q}}{dpr_{i, j}}$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u0440\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u0439 \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u043e\u0439 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6ab\/e7c\/167\/6abe7c167e988a349e99942b88d40e48.svg\" alt=\"$dpr\\_max_{i, j} = \\max{(dpr_{i, j}, dpr\\_max_{i + 1, j}, dpr\\_max_{i, j - 1})}$\" data-tex=\"inline\"><\/math>. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043f\u0440\u043e\u0441\u0447\u0435\u0442\u0430 \u2014 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e83\/b4c\/0f0\/e83b4c0f0af0f78e8e3fd01111d3d8ad.svg\" alt=\"$O(nk)$\" data-tex=\"inline\"><\/math>, \u0438 \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0443\u0444\u0444\u0438\u043a\u0441 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u0440\u044b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/839\/f25\/c27\/839f25c2746382debd4f08ea25ad5ecf.svg\" alt=\"$p$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d68\/cc4\/926\/d68cc4926bf74bae8fa3b51ca4a09ec8.svg\" alt=\"$q$\" data-tex=\"inline\"><\/math> \u0437\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/655\/b80\/5d6\/655b805d68b4b00a4e90f64eefbc6f1c.svg\" alt=\"$O(1)$\" data-tex=\"inline\"><\/math>.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e83\/b4c\/0f0\/e83b4c0f0af0f78e8e3fd01111d3d8ad.svg\" alt=\"$O(nk)$\" data-tex=\"inline\"><\/math> \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Python<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import sys  def solve():     n, k = map(int, sys.stdin.readline().split())     arr = list(map(int, sys.stdin.readline().split()))      ans = max(arr)     if ans &lt;= 0:         return ans      dp_l = [[0 for j in range(k + 2)] for i in range(n + 2)]     dp_r = [[0 for j in range(k + 2)] for i in range(n + 2)]      for i in range(1, n + 1):         for j in range(k + 1):             dp_l[i][j] = max(0, dp_l[i - 1][j] + arr[i - 1])             if j: dp_l[i][j] = max(dp_l[i][j], dp_l[i - 1][j - 1])             ans = max(ans, dp_l[i][j])      for i in range(1, n + 1):         for j in range(k + 1):             dp_l[i][j] = dp_l[i - 1][j] + arr[i - 1]             if j: dp_l[i][j] = max(dp_l[i][j], dp_l[i - 1][j - 1])      for i in range(n, 0, -1):         for j in range(k + 1):             dp_r[i][j] = dp_r[i + 1][j]  + arr[i - 1]             if j: dp_r[i][j] = max(dp_r[i][j], dp_r[i + 1][j - 1])      for i in range(1, n + 1):         for j in range(k + 1):             if i != 1: dp_l[i][j] = max(dp_l[i][j], dp_l[i - 1][j])             if j: dp_l[i][j] = max(dp_l[i][j], dp_l[i][j - 1])      for i in range(n, 0, -1):         for j in range(k + 1):             if i != n: dp_r[i][j] = max(dp_r[i][j], dp_r[i + 1][j])             if j: dp_r[i][j] = max(dp_r[i][j], dp_r[i][j - 1])      for i in range(1, n):         for j in range(k + 1):             ans = max(ans, dp_l[i][j] + dp_r[i + 1][k - j])      return ans  def main():     t = int(sys.stdin.readline())      ans = []     for i in range(t):         ans.append(str(solve()))      sys.stdout.write(&quot;\\n&quot;.join(ans) + &quot;\\n&quot;)  main()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 C++<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;stdio.h&gt; #include &lt;iostream&gt; #include &lt;stdlib.h&gt; #include &lt;string&gt; #include &lt;string.h&gt; #include &lt;vector&gt; #include &lt;stack&gt; #include &lt;queue&gt; #include &lt;deque&gt; #include &lt;set&gt; #include &lt;map&gt; #include &lt;assert.h&gt; #include &lt;algorithm&gt; #include &lt;iomanip&gt; #include &lt;time.h&gt; #include &lt;math.h&gt; #include &lt;bitset&gt;  #pragma comment(linker, &quot;\/STACK:256000000&quot;)  using namespace std;  typedef long long int ll; typedef long double ld;  const int INF = 1000 * 1000 * 1000 + 21; const ll LLINF = (1ll &lt;&lt; 60) + 5; const int MOD = 1000 * 1000 * 1000 + 7;  const int MAX_N = 100 * 1000 + 227; const int MAX_K = 105;  int n, k; int arr[MAX_N]; ll dp_l[MAX_N][MAX_K]; ll dp_r[MAX_N][MAX_K];  void solve() {     scanf(&quot;%d%d&quot;, &amp;n, &amp;k);      ll ans = -LLINF;     for (int i = 0; i &lt; n; ++i) {         scanf(&quot;%d&quot;, &amp;arr[i]);         ans = max(ans, (ll)arr[i]);     }      if (ans &lt;= 0) {         printf(&quot;%lld\\n&quot;, ans);         return;     }      for (int i = 0; i &lt;= k; ++i) {         dp_l[n + 1][i] = 0;         dp_r[n + 1][i] = 0;     }      for (int i = 1; i &lt;= n; ++i) {         for (int j = 0; j &lt;= k; ++j) {             dp_l[i][j] = max(0ll, dp_l[i - 1][j] + arr[i - 1]);             if (j) {                 dp_l[i][j] = max(dp_l[i][j], dp_l[i - 1][j - 1]);             }              ans = max(ans, dp_l[i][j]);         }     }      for (int i = 1; i &lt;= n; ++i) {         for (int j = 0; j &lt;= k; ++j) {             dp_l[i][j] = dp_l[i - 1][j] + arr[i - 1];             if (j) {                 dp_l[i][j] = max(dp_l[i][j], dp_l[i - 1][j - 1]);             }         }     }      for (int i = n; i &gt;= 1; --i) {         for (int j = 0; j &lt;= k; ++j) {             dp_r[i][j] = dp_r[i + 1][j] + arr[i - 1];             if (j) {                 dp_r[i][j] = max(dp_r[i][j], dp_r[i + 1][j - 1]);             }         }     }      for (int i = 1; i &lt;= n; ++i) {         for (int j = 0; j &lt;= k; ++j) {             if (i != 1) {                 dp_l[i][j] = max(dp_l[i][j], dp_l[i - 1][j]);             }             if (j) {                 dp_l[i][j] = max(dp_l[i][j], dp_l[i][j - 1]);             }         }     }      for (int i = n; i &gt;= 1; --i) {         for (int j = 0; j &lt;= k; ++j) {             if (i != n) {                 dp_r[i][j] = max(dp_r[i][j], dp_r[i + 1][j]);             }             if (j) {                 dp_r[i][j] = max(dp_r[i][j], dp_r[i][j - 1]);             }         }     }      for (int i = 1; i &lt; n; ++i) {         for (int j = 0; j &lt;= k; ++j) {             ans = max(ans, dp_l[i][j] + dp_r[i + 1][k - j]);         }     }      printf(&quot;%lld\\n&quot;, ans); }  int main() { #ifdef CH_EGOR     freopen(&quot;input.txt&quot;, &quot;r&quot;, stdin);     \/\/freopen(&quot;output.txt&quot;, &quot;w&quot;, stdout); #else     \/\/freopen(&quot;&quot;, &quot;r&quot;, stdin);     \/\/freopen(&quot;&quot;, &quot;w&quot;, stdout); #endif      int t;     scanf(&quot;%d&quot;, &amp;t);     while (t--) {         solve();     }      return 0; }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u043d\u0430 Java<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.IOException; import java.io.InputStream;  \/**  * Built using CHelper plug-in  * Actual solution is at the top  *  * @author ch_egor  *\/ public class Main {     public static void main(String[] args) {         InputStream inputStream = System.in;         OutputStream outputStream = System.out;         InputReader in = new InputReader(inputStream);         OutputWriter out = new OutputWriter(outputStream);         MaxSum solver = new MaxSum();         int testCount = Integer.parseInt(in.next());         for (int i = 1; i &lt;= testCount; i++)             solver.solve(i, in, out);         out.close();     }      static class MaxSum {         static final long LLINF = (1L &lt;&lt; 60) + 5;          public void solve(int testNumber, InputReader in, OutputWriter out) {             int n = in.nextInt();             int k = in.nextInt();              int[] arr = new int[n];             long[][] dp_l = new long[n + 2][k + 2];             long[][] dp_r = new long[n + 2][k + 2];              long ans = -LLINF;             for (int i = 0; i &lt; n; ++i) {                 arr[i] = in.nextInt();                 ans = Math.max(ans, arr[i]);             }              if (ans &lt;= 0) {                 out.println(ans);                 return;             }              for (int i = 0; i &lt;= k; ++i) {                 dp_l[n + 1][i] = 0;                 dp_r[n + 1][i] = 0;             }              for (int i = 1; i &lt;= n; ++i) {                 for (int j = 0; j &lt;= k; ++j) {                     dp_l[i][j] = Math.max(0L, dp_l[i - 1][j] + arr[i - 1]);                     if (j != 0) {                         dp_l[i][j] = Math.max(dp_l[i][j], dp_l[i - 1][j - 1]);                     }                      ans = Math.max(ans, dp_l[i][j]);                 }             }              for (int i = 1; i &lt;= n; ++i) {                 for (int j = 0; j &lt;= k; ++j) {                     dp_l[i][j] = dp_l[i - 1][j] + arr[i - 1];                     if (j != 0) {                         dp_l[i][j] = Math.max(dp_l[i][j], dp_l[i - 1][j - 1]);                     }                 }             }              for (int i = n; i &gt;= 1; --i) {                 for (int j = 0; j &lt;= k; ++j) {                     dp_r[i][j] = dp_r[i + 1][j] + arr[i - 1];                     if (j != 0) {                         dp_r[i][j] = Math.max(dp_r[i][j], dp_r[i + 1][j - 1]);                     }                 }             }              for (int i = 1; i &lt;= n; ++i) {                 for (int j = 0; j &lt;= k; ++j) {                     if (i != 1) {                         dp_l[i][j] = Math.max(dp_l[i][j], dp_l[i - 1][j]);                     }                     if (j != 0) {                         dp_l[i][j] = Math.max(dp_l[i][j], dp_l[i][j - 1]);                     }                 }             }              for (int i = n; i &gt;= 1; --i) {                 for (int j = 0; j &lt;= k; ++j) {                     if (i != n) {                         dp_r[i][j] = Math.max(dp_r[i][j], dp_r[i + 1][j]);                     }                     if (j != 0) {                         dp_r[i][j] = Math.max(dp_r[i][j], dp_r[i][j - 1]);                     }                 }             }              for (int i = 1; i &lt; n; ++i) {                 for (int j = 0; j &lt;= k; ++j) {                     ans = Math.max(ans, dp_l[i][j] + dp_r[i + 1][k - j]);                 }             }              out.println(ans);         }      }      static class OutputWriter {         private final PrintWriter writer;          public OutputWriter(OutputStream outputStream) {             writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));         }          public OutputWriter(Writer writer) {             this.writer = new PrintWriter(writer);         }          public void close() {             writer.close();         }          public void println(long i) {             writer.println(i);         }      }      static class InputReader {         private InputStream stream;         private byte[] buf = new byte[1024];         private int curChar;         private int numChars;         private InputReader.SpaceCharFilter filter;          public InputReader(InputStream stream) {             this.stream = stream;         }          public int read() {             if (numChars == -1) {                 throw new UnknownError();             }             if (curChar &gt;= numChars) {                 curChar = 0;                 try {                     numChars = stream.read(buf);                 } catch (IOException e) {                     throw new UnknownError();                 }                 if (numChars &lt;= 0) {                     return -1;                 }             }             return buf[curChar++];         }          public int nextInt() {             int c = read();             while (isSpaceChar(c)) {                 c = read();             }             int sgn = 1;             if (c == '-') {                 sgn = -1;                 c = read();             }             int res = 0;             do {                 if (c &lt; '0' || c &gt; '9') {                     throw new UnknownError();                 }                 res *= 10;                 res += c - '0';                 c = read();             } while (!isSpaceChar(c));             return res * sgn;         }          public String nextString() {             int c = read();             while (isSpaceChar(c)) {                 c = read();             }             StringBuilder res = new StringBuilder();             do {                 if (Character.isValidCodePoint(c)) {                     res.appendCodePoint(c);                 }                 c = read();             } while (!isSpaceChar(c));             return res.toString();         }          public boolean isSpaceChar(int c) {             if (filter != null) {                 return filter.isSpaceChar(c);             }             return isWhitespace(c);         }          public static boolean isWhitespace(int c) {             return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;         }          public String next() {             return nextString();         }          public interface SpaceCharFilter {             public boolean isSpaceChar(int ch);          }      } }<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/yandex\/blog\/493966\/\"> https:\/\/habr.com\/ru\/company\/yandex\/blog\/493966\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/yandex\/blog\/493966\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/5d\/rh\/fo\/5drhfost9i2nmn9onzzyiy_ixli.jpeg\" align=\"right\" width=\"30%\">\u0425\u0430\u0431\u0440, \u044d\u0442\u043e \u0441\u043d\u043e\u0432\u0430 \u044f, \u0410\u043b\u0435\u043a\u0441\u0435\u0439 \u0420\u0430\u043a (\u0444\u043e\u0442\u043e \u043d\u0435 \u043c\u043e\u0435). \u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0433\u043e\u0434\u0443, \u043f\u043e\u043c\u0438\u043c\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u043c\u043d\u0435 \u0434\u043e\u0432\u0435\u043b\u043e\u0441\u044c \u0441\u0442\u0430\u0442\u044c \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0430\u0432\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u0434\u0430\u0447 \u0434\u043b\u044f \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432 \u0432 \u042f\u043d\u0434\u0435\u043a\u0441. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043d\u0430\u0448\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0437\u0430 \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e. \u042d\u0442\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u043e \u0444\u0435\u0432\u0440\u0430\u043b\u044f 2020 \u0433\u043e\u0434\u0430 \u043f\u0440\u0438 \u043e\u0442\u0431\u043e\u0440\u0435 \u043d\u0430 \u0441\u0442\u0430\u0436\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u0431\u044d\u043a\u0435\u043d\u0434\u0435\u0440\u043e\u0432. \u0420\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440. \u0421\u0435\u0439\u0447\u0430\u0441 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u0420\u0430\u0437\u0431\u043e\u0440\u044b \u0438 \u043a\u043e\u0434 \u0441\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043f\u0440\u044f\u0442\u0430\u043d\u044b \u0432 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u044b. \u0415\u0441\u043b\u0438 \u0432\u044b \u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u0441\u044c \u043a \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f\u043c \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 IT-\u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0440\u0435\u0448\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u0447, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0440\u0430\u0437\u0431\u043e\u0440. \u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430 Codeforces \u2014 \u043e\u0442\u0432\u0435\u0442 \u043f\u0440\u0438\u0434\u0451\u0442 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 (<a href=\"https:\/\/codeforces.com\/gym\/102558\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 Codeforces<\/a> \u0438 <abbr title=\"\u041d\u0430 Codeforces \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u0430\u043c \u044d\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0437\u0430\u0434\u0430\u0447 \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435.\">\u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/abbr>). \u041a\u043e\u0434 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043d\u0430 Python, C++ \u0438 Java.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-300735","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=300735"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300735\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=300735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=300735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=300735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}