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
e6b7e7392f48b167d94f2e889a34a656
An express train to reveries
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of intege...
[ "from sys import stdin, stdout\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\n\r\nl = [0] * n\r\no = list(range(1, n+1))\r\nfor i in range(n):\r\n if a[i] == b[i]:\r\n l[i] = a[i]\r\n o.pop(o.index(a[i]))\r\n\r\nu = 0\r\npl = list(l)\r\nfor i in range...
{"inputs": ["5\n1 2 3 4 3\n1 2 5 4 5", "5\n4 4 2 3 1\n5 4 5 3 1", "4\n1 1 3 4\n1 4 3 4", "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10", "10\n1 2 3 4 5 6 7 8 7 10\n1 2 3 4 5 6 7 8 9 9", "10\n1 2 3 4 5 6 7 8 4 10\n1 2 3 4 5 6 7 6 9 10", "10\n8 6 1 7 9 3 5 2 10 9\n8 6 1 7 4 3 5 2 10 4", "10\n2 9 7 7 8 5 4 10 6 1\n2 8 7...
UNKNOWN
PYTHON3
CODEFORCES
55
e6ba62d7628af9509485a672f3cc2f6d
Permutation
A permutation *p* is an ordered group of numbers *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*, consisting of *n* distinct positive integers, each is no more than *n*. We'll define number *n* as the length of permutation *p*1,<=<=<=*p*2,<=<=<=...,<=<=<=*p**n*. Simon has a positive integer *n* and a non-negative integer *k*, ...
[ "n, k = map(int, input().split())\r\np = [str(i) for i in range(1, 2 *n + 1)]\r\nfor i in range(k):\r\n p[2 * i], p[2 * i + 1] = p[2 * i + 1], p[2 * i]\r\nprint(\" \".join(p))", "n, k = map(int, input().split())\n\nif n == 0:\n print(0)\nelse:\n arr = [0] * 2 * n\n for i in range(2 * n):\n arr[i]...
{"inputs": ["1 0", "2 1", "4 0", "50000 0", "50000 25000", "50000 24999", "49999 24999", "49999 3", "1333 156", "7563 3781", "7563 3780", "2 0", "3 0", "4 1", "4 2", "6 3", "48888 24444", "50000 1", "50000 1000", "34 17", "43244 1233", "213 100", "50 1", "55 0", "5000 0", "3 1", "7563 0", "7563 1", "7563 2", "6 0"], "o...
UNKNOWN
PYTHON3
CODEFORCES
90
e6f40a496ed1368ff423474239e446b9
Flea travel
A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that ...
[ "ka=int(input())\r\nif(ka&(ka-1)>0):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "n = int(input())\r\n\r\nprint('NO' if n & n-1 else 'YES')", "from math import log2\r\nn=int(input())\r\nprint(\"YES\" if log2(n)%1==0 else \"NO\")", "i = int(input())\r\nmods = [0] * i\r\nk = 0\r\nfor j in range(i):\r\...
{"inputs": ["1", "3", "2", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "64", "289", "170...
UNKNOWN
PYTHON3
CODEFORCES
57
e6f96ba887f3f4cbc4d1ee4739ea50c5
The Elder Trolls IV: Oblivon
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so ...
[ "xyzk = [int(i) for i in input().split()]\r\nk=xyzk[3]\r\nx, y, z = sorted([xyzk[0],xyzk[1],xyzk[2]])\r\nx = min(k // 3 + 1, x)\r\ny = min((k - x + 1) // 2 + 1, y)\r\nz = min(k - x - y + 3, z)\r\nprint(x * y * z)", "x,y,z,k=map(int,input().split())\r\na,b,c=1,1,1\r\nwhile k//3 and (a<x or b<y or c<z):p=k//((a<x)+...
{"inputs": ["2 2 2 3", "2 2 2 1", "1 1 1 1", "1 2 3 3", "20 4 5 12", "100 500 100500 1000000000", "2 5 5 9", "11 1 11 11", "100500 5000 500 100000000", "2 2 2 0", "1000000 1000000 1000000 2444441", "1000000 1000000 1000000 1000000000", "1000000 1000000 1000000 2999996", "1000000 1000000 1000000 2999997", "999999 100000...
UNKNOWN
PYTHON3
CODEFORCES
9
e6f9f6acedf37f05d69ecf8aba64bce8
Maximum Number
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. ...
[ "a = int(input())\r\nif ( a % 2 ):\r\n print('7', end='')\r\n a -= 3\r\nwhile (a > 0) :\r\n a -= 2\r\n print('1', end='')", "a=int(input())\r\nif a%2==0:print(\"1\"*(a//2))\r\nelse:\r\n print(\"7\"+\"1\"*((a-3)//2))", "n = int(input())\r\nif n % 2 == 0:\r\n for i in range(0, int(n/2)):\r\n ...
{"inputs": ["2", "3", "4", "5", "6", "85651", "85666", "99999", "100000", "99998", "9", "99997", "99996", "99995", "156", "255", "4568", "5431", "6782", "8343", "9514"], "outputs": ["1", "7", "11", "71", "111", "711111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
UNKNOWN
PYTHON3
CODEFORCES
92
e70fa67ea06a7630a6efb9cae15a0301
Aramic script
In Aramic language words can only represent objects. Words in Aramic have special properties: - A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$...
[ "import sys\r\nfrom math import factorial\r\ninput = sys.stdin.readline\r\n #X,Y,Z = list(map(int,input().strip().split()))\r\nn = input()\r\narr = list(map(str,input().strip().split()))\r\nroots = []\r\nfor i in arr:\r\n word = []\r\n for j in i :\r\n if j not in word:\r\n word.append(j)...
{"inputs": ["5\na aa aaa ab abb", "3\namer arem mrea", "10\nbda bbb cda dca dda dcb bcd dcb ada ddd", "2\nfhjlqs aceginpr", "2\nbcdfghimn efghijlmo"], "outputs": ["2", "1", "6", "2", "2"]}
UNKNOWN
PYTHON3
CODEFORCES
310
e73692d6bb84386ad415f4124200e21c
The Holmes Children
The Holmes children are fighting over who amongst them is the cleverest. Mycroft asked Sherlock and Eurus to find value of *f*(*n*), where *f*(1)<==<=1 and for *n*<=≥<=2, *f*(*n*) is the number of distinct ordered positive integer pairs (*x*,<=*y*) that satisfy *x*<=+<=*y*<==<=*n* and *gcd*(*x*,<=*y*)<==<=1. The integ...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef prime_factorize(n):\r\n ans = []\r\n for i in range(2, int(n ** (1 / 2)) + 1):\r\n while True:\r\n if n % i:\r\n break\r\n ans.append(i)\r\n n //= i\r\n ...
{"inputs": ["7 1", "10 2", "640 15", "641 17", "641 2000", "961 2", "524288 1000000000000", "557056 12", "999961 19", "891581 1", "500009 1", "549755813888 2", "893277279607 1", "500000000023 2", "999999999937 1", "549755813888 38", "549755813888 100000", "847288609443 47", "847288609443 200", "999999999937 10000000000...
UNKNOWN
PYTHON3
CODEFORCES
6
e758d03fb0bcaacacfd82acd36a1127c
Little Elephant and Array
The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*. Additionally the Little Elephant has *m* queries to the array, each query is characterised by a pair of integers *l**j* and *r**j* (1<=≤<=*l**j...
[ "from sys import stdin\nfrom collections import defaultdict\n\ndef lmap(function, iterable): return list(map(function, iterable))\ndef line(): return stdin.readline().strip()\ndef rd(converter): return converter(line())\ndef rl(converter, delimeter = None): return lmap(converter, line().split(delimeter))\ndef rls(n...
{"inputs": ["7 2\n3 1 2 2 3 3 7\n1 7\n3 4", "6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6", "1 2\n1\n1 1\n1 1", "1 1\n1000000000\n1 1"], "outputs": ["3\n1", "1\n0\n2\n1\n1\n3", "1\n1", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
13
e78bff238edea0cf1c9a09c8dda2be96
WTF?
The input contains between 1 and 10 lines, *i*-th line contains an integer number *x**i* (0<=≤<=*x**i*<=≤<=9). Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=4. Sample Input 3 0 1 1 Sample Output 0.666667
[ "TUX=int(input())\r\nFOO=0\r\nBAR=0\r\nBAZ=0\r\nQUZ=1\r\nfor i in range(TUX):\r\n PUR=int(input())\r\n FOO=FOO+PUR\r\n BAR=BAR+1\r\n if FOO*QUZ>BAZ*BAR:\r\n BAZ=FOO\r\n QUZ=BAR\r\nprint(BAZ/QUZ)", "a=[0,0]\r\nmx=0\r\nfor i in range(int(input())):\r\n s=int(input())\r\n a[s]+=1\r\n mx=max(mx,a[1...
{"inputs": ["3\n0\n1\n1", "1\n0", "1\n1", "2\n0\n1", "9\n0\n0\n0\n0\n0\n0\n0\n0\n1", "5\n1\n1\n1\n0\n1", "9\n1\n0\n0\n1\n0\n1\n1\n1\n1", "9\n1\n1\n1\n0\n0\n1\n1\n1\n0", "9\n1\n0\n0\n0\n0\n1\n1\n1\n1", "6\n0\n0\n1\n1\n1\n0", "6\n0\n1\n1\n0\n1\n0", "1\n0", "7\n1\n0\n1\n0\n0\n0\n0", "8\n1\n1\n0\n1\n1\n0\n0\n1", "5\n0\n1\n...
UNKNOWN
PYTHON3
CODEFORCES
17
e790774778ff918d8e1a9920c7285ad1
Cellular Network
You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than ...
[ "R = lambda: map(int, input().split())\r\nn, mm = R()\r\ncts, tws = list(R()), list(R())\r\nl, r = 0, 2 * 10 ** 9 + 7\r\nwhile l < r:\r\n m = (l + r) // 2\r\n j = 0\r\n for i in range(mm):\r\n while j < n and tws[i] - m <= cts[j] <= tws[i] + m:\r\n j += 1\r\n if j != n:\r\n l = ...
{"inputs": ["3 2\n-2 2 4\n-3 0", "5 3\n1 5 10 14 17\n4 11 15", "1 1\n-1000000000\n1000000000", "1 1\n1000000000\n-1000000000", "10 10\n1 1 2 2 2 4 4 6 7 9\n0 1 3 3 3 6 7 8 9 10", "10 10\n2 52 280 401 416 499 721 791 841 943\n246 348 447 486 507 566 568 633 953 986", "7 7\n1 2 3 3 4 5 6\n1 1 2 3 4 5 6", "1 3\n-3\n-1 -1 ...
UNKNOWN
PYTHON3
CODEFORCES
64
e7a24282e64e9a559734d9c57f71f873
DZY Loves Planting
DZY loves planting, and he enjoys solving tree problems. DZY has a weighted tree (connected undirected graph without cycles) containing *n* nodes (they are numbered from 1 to *n*). He defines the function *g*(*x*,<=*y*) (1<=≤<=*x*,<=*y*<=≤<=*n*) as the longest edge in the shortest path between nodes *x* and *y*. Speci...
[ "n = int(input())\nedges = [[int(x) for x in input().split()] for i in range(n-1)]\nedges = sorted(edges)\nuse_count = [0]+[int(input()) for i in range(n)]\nlo,hi = 0,10000\ndef getpar(par,u):\n if par[par[u]] == par[u]:\n return par[u]\n par[u] = getpar(par,par[u])\n return par[u]\ndef unite(par,sz...
{"inputs": ["4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1", "4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4", "10\n2 1 8760\n3 1 3705\n4 1 1862\n5 2 7332\n6 3 7015\n7 5 4866\n8 3 4465\n9 7 8886\n10 3 9362\n2\n5\n5\n4\n4\n5\n4\n5\n1\n2", "10\n2 1 5297\n3 2 7674\n4 1 1935\n5 2 1941\n6 3 1470\n7 1 3823\n8 2 4959\n9 4 6866\n10 9 2054\n1\n1\n1\n...
UNKNOWN
PYTHON3
CODEFORCES
1
e7cb4a185fea978cd8a86b3eb35306f6
Chat room
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
[ "str = list(input())\r\n\r\nn = len(str)\r\n\r\nhello = \"hello\"\r\ncounter = 0\r\n\r\nfor i in range(0,n):\r\n if(counter < 5 and str[i] == hello[counter]):\r\n counter += 1\r\n\r\nif(counter >= 5):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=list(input())\r\nn='NO'\r\nfor i in range(len(...
{"inputs": ["ahhellllloou", "hlelo", "helhcludoo", "hehwelloho", "pnnepelqomhhheollvlo", "tymbzjyqhymedasloqbq", "yehluhlkwo", "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqa...
UNKNOWN
PYTHON3
CODEFORCES
2,810
e7de8ed09278a82f75b3789e7969a25b
Programming Language
Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithms, without reference to some parameters (e.g., data types, buffer sizes, de...
[ "import re\n\n#判别函数类型是否匹配\ndef is_type_match(var_type, arg_type):\n return var_type == \"T\" or var_type == arg_type #当var_type为时T,函数返回True;当var_type不是T时,只有当var_type和arg_type等时,函数才会返回True\n\n#模板过程的变量类型\nn = int(input())\nprocedures = []\nfor i in range(n):\n line = input()\n m = re.match(r'\\s*void\\...
{"inputs": ["4\nvoid f(int,T)\nvoid f(T, T)\n void foo123 ( int, double, string,string ) \n void p(T,double)\n3\nint a\n string s\ndouble x123 \n5\nf(a, a)\n f(s,a )\nfoo (a,s,s)\n f ( s ,x123)\nproc(a)", "6\nvoid f(string,double,int)\nvoid f(int)\n void f ( T )\nvoid procedure(int,double)\nvoid...
UNKNOWN
PYTHON3
CODEFORCES
4
e7e468057d071412f9402d331e19530a
none
A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practi...
[ "#! /usr/bin/env python\n# -*- coding: utf-8 -*-\n# vim:fenc=utf-8\n#\n# Copyright © 2016 missingdays <missingdays@missingdays>\n#\n# Distributed under terms of the MIT license.\n\n\"\"\"\n\n\"\"\"\n\nn = int(input())\n\na = [i for i in input().split()]\n\ndef change(l, r):\n global a\n\n if l == r:\n ...
{"inputs": ["4\n0 0 1 1", "5\n0 1 0 1 0", "3\n1 0 0", "4\n1 0 0 1", "7\n1 0 1 1 1 0 1", "14\n0 1 0 0 0 1 1 0 1 0 1 0 1 0", "3\n1 0 1", "3\n0 0 1", "3\n1 1 0", "3\n1 1 1", "4\n1 1 0 1", "4\n1 0 1 1", "10\n0 1 0 1 0 0 1 0 1 0", "4\n0 1 1 0", "168\n0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 ...
UNKNOWN
PYTHON3
CODEFORCES
19
e7e6030c3ae371e9f00ee3345a6d9d83
Flag of Berland
The flag of Berland is such rectangular field *n*<=×<=*m* that satisfies following conditions: - Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. - Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. ...
[ "def rotate_90_degree_anticlckwise(matrix):\r\n new_matrix = []\r\n for i in range(len(matrix[0]), 0, -1):\r\n new_matrix.append(list(map(lambda x: x[i-1], matrix)))\r\n return new_matrix\r\nn,m = map(int,input().split())\r\nmat = []\r\nfor i in range(n):\r\n temp = input()\r\n mat.append([i f...
{"inputs": ["6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG", "4 3\nBRG\nBRG\nBRG\nBRG", "6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB", "4 4\nRRRR\nRRRR\nBBBB\nGGGG", "1 3\nGRB", "3 1\nR\nG\nB", "4 3\nRGB\nGRB\nGRB\nGRB", "4 6\nGGRRBB\nGGRRBB\nGGRRBB\nRRGGBB", "100 3\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB...
UNKNOWN
PYTHON3
CODEFORCES
37
e7efdd6202603b58ce82a64e3af8ac83
Sereja and Mugs
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume th...
[ "k = int(input().split()[1])\r\nif sum(sorted(list(map(int,input().split())))[:-1]) > k:\r\n print('NO')\r\nelse:\r\n print('YES')", "a,b=input().split()\r\na,b=int(a),int(b)\r\nc=input().split()\r\nfor i in range(a-1):\r\n b-=int(min(c))\r\n c.remove(min(c))\r\nif b<0:\r\n print('NO')\r\nelse:\r\n...
{"inputs": ["3 4\n1 1 1", "3 4\n3 1 3", "3 4\n4 4 4", "2 1\n1 10", "3 12\n5 6 6", "4 10\n6 3 8 7", "5 16\n3 3 2 7 9", "6 38\n9 10 3 8 10 6", "7 12\n4 4 5 2 2 4 9", "8 15\n8 10 4 2 10 9 7 6", "9 22\n1 3 5 9 7 6 1 10 1", "10 30\n9 10 4 5 5 7 1 7 7 2", "38 83\n9 9 3 10 2 4 6 10 9 5 1 8 7 4 7 2 6 5 3 1 10 8 4 8 3 7 1 2 7 6...
UNKNOWN
PYTHON3
CODEFORCES
235
e7f8d16eda19fa59e0fcebc5e64319f7
Transferring Pyramid
Vasya and Petya are using an interesting data storing structure: a pyramid. The pyramid consists of *n* rows, the *i*-th row contains *i* cells. Each row is shifted half a cell to the left relative to the previous row. The cells are numbered by integers from 1 to as shown on the picture below. An example of a pyrami...
[ "# LUOGU_RID: 96259783\nn,m=map(int,input().split())\r\nes=[[]for i in range(n)]\r\ndp,inf=[0]*(n+1),10**9\r\nfor i in range(m):\r\n\tr,c=map(int,input().split())\r\n\tes[c-1].append(n-r+1)\r\nfor i in range(n-1,-1,-1):\r\n\tmx=min(n-i,1000)\r\n\tfor j in es[i]:\r\n\t\tfor k in range(min(mx+1,j)):\r\n\t\t\tif j<=mx...
{"inputs": ["4 5\n3 1\n3 3\n4 1\n4 3\n4 4", "7 11\n2 2\n3 1\n4 3\n5 1\n5 2\n5 5\n6 4\n7 2\n7 3\n7 4\n7 5", "2 3\n1 1\n2 1\n2 2", "10 15\n2 1\n3 2\n4 1\n4 2\n4 3\n5 5\n7 6\n7 7\n8 2\n8 6\n9 7\n10 4\n10 7\n10 9\n10 10", "10 18\n4 3\n5 4\n6 1\n6 3\n7 2\n7 6\n8 2\n9 1\n9 4\n9 6\n9 7\n9 8\n9 9\n10 3\n10 4\n10 7\n10 9\n10 10...
UNKNOWN
PYTHON3
CODEFORCES
1
e80bb87ba55d7191e672aba5bedf48eb
Build String
You desperately need to build some string *t*. For that you've got *n* more strings *s*1,<=*s*2,<=...,<=*s**n*. To build string *t*, you are allowed to perform exactly |*t*| (|*t*| is the length of string *t*) operations on these strings. Each operation looks like that: 1. choose any non-empty string from strings *s*...
[ "from heapq import heappush, heappop\r\nclass MinCostFlow:\r\n INF = 10**18\r\n\r\n def __init__(self, N):\r\n self.N = N\r\n self.G = [[] for i in range(N)]\r\n\r\n def add_edge(self, fr, to, cap, cost):\r\n G = self.G\r\n G[fr].append([to, cap, cost, len(G[to])])\r\n G[...
{"inputs": ["bbaze\n3\nbzb 2\naeb 3\nba 10", "abacaba\n4\naba 2\nbcc 1\ncaa 2\nbbb 5", "xyz\n4\naxx 8\nza 1\nefg 4\nt 1", "aaabbtttefg\n6\nabbbca 3\nffatgg 2\nyioa 4\nppaeg 2\naetgffff 4\ntreiiaav 10", "tatarioispoe\n5\ntyfad 3\npopsia 10\ntszza 3\nioioioio 4\nrarartteea 3", "abcdabcd\n4\nabc 10\nab 3\nefg 3\nsahdjqweg...
UNKNOWN
PYTHON3
CODEFORCES
2
e838a89a79807b2a26db58e7b829b520
Maximum Value
You are given a sequence *a* consisting of *n* integers. Find the maximum possible value of (integer remainder of *a**i* divided by *a**j*), where 1<=≤<=*i*,<=*j*<=≤<=*n* and *a**i*<=≥<=*a**j*. The first line contains integer *n* — the length of the sequence (1<=≤<=*n*<=≤<=2·105). The second line contains *n* space-...
[ "import bisect\r\n\r\nMAXN = 10**6\r\nN = int(input())\r\nexist = [False for i in range(MAXN + 10)]\r\narr = list(map(int, input().split()))\r\na = []\r\n\r\nfor x in arr:\r\n if exist[x] == False:\r\n exist[x] = True\r\n a.append(x)\r\n\r\na.sort()\r\nN = len(a)\r\n\r\nans = 0\r\nfor i in range(N ...
{"inputs": ["3\n3 4 5", "3\n1 2 4", "1\n1", "1\n1000000", "2\n1000000 999999", "12\n4 4 10 13 28 30 41 43 58 61 70 88", "7\n2 13 22 32 72 91 96", "5\n5 11 12 109 110"], "outputs": ["2", "0", "0", "0", "1", "30", "27", "10"]}
UNKNOWN
PYTHON3
CODEFORCES
10
e8457e84553f2509c31ae7956890a5fa
Largest Beautiful Number
Yes, that's another problem with definition of "beautiful" numbers. Let's call a positive integer *x* beautiful if its decimal representation without leading zeroes contains even number of digits, and there exists a permutation of this representation which is palindromic. For example, 4242 is a beautiful number, since...
[ "import sys\r\n\r\nt = int(sys.stdin.buffer.readline().decode('utf-8'))\r\nans = ['']*t\r\n\r\nfor _ in range(t):\r\n a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').rstrip()))\r\n n = len(a)\r\n parity = [0]*10\r\n for x in a:\r\n parity[x] ^= 1\r\n psum = sum(parity)\r\n\r\n ...
{"inputs": ["4\n89\n88\n1000\n28923845", "1\n100001", "2\n1001\n100001", "3\n100001\n100000\n100002", "1\n1001", "60\n799032\n1880\n489633\n167604\n641858\n521214\n951107\n121088\n952294\n514428\n890184\n883033\n317778\n456130\n373364\n404297\n757369\n815335\n317046\n148887\n834163\n990592\n721319\n402371\n458279\n5702...
UNKNOWN
PYTHON3
CODEFORCES
2
e8522845c6f3cbabfb4c591b87b19079
Commentator problem
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to cho...
[ "from math import *\r\n\r\nx1, y1, r1 = map(float, input().split())\r\nx2, y2, r2 = map(float, input().split())\r\nx3, y3, r3 = map(float, input().split())\r\nx, y = (x1 + x2 + x3) / 3, (y1 + y2 + y3) / 3\r\n\r\n\r\ndef cost(a, b):\r\n d1, d2, d3 = sqrt((x1 - a) ** 2 + (y1 - b) ** 2), sqrt((x2 - a) ** 2 + (y2 - ...
{"inputs": ["0 0 10\n60 0 10\n30 30 10", "0 0 10\n100 100 10\n200 0 20", "0 0 10\n300 300 11\n500 -500 12", "0 0 10\n300 300 12\n500 -500 14", "0 0 10\n300 300 13\n500 -500 16", "0 0 10\n300 300 15\n500 -500 20", "0 0 10\n300 300 20\n500 -500 40", "0 0 10\n300 300 21\n500 -500 42", "0 0 10\n300 300 22\n500 -500 44", "0...
UNKNOWN
PYTHON3
CODEFORCES
9
e8589326b260d6321cd1a00bcf796662
Candy Bags
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies. Help him give *n* bags of candies to each b...
[ "n=int(input())\r\nn=n**2\r\nfor i in range (0,n//2):\r\n\tprint(i+1,n-i)", "import math\n\nn = int(input())\nbags = int(math.pow(n,2))\n#candies = math.factorial(bags)\n\nn_bags = []\n\nfor j in range (n):\n\tn_bags.append(\"\")\n\tfor i in range(int(n/2)):\n\t\tn_bags[j] += str((i*n)+j+1)\n\t\tn_bags[j] += \" \...
{"inputs": ["2", "4", "6", "8", "10", "100", "62", "66", "18", "68", "86", "96", "12", "88", "28", "80", "48", "54", "58", "64", "44"], "outputs": ["1 4\n2 3", "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9", "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19", "1 64 2 ...
UNKNOWN
PYTHON3
CODEFORCES
465
e8745b9416581d6826e31166fb2b4f28
Cycles
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly *k* cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices *a*, *b* and *c*, such that each pair of them is connected by a graph edge. John has...
[ "import sys\r\nimport math\r\nc=int(input())\r\n\r\nAns=[]\r\nF=[1]\r\nfor i in range(1,101):\r\n F.append(F[-1]*i)\r\nfor i in range(100):\r\n Ans.append([0]*100)\r\n\r\nprint(100)\r\ncycles=1\r\n\r\nAns[0][1]=1\r\nAns[1][0]=1\r\nAns[1][2]=1\r\nAns[2][1]=1\r\nAns[0][2]=1\r\nAns[2][0]=1\r\n\r\nm=3\r\nwhile(cy...
{"inputs": ["1", "10", "2", "3", "4", "5", "6", "7", "8", "9", "12", "29257", "99990", "99000", "99001", "99002", "99003", "99004", "99005", "99006", "99007", "99008", "99009", "99010", "99011", "99012", "99013", "99014", "99015", "99016", "99017", "99018", "99019", "99020", "99021", "99022", "99023", "99024", "99025",...
UNKNOWN
PYTHON3
CODEFORCES
8
e881e66aa9438f91dbec22567634de7d
Two Cakes
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces. Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ...
[ "import sys,math\r\n#sys.stdin=open('input.txt','r')\r\n#sys.stdout=open('output.txt','w')\r\n\r\n\r\ndef solve():\r\n n,a,b=map(int,input().split())\r\n ans=0\r\n for i in range(1,n):\r\n mina=a//i\r\n minb=b//(n-i)\r\n ans1=min(mina,minb)\r\n ans=max(ans,ans1)\r\n print(ans...
{"inputs": ["5 2 3", "4 7 10", "100 100 100", "10 100 3", "2 9 29", "4 6 10", "3 70 58", "5 7 10", "5 30 22", "5 5 6", "2 4 3", "10 10 31", "2 1 1", "10 98 99", "4 10 16", "11 4 8", "5 10 14", "6 7 35", "5 6 7", "4 15 3", "7 48 77", "4 4 10", "4 7 20", "5 2 8", "3 2 3", "14 95 1", "99 82 53", "10 71 27", "5 7 8", "11 7...
UNKNOWN
PYTHON3
CODEFORCES
140
e882f34c679fcad1f0703d8a4ef2db1f
Family Photos
Alice and Bonnie are sisters, but they don't like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking photos. Alice goes first. There are *n* stacks of photos. Each stack c...
[ "# LUOGU_RID: 105175736\nn=int(input())\r\nret,ans=[],0\r\nfor i in range(n):\r\n\ta1,b1,a2,b2=map(int,input().split())\r\n\tif a1+b1>=a2+b2:\r\n\t\tret.extend([a1+b1,a2+b2])\r\n\t\tans+=a1+a2\r\n\telif a1>b2:\r\n\t\tans+=a1-b2\r\n\telif a2<b1:\r\n\t\tans+=a2-b1\r\nfor x in sorted(ret)[::2]:\r\n\tans-=x\r\nprint(an...
{"inputs": ["2\n12 3 4 7\n1 15 9 1", "2\n5 4 8 8\n4 12 14 0", "1\n0 10 0 10", "10\n0 1000000000 0 1000000000\n0 1000000000 0 1000000000\n0 1000000000 0 1000000000\n0 1000000000 0 1000000000\n0 1000000000 0 1000000000\n0 1000000000 0 1000000000\n0 1000000000 0 1000000000\n0 1000000000 0 1000000000\n0 1000000000 0 100000...
UNKNOWN
PYTHON3
CODEFORCES
2
e885d82416ccee788a6b4d182d3995d1
Pairs of Numbers
Let's assume that we have a pair of numbers (*a*,<=*b*). We can get a new pair (*a*<=+<=*b*,<=*b*) or (*a*,<=*a*<=+<=*b*) from the given pair in a single step. Let the initial pair of numbers be (1,1). Your task is to find number *k*, that is, the least number of steps needed to transform (1,1) into the pair where at ...
[ "def solve(N, M):\r\n ans = 0\r\n while M > 1:\r\n ans += N // M\r\n N, M = M, N % M\r\n if M == 0: return 1000000\r\n return N - 1 + ans\r\n\r\nN = int(input())\r\nans = 1000000\r\nfor M in range(1, N + 1):\r\n ans = min([ans, solve(N, M)])\r\nprint(ans)", "TMP = 0\n\n\ndef dfs(a, b,...
{"inputs": ["5", "1", "2", "3", "4", "10", "1009", "2009", "7009", "9009", "19009", "29009", "12434", "342342", "342235", "362235", "762235", "878235", "978235", "1000000", "6", "10000", "999999", "524287", "777777", "123756", "976438", "434563", "345634", "65457", "123456", "999997", "98989", "8", "123455", "990001", ...
UNKNOWN
PYTHON3
CODEFORCES
5
e8908e1d6d457399e3895364aa5e96ce
Games with Rectangle
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted *n*<=×<=*m* rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid...
[ "n, m, k = map(int, input().split())\r\nli = [[0 for _ in range(1001)] for _ in range(1001)]\r\nfor i in range(1001):\r\n li[i][0] = 1\r\n li[i][i] = 1\r\nfor i in range(1, 1001):\r\n for j in range(1, i):\r\n li[i][j] = li[i-1][j-1] + li[i-1][j]\r\nif 2 * k <= n-1 and 2 * k <= m:\r\n print(li[n-...
{"inputs": ["3 3 1", "4 4 1", "6 7 2", "5 5 3", "2 2 1", "999 999 499", "456 876 1000", "3 5 1", "5 7 2", "10 13 3", "1000 1000 499", "1000 1000 500", "3 1000 1", "1000 3 1", "998 1000 499", "1000 1000 250", "999 996 247", "86 564 16", "711 390 95", "963 415 36", "356 628 17", "214 538 33", "840 474 207", "589 898 280"...
UNKNOWN
PYTHON3
CODEFORCES
13
e89960771ce7eba2a45f2ce8487fd6e2
Magic Forest
Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order *n* is such a non-degenerate triangle, that lengths of its sides are integers not exceeding *n*, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order *n* to get out of the forest. Formally...
[ "n=int(input())\r\nk=0\r\nfor a in range(1,n+1):\r\n\tfor b in range(a,n+1):\r\n\t\tc=a^b\r\n\t\tif b<=c and c<=n and a+b>c and b+c>a and a+c>b:\r\n\t\t\tk+=1\r\nprint(k)\r\n", "n = int(input())\r\nans=[[0]*(n+1) for i in range(n+1)]\r\naa=0\r\nfor i in range(1,n+1):\r\n for j in range(i,n+1):\r\n if i^...
{"inputs": ["6", "10", "3", "4", "5", "2500", "952", "88", "1216", "2140", "564", "1488", "116", "1040", "1965", "593", "779", "1703", "331", "1051", "2179", "603", "1731", "2451", "1079", "2207", "2394", "818", "1946", "166", "1294", "2218", "846", "1566", "194", "1322", "1508", "2433", "857", "1781", "1", "2", "2444"...
UNKNOWN
PYTHON3
CODEFORCES
43
e8ae8c9ad5707a2ba6b86f356f3bdda6
Simple Strings
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with th...
[ "s=list(input()+'a')\r\nfor i in range(len(s)-2):\r\n if s[i]==s[i+1]:\r\n s[i+1]=list({'a', 'b', 'c'}-{s[i]}-{s[i+2]})[0]\r\nprint(''.join(s[:-1]))\r\n", "def add(a, b):\r\n for j in range(26):\r\n c = chr(j + ord('a'))\r\n if(c != a and c != b):\r\n return c\r\n \r\n\r\n...
{"inputs": ["aab", "caaab", "zscoder", "u", "h", "dtottttotd", "rxxxrrxrxxxxxrrrrrxxxxrrrrxrxxrxxrxrxrrrxrrxrrxrxxxrxrrxrrxrxrxxxxxrxxxxrrrxrxxrxxrxxxrrrrrxrrxrrxrr", "aazz", "zz", "gg", "qasdasd", "aa", "ab", "zza", "g", "nnop", "xx"], "outputs": ["bab", "cabab", "zscoder", "u", "h", "dtotataotd", "rxaxraxrxaxaxrararx...
UNKNOWN
PYTHON3
CODEFORCES
110
e8cb5c49fb8b3653b3c5c23c8b90dec4
none
Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**...
[ "def mex(arr,n):\r\n mini=float(\"inf\")\r\n for l,r in arr:\r\n mini=min(mini,r-l+1)\r\n print(mini)\r\n for i in range(n):\r\n print(i%mini,end=\" \")\r\n return \"\"\r\n\r\na,b=map(int,input().strip().split())\r\nblanck=[]\r\nfor i in range(b):\r\n x,y=map(int,input().strip().spli...
{"inputs": ["5 3\n1 3\n2 5\n4 5", "4 2\n1 4\n2 4", "1 1\n1 1", "2 1\n2 2", "5 6\n2 4\n2 3\n1 4\n3 4\n2 5\n1 3", "8 3\n2 3\n2 8\n3 6", "10 10\n1 9\n4 8\n4 8\n5 9\n1 9\n3 8\n1 6\n1 9\n1 6\n6 9", "3 6\n1 3\n1 3\n1 1\n1 1\n3 3\n3 3", "3 3\n1 3\n2 2\n1 3", "6 8\n3 5\n3 6\n4 6\n2 5\n2 5\n1 3\n3 6\n3 5", "10 4\n4 10\n4 6\n6 8...
UNKNOWN
PYTHON3
CODEFORCES
99
e8d060c6b763f49d3bfda0c2d5dc9baf
New Year and Domino
They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so. Limak is a little polar bear who loves to play. He has recently got a rectangular grid with *h* rows and *w* columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#')....
[ "read = lambda: map(int, input().split())\r\nh, w = read()\r\na = [input() for i in range(h)]\r\nN = 501\r\nvr = [[0] * N for i in range(N)]\r\nhr = [[0] * N for i in range(N)]\r\nfor i in range(h):\r\n for j in range(w):\r\n vr[j + 1][i + 1] = vr[j][i + 1] + vr[j + 1][i] - vr[j][i]\r\n hr[j + 1][i...
{"inputs": ["5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8", "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n...
UNKNOWN
PYTHON3
CODEFORCES
51
e8e54a74db5b00dcc2b92b7c2602e26c
Crunching Numbers Just for You
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order. The input consists of a single line of spac...
[ "a = [int(x) for x in input().split()]\r\ndel a[0]\r\nk = 7777777 ** 66666\r\nk = 7777777 ** 66666\r\nk = 7777777 ** 66666\r\nk = 7777777 ** 66666\r\nk = 7777777 ** 66666\r\nprint(*sorted(a))", "s = list(map(int, input().split()))\r\ns[0] = 101\r\ns.sort()\r\ns = s[:-1]\r\nc = 0\r\nfor i in range(10**7):\r\n c...
{"inputs": ["3 3 1 2", "10 54 100 27 1 33 27 80 49 27 6"], "outputs": ["1 2 3 ", "1 6 27 27 27 33 49 54 80 100 "]}
UNKNOWN
PYTHON3
CODEFORCES
19
e8ef8fbc062cb5617ef9df7bd68624ef
Field of Wonders
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ...
[ "n = int(input())\r\ns = input()\r\nalready = set()\r\nfor i in s:\r\n if i != '*':\r\n already.add(i)\r\nans = [chr(ord('a') + i) for i in range(26)]\r\nans = set(ans)\r\nfor i in range(int(input())):\r\n cur = input()\r\n can = True\r\n clos = set() #should be closed\r\n for j in range(n):\r...
{"inputs": ["4\na**d\n2\nabcd\nacbd", "5\nlo*er\n2\nlover\nloser", "3\na*a\n2\naaa\naba", "1\n*\n1\na", "1\n*\n1\nz", "1\n*\n2\na\nz", "2\n**\n1\naa", "2\n**\n1\nfx", "2\n**\n2\nfx\nab", "2\n**\n2\nfx\naf", "2\na*\n2\naa\nab", "4\na*b*\n2\nabbc\nadbd", "4\na*b*\n3\nabbc\nadbd\nacbe", "4\na*b*\n3\nabbc\nadbd\nacbd", "3\...
UNKNOWN
PYTHON3
CODEFORCES
31
e8fe414f9d8189bc044503e9ec4a1b2d
Unfair Poll
On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others. Seating in the class looks like a rectangle, where *n* rows with *m* pupils in each. The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order ...
[ "if __name__ == '__main__':\r\n n, m, k, x, y = map(int, input().split())\r\n d = n * m + ((n - 2) * m if n != 1 else 0)\r\n r = k % d\r\n q = k // d\r\n a = q + (1 if r >= 1 else 0)\r\n b = 0\r\n ser = 0\r\n if n > 2:\r\n b = 2 * q + (r > m) + (r > n * m)\r\n if x == 1 or x == n:\...
{"inputs": ["1 3 8 1 1", "4 2 9 4 2", "5 5 25 4 3", "100 100 1000000000000000000 100 100", "3 2 15 2 2", "4 1 8 3 1", "3 2 8 2 1", "4 2 9 4 1", "1 3 7 1 1", "2 2 8 2 1", "3 1 6 2 1", "5 6 30 5 4", "3 8 134010 3 4", "10 10 25 5 1", "100 100 1000000000 16 32", "100 100 1 23 39", "1 1 1000000000 1 1", "1 1 1 1 1", "47 39 ...
UNKNOWN
PYTHON3
CODEFORCES
2
e93b27341586dc75e694066814ae4cfc
A Leapfrog in the Array
Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he has come up with the following extravagant algorithm. Let's consider that i...
[ "import sys\n\ndef query(n, a):\n while not (a & 1):\n a += (n - a//2)\n return a+1 >> 1\n\nn, q = map(int, sys.stdin.readline().split())\narr = [int(sys.stdin.readline()) for _ in range(q)]\nsys.stdout.write(\"\\n\".join(str(query(n, a)) for a in arr))", "import sys\r\ninput=sys.stdin.readline\r\n\r...
{"inputs": ["4 3\n2\n3\n4", "13 4\n10\n5\n4\n8", "2 2\n1\n2", "1 1\n1", "3 3\n3\n2\n1", "12 12\n9\n11\n5\n3\n7\n2\n8\n6\n4\n10\n12\n1"], "outputs": ["3\n2\n4", "13\n3\n8\n9", "1\n2", "1", "2\n3\n1", "5\n6\n3\n2\n4\n7\n12\n8\n10\n9\n11\n1"]}
UNKNOWN
PYTHON3
CODEFORCES
13
e9436315da64d24762ce73416e7de23c
PawnChess
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess». This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed...
[ "grid = []\nfor k in range(8):\n grid.append(input())\n\nbbc = [] #blocked black columns\nbwc = [] #blocked white columns\n\n#first processing : downwards\n\n\nwhite = 8\nfor k in range(8):\n for j in range(8):\n if grid[k][j] == \"B\":\n bbc.append(j)\n if grid[k][j] == \"W\" and not...
{"inputs": [".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.", "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.", "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n........\n...BB.B.\nW.WWWW.W", "BB......\nW....BBW\n........\n.B.B.BBB\n....BB..\nB....BB.\n....
UNKNOWN
PYTHON3
CODEFORCES
61
e946dd7624e584fa77bc531a34654cce
My pretty girl Noora
In Pavlopolis University where Noora studies it was decided to hold beauty contest "Miss Pavlopolis University". Let's describe the process of choosing the most beautiful girl in the university in more detail. The contest is held in several stages. Suppose that exactly *n* girls participate in the competition initiall...
[ "t, l, r = map(int, input().split())\r\nx = [False] * 5000001\r\nk = [0] * 5000001\r\nb = [0] * 5000001\r\nN = 0\r\nres = 0\r\nfor i in range(2, r + 1):\r\n if not x[i]:\r\n b[N] = i\r\n N += 1\r\n b[i] = i\r\n j = 0\r\n while j < N and i * b[j] <= r:\r\n x[i * b[j]] = True\r\n ...
{"inputs": ["2 2 4", "7 2444902 2613424", "7 2055976 2242066", "5 431999 611310", "9 1621304 1742530", "71 3517969 3712339", "95 941230 1053167", "242954372 1561852 4674408", "844079775 8212 4470298", "17205735 14 4402745", "451693431 631385 4779609", "613442910 7402 7402", "491601604 602162 602166", "959694842 4587040...
UNKNOWN
PYTHON3
CODEFORCES
1
e9487853622129fa4af1e16040fc61b9
Vasya and Chess
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell cont...
[ "from sys import stdin\n\n\n# main starts\nn = int(stdin.readline().strip())\nif n% 2 == 0:\n\tprint(\"white\")\n\tprint(1, 2)\nelse:\n\tprint(\"black\")", "a=int(input())\nif a%2==0:\n print('white')\n print('1 2')\nelse:\n print('black')\n\t \t\t \t\t \t\t \t\t\t\t\t\t\t \t\t\t \t\t\t\t \t", "print(...
{"inputs": ["2", "3", "4", "6", "10", "16", "100", "10006", "99966246", "1000000000", "999999999", "999999997", "900001", "775681", "666666", "12345", "111111", "346367", "13", "11", "9", "7", "5", "19", "939698497", "999999996"], "outputs": ["white\n1 2", "black", "white\n1 2", "white\n1 2", "white\n1 2", "white\n1 2"...
UNKNOWN
PYTHON3
CODEFORCES
60
e94e71bac3d4be298a3178a4b1660147
Summer Homework
By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher: You are given a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to perform on it *m* consecutive operations of the following type: 1. For given numbers *x**i* and *v**i* assign valu...
[ "from sys import *\r\nfrom math import *\r\n\r\nmod = 1000000000\r\nf = [0 for i in range(200)]\r\nf[0] = f[1] = 1\r\nfor i in range(2, 200):\r\n f[i] = f[i - 1] + f[i - 2]\r\nn, m = stdin.readline().split()\r\nn = int(n)\r\nm = int(m)\r\na = list(map(int, stdin.readline().split()))\r\nfor i in range(m):\r\n tp, ...
{"inputs": ["5 5\n1 3 1 2 4\n2 1 4\n2 1 5\n2 2 4\n1 3 10\n2 1 5", "1 3\n2\n2 1 1\n1 1 3\n2 1 1", "11 11\n6 1 9 0 2 9 1 6 2 8 0\n2 9 9\n1 9 0\n1 1 8\n2 2 5\n2 7 11\n2 2 8\n1 3 2\n1 10 0\n2 1 8\n2 9 11\n1 9 7", "11 18\n14 13 18 17 14 17 13 3 0 3 21\n2 6 9\n2 1 6\n2 5 7\n2 1 3\n2 1 9\n2 3 9\n2 2 5\n2 7 10\n2 1 5\n2 4 6\n2...
UNKNOWN
PYTHON3
CODEFORCES
6
e954e4594799351cf3326beb7d94c2f9
Professor GukiZ's Robot
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe...
[ "x1, y1 = list(map(int, input().split()))\r\nx2, y2 = list(map(int, input().split()))\r\nprint(max(abs(x1-x2), abs(y1-y2)))", "x1, y1 = map(int, input().split())\r\nx2, y2 = map(int, input().split())\r\nmoo = 0\r\nx, y = x1, y1\r\na = min(abs(x2-x1), abs(y2-y1))\r\nmoo += a\r\nif x2 > x and y2 > y:\r\n x += a\...
{"inputs": ["0 0\n4 5", "3 4\n6 1", "0 0\n4 6", "1 1\n-3 -5", "-1 -1\n-10 100", "1 -1\n100 -100", "-1000000000 -1000000000\n1000000000 1000000000", "-1000000000 -1000000000\n0 999999999", "0 0\n2 1", "10 0\n100 0", "1 5\n6 4", "0 0\n5 4", "10 1\n20 1", "1 1\n-3 4", "-863407280 504312726\n786535210 -661703810", "-588306...
UNKNOWN
PYTHON3
CODEFORCES
373
e95cd29952a0862bf4dd0af544ea2c51
Danil and a Part-time Job
Danil decided to earn some money, so he had found a part-time job. The interview have went well, so now he is a light switcher. Danil works in a rooted tree (undirected connected acyclic graph) with *n* vertices, vertex 1 is the root of the tree. There is a room in each vertex, light can be switched on or off in each ...
[ "import math\r\nimport sys\r\nfrom bisect import *\r\nfrom collections import *\r\nfrom functools import *\r\nfrom heapq import *\r\nfrom itertools import *\r\nfrom random import *\r\nfrom string import *\r\nfrom types import GeneratorType\r\n\r\n# region fastio\r\ninput = lambda: sys.stdin.readline().rstrip()\r\ns...
{"inputs": ["4\n1 1 1\n1 0 0 1\n9\nget 1\nget 2\nget 3\nget 4\npow 1\nget 1\nget 2\nget 3\nget 4", "1\n\n1\n4\npow 1\nget 1\npow 1\nget 1", "10\n1 2 3 4 2 4 1 7 8\n1 1 0 1 1 0 0 0 1 1\n10\npow 1\nget 2\npow 2\npow 8\nget 6\npow 6\npow 10\nget 6\npow 8\npow 3", "10\n1 1 1 4 5 3 5 6 3\n0 0 0 0 0 0 1 0 0 0\n10\nget 2\nget...
UNKNOWN
PYTHON3
CODEFORCES
2
e969b270d758ea26928161fd803c97df
Sweets Game
Karlsson has visited Lillebror again. They found a box of chocolates and a big whipped cream cake at Lillebror's place. Karlsson immediately suggested to divide the sweets fairly between Lillebror and himself. Specifically, to play together a game he has just invented with the chocolates. The winner will get the cake a...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\npow2 = [1]\r\nfor _ in range(19):\r\n pow2.append(2 * pow2[-1])\r\nx = [[] for _ in range(15)]\r\nz, c = 0, 0\r\nfor i in range(5):\r\n s = list(input().rstrip())\r\n for j in s:\r\n if j == 32:\r\n ...
{"inputs": [" . . .\n . . O .\n. . O O .\n . . . .\n . . .", " . . .\n . . . O\n. . . O .\n O . O .\n . O .", " . . .\n . . . .\n. . . . .\n . . O .\n . . .", " . . .\n . . . .\n. . . . .\n O . . .\n . . O", " . . .\n . O . .\n. . . O .\n . O . .\n . . .", " . O O\n . . O .\n. . . . .\n . . . .\n . . .", " ...
UNKNOWN
PYTHON3
CODEFORCES
3
e9a0b293e135c9a2a244df6e57d25ea1
Rectangle Puzzle
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the *Ox* axis, equals *w*, the length of the side...
[ "from math import *\nw,h,alpha = [int(x) for x in input().strip().split()]\nif alpha > 90 : alpha = 180-alpha\nif w < h: w,h = h,w\nc = cos(alpha*pi/180.0)\ns = sin(alpha*pi/180.0)\nt = tan(alpha*pi/360.0)\n \nprint(h*h/s) if t > h/w else print( (w*h-(w*w+h*h)/2*tan(alpha*pi/360.0))/(c) )\n \t \t \t \t \t\t \t\t...
{"inputs": ["1 1 45", "6 4 30", "100 100 0", "100 100 30", "303304 904227 3", "217708 823289 162", "872657 1807 27", "787062 371814 73", "925659 774524 134", "852428 738707 49", "991024 917226 95", "938133 287232 156", "76730 689942 119", "507487 609004 180", "646084 979010 45", "560489 381720 91", "991245 527535 69", ...
UNKNOWN
PYTHON3
CODEFORCES
10
e9b4a333053f8e447d675f051b0bc56d
Rewards
Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize c...
[ "a1, a2, a3 = map(int,input().split())\r\nb1, b2, b3 = map(int,input().split())\r\nn = int(input())\r\na = a1 + a2 + a3\r\nb = b1 + b2 + b3\r\n\r\nif (a%5 == 0):\r\n x = int((a/5))\r\nelse: x = int((a/5 + 1))\r\nif (b%10 == 0):\r\n z = int((b/10))\r\nelse: z = int((b/10 + 1))\r\n\r\nif (x + z) > n :\r\n pr...
{"inputs": ["1 1 1\n1 1 1\n4", "1 1 3\n2 3 4\n2", "1 0 0\n1 0 0\n1", "0 0 0\n0 0 0\n1", "100 100 100\n100 100 100\n100", "100 100 100\n100 100 100\n1", "1 10 100\n100 10 1\n20", "1 1 1\n0 0 0\n1", "0 0 0\n1 1 1\n1", "5 5 5\n0 0 0\n2", "0 0 0\n10 10 10\n2", "21 61 39\n63 58 69\n44", "18 95 4\n7 1 75\n46", "64 27 81\n72 ...
UNKNOWN
PYTHON3
CODEFORCES
233
e9ba4678ec42e794fd34f5aedb24d337
Pretty Song
When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title. Let's d...
[ "\r\ndef process(S):\r\n n = len(S)\r\n answer = 0\r\n harmonic_sums = [0]\r\n for i in range(1, n+2):\r\n x = harmonic_sums[-1]\r\n harmonic_sums.append(x+1/i)\r\n for i in range(n):\r\n if S[i] in 'AEIOUY':\r\n if i <= n-1-i:\r\n answer1 = (i+1)\r\n ...
{"inputs": ["IEAIAIO", "BYOB", "YISVOWEL", "EZYYOIYUZXEVRTOUYXIQ", "MTOESEPRFEIWAIWLAFJMGBIQB", "ZUBQNDCHHKWNWRVSDSRRRTGZDDPNTVJFKTCNGWND", "POKKJNWMNCSXBJLDWVG", "KZTNJQLPZVHZKZWIB", "A", "Z"], "outputs": ["28.0000000", "5.8333333", "17.0500000", "124.0168163", "127.2203685", "7.5320861", "6.0428477", "5.8202815", "1....
UNKNOWN
PYTHON3
CODEFORCES
4
e9ba47b7421ed5da8d6f98ef3d9211e7
Arpa’s hard exam and Mehrdad’s naive cheat
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, al...
[ "x = int(input())\r\nif not x:\r\n print(1)\r\n exit()\r\nprint('8426'[(x-1) % 4])", "n=int(input())\r\nlist1=[6,8,4,2]\r\nif(n==0):\r\n print(1)\r\nelse:\r\n print(list1[n%4])\r\n", "n = int(input())\r\nprint(pow(8,n,10))", "poss = [8, 4, 2, 6]\r\nn = int(input())\r\nif not n:\r\n print(1)\r\...
{"inputs": ["1", "2", "1000", "3", "4", "1000000000", "5", "6", "999999999", "1378", "13781378", "51202278", "999999998", "999999997", "12193721", "0", "989898989", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "999999996", "999999995", "999999994"], "outputs": ["8", "4", "6", "2", "6", "6", "8", "4", "2", "...
UNKNOWN
PYTHON3
CODEFORCES
249
e9e80f61195367d9ed2defd646c130bd
Mister B and Angle in Polygon
On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides). That's why Mister B decided to use this polygon. Now Mister B must...
[ "n, alp = map(int, input().split())\r\na = 180 / n\r\n\r\nif alp >= (n-2)*180/n:\r\n print(\"1 2 3\")\r\nelse:\r\n k1 = int(alp / a)\r\n if (k1 + 1) * a - alp < alp - k1 * a:\r\n k1 += 1\r\n if k1 == 0:\r\n print(\"2 1 3\")\r\n else:\r\n print(1, 2, n + 1 - k1)\r\n", "n,a=[int(...
{"inputs": ["3 15", "4 67", "4 68", "3 1", "3 180", "100000 1", "100000 180", "100000 42", "100000 123", "5 1", "5 36", "5 54", "5 55", "5 70", "5 89", "5 90", "5 91", "5 111", "5 126", "5 127", "5 141", "5 162", "5 180", "6 46", "6 33", "13 4", "23 11", "11 119", "13 117", "18 174", "8509 139", "29770 76", "59115 40",...
UNKNOWN
PYTHON3
CODEFORCES
82
ea1466c65e068662ccb93b9f2bf20b65
none
As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (*x*,<=*y*,<=*z*). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formu...
[ "'''\n Python3(PyPy3) Template for Programming-Contest.\n'''\n\nimport sys\n\n\ndef input():\n return sys.stdin.readline().rstrip()\n\n\nDXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] # LDRU\nmod = 998244353\ninf = 1 << 64\n\n\ndef main():\n S = int(input())\n a, b, c = map(int, input().split())\n #Do mat...
{"inputs": ["3\n1 1 1", "3\n2 0 0", "10\n1 6 3", "9\n8 2 0", "1\n0 9 2", "1\n3 5 1", "7\n8 2 2", "9\n3 7 0", "1000\n0 0 0", "624\n553 828 109", "902\n742 737 340", "239\n995 385 267", "797\n917 702 538", "938\n414 308 795", "422\n215 779 900", "413\n569 138 159", "188\n748 859 686", "48\n395 552 466", "492\n971 305 807...
UNKNOWN
PYTHON3
CODEFORCES
9
ea20b41b37dc6350d0b88e4cf865a2b7
Tic-Tac-Toe
Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. Players are making moves by turns. At first move a player can put his chip in any cell of any small field...
[ "field = [[\"\"]*9 for i in range(9)]\r\nz = 0\r\nfor i in range(3):\r\n temp2 = input()\r\n for z2 in range(len(temp2)):\r\n if temp2[z2] != \" \":\r\n field[i][z] = temp2[z2]\r\n z+= 1\r\n z = 0\r\ninput()\r\nfor i in range(3,6):\r\n temp2 = input()\r\n for z2 in range(...
{"inputs": ["... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4", "xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4", "o.. ... ...\n... ... ...\n... ... ...\n\n... xxx .....
UNKNOWN
PYTHON3
CODEFORCES
110
ea27ab9331ead61abf67215950c36393
Measuring Lengths in Baden
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches. You are given a length equal to *n* centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The ...
[ "x = int(input())\r\nx = (x+1)//3\r\nprint(x//12, x%12)\r\n", "n=(int(input())+1)//3;print(n//12,n%12)", "# LUOGU_RID: 121460821\nn = int(input())\r\n\r\ninch = round(n / 3)\r\nfoot = inch // 12\r\ninch = inch - 12 * foot\r\n\r\nprint(\"{} {}\".format(foot,inch))", "n=int(input())\r\na=((n+1)//3)//12\r\nb=(n+...
{"inputs": ["42", "5", "24", "1", "2", "3", "4", "8", "10", "12", "13", "100", "120", "199", "501", "1000", "1233", "9876", "9999", "10000", "35", "71"], "outputs": ["1 2", "0 2", "0 8", "0 0", "0 1", "0 1", "0 1", "0 3", "0 3", "0 4", "0 4", "2 9", "3 4", "5 6", "13 11", "27 9", "34 3", "274 4", "277 9", "277 9", "1 0...
UNKNOWN
PYTHON3
CODEFORCES
58
ea2800a75bc8751cf70a0c054703d0cf
Two Substrings
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. Print "YES" (without the quotes), if str...
[ "s = input()\r\n\r\nif 'AB' in s and 'BA' in s:\r\n # Find the first occurrence of \"AB\" and the first occurrence of \"BA\" after the \"AB\"\r\n ab_index = s.find('AB')\r\n ba_index = s.find('BA', ab_index + 2)\r\n\r\n # Check if the substrings are non-overlapping\r\n if ba_index != -1 and ba_index ...
{"inputs": ["ABA", "BACFAB", "AXBYBXA", "ABABAB", "BBBBBBBBBB", "ABBA", "ABAXXXAB", "TESTABAXXABTEST", "A", "B", "X", "BA", "AB", "AA", "BB", "BAB", "AAB", "BAA", "ABB", "BBA", "AAA", "BBB", "AXBXBXA", "SKDSKDJABSDBADKFJDK", "ABAXXBBXXAA", "ABAB", "BABA", "AAAB", "AAAA", "AABA", "ABAA", "BAAA", "AABB", "BAAB", "BBAA", ...
UNKNOWN
PYTHON3
CODEFORCES
176
ea328bc26e5db89c9b42b288c49b2abc
none
Ivan had string *s* consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string *s*. Ivan preferred making a new string to finding the old one. Ivan knows some information about the string *s*. Namely, he remembers, that string *t**i* occurs in string *s* at least *k**...
[ "import math as mt \nimport sys,string\ninput=sys.stdin.readline\nprint=sys.stdout.write\nimport random\nfrom collections import deque,defaultdict\nL=lambda : list(map(int,input().split()))\nLs=lambda : list(input().split())\nM=lambda : map(int,input().split())\nI=lambda :int(input())\nt=I()\nd=defaultdict(str)\nml...
{"inputs": ["3\na 4 1 3 5 7\nab 2 1 5\nca 1 4", "1\na 1 3", "3\nab 1 1\naba 1 3\nab 2 3 5", "6\nba 2 16 18\na 1 12\nb 3 4 13 20\nbb 2 6 8\nababbbbbaab 1 3\nabababbbbb 1 1", "17\na 4 2 7 8 9\nbbaa 1 5\nba 2 1 6\naa 2 7 8\nb 6 1 3 4 5 6 10\nbbbaa 1 4\nbbba 1 4\nbab 1 1\nbba 1 5\nbbb 2 3 4\nbb 3 3 4 5\nab 1 2\nabbb 1 2\nb...
UNKNOWN
PYTHON3
CODEFORCES
1
ea4c5c905f3855d3cf2b5c06ce51f938
Cashback
Since you are the best Wraith King, Nizhniy Magazin «Mir» at the centre of Vinnytsia is offering you a discount. You are given an array *a* of length *n* and an integer *c*. The value of some array *b* of length *k* is the sum of its elements except for the smallest. For example, the value of the array [3,<=1,<=6,<...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef slide_min(n, k, a):\r\n ans, s = [], []\r\n j = 0\r\n for i in range(n):\r\n ai = a[i]\r\n while len(s) ^ j and a[s[-1]] >= ai:\r\n s.pop()\r\n s.append(i)\r\n while len(s) ...
{"inputs": ["3 5\n1 2 3", "12 10\n1 1 10 10 10 10 10 10 9 10 10 10", "7 2\n2 3 6 4 5 7 1", "8 4\n1 3 4 5 5 3 4 1", "15 5\n11 15 16 24 24 28 36 40 49 49 53 55 66 73 100", "11 10\n58 97 93 74 59 59 76 59 59 59 30", "1 1\n1", "15 5\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "15 10\n2 3 3 3 3 3 3 3 3 3 3 3 3 3 1", "15 10\n4 5 5 5 5 ...
UNKNOWN
PYTHON3
CODEFORCES
9
ea506486c9daab1ea0288db21c6d80d1
World Cup
Allen wants to enter a fan zone that occupies a round square and has $n$ entrances. There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute. Allen uses the following strategy to enter the fan zone: - Initially he s...
[ "n=int(input())\nl=[int(x) for x in input().split()]\ncur_idx=0\ncur_val=max(0,(l[0]-1)//n+1)\nfor i in range(n):\n val = max(0,(l[i]-i-1)//n+1)\n if(val<cur_val):\n cur_val=val\n cur_idx=i\nprint(cur_idx+1)\n\t\t \t\t \t \t\t\t \t\t \t\t \t \t \t", "import math\n\nn = int(input())\nq ...
{"inputs": ["4\n2 3 2 0", "2\n10 10", "6\n5 2 6 5 7 4", "2\n483544186 940350702", "10\n3 3 3 5 6 9 3 1 7 3", "10\n0 8 45 88 48 68 28 55 17 24", "100\n8 8 9 10 6 8 2 4 2 2 10 6 6 10 10 2 3 5 1 2 10 4 2 0 9 4 9 3 0 6 3 2 3 10 10 6 4 6 4 4 2 5 1 4 1 1 9 8 9 5 3 5 5 4 5 5 6 5 3 3 7 2 0 10 9 7 7 3 5 1 0 9 6 3 1 3 4 4 3 6 3 ...
UNKNOWN
PYTHON3
CODEFORCES
12
ea674a6739d20fa4fe9614273910c29d
Military Problem
In this problem you will have to help Berland army with organizing their command delivery system. There are $n$ officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer $a$ is the direct superior of off...
[ "n,q= map(int, input().split())\r\nparent=[-1]+[int(x) -1 for x in input().split()]\r\nstart=[0]*n\r\nend=[1]*n\r\nsize=[1]*n\r\npath=[0]*n\r\nfor i in range(n-1, 0, -1):\r\n size[parent[i]]+=size[i]\r\nfor v in range(1, n):\r\n start[v]=end[parent[v]]\r\n end[v]=start[v]+1\r\n end[parent[v]]+=size[v]\r...
{"inputs": ["9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9", "2 1\n1\n1 1", "13 12\n1 1 1 1 1 1 1 1 1 1 1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1"], "outputs": ["3\n6\n8\n-1\n9\n4", "1", "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"]}
UNKNOWN
PYTHON3
CODEFORCES
25
ea6a40cbcf6bd18d19f3bef28f952fe8
Vasya and Public Transport
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has *n* buses and *m* trolleys, the buses are numbered by integers from 1 to *n*, the trolleys are numbered by integers from 1 to *m*. Public transport is not free. There are 4 types of tickets: 1. A ticket fo...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nc1, c2, c3, c4 = map(int, input().split())\r\nn, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\n\r\n\r\nz = c2/c1\r\ns1, s2 = 0, 0\r\nfor i in a:\r\n if i > z:\r\n s1 += c2\r\n else:\r\n ...
{"inputs": ["1 3 7 19\n2 3\n2 5\n4 4 4", "4 3 2 1\n1 3\n798\n1 2 3", "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42", "3 103 945 1000\n7 9\n34 35 34 35 34 35 34\n0 0 0 0 0 0 0 0 0", "7 11 597 948\n4 1\n5 1 0 11\n7", "7 32 109 645\n1 3\n0\n0 0 0", "680 871 347 800\n10 100\n872 156 571 136 703 201 832 213 15 333\n465 435 87...
UNKNOWN
PYTHON3
CODEFORCES
64
ea714bf98e97eed297eaa11c6ac550bc
Anton and Lines
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*·*x*<=+<=*b**i*. It was necessary to determine whether there is at least one point of intersection of t...
[ "n = int(input())\r\na = list()\r\nx1, x2 = map(int, input().split())\r\nfor i in range(n):\r\n k, b = map(int, input().split())\r\n y1 = k * x1 + b\r\n y2 = k * x2 + b\r\n a.append((y1, y2))\r\na.sort()\r\nfl = 'NO'\r\ny1m = a[0][0]\r\ny2m = a[0][1]\r\nfor y1, y2 in a:\r\n if y2 < y2m:\r\n fl...
{"inputs": ["4\n1 2\n1 2\n1 0\n0 1\n0 2", "2\n1 3\n1 0\n-1 3", "2\n1 3\n1 0\n0 2", "2\n1 3\n1 0\n0 3", "2\n0 1\n-1000000 1000000\n1000000 -1000000", "2\n-1337 1888\n-1000000 1000000\n1000000 -1000000", "2\n-1337 1888\n-1000000 1000000\n-999999 -1000000", "15\n30 32\n-45 1\n-22 -81\n4 42\n-83 -19\n97 70\n55 -91\n-45 -64...
UNKNOWN
PYTHON3
CODEFORCES
42
ea74d39916f5ed7f6f66014b10648f43
Robot Vacuum Cleaner
Pushok the dog has been chasing Imp for a few hours already. Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner. While moving, the robot generates a string *t* consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string *t* as the number of occurrences of string "sh...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef check(li):\r\n cnt = 0\r\n n = len(li)\r\n\r\n a = [0]*n\r\n for i in range(n - 1, -1, -1):\r\n if li[i] == \"h\":\r\n cnt += 1\r\n a[i] = cnt\r\n \r\n ret = 0\r\n for i in range(n):\r\n if li[i] == \"s\":\r\n ...
{"inputs": ["4\nssh\nhs\ns\nhhhs", "2\nh\ns", "6\nh\ns\nhhh\nh\nssssss\ns", "1\ns", "10\nsshshss\nhssssssssh\nhhhhhh\nhhhs\nhshhh\nhhhhshsh\nhh\nh\nshs\nsshhshhss", "100\nh\nshh\nh\nhs\nshh\nhh\nh\nssh\nhss\nh\nhh\nh\nh\nh\nh\nh\nh\nh\nh\nh\nhh\nh\nh\nh\nh\nhhh\nh\nh\nhhh\nsh\nhh\nhs\nh\nh\nshs\nh\nh\nh\nshh\nhs\nhs\nh...
UNKNOWN
PYTHON3
CODEFORCES
17
ea78c85fa0679b34e19d492a4f4fbbc7
Good Substrings
You've got string *s*, consisting of small English letters. Some of the English letters are good, the rest are bad. A substring *s*[*l*...*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) of string *s*<=<==<=<=*s*1*s*2...*s*|*s*| (where |*s*| is the length of string *s*) is string <=*s**l**s**l*<=+<=1...*s**r*. The substring *s*[*l...
[ "s = input()\r\nalpha = input()\r\nk = int(input())\r\nsubs = sorted(s[i:] for i in range(len(s)))\r\nprev = ''\r\nans = 0\r\nfor j in subs:\r\n uni = False\r\n bad = 0\r\n for i in range(len(j)):\r\n if i >= len(prev) or prev[i] != j[i]:\r\n uni = True\r\n if alpha[ord(j[i])-ord('...
{"inputs": ["ababab\n01000000000000000000000000\n1", "acbacbacaa\n00000000000000000000000000\n2", "a\n00000000000000000000000000\n0", "aaaa\n00000000000000000000000000\n0", "aaaaaa\n00000000000000000000000000\n1", "bbbbbbbbba\n01000000000000000000000000\n0", "bbbbbbbbba\n10000000000000000000000000\n0", "kqdwdulmgvugvbl...
UNKNOWN
PYTHON3
CODEFORCES
7
ea87810aa22004f346f63313d553a2f9
Name
Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner. Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string *s*. To ke...
[ "from sys import stdin, stdout\r\n\r\nwords = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\ns = stdin.readline().strip()\r\nf = stdin.readline().strip()\r\nans = -1\r\nd = {}\r\n\r\nfor v in s:\r\n if v in d:\r\n d[v] ...
{"inputs": ["aad\naac", "abad\nbob", "abc\ndefg", "czaaab\nabcdef", "a\na", "a\nb", "z\na", "aa\naa", "ab\naa", "aa\nab", "abc\naca", "abc\ncaa", "abab\naaba", "zaaa\naaaw", "abacaba\naba", "abacaba\nabababa", "abc\nbbb", "abc\ncac", "abc\naaac", "abc\nabbc", "abc\naabb", "abcabc\naaccba", "aabbaa\ncaaaaaaaaa", "aabbaa...
UNKNOWN
PYTHON3
CODEFORCES
1
ea889f9ca3c5eae8346616216b5a120e
Round House
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th...
[ "n,a,b=map(int,input().split(' '))\r\nz=(((a+b)%n)+n)%n\r\nif(z==0):\r\n print(n)\r\nelse:\r\n print(z)", "n,a,b=map(int,input().split())\r\na1=a+b-1\r\na2=a1%n+1\r\nprint(a2)", "n,a,b=list(map(int,input().split()))\r\nres = (a+b-1)%n\r\nprint(res+1)\r\n \r\n", "n, a, b = map(int, input().split(\" \"))\n...
{"inputs": ["6 2 -5", "5 1 3", "3 2 7", "1 1 0", "1 1 -1", "1 1 1", "100 1 -1", "100 54 100", "100 37 -100", "99 41 0", "97 37 -92", "99 38 59", "35 34 1", "48 1 -1", "87 65 -76", "76 26 29", "100 65 0", "2 1 100", "3 2 -100", "1 1 100", "1 1 -100", "3 1 -100", "4 3 -100", "3 2 -12", "2 2 -100", "3 2 -90", "6 2 -10", "...
UNKNOWN
PYTHON3
CODEFORCES
212
ea97e7c41443f3897db52cd4d1f5d504
Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate...
[ "n, M = map(int, input().split())\r\na = [int(x) for x in input().split()]\r\na.append(0)\r\na.append(M)\r\na.sort()\r\non = 0\r\nfor i in range(1, len(a), 2):\r\n on += a[i] - a[i-1]\r\nh = on \r\ns = 0\r\nfor i in range(2, len(a), 2):\r\n s += a[i-1] - a[i-2] \r\n t = on - s \r\n h = max(h, s + M-a[i-...
{"inputs": ["3 10\n4 6 7", "2 12\n1 10", "2 7\n3 4", "1 2\n1", "5 10\n1 3 5 6 8", "7 1000000000\n1 10001 10011 20011 20021 40021 40031", "7 1000000000\n3 10001 10011 20011 20021 40021 40031", "1 10\n1", "1 10000000\n1", "1 8\n1", "7 17\n1 5 9 10 11 14 16", "4 17\n1 5 9 10", "5 12\n1 2 3 4 5", "2 1000000000\n100 111", "...
UNKNOWN
PYTHON3
CODEFORCES
162
ea980f2d5cb2925d21f321ea9785a112
Triangles
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has *n* level...
[ "# METO Bot 0.9.9\na,b,c,m=1,2,4,10**9+9\nn=int(input())\nfor i in range(1,n//2):\n\tc=c*a%m\n\tb=(b+c)%m\n\ta=(2*a+3)%m\nprint((b*b+1)*2%m)\n\n\t\t\t \t\t\t \t\t \t \t \t\t", "__author__ = 'Darren'\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n a, b, c, mod = 2, 2, 4, 1000000009\r\n whil...
{"inputs": ["2", "4", "6", "8", "10", "966", "9158", "95576", "804974", "635758", "982894", "813678", "524288", "908550", "988794", "939636", "956022", "972408", "988794", "905180", "921566", "975778", "992164", "908550", "924936", "939636", "992164", "906864", "921566", "974094", "38", "94", "48", "54", "8", "14", "68...
UNKNOWN
PYTHON3
CODEFORCES
7
eab4a34e792de7818ab268da734745b6
Enduring Exodus
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his *k* cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of *n* rooms located in a row, some of which are occupie...
[ "n, k = [int(_) for _ in input().split()]\r\na = input()\r\n\r\n\r\ndef next_free(x):\r\n x += 1\r\n while x < n and a[x] == '1':\r\n x += 1\r\n return x\r\n\r\n\r\nl = next_free(-1)\r\nr = -1\r\n\r\n\r\nk += 1\r\nfor _ in range(k):\r\n r = next_free(r)\r\ni = l\r\ndis = max(i-l, r-i)\r\nnext_i =...
{"inputs": ["7 2\n0100100", "5 1\n01010", "3 2\n000", "10 1\n1101111101", "2 1\n00", "3 1\n010", "8 7\n00000000", "7 6\n0000000", "112 12\n0110101000000010101110010111100101011010011110100111111100011101011111000111101101110100111011110001100110110010", "9 8\n000000000", "9 3\n010001000", "5 3\n00000", "8 7\n00000000",...
UNKNOWN
PYTHON3
CODEFORCES
26
eabcd07fee296c3e23fe3896ca4aa001
A and B and Chess
A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its weight: - the queen's weight is 9, - the rook's weight is 5, - the bisho...
[ "#519A\r\nvalW = 0\r\nvalB = 0\r\nfor _ in range(8):\r\n a = input()\r\n for i in range(8) :\r\n if a[i] == 'Q':\r\n valW = valW + 9\r\n elif a[i] == 'R' :\r\n valW = valW + 5\r\n elif a[i] == 'B' :\r\n valW = valW + 3\r\n elif a[i] == 'N' :\r\n ...
{"inputs": ["rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR", "....bQ.K\n.B......\n.....P..\n........\n........\n........\n...N.P..\n.....R..", "b....p..\nR.......\n.pP...b.\npp......\nq.PPNpPR\n..K..rNn\nP.....p.\n...Q..B.", "...Nn...\n........\n........\n........\n.R....b.\n........\n....
UNKNOWN
PYTHON3
CODEFORCES
100
eac03c31f374da8998234c71c2496881
Om Nom and Candies
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? One day, when he came to his friend Evan, Om Nom didn't find him at home but h...
[ "def main():\n c, hr, hb, wr, wb = map(int, input().split())\n ans = 0\n for i in range(10**6 + 1):\n if i * wr <= c:\n ans = max(ans, i * hr + ((c - i * wr) // wb) * hb)\n if i * wb <= c:\n ans = max(ans, i * hb + ((c - i * wb) // wr) * hr)\n print(ans)\n\n\n\n\n\nma...
{"inputs": ["10 3 5 2 3", "5 3 1 6 7", "982068341 55 57 106 109", "930064129 32726326 25428197 83013449 64501049", "927155987 21197 15994 54746 41309", "902303498 609628987 152407246 8 2", "942733698 9180 9072 1020 1008", "951102310 39876134 24967176 70096104 43888451", "910943911 107 105 60 59", "910943911 38162 31949...
UNKNOWN
PYTHON3
CODEFORCES
6
eb08ac6547136d7a61bc73f76e633bec
Choosing Teams
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. Th...
[ "fristNum,secondNum=map(int,input().split())\r\nlistNum=list(map(int,input().split()))\r\ncounts=0\r\nfor i in range(fristNum):\r\n if(listNum[i]+secondNum <= 5):\r\n counts+=1\r\nprint(counts//3)\r\n \r\n", "n=input().split()\r\np=input().split()\r\nk=int(n[1])\r\nx=int(n[0])\r\na=0\r\no=0\r\nif...
{"inputs": ["5 2\n0 4 5 1 0", "6 4\n0 1 2 3 4 5", "6 5\n0 0 0 0 0 0", "3 4\n0 1 0", "3 4\n0 2 0", "6 5\n0 0 0 0 0 0", "12 2\n0 1 2 3 4 0 1 2 3 4 0 1", "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4", "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1", "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0", "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4...
UNKNOWN
PYTHON3
CODEFORCES
1,007
eb0f579bdb955817ecac937719066510
Facetook Priority Wall
Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described). This priority factor will be affected by three types of actions: - 1. "*X* posted on *Y*'s wall...
[ "# \"X posted on Y's wall\" (15 points),\r\n# 2. \"X commented on Y's post\" (10 points),\r\n# 3. \"X likes Y's post\" (5 points).\r\ndef face(name,arr):\r\n points={\"posted\":15,\"commented\":10,\"likes\":5}\r\n dct=dict()\r\n for i in arr:\r\n c=3\r\n if i[1]==\"likes\":\r\n c=...
{"inputs": ["ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post", "aba\n1\nlikes likes posted's post", "nu\n5\ng commented on pwyndmh's post\nqv posted on g's wall\ng likes nu's post\ng posted on nu's wall\nqv commented on pwyndmh's post", "szfwtzfp\n5\nzqx posted on szfwtz...
UNKNOWN
PYTHON3
CODEFORCES
26
eb3b920526be9ea37a4c0f8c8d250671
Santa Claus and Candies
Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. The only line contains positive integer n...
[ "a=int(input())\r\nc=[]\r\nd=0\r\nfor i in range(1,a+1):\r\n c.append(i)\r\nsum=0\r\nfor j in range(a):\r\n if sum+c[j]>a:\r\n sum+=c[j]\r\n d+=1\r\n break\r\n else:\r\n sum+=c[j]\r\n d+=1\r\nsum=0\r\ne=[]\r\nfor i in range(d-2):\r\n e.append(c[i])\r\n sum+=c[i]\r\n...
{"inputs": ["5", "9", "2", "1", "3", "1000", "4", "6", "7", "8", "10", "11", "12", "13", "14", "15", "16", "20", "21", "22", "27", "28", "29", "35", "36", "37", "44", "45", "46", "230", "231", "232", "239", "629", "630", "631", "945", "946", "947", "989", "990", "991", "956", "981", "867", "906", "999", "100", "126"], ...
UNKNOWN
PYTHON3
CODEFORCES
288
eb61db945f3becf1cef42dc551e366fc
Palindromes in a Tree
You are given a tree (a connected acyclic undirected graph) of *n* vertices. Vertices are numbered from 1 to *n* and each vertex is assigned a character from a to t. A path in the tree is said to be palindromic if at least one permutation of the labels in the path is a palindrome. For each vertex, output the number o...
[ "import sys, os\r\n\r\ndef centroid_decomp(coupl):\r\n n = len(coupl)\r\n \r\n bfs = [n - 1]\r\n for node in bfs:\r\n bfs += coupl[node]\r\n for nei in coupl[node]:\r\n coupl[nei].remove(node)\r\n \r\n size = [0] * n\r\n for node in reversed(bfs):\r\n size[node] ...
{"inputs": ["5\n1 2\n2 3\n3 4\n3 5\nabcbb", "7\n6 2\n4 3\n3 7\n5 2\n7 2\n1 4\nafefdfs", "5\n3 1\n3 5\n5 4\n5 2\nticdm", "10\n10 8\n3 2\n9 7\n1 5\n5 3\n7 6\n8 4\n10 9\n2 6\nqbilfkqcll", "20\n10 9\n15 14\n11 12\n2 3\n15 16\n2 1\n18 19\n20 19\n8 9\n7 6\n8 7\n12 13\n5 6\n4 3\n13 14\n18 17\n11 10\n16 17\n5 4\naabbccddeeffgg...
UNKNOWN
PYTHON3
CODEFORCES
1
eb6b9fc1c91d845a2b77258e5ac780a2
Anastasia and pebbles
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim...
[ "\"\"\"def main():\r\n n, k = map(int, input().split())\r\n lst = [int(i) for i in input().split()]\r\n counter = 0\r\n while sum(lst) > 0:\r\n max_c = max(lst)\r\n if max_c >= 2*k:\r\n lst[lst.index(max_c)] -= 2 * k\r\n elif k<=max_c <= 2*k:\r\n lst[lst.index(...
{"inputs": ["3 2\n2 3 4", "5 4\n3 1 8 9 7", "1 22\n1", "3 57\n78 165 54", "5 72\n74 10 146 189 184", "9 13\n132 87 200 62 168 51 185 192 118", "1 1\n10000", "10 1\n1 1 1 1 1 1 1 1 1 1", "2 2\n2 2"], "outputs": ["3", "5", "1", "3", "6", "48", "5000", "5", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
233
eb6bc5b829705259591a6f49ca015bae
Mahmoud and Ehab and yet another xor task
Ehab has an array *a* of *n* integers. He likes the [bitwise-xor operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) and he likes to bother Mahmoud so he came up with a problem. He gave Mahmoud *q* queries. In each of them, he gave Mahmoud 2 integers *l* and *x*, and asked him to find the number of subseque...
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, q = map(int, input().split())\r\nmod = pow(10, 9) + 7\r\na = list(map(int, input().split()))\r\ny = [[] for _ in range(n)]\r\nfor i in range(q):\r\n l, x = map(int, input().split())\r\n y[l - 1].append((x, i))\r\nm =...
{"inputs": ["5 5\n0 1 2 3 4\n4 3\n2 0\n3 7\n5 7\n5 8", "3 2\n1 1 1\n3 1\n2 0", "20 20\n353123 353123 677328 353123 0 997043 677328 420884 968991 566539 420884 801220 1030642 937882 762558 599450 196420 299659 101896 600581\n14 764540\n10 140147\n20 631492\n15 403662\n14 730429\n11 566539\n2 353123\n9 353123\n18 463456\...
UNKNOWN
PYTHON3
CODEFORCES
2
eb7fe32e1f4b40295a8566b7a4956313
Weakness and Poorness
You are given a sequence of n integers *a*1,<=*a*2,<=...,<=*a**n*. Determine a real number *x* such that the weakness of the sequence *a*1<=-<=*x*,<=*a*2<=-<=*x*,<=...,<=*a**n*<=-<=*x* is as small as possible. The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous su...
[ "def weakness(a, x):\n a = [elem-x for elem in a]\n acumulado = maximo = 0\n for elem in a:\n if acumulado + elem > 0:\n acumulado += elem\n else:\n acumulado = 0\n if acumulado > maximo:\n maximo = acumulado\n acumulado = minimo = 0\n for elem in...
{"inputs": ["3\n1 2 3", "4\n1 2 3 4", "10\n1 10 2 9 3 8 4 7 5 6", "1\n-10000", "3\n10000 -10000 10000", "20\n-16 -23 29 44 -40 -50 -41 34 -38 30 -12 28 -44 -49 15 50 -28 38 -2 0", "10\n-405 -230 252 -393 -390 -259 97 163 81 -129"], "outputs": ["1.000000000000000", "2.000000000000000", "4.500000000000000", "0.0000000000...
UNKNOWN
PYTHON3
CODEFORCES
2
eb9f0d71bc5e7db3dc9654b0e76c8a88
Fixing Typos
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos. In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" ...
[ "def correct_typos(word):\r\n stack = []\r\n for letter in word:\r\n if len(stack) < 2:\r\n stack.append(letter)\r\n else:\r\n #if len(stack)>=3:\r\n #print(letter,stack[-1],stack[-2],stack[-3],letter == stack[-1], stack[-2] == stack[-3],len(stack)>=3)\r\n ...
{"inputs": ["helloo", "woooooow", "aabbaa", "yesssssss", "aabbaabbaabbaabbaabbaabbcccccc", "aaa", "abbbbbccbbbbbbbccccbbbbzbbbbbccbbbbbbbccccbbbbxybbbbbccbbbbbbbccccbbbb", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...
UNKNOWN
PYTHON3
CODEFORCES
18
ebb086d69d50f3fad48f0133208f782b
Sereja and Mirroring
Let's assume that we are given a matrix *b* of size *x*<=×<=*y*, let's determine the operation of mirroring matrix *b*. The mirroring of matrix *b* is a 2*x*<=×<=*y* matrix *c* which has the following properties: - the upper half of matrix *c* (rows with numbers from 1 to *x*) exactly matches *b*; - the lower half o...
[ "from sys import stdin ,stdout\r\nfrom os import path\r\nrd = lambda:stdin.readline().strip()\r\nwr = stdout.write\r\nif(path.exists('input.txt')):\r\n stdin = open(\"input.txt\",\"r\")\r\nimport time ,math\r\n#------------------------------------\r\nx,y = map(int,rd().split())\r\nmylist = [''.join(map(str,rd()....
{"inputs": ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "10 4\n0 0 1 0\n0 0 1 0\n1 1 0 1\n0 0 1 1\n1 0 1 0\n1 0 1 0\n0 0 1 1\n1 1 0 1\n0 0 1 0\n0 0 1 0", "10 3\n0 0 0\n1 1 1\n1 1 0\n0 0 0\n0 1 1\n0 1 1\n0 0 0\n1 1 0\n1 1 1\n0 0 0", "8 4\n1 0 0 0\n1 1 0 0\n1 0 0 1\n1 1 1...
UNKNOWN
PYTHON3
CODEFORCES
49
ebbf2ce66da611800a98db2b6e240fec
Underfail
You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular, daily walks through the unknown, you have encountered two unusually looking skeletons called Sanz and P’pairus, who decided to accompany you and give you some puzzle...
[ "import sys\r\nfrom heapq import heappop, heappush\r\n\r\nclass Edge:\r\n def __init__(self, u, v, cap, flow, cost, rev) -> None:\r\n self.u = u\r\n self.v = v\r\n self.cap = cap\r\n self.flow = flow\r\n self.cost = cost\r\n self.rev = rev\r\n\r\ndef add_edge(adj, u, v, ...
{"inputs": ["6\nabacba\n2\naba 6\nba 3\n3", "6\nabacba\n2\naba 6\nba 3\n1", "6\nabacba\n5\naba 6\nba 3\nbac 4\ncb 3\nc 6\n2", "6\nabacba\n5\naba 6\nba 3\nbac 4\ncb 3\nc 6\n1", "7\nafxfxfg\n3\nf 3\nx 2\nfxf 6\n1", "11\nfghdgrakmnq\n8\nfgh 4\ngh 3\nh 10\nhdg 6\nhdgra 7\nakm 12\nrakm 5\na 15\n3", "8\naxghcdex\n5\naxgh 13\...
UNKNOWN
PYTHON3
CODEFORCES
2
ebc6d8198d92dcc6389b6e6800d27ac5
Vanya and Table
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose *n* rectangles with sides that go along borders of squares (some rectangles probably occur mu...
[ "def solve(x1, y1, x2, y2):\r\n return sum((x2[i] - x1[i] + 1) * (y2[i] - y1[i] + 1) for i in range(len(x1)))\r\n\r\ndef main():\r\n n = int(input())\r\n x1 = []\r\n y1 = []\r\n x2 = []\r\n y2 = []\r\n \r\n for _ in range(n):\r\n x1_i, y1_i, x2_i, y2_i = map(int, input().split())\r\n ...
{"inputs": ["2\n1 1 2 3\n2 2 3 3", "2\n1 1 3 3\n1 1 3 3", "5\n4 11 20 15\n7 5 12 20\n10 8 16 12\n7 5 12 15\n2 2 20 13", "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11", "5\n1 1 1 100\n1 1 1 100\n1 1 1 100\n1 1 1 100\n1 1 1 100", "1\n1 1 1 1", "1\n100 100 100 100", "1\n1 1 1 100", "3\n1 1 1 1\n1 2 1 2\n1 3...
UNKNOWN
PYTHON3
CODEFORCES
116
ebd1932af5753d368e362327f9dccc1f
Game with Powers
Vasya and Petya wrote down all integers from 1 to *n* to play the "powers" game (*n* can be quite large; however, Vasya and Petya are not confused by this fact). Players choose numbers in turn (Vasya chooses first). If some number *x* is chosen at the current turn, it is forbidden to choose *x* or all of its other pos...
[ "import math\r\nval = [\r\n 0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1,\r\n 10, 9, 3, 6, 11, 12\r\n]\r\nn = int(input())\r\ntaken = [False] * 40005\r\nres = 0\r\nrem = n\r\nfor i in range(2, int(math.sqrt(n)) + 1):\r\n if taken[i]:\r\n continue\r\n sz = 1\r\n a = i\...
{"inputs": ["1", "2", "8", "52", "53", "3", "4", "5", "6", "7", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "200", "246", "247", "248", "249", "250", "10153", "10154", "10155", "200702", "200703", "200704", "200705", "200706", "19000880", "19000...
UNKNOWN
PYTHON3
CODEFORCES
2
ebd32beb9066a84f26d40bf05059dc9a
Balls Game
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color *x*. He can insert his ball at...
[ "# @author Matheus Alves dos Santos\n\nn_balls, n_colors, new_ball = map(int, input().split())\nballs = list(map(int, input().split()))\n\nanswer = 0\n\nfor i in range(n_balls):\n copy = balls[:]\n copy.insert(i, new_ball)\n \n while (len(copy) > 2):\n size = len(copy)\n for j in range(2, ...
{"inputs": ["6 2 2\n1 1 2 2 1 1", "1 1 1\n1", "10 2 1\n2 1 2 2 1 2 2 1 1 2", "50 2 1\n1 1 2 2 1 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 1 2 1 1 2 2 1 1 2", "75 5 5\n1 1 5 5 3 5 2 3 3 2 2 1 1 5 4 4 3 4 5 4 3 3 1 2 2 1 2 1 2 5 5 2 1 3 2 2 3 1 2 1 1 5 5 1 1 2 1 1 2 2 5 2 2 1 1 2 1 2 1 1 3 3...
UNKNOWN
PYTHON3
CODEFORCES
68
ebd38a0a5c6f96dbd3510a8558a90998
Boxes And Balls
Ivan has *n* different boxes. The first of them contains some balls of *n* different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*. In order to do this, Ivan will make some tu...
[ "import heapq as h\r\n\r\nn = int(input())\r\nline2 = input().split()\r\na = []\r\nfor i in range(n):\r\n h.heappush(a,int(line2[i]))\r\nif n == 1:\r\n print(0)\r\nelse:\r\n result = 0\r\n if n%2 == 1:\r\n k = n\r\n else:\r\n a.append(0)\r\n k = n + 1\r\n while k > 3:\r\n ...
{"inputs": ["3\n1 2 3", "4\n2 3 4 5", "6\n1 4 4 4 4 4", "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158", "1\n10", "1\n4", "1\n12312", "1\n1", "2\n3 4"], "outputs": ["6", "19", "38", "8176373828", "0", "0", "0", "0", "7"]}
UNKNOWN
PYTHON3
CODEFORCES
26
ebe1dd327ab648efda25387021230af2
Petya and Java
Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger. But h...
[ "n=int(input())\r\nif n>=-128 and n<=127:print('byte')\r\nelif n>=-32768 and n<=32767:print('short')\r\nelif n>=-2147483648 and n<=2147483647:print('int')\r\nelif n>=-9223372036854775808 and n<=9223372036854775807:print('long')\r\nelse: print('BigInteger')\r\n", "n = int(input())\n\nif (n >= -128) and (n <= 127):...
{"inputs": ["127", "130", "123456789101112131415161718192021222324", "6", "16", "126", "128", "32766", "111111", "22222", "32767", "32768", "32769", "2147483645", "2147483646", "2147483647", "2147483648", "2147483649", "9223372036854775805", "9223372036854775806", "9223372036854775807", "9223372036854775808", "92233720...
UNKNOWN
PYTHON3
CODEFORCES
145
ebe254ac02080f08c2de7e14791a211a
Night at the Museum
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character...
[ "s = 'abcdefghijklmnopqrstuvwxyz';\r\n\r\nword = input();\r\n\r\nresult = 0;\r\nptr = 0;\r\n\r\nfor i in range(len(word)):\r\n from_st = s.index(word[i]);\r\n from_end = s[::-1].index(word[i]);\r\n if(from_st > from_end):\r\n ptr = from_end;\r\n start = s[26 - ptr-1::];\r\n end = s[0:...
{"inputs": ["zeus", "map", "ares", "l", "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "gngvi", "aaaaa", "a", "z", "vyadeehhikklnoqrs", "jjiihhhhgggfedcccbazyxx", "fyyptqqxuciqvwdewyppjdzur", "fqcnzmzmbobmancqcoalzmanaobpdse", "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaa...
UNKNOWN
PYTHON3
CODEFORCES
1,067
ec1bcbab246384797e7e84147912b38e
Planting Trees
Vasya is a Greencode wildlife preservation society proponent. One day he found an empty field nobody owned, divided it into *n*<=×<=*m* squares and decided to plant a forest there. Vasya will plant *nm* trees of all different heights from 1 to *nm*. For his forest to look more natural he wants any two trees growing in ...
[ "import math\r\n\r\n\r\ndef solve():\r\n def can_place(x, y):\r\n for dx in range(-1, 2):\r\n for dy in range(-1, 2):\r\n if [dx, dy] == [0, 0] or dx * dy != 0:\r\n continue\r\n if abs(f[x + dx][y + dy] - f[x][y]) == 1:\r\n ret...
{"inputs": ["2 3", "2 1", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "1 98", "1 99", "1 100", "1 1", "2 1", "3 1", "4 1", "5 1", "6 1", "98 1", "99 1", "100 1", "2 2", "2 4", "2 5", "2 6", "2 99", "2 100", "3 2", "3 3", "3 4", "3 5", "3 99", "3 100", "4 2", "4 3", "4 4", "4 5", "4 99", "4 100", "5 2", "5 3", "5 4", "5 5...
UNKNOWN
PYTHON3
CODEFORCES
2
ec1ddab062f5eecb7a4aacb90cb5fa2e
Rat Kwesh and Cheese
Wet Shark asked Rat Kwesh to generate three positive real numbers *x*, *y* and *z*, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point. Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportuni...
[ "from decimal import *\r\nx,y,z=map(Decimal,input().split())\r\nprint(max((y**z*x.ln(),9,'x^y^z'),(z**y*x.ln(),8,'x^z^y'),(y*z*x.ln(),7,'(x^y)^z'),\r\n(x**z*y.ln(),6,'y^x^z'),(z**x*y.ln(),5,'y^z^x'),(z*x*y.ln(),4,'(y^x)^z'),(x**y*z.ln(),3,'z^x^y'),(y**x*z.ln(),2,'z^y^x'),(y*x*z.ln(),1,'(z^x)^y'))[2])", "from deci...
{"inputs": ["1.1 3.4 2.5", "2.0 2.0 2.0", "1.9 1.8 1.7", "2.0 2.1 2.2", "1.5 1.7 2.5", "1.1 1.1 1.1", "4.2 1.1 1.2", "113.9 125.2 88.8", "185.9 9.6 163.4", "198.7 23.7 89.1", "141.1 108.1 14.9", "153.9 122.1 89.5", "25.9 77.0 144.8", "38.7 142.2 89.8", "51.5 156.3 145.1", "193.9 40.7 19.7", "51.8 51.8 7.1", "64.6 117.1...
UNKNOWN
PYTHON3
CODEFORCES
5
ec34ac0f05f569c72bc274cc46a1ae83
Crossword
Vasya trains to compose crossword puzzles. He can only compose crosswords of a very simplе type so far. All of them consist of exactly six words; the words can be read only from top to bottom vertically and from the left to the right horizontally. The words are arranged in the form of a rectangular "eight" or infinity ...
[ "from itertools import permutations\r\nv = []\r\nfor p in permutations(input() for i in range(6)):\r\n if len(p[1]) != len(p[0]) + len(p[2]) - 1 or len(p[4]) != len(p[3]) + len(p[5]) - 1:\r\n continue\r\n elif p[0][0] != p[3][0] or p[0][-1] != p[4][0]:\r\n continue\r\n elif p[1][0] != p[3][-1...
{"inputs": ["NOD\nBAA\nYARD\nAIRWAY\nNEWTON\nBURN", "AAA\nAAA\nAAAAA\nAAA\nAAA\nAAAAA", "PTC\nJYNYFDSGI\nZGPPC\nIXEJNDOP\nJJFS\nSSXXQOFGJUZ", "BAMSVFSFVUWRXSABRGSOINNWAQR\nUWHQCTMHVKWAWVT\nUACWQUGQUXXTBLUDFGCHB\nTXHHXRYEEAMLFWKSRUEBAZSUEYU\nROCCNYN\nUCWYOHJYZQGYN", "ABA\nCABA\nDABA\nCABA\nGIP\nTOII", "XOWGMRPLRJMSMEDRT...
UNKNOWN
PYTHON3
CODEFORCES
2
ec6093d406c61d479fbc0a78b0e39325
Dima and Hares
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her *n* hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to *n* from left to right and started feeding them wi...
[ "\"\"\"\r\nCreated on Fri Jan 18 12:23:03 2019\r\n\r\n@author: nm57315\r\n\"\"\"\r\n\r\nn = int(input())\r\na,b,c = (list(map(int,input().strip().split())) for x in range(3))\r\nd,e = a[0],b[0]\r\nfor x in range(1,n):\r\n d,e = max(e+a[x],d+b[x]),max(e+b[x],d+c[x])\r\nprint(d)", "n = int(input())\r\na, b, c = ...
{"inputs": ["4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "3\n1 1 1\n1 2 1\n1 1 1", "7\n1 3 8 9 3 4 4\n6 0 6 6 1 8 4\n9 6 3 7 8 8 2", "2\n3 5\n9 8\n4 0", "7\n3 6 1 5 4 2 0\n9 7 3 7 2 6 0\n1 6 5 7 5 4 1", "1\n0\n1\n4", "1\n7\n1\n7", "8\n7 3 3 5 9 9 8 1\n8 2 6 6 0 3 8 0\n1 2 5 0 9 4 7 ...
UNKNOWN
PYTHON3
CODEFORCES
13
ec6954a439dbc886dbd02979577beaa8
Average Score
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received *n* marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark. Now i...
[ "n=int(input())\r\na,b=map(int,input().split())\r\nt=list(map(int,input().split()))\r\nif(a==b):\r\n for i in range(a): print(1,end=\" \")\r\n for i in range(b-1): print(2,end=\" \")\r\n print(2)\r\nelse:\r\n vec=[[i,j] for i,j in enumerate(t)]\r\n if(a<b):\r\n vec.sort(key=lambda x:(x[1],-x[0...
{"inputs": ["5\n3 2\n4 4 5 4 4", "4\n2 2\n3 5 4 5", "6\n1 5\n4 4 4 5 4 4", "4\n2 2\n2 1 3 3", "9\n3 6\n4 5 4 1 2 2 2 4 5", "2\n1 1\n4 4", "2\n1 1\n5 1", "3\n2 1\n1 2 2", "3\n1 2\n1 2 2", "3\n1 2\n1 2 3", "3\n2 1\n5 5 5", "4\n2 2\n1 2 2 3", "4\n1 3\n2 1 2 2", "4\n3 1\n2 1 2 2", "4\n3 1\n2 1 3 3", "4\n1 3\n2 3 3 3", "5\n...
UNKNOWN
PYTHON3
CODEFORCES
7
ec696b189ffe655aed8f50671e7ecc61
String Typing
You are given a string *s* consisting of *n* lowercase Latin letters. You have to type this string using your keyboard. Initially, you have an empty string. Until you type the whole string, you may perform the following operation: - add a character to the end of the string. Besides, at most once you may perform one...
[ "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\ns = input()[:-1]\r\nc = 1\r\nfor i in range(1, n//2+1):\r\n if s[:i] == s[i:i+i]:\r\n c = i\r\nprint(n-c+1)", "n = int(input())\r\ns = input().strip()\r\noperations = 0\r\n\r\nm = 0\r\nfor i in range(1, n):\r\n if s[:i] == s[i:2 * i...
{"inputs": ["7\nabcabca", "8\nabcdefgh", "100\nmhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxcmhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxc", "99\ntrolnjmzxxrfxuexcqpjvefndwuxwsukxwmjhhkqmlzuhrplrtrolnjmzxxrfxuexcqpjvefndwuxwsukxwmjhhkqmlzuhrplrm", "100\nyeywsnxcwslfyiqbbeoaawtmioksfdndptxxcwzfmrpcixjbzvicijofj...
UNKNOWN
PYTHON3
CODEFORCES
15
ecce9933a439bb91f36650ff36a8acbc
Keyboard
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean...
[ "a = input()\nb = list(input())\nkey = list(\"qwertyuiopasdfghjkl;zxcvbnm,./\")\nif a ==\"L\":\n d=1\nelse:\n d=-1\nn=[]\nfor i in range(len(b)):\n e = b[i]\n f = key.index(e)\n n.append(key[f+d])\nprint(''.join(n))", "kd = dict()\r\nkd[0] = 'qwertyuiop'\r\nkd[1] = 'asdfghjkl;'\r\nkd[2] = 'zxcvbnm,...
{"inputs": ["R\ns;;upimrrfod;pbr", "R\nwertyuiop;lkjhgfdsxcvbnm,.", "L\nzxcvbnm,kjhgfdsaqwertyuio", "R\nbubbuduppudup", "L\ngggggggggggggggggggggggggggggggggggggggggg", "R\ngggggggggggggggggggggggggggggggggggggggggg", "L\ngggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg...
UNKNOWN
PYTHON3
CODEFORCES
346
ed07dc5d503de30662b00ec8c638509f
Oh Sweet Beaverette
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcom...
[ "from collections import defaultdict as dc,Counter as C\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nmp=dc(lambda:list())\r\nfor i in range(len(arr)):mp[arr[i]].append(i)\r\nst=set(arr)\r\nlst=[arr[0]]\r\nfor i in range(1,len(arr)):lst.append(lst[i-1]+arr[i])\r\n#print(st)\r\n#print(lst)\r\n#print(mp)...
{"inputs": ["5\n1 2 3 1 2", "5\n1 -2 3 1 -2", "2\n0 0", "3\n0 -1 0", "3\n1 1 1", "4\n-1 1 1 -1", "4\n-1 1 -1 1", "2\n-1 -1", "3\n-1 0 -1", "6\n-1 3 3 5 5 -1", "2\n-1000000000 -1000000000", "3\n-1000000000 -1000000000 -1000000000", "3\n1000000000 1000000000 1000000000", "10\n-589330597 -126288833 -126288833 -834860352 -...
UNKNOWN
PYTHON3
CODEFORCES
10
ed36ccf2b276a8c6143251b80d106d88
Strange Addition
Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*. Vasya wants to choo...
[ "n = int(input().strip())\r\nlst = list(map(int, input().strip().split()))\r\nl1 = ['0']*lst.count(0) + ['100']*lst.count(100)\r\nl2 = []\r\nfor i in range(n):\r\n if lst[i] > 0 and lst[i] < 10:\r\n l2.append(str(lst[i]))\r\n break\r\nl3 = []\r\nfor i in range(n):\r\n if lst[i] % 10 == 0 and lst...
{"inputs": ["4\n100 10 1 0", "3\n2 70 3", "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29", "50\n20 67 96 6 75 12 37 46 38 86 83 22 10 8 21 2 93 9 81 49 69 52 63 62 70 92 97 40 47 99 16 85 48 77 39 100 28 5 11 44 89 1 19 42 35 27 7 14 88 33", "2\n...
UNKNOWN
PYTHON3
CODEFORCES
24
ed3db0986ebe3ad377cd14cab75ec8ef
none
There is a rectangular grid of *n* rows of *m* initially-white cells each. Arkady performed a certain number (possibly zero) of operations on it. In the *i*-th operation, a non-empty subset of rows *R**i* and a non-empty subset of columns *C**i* are chosen. For each row *r* in *R**i* and each column *c* in *C**i*, the...
[ "import sys\r\nn,m = [int(x) for x in input().split(' ')]\r\na=[]\r\nfor i in range(n):\r\n b=[]\r\n s = input().strip()\r\n for j in range(m):\r\n if s[j]=='#':\r\n b.append(j)\r\n if b not in a:\r\n a.append(b)\r\nc=[0]*m\r\nans=True\r\n#print(a)\r\nfor i in a:\r\n for j in...
{"inputs": ["5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..", "5 5\n..#..\n..#..\n#####\n..#..\n..#..", "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#", "1 1\n#", "2 1\n.\n#", "2 5\n.####\n#..##", "5 2\n##\n##\n..\n##\n..", "5 2\n#.\n##\n##\n#.\n..", "4 10\n###..#..##\n...##..#..\n.##..#..#.\n.........
UNKNOWN
PYTHON3
CODEFORCES
84
ed6198d759f796ee6d8694da686f11a9
Present
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted *n* flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver no...
[ "import sys\r\nRI = lambda: map(int, sys.stdin.buffer.readline().split())\r\n\r\nn, m, w = RI()\r\nnums = list(RI())\r\nd = [0] * n\r\nd[0] = nums[0]\r\nfor i in range(1, n):\r\n d[i] = nums[i] - nums[i - 1]\r\n\r\n# 校验min(a)为x能不能行\r\ndef check(x):\r\n if min(nums) >= x:\r\n return True\r\n dd = d[:]\r\n # 先...
{"inputs": ["6 2 3\n2 2 2 2 1 1", "2 5 1\n5 8", "1 1 1\n1", "3 2 3\n999999998 999999998 999999998", "10 8 3\n499 498 497 497 497 497 497 497 498 499", "11 18 8\n4996 4993 4988 4982 4982 4982 4982 4982 4986 4989 4994", "1 100000 1\n1000000000", "4 100 3\n1 100000 100000 1"], "outputs": ["2", "9", "2", "1000000000", "500...
UNKNOWN
PYTHON3
CODEFORCES
17
eda1e2852cb7129fa18c2743586c73a1
The same permutation
Seyyed and MoJaK are friends of Sajjad. Sajjad likes a permutation. Seyyed wants to change the permutation in a way that Sajjad won't like it. Seyyed thinks more swaps yield more probability to do that, so he makes MoJaK to perform a swap between every pair of positions (*i*,<=*j*), where *i*<=&lt;<=*j*, exactly once. ...
[ "n=int(input())\r\np=lambda a,b:print(a+1,b+1)\r\nb=[0,1]\r\nif n%4>1:\r\n\tprint(\"NO\")\r\nelse:\r\n\tprint(\"YES\")\r\n\tfor i in range(n%4,n,4):\r\n\t\tfor x in b:\r\n\t\t\ta=2*x\r\n\t\t\tfor j in range(i):p(j,i+a)\r\n\t\t\tp(i+a,i+a+1)\r\n\t\t\tfor j in range(i,0,-1):p(j-1,i+a+1)\r\n\t\t[p(i+y,i+(y^(3-x))) for...
{"inputs": ["3", "1", "5", "6", "7", "8", "1000", "901", "800", "772", "10", "766", "555", "999", "997", "150", "808", "809", "899", "111", "2", "22", "695", "972", "245", "406", "219", "760", "609", "974", "431", "656", "801", "186", "75", "964", "161", "898", "731", "568", "845", "26", "551", "748", "917", "310", "84...
UNKNOWN
PYTHON3
CODEFORCES
3
edc5da9755841b3c40687396c3fbb42d
On a plane
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of points on a plane. Each of the next *n* lines contains two real coordinates *x**i* and *y**i* of the point, specified with exactly 2 fractional digits. All coordinates are between <=-<=1000 and 1000, inclusive. Output a single real num...
[ "# LUOGU_RID: 112712157\nn = int(input())\nSum = 0\nfor _ in range(n):\n [x, y] = [float(i) for i in input().split()]\n Sum += y\nprint(5 + Sum / n)\n", "from sys import stdin,stdout\r\n# from os import _exit\r\n# from bisect import bisect_left,bisect\r\n# from heapq import heapify,heappop,heappush\r\n# fro...
{"inputs": ["8\n-2.14 2.06\n-1.14 2.04\n-2.16 1.46\n-2.14 0.70\n-1.42 0.40\n-0.94 -0.48\n-1.42 -1.28\n-2.16 -1.62", "5\n2.26 1.44\n2.28 0.64\n2.30 -0.30\n1.58 0.66\n3.24 0.66", "8\n6.98 2.06\n6.40 1.12\n5.98 0.24\n5.54 -0.60\n7.16 0.30\n7.82 1.24\n8.34 0.24\n8.74 -0.76", "5\n10.44 2.06\n10.90 0.80\n11.48 -0.48\n12.06 0...
UNKNOWN
PYTHON3
CODEFORCES
7
edd90ec0fb4192d4cf2ab1cba9399a94
Free Cash
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free...
[ "n = int(input())\r\nd = {}\r\nc = 1\r\nfor i in range(n):\r\n m,h = list(map(str, input().split()))\r\n if m+\":\"+h in d.keys():\r\n d[m+\":\"+h] += 1\r\n c = max(c, d[m+\":\"+h]) \r\n else:\r\n d[m+\":\"+h] = 1\r\n\r\nprint(c)", "from collections import defaultdict\r\nn = int(input())\r\na = defaul...
{"inputs": ["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22", "5\n12 8\n15 27\n15 27\n16 2\n19 52", "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6", "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\...
UNKNOWN
PYTHON3
CODEFORCES
330
ede3277e0b4e9adcab46d69aeb3e1e52
Simple Skewness
Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of *n* (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness. The mean of a collection is the average of its elements. The median of a col...
[ "def CalcMean(n,a,c,median,k):\r\n if k==0: return a[median]\r\n s = c[median+1] - c[median-k] + c[n] - c[n-k]\r\n return s/(2*k+1)\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\nc=[0]\r\nfor i in range(n):\r\n c.append(c[-1]+a[i])\r\n\r\nans=optMed=optK=0\r\nfor median in rang...
{"inputs": ["4\n1 2 3 12", "4\n1 1 2 2", "2\n1 2", "1\n1000000", "20\n999999 999998 999996 999992 999984 999968 999936 999872 999744 999488 998976 997952 995904 991808 983616 967232 934464 868928 737856 475712", "21\n999999 999998 999996 999992 999984 999968 999936 999872 999744 999488 998976 997952 995904 991808 98361...
UNKNOWN
PYTHON3
CODEFORCES
4
edfcbfd7e4c41d5aa3ea7d87b45ca8c5
Bash and a Tough Math Puzzle
Bash likes playing with arrays. He has an array *a*1,<=*a*2,<=... *a**n* of *n* integers. He likes to guess the greatest common divisor (gcd) of different segments of the array. Of course, sometimes the guess is not correct. However, Bash will be satisfied if his guess is almost correct. Suppose he guesses that the gc...
[ "#!/usr/bin/env python3\nimport os\nimport sys\nfrom atexit import register\nfrom io import StringIO\nfrom math import gcd\n\nsys.stdin = StringIO(os.read(0, os.fstat(0).st_size).decode())\nsys.stdout = StringIO()\nregister(lambda: os.write(1, sys.stdout.getvalue().encode()))\n\ninput = lambda: sys.stdin.readline()...
{"inputs": ["3\n2 6 3\n4\n1 1 2 2\n1 1 3 3\n2 1 9\n1 1 3 2", "5\n1 2 3 4 5\n6\n1 1 4 2\n2 3 6\n1 1 4 2\n1 1 5 2\n2 5 10\n1 1 5 2", "1\n1000000000\n1\n1 1 1 1000000000", "4\n3 3 7 7\n1\n1 1 4 3"], "outputs": ["YES\nYES\nNO", "NO\nYES\nNO\nYES", "YES", "NO"]}
UNKNOWN
PYTHON3
CODEFORCES
2
ee0338e504b3be3af2f6f6a8319b86cd
Hacker, pack your bags!
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha. So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly *x* days. Y...
[ "\r\nimport sys\r\ninput = sys.stdin.readline\r\nfrom collections import defaultdict\r\n\r\n\r\ndef f():\r\n global ew\r\n for a in d1:\r\n d1[a].sort()\r\n c = q = 10 ** 10\r\n b = x - a\r\n if b < 1 or b not in d2:\r\n continue\r\n d2[b].sort()\r\n j = 0\...
{"inputs": ["4 5\n1 3 4\n1 2 5\n5 6 1\n1 2 4", "3 2\n4 6 3\n2 4 1\n3 5 4", "2 1855\n159106 161198 437057705\n149039 158409 889963913", "15 17\n1 10 8\n5 19 1\n12 14 6\n9 19 8\n6 7 3\n5 11 9\n7 12 5\n17 20 8\n6 12 6\n11 19 4\n3 14 1\n15 19 10\n3 20 5\n5 19 9\n10 18 10", "15 7\n16 18 6\n11 15 2\n5 17 3\n4 5 1\n3 11 5\n13...
UNKNOWN
PYTHON3
CODEFORCES
2
ee0e50b53b2a126e3d7638106a270695
How many trees?
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terribl...
[ "n, h = map(int, input().split())\r\nt = s = [1] * (n + 1)\r\nfor m in range(1, n + 1): s[m] = sum(s[m - 1 - k] * s[k] for k in range(m))\r\nfor j in range(h): t = [sum((s[k] - t[k]) * t[m - 1 - k] + s[m - 1 - k] * t[k] for k in range(m)) for m in range(n + 1)]\r\nprint(t[n])", "n, hh = map(int, input().split())\...
{"inputs": ["3 2", "3 3", "1 1", "2 1", "2 2", "27 11", "32 27", "4 1", "9 1", "33 4", "4 4", "8 5", "12 8", "15 5", "19 18", "23 17", "27 15", "29 14", "33 18", "7 7", "23 21", "7 3", "21 18", "4 1", "21 12", "35 13", "19 2", "33 26", "16 9", "16 14", "10 2", "4 4", "33 17", "27 25", "20 14", "16 11", "10 10", "4 3", ...
UNKNOWN
PYTHON3
CODEFORCES
21