problem_id stringlengths 32 32 | name stringlengths 2 54 | problem stringlengths 204 5.28k | solutions listlengths 1 5.17k | test_cases stringlengths 38 86.7k | difficulty stringclasses 1
value | language stringclasses 1
value | source stringclasses 1
value | num_solutions int64 1 5.17k | starter_code stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|
b50a323239599a39079a5be33a3b8d55 | Change-free | Student Arseny likes to plan his life for *n* days ahead. He visits a canteen every day and he has already decided what he will order in each of the following *n* days. Prices in the canteen do not change and that means Arseny will spend *c**i* rubles during the *i*-th day.
There are 1-ruble coins and 100-ruble notes ... | [
"from heapq import *\n\n\nn,m = [int(x) for x in input().split(\" \")] \nc = [int(x) for x in input().split(\" \")]\nw = [int(x) for x in input().split(\" \")]\nplan = [[0,0] for i in range(n)]\ncost_tot = 0\nQ = []\nfor i in range(n):\n q = c[i]//100\n r = c[i]%100\n plan[i][0] = q\n plan[i][1] = r\n ... | {"inputs": ["5 42\n117 71 150 243 200\n1 1 1 1 1", "3 0\n100 50 50\n1 3 2", "5 42\n117 71 150 243 200\n5 4 3 2 1", "5 32\n83 13 61 34 31\n7 5 6 8 8", "14 138\n479 330 487 127 170 55 122 480 331 434 447 246 104 263\n1 1 1 1 1 1 1 1 1 1 1 1 1 1", "1 0\n49\n2", "1 100\n51\n2", "1 50\n51\n100000", "20 148\n469 474 336 120 ... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
b52e1bb705348e452f7a8fab3f31c955 | Filya and Homework | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc... | [
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=list(set(a))\r\nif (len(s)==3 and sum(s)%3==0 and sum(s)/3 in s) or len(s)<3:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ",
"n = int(input())\r\nlista = list(map(int,input().split()))\r\n\r\nlista.sort()\r\n\r\ncountDiff = 1\r\ndiff = []\r\nfor i i... | {"inputs": ["5\n1 3 3 2 1", "5\n1 2 3 4 5", "2\n1 2", "3\n1 2 3", "3\n1 1 1", "2\n1 1000000000", "4\n1 2 3 4", "10\n1 1 1 1 1 2 2 2 2 2", "2\n4 2", "4\n1 1 4 7", "3\n99999999 1 50000000", "1\n0", "5\n0 0 0 0 0", "4\n4 2 2 1", "3\n1 4 2", "3\n1 4 100", "3\n2 5 11", "3\n1 4 6", "3\n1 2 4", "3\n1 2 7", "5\n1 1 1 4 5", "2\... | UNKNOWN | PYTHON3 | CODEFORCES | 159 | |
b534f7c7d0bc5fa08e541dd75d932c2c | Prizes, Prizes, more Prizes | Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After ... | [
"\r\nn = int(input())\r\np = [int(x) for x in input().split()]\r\na, b, c, d, e = map(int, input().split())\r\n\r\namt = [0,0,0,0,0]\r\ntotal = 0\r\nfor i in range(n):\r\n total += p[i]\r\n\r\n amt[4] += int(total/e)\r\n total -= int(total/e)*e\r\n amt[3] += int(total/d)\r\n total -= int(total/d)*d\r... | {"inputs": ["3\n3 10 4\n2 4 10 15 20", "4\n10 4 39 2\n3 5 10 11 12", "1\n45\n1 2 3 4 5", "1\n50\n1 2 4 5 6", "1\n6\n1 2 4 6 7", "1\n11\n1 2 3 6 8", "45\n54672703 354223499 798425228 192616902 934526477 130046515 120969797 1128116 221465324 487958664 211577865 653388287 538234 467693667 387627267 811104156 26715905 1085... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
b55445c6d760c93b19a016fc27f199d0 | Snow Footprints | There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave... | [
"input(); a = input()\r\nl=a.count('L')\r\nr=a.count('R')\r\nif (r==0):\r\n print(a.rindex('L')+1,a.index('L'))\r\nelif (l==0):\r\n print( a.index('R')+1,a.rindex('R')+2,)\r\nelse :\r\n print(a.index('R')+1,a.index('L'))",
"import string\r\nn=int(input())\r\ns=input()\r\nif 'L' not in s:\r\n print(s.f... | {"inputs": ["11\n.RRRLLLLL..", "4\n.RL.", "3\n.L.", "3\n.R."], "outputs": ["7 5", "3 2", "2 1", "2 3"]} | UNKNOWN | PYTHON3 | CODEFORCES | 101 | |
b56f70fce31dc3a7f2ae03d2a68d63b7 | Mathematical Analysis Rocks! | Students of group 199 have written their lectures dismally. Now an exam on Mathematical Analysis is approaching and something has to be done asap (that is, quickly). Let's number the students of the group from 1 to *n*. Each student *i* (1<=≤<=*i*<=≤<=*n*) has a best friend *p*[*i*] (1<=≤<=*p*[*i*]<=≤<=*n*). In fact, e... | [
"import string\r\n\r\n\r\ndef main_function():\r\n n = int(input())\r\n a = [int(i) for i in input().split(\" \")]\r\n b = [int(i) for i in input().split(\" \")]\r\n hash_a = [0 for i in range(n + 1)]\r\n hash_b = [0 for i in range(n + 1)]\r\n for i in range(len(a)):\r\n hash_a[a[i]] = i + ... | {"inputs": ["4\n2 1 4 3\n3 4 2 1", "5\n5 2 3 1 4\n1 3 2 4 5", "2\n1 2\n2 1", "1\n1\n1", "2\n1 2\n1 2", "3\n2 3 1\n1 2 3", "3\n1 2 3\n2 1 3", "3\n1 2 3\n1 2 3", "4\n1 2 3 4\n2 1 4 3", "5\n4 1 2 5 3\n2 3 5 1 4", "10\n2 9 1 7 6 8 5 4 10 3\n6 8 5 1 9 10 2 3 4 7", "10\n5 9 7 1 4 10 3 6 2 8\n8 3 9 10 6 5 2 1 7 4", "10\n9 10 ... | UNKNOWN | PYTHON3 | CODEFORCES | 55 | |
b577e53a353f5d81e069f5c1079023ae | I.O.U. | Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The... | [
"n, m = map(int, input().split())\r\nd = [0 for i in range(n)]\r\nfor i in range(m):\r\n a, b, c = map(int, input().split())\r\n d[a-1] -= c\r\n d[b-1] += c\r\nprint(sum(i for i in d if i > 0))",
"n, m = map(int, input().split())\r\nans = 0\r\nw = [0] * n\r\nwhile m:\r\n a, b, c = map(int, input().spl... | {"inputs": ["5 3\n1 2 10\n2 3 1\n2 4 1", "3 0", "4 3\n1 2 1\n2 3 1\n3 1 1", "20 28\n1 5 6\n1 12 7\n1 13 4\n1 15 7\n1 20 3\n2 4 1\n2 15 6\n3 5 3\n3 8 10\n3 13 8\n3 20 6\n4 6 10\n4 12 8\n4 19 5\n5 17 8\n6 9 9\n6 16 2\n6 19 9\n7 14 6\n8 9 3\n8 16 10\n9 11 7\n9 17 8\n11 13 8\n11 17 17\n11 19 1\n15 20 2\n17 20 1", "20 36\n1... | UNKNOWN | PYTHON3 | CODEFORCES | 99 | |
b596102013f72cefd7ac7e1ee3b233f1 | Ravioli Sort | Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you...
You come up with... | [
"n=int(input())\r\nx=list(map(int,input().split()))\r\ncount=0\r\nfor i in range(n-1):\r\n if x[i]+1==x[i+1] or x[i]-1==x[i+1] or x[i]==x[i+1]: count+=1\r\n else: break\r\nif count==n-1: print('YES')\r\nelse: print('NO')",
"#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-08 22:48:52... | {"inputs": ["3\n1 2 3", "3\n3 1 2", "1\n13", "10\n67 67 67 67 67 67 67 67 67 67", "10\n16 17 16 15 14 15 16 17 16 15", "4\n54 54 54 55", "3\n68 67 67", "5\n46 46 47 46 45", "4\n14 15 15 16", "6\n59 59 60 60 59 58", "3\n40 40 40", "4\n90 91 90 91", "10\n9 9 9 10 10 9 8 8 9 9", "3\n22 23 24", "9\n71 71 70 70 71 70 69 70 ... | UNKNOWN | PYTHON3 | CODEFORCES | 31 | |
b599781f151d50775bd909266a6d2d84 | Steps | One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple.
Vasya noticed that the yard is a rectangu... | [
"n, m = map(int, input().split())\r\nx, y = map(int, input().split())\r\ne = 0\r\n \r\n \r\nfor i in range(int(input())):\r\n dx, dy = map(int, input().split())\r\n a, b = n, m\r\n op1=(m - y)\r\n op2=(y - 1)\r\n op3=(n - x)\r\n op4=(x - 1)\r\n if dy > 0: \r\n a = op1 // dy\r\n elif dy ... | {"inputs": ["4 5\n1 1\n3\n1 1\n1 1\n0 -2", "10 10\n1 2\n1\n-1 0", "10 20\n10 3\n10\n-2 -6\n-1 0\n-8 0\n0 5\n-1 3\n16 -16\n-1 9\n0 -18\n9 -1\n-9 5", "20 10\n14 4\n10\n6 0\n-7 -7\n12 -2\n-4 9\n20 3\n-1 -16\n0 2\n-1 1\n20 0\n-1 1", "1000 2000\n226 566\n20\n0 -100\n-100 100\n100 0\n42 0\n-100 -79\n-66 -16\n0 -7\n-1 0\n0 10... | UNKNOWN | PYTHON3 | CODEFORCES | 90 | |
b59bb60be8ab88d8f6115c8038434653 | Ball Game | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is... | [
"aruncari = int(input(''))\r\n\r\ndef nr_ce_primesc_mingea(aruncari):\r\n numar = 1\r\n for i in range(1, aruncari):\r\n numar = numar + i\r\n if numar > aruncari:\r\n numar = numar - aruncari\r\n print(numar, end=' ')\r\n\r\nnr_ce_primesc_mingea(aruncari)",
"n = int(input())... | {"inputs": ["10", "3", "4", "5", "6", "7", "8", "9", "2", "11", "12", "13", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "96", "97", "98", "99", "100"], "outputs": ["2 4 7 1 6 2 9 7 6", "2 1", "2 4 3", "2 4 2 1", "2 4 1 5 4", "2 4 7 4 2 1", "2 4 7 3 8 6 5", "2 4 7 2 7 ... | UNKNOWN | PYTHON3 | CODEFORCES | 226 | |
b5c7aed54daabe4e21c9ed4af7d7a6e1 | Abracadabra | Polycarpus analyzes a string called abracadabra. This string is constructed using the following algorithm:
- On the first step the string consists of a single character "a". - On the *k*-th step Polycarpus concatenates two copies of the string obtained on the (*k*<=-<=1)-th step, while inserting the *k*-th characte... | [
"saida = 0\ndef func(a, b, c, d, l):\n global saida\n if a > b or c > d or not l:\n return\n saida = max(saida, min(b - c, b - a, d - a, d - c) + 1)\n if b - a < saida or d - c < saida:\n return\n aux = 1 << (l - 1)\n func(a, min(b, aux - 1), c, min(d, aux - 1), l - 1)\n func(a, m... | {"inputs": ["3 6 1 4", "1 1 4 4", "2 2 6 6", "73426655 594361930 343984155 989446962", "169720415 312105195 670978284 671296539", "1 1 1 1", "1 1 2 3", "2 3 1 1", "4 5 6 7", "5 6 5 10", "20 59 93 97", "59 797 761 863", "3563 8248 1195 5811", "26733 47464 19138 46248", "183307 582175 813247 925985", "42765 7043311 39308... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
b5d91d162d7adcda8d76b38528f7d618 | Design Tutorial: Inverse the Problem | There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.
Now ... | [
"from math import inf\r\nfrom collections import *\r\nimport math, os, sys, heapq, bisect, random,threading\r\nfrom functools import lru_cache\r\nfrom itertools import *\r\nimport sys\r\ndef inp(): return sys.stdin.readline().rstrip(\"\\r\\n\")\r\ndef out(var): sys.stdout.write(str(var)) # for fast output, always ... | {"inputs": ["3\n0 2 7\n2 0 9\n7 9 0", "3\n1 2 7\n2 0 9\n7 9 0", "3\n0 2 2\n7 0 9\n7 9 0", "3\n0 1 1\n1 0 1\n1 1 0", "2\n0 0\n0 0", "1\n0", "1\n1", "2\n0 1000000000\n1000000000 0", "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "2\n0 1\n1 0", "4\n0 3 7 6\n3 0 4 9\n7 4 0 2\n6 9 2 0", "3\n0 1 2\n1 0 2\n2 2 0"... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
b5dc46e82fa44550d2c5ae0bef993f26 | Messages | There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* each minute (it can become negative). Vasya can read any message after receiving it at any mome... | [
"n,a,b,c,t=[int(i) for i in (input().split(\" \"))]\r\nans=0\r\n\r\nlis=[int(i) for i in input().split(\" \")]\r\n\r\n\r\nif(b>=c):\r\n ans=n*a\r\nelse:\r\n for i in lis:\r\n ans+=(c*(t-i)+a-b*(t-i))\r\nprint(ans)",
"n, A, B, C, T = list(map(int, input().split()))\n\nt = list(map(int, input().split()... | {"inputs": ["4 5 5 3 5\n1 5 5 4", "5 3 1 1 3\n2 2 2 1 1", "5 5 3 4 5\n1 2 3 4 5", "1 6 4 3 9\n2", "10 9 7 5 3\n3 3 3 3 2 3 2 2 3 3", "44 464 748 420 366\n278 109 293 161 336 9 194 203 13 226 303 303 300 131 134 47 235 110 263 67 185 337 360 253 270 97 162 190 143 267 18 311 329 138 322 167 324 33 3 104 290 260 349 89",... | UNKNOWN | PYTHON3 | CODEFORCES | 107 | |
b5deae704fa7e015b4155280c24f9733 | Count Good Substrings | We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba".
Given a string, you have to find two values:
1. the number of good substrings of even length; 1. the number of good sub... | [
"s = input()\r\nn = len(s)\r\n\r\n#奇数番目、偶数番目に登場するa,bの個数をカウント\r\nodda = 0\r\nevena = 0\r\noddb = 0\r\nevenb = 0\r\n\r\neven = 0\r\nodd = 0\r\n\r\nfor i in range(n):\r\n odd += 1\r\n x = s[i]\r\n if x == \"a\":\r\n if i % 2 == 0:\r\n even += odda\r\n odd += evena\r\n \r\n evena += 1\r\n e... | {"inputs": ["bb", "baab", "babb", "babaa", "baabbbb", "babbbbbaaabaabbabbabbababbaaba", "baabaababaabbaabaaabbbaaaaaabbbabaaaabbbaaaaaaaaabbaabbbaabbaabbaabbababbbbbaaabbaabaaaaabaababbbbababaabaababbbaabbbaabbbbaaaabaabbbaabbbbbabbbabbabaaaabbbabbbaabaaaabbbbabbbababbabaaaabbabababbaaaaaabaabaaaaabbbbabbabbababaaaaabb... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
b5e153d17dff03546ea0123ce9cfe8d4 | T-shirts from Sponsor | One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not ... | [
"import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353\r\nfrom collections import defaultdict\r\nd = defaultdict()\r\nd[\"S\"],d[\"M\"],d[\"L\"],d[\"XL\"],d[\"XXL\"] = M()\r\nvalst = defaultdict()\r\nvalst... | {"inputs": ["1 0 2 0 1\n3\nXL\nXXL\nM", "0 0 0 0 1\n1\nS", "1 0 1 0 1\n1\nS", "1 0 0 0 1\n2\nS\nL", "1 1 1 1 1\n2\nXL\nM", "1 0 1 1 1\n3\nS\nXXL\nL", "1 0 2 1 1\n4\nS\nXXL\nL\nM", "1 0 3 0 1\n5\nS\nS\nS\nXL\nL", "2 1 0 1 3\n4\nXL\nM\nS\nS", "2 2 0 2 1\n6\nS\nXXL\nM\nXL\nXXL\nXL", "3 1 1 4 1\n10\nXL\nL\nL\nXXL\nXXL\nXL\... | UNKNOWN | PYTHON3 | CODEFORCES | 69 | |
b5f0cf3f5a08982e7fb7810190f5c4a9 | Again Twenty Five! | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | [
"if int(input()) == 1:\r\n print(5)\r\nelse:\r\n print(25)",
"n = int(input())\r\nresult = pow(5, n, 100)\r\nprint(result)",
"print(25)\n# Thu Jul 06 2023 12:17:28 GMT+0300 (Moscow Standard Time)\n\n# Thu Jul 06 2023 12:17:33 GMT+0300 (Moscow Standard Time)\n\n# Thu Jul 06 2023 12:17:48 GMT+0300 (Moscow Stand... | {"inputs": ["2", "7", "1000000000000000000", "2000000000000000000", "987654321012345678"], "outputs": ["25", "25", "25", "25", "25"]} | UNKNOWN | PYTHON3 | CODEFORCES | 216 | |
b60b41ba80a849c2e35814b18f11ad83 | Bear and Compressing | Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'.
You are given a set of *q* possible operations. Limak can perform them in any order... | [
"import collections\r\n\r\nn, q = map(int, input().split())\r\nd = collections.defaultdict(list)\r\ncnt, t = [0] * 6, [0] * 6\r\nfor i in range(q):\r\n s1, s2 = input().split()\r\n d[s2].append(s1)\r\n cnt[ord(s2) - ord('a')] += 1\r\nfor s in d['a']:\r\n t[ord(s[0]) - ord('a')] += 1\r\nfor i in range(n ... | {"inputs": ["3 5\nab a\ncc c\nca a\nee c\nff d", "2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c", "6 2\nbb a\nba a", "2 5\nfe b\nbb a\naf b\nfd b\nbf c", "3 4\neb b\nbd a\ncd d\nbb b", "3 36\nab b\nbb a\naf c\nbd b\ncd a\nff c\nce a\nae a\ncb a\nba a\nad d\ndb a\nbf a\nbe a\ncc b\ndc a\nbc a\nca e\naa e\nec b\nac... | UNKNOWN | PYTHON3 | CODEFORCES | 77 | |
b62bc8e7d7903ff97e2f590081085244 | Game of chess unfinished | Once Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. "Aha, blacks certainly didn't win!", — Volodya said and was right for sure. And your task is to say whether whites had won or not.
Pieces on the ch... | [
"import sys\r\nb = 'sabcdefgh'\r\na1,a2,a3,a4 = map(str,input().split())\r\nx1 = b.index(a1[0])-1\r\ny1 = int(a1[1]) -1\r\nx2 = b.index(a2[0])-1\r\ny2 = int(a2[1]) -1\r\nx3 = b.index(a3[0])-1\r\ny3 = int(a3[1]) -1\r\nx4 = b.index(a4[0])-1\r\ny4 = int(a4[1]) -1\r\nc = []\r\nfor i in range(8):\r\n c.append([0]*8)\... | {"inputs": ["a6 b4 c8 a8", "a6 c4 b6 b8", "a2 b1 a3 a1", "a5 c5 c2 a1", "a5 c5 c3 a1", "c1 c2 d1 f1", "a1 a2 c4 c2", "a1 a2 d4 c2", "a1 a2 b4 c2", "b2 c2 b3 c1", "b2 c2 b3 b1", "b3 a8 c2 a3", "b3 a8 c4 a3", "b3 a8 d3 a3", "d4 e5 a7 a5", "d4 e5 b7 a5", "d4 e5 c7 a5", "h7 h8 d8 a8", "h7 h8 c7 a8", "a6 a8 c2 a1", "a7 b7 d... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
b6301df465da106d16a20b6a53b96e3b | Mahmoud and Ehab and the even-odd game | Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that:
- 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab'... | [
"if __name__ == '__main__':\n n = int(input())\n if n == 1:\n print(\"Ehab\")\n elif n % 2 == 0 and n >= 2:\n print('Mahmoud')\n else:\n print('Ehab')",
"# https://codeforces.com/problemset/problem/959/A\r\n# ehab first chosses n\r\nn_ehab = int(input())\r\nprint (\"Mahmoud\") if ... | {"inputs": ["1", "2", "10000", "33333", "5", "1000000000", "999999999", "123123123", "22222221", "22222220", "3", "4", "6", "7", "8", "9", "10", "536870912", "536870913", "536870911"], "outputs": ["Ehab", "Mahmoud", "Mahmoud", "Ehab", "Ehab", "Mahmoud", "Ehab", "Ehab", "Ehab", "Mahmoud", "Ehab", "Mahmoud", "Mahmoud", "... | UNKNOWN | PYTHON3 | CODEFORCES | 224 | |
b63cf6da05f344b33246dec66bd7e951 | The Time | You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedi... | [
"# -*- coding: utf-8 -*-\n\"\"\"codeforces 622B\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1fnRVrX6kGGXBPnaZduqeU_eo6w87jUi5\n\"\"\"\n\nT=input() \na=int(input())\nh=int(T[ :-3])\nm=int(T[-2: ])\n\nx=a//60\ny=a%60 \n\nhour=h+x\nmin=m+y\n\n... | {"inputs": ["23:59\n10", "20:20\n121", "10:10\n0", "12:34\n10000", "00:00\n10000", "00:00\n1440", "23:59\n8640", "10:01\n0", "04:05\n0", "02:59\n1", "05:15\n10", "03:10\n20", "09:11\n0", "19:00\n0", "23:59\n1", "11:59\n1", "19:34\n566", "00:01\n59", "03:30\n0", "22:30\n30", "22:50\n70", "05:12\n0", "09:20\n40", "15:04\... | UNKNOWN | PYTHON3 | CODEFORCES | 186 | |
b6507c39ea5f74da765fc7a4061089ca | Gerald's Hexagon | Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He pain... | [
"a = list(map(int, input().split(' ')))\r\nprint((a[0]+a[1]+a[2])**2 - (a[0]**2 + a[2]**2 +a[4]**2))",
"ar=list(map(int,input().split()))\nprint((ar[0]+ar[1]+ar[2])**2-(ar[0])**2-ar[2]**2-ar[4]**2)\n\n \t \t\t \t\t\t \t \t\t\t\t \t \t",
"a = list(map(int, input().split()))\r\nmx = 0\r\ni = 0\r\nfor ... | {"inputs": ["1 1 1 1 1 1", "1 2 1 2 1 2", "2 4 5 3 3 6", "45 19 48 18 46 21", "66 6 65 6 66 5", "7 5 4 8 4 5", "3 2 1 4 1 2", "7 1 7 3 5 3", "9 2 9 3 8 3", "1 6 1 5 2 5", "41 64 48 61 44 68", "1 59 2 59 1 60", "30 36 36 32 34 38", "50 40 46 38 52 34", "4 60 4 60 4 60", "718 466 729 470 714 481", "131 425 143 461 95 473... | UNKNOWN | PYTHON3 | CODEFORCES | 147 | |
b6672363faf5a42cbddc6ff649f205ea | Group of Students | At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got ... | [
"estudiantes = int(input())\ncalificaciones = list(str(input()).split())\nxy = list(str(input()).split())\ncontador1 = 0\ncontador2 = 0\npartitura = 0\nentro = False\nfor i in range(len(calificaciones)):\n calificaciones[i] = int(calificaciones[i])\nxy[0] = int(xy[0])\nxy[1] = int(xy[1])\n\nfor j in range(len(ca... | {"inputs": ["5\n3 4 3 2 1\n6 8", "5\n0 3 3 4 2\n3 10", "2\n2 5\n3 6", "3\n0 1 0\n2 10", "5\n2 2 2 2 2\n5 5", "10\n1 1 1 1 1 1 1 1 1 1\n1 10", "10\n1 1 1 1 1 1 1 1 1 1\n5 5", "6\n0 0 1 1 0 0\n1 6", "7\n3 2 3 3 2 1 1\n5 10", "4\n1 0 0 100\n1 100", "100\n46 6 71 27 94 59 99 82 5 41 18 89 86 2 31 35 52 18 1 14 54 11 28 83 ... | UNKNOWN | PYTHON3 | CODEFORCES | 95 | |
b672c0578e56eba7e555c45884a47834 | Vasya the Hipster | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | [
"def main():\r\n (red_socks, blue_socks) = input().split()\r\n count = 0\r\n (red_socks, blue_socks) = int(red_socks), int(blue_socks)\r\n while int(red_socks) > 0 and int(blue_socks) > 0:\r\n count += 1\r\n (red_socks, blue_socks) = red_socks - 1, blue_socks - 1\r\n print(count, red_so... | {"inputs": ["3 1", "2 3", "7 3", "100 100", "4 10", "6 10", "6 11", "10 40", "11 56", "34 30", "33 33", "100 45", "100 23", "45 12", "1 1", "1 100", "100 1", "68 59", "45 99", "99 100", "100 98", "59 12", "86 4", "68 21", "100 11", "100 10", "15 45", "11 32", "34 96", "89 89"], "outputs": ["1 1", "2 0", "3 2", "100 0",... | UNKNOWN | PYTHON3 | CODEFORCES | 958 | |
b69966fa1be3df61ae53f6d11ed7ea9a | Dima and Two Sequences | Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*).
Now Dima wants to count the number of distinct sequences of points of length 2·*n* that can be assembled from these sequences, such that... | [
"n = int(input()) #tamaño de las sucesiones\r\na_n = input().split() #sucesion a_n\r\nb_n = input().split() #sucesion b_n\r\nk = int(input()) #numero para obtener un resultado de la forma km + r con 0 <= r < k\r\n\r\ndef solution(n, a_n, b_n, k):\r\n c_n = {} #sucesion c_n que representa l... | {"inputs": ["1\n1\n2\n7", "2\n1 2\n2 3\n11", "100\n1 8 10 6 5 3 2 3 4 2 3 7 1 1 5 1 4 1 8 1 5 5 6 5 3 7 4 5 5 3 8 7 8 6 8 9 10 7 8 5 8 9 1 3 7 2 6 1 7 7 2 8 1 5 4 2 10 4 9 8 1 10 1 5 9 8 1 9 5 1 5 7 1 6 7 8 8 2 2 3 3 7 2 10 6 3 6 3 5 3 10 4 4 6 9 9 3 2 6 6\n4 3 8 4 4 2 4 6 6 3 3 5 8 4 1 6 2 7 6 1 6 10 7 9 2 9 2 9 10 1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
b6f07197a8fc3bc347b904acb9b96107 | Xenia and Ringroad | Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete... | [
"n,m = map(int, input().split(\" \"))\r\nx=0\r\nwork = [int(x) for x in input().split()[:m]]\r\npos=1\r\nfor i in range(len(work)):\r\n if(pos>work[i]):\r\n x+=(n-(pos-work[i]))\r\n pos=work[i]\r\n else:\r\n x+=((work[i]-pos))\r\n pos=work[i]\r\nprint(x) ",
"# https://codeforce... | {"inputs": ["4 3\n3 2 3", "4 3\n2 3 3", "2 2\n1 1", "2 2\n1 2", "2 2\n1 2", "100 100\n56 46 1 47 5 86 45 35 81 1 31 70 67 70 62 99 100 47 44 33 78 35 32 37 92 12 95 18 3 22 54 24 22 90 25 22 78 88 51 92 46 84 15 29 28 40 8 5 93 68 77 47 45 76 85 39 84 94 52 69 93 64 31 60 99 17 51 59 62 37 46 47 86 60 88 14 68 22 47 93... | UNKNOWN | PYTHON3 | CODEFORCES | 89 | |
b70de8293485a4fce89810f0c6ad4733 | Tricky Sum | In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*.
Th... | [
"t = int(input())\r\nfor _ in range(t):\r\n x = int(input())\r\n s = (x * (x+1)) // 2\r\n y = 1\r\n z = 0\r\n while y <= x:\r\n z += y\r\n y *= 2\r\n print(s - z*2)\r\n",
"t = int(input())\r\nfor i in range(t):\r\n n = int(input())\r\n s = ((n+1)*n)//2\r\n i = 1\r\n whi... | {"inputs": ["2\n4\n1000000000", "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "100\n901\n712\n3\n677\n652\n757\n963\n134\n205\n888\n847\n283\n591\n984\n1\n61\n540\n986\n950\n729\n104\n244\n500\n461\n251\n685\n631\n803\n526\n600\n1000\n899\n411\n219\n597\n342\n771\n348\n507\n775\n454\... | UNKNOWN | PYTHON3 | CODEFORCES | 261 | |
b713b03e6099d1ef6f57349f4ce7e41e | Chloe and the sequence | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq... | [
"def getAns(n, k):\n c = 1 << (n - 1)\n if k == c: return n\n if k < c: return getAns(n - 1, k)\n return getAns(n - 1, k - c)\n\n\nif __name__ == '__main__':\n n, k = map(int, input().strip().split())\n print(getAns(n, k))\n\t \t\t \t \t \t\t \t \t \t\t\t\t \t\t \t",
"n, k = map(int, input... | {"inputs": ["3 2", "4 8", "5 27", "7 44", "15 18432", "20 259676", "30 671088640", "38 137438953472", "1 1", "3 3", "4 12", "8 224", "13 1368", "16 49152", "19 1024", "24 15204352", "27 6586544", "31 536870912", "38 94489280512", "42 215268308020", "42 3452074721280", "46 34394312982528", "48 133865540681728", "49 7654... | UNKNOWN | PYTHON3 | CODEFORCES | 237 | |
b7238b46f51e396406ba4766796bbe9e | DZY Loves Chemistry | DZY loves chemistry, and he enjoys mixing chemicals.
DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order.
Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY ... | [
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Jan 24 21:16:11 2022\r\n\r\n@author: Lai Phuc\r\nproblem 445B - codeforce\r\n\"\"\"\r\nn, m = map(int, input().split(\" \"))\r\nroot = list(range(n+1))\r\ndef find_root(u):\r\n if u == root[u]:\r\n return u\r\n else:\r\n return find_root(root[... | {"inputs": ["1 0", "2 1\n1 2", "3 2\n1 2\n2 3", "10 10\n1 8\n4 10\n4 6\n5 10\n2 3\n1 7\n3 4\n3 6\n6 9\n3 7", "20 20\n6 8\n13 20\n7 13\n6 17\n5 15\n1 12\n2 15\n5 17\n5 14\n6 14\n12 20\n7 20\n1 6\n1 7\n2 19\n14 17\n1 10\n11 15\n9 18\n2 12", "30 30\n7 28\n16 26\n14 24\n16 18\n20 29\n4 28\n19 21\n8 26\n1 25\n14 22\n13 23\n... | UNKNOWN | PYTHON3 | CODEFORCES | 60 | |
b7309b7ebc8cd521bc6f78479feeec2b | Flipping Game | Iahub got bored, so he invented a game to be played on paper.
He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in... | [
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nmax_ones = 0\r\n\r\nfor i in range(n):\r\n for j in range(i, n):\r\n temp = a.copy()\r\n for k in range(i, j+1):\r\n temp[k] = 1 - temp[k]\r\n max_ones = max(max_ones, temp.count(1))\r\n\r\nprint(max_ones)\r\n",
"n=... | {"inputs": ["5\n1 0 0 1 0", "4\n1 0 0 1", "1\n1", "1\n0", "8\n1 0 0 0 1 0 0 0", "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "23\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "100\n0 1 0 1 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 167 | |
b7615d17dd2c5e3883a3b7d1502b8c28 | Tavas and SaDDas | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | [
"def count_lucky_numbers(n):\r\n d = len(n)\r\n s = \"\"\r\n for i in range(d):\r\n if n[i] == '4':\r\n s += '0'\r\n else:\r\n s += '1'\r\n return 2*(2**(d-1)-1)+int(s,2)+1\r\n\r\nn = input() # Input lucky number\r\nindex = count_lucky_numbers(n)\r\nprint(index)\r\n"... | {"inputs": ["4", "7", "77", "4", "474744", "777774", "447", "774", "4", "4447747", "7747474", "4444", "4447", "7", "4", "4447744", "77474", "7747", "444", "7", "7774477", "4477774", "7444", "7474747", "77", "774477", "7", "47", "747777", "444444444", "777777777", "477477447", "777744747"], "outputs": ["1", "2", "6", "1... | UNKNOWN | PYTHON3 | CODEFORCES | 524 | |
b762206307f1cbfb8fb8c9bee5981ae9 | Is it rated? | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | [
"t = int(input())\r\nleft = []\r\nright = []\r\nfor i in range(t):\r\n x , y = input().split()\r\n x , y = int(x) , int(y)\r\n left.append(x)\r\n right.append(y)\r\nif left != right :print('rated')\r\nelif left == right and sorted(left , reverse=True) != left and sorted(right , reverse=True) != right:... | {"inputs": ["6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "2\n1 1\n1 1", "2\n4126 4126\n4126 4126", "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\... | UNKNOWN | PYTHON3 | CODEFORCES | 505 | |
b78c48bd93b78adcb886a8bf17ea0d92 | Dasha and Puzzle | Dasha decided to have a rest after solving the problem. She had been ready to start her favourite activity — origami, but remembered the puzzle that she could not solve.
The tree is a non-oriented connected graph without cycles. In particular, there always are *n*<=-<=1 edges in a tree with *n* vertices.
The puzzle ... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nG = [[] for _ in range(n + 1)]\r\nfor _ in range(n - 1):\r\n u, v = map(int, input().split())\r\n G[u].append(v)\r\n G[v].append(u)\r\ninf = pow(10, 9) + 1\r\npow2 = [1]\r\nfor _ in range(40):\r\n... | {"inputs": ["7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7", "6\n1 2\n2 3\n2 4\n2 5\n2 6", "4\n1 2\n2 3\n3 4", "10\n2 9\n9 3\n3 10\n9 4\n9 6\n9 5\n2 7\n2 1\n2 8", "10\n2 5\n5 6\n6 1\n6 7\n6 8\n5 10\n5 3\n2 9\n2 4", "8\n7 8\n8 2\n2 4\n8 6\n8 5\n7 3\n7 1", "10\n10 9\n9 3\n3 4\n4 5\n5 1\n1 8\n8 2\n2 6\n6 7", "12\n1 5\n5 7\n7 4\n4 6\n4 ... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
b7a803bd3143ed90bd6acb94d848ca80 | Bank Robbery | A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe f... | [
"n = [int(x) for x in input().split()]\r\nnum = int(input())\r\nacc = [int(x) for x in input().split()]\r\ncount = 0\r\nfor i in acc:\r\n if(n[1]<i and n[2]>i):\r\n count+=1\r\nprint(count)",
"a, b, c = map(int, input().split()); n = int(input())\r\nprint(sum(1 for x in input().split() if int(x) in rang... | {"inputs": ["5 3 7\n8\n4 7 5 5 3 6 2 8", "6 5 7\n5\n1 5 7 92 3", "3 2 4\n1\n3", "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6", "7 3 10\n5\n3 3 3 3 3", "3 2 5\n4\n1 3 4 5", "3 2 4\n1\n1", "6 4 8\n1\n4", "2 1 3\n1\n3"], "outputs": ["4", "0", "1", "8", "0", "2", "0", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 221 | |
b7bb00724e30ca5e030171a98d9c0d0c | Polo the Penguin and Houses | Little penguin Polo loves his home village. The village has *n* houses, indexed by integers from 1 to *n*. Each house has a plaque containing an integer, the *i*-th house has a plaque containing integer *p**i* (1<=≤<=*p**i*<=≤<=*n*).
Little penguin Polo loves walking around this village. The walk looks like that. Firs... | [
"n, k = [int(x) for x in input().split()]\r\nresult = ((n - k) ** (n - k)) * ((k) ** (k - 1)) % (10 ** 9 + 7)\r\nprint(result)\r\n",
"n,k=map(int,input().split());n-=k;print(k**~-k*n**n%(10**9+7))\n",
"(n, k), mod = map(int, input().split()), 1000000007\nprint((k**(k-1)%mod)*((n-k)**(n-k)%mod)%mod)\n \t \t \t... | {"inputs": ["5 2", "7 4", "8 5", "8 1", "10 7", "12 8", "50 2", "100 8", "1000 8", "999 7", "685 7", "975 8", "475 5", "227 6", "876 8", "1000 1", "1000 2", "1000 3", "1000 4", "1000 5", "1000 6", "657 3", "137 5", "8 8", "9 8", "1 1", "2 1", "2 2", "3 3", "473 4"], "outputs": ["54", "1728", "16875", "823543", "3176523... | UNKNOWN | PYTHON3 | CODEFORCES | 23 | |
b7ce3faab689d1f84c1a04272bc4d6e8 | Classroom Watch | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | [
"# Author: lizi\r\n# Email: [email protected]\r\n\r\nimport sys\r\nimport math\r\n\r\nn = int(input())\r\nans = []\r\nfor i in range(min(n,100)):\r\n p = n - i\r\n s = p\r\n while p > 0:\r\n s += p % 10\r\n p = p // 10\r\n #print(s,' ',p)\r\n if s == n:\r\n ans.append( n - i );\r... | {"inputs": ["21", "20", "1", "2", "3", "100000001", "1000000000", "999999979", "9", "10", "11", "39", "66", "75", "100", "101", "2014", "999999994"], "outputs": ["1\n15", "0", "0", "1\n1", "0", "2\n99999937\n100000000", "1\n999999932", "2\n999999899\n999999908", "0", "1\n5", "1\n10", "1\n33", "1\n60", "0", "1\n86", "2\... | UNKNOWN | PYTHON3 | CODEFORCES | 172 | |
b7d07bbf111bba1f3ecb254e4e9c03d1 | Isomorphic Strings | You are given a string *s* of length *n* consisting of lowercase English letters.
For two given strings *s* and *t*, say *S* is the set of distinct characters of *s* and *T* is the set of distinct characters of *t*. The strings *s* and *t* are isomorphic if their lengths are equal and there is a one-to-one mapping (bi... | [
"from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nmod=10**9+7\r\nn,q=map(int,input().split())\r\nbase=103\r\ns=[ord(i)-97 for i in input()]\r\n\r\na=[]\r\nfor i in range(26):\r\n b=[0]\r\n tmp=0\r\n res=1\r\n for j in range(n):\r\n res*=base\r\n res%=mod\r\n if s[j]==i:\r\n tmp+... | {"inputs": ["7 4\nabacaba\n1 1 1\n1 4 2\n2 1 3\n2 4 3", "1 2\nz\n1 1 1\n1 1 1", "36 4\naababcbbcbczaaawwwwwaaaabbbbtestbest\n1 7 6\n13 18 5\n23 26 3\n29 33 4", "4 1\nabac\n1 2 3", "5 10\ncaabc\n5 4 1\n5 4 1\n1 5 1\n4 2 2\n1 3 1\n5 5 1\n4 4 1\n4 3 2\n1 4 1\n5 1 1", "10 30\naccbaaccac\n6 8 3\n2 9 1\n6 8 3\n10 5 1\n6 2 2\... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
b7d321c69eff68ca61b821eff8437223 | Median | A median in an array with the length of *n* is an element which occupies position number after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2,<=6,<=1,<=2,<=3) is the number 2, and a median of array (0,<=96,<=17,<=23) — the number 17.
We defi... | [
"import sys\r\ninput = sys.stdin.readline \r\n\r\nn, x = map(int, input().split()) \r\na = list(map(int, input().split()))\r\n\r\nf = 0 \r\nif(x not in a):\r\n a.append(x) \r\n n += 1 \r\n f = 1\r\na.sort()\r\nans, m, c = n, n, 0 \r\nwhile(c <= m and a[(n + 1) // 2 - 1] != x):\r\n c += 1\r\n a.insert... | {"inputs": ["3 10\n10 20 30", "3 4\n1 2 3", "2 2\n3 2", "5 1\n1 1 2 1 2", "5 4\n5 5 4 3 5", "10 2\n2 2 1 3 2 1 2 1 1 3", "10 55749\n46380 58202 54935 26290 18295 83040 6933 89652 75187 93963", "10 809\n949 31 175 118 640 588 809 398 792 743", "50 1\n1 2 1 2 1 1 1 2 2 2 2 2 1 1 2 2 2 2 1 2 2 2 1 2 1 1 2 1 1 1 2 2 2 2 2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 27 | |
b7da26f8d4b9ae6a92c5d977a88d7616 | Balancer | Petya has *k* matches, placed in *n* matchboxes lying in a line from left to right. We know that *k* is divisible by *n*. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired c... | [
"n = int(input())\r\na = list(map(int, input().split()))\r\nsum = 0\r\nfor x in a:\r\n sum += x\r\nt = sum // n\r\nans = 0\r\nfor i in range(n - 1):\r\n if a[i] < t:\r\n ans += (t - a[i])\r\n a[i + 1] -= (t - a[i])\r\n else:\r\n ans += (a[i] - t)\r\n a[i + 1] += (a[i] - t)\r\npr... | {"inputs": ["6\n1 6 2 5 3 7", "6\n6 6 6 0 0 0", "6\n0 0 0 6 6 6", "6\n6 6 0 0 6 6", "5\n0 0 0 0 0", "10\n0 100 0 100 0 100 0 100 0 100", "1\n0", "2\n0 0", "3\n0 0 0", "4\n0 0 0 0", "2\n921 29111", "2\n0 1000000000", "2\n291911 1", "2\n20180000 0", "10\n10 9 7 13 7 5 13 15 10 11", "100\n6 3 4 5 3 4 2 4 1 2 4 1 8 5 2 2 4... | UNKNOWN | PYTHON3 | CODEFORCES | 19 | |
b7dcd21ec503ab2edf961df1c3ec9de6 | k-rounding | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
W... | [
"import math\r\nn,k = map(int,input().split())\r\nm =(n * (10**k)) / math.gcd(n, (10**k))\r\nprint(int(m))",
"def gcd(a, b):\r\n if a == 0:\r\n return b\r\n return gcd(b % a, a)\r\n\r\n\r\ndef nok(a, b):\r\n return a // gcd(a, b) * b\r\n\r\n\r\nn, k = map(int, input().split())\r\nprint(nok(n, 10 *... | {"inputs": ["375 4", "10000 1", "38101 0", "123456789 8", "1 0", "2 0", "100 0", "1000000000 0", "160 2", "3 0", "10 0", "1 1", "2 1", "3 1", "4 1", "5 1", "6 1", "7 1", "8 1", "9 1", "10 1", "11 1", "12 1", "16 2", "2 2", "1 2", "5 2", "15 2", "36 2", "1 8", "8 8", "96 8", "175 8", "9999995 8", "999999999 8", "1234567... | UNKNOWN | PYTHON3 | CODEFORCES | 250 | |
b7f25d647ca43fead8becd81059cb693 | Bear in the Field | Our bear's forest has a checkered field. The checkered field is an *n*<=×<=*n* table, the rows are numbered from 1 to *n* from top to bottom, the columns are numbered from 1 to *n* from left to right. Let's denote a cell of the field on the intersection of row *x* and column *y* by record (*x*,<=*y*). Each cell of the ... | [
"#Simple non-optimized class of matrices. Used with small dense matrices.\nimport functools\nimport itertools\nimport math\n\nclass NotAMatrixError(Exception):\n pass\n\nclass MatrixSizeError(Exception):\n def __init__(self, s1, s2):\n print('sizes do not match : ', s1, ', ', s2)\n\nclass NotSquareErro... | {"inputs": ["5 1 2 0 1 2", "1 1 1 -1 -1 2", "1 1 1 1 1 0", "2 2 1 -2 -2 5", "1000000000 1 1 1 1 1000000000000000000", "1000000000 1 2 -100 -100 1", "3 2 2 -100 -100 2", "1000000000 1000000000 1000000000 100 -100 1000000000000000000", "907122235 107269653 309181328 26 -64 242045007473044676", "804 658 177 -95 37 9", "2 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
b7fb6e57a6651eb7e580fa89cf2c426c | Cutting Rectangle | A rectangle with sides $A$ and $B$ is cut into rectangles with cuts parallel to its sides. For example, if $p$ horizontal and $q$ vertical cuts were made, $(p + 1) \cdot (q + 1)$ rectangles were left after the cutting. After the cutting, rectangles were of $n$ different types. Two rectangles are different if at least o... | [
"from math import gcd\r\n\r\nnum_elements = int(input())\r\n\r\na_vals = [0] * (3000001)\r\nb_vals = [0] * (3000001)\r\nc_vals = [0] * (3000001)\r\n\r\nf1_map = {}\r\nf2_map = {}\r\n\r\nsum_c = 0\r\ngcd_c = 0\r\n\r\nfor i in range(1, num_elements+1):\r\n a_vals[i], b_vals[i], c_vals[i] = map(int, input().split()... | {"inputs": ["1\n1 1 9", "2\n2 3 20\n2 4 40", "2\n1 2 5\n2 3 5"], "outputs": ["3", "6", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
b81d6b2d5370a2792e2da862c3adb452 | Two Squares | You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the ... | [
"def outp(v1,v2):\r\n a1,a2=v1\r\n b1,b2=v2\r\n det = a1*b2-a2*b1\r\n return 'M' if det==0 else ('L' if det>0 else 'R')\r\n\r\ndef check(p,PS):\r\n sides = {'M':0,'L':0,'R':0}\r\n for i in range(4):\r\n v1 = [PS[i+1][0]-PS[i][0],PS[i+1][1]-PS[i][1]]\r\n v2 = [p[0]-PS[i][0],p[1]-PS[i][1]]\r\n sides[ou... | {"inputs": ["0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1", "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7", "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8", "2 2 4 2 4 4 2 4\n0 3 3 6 6 3 3 0", "-5 -5 5 -5 5 5 -5 5\n-5 7 0 2 5 7 0 12", "-5 -5 5 -5 5 5 -5 5\n-5 12 0 7 5 12 0 17", "-5 -5 5 -5 5 5 -5 5\n6 0 0 6 -6 0 0 ... | UNKNOWN | PYTHON3 | CODEFORCES | 54 | |
b82293c0815f13d9f04492522106193c | Cows and Sequence | Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform *n* operations. Each operation is one of the following:
1. Add the integer *x**i* to the first *a**i* elements of the sequence. 1. Append an integer *k**i* to the end of ... | [
"n=int(input())\r\ns=0\r\nc=1\r\nl=[0]\r\nd=[0]\r\nans=[0]*n\r\nfor i in range(n):\r\n x=list(map(int,input().split()))\r\n if x[0]==1:\r\n d[x[1]-1]+=x[2]\r\n s=s+x[1]*x[2]\r\n elif x[0]==2:\r\n l.append(x[1])\r\n d.append(0)\r\n s=s+x[1]\r\n c=c+1\r\n else:\r\... | {"inputs": ["5\n2 1\n3\n2 3\n2 1\n3", "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3", "1\n1 1 1", "1\n2 1", "2\n2 1\n1 2 1", "5\n2 1\n1 2 1\n2 1\n2 1\n1 2 1", "5\n1 1 7\n1 1 7\n1 1 7\n2 5\n1 2 2", "5\n1 1 -48\n1 1 19\n1 1 -35\n2 -67\n1 2 -13", "1\n1 1 0", "1\n2 0", "5\n2 -980\n1 2 -156\n2 641\n2 -253\n2 -514"], "outputs": ["0.500... | UNKNOWN | PYTHON3 | CODEFORCES | 22 | |
b85848958f173f58de6def1bf136ec8e | A Heap of Heaps | Andrew skipped lessons on the subject 'Algorithms and Data Structures' for the entire term. When he came to the final test, the teacher decided to give him a difficult task as a punishment.
The teacher gave Andrew an array of *n* numbers *a*1, ..., *a**n*. After that he asked Andrew for each *k* from 1 to *n*<=-<=1 to... | [
"def f_sum(arr, index):\r\n summa = 0\r\n while index >= 0:\r\n summa += arr[index]\r\n index = (index & (index + 1)) - 1\r\n return summa\r\n\r\n\r\ndef f_add(arr, index, item):\r\n while index < len(arr):\r\n arr[index] += item\r\n index |= index + 1\r\n\r\n\r\ndef solve(n,... | {"inputs": ["5\n1 5 4 3 2", "6\n2 2 2 2 2 2", "2\n0 0", "2\n1 2", "2\n10 -1", "5\n934 235 171 111 197", "100\n0 1 1 1 0 0 0 2 1 2 2 1 2 2 2 0 0 2 1 2 0 1 1 0 2 0 1 2 2 0 2 0 1 0 1 2 0 2 1 1 0 1 0 1 0 0 1 2 2 2 2 1 1 1 0 2 1 0 0 0 0 0 1 0 2 0 1 0 0 2 0 2 2 1 0 2 2 0 2 0 2 1 2 1 1 1 0 2 1 0 2 1 1 2 1 2 0 1 2 2", "2\n-492... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
b8647a7e2926935660a06e9ef1fce9ea | Declined Finalists | This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ... | [
"from sys import stdin\r\nn = stdin.readline()\r\nm = max(list(map(int,stdin.readline().split())))\r\nif m > 25:print(m-25)\r\nelse:print(0) \r\n",
"T = int(input())\rA = [int(x) for x in input().split()]\rprint(0 if max(A) <= 25 else max(A) - 25)\r",
"k=int(input())\r\na=list(map(int,input().split()))\r\nb=max... | {"inputs": ["25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28", "5\n16 23 8 15 4", "3\n14 15 92", "1\n1000000", "25\n1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976", "25... | UNKNOWN | PYTHON3 | CODEFORCES | 279 | |
b86e30843c84440849b6b0560eb93808 | st-Spanning Tree | You are given an undirected connected graph consisting of *n* vertices and *m* edges. There are no loops and no multiple edges in the graph.
You are also given two distinct vertices *s* and *t*, and two values *d**s* and *d**t*. Your task is to build any spanning tree of the given graph (note that the graph is not wei... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef get_root(s):\r\n v = []\r\n while not s == root[s]:\r\n v.append(s)\r\n s = root[s]\r\n for i in v:\r\n root[i] = s\r\n return s\r\n\r\ndef unite(s, t):\r\n rs, rt = get_root(s), get_ro... | {"inputs": ["3 3\n1 2\n2 3\n3 1\n1 2 1 1", "7 8\n7 4\n1 3\n5 4\n5 7\n3 2\n2 4\n6 1\n1 2\n6 4 1 4", "10 15\n4 1\n5 10\n2 1\n5 7\n9 2\n4 6\n6 7\n9 1\n6 9\n8 4\n8 3\n9 8\n3 9\n2 3\n7 10\n10 1 2 3", "10 10\n1 3\n10 3\n6 1\n2 7\n1 7\n1 9\n9 5\n2 10\n10 8\n4 3\n9 5 2 4", "4 4\n1 4\n4 2\n1 3\n4 3\n3 4 3 3", "3 2\n3 1\n2 3\n1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
b8a883f6d70b75a151dc0664da41aa54 | Counting Rectangles is Fun | There is an *n*<=×<=*m* rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call the cell on the *i*-th row and the *j*-th column as (*i*,<=*j*).
Let's define a "rectangle" as four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*<=≤<=*c*<=≤<=*n*; 1<=≤<=*b*<=≤<=*d*<=≤<=*m*). Rectangle denotes... | [
"import os, sys\r\nfrom io import BytesIO, IOBase\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buff... | {"inputs": ["5 5 5\n00101\n00000\n00001\n01000\n00001\n1 2 2 4\n4 5 4 5\n1 2 5 2\n2 2 4 5\n4 2 5 3", "4 7 5\n0000100\n0000010\n0011000\n0000000\n1 7 2 7\n3 1 3 1\n2 3 4 5\n1 2 2 7\n2 2 4 7", "10 10 10\n0010001010\n0011011010\n0100001110\n0010100000\n0000100011\n0100000001\n0000010100\n1000000010\n0000010000\n0110010000... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
b8bf78afb79fadde1f00b79f93ba318c | none | Карта звёздного неба представляет собой прямоугольное поле, состоящее из *n* строк по *m* символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть звезда).
Новое издание карты звёздного неба будет напечатано на квадратных листах, поэто... | [
"z = input().split()\r\na = []\r\nfor i in range(2):\r\n a.append(int(z[i]))\r\nn = a[0]\r\nm = a[1]\r\nb = []\r\nx1 = 1001\r\nx2 = 0\r\ny1 = 1001\r\ny2 = 0\r\nfor i in range(n):\r\n b.append(str(input()))\r\nfor i in range(n):\r\n for j in range(m):\r\n if b[i][j] == '*':\r\n if i < y1 :... | {"inputs": ["4 4\n....\n..*.\n...*\n..**", "1 3\n*.*", "2 1\n.\n*", "1 1\n*", "1 2\n.*", "1 2\n*.", "1 2\n**", "2 1\n.\n*", "2 1\n*\n.", "2 1\n*\n*", "5 3\n..*\n.**\n..*\n...\n..*", "1 1\n*", "1 2\n*.", "1 2\n**", "1 3\n.**", "1 3\n*.*", "1 4\n..**", "1 4\n*..*", "1 5\n.*.**", "1 5\n.*..*", "2 1\n*\n.", "2 1\n*\n*", "2... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
b8d8b73277f7749e7852f8884ff19b71 | Subtractions | You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some num... | [
"for _ in range(int(input())):\r\n a,b=map(int,input().split())\r\n ans=int(0)\r\n while a and b:\r\n a,b=min(a,b),max(a,b)\r\n ans,b=ans+b//a,b%a\r\n print(ans)\r\n",
"import sys\r\n\r\nline = input().split(\" \");\r\n\r\ntest_cases = int(line[0]);\r\n\r\nfor tc in range(test_cases):\r\... | {"inputs": ["2\n4 17\n7 987654321", "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321", "1\n536870912 32", "20\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999... | UNKNOWN | PYTHON3 | CODEFORCES | 242 | |
b8de50a62a5672e6b2de556a0385efe3 | none | Note that girls in Arpa’s land are really attractive.
Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw *n* pairs of friends sitting around a table. *i*-th pair consisted of a boy, sitting on the *a**i*-th chair, and his girlfriend, sitting on the *b**i*-th chair. Th... | [
"n = int(input())\r\n\r\np = [-1] * (2 * n)\r\nc = [-1] * (2 * n)\r\npp = [None] * n\r\n\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n x, y = x-1, y-1\r\n\r\n p[x], p[y] = y, x\r\n pp[i] = (x, y)\r\n\r\nfor i in range(2 * n):\r\n v = i\r\n while c[v] == -1:\r\n c[v] = 1\r\n... | {"inputs": ["3\n1 4\n2 5\n3 6", "6\n3 2\n5 11\n7 12\n6 9\n8 4\n1 10", "19\n30 27\n6 38\n10 28\n20 5\n14 18\n32 2\n36 29\n12 1\n31 24\n15 4\n35 11\n3 7\n21 17\n25 19\n16 8\n23 22\n37 33\n13 9\n34 26", "4\n4 2\n6 8\n5 1\n3 7", "17\n11 12\n17 22\n34 7\n3 1\n5 24\n18 20\n27 30\n16 33\n23 21\n19 4\n2 15\n29 28\n9 8\n13 25\n... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
b8e4040e30b7e2f49655da687a4e31d4 | Bash's Big Day | Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of *k*<=><=1 Pokemon with strengths {*... | [
"n = int(input())\r\narr = list(map(int,input().split()))\r\nN = int(1e5+3)\r\nres, s = 1, [0] * N\r\nfor i in arr:\r\n s[i] += 1\r\nfor i in range(2, N):\r\n p = 0\r\n for j in range(i, N, i):\r\n p += s[j]\r\n res = max(res, p)\r\nprint(res)\r\n",
"input()\r\ns = list(map(int, input().split()... | {"inputs": ["3\n2 3 4", "5\n2 3 4 6 7", "3\n5 6 4", "8\n41 74 4 27 85 39 100 36", "6\n89 20 86 81 62 23", "71\n23 84 98 8 14 4 42 56 83 87 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10", "... | UNKNOWN | PYTHON3 | CODEFORCES | 39 | |
b8ec3437ad5a9b841daa2d404ddece70 | Chat Servers Outgoing Traffic | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
- Include a person... | [
"import sys\nnames = set()\nresult = 0\n\nlines = sys.stdin.readlines()\n\nfor s in lines:\n s = s.strip()\n if '+' in s:\n names.add(s[1:])\n continue\n if '-' in s:\n names.remove(s[1:])\n continue\n name, messsage = s.split(':')\n result += len(names) * len(messsage)\n\... | {"inputs": ["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate", "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM\nDmitry:And digits too\nDmitry:1234567890 0987654321\n-Dmitry", "+Dmit... | UNKNOWN | PYTHON3 | CODEFORCES | 219 | |
b8fffd9ad83f41df8f97739b5e939e71 | Make a Permutation! | Ivan has an array consisting of *n* elements. Each of the elements is an integer from 1 to *n*.
Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in such a way that his array becomes a permutation (i.e. each of the integer... | [
"n = int(input())\na = [int(x) for x in input().split(' ')]\nb = [0] * (n + 1)\narr = []\nused = [0] * (n + 1)\nfor i in range(0, n):\n b[a[i]] += 1\nfor i in range(1, n + 1):\n if b[i] == 0:\n arr.append(i)\n\ncnt = 0\nj = 0;\nfor i in range(0, n):\n if b[a[i]] == 1:\n continue;\n if used[a[i]] == 1:\n ... | {"inputs": ["4\n3 2 2 3", "6\n4 5 6 3 2 1", "10\n6 8 4 6 7 1 6 3 4 5", "6\n5 5 5 6 4 6", "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "50\n1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "50\n2 4 1 2 3 7 ... | UNKNOWN | PYTHON3 | CODEFORCES | 31 | |
b90159b3b2c41c91a4086c3dd7b577d5 | Vladik and Memorable Trip | Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:
Vladik is at initial train station, and now *n* people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code *a**i* i... | [
"from sys import stdin\r\ninput = stdin.readline\r\n \r\ndef answer():\r\n\r\n xor , s = [0] * (n + 1) , set()\r\n for i in range(1 , n + 1):\r\n\r\n xor[i] = xor[i - 1]\r\n \r\n if(a[i - 1] not in s):\r\n xor[i] ^= a[i - 1]\r\n s.add(a[i - 1])\r\n else:\r\n ... | {"inputs": ["6\n4 4 2 5 2 3", "9\n5 1 3 1 5 2 4 2 5", "5\n1558 4081 3591 1700 3232", "10\n3838 1368 4825 2068 4755 2048 1342 4909 2837 4854", "10\n4764 4867 2346 1449 1063 2002 2577 2089 1566 614", "10\n689 3996 3974 4778 1740 3481 2916 2744 294 1376", "100\n1628 4511 4814 3756 4625 1254 906 1033 2420 2622 2640 3225 35... | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
b93fdbb19a50d95418de5887b98a8017 | Sasha and Sticks | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | [
"import sys\ntoks = (tok for tok in sys.stdin.read().split())\n\nn = int(next(toks))\nk = int(next(toks))\ntotal = n // k\nif total % 2 == 0:\n print('NO')\nelse:\n print('YES')\n\n\t \t\t \t\t \t \t\t\t \t\t\t \t \t\t\t \t",
"h,k=[int(i) for i in input().split()]\r\nif ((h//k)%2!=0):\r\n print('yes')\... | {"inputs": ["1 1", "10 4", "251656215122324104 164397544865601257", "963577813436662285 206326039287271924", "1000000000000000000 1", "253308697183523656 25332878317796706", "669038685745448997 501718093668307460", "116453141993601660 87060381463547965", "766959657 370931668", "255787422422806632 146884995820359999", "... | UNKNOWN | PYTHON3 | CODEFORCES | 350 | |
b9435cb564d17c1f2aae1353c4f988ab | Hobbits' Party | Everyone knows that hobbits love to organize all sorts of parties and celebrations. There are *n* hobbits living in the Shire. They decided to organize the Greatest Party (GP) that would last for several days. Next day the hobbits wrote a guest list, some non-empty set containing all the inhabitants of the Shire. To en... | [
"n = int(input())\r\nd = int(0.5 + (1 + 8*n)**0.5 / 2)\r\ncurr = 1\r\nres = [[] for _ in range(d)]\r\n\r\nfor i in range(d):\r\n j = i + 1\r\n while len(res[i]) < d - 1:\r\n res[i].append(str(curr))\r\n res[j].append(str(curr))\r\n curr += 1\r\n j += 1\r\nprint(d)\r\nfor l in res:\... | {"inputs": ["4", "5", "6", "7", "8", "9", "10", "11", "14", "15", "16", "20", "21", "44", "45", "189", "190", "191", "209", "210", "230", "231", "251", "252", "253", "254", "255", "3", "9000", "9100", "9200", "9300", "9400", "9500", "9600", "9700", "9800", "9900", "9998", "9999", "10000", "9868", "9869", "9870", "9871"... | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
b95a8706627d77a638a45e9ced72df03 | none | This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet... | [
"from __future__ import print_function\r\nfrom sys import stdin, stdout\r\n\r\nrints = lambda: [int(x) for x in stdin.readline().split()]\r\nm, n = rints()\r\nans = []\r\n\r\nfor i in range(1, min(n, m) + 1):\r\n print(i, flush=True)\r\n ans.append(int(input()))\r\n\r\n if ans[-1] == 0:\r\n exit()\r... | {"inputs": ["5 2 3\n1 0", "1 1 1\n1", "3 2 3\n1 0", "6 3 5\n1 1 1", "10 4 3\n0 0 1 0", "30 5 16\n0 1 1 1 0", "60 6 21\n1 0 0 1 0 1", "100 7 73\n0 0 0 1 0 1 1", "1000000000 29 958572235\n1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0", "738009704 30 116044407\n0 0 1 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0... | UNKNOWN | PYTHON3 | CODEFORCES | 27 | |
b9622c31d50bf23062fb84ae34d8743b | New Year Book Reading | New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has *n* books numbered by integers from 1 to *n*. The weight of the *i*-th (1<=≤<=*i*<=≤<=*n*) book is *w**i*.
As Jaehyun's house is not large enough to have a bookshelf, he keeps the *n* books by stacking them vertically. Whe... | [
"n, m = map(int,input().split())\r\nw = list(map(int, input().split())) + [0]\r\nb = [(int(x)-1) for x in input().split()]\r\nans = 0\r\nfor i in range(m):\r\n for j in range(i-1,-1,-1):\r\n if b[j] == b[i]:\r\n b[j] = n\r\n break\r\n ans += w[b[j]]\r\nprint(ans)",
"n, m = [... | {"inputs": ["3 5\n1 2 3\n1 3 2 3 1", "3 3\n10 20 30\n1 2 3", "2 2\n10 12\n2 1", "10 10\n61 59 97 16 2 94 57 48 91 93\n2 8 6 5 3 1 3 4 9 10", "50 50\n75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99\n26 30 5 33 35 29 6 15 36... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
b97db026ba1258b019779e2780f685b7 | Lie or Truth | Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*.
While Vasya was walking, his little brother Stepan played with Vasya's cub... | [
"import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\n\nN,L,R = map(int,input().split())\nA = list(map(int,input().split()))\... | {"inputs": ["5 2 4\n3 4 2 3 1\n3 2 3 4 1", "3 1 2\n1 2 3\n3 1 2", "4 2 4\n1 1 1 1\n1 1 1 1", "5 1 3\n2 2 2 1 2\n2 2 2 1 2", "7 1 4\n2 5 5 5 4 3 4\n2 5 5 5 4 3 4", "10 1 10\n6 7 6 1 10 10 9 5 3 9\n7 10 9 6 1 5 9 3 10 6", "1 1 1\n1\n1", "4 3 4\n1 2 3 4\n2 1 3 4", "7 2 4\n1 2 3 4 5 7 6\n1 2 3 4 5 6 7", "5 1 2\n1 2 3 4 5\n... | UNKNOWN | PYTHON3 | CODEFORCES | 56 | |
b9872594d263a975d2c53559931b8334 | Little Pony and Expected Maximum | Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots... | [
"def prob(m, n):\n ans = 0.0\n i = m\n while (i):\n ans += (pow(i / m, n) - pow((i - 1) / m, n)) * i\n i = i - 1\n return ans\n\nm, n = map(int, input().split())\n\nprint(prob(m, n))\n \t \t \t \t \t\t\t \t \t \t \t\t",
"faces,vezes = [int(s) for s in input().split(' ')]\ntotal... | {"inputs": ["6 1", "6 3", "2 2", "5 4", "5 8", "3 10", "3 6", "1 8", "24438 9", "94444 9", "8 66716", "4 25132", "51520 73331", "54230 31747", "24236 90163", "26946 99523", "50323 7", "53033 3", "55743 5", "59964 79", "1 1", "1 1", "3 1", "1 2", "53513 34040", "100000 100000", "1 100000", "100000 1", "2 100000", "10000... | UNKNOWN | PYTHON3 | CODEFORCES | 192 | |
b98a21fa072aed9a5f1c1c67eb2c1ce9 | Create a Maze | ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of *n*<=×<=*m* rooms, and the rooms are arranged in *n* rows (numbered from the top to the bottom starting from 1) and *m* columns (numbered from the left to the right starting from 1). The room in the *i*-th row and *j*-th... | [
"corr = lambda x, y: 1 <= x <= n and 1 <= y <= m\r\n\r\nT = int(input())\r\na = []\r\nwhile T:\r\n a.append(T % 6)\r\n T //= 6\r\nL = len(a)\r\nn = m = L * 2 + 2\r\nans = [(1, 2, 2, 2), (2, 1, 2, 2)]\r\nf = [[1] * 9 for i in range(7)]\r\nf[1][2] = f[2][2] = f[2][6] = f[3][5] = 0\r\nf[4][5] = f[4][6] = f[5][2]... | {"inputs": ["3", "4", "576460752303423488", "576460752303423487", "99999988898898889", "989466010702279111", "1000000000000000000", "1", "2", "201620162016201600", "138944482508455329", "327543848458922240", "516143210114421854", "481370539210112956", "639733286738742273", "604960615834433375", "793559981784900286", "9... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
b9a4afd6adac4ec8d2a946362c08d270 | Chloe and pleasant prizes | Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes.
They took *n* prizes for the contestants and wrote on each of them a unique id (integer... | [
"import sys\r\ninput = sys.stdin.readline\r\n\r\noo = 10**20\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nadj = [[] for _ in range(n)]\r\nfor _ in range(n-1):\r\n u, v = [int(i) - 1 for i in input().split()]\r\n adj[u].append(v)\r\n adj[v].append(u)\r\nsm = [0] * n\r\nmx = [-oo] * n\r\nbes... | {"inputs": ["8\n0 5 -1 4 3 2 6 5\n1 2\n2 4\n2 5\n1 3\n3 6\n6 7\n6 8", "4\n1 -5 1 1\n1 2\n1 4\n2 3", "1\n-1", "10\n3 2 -4 2 0 3 3 3 3 4\n10 8\n4 2\n4 9\n3 5\n5 2\n7 4\n2 6\n1 8\n10 9", "10\n-1 2 -2 -3 -1 -1 0 -4 -5 -4\n4 6\n6 9\n1 2\n6 2\n7 8\n7 9\n5 10\n6 3\n10 1", "10\n4 -4 2 5 -1 3 -1 1 4 5\n1 8\n7 1\n4 1\n9 6\n1 2\n... | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
b9ad6ca1fc6d03437f5d46ec93ad89c2 | Inna and Sweet Matrix | Inna loves sweets very much. That's why she decided to play a game called "Sweet Matrix".
Inna sees an *n*<=×<=*m* matrix and *k* candies. We'll index the matrix rows from 1 to *n* and the matrix columns from 1 to *m*. We'll represent the cell in the *i*-th row and *j*-th column as (*i*,<=*j*). Two cells (*i*,<=*j*) a... | [
"def getCells(n, m, k):\r\n penalty = 0\r\n cells = []\r\n for l in range(2,n+m+1):\r\n iLeft = 1 if l-1 <= m else l-m\r\n iRight = n if l-n > 0 else l-1\r\n for i in range(iLeft, iRight+1):\r\n j = l-i\r\n penalty += l-1\r\n cells.append((i,j))\r\n ... | {"inputs": ["4 4 4", "1 1 1", "1 50 50", "50 1 50", "50 50 1", "4 4 9", "10 10 10", "10 10 100", "10 10 50", "10 10 25", "10 10 75", "50 50 1000", "50 50 2500", "50 50 1", "50 50 10", "50 50 100", "50 50 500", "50 50 200", "50 50 1000", "50 50 1500", "50 50 2000", "50 50 2499", "30 30 56", "30 30 800", "2 2 3", "1 2 1"... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
b9b279d1b0b471a11dcd0b7afc2c685e | Searching for Graph | Let's call an undirected graph of *n* vertices *p*-interesting, if the following conditions fulfill:
- the graph contains exactly 2*n*<=+<=*p* edges; - the graph doesn't contain self-loops and multiple edges; - for any integer *k* (1<=≤<=*k*<=≤<=*n*), any subgraph consisting of *k* vertices contains at most 2*k*<=... | [
"def construct(n, p):\n \n for i in range (2*n + p):\n pos = i % n \n \n # 1, ...\n cycle = (i // n) + 1 \n\n neighbor = (pos + cycle) % n\n\n # convert to 1-index\n print(pos+1, neighbor+1)\n\n\nfor _ in range(int(input())):\n n, p = [int(x) for x in input... | {"inputs": ["1\n6 0", "1\n5 0", "5\n6 0\n5 0\n7 0\n8 0\n9 0", "5\n6 1\n5 0\n7 1\n8 1\n9 1", "5\n24 0\n23 0\n22 0\n21 0\n24 1", "5\n24 1\n23 1\n22 1\n21 1\n20 1", "5\n20 0\n19 0\n18 0\n17 0\n16 0", "5\n15 0\n14 0\n13 0\n12 0\n11 0", "5\n10 0\n20 0\n24 0\n19 0\n17 0", "5\n24 0\n23 0\n24 1\n23 1\n22 0", "5\n24 0\n24 0\n24... | UNKNOWN | PYTHON3 | CODEFORCES | 62 | |
b9b2cf2e122e6b22549b44b01e380445 | Vasya and Wrestling | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of... | [
"n = int(input())\r\npos_arr = []\r\nneg_arr = []\r\npos_sum = 0\r\nneg_sum = 0\r\nfor i in range(n):\r\n x = int(input())\r\n if x>0:\r\n pos_sum += x\r\n pos_arr.append(x)\r\n else:\r\n neg_sum += -x\r\n neg_arr.append(-x)\r\n if i==n-1:\r\n last = x\r\nif pos_sum>ne... | {"inputs": ["5\n1\n2\n-3\n-4\n3", "3\n-1\n-2\n3", "2\n4\n-4", "7\n1\n2\n-3\n4\n5\n-6\n7", "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-12\n-13\n-14", "4\n16\n12\n19\n-98", "5\n-6\n-1\n-1\n5\n3", "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1", "1\n-534365", "1\n10253033", "3\n-1\n-2\n3", "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8", "2\... | UNKNOWN | PYTHON3 | CODEFORCES | 157 | |
b9b4e52303af6ee09e25948b343ce56f | Where Are My Flakes? | One morning the Cereal Guy found out that all his cereal flakes were gone. He found a note instead of them. It turned out that his smart roommate hid the flakes in one of *n* boxes. The boxes stand in one row, they are numbered from 1 to *n* from the left to the right. The roommate left hints like "Hidden to the left o... | [
"n, m = input().split(' ')\r\n\r\nn = int(n)\r\nm = int(m)\r\n\r\nhints = {}\r\n\r\nmax_right = None\r\nmin_left = None\r\n\r\nif m > 0:\r\n\r\n for i in range(m):\r\n do_nothing = False\r\n line = input().split(' ')\r\n hint_position = int(line[4])-1\r\n\r\n if line[2] == 'left':\r\n... | {"inputs": ["2 1\nTo the left of 2", "3 2\nTo the right of 1\nTo the right of 2", "3 1\nTo the left of 3", "3 2\nTo the left of 2\nTo the right of 1", "3 0", "2 2\nTo the left of 2\nTo the left of 2", "5 0", "6 2\nTo the right of 2\nTo the left of 4", "8 6\nTo the right of 3\nTo the left of 4\nTo the left of 4\nTo the ... | UNKNOWN | PYTHON3 | CODEFORCES | 46 | |
b9ce4117c8187dc8b1c2b57344133486 | Case of Fake Numbers | Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of *n* similar gears. Each gear has *n* teeth containing all numbe... | [
"import sys\r\nn=int(input())\r\na=list(map(int, sys.stdin.readline().strip().split()))\r\nnr=n-a[0]\r\nfor i in range(n):\r\n if(i%2==0):\r\n a[i]+=nr\r\n else:\r\n a[i]-=nr\r\n a[i]=a[i]%n\r\nif a == list(range(n)):\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")",
"import sys, os, io... | {"inputs": ["3\n1 0 0", "5\n4 2 1 4 3", "4\n0 2 3 1", "1\n0", "2\n1 0", "5\n2 4 4 1 1", "10\n0 1 2 3 4 5 6 7 8 9", "10\n1 5 1 0 6 1 3 5 9 9", "20\n10 11 12 13 14 15 16 17 18 19 0 1 2 3 4 5 6 7 8 9", "20\n2 15 18 0 3 12 4 16 13 7 17 9 8 2 15 18 19 17 5 8", "50\n38 13 40 15 42 17 44 19 46 21 48 23 0 25 2 27 4 29 6 31 8 3... | UNKNOWN | PYTHON3 | CODEFORCES | 18 | |
b9e45bc4775a8d7761b45f8ab27508bc | Прокат велосипедов | Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат и... | [
"n, k = map(int, input().split())\ncor = [int(x) for x in input().split()]\nN = 1\nkon = n\ntek = 0\n\nwhile tek!=kon-1:\n for i in range(tek+1,kon):\n if cor[i]-cor[tek]>k:\n break\n if cor[kon-1] - cor[tek] <= k:\n break\n if i==tek+1:\n N=-1\n break\n tek=i-1\n ... | {"inputs": ["4 4\n3 6 8 10", "2 9\n10 20", "12 3\n4 6 7 9 10 11 13 15 17 18 20 21", "2 1\n11164 11165", "3 7\n45823 45825 45829", "2 100000\n0 100000", "50 15001\n1269 1580 5431 5916 6642 14145 15760 19922 20589 22062 24138 33454 33505 35916 37012 42577 43140 49457 54720 55188 56205 56639 56870 57997 58379 59088 59297 ... | UNKNOWN | PYTHON3 | CODEFORCES | 103 | |
b9ea26d8fd625c2e46bc6f4fbe356598 | George and Round | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | [
"n, m = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\njb = 0\ncnt = 0\nfor ai in a:\n while jb < m and b[jb] < ai: \n jb += 1\n if jb == m:\n break\n cnt += 1\n jb += 1\n\nprint(len(a) - cnt)\n",
"n, k = map(int, input().split())... | {"inputs": ["3 5\n1 2 3\n1 2 2 3 3", "3 5\n1 2 3\n1 1 1 1 1", "3 1\n2 3 4\n1", "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 ... | UNKNOWN | PYTHON3 | CODEFORCES | 225 | |
b9ec62d47e98670266215b759dd020f0 | Sagheer and Nubian Market | On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<... | [
"def check(n,s,f):\r\n a=[]\r\n for i in range(len(l)):\r\n a.append(l[i]+n*(i+1))\r\n # print(a)\r\n a.sort()\r\n # print(n)\r\n return sum(a[0:n])<=s if f==1 else sum(a[0:n])\r\nn,s=map(int,input().split())\r\nl=list(map(int,input().split()))\r\ni=0\r\n\r\nwhile i<=n:\r\n \r\n mid =... | {"inputs": ["3 11\n2 3 5", "4 100\n1 2 5 6", "1 7\n7", "1 7\n5", "1 1\n1", "4 33\n4 3 2 1", "86 96\n89 48 14 55 5 35 7 79 49 70 74 18 64 63 35 93 63 97 90 77 33 11 100 75 60 99 54 38 3 6 55 1 7 64 56 90 21 76 35 16 61 78 38 78 93 21 89 1 58 53 34 77 56 37 46 59 30 5 85 1 52 87 84 99 97 9 15 66 29 60 17 16 59 23 88 93 3... | UNKNOWN | PYTHON3 | CODEFORCES | 135 | |
b9ffc730bfcf1d8951e5290a7cc2ca24 | Divisibility by 25 | You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes.
In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.
What is the mi... | [
"n = int(input())\r\ns = list(str(n))\r\ns = [int(i) for i in s]\r\nl = len(s)\r\n\r\nif l == 1:\r\n print(-1)\r\n exit()\r\n\r\nimport copy\r\nINF = 10**18\r\nans = INF\r\nfor i in range(l):\r\n for j in range(l):\r\n t = copy.copy(s)\r\n if i == j:\r\n continue\r\n temp = ... | {"inputs": ["5071", "705", "1241367", "7501", "507", "17010", "52231", "50267", "574196831896431419", "1", "10", "123456123450", "1000000000000000000", "100000000000762582", "123456789987654321", "213716413141380147", "5284691", "750000000000000001", "101", "275257725752725722", "50932", "50272", "25", "52", "57", "75"... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
ba27c1ae25a9c6f3a632edc8ad96ab06 | none | Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location by *p*0. First, the robot will move from *p*0 to *p*1 along one of the shortest paths betwe... | [
"n = int(input())\r\ns = input()\r\nl = 0\r\nr = 0\r\nu = 0\r\nd = 0\r\n\r\nc = 1\r\nfor x in s:\r\n if(x=='L'):\r\n if(r==0):\r\n l += 1\r\n else:\r\n c += 1\r\n l = 1\r\n r = 0\r\n u = 0\r\n d = 0\r\n elif(x=='R'):\r\n if... | {"inputs": ["4\nRURD", "6\nRRULDD", "26\nRRRULURURUULULLLDLDDRDRDLD", "3\nRLL", "4\nLRLR", "5\nLRDLR", "10\nDDRDUULUDD", "1\nD"], "outputs": ["2", "2", "7", "2", "4", "4", "3", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 107 | |
ba4d78b29a18d60849c1647760ddd911 | Arpa and a game with Mojtaba | Mojtaba and Arpa are playing a game. They have a list of *n* numbers in the game.
In a player's turn, he chooses a number *p**k* (where *p* is a prime number and *k* is a positive integer) such that *p**k* divides at least one number in the list. For each number in the list divisible by *p**k*, call it *x*, the player... | [
"import sys\r\ninput = sys.stdin.buffer.readline\r\nfrom collections import Counter\r\n\r\ngames = Counter() # prime : bitmask of if that power of the prime exists\r\n\r\ndef add_primes(a):\r\n i = 2\r\n while i*i <= a:\r\n cnt = 0\r\n while a % i == 0:\r\n a //= i\r\n cnt ... | {"inputs": ["4\n1 1 1 1", "4\n1 1 17 17", "4\n1 1 17 289", "5\n1 2 3 4 5", "10\n10 14 16 9 17 13 12 4 6 10", "10\n13 13 18 3 8 9 19 12 20 14", "10\n10 18 16 10 8 20 8 4 4 2", "10\n1 4 15 1 16 14 7 17 11 8", "10\n9 19 4 1 20 7 19 18 11 11", "100\n80 35 113 179 195 92 143 152 125 55 68 121 71 147 172 153 87 68 143 133 32... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
ba5f27a8af10e0175f956f2fcf748134 | Grandma Laura and Apples | Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and ... | [
"n,p=map(int,input().split())\r\nls=[]\r\nfor i in range(n):\r\n x=input()\r\n ls.append(x)\r\nls.reverse()\r\ns=0\r\ncnt=0\r\nfor i in ls:\r\n if i=='halfplus':\r\n s=(s+0.5)*2\r\n cnt+=1\r\n else:\r\n s=s*2\r\nprint(int((s-cnt*0.5)*p))",
"n,k = map(int,input().split())\r\ntot = ... | {"inputs": ["2 10\nhalf\nhalfplus", "3 10\nhalfplus\nhalfplus\nhalfplus", "10 328\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalfplus", "1 2\nhalfplus", "5 6\nhalf\nhalf\nhalfplus\nhalf\nhalfplus", "10 2\nhalfplus\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalf\nhalfplus\nhalfplus"... | UNKNOWN | PYTHON3 | CODEFORCES | 80 | |
ba60028702652ff2df427b79f2f6558d | Functions again | Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function *f*, which is defined ... | [
"n = int(input())\r\narr = list(map(int, input().split()))\r\ndiff = [abs(arr[i] - arr[i-1]) for i in range(1, n)]\r\nres0, res1, res, curr_sum = -2e9, 0, -2e9, 0\r\nfor i in range(n-1):\r\n curr_sum += diff[i] * (1 if i % 2 == 0 else -1)\r\n res = max(res, curr_sum - res1, res0 - curr_sum)\r\n if i % 2 ==... | {"inputs": ["5\n1 4 2 3 1", "4\n1 5 4 7", "8\n16 14 12 10 8 100 50 0", "2\n1 1", "50\n-5 -9 0 44 -10 37 34 -49 11 -22 -26 44 8 -13 23 -46 34 12 -24 2 -40 -15 -28 38 -40 -42 -42 7 -43 5 2 -11 10 43 9 49 -13 36 2 24 46 50 -15 -26 -6 -6 8 4 -44 -3", "100\n23 64 60 -45 -36 -64 -59 15 -75 69 -30 -7 -20 17 -77 58 93 -76 -98 ... | UNKNOWN | PYTHON3 | CODEFORCES | 112 | |
ba61328e541f4203d3920b0fb7fb0ea3 | Wormhouse | Arnie the Worm has finished eating an apple house yet again and decided to move. He made up his mind on the plan, the way the rooms are located and how they are joined by corridors. He numbered all the rooms from 1 to *n*. All the corridors are bidirectional.
Arnie wants the new house to look just like the previous on... | [
"n,m = map(int,input().split())\r\nm+=1\r\np = list(map(lambda x:int(x)-1,input().split()))\r\na = [0]*m\r\nq = [[False]*n for i in range(n)]\r\nd = [[] for i in range(n)]\r\nfor i in range(1,m):\r\n d[p[i]].append(p[i-1])\r\n d[p[i-1]].append(p[i])\r\nfor i in range(n):\r\n d[i].sort()\r\ns = [(p[0],True,... | {"inputs": ["3 3\n1 2 3 1", "3 3\n1 3 2 1", "4 4\n1 2 4 3 1", "6 7\n3 2 4 1 6 5 1 3", "8 12\n4 6 5 1 4 3 1 8 3 7 8 5 4", "5 6\n3 4 1 2 5 1 3", "7 9\n3 2 7 3 5 1 2 6 1 3", "6 7\n1 5 6 1 4 3 2 1", "4 3\n1 2 3 1", "10 40\n10 3 8 4 10 2 8 1 2 6 3 5 7 6 10 8 9 7 8 5 4 9 1 3 7 2 5 10 9 2 4 3 9 6 5 1 4 6 1 7 10", "30 100\n8 2... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
ba6e2b6a7239ac8f2e8a5c94037059f3 | Special Task | Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get th... | [
"def main():\r\n hint = input()\r\n\r\n hint_nodigits = [h for h in hint if not h.isdigit()]\r\n letters = [h for h in hint_nodigits if h != '?']\r\n \r\n combs_letters = 1\r\n for i in range(10, 10 - len(set(letters)), -1):\r\n combs_letters *= i\r\n\r\n combs_jolly = 10 ** (len(hint_no... | {"inputs": ["AJ", "1?AA", "?", "7", "A", "BBB?", "BC??", "CC", "CB?", "B??C?", "BB?C?", "?BCB?", "?C", "??C?C", "???2", "9???", "GJH2?", "7I9G4", "JG50?", "CDEFG"], "outputs": ["81", "100", "9", "1", "9", "90", "8100", "9", "810", "81000", "8100", "8100", "90", "9000", "900", "1000", "6480", "90", "810", "27216"]} | UNKNOWN | PYTHON3 | CODEFORCES | 53 | |
baddb954f5f204cdf827de7b355fa03f | Dima and Lisa | Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.
More formally, you are given an odd numer *n*. Find a set of numbers *p**i* (1<=≤<=*i*<=≤<=*k*), such that
1. 1<=... | [
"import sys\r\nimport random\r\n\r\ninput = sys.stdin.readline\r\nrd = random.randint(10 ** 9, 2 * 10 ** 9)\r\n\r\nn = int(input())\r\n\r\n\r\ndef isPrime(x: int) -> bool:\r\n if x < 3:\r\n return x == 2\r\n if x % 2 != 1:\r\n return False\r\n A = [2, 325, 9375, 28178, 450775, 9780504, 179526... | {"inputs": ["27", "3", "25", "9", "91", "57", "31", "555", "700000001", "5", "7", "11", "13", "15", "17", "19", "21", "23", "29", "79", "99", "27", "55", "79", "585", "245", "793", "133", "681", "981399", "867773", "654141", "202985", "784533", "370359", "396831", "492211", "838347", "1098945", "1313565", "1349631", "1... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
bafeb7c12c0d4cc7009ce0f7dfa473fc | Bear and Colors | Bear Limak has *n* colored balls, arranged in one long row. Balls are numbered 1 through *n*, from left to right. There are *n* possible colors, also numbered 1 through *n*. The *i*-th ball has color *t**i*.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurr... | [
"import sys \r\ninput = sys.stdin.buffer.readline \r\n\r\ndef process(A):\r\n n = len(A)\r\n answer = [0 for i in range(n)]\r\n for i in range(n):\r\n count = [0 for j in range(n+1)]\r\n my_max = [0, None]\r\n for j in range(i, -1, -1):\r\n aj = A[j]\r\n count[aj]... | {"inputs": ["4\n1 2 1 2", "3\n1 1 1", "10\n9 1 5 2 9 2 9 2 1 1", "50\n17 13 19 19 19 34 32 24 24 13 34 17 19 19 7 32 19 13 13 30 19 34 34 28 41 24 24 47 22 34 21 21 30 7 22 21 32 19 34 19 34 22 7 28 6 13 19 30 13 30", "150\n28 124 138 71 71 18 78 136 138 93 145 93 18 15 71 47 47 64 18 72 138 72 18 150 7 71 109 149 18 1... | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
bb1e3bb6c310b0882dcd8872d6ac76d1 | Games | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | [
"n = int(input())\r\nho = []\r\ngst = []\r\nfor i in range(n):\r\n team = input().split()\r\n ho.append(team[0])\r\n gst.append(team[1])\r\ncount = 0\r\nfor c in ho:\r\n count += gst.count(c)\r\nprint(count)",
"n = int(input())\r\n\r\nhome = []\r\naway = []\r\n\r\nfor i in range(n):\r\n h, a = map(... | {"inputs": ["3\n1 2\n2 4\n3 4", "4\n100 42\n42 100\n5 42\n100 5", "2\n1 2\n1 2", "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28", "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 6... | UNKNOWN | PYTHON3 | CODEFORCES | 925 | |
bb4f21e3fb5d468b2df9010b6f3af889 | Last Chance | Having read half of the book called "Storm and Calm" on the IT lesson, Innocentius was absolutely determined to finish the book on the maths lessons. All was fine until the math teacher Ms. Watkins saw Innocentius reading fiction books instead of solving equations of the fifth degree. As during the last maths class Inn... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef segment_tree(n, a):\r\n i = 2\r\n while True:\r\n if i >= n * 2:\r\n tree = [inf] * i\r\n break\r\n else:\r\n i *= 2\r\n l = len(tree) // 2\r\n for i in range(l, ... | {"inputs": ["Abo", "OEIS", "auBAAbeelii", "AaaBRAaaCAaaDAaaBRAaa", "EA", "BBBAABAABAABBBB", "b", "AABAABAABAA", "aaaaaaa", "AAAAAAABBB", "aabaaaaaaaaaaaaaaab", "aaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaabaaaaab", "aaaaabaaaaabaaaaabaaaaabaaaaa... | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
bb53026b93847d7813469885cb9da1cf | Helga Hufflepuff's Cup | Harry, Ron and Hermione have figured out that Helga Hufflepuff's cup is a horcrux. Through her encounter with Bellatrix Lestrange, Hermione came to know that the cup is present in Bellatrix's family vault in Gringott's Wizarding Bank.
The Wizarding bank is in the form of a tree with total *n* vaults where each vault ... | [
"\r\nfrom types import GeneratorType\r\ndef bootstrap(f, stack=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n if stack:\r\n return f(*args, **kwargs)\r\n else:\r\n to = f(*args, **kwargs)\r\n while True:\r\n if type(to) is GeneratorType:\r\n ... | {"inputs": ["4 2\n1 2\n2 3\n1 4\n1 2", "3 3\n1 2\n1 3\n2 1", "3 1\n1 2\n1 3\n1 1", "3 1000000000\n2 3\n3 1\n585430050 9", "4 50000\n2 1\n4 2\n2 3\n42169 9", "15 100000\n9 7\n15 13\n1 13\n14 5\n6 10\n5 12\n4 14\n4 6\n8 3\n8 2\n9 3\n10 15\n11 8\n10 3\n16283 7"], "outputs": ["1", "13", "0", "91592837", "542369366", "77019... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
bb6533d1cf6db1f3d3ef4bc882371c7c | none | An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).
The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the... | [
"n,m = map(int, input().split())\r\nc=pow(3,n,m)-1;\r\nprint(c%m)",
"n, m = map(int, input().split())\r\n\r\ndef fast_power(base, exp):\r\n res = 1\r\n while exp > 0:\r\n if exp % 2 == 1:\r\n res = (res * base) % m\r\n base = (base * base) % m\r\n exp //= 2\r\n return res\... | {"inputs": ["1 10", "3 8", "8 12", "4 84", "9 95", "331358794 820674098", "5 56", "10 22", "8 73", "7 63", "1 57", "6 5", "6 25", "1 39", "3 60", "2 81", "5 35", "8 100", "6 29", "7 90", "1 37", "7 34", "3 49", "1 38", "7 88", "9 30", "333734901 647005907", "140068687 419634856", "725891944 969448805", "792362041 42349... | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
bb658a7df66938411259566bbf53ad8e | Links and Pearls | A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you l... | [
"s = [x for x in input().lower()]\r\nb = s.count('o')\r\nv = s.count('-')\r\nif b == 0 or v % b == 0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"st = input()\r\np = st.count('o')\r\nl = st.count('-')\r\nif not p:\r\n print('YES')\r\nelif not l%p:\r\n print('YES')\r\nelse:\r\n print('NO')"... | {"inputs": ["-o-o--", "-o---", "-o---o-", "ooo", "---", "--o-o-----o----o--oo-o-----ooo-oo---o--", "-o--o-oo---o-o-o--o-o----oo------oo-----o----o-o-o--oo-o--o---o--o----------o---o-o-oo---o--o-oo-o--", "-ooo--", "---o--", "oo-ooo", "------o-o--o-----o--", "--o---o----------o----o----------o--o-o-----o-oo---oo--oo---o-... | UNKNOWN | PYTHON3 | CODEFORCES | 216 | |
bb6f8901c7e3ad27813fe9d022d7ed4d | Water The Garden | It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *... | [
"import math\r\nt = int(input())\r\nfor i in range(t):\r\n n, k = input().split(\" \")\r\n n = int(n)\r\n k = int(k)\r\n arr = input().split(\" \")\r\n if n == k:\r\n print(1, '\\n')\r\n continue\r\n for j in range(len(arr)):\r\n arr[j] = int(arr[j])\r\n maxi = 0\r\n for... | {"inputs": ["3\n5 1\n3\n3 3\n1 2 3\n4 1\n1", "26\n1 1\n1\n2 1\n2\n2 1\n1\n2 2\n1 2\n3 1\n3\n3 1\n2\n3 2\n2 3\n3 1\n1\n3 2\n1 3\n3 2\n1 2\n3 3\n1 2 3\n4 1\n4\n4 1\n3\n4 2\n3 4\n4 1\n2\n4 2\n2 4\n4 2\n2 3\n4 3\n2 3 4\n4 1\n1\n4 2\n1 4\n4 2\n1 3\n4 3\n1 3 4\n4 2\n1 2\n4 3\n1 2 4\n4 3\n1 2 3\n4 4\n1 2 3 4", "31\n5 1\n5\n5 ... | UNKNOWN | PYTHON3 | CODEFORCES | 132 | |
bb71d6ab1355a5ce318f88adc38bf033 | Little Xor | Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that.
... | [
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl.insert(0 , 0)\r\nfor i in range(n):l[i+1]^=l[i]\r\nprint(max(i^j for i in l for j in l))",
"inputs = int(input())\nnumList = [int(x) for x in input().split()]\nmaxValue = 0\n\nfor i in range(inputs):\n xor = 0\n for j in range(i, -1, -1):\n xor ^= numL... | {"inputs": ["5\n1 2 1 1 2", "3\n1 2 7", "4\n4 2 4 8", "5\n1 1 1 1 1", "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "20\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10", "100\n28 20 67 103 72 81 82 83 7 109 122 30 50 118 83 89 108 82 92 17 97 3 62 12 9 100 14 11 99 106 10 8 60 101 88 119 104 62 76 6 5 57 32 94 60 50 58 97 1 ... | UNKNOWN | PYTHON3 | CODEFORCES | 71 | |
bb883e074b47c2bd5d1d4f497d9eb006 | Inversions problem | You are given a permutation of *n* numbers *p*1,<=*p*2,<=...,<=*p**n*. We perform *k* operations of the following type: choose uniformly at random two indices *l* and *r* (*l*<=≤<=*r*) and reverse the order of the elements *p**l*,<=*p**l*<=+<=1,<=...,<=*p**r*. Your task is to find the expected value of the number of in... | [
"def f(p):\r\n ans = 0\r\n for i in range(len(p)):\r\n for j in range(i, len(p)):\r\n if (p[i] > p[j]):\r\n ans += 1\r\n \r\n return ans\r\n\r\n\r\n\r\nn, k = map(int, input().split())\r\n\r\np = list(map(int, input().split()))\r\n\r\nnum = 0\r\ncnt = 0\r\n\r\nif... | {"inputs": ["3 1\n1 2 3", "3 4\n1 3 2", "6 1\n4 2 5 1 3 6", "6 2\n1 4 6 5 2 3", "4 4\n2 3 1 4", "4 1\n3 4 2 1", "4 3\n3 1 2 4", "4 4\n4 2 3 1", "4 1\n1 2 4 3", "5 4\n4 3 2 5 1", "5 2\n3 1 2 5 4", "5 1\n3 5 1 2 4", "6 1\n5 2 3 4 1 6", "5 2\n4 3 2 1 5", "6 1\n5 3 4 6 2 1", "6 4\n1 2 3 4 5 6", "6 4\n6 5 4 3 2 1", "1 1\n1"... | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
bb9dcfed83c01117e82f8dc14ff02c18 | Equalize the Remainders | You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$.
In a single move, you can choose any position $i$ between $1$ and $n$ and increase $a_i$ by $1$.
Let's calculate $c_r$ ($0 \le r \le m-1)$ — the number of elements havin... | [
"\"\"\"\r\n-*- coding: utf-8 -*-\r\n\r\nCreated on Sat Jan 22 18:33:32 2022\r\n\r\n@author: Tausif Khan Arnob\r\n\"\"\"\r\n\r\nn, m = map(int, input().split())\r\na = [*map(int, input().split())]\r\n\r\nli = [[] for i in range(m)]\r\nk, s, j = n // m, sum(a), 0\r\n\r\nfor i, val in enumerate(a):\r\n li[val % m].... | {"inputs": ["6 3\n3 2 0 6 10 12", "4 2\n0 1 2 3", "1 1\n1000000000", "6 3\n3 2 0 6 10 11", "100 25\n6745 2075 7499 7517 1776 5164 2335 2745 4465 1457 7565 2232 2486 9025 8059 9646 8017 7662 9690 3352 2306 366 7422 1073 7169 8966 4506 8225 5614 8628 2908 7452 9625 9332 7097 353 1043 8118 5794 4486 626 971 6731 6618 887 ... | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
bbad5c3797c66cec0db1fc0f3434ac7b | Whose sentence is it? | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of ... | [
"n = int(input())\r\na = []\r\n\r\nfor x in range(n) : a.append(str(input()))\r\nfor x in range(n):\r\n if (a[x][-5:] == 'lala.' and a[x][:5] == 'miao.'): print('OMG>.< I don\\'t know!')\r\n elif (a[x][-5:] == 'lala.'): print('Freda\\'s')\r\n elif (a[x][:5] == 'miao.'): print('Rainbow\\'s')\r\n else: pr... | {"inputs": ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .", "10\nLpAEKiHVJrzSZqBVSSyY\nYECGBlala.\nUZeGpeM.UCwiHmmA\nqt_,.b_.LSwJtJ.\nFAnXZtHlala.\nmiao.iapelala.\nCFPlbUgObrXLejPNu.F\nZSUfvisiHyrIMjMlala.\nmiao. lala.\nd,IWSeumytrVlala.", "10\nmiao.,taUvXPVlala.\nmiao.txEeId.X_lala.\nL... | UNKNOWN | PYTHON3 | CODEFORCES | 81 | |
bbbbaaae57ce7ca35845708495dd1699 | Mishap in Club | Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ... | [
"notes = list(input())\ny = 0\nMAY = 0\nMIY = 0\nfor i in notes:\n if i == '+':\n y += 1\n MAY = max(MAY, y)\n else: \n y -= 1\n MIY = min(MIY, y)\nprint(MAY-MIY)\n\n",
"s = input()\r\nt = mx = 0\r\nfor i in s:\r\n if i == '-' and t > 0:\r\n t -= 1\r\n elif i == '+':... | {"inputs": ["+-+-+", "---", "-", "--", "---", "----", "---+", "--+-", "--++", "-+--", "-++", "-++-", "+", "+-", "+--", "+--+", "++--", "-+++--+-++--+-+--+-+", "++-++--+++++-+++++---+++-++-++-", "----+-+--++---++---++-+-----+--", "-+++---+++++++++++++-++-++++++-++-+-+++-", "++++++++++++++++++++++++++++++++++++++++++++++... | UNKNOWN | PYTHON3 | CODEFORCES | 40 | |
bbd37e23be19f61cce43427551e0e712 | The Same Calendar | The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is the next year after *y* when the calendar will be exactly the same. Help ... | [
"import datetime\r\n\r\ny=int(input())\r\n\r\ny_temp=y%400\r\nif y_temp==0:\r\n\tprint(y+28)\r\nelse:\r\n\ty_2_28=datetime.datetime(y_temp,2,28).weekday()\r\n\ty_3_1=datetime.datetime(y_temp,3,1).weekday()\r\n\tcount=1\r\n\twhile datetime.datetime(y_temp+count,2,28).weekday()!=y_2_28 or datetime.datetime(y_temp+cou... | {"inputs": ["2016", "2000", "50501", "1000", "1900", "1899", "99999", "50000", "99900", "12345", "1004", "2100", "1313", "1872", "2098", "2072", "2002", "1179", "2096", "1096", "1796", "2014", "2006", "1874", "1884", "2342", "2010", "2097", "1072", "1191", "2896", "1797", "1002", "99988", "1788", "1994", "5094", "99996... | UNKNOWN | PYTHON3 | CODEFORCES | 43 | |
bbda5083b762ef3b2b0b127c37da519c | Jumping Jack | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri... | [
"x=abs(int(input()))\r\nn=0\r\nf=False\r\nfor i in range(1,x+1):\r\n if (i*(i+1))/2==x:\r\n print(i)\r\n f=True\r\n break\r\n if (i*(i+1))/2>x:\r\n n=i\r\n break\r\nif x==0:\r\n print(0)\r\n f=True\r\nif not f:\r\n s= int((n*(n+1))/2)\r\n if (s-x)%2==0:\r\n ... | {"inputs": ["2", "6", "0", "-1000000000", "999961560", "999961561", "999961559", "-488979819", "-865918189", "-278253406", "-87275307", "103702792", "294680891", "485658989", "676637088", "867615187", "-941406715", "-897912263", "-706934164", "-790244010", "16417015", "823078041", "-517744582", "288916443", "-904422532... | UNKNOWN | PYTHON3 | CODEFORCES | 61 | |
bbfbef8cfdb66fcb1844230b423e42e2 | XOR and OR | The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.
A Bitlandish string is a string made only of characters "0" and "1".
BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish ... | [
"def is_possible(a, b):\r\n if len(a) != len(b) :\r\n return \"NO\"\r\n \r\n\r\n if a == b :\r\n return \"YES\"\r\n\r\n \r\n setbits_in_a = False \r\n setbits_in_b = False\r\n\r\n for ch in a :\r\n if ch == \"1\":\r\n setbits_in_a = True \r\n break \r\... | {"inputs": ["11\n10", "1\n01", "000\n101", "1101\n1111", "11000001\n00000001", "01\n10", "0000\n1110", "010101\n101010", "0\n1", "1\n1", "0\n0", "1\n0", "100\n11111", "1000000000000000000000000000000000000011111111000000000000\n0111111111100000000000111111111000000000000000111111110001", "000000000000000000000000000000... | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
bc00254d261298878bf4229043d2b405 | Hamburgers | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (... | [
"s=input()\r\ndic={\"B\":0,\"S\":0,\"C\":0}\r\nnb,ns,nc=[int(i) for i in input().split()]\r\npb,ps,pc=[int(i) for i in input().split()]\r\namount=int(input())\r\nlow=0\r\nhigh=10**17\r\nfor i in s:\r\n dic[i]+=1\r\nwhile low <= high:\r\n mid=(high+low)//2\r\n burger=mid*dic[\"B\"] - nb\r\n sausage=mid*d... | {"inputs": ["BBBSSC\n6 4 1\n1 2 3\n4", "BBC\n1 10 1\n1 10 1\n21", "BSC\n1 1 1\n1 1 3\n1000000000000", "B\n1 1 1\n1 1 1\n381", "BSC\n3 5 6\n7 3 9\n100", "BSC\n100 1 1\n100 1 1\n100", "SBBCCSBB\n1 50 100\n31 59 21\n100000", "BBBBCCCCCCCCCCCCCCCCCCCCSSSSBBBBBBBBSS\n100 100 100\n1 1 1\n3628800", "BBBBBBBBBBCCCCCCCCCCCCCCCC... | UNKNOWN | PYTHON3 | CODEFORCES | 187 | |
bc032e5d3c2c75050a8a48f992de8d6e | Fibonacci Sums | Fibonacci numbers have the following form:
Let's consider some non-empty set *S*<==<={*s*1,<=*s*2,<=...,<=*s**k*}, consisting of different Fibonacci numbers. Let's find the sum of values of this set's elements:
Let's call the set *S* a number *n*'s decomposition into Fibonacci sum.
It's easy to see that several num... | [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nt = int(input())\r\nans = []\r\nf = [1, 2]\r\ninf = pow(10, 18) + 1\r\nwhile f[-1] + f[-2] < inf:\r\n f.append(f[-1] + f[-2])\r\nl = len(f)\r\nfor _ in range(t):\r\n n = int(input())\r\n x = []\r\n for i in range(... | {"inputs": ["2\n13\n16", "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "10\n24\n37\n42\n58\n60\n73\n79\n84\n92\n99", "5\n484775665757\n968685776575\n687675666422\n348587665784\n373875686864", "1\n123456789101112", "22\n304056783818718320\n491974210728665289\n187917426909946968\n796030994547383610\n912170329762608884\n9839524503... | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
bc4528d68579e1604b5cfcbe0e276380 | Candies | After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
This means the process of eating candies is the following: in the beginning Vasya cho... | [
"def check(n, k):\r\n S = n\r\n Vasya = 0\r\n Petya = 0\r\n while S > 0:\r\n Vasya+=min(S, k)\r\n S-=min(S, k)\r\n Petya+=(S//10)\r\n S-=(S//10)\r\n return Vasya >= Petya\r\n \r\ndef process(n):\r\n if check(n, 1):\r\n print(1)\r\n return\r\n s = 1\r... | {"inputs": ["68", "1", "2", "42", "43", "756", "999999972", "999999973", "1000000000000000000", "6", "3", "4", "5", "66", "67", "1000", "10000", "100500", "1000000", "10000000", "100000000", "123456789", "543212345", "505050505", "777777777", "888888871", "1000000000", "999999999999999973", "999999999999999998", "99999... | UNKNOWN | PYTHON3 | CODEFORCES | 56 | |
bc613d8c5d133aa3218104a12bd2c957 | Ant colony | Mole is hungry again. He found one ant colony, consisting of *n* ants, ordered in a row. Each ant *i* (1<=≤<=*i*<=≤<=*n*) has a strength *s**i*.
In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) and each... | [
"import time\r\nimport bisect\r\nimport functools\r\nimport math\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\nimport threading\r\nfrom collections import Counter, defaultdict, deque\r\nfrom copy import deepcopy\r\nfrom functools import cmp_to_key, lru_cache, reduce\r\nfrom heapq import heapify, heapp... | {"inputs": ["5\n1 3 2 4 2\n4\n1 5\n2 5\n3 5\n4 5"], "outputs": ["4\n4\n1\n1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
bc64e74229636684b4bed21608cbda11 | Billiard | Consider a [billiard table](https://en.wikipedia.org/wiki/Billiard_table) of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture).
There is one ball at the point $(x, y)$ currently. Max comes to the table and strikes the ball. ... | [
"def mod(x, m):\r\n if (x % m < 0): return x+m\r\n return x % m\r\n\r\ndef mul(x, y, m):\r\n return (x*y)%m\r\n\r\ndef add(x, y, m):\r\n return (x+y)%m\r\n\r\ndef gcdext(a, b):\r\n if b == 0: return (a, 1, 0)\r\n g, y, x = gcdext(b, a%b)\r\n return (g, x, y-x*(a//b))\r\n\r\ndef CRT(r1, m1, r2, ... | {"inputs": ["4 3 2 2 -1 1", "4 4 2 0 1 1", "10 10 10 1 -1 0", "1000000000 1000000000 1 1000000000 0 1", "2 1 1 0 -1 -1", "4 2 1 2 1 1", "5 3 4 3 1 -1", "15 9 1 1 1 1", "15 9 1 1 -1 -1", "15 9 2 1 1 1", "15 9 2 1 -1 1", "1000000000 999999999 999999998 999999999 -1 -1", "1000000000 999999999 999999998 999999999 -1 1", "1... | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
bc675e3dd359f3855d27c61fbbe05bb0 | Bear and Strings | The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string... | [
"s = input()\r\nind = [i for (i, _) in enumerate(s) if s.startswith('bear', i)]\r\nL = len(s)\r\nr, z = 0, 0\r\nfor e in ind:\r\n for _ in range(z, e + 1):\r\n z = e + 1\r\n r += L - (e + 3)\r\nprint(r)",
"import sys\r\nimport math\r\n\r\n\r\ndef main():\r\n read = sys.stdin.readline\r\n wo... | {"inputs": ["bearbtear", "bearaabearc", "pbearbearhbearzqbearjkterasjhy", "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "bear", "a", "be"], "outputs": ["6", "20", "291", "4419", "1", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 145 | |
bc6d7c53a34b7bb783f08170fd4f3ffb | Subsequences | For the given sequence with *n* different elements find the number of increasing subsequences with *k*<=+<=1 elements. It is guaranteed that the answer is not greater than 8·1018.
First line contain two integer values *n* and *k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=≤<=10) — the length of sequence and the number of elements... | [
"\"\"\"\nNTC here\n\"\"\"\n\noptimize = 1\n\n#!/usr/bin/env pypy\nif optimize:\n import os\n from io import BytesIO\n input = BytesIO(os.read(0, os.fstat(0).st_size)).readline\n\n\ndef iin(): return int(input())\ndef lin(): return list(map(int, input().split()))\n\n\n\nn, k = lin()\na = [iin() for _ in ran... | {"inputs": ["5 2\n1\n2\n3\n5\n4", "1 0\n1", "2 1\n1\n2", "2 1\n2\n1", "3 2\n1\n2\n3", "3 1\n1\n3\n2", "3 1\n2\n1\n3", "3 1\n2\n3\n1", "3 1\n3\n1\n2", "3 2\n3\n2\n1", "10 2\n6\n10\n9\n7\n1\n2\n8\n5\n4\n3", "100 7\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n... | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
bc958cdf56381e768a6fa20968b74312 | Congruence Equation | Given an integer $x$. Your task is to find out how many positive integers $n$ ($1 \leq n \leq x$) satisfy $$n \cdot a^n \equiv b \quad (\textrm{mod}\;p),$$ where $a, b, p$ are all known constants.
The only line contains four integers $a,b,p,x$ ($2 \leq p \leq 10^6+3$, $1 \leq a,b < p$, $1 \leq x \leq 10^{12}$). It i... | [
"def fpow(a, n, mod):\r\n if n == 0:\r\n return 1\r\n if n % 2 == 0:\r\n return (fpow(a, n // 2, mod) ** 2) % mod\r\n return (fpow(a, n - 1, mod) * a) % mod\r\n\r\ndef main():\r\n a, b, p, x = map(int, input().split())\r\n # n = i * (p - 1) + j\r\n ans = 0\r\n for j in range(0, p ... | {"inputs": ["2 3 5 8", "4 6 7 13", "233 233 10007 1", "338792 190248 339821 152634074578", "629260 663548 739463 321804928248", "656229 20757 818339 523535590429", "1000002 1000002 1000003 1000000000000", "345 2746 1000003 5000000", "802942 824238 836833 605503824329", "1 1 2 880336470888", "2 2 3 291982585081", "69960... | UNKNOWN | PYTHON3 | CODEFORCES | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.