{"id":298831,"date":"2020-02-18T09:00:07","date_gmt":"2020-02-18T09:00:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=298831"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=298831","title":{"rendered":"\u041a\u0430\u043a \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430\u0432\u044b\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u00a0Python? \u0417\u0430\u0434\u0430\u0447\u0438 \u043e\u0442 \u042f\u043d\u0434\u0435\u043a\u0441\u0430"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/yandex\/blog\/488682\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/0y\/0c\/l3\/0y0cl3wavrx-rjbz3zjr_vtkdrm.jpeg\" width=\"600\"><br \/>  <b><sup><sub>\u0425\u0430\u043a\u0430\u0442\u043e\u043d \u0432 \u0428\u043a\u043e\u043b\u0435 \u0431\u044d\u043a\u0435\u043d\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/sub><\/sup><\/b><\/p>\n<p>  \u0412 2019 \u0433\u043e\u0434\u0443 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0443\u043c\u0435\u043d\u0438\u0435 \u043f\u0438\u0441\u0430\u0442\u044c Python-\u043a\u043e\u0434 \u0443 \u0441\u043e\u0442\u0435\u043d \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432. \u0422\u0430\u043a \u043c\u044b \u043e\u0442\u0431\u0438\u0440\u0430\u043b\u0438 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0428\u043a\u043e\u043b\u044b \u0431\u044d\u043a\u0435\u043d\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u042d\u0442\u043e \u043d\u0435 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430 \u043b\u0438\u0441\u0442\u0435 \u0431\u0443\u043c\u0430\u0433\u0438, \u043a\u0430\u043a \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u043c\u043e\u0433\u043b\u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0437\u0430\u0434\u0430\u0447, \u0443\u0436\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u0439 \u043f\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u0446\u0435\u043b\u044c\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0445 \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u2014 \u044d\u0442\u043e \u043e\u0434\u043d\u043e, \u0430 \u043e\u0442\u0431\u043e\u0440 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u043e\u0432 \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u0432 \u0448\u043a\u043e\u043b\u0443 \u2014 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0435. \u041d\u0430\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0437\u0430\u0434\u0430\u0447\u0438, \u043f\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u0438\u0434\u043d\u043e, \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043b\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0431\u0430\u0437\u043e\u0432\u044b\u043c\u0438 \u043d\u0430\u0432\u044b\u043a\u0430\u043c\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0438 \u0443\u043c\u0435\u043d\u0438\u0435\u043c \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u0432\u0440\u0435\u043c\u044f. \u0412\u043e\u0442 \u043a\u0430\u043a\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043c\u044b \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0427\u0430\u0441\u0442\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442<\/h2>\n<p><sup><i>\u0410\u0432\u0442\u043e\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f: \u041c\u0438\u0445\u0430\u0438\u043b \u0428\u0443\u0448\u043f\u0430\u043d\u043e\u0432 <a href=\"https:\/\/habr.com\/ru\/users\/mishush\/\" class=\"user_link\">mishush<\/a>. \u0417\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0448\u0438\u043b\u0438 50% \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432<\/i><\/sup><\/p>\n<p>  \u0414\u0430\u043d \u043c\u0430\u0441\u0441\u0438\u0432 a \u0438\u0437 n \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b. \u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0439\u0434\u0435\u0442 \u0447\u0438\u0441\u043b\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0447\u0430\u0449\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438: 2 \u0441, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438: 256 \u041c\u0411.<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0447\u0438\u0441\u043b\u043e n (1 \u2264 n \u2264 300\u202f000). <br \/>  \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b n \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b a<sub>i<\/sub> (0 \u2264 a<sub>i<\/sub> \u2264 1\u202f000\u202f000\u202f000).<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u044b\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e x, \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0438\u0437 \u0447\u0438\u0441\u0435\u043b, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0447\u0430\u0449\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 a. <\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u041f\u0440\u043e\u0441\u0442\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u043a\u0430\u043a \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f, \u0442\u0430\u043a \u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b Counter \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f collections.<\/p>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u0438\u0437 \u0442\u0435\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0440\u0430\u0437. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 O(n) \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 O(n) \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<pre><code class=\"python\">from collections import Counter  n = int(input())  a = [int(i) for i in input().split()]   counter = Counter(a)  result = a[0] max_count = counter[result] for number, count in counter.items():     if count &gt; max_count or (count == max_count and number &gt; result):         result = number         max_count = count  print(result) <\/code><\/pre>\n<p>  <\/p>\n<h2>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p><sup><i>\u0410\u0432\u0442\u043e\u0440: \u041c\u0438\u0445\u0430\u0438\u043b \u0428\u0443\u0448\u043f\u0430\u043d\u043e\u0432. \u0417\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0448\u0438\u043b\u0438 20% \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432<\/i><\/sup><\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c f<sub>0<\/sub>, f<sub>1<\/sub>, f<sub>2<\/sub>,\u2026 \u0437\u0430\u0434\u0430\u043d\u0430 \u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u043c\u0438 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438 f<sub>0<\/sub> = 0, f<sub>1<\/sub> = 1, f<sub>2<\/sub> = 2, f<sub>k<\/sub> = f<sub>k\u20131<\/sub> + f<sub>k\u20133<\/sub>.<\/p>\n<p>  \u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 n \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u044d\u0442\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 c \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 k<sub>1<\/sub>, k<sub>2<\/sub>, &#8230;, k<sub>n<\/sub>. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438: 1 \u0441, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438: 10 \u041c\u0411.<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e n (1 \u2264 n \u2264 1000).<br \/>  \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b n \u0446\u0435\u043b\u044b\u0445 \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b (0 \u2264 k<sub>i<\/sub> \u2264 16000), \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u0435\u043b\u0430\u043c\u0438.<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u044b\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f f<sub>k<sub>1<\/sub><\/sub>, f<sub>k<sub>2<\/sub><\/sub>, &#8230;, f<sub>k<sub>n<\/sub><\/sub>.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0412 \u0437\u0430\u0434\u0430\u0447\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043d\u043e \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u0441\u043b\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0435 \u0443\u043b\u043e\u0436\u0438\u043b\u0438\u0441\u044c \u0432 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u043b\u0438 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f f<sub>k<\/sub> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c f<sub>0<\/sub>, f<sub>1<\/sub>, &#8230;, f<sub>k\u20131<\/sub>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c f<sub>k<\/sub>, \u0433\u0434\u0435 k = max(k<sub>1<\/sub>, k<sub>2<\/sub>, &#8230;, k<sub>n<\/sub>). \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u044b \u043b\u0438\u0448\u044c \u0438 f<sub>k\u20131<\/sub> \u0438 f<sub>k\u20133<\/sub>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 O(max(k, n)) \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 O(n) \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<pre><code class=\"python\">n = int(input()) indices = [int(i) for i in input().split()] results = {i: i if i &lt; 3 else None for i in indices} k = max(indices) a, b, c = 0, 1, 2 for i in range(3, k + 1):     a, b, c = b, c, a + c     if i in results:         results[i] = c print(&quot; &quot;.join(str(results[i]) for i in indices)) <\/code><\/pre>\n<p>  <\/p>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c JOIN<\/h2>\n<p><sup><i>\u0410\u0432\u0442\u043e\u0440: \u0414\u043c\u0438\u0442\u0440\u0438\u0439 \u0422\u0435\u0440\u0440\u043e\u0432 <a href=\"https:\/\/habr.com\/ru\/users\/terrmit\/\" class=\"user_link\">terrmit<\/a>. \u0417\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0448\u0438\u043b\u0438 6% \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432<\/i><\/sup><\/p>\n<p>  \u0414\u0430\u043d\u044b \u0434\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b T1 \u0438 T2. \u041a\u0430\u0436\u0434\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0434\u0432\u0443\u043c\u044f \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438. \u0422\u0430\u0431\u043b\u0438\u0446\u0430 T1 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u043b\u044f a \u0438 b. \u0422\u0430\u0431\u043b\u0438\u0446\u0430 T2 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u043b\u044f a \u0438 \u0441. <\/p>\n<p>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u0443\u044e \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u044e SQL JOIN \u0434\u0432\u0443\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u043f\u043e \u043f\u043e\u043b\u044e a \u0438 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 T3. <\/p>\n<p>  \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043c\u043e\u0433\u0443\u0442 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0439 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 5. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438: 1 \u0441, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438: 64 \u041c\u0411.<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e n1 (1 \u2264 n1 \u2264 15000) \u2013\u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 T1. \u0414\u0430\u043b\u0435\u0435 \u0432 n1 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b \u043f\u043e \u0434\u0432\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 \u2014 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439 ai \u0438 bi (1 \u2264 ai, bi \u2264 1000) \u0442\u0430\u0431\u043b\u0438\u0446\u044b T1. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e n2 (1 \u2264 n2 \u2264 10000) \u2013\u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 T2. \u0414\u0430\u043b\u0435\u0435 \u0432 n2 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b \u043f\u043e \u0434\u0432\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 \u2014 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439 aj \u0438 cj (1 \u2264 aj, cj \u2264 1000) \u0442\u0430\u0431\u043b\u0438\u0446\u044b T2. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (INNER, LEFT, RIGHT, FULL).<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u044b\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0447\u0438\u0441\u043b\u043e n3 \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 T3. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 n3 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439 ak, bk \u0438 ck \u0442\u0430\u0431\u043b\u0438\u0446\u044b T3. \u0415\u0441\u043b\u0438 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u043f\u043e\u043b\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 NULL \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f. \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u0442\u0440\u043e\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u044b T3 \u043d\u0435 \u0432\u0430\u0436\u0435\u043d.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 a \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b. \u041d\u0430\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u2014 \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c \u043f\u043e \u043e\u0431\u0435\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c:<\/p>\n<pre><code class=\"python\">for a1, b in t1:     for a2, c in t2:         if a1 == a2:             t3.append((a1, b, c))<\/code><\/pre>\n<p>  \u0422\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0438 \u043d\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u043f\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041d\u0443\u0436\u0435\u043d \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u044f a. \u041c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">for row in t1:     t1_map[row[0]] = row<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e LEFT. \u041f\u0440\u043e\u0445\u043e\u0434\u044f \u043f\u043e \u043a\u043b\u044e\u0447\u0430\u043c \u043f\u0435\u0440\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u044e\u0447 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0415\u0441\u043b\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u2014 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 (a, b, c), \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 (a, b, NULL).<\/p>\n<pre><code class=\"python\">for a, b in t1_map.items():      if a in t2_map:          t3.append((a, b, t2[a]))      else:          t3.append((a, b, 'NULL'))<\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 RIGHT \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0442\u0430\u0431\u043b\u0438\u0446.<\/p>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 FULL \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0445\u043e\u0434 \u0443\u0436\u0435 \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435:<\/p>\n<pre><code class=\"python\">for a, c in t2_map.items():     if a not in t1_map:         t3.append((a, 'NULL', c))<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 a \u043d\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 hash-map \u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0440\u043e\u043a, \u0430 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0435\u043a\u0430\u0440\u0442\u043e\u0432\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u043f\u043e\u043b\u0435\u043c a. \u0412 Python \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f itertools.product.<\/p>\n<p>  \u0421\u0442\u043e\u0438\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f a \u0432\u043e \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u043e\u0431\u0435\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u2014 N x N. \u041d\u043e \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u0442\u0430\u043a\u0438\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u043f\u044f\u0442\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0417\u043d\u0430\u0447\u0438\u0442, \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043d\u0435\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0441\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430.<\/p>\n<h2>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043f\u0443\u0441\u0442\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <\/h2>\n<p><sup><i>\u0410\u0432\u0442\u043e\u0440: \u041c\u0438\u0445\u0430\u0438\u043b \u0428\u0443\u0448\u043f\u0430\u043d\u043e\u0432. \u0417\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0448\u0438\u043b\u0438 7% \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432<\/i><\/sup><\/p>\n<p>  \u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0437 JSON-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u043f\u0443\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c\u0438 ({}) \u0438\u043b\u0438 \u043f\u0443\u0441\u0442\u044b\u043c\u0438 \u0441\u043f\u0438\u0441\u043a\u0430\u043c\u0438 ([]), \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u0442\u043e \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u044e\u0447. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438: 0,2 \u0441, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438: 6 \u041c\u0411.<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043b\u0438\u043d\u044b n (1 \u2264 n \u2264 1000). \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 JSON-\u0441\u0442\u0440\u043e\u043a\u043e\u0439.<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u044b\u0432\u043e\u0434\u0430:<\/b><br \/>  \u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0443\u0441\u0442\u044b\u0445 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0443\u0441\u0442\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0412 \u0437\u0430\u0434\u0430\u0447\u0435 \u0437\u0430\u043c\u0430\u0441\u043a\u0438\u0440\u043e\u0432\u0430\u043d \u043e\u0431\u0445\u043e\u0434 \u0434\u0435\u0440\u0435\u0432\u0430 \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0443. \u0411\u044b\u043b\u0438 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0435\u0448\u0438\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0431\u0435\u0437 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 JSON. \u041f\u043e\u043b\u0435\u0437\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u043d\u0430\u0442\u044c \u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u044f json, \u0444\u0443\u043d\u043a\u0446\u0438\u0438 isinstance, \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u0438 \u0441\u043f\u0438\u0441\u043a\u0438 \u0432 Python. \u0412 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445 \u0431\u0435\u0437 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 JSON \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0447\u0430\u0441\u0442\u043e \u0441\u0442\u0430\u0440\u0430\u043b\u0438\u0441\u044c \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432\u0440\u043e\u0434\u0435 {}, [], \u043d\u043e \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 &#187;{}, []&#187; \u043d\u0438\u0447\u0435\u0433\u043e \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e.<\/p>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u2014 \u043f\u0440\u0438 \u043e\u0431\u0445\u043e\u0434\u0435 \u0434\u0435\u0440\u0435\u0432\u0430 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0435\u0432\u0430 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u044d\u0442\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0435\u0432\u043e, \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u043f\u0443\u0441\u0442\u043e\u0435.<\/p>\n<pre><code class=\"python\">import json dict_counter, list_counter = 0, 0 def clean_struct(struct):     global dict_counter, list_counter     if isinstance(struct, dict):         for key, value in struct.copy().items():             cleaned_struct = clean_struct(value)             if cleaned_struct is None:                 del struct[key]             else:                 struct[key] = cleaned_struct         if len(struct) == 0:             dict_counter += 1             return None     if isinstance(struct, list):         i = 0         while i &lt; len(struct):             cleaned_struct = clean_struct(struct[i])             if cleaned_struct is None:                 del struct[i]             else:                 struct[i] = cleaned_struct                 i += 1         if len(struct) == 0:             list_counter += 1             return None     return struct struct = json.loads(input()) clean_struct(struct) print(dict_counter, list_counter) <\/code><\/pre>\n<p>  <\/p>\n<h2>\u0412\u044b\u0441\u043e\u043a\u0430\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 <\/h2>\n<p><sup><i>\u0410\u0432\u0442\u043e\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f: \u0414\u043c\u0438\u0442\u0440\u0438\u0439 \u0422\u0435\u0440\u0440\u043e\u0432. \u0417\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0448\u0438\u043b\u0438 14% \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432<\/i><\/sup><\/p>\n<p>  \u0412\u0430\u043c \u0434\u0430\u043d\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u0441\u0435\u0441\u0441\u0438\u0439 \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u044b\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0435. \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0435\u0441\u0441\u0438\u044f \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u0430 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f si \u0438 fi, \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0432\u0441\u0435 \u044d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b.<\/p>\n<p>  \u041d\u0430\u0439\u0434\u0438\u0442\u0435 \u0442\u0430\u043a\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 t, \u043a\u043e\u0433\u0434\u0430 \u0431\u044b\u043b\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u0441\u0441\u0438\u0439. \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u0438\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e, \u0442\u043e \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u0430\u043c\u044b\u0439 \u0440\u0430\u043d\u043d\u0438\u0439 \u0438\u0437 \u043d\u0438\u0445. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438: 1 \u0441, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438: 256 \u041c\u0411.<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e n (1 \u2264 n \u2264 1000). \u0414\u0430\u043b\u0435\u0435 \u0432 n \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b \u043f\u043e \u0434\u0432\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 si \u0438 fi (0 \u2264 si &lt; fi \u2264 1 000 000 000).<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u044b\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 t.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e\u0439, \u043d\u043e \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u2014 \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u0432\u0441\u0435\u043c \u0441\u0435\u0441\u0441\u0438\u044f\u043c \u0438 \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0441 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0439 \u0438 \u043d\u0430\u0439\u0434\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u2014 O(N x N).<\/p>\n<p>  \u041d\u043e \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u0441\u0435\u0441\u0441\u0438\u0439 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0434\u0432\u0443\u0445 \u0442\u0438\u043f\u043e\u0432 \u2014 \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u0435\u0441\u0441\u0438\u0438 \u0438 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0441\u0435\u0441\u0441\u0438\u0438. \u041e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u0440\u043e\u0445\u043e\u0434\u044f \u043f\u043e \u043d\u0438\u043c, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u043a \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0441\u0435\u0441\u0441\u0438\u0439, \u0435\u0441\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u2014 \u044d\u0442\u043e \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u0435\u0441\u0441\u0438\u0438 \u0438 \u0432\u044b\u0447\u0438\u0442\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u2014 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435 \u0441\u0435\u0441\u0441\u0438\u0438. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u2014 O(N x log N).<\/p>\n<pre><code class=\"python\">n = int(input()) sessions = [] for _ in range(n):     x, y = map(int, input().split())     sessions.append((x, y))  events = [] for start, end in sessions:     events.append((start, 1))     events.append((end, -1)) events.sort()  max_number = min_time = cur_number = 0 for cur_time, operation in events:     cur_number = cur_number + operation     if cur_number &gt; max_number:         max_number = cur_number         min_time = cur_time  print(min_time)<\/code><\/pre>\n<p>  <\/p>\n<h2>\u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u0438\u043d \u0441\u0435\u0440\u0438\u0439 <\/h2>\n<p><sup><i>\u0410\u0432\u0442\u043e\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f: \u041c\u0438\u0445\u0430\u0438\u043b \u0428\u0443\u0448\u043f\u0430\u043d\u043e\u0432. \u0417\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0448\u0438\u043b\u0438 33% \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432<\/i><\/sup><\/p>\n<p>  \u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u0438\u043d \u0441\u0435\u0440\u0438\u0439 (RLE) \u2014 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u0436\u0430\u0442\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043d\u0430 \u043e\u0434\u0438\u043d \u0441\u0438\u043c\u0432\u043e\u043b \u0438 \u0447\u0438\u0441\u043b\u043e \u0435\u0433\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043e\u0432. \u0421\u0435\u0440\u0438\u0435\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 (\u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e). \u041f\u0440\u0438 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0441\u0435\u0440\u0438\u044e, \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0439, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u0441\u0430\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0435\u0433\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0442\u0440\u043e\u043a\u0430 AAAABBB \u0431\u0443\u0434\u0435\u0442 \u0441\u0436\u0430\u0442\u0430 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 A4B3, \u0430 \u0441\u0442\u0440\u043e\u043a\u0430 AAAAAAAAAAAAAAABAAAAA \u2014 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 A15BA5.<\/p>\n<p>  \u0412\u0430\u043c \u0434\u0430\u043d\u0430 \u0441\u0436\u0430\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u043d\u0430\u0439\u0434\u0438\u0442\u0435 \u0434\u043b\u0438\u043d\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0414\u043b\u0438\u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 1000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u2014 \u0437\u0430\u0433\u043b\u0430\u0432\u043d\u044b\u0435 \u0431\u0443\u043a\u0432\u044b \u043b\u0430\u0442\u0438\u043d\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438: 2 \u0441, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438: 264 \u041c\u0411.<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043d\u0435\u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430. \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e RLE-\u0441\u0436\u0430\u0442\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u044b\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0434\u043b\u0438\u043d\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u042d\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438 \u0438 \u0437\u043d\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u043e, \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0446\u0438\u0444\u0440\u044b \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0430\u0441\u044c \u0446\u0438\u0444\u0440\u0430, \u0442\u043e \u044d\u0442\u043e \u0446\u0438\u0444\u0440\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0438 \u043c\u044b \u043a\u043e\u043f\u0438\u043c \u0447\u0438\u0441\u043b\u043e. \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0431\u0443\u043a\u0432\u044b \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0430\u0441\u044c \u0431\u0443\u043a\u0432\u0430 \u2014 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443. \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0446\u0438\u0444\u0440\u044b \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0430\u0441\u044c \u0431\u0443\u043a\u0432\u0430 \u2014 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e. \u0411\u044b\u043b\u0438 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0448\u0438\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 O(n) \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 O(1) \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 (O(n) \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u0430\u043c\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438).<\/p>\n<pre><code class=\"python\">first_symbol = True result = 0 number = ''  for c in input():     if c.isdigit():         number += c     elif c.isalpha() and not number:         if first_symbol:             first_symbol = False         else:             result += 1     elif c.isalpha() and number:         result += int(number)         number = '' \t if number:     result += int(number) else:     result += 1 print(result)<\/code><\/pre>\n<p>  <\/p>\n<h2>\u0414\u0435\u0442\u0435\u043a\u0442\u043e\u0440 DDoS <\/h2>\n<p><sup><i>\u0410\u0432\u0442\u043e\u0440: \u0421\u0435\u0440\u0433\u0435\u0439 \u0414\u0435\u043c\u0443\u0440\u0438\u043d <a href=\"https:\/\/habr.com\/ru\/users\/kakty3\/\" class=\"user_link\">kakty3<\/a>. \u0417\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0448\u0438\u043b\u0438 7% \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432<\/i><\/sup><\/p>\n<p>  \u0414\u0430\u043d \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 N IP-\u0430\u0434\u0440\u0435\u0441\u043e\u0432. \u041d\u0430\u0437\u043e\u0432\u0435\u043c IP-\u0430\u0434\u0440\u0435\u0441 \u00ab\u043f\u043b\u043e\u0445\u0438\u043c\u00bb, \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 M \u043f\u043e\u0434\u0440\u044f\u0434 \u0438\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0440\u043e\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044d\u0442\u043e\u0442 IP-\u0430\u0434\u0440\u0435\u0441 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0445\u043e\u0442\u044f \u0431\u044b K \u0440\u0430\u0437. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438: 10 \u0441, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438: 10 \u041c\u0411.<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u0432\u043e\u0434\u0430<\/b><br \/>  \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0447\u0438\u0441\u043b\u043e N (1 \u2264 N \u2264 10<sup>6<\/sup>).<br \/>  \u0412\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0447\u0438\u0441\u043b\u043e M (1 \u2264 M \u2264 10<sup>3<\/sup>).<br \/>  \u0422\u0440\u0435\u0442\u044c\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0447\u0438\u0441\u043b\u043e K (1 \u2264 K \u2264 M).<br \/>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 N \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b IP-\u0430\u0434\u0440\u0435\u0441\u0430, \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0443.<\/p>\n<p>  <b>\u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u044b\u0432\u043e\u0434\u0430<\/b><br \/>  \u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u00ab\u043f\u043b\u043e\u0445\u0438\u0445\u00bb IP-\u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u0432 \u043b\u0435\u043a\u0441\u0438\u043a\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u041d\u0430\u0438\u0432\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0430\u0434\u0440\u0435\u0441\u0430 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u043d\u0435\u043c\u0443 \u043e\u043a\u043d\u043e\u043c \u0434\u043b\u0438\u043d\u043e\u0439 M \u0438 \u043d\u0430\u0439\u0442\u0438 \u0430\u0434\u0440\u0435\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432 \u044d\u0442\u043e\u043c \u043e\u043a\u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 K \u0448\u0442\u0443\u043a. \u0422\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0442\u0435\u0441\u0442\u0430\u0445, \u043d\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0438\u0437-\u0437\u0430 \u043b\u0438\u043c\u0438\u0442\u043e\u0432 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<p>  \u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435: \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a M \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432. \u0415\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u043a\u0430 \u0434\u043b\u0438\u043d\u044b M. \u0412 \u0434\u0435\u043a\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043a\u0430\u0442\u044c \u0430\u0434\u0440\u0435\u0441\u0430, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u2265 K. \u042d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u0430\u0447\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0430\u0434\u0440\u0435\u0441\u0430 \u0432 \u0434\u0435\u043a\u0435, \u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0435 \u0443\u043b\u043e\u0436\u0438\u043c\u0441\u044f \u0432 \u043b\u0438\u043c\u0438\u0442 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0430\u0434\u0440\u0435\u0441\u0430 \u0437\u0430\u043d\u043e\u0432\u043e, \u0431\u0443\u0434\u0435\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u2014 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043e\u043d \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u041c \u0430\u0434\u0440\u0435\u0441\u043e\u0432. \u041f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0431\u0443\u0434\u0435\u043c:<br \/>  \u2014 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e,<br \/>  \u2014 \u0430 \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u00ab\u043f\u043b\u043e\u0445\u0438\u0445\u00bb \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u043d\u043e\u0432\u044b\u0439 \u0430\u0434\u0440\u0435\u0441, \u0435\u0441\u043b\u0438 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0434\u043e\u0441\u0442\u0438\u0433 K. <\/p>\n<p>  \u041d\u043e \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435 \u0443\u043b\u043e\u0436\u0438\u0442\u0441\u044f \u0432 \u043b\u0438\u043c\u0438\u0442 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 IP-\u0430\u0434\u0440\u0435\u0441\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435. \u0422\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u043e\u0432 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0435\u0442 10<sup>6<\/sup>. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u043e\u043b\u044c. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0430\u0434\u0440\u0435\u0441\u0430 \u043f\u0440\u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0438 \u0434\u043e\u0441\u0442\u0438\u0433 \u043d\u0443\u043b\u044f, \u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438. \u0422\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0435 \u043f\u0440\u0438\u0432\u044b\u0441\u0438\u0442 10<sup>3<\/sup>.<\/p>\n<p>  \u0424\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 O(N) \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0445\u043e\u0434\u0430 \u043f\u043e \u0432\u0441\u0435\u043c IP-\u0430\u0434\u0440\u0435\u0441\u0430\u043c \u0438 O(M) \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u0438 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u043e\u0432 \u0430\u0434\u0440\u0435\u0441\u043e\u0432.<\/p>\n<pre><code class=\"python\"># coding: utf-8 from collections import Counter, deque import sys  def main():     # \u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u0430 N, M \u0438 K     n_of_lines = int(sys.stdin.readline().strip())     window_size = int(sys.stdin.readline().strip())     threshold = int(sys.stdin.readline().strip())      # \u0417\u0430\u0432\u043e\u0434\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u00ab\u043f\u043b\u043e\u0445\u0438\u0445\u00bb \u0430\u0434\u0440\u0435\u0441\u043e\u0432,     # \u0434\u0435\u043a \u0434\u043b\u044f \u043e\u043a\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432     # \u0438 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0430\u0434\u0440\u0435\u0441\u043e\u0432     bad_ips = set()     last_ips = deque(maxlen=window_size)     counter = Counter()      for _ in range(n_of_lines):         # \u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c IP-\u0430\u0434\u0440\u0435\u0441         current_ip = sys.stdin.readline().rstrip()          # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0434\u0435\u043a \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f         if len(last_ips) == window_size:             # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u0437 \u0434\u0435\u043a\u0430 \u0441\u0430\u043c\u044b\u0439 \u0441\u0442\u0430\u0440\u044b\u0439 \u0430\u0434\u0440\u0435\u0441             # \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u0435\u0433\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443             oldest_ip = last_ips.pop()             counter[oldest_ip] -= 1              # \u0415\u0441\u043b\u0438 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441\u0442\u0430\u043b \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e \u2014 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0430\u0434\u0440\u0435\u0441             if not counter[oldest_ip]:                 del counter[oldest_ip]          # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0432 \u0434\u0435\u043a         last_ips.appendleft(current_ip)          # \u0415\u0441\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u00ab\u043f\u043b\u043e\u0445\u0438\u0445\u00bb,         # \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0430\u0434\u0440\u0435\u0441\u0443         if current_ip in bad_ips:             continue          # \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430         counter[current_ip] += 1          # \u0415\u0441\u043b\u0438 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0434\u043e\u0441\u0442\u0438\u0433 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f K,         # \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u00ab\u043f\u043b\u043e\u0445\u0438\u0445\u00bb         if counter[current_ip] &gt;= threshold:             bad_ips.add(current_ip)             # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u00ab\u043f\u043b\u043e\u0445\u043e\u0439\u00bb \u0430\u0434\u0440\u0435\u0441 \u0438\u0437 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430,             # \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438\u0448\u043d\u044e\u044e \u043f\u0430\u043c\u044f\u0442\u044c             del counter[current_ip]      # \u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u00ab\u043f\u043b\u043e\u0445\u0438\u0435\u00bb \u0430\u0434\u0440\u0435\u0441\u0430 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442     print('\\n'.join(current_ip for current_ip in sorted(bad_ips)))  if __name__ == &quot;__main__&quot;:     main()<\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u044b\u043b\u0438 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0432\u0441\u0442\u0443\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0432 \u0428\u043a\u043e\u043b\u0443 \u0431\u044d\u043a\u0435\u043d\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0412\u0442\u043e\u0440\u0443\u044e \u0447\u0430\u0441\u0442\u044c (\u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441) \u043c\u044b \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u0438 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0435 \u043d\u0435\u0434\u0435\u043b\u0438.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0431\u044d\u043a\u0435\u043d\u0434\u0435\u0440\u043e\u0432, \u043f\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u043e\u0440\u044b \u0431\u044d\u043a\u0435\u043d\u0434-\u0442\u0440\u0435\u043a\u043e\u0432 <a href=\"https:\/\/habr.com\/ru\/company\/yandex\/blog\/457262\/\">\u043f\u0435\u0440\u0432\u043e\u0433\u043e<\/a> \u0438 <a href=\"https:\/\/habr.com\/ru\/company\/yandex\/blog\/483624\/\">\u0432\u0442\u043e\u0440\u043e\u0433\u043e<\/a> \u0447\u0435\u043c\u043f\u0438\u043e\u043d\u0430\u0442\u0430 \u043f\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e.<\/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\/488682\/\"> https:\/\/habr.com\/ru\/company\/yandex\/blog\/488682\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/yandex\/blog\/488682\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/0y\/0c\/l3\/0y0cl3wavrx-rjbz3zjr_vtkdrm.jpeg\" width=\"600\"><br \/>  <b><sup><sub>\u0425\u0430\u043a\u0430\u0442\u043e\u043d \u0432 \u0428\u043a\u043e\u043b\u0435 \u0431\u044d\u043a\u0435\u043d\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/sub><\/sup><\/b><\/p>\n<p>  \u0412 2019 \u0433\u043e\u0434\u0443 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0443\u043c\u0435\u043d\u0438\u0435 \u043f\u0438\u0441\u0430\u0442\u044c Python-\u043a\u043e\u0434 \u0443 \u0441\u043e\u0442\u0435\u043d \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432. \u0422\u0430\u043a \u043c\u044b \u043e\u0442\u0431\u0438\u0440\u0430\u043b\u0438 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0428\u043a\u043e\u043b\u044b \u0431\u044d\u043a\u0435\u043d\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u042d\u0442\u043e \u043d\u0435 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430 \u043b\u0438\u0441\u0442\u0435 \u0431\u0443\u043c\u0430\u0433\u0438, \u043a\u0430\u043a \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u043c\u043e\u0433\u043b\u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0437\u0430\u0434\u0430\u0447, \u0443\u0436\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u0439 \u043f\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u0446\u0435\u043b\u044c\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0445 \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u2014 \u044d\u0442\u043e \u043e\u0434\u043d\u043e, \u0430 \u043e\u0442\u0431\u043e\u0440 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u043e\u0432 \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u0432 \u0448\u043a\u043e\u043b\u0443 \u2014 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0435. \u041d\u0430\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0437\u0430\u0434\u0430\u0447\u0438, \u043f\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u0438\u0434\u043d\u043e, \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043b\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0431\u0430\u0437\u043e\u0432\u044b\u043c\u0438 \u043d\u0430\u0432\u044b\u043a\u0430\u043c\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0438 \u0443\u043c\u0435\u043d\u0438\u0435\u043c \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u0432\u0440\u0435\u043c\u044f. \u0412\u043e\u0442 \u043a\u0430\u043a\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043c\u044b \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438.  <\/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-298831","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298831","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=298831"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298831\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=298831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=298831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=298831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}