Advertisement
stupid_pro

Untitled

May 5th, 2023 (edited)
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.58 KB | None | 0 0
  1. # with open('P4.txt') as f:
  2. # a = f.readlines()
  3. # n = a.pop(0).split()
  4. # for i in range(len(a)):
  5. # a[i] = int(a[i])
  6. #
  7. # even = []
  8. # for i in range(len(a)):
  9. # if a[i] % 2 == 0:
  10. # even.append(int(a[i]))
  11. #
  12. # pair_count = 0
  13. # min_av = 10 ** 100
  14. #
  15. # for i in range(len(even) - 1):
  16. # for j in range(i + 1, len(even)):
  17. # a_s = (even[i] + even[j]) // 2
  18. # if a_s in a:
  19. # pair_count += 1
  20. # min_av = min(min_av, a_s)
  21. # print(even[i], even[j])
  22. # print(pair_count, min_av)
  23.  
  24. # with open('P3.txt') as f:
  25. # a = f.readlines()
  26. # n, m = a[0].split()
  27. # n = int(n)
  28. # m = int(m)
  29. # a.pop(0).split()
  30. #
  31. # first = m
  32. #
  33. # cntr = 0
  34. # max = 0
  35. #
  36. # for i in range(len(a)):
  37. # a[i] = int(a[i])
  38. #
  39. # a.sort()
  40. # for i in range(len(a)):
  41. # if 310 <= a[i] <= 320:
  42. # cntr += 1
  43. # m -= a[i]
  44. #
  45. # for i in range(len(a)):
  46. # if m - a[i] >= 0:
  47. # m -= a[i]
  48. # cntr += 1
  49. # max = a[i]
  50. # else:
  51. # m += max
  52. # if m - a[i] >= 0:
  53. # max = a[i]
  54. # m -= max
  55. # print(cntr, first - m)
  56.  
  57. # with open('DZ1.txt') as f:
  58. # a = f.readlines()
  59. #
  60. # m = a.pop(0).split()
  61. #
  62. # s = int(m[0])
  63. # n = int(m[1])
  64. #
  65. # for i in range(len(a)):
  66. # a[i] = int(a[i])
  67. #
  68. # a.sort()
  69. #
  70. # cntr = 0
  71. # max_ = 0
  72. # summa = 0
  73. #
  74. # for i in range(len(a)):
  75. # if summa + a[i] <= s:
  76. # cntr += 1
  77. # max_ = max(max_, a[i])
  78. # summa += a[i]
  79. # else:
  80. # summa -= max_
  81. # if summa + a[i] <= s:
  82. # max_ = a[i]
  83. # summa += max_
  84. # print(cntr, max_)
  85.  
  86. # with open('DZ3.txt') as f:
  87. # a = f.readlines()
  88. # m = a.pop(0).split()
  89. # n = int(m[0])
  90. # k = int(m[1])
  91. # v = int(m[2])
  92. # for i in range(len(a)):
  93. # a[i] = int(a[i])
  94. # a.sort(reverse=True)
  95. # min_win = 10 ** 10
  96. # min_prize = 10 ** 10
  97. # c_win = 0
  98. # c_prize = c_win
  99. # print(a)
  100. # # min_win = a[k - 1]
  101. # # min_prize = a[k + v - 1]
  102. # for i in range(len(a)):
  103. # if c_win != k:
  104. # c_win += 1
  105. # min_win = min(min_win, a[i])
  106. # if c_win >= k and c_prize != v:
  107. # c_prize += 1
  108. # min_prize = min(min_prize, a[i])
  109. # print(min_prize, min_win)
  110.  
  111. # with open('DZ4.txt') as f:
  112. # m = f.readlines()
  113. # a = m.pop(0).split()
  114. # n, k = int(a[0]), int(a[1])
  115. # for i in range(len(m)):
  116. # m[i] = int(m[i])
  117. # m.sort(reverse=True)
  118. # the_best = m[0:k]
  119. # excell = sum(the_best) // len(the_best)
  120. # the_good = m[k:2 * k]
  121. # print(len(the_good))
  122. # good = sum(the_good) // len(the_good)
  123. # print(good, excell)
  124.  
  125.  
  126. # a = []
  127. # cntr = 0
  128. # max_sum = - 10 ** 10
  129. # with open('17-1 (1).txt') as f:
  130. # for line in f:
  131. # a.append(int(line))
  132. # average = sum(a) / len(a)
  133. # print(average)
  134. # for i in range(len(a) - 2):
  135. # first = a[i]
  136. # second = a[i + 1]
  137. # third = a[i + 2]
  138. # c = 0
  139. # funf_c = 0
  140. # if first < average:
  141. # c += 1
  142. # if second < average:
  143. # c += 1
  144. # if third < average:
  145. # c += 1
  146. # if c >= 2:
  147. # if "5" in str(first):
  148. # funf_c += 1
  149. # if "5" in str(second):
  150. # funf_c += 1
  151. # if "5" in str(third):
  152. # funf_c += 1
  153. # if funf_c >= 2:
  154. # cntr += 1
  155. # summa = first + second + third
  156. # max_sum = max(max_sum, summa)
  157. # print(first, second, third, summa)
  158. # print(cntr, max_sum)
  159.  
  160. # cntr = 0
  161. # for a in "жалей":
  162. # for b in "жалей":
  163. # for c in "жалей":
  164. # for d in "жалей":
  165. # for e in "жалей":
  166. # s = a + b + c + d + e
  167. # if (s.count("й") == 1 or s.count("й") == 0) and s[0] != "й" \
  168. # and s[4] != "й" and not("йе" in s) and not('ей' in s):
  169. # cntr += 1
  170. # print(cntr)
  171.  
  172. # print('x y z w')
  173. # for x in range(2):
  174. # for y in range(2):
  175. # for z in range(2):
  176. # for w in range(2):
  177. # f = (w <= z) and ((y <= x) == (z <= y))
  178. # if f:
  179. # print(x, y, z, w)
  180.  
  181. # def f(n):
  182. # str_n = bin(n).removeprefix('0b')
  183. # str_n = str_n + str_n[len(str_n) - 1]
  184. # if int(str_n, 2) % 2 == 0:
  185. # str_n = str_n + "0"
  186. # else:
  187. # str_n = str_n + "1"
  188. # if int(str_n, 2) % 2 == 0:
  189. # str_n = str_n + "0"
  190. # else:
  191. # str_n = str_n + "1"
  192. # return int(str_n, 2)
  193. #
  194. #
  195. # for i in range(1, 1000):
  196. # print(i, f(i))
  197.  
  198. # import turtle as t
  199. #
  200. # t.tracer(0, 0)
  201. # t.left(90)
  202. # k = 20
  203. #
  204. # for i in range(11):
  205. # t.forward(8 * k)
  206. # t.left(120)
  207. #
  208. # t.up()
  209. #
  210. # for x in range(-20, 20):
  211. # for y in range(-20, 20):
  212. # t.goto(x * k, y * k)
  213. # t.dot(2)
  214. #
  215. # t.update()
  216. # t.mainloop()
  217.  
  218. # s = 84 * '9'
  219. # while "33333" in s or "999" in s:
  220. # if "33333" in s:
  221. # s = s.replace("33333", "99", 1)
  222. # else:
  223. # s = s.replace("999", "3", 1)
  224. # print(s)
  225.  
  226. # n = 36 ** 10 + 6 ** 25 - 15
  227. # c = 0
  228. # while n > 0:
  229. # if n % 6 == 0:
  230. # c += 1
  231. # n //= 6
  232. # print(c)
  233.  
  234. # def f(n):
  235. # if n < 4:
  236. # return n - 1
  237. # if n >= 4 and n % 3 == 0:
  238. # return n + 2 * f(n - 1)
  239. # if n >= 4 and n % 3 != 0:
  240. # return f(n - 2) + f(n - 3)
  241. # print(f(25))
  242.  
  243. # a = []
  244. # cntr = 0
  245. # max_summa = 0
  246. # with open('tup.txt') as f:
  247. # for line in f:
  248. # a.append(int(line))
  249. # average = sum(a) / len(a)
  250. # for i in range(len(a) - 1):
  251. # if (a[i] < average or a[i + 1] < average) and (a[i] % 100 == 13 or a[i + 1] % 100 == 13):
  252. # cntr += 1
  253. # max_summa = max(max_summa, a[i] + a[i + 1])
  254. # print(cntr, max_summa)
  255.  
  256. # def win(s):
  257. # return s >= 165
  258. #
  259. # def first(s):
  260. # return (win(s + 1) or win(2 * s)) and not(win(s))
  261. #
  262. # def second(s):
  263. # return first(s + 1) and first(s + 2) and not win(s)
  264. #
  265. # def third(s):
  266. # return (second(s + 1) or second(s + 2)) and not(win(s))
  267.  
  268. # def func(s, f):
  269. # if s == f:
  270. # return 1
  271. # if s > f:
  272. # return 0
  273. # if s < f:
  274. # return func(s + 1, f) + func(s + 2, f) + func(s * 2, f)
  275. #
  276. #
  277. # print(func(3, 10) * func(10, 13))
  278.  
  279. # a = []
  280. # c = 0
  281. # with open('P1a.txt') as file:
  282. # for line in file:
  283. # a.append(int(line))
  284. # for i in range(len(a) - 1):
  285. # for j in range(i + 1, len(a)):
  286. # if ((a[i] + a[j]) % 2 != 0) and ((a[i] * a[j]) % 13 == 0):
  287. # c += 1
  288. # print(c)
  289.  
  290. # a = []
  291. # c = 0
  292. # with open('P2a.txt') as f:
  293. # for line in f:
  294. # a.append(int(line))
  295. #
  296. # for i in range(len(a) - 1):
  297. # for j in range(i + 1, len(a)):
  298. # if (abs(j - i) >= 7) and (a[i] * a[j]) % 14 == 0:
  299. # c += 1
  300. # print(c)
  301.  
  302. # a = []
  303. # min_s = 10 ** 10000
  304. # with open('P3a.txt') as f:
  305. # for line in f:
  306. # a.append(int(line))
  307. # for i in range(len(a) - 1):
  308. # for j in range(i + 1, len(a)):
  309. # if abs(j - i) >= 5:
  310. # min_s = min(min_s, a[i] ** 2 + a[j] ** 2)
  311. # print(min_s)
  312.  
  313. # a = []
  314. # with open('DP1a.txt') as f:
  315. # for line in f:
  316. # a.append(int(line))
  317. # a.sort()
  318. # print(a)
  319. # ans = []
  320. # for i in range(0, len(a) - 1):
  321. # for j in range(i + 1, len(a)):
  322. # d = a[j] - a[i]
  323. # a1 = a[i]
  324. # progr = [a1]
  325. # if 1 <= d <= 100:
  326. # while True:
  327. # if (a1 + d) in a:
  328. # progr.append(a1 + d)
  329. # a1 = a1 + d
  330. # else:
  331. # ans.append(progr)
  332. # break
  333. # pr = []
  334. # for i in ans:
  335. # pr.append(len(i))
  336. # print(max(pr))
  337.  
  338.  
  339. # delta = 10 ** 10
  340. # sm = 0
  341. # with open('P1a (1).txt') as f:
  342. # n = int(f.readline())
  343. # for i in range(n):
  344. # a = f.readline().split()
  345. # x, y = int(a[0]), int(a[1])
  346. #
  347. # sm += max(x, y)
  348. #
  349. # if abs(x - y) % 3 == 0 and abs(x - y) < delta:
  350. # delta = abs(x - y)
  351. # with open('P1a (1).txt') as f:
  352. # n = int(f.readline())
  353. #
  354. # arr = []
  355. # if sm % 3 == 0:
  356. # print(sm)
  357. # else:
  358. # for i in range(n):
  359. # a = f.readline().split()
  360. # x, y = int(a[0]), int(a[1])
  361. # if (sm - max(x, y) + min(x, y)) % 3 == 0:
  362. # arr.append(sm - max(x, y) + min(x, y))
  363. # for i in arr:
  364. # print(i % 3, i, max(arr))
  365.  
  366. # a = []
  367. # sm = 0
  368. # with open('P2a (1).txt') as f:
  369. # for line in f:
  370. # line = line.replace('\n', '')
  371. # add = line.split()
  372. # for i in range(len(add)):
  373. # add[i] = int(add[i])
  374. # add.sort()
  375. # a.append(add)
  376. # sm += max(add)
  377. # print(a)
  378. # answers = []
  379. # if sm % 8 == 0:
  380. # print(sm)
  381. # else:
  382. # for i in range(len(a)):
  383. # w = a[i]
  384. # if (sm - w[2] + w[1]) % 8 == 0:
  385. # answers.append(sm - w[2] + w[1])
  386. # if (sm - w[2] + w[0]) % 8 == 0:
  387. # answers.append(sm - w[2] + w[0])
  388. # print(answers)
  389. # print(max(answers))
  390.  
  391. # with open('P3a (1).txt') as f:
  392. # for line in f:
  393. # line = line.replace('\n', '')
  394. # add = line.split()
  395. # for i in range(len(add)):
  396. # add[i] = int(add[i])
  397. # add.sort()
  398. # a.append(add)
  399. # sm += max(add)
  400.  
  401. # print('x y z w')
  402. # for x in range(2):
  403. # for y in range(2):
  404. # for z in range(2):
  405. # for w in range(2):
  406. # f = (x <= y) and (y <= z) and (z <= w)
  407. # if f:
  408. # print(x, y, z, w)
  409.  
  410.  
  411. # def f(n):
  412. # str_n = bin(n).removeprefix('0b')
  413. # for t in range(2):
  414. # sm = 0
  415. # for i in str_n:
  416. # sm += int(i)
  417. # str_n = str_n + str(sm % 2)
  418. # return int(str_n, 2)
  419. #
  420. #
  421. # c = 0
  422. # for i in range(1000):
  423. # if f(i) < 100:
  424. # c += 1
  425. # else:
  426. # break
  427. # print(c)
  428.  
  429. # import turtle as t
  430. #
  431. # t.left(90)
  432. # t.tracer(0, 0)
  433. # k = 20
  434. #
  435. # for i in range(15):
  436. # t.forward(15 * k)
  437. # t.right(120)
  438. #
  439. # t.up()
  440. #
  441. # for x in range(-20, 20):
  442. # for y in range(-20, 20):
  443. # t.goto(x * k, y * k)
  444. # t.dot(2)
  445.  
  446.  
  447. # t.mainloop()
  448. # t.update()
  449.  
  450. # cntr = 0
  451. # for a in "ШАРЛТН":
  452. # for b in "ШАРЛТН":
  453. # for c in "ШАРЛТН":
  454. # for d in "ШАРЛТН":
  455. # for e in "ШАРЛТН":
  456. # for f in "ШАРЛТН":
  457. # for g in "ШАРЛТН":
  458. # for h in "ШАРЛТН":
  459. # s = a + b + c + d + e + f + g + h
  460. # # print(s)
  461. # if s.count("Ш") == 1 and s.count("А") == 3 and s.count("Р") == 1 and s.count("Л") == 1 and s.count("Т") == 1\
  462. # and s.count("Н") == 1:
  463. # if ("АА" in s) or ("ШШ" in s) or ("РР" in s) or ("ЛЛ" in s) or ("ТТ" in s) or ("НН" in s):
  464. # cntr += 1
  465. # print(cntr)
  466.  
  467.  
  468. # for i in range(201, 300):
  469. # s = i * '8'
  470. # while ('555' in s) or ('888' in s):
  471. # s = s.replace('555', '8', 1)
  472. # s = s.replace('888', '55', 1)
  473. # print(s, i)
  474. # break
  475. # print(s)
  476. # break
  477. # if s.count('5') == s.count('8'):
  478. # print(i, s)
  479. # break
  480.  
  481. # for x in range(15):
  482. # for y in range(17):
  483. # n = 1 * 15 ** 4 + 2 * 15 ** 3 + 3 * 15 ** 2 + x * 15 ** 1 + 5 * 15 ** 0
  484. # m = 6 * 17 ** 3 + 7 * 17 ** 2 + y * 17 ** 1 + 9 * 17 ** 0
  485. # if ((n + m) % 131) == 0:
  486. # print((n + m) / 131, x, y)
  487.  
  488. # ЗАДАЧА3(ТУПОЙ)
  489. # a = [10, 30, 50, 40, 60, 70, 90, 80]
  490. # max_pr = 0
  491. # n1 = 0
  492. # n2 = 0
  493. # for i in range(len(a) - 1):
  494. # for j in range(i + 1, len(a)):
  495. # if a[i] * a[j] > max_pr and (a[i] + a[j]) % 60 == 0:
  496. # max_pr = a[i] * a[j]
  497. # n1 = a[i]
  498. # n2 = a[j]
  499. # print(n1, n2)
  500.  
  501. #ЭФФЕКТИВНЫЙ
  502. # s = [10, 30, 50, 40, 60, 70, 90, 80]
  503. # d = [0] * 60
  504. #
  505. # max_s = 0
  506. # for x in s:
  507. # if x * d[(60 - x % 60) % 60] > max_s:
  508. # max_s = x * d[(60 - x % 60) % 60]
  509. # p1 = x
  510. # p2 = d[(60 - x % 60) % 60]
  511. #
  512. # if x > d[x % 60]:
  513. # d[x % 60] = x
  514. #
  515. # print(p1, p2)
  516.  
  517. #ЗАДАЧА4(ТУПОЙ)
  518. # s = [75, 123, 5, 40, 15, 3, 65, 80]
  519. # max_sum = 0
  520. # p1, p2 = 0, 0
  521. # for i in range(len(s) - 1):
  522. # for j in range(i + 1, len(s)):
  523. # if (abs(s[i] - s[j])) % 60 == 0:
  524. # if (s[i] + s[j]) > max_sum:
  525. # max_sum = s[i] + s[j]
  526. # p1 = s[i]
  527. # p2 = s[j]
  528. # print(p1, p2)
  529.  
  530. #ЭФФЕКТИВНЫЙ
  531. # s = [75, 123, 5, 40, 15, 3, 65, 80]
  532. # max_s = 0
  533. # d = [0] * 60
  534. # for x in s:
  535. # if x + d[x % 60] > max_s:
  536. # max_s = x + d[x % 60]
  537. # p1 = x
  538. # p2 = d[x % 60]
  539. # if x > d[x % 60]:
  540. # d[x % 60] = x
  541. #
  542. # print(p1, p2)
  543.  
  544. #ЗАДАЧА8(ТУПОЙ)
  545. # s = [30, 30, 150, 20, 40, 100]
  546. # cntr = 0
  547. # for i in range(len(s) - 1):
  548. # for j in range(i + 1, len(s)):
  549. # if (s[i] + s[j]) % 60 == 0 and ((s[i] > 40) or (s[j] > 40)):
  550. # cntr += 1
  551. # print(cntr)
  552.  
  553. #ЭФФЕКТИВНЫЙ
  554.  
  555.  
  556.  
  557. # f = open('P1a (2).txt')
  558. # n = int(f.readline())
  559. # s = [0]
  560. # for i in range(n):
  561. # pair = [int(x) for x in f.readline().split()]
  562. # s = [a + b for a in s for b in pair]
  563. # print(max(x for x in s if x % 3 == 0)) ЭТО тупой метод
  564.  
  565. # f = open('P1b.txt')
  566. # n = int(f.readline())
  567. # s = [0]
  568. # for i in range(n):
  569. # pair = [int(x) for x in f.readline().split()]
  570. # s = [a + b for a in pair for b in s]
  571. # s = {x % 3: x for x in sorted(s)}.values()
  572. # print(max(x for x in s if x % 3 == 0)) Это очень умный метод
  573.  
  574. # f = open('P2b.txt')
  575. # n = int(f.readline())
  576. # s = [0]
  577. # for i in range(n):
  578. # triple = [int(x) for x in f.readline().split()]
  579. # s = [a + b for a in triple for b in s]
  580. # s = {x % 8: x for x in sorted(s)}.values()
  581. # f.close()
  582. # print(max(x for x in s if x % 8 == 0))
  583.  
  584. # f = open('P3b.txt')
  585. # n = int(f.readline())
  586. # s = [0]
  587. # for i in range(n):
  588. # pair = [int(x) for x in f.readline().split()]
  589. # s = [a + b for a in pair for b in s]
  590. # s = {x % 10: x for x in sorted(s)}.values()
  591. # print(max(x for x in s if x % 10 != 5))
  592.  
  593. # #27, Тип2, 1
  594. # n = 10
  595. # s = [1, 3, 5, 4, 6, 7, 9, 10, 12, 11]
  596. # summa = 0
  597. # for i in range(len(s) - 8):
  598. # for j in range(i + 8, len(s)):
  599. # summa = max(summa, s[i] + s[j])
  600. # print(summa) #тупой
  601. #
  602. # n = 10
  603. # data = [1, 3, 5, 4, 6, 7, 9, 10, 12, 11]
  604. # max_x = 0
  605. # sum_max = 0
  606. # for i in range(8, n):
  607. # max_x = max(max_x, data[i - 8])
  608. # sum_max = max(sum_max, max_x + data[i])
  609. # print(sum_max) оптимизированный
  610.  
  611. # #27, Тип2, 2
  612. # n = 12
  613. # a = [1, 5, 5, 8, 9, 4, 12, 14, 6, 7, 9, 8]
  614. # cntr = 0
  615. # for i in range(len(a) - 10):
  616. # for j in range(i + 10, len(a)):
  617. # if a[i] * a[j] % 10 == 0:
  618. # cntr += 1
  619. # print(cntr) тупой
  620. #
  621. # n = 12
  622. # a = [1, 5, 5, 8, 9, 4, 12, 14, 6, 7, 9, 8]
  623. # cntr = 0
  624. # c10 = 0
  625. # c5 = 0
  626. # c2 = 0
  627. # c = 0
  628. # res = 0
  629. # for i in range(10, len(a)):
  630. # if a[i - 10] % 10 == 0:
  631. # c10 += 1
  632. # elif a[i - 10] % 5 == 0:
  633. # c5 += 1
  634. # elif a[i - 10] % 2 == 0:
  635. # c2 += 1
  636. # c += 1
  637. # if a[i] % 10 == 0:
  638. # res += c + c2 + c5 + c10
  639. # elif a[i] % 5 == 0:
  640. # res += c10 + c2
  641. # elif a[i] % 2 == 0:
  642. # res += c10 + c5
  643. # else:
  644. # res += c10
  645. # print(res) оптимизированный
  646.  
  647. # 27, Тип2, 4
  648. # n = 8
  649. # data = [1, 3, 5, 4, 6, 7, 9, 8]
  650. # c = 0
  651. # for i in range(len(data) - 6):
  652. # for j in range(i + 6, len(data)):
  653. # if (data[i] + data[j]) % 2 == 0:
  654. # c += 1
  655. # print(c) тупой
  656.  
  657. # n = 8
  658. # data = [1, 3, 5, 4, 6, 7, 9, 8]
  659. # c1 = 0
  660. # c0 = 0
  661. # ans = 0
  662. # for i in range(6, len(data)):
  663. # if data[i - 10] % 2 == 0:
  664. # c0 += 1
  665. # else:
  666. # c1 += 1
  667. #
  668. # if data[i] % 2 == 0:
  669. # ans += c0
  670. # else:
  671. # ans += c1
  672. # print(ans) оптимизированный
  673.  
  674. # 27, Тип2, 6
  675. # n = 8
  676. # a = [2, 6, 5, 4, 6, 7, 9, 8]
  677. # c = 0
  678. # for i in range(len(a) - 6):
  679. # for j in range(i + 6, len(a)):
  680. # if abs(a[i] - a[j]) % 3 == 0:
  681. # c += 1
  682. # print(c) тупой
  683.  
  684. # n = 8
  685. # a = [2, 6, 5, 4, 6, 7, 9, 8]
  686. # c0 = c1 = c2 = res = 0
  687. # for i in range(6, len(a)):
  688. # if a[i - 6] % 3 == 1:
  689. # c1 += 1
  690. # if a[i - 6] % 3 == 2:
  691. # c2 += 1
  692. # if a[i - 6] % 3 == 0:
  693. # c0 += 1
  694. # if a[i] % 3 == 1:
  695. # res += c1
  696. # if a[i] % 3 == 2:
  697. # res += c2
  698. # if a[i] % 3 == 0:
  699. # res += c0
  700. # print(res) оптимизированный
  701.  
  702. # n = 8
  703. # a = [1, 6, 5, 5, 4, 6, 7, 9, 8]
  704. # max_1 = max_0 = 0
  705. # max_res = 0
  706. # for i in range(6, len(a)):
  707. # if a[i - 6] % 2 == 0:
  708. # max_0 = max(max_0, a[i - 6])
  709. # else:
  710. # max_1 = max(max_1, a[i - 6])
  711. # if a[i] % 2 == 0:
  712. # max_res = max(max_0 + a[i], max_res)
  713. # else:
  714. # max_res = max(max_1 + a[i], max_res)
  715. # print(max_res) оптимизированный
  716.  
  717. # f = open('P1b (1).txt')
  718. # n = int(f.readline())
  719. # k13_0 = k_13_1 = k_0 = k_1 = 0
  720. # # a = [int(x) for x in f.readlines()]
  721. # # c = 0
  722. # # for i in range(len(a) - 1):
  723. # # for j in range(i + 1, len(a)):
  724. # # if (a[i] + a[j]) % 2 == 1 and (a[i] * a[j]) % 13 == 0:
  725. # # c += 1
  726. # # print(c)
  727. # for i in range(n):
  728. # x = int(f.readline())
  729. # if x % 13 == 0 and x % 2 == 0:
  730. # k13_0 += 1
  731. # if x % 13 == 0 and x % 2 == 1:
  732. # k_13_1 += 1
  733. # if x % 13 != 0 and x % 2 == 0:
  734. # k_0 += 1
  735. # if x % 13!= 0 and x % 2 == 1:
  736. # k_1 += 1
  737. # print(k13_0 * k_13_1 + k13_0 * k_1 + k_13_1 * k_0)
  738.  
  739. # f = open('P2b (1).txt')
  740. # n = int(f.readline())
  741. # # res = 0
  742. # # a = [int(x) for x in f.readlines()]
  743. # # for i in range(len(a) - 7):
  744. # # for j in range(i + 7, len(a)):
  745. # # if a[i] * a[j] % 14 == 0:
  746. # # res += 1
  747. # # print(res)
  748. # k14 = k7 = k2 = k = 0
  749. # res = 0
  750. # a = [int(x) for x in f.readlines()]
  751. # for i in range(7, n):
  752. # if a[i - 7] % 14 == 0:
  753. # k14 += 1
  754. # elif a[i - 7] % 7 == 0:
  755. # k7 += 1
  756. # elif a[i - 7] % 2 == 0:
  757. # k2 += 1
  758. # k += 1
  759. # if a[i] % 14 == 0:
  760. # res += k
  761. # elif a[i] % 7 == 0:
  762. # res += k2 + k14
  763. # elif a[i] % 2 == 0:
  764. # res += k7 + k14
  765. # else:
  766. # res += k14
  767. # print(res)
  768.  
  769. # f = open('P3b (1).txt')
  770. # n = int(f.readline())
  771. # a = [int(x) for x in f.readlines()]
  772. # # min_ans = 10 ** 10000
  773. # # for i in range(len(a) - 5):
  774. # # for j in range(i + 5, len(a)):
  775. # # min_ans = min(min_ans, a[i] ** 2 + a[j] ** 2)
  776. # # print(min_ans)
  777. # minimum_x = 199 ** 1000
  778. # min_square = 199 ** 1000
  779. # for i in range(5, len(a)):
  780. # minimum_x = min(minimum_x, a[i - 5])
  781. # min_square = min(min_square, (a[i] ** 2 + minimum_x ** 2) )
  782. # print(min_square)
  783.  
  784. # f = open('DP1b.txt')
  785. # n = int(f.readline())
  786. # a6 = []
  787. # a2 = []
  788. # a3 = []
  789. # a = []
  790. # for i in range(n):
  791. # x = int(f.readline())
  792. # if x % 6 == 0:
  793. # a6 += [x]
  794. # elif x % 3 == 0:
  795. # a3 += [x]
  796. # elif x % 2 == 0:
  797. # a2 += [x]
  798. # else:
  799. # a += [x]
  800. # a.sort()
  801. # a6.sort()
  802. # a2.sort()
  803. # a3.sort()
  804. # # print(a, a3, a2, a6)
  805. # max_ans = 0
  806. # ar = [a[-1], a[-2], a6[-1], a6[-2], a2[-1], a2[-2], a3[-1], a3[-2]]
  807. # print(ar)
  808. # for i in range(len(ar) - 1):
  809. # for j in range(i + 1, len(ar)):
  810. # if ar[i] * ar[j] % 6 == 0:
  811. # max_ans = max(ar[i] * ar[j], max_ans)
  812. # print(max_ans)
  813. # max_ans = 0
  814. # for i in range(len(a)):
  815. # for j in range(len(a6)):
  816. # if a[i] * a6[j] % 6 == 0:
  817. # max_ans = max(max_ans, a[i] * a6[j])
  818. # for i in range(len(a3)):
  819. # for j in range(len(a2)):
  820. # if (a3[i] * a2[j]) % 6 == 0:
  821. # max_ans = max(max_ans, a3[i] * a2[j])
  822. # for i in range(len(a3)):
  823. # for j in range(len(a6)):
  824. # if a3[i] * a6[j] % 6 == 0:
  825. # max_ans = max(max_ans, a3[i] * a6[j])
  826. # for i in range(len(a2)):
  827. # for j in range(len(a6)):
  828. # if a2[i] * a6[j] % 6 == 0:
  829. # max_ans = max(max_ans, a2[i] * a6[j])
  830. # print(max_ans)
  831.  
  832. # f = open('DP2a.txt')
  833. # n = int(f.readline())
  834. # k = [0]
  835. # for i in range(n):
  836. # x = int(f.readline())
  837. # ost = x % 12
  838. # k[ost] += 1
  839. # print(k[0] * (k[0] - 1) // 2 + )
  840. # for i in range
  841.  
  842. # print('x y z w')
  843. # for x in range(2):
  844. # for y in range(2):
  845. # for z in range(2):
  846. # for w in range(2):
  847. # f = (x and (not y)) or (y == z) or (not w)
  848. # if not f:
  849. # print(x, y, z, w)
  850.  
  851. # import turtle as t
  852. #
  853. # k = 10
  854. # t.left(90)
  855. # t.tracer(0, 0)
  856. #
  857. # t.right(315)
  858. # for i in range(7):
  859. # t.forward(16 * k)
  860. # t.right(45)
  861. # t.forward(8 * k)
  862. # t.right(135)
  863. # t.up()
  864. #
  865. # for x in range(-40, 40):
  866. # for y in range(-40, 40):
  867. # t.goto(x * k, y * k)
  868. # t.dot(2)
  869. #
  870. # t.update()
  871. # t.mainloop()
  872.  
  873. # for n in range(4, 300):
  874. # s = '3' + '5' * n
  875. # while ('25' in s) or ('355' in s) or ('555' in s):
  876. # if '25' in s:
  877. # s = s.replace('25', '3', 1)
  878. # if '355' in s:
  879. # s = s.replace('355', '52', 1)
  880. # if '555' in s:
  881. # s = s.replace('555', '23', 1)
  882. # summa = 0
  883. # for i in s:
  884. # summa += int(i)
  885. # if summa == 27:
  886. # print(n, summa)
  887.  
  888. # for x in range(15):
  889. # n = 9 * 15 ** 7 + 7 * 15 ** 6 + 9 * 15 ** 5 + 6 * 15 ** 4 + 8 * 15 ** 3 + x * 15 ** 2 + 1 * 15 ** 1 + 3 * 15 ** 0
  890. # m = 7 * 15 ** 4 + x * 15 ** 3 + 2 * 15 ** 2 + 1 * 15 ** 1 + 3 * 15 ** 0
  891. # if (n + m) % 14 == 0:
  892. # print((n + m) // 14, x, n, m)
  893.  
  894. # for A in range(0, 100):
  895. # flag = 1
  896. # for x in range(0, 100):
  897. # f = ((x & 39) == 0) or ((x & 11 == 0) <= (x & A != 0))
  898. # if not f:
  899. # flag = 0
  900. # if flag:
  901. # print(A)
  902.  
  903. # def f(n):
  904. # if n >= 2025:
  905. # return n
  906. # if n < 2025:
  907. # return n + 3 + f(n + 3)
  908. #
  909. #
  910. # print(f(23) - f(21))
  911.  
  912. # a = []
  913. # with open('17.txt') as file:
  914. # for line in file:
  915. # a.append(int(line))
  916. #
  917. # cntr = 0
  918. # max_sum = -10 ** 100
  919. # min_three = 10 ** 1000
  920. # for i in range(len(a)):
  921. # if len(str(a[i])) == 3:
  922. # min_three = min(min_three, a[i])
  923. #
  924. # for i in range(len(a) - 1):
  925. # n1 = str(a[i])
  926. # n2 = str(a[i + 1])
  927. # cntr_len = 0
  928. # if len(n1) == 3:
  929. # cntr_len += 1
  930. # if len(n2) == 3:
  931. # cntr_len += 1
  932. # if cntr_len == 1:
  933. # print(n1, n2, (a[i] + a[i + 1]) % min_three)
  934. # # if cntr_len == 1:
  935. # # if (a[i] + a[i + 1]) % min_three == 0:
  936. # # cntr += 1
  937. # # max_sum = max(max_sum, a[i] + a[i + 1])
  938. # print(cntr, max_sum)
  939.  
  940. # def win(s):
  941. # return s >= 78
  942. #
  943. #
  944. # def first(s):
  945. # return (win(s + 1) or win(s + 4) or win(s * 4)) and not (win(s))
  946. #
  947. #
  948. # def second(s):
  949. # return first(s + 1) and first(s + 4) and first(s * 4) and not (win(s))
  950. #
  951. #
  952. # def third(s):
  953. # return (second(s + 1) or second(s + 4) or second(s * 4)) and not (win(s))
  954. #
  955. #
  956. # def fourth(s):
  957. # return (third(s + 1) or first(s + 1)) and (third(s + 4) or first(s + 4)) and (third(s * 4) or first(s * 4)) and not win(s)
  958. #
  959. #
  960. # # for i in range(1, 38):
  961. # # if third(i) and not(first(i)):
  962. # # print(i, end=' ')
  963. #
  964. # for i in range(1, 38):
  965. # if fourth(i) and not second(i):
  966. # print(i, end = ' ')
  967.  
  968. # def f(x, y):
  969. # if x == y:
  970. # return 1
  971. # if x > y or x == 13:
  972. # return 0
  973. # if x < y:
  974. # return f(x + 1, y) + f(x + 2, y) + f(x * 3, y)
  975. #
  976. #
  977. # print(f(3, 8) * f(8, 18))
  978.  
  979. # with open('24.txt') as file:
  980. # s = file.readline()
  981. # a = []
  982. # max_len = -10 ** 10
  983. # for i in 'QRS':
  984. # for j in 'QRS':
  985. # for k in 'QRS':
  986. # st = i + j + k
  987. # a.append(st)
  988. # ws = ''
  989. # cntr = 0
  990. # for i in range(len(s)):
  991. # ws += s[i]
  992. # cntr += 1
  993. # last_three = ws[-3::]
  994. # # print(last_three)
  995. # if last_three in a:
  996. # max_len = max(max_len, cntr - 1)
  997. # cntr = 0
  998. # ws = s[i]
  999. # print(max_len)
  1000.  
  1001.  
  1002. # from fnmatch import fnmatch
  1003. #
  1004. # for i in range(1200381, 10 ** 8 + 1, 273):
  1005. # if fnmatch(str(i), "12??36*1"):
  1006. # print(i, i / 273)
  1007.  
  1008. # f = open('27B.txt')
  1009. # n = int(f.readline())
  1010. # k = int(f.readline())
  1011. # a = []
  1012. # for line in f:
  1013. # a.append(int(line))
  1014. # max_x = 0
  1015. # max_sum = 0
  1016. # for i in range(25, len(a)):
  1017. # max_x = max(max_x, a[i - k])
  1018. # max_sum = max(max_sum, max_x + a[i])
  1019. # print(max_sum)
  1020. #
  1021.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement