context
stringlengths
88
7.54k
groundtruth
stringlengths
9
28.8k
groundtruth_language
stringclasses
3 values
type
stringclasses
2 values
code_test_cases
listlengths
1
565
dataset
stringclasses
6 values
code_language
stringclasses
1 value
difficulty
float64
0
1
mid
stringlengths
32
32
You know that the Martians use a number system with base k. Digit b (0 ≤ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology). A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of...
k, b, n = map(int, input().split()) digits = list(map(int, input().split())) def ans0(): j = -1 answer = 0 for i in range(n): if digits[i] != 0 or i < j: continue j = i while j < n and digits[j] == 0: j += 1 r = j - i answer += r * (r + 1) ...
python
code_algorithm
[ { "input": "7 6 4\n3 5 0 4\n", "output": "1\n" }, { "input": "10 5 6\n3 2 0 5 6 1\n", "output": "5\n" }, { "input": "257 0 3\n0 0 256\n", "output": "3\n" }, { "input": "2 1 1\n0\n", "output": "0\n" }, { "input": "8 5 205\n5 6 5 0 2 1 1 3 7 2 1 7 7 7 7 6 5 5 0 2 0 ...
code_contests
python
0
8862591376b3c6e9a6bf5968e6794a2f
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered from 1 to n in order. The stones always fall to the center of Liss's inter...
s=input() r=[] l=[] num=1 for i in s: if i=='r': r.append(num) elif i=='l': l.append(num) num+=1 res=r+l[::-1] for i in res: print(i)
python
code_algorithm
[ { "input": "lrlrr\n", "output": "2\n4\n5\n3\n1\n" }, { "input": "llrlr\n", "output": "3\n5\n4\n2\n1\n" }, { "input": "rrlll\n", "output": "1\n2\n5\n4\n3\n" }, { "input": "r\n", "output": "1\n" }, { "input": "llrlrlllrrllrllllrlrrlrlrrllrlrlrrlrrrrrrlllrrlrrrrrlrrr...
code_contests
python
0.2
15e92cfa6395fcd8f7e058dd1c7d499e
Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring...
def fastio(): import sys from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() MOD = 10**9 + 7 I = lambda:list(...
python
code_algorithm
[ { "input": "7 4\n", "output": "ababacd\n" }, { "input": "4 7\n", "output": "-1\n" }, { "input": "6875 2\n", "output": "ababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa...
code_contests
python
0
632a5f9b140e91c72e3e8c3deee4a927
A Martian boy is named s — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets happy...
import sys count = 0 matrix = [] for line in sys.stdin: if count == 0: pattern = line.strip() count += 1 else: s = line.strip() dp1 = [0 for i in range(len(s))] dp2 = [0 for i in range(len(s))] i = 0 j = 0 while i < len(pattern) and j < len(s): if pattern[i] == s[j]: i += ...
python
code_algorithm
[ { "input": "mars\nsunvenusearthmarsjupitersaturnuranusneptune\n", "output": "0\n" }, { "input": "aba\nbaobababbah\n", "output": "2\n" }, { "input": "a\na\n", "output": "0\n" }, { "input": "a\naaaaaaaaaaaaaa\n", "output": "13\n" }, { "input": "lol\nlol\n", "out...
code_contests
python
0.1
85493dc831257ea16c447d79e097e275
The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c...
def searchInRange(arr: list, start: int, end: int) -> int: for i in range(start, end + 1): if i in arr: return i return -1 n, k = [int(item) for item in input().split(' ')] holidays = [int(item) for item in input().split(' ')] del holidays[:1] ans, start, end = 0, 1, k while start <= n: ...
python
code_algorithm
[ { "input": "10 1\n3 6 7 8\n", "output": "10\n" }, { "input": "5 2\n1 3\n", "output": "3\n" }, { "input": "350 16\n12 31 76 103 116 191 201 241 256 260 291 306 336\n", "output": "24\n" }, { "input": "365 40\n30 1 14 21 31 32 36 56 59 68 96 119 131 137 166 179 181 202 235 248 2...
code_contests
python
0
331a2d3a032afa5788d38aeab2db3240
A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the condition holds: "vertices u and v are connected by an edge if and only if vert...
def read_data(): n = int(input()) ps = list(map(int, input().split())) return n, ps def solve(n, ps): ps = [p - 1 for p in ps] cycles = [0] * n roots = [] has_odd_cycle = False for i in range(n): if cycles[i] > 0: continue q = ps[i] cycle = 1 ...
python
code_algorithm
[ { "input": "3\n3 1 2\n", "output": "NO\n" }, { "input": "4\n4 3 2 1\n", "output": "YES\n1 4\n1 2\n4 3\n" }, { "input": "6\n4 1 2 3 6 5\n", "output": "YES\n5 6\n5 1\n6 4\n5 3\n6 2\n" }, { "input": "6\n2 1 4 5 6 3\n", "output": "YES\n1 2\n1 3\n2 4\n1 5\n2 6\n" }, { ...
code_contests
python
0
700b9b0da91d581c4253d826c734f773
"The zombies are lurking outside. Waiting. Moaning. And when they come..." "When they come?" "I hope the Wall is high enough." Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segment...
# 690 D1 r,c = [int(i) for i in input().split()] for i in range(r-1): input() s = input() segs = 0 prev = '.' for x in s: if x=='B' and prev =='.': segs += 1 prev = x print(segs)
python
code_algorithm
[ { "input": "10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\nB.BB.B.\n", "output": "3\n" }, { "input": "3 7\n.......\n.......\n.BB.B..\n", "output": "2\n" }, { "input": "1 1\nB\n", "output": "1\n" }, { "input": "4 6\n..B...\nB.B.BB\nBBB.B...
code_contests
python
0.9
a55e9f8e779701d5ae409ec137d554bb
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. + ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occur...
# Problem : C. Sonya and Queries # Contest : Codeforces Round #371 (Div. 2) # URL : https://codeforces.com/contest/714/problem/C # Memory Limit : 256 MB # Time Limit : 1000 ms # Powered by CP Editor (https://github.com/cpeditor/cpeditor) """ // Author : snape_here - Susanta Mukherjee """ from __future__ impo...
python
code_algorithm
[ { "input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n", "output": "2\n1\n2\n1\n1\n" }, { "input": "4\n+ 200\n+ 200\n- 200\n? 0\n", "output": "1\n" }, { "input": "20\n+ 8\n+ 39532\n+ 813\n- 39532\n? 00011\n? 00000\n? 00011\n+ 70424\n- 8\n? 00011\...
code_contests
python
0.5
9acbef66cd95fba6e678b91a83efb2ea
For given n, l and r find the number of distinct geometrical progression, each of which contains n distinct integers not less than l and not greater than r. In other words, for each progression the following must hold: l ≤ ai ≤ r and ai ≠ aj , where a1, a2, ..., an is the geometrical progression, 1 ≤ i, j ≤ n and i ≠ j...
Primes = [2, 3, 5, 7] def check (a, b) : for pr in Primes : if a % pr == 0 and b % pr == 0 : return False while (b) : a %= b a ^= b b ^= a a ^= b return a == 1 n, l, r = map(int, input().split()) if n == 1 : ans = r - l + 1 elif n == 2 : ans = (r - l + 1) * (r - l) else : n -= 1 l -= 1 ans = 0 f...
python
code_algorithm
[ { "input": "3 1 10\n", "output": "8\n" }, { "input": "3 3 10\n", "output": "2\n" }, { "input": "1 1 10\n", "output": "10\n" }, { "input": "2 6 9\n", "output": "12\n" }, { "input": "3 100 1000000\n", "output": "7474368\n" }, { "input": "19 1 10000000\n"...
code_contests
python
0
1a3e2be30b39b74a4f665cad3a479516
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater tabl...
_,o,d=map(int,input().split()) h=0 a=list(map(int,input().split())) n=0 for i in a: if i==1: if o>0: o-=1 elif d>0: d-=1 h+=1 elif h>0: h-=1 else: n+=1 elif i==2: if d>0: d-=1 else: ...
python
code_algorithm
[ { "input": "4 1 1\n1 1 2 1\n", "output": "2\n" }, { "input": "4 1 2\n1 2 1 1\n", "output": "0\n" }, { "input": "5 2 2\n2 1 2 1 2\n", "output": "2\n" }, { "input": "20 4 3\n2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 1 2\n", "output": "25\n" }, { "input": "3 1 2\n1 1 2\n",...
code_contests
python
0.5
98ba46af04f6675e3e8f606126421d68
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical. Valera absolutel...
from sys import stdin, stdout from math import factorial n = int(stdin.readline()) values = list(map(int, stdin.readline().split())) ans = 0 cnt = 1 for i in range(1, n): if values[i] != values[i - 1]: ans += cnt * (cnt + 1) // 2 cnt = 1 else: cnt += 1 ans += cnt * (cnt + 1) // 2 std...
python
code_algorithm
[ { "input": "4\n2 1 1 4\n", "output": "5" }, { "input": "5\n-2 -2 -2 0 1\n", "output": "8" }, { "input": "50\n2 0 2 0 0 0 0 -1 -2 -2 -2 1 1 2 2 0 2 0 2 -3 0 0 0 0 3 1 -2 0 -1 0 -2 3 -1 2 0 2 0 0 0 0 2 0 1 0 0 3 0 0 -2 0\n", "output": "75" }, { "input": "10\n7 1 0 10 0 -5 -3 -2...
code_contests
python
0.5
a20eda1216c79ff3280f2a05e1d890c7
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute. Vitalya will defin...
n, m, k = map(int,input().split()) a = list(map(int,input().split())) a.sort() vis = [] for i in range(n): vis.append(0) ans = l = r = 0 cnt = 1 while(r < n): while(a[r]-a[l]+1 > m): if(vis[l] == 0): cnt -= 1 l += 1 if cnt >= k: ans += 1 vis[r] = 1; cnt -= 1 r += ...
python
code_algorithm
[ { "input": "2 2 2\n1 3\n", "output": "0\n" }, { "input": "3 3 2\n3 5 1\n", "output": "1\n" }, { "input": "7 7 2\n7 3 4 1 6 5 2\n", "output": "6\n" }, { "input": "5 10 3\n12 8 18 25 1\n", "output": "0\n" }, { "input": "13 10 4\n5 28 67 70 68 3 84 4 30 82 96 37 49\n...
code_contests
python
0
85c856ce0ac16f948200d971aee47e70
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. <image> Initially, each hole has a_i stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in th...
A = [int(x) for x in input().split()] N = 14 result = 0 for i in range(N): B = A[:] to_distribute = B[i] B[i] = 0 for j in range(N): B[j] += to_distribute // N for j in range(1, to_distribute % N + 1): B[(i + j) % N] += 1 result = max(result, sum([x for x in B ...
python
code_algorithm
[ { "input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0\n", "output": "4\n" }, { "input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0\n", "output": "8\n" }, { "input": "787 393 649 463 803 365 81 961 989 531 303 407 579 915\n", "output": "7588\n" }, { "input": "10001 10001 10001 10001 10001 10001 10001 100...
code_contests
python
0
094af441e024ea0a087a8eb56c6528f1
You are given two binary strings a and b of the same length. You can perform the following two operations on the string a: * Swap any two bits at indices i and j respectively (1 ≤ i, j ≤ n), the cost of this operation is |i - j|, that is, the absolute difference between i and j. * Select any arbitrary index i (1 ...
def solve(n, a, b): ans = 0 i = 0 while i < n: if a[i] != b[i]: if i < n-1 and a[i+1] != b[i+1] and a[i+1] != a[i]: ans += 1 i += 2 else: ans += 1 i += 1 else: i += 1 return ans n = int(in...
python
code_algorithm
[ { "input": "4\n0101\n0011\n", "output": "1\n" }, { "input": "3\n100\n001\n", "output": "2\n" }, { "input": "91\n0010010000110001001011011011111001000110001000100111110010010001100110010111100111011111100\n11011101100001001100001000110101101111011000000110111001111110001100000011011011111...
code_contests
python
0.2
de2a724fb74014955a228e07ee360ede
You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positiv...
for _ in range(int(input())): a,b,c = list(map(int, input().split())) ans = None; dist = 1e10 for i in range(1, 2*a +1): for j in range(i, 2*b +1, i): for k in range(j, 2*c + 1, j): if abs(a-i)+abs(b-j)+abs(c-k) < dist: ans = [i, j, k] ...
python
code_algorithm
[ { "input": "8\n1 2 3\n123 321 456\n5 10 15\n15 18 21\n100 100 101\n1 22 29\n3 19 38\n6 30 46\n", "output": "1\n1 1 3\n102\n114 228 456\n4\n4 8 16\n6\n18 18 18\n1\n100 100 100\n7\n1 22 22\n2\n1 19 38\n8\n6 24 48\n" }, { "input": "1\n451 10000 10000\n", "output": "24\n455 10010 10010\n" }, { ...
code_contests
python
0
c4a196c195ffc9408c38da24f97f5b74
T is playing a game with his friend, HL. There are n piles of stones, the i-th pile initially has a_i stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in th...
from collections import defaultdict from math import inf for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) mi=min(arr) ans=0 su=0 res="T" for i in arr: ans+=i-mi su+=i if max(arr)>su-max(arr): print(res) else: if ans%2==1:...
python
code_algorithm
[ { "input": "2\n1\n2\n2\n1 1\n", "output": "T\nHL\n" }, { "input": "2\n2\n1 4\n3\n3 1 3\n", "output": "T\nT\n" }, { "input": "1\n3\n2 1 1\n", "output": "HL\n" }, { "input": "4\n5\n1 3 1 3 4\n1\n4\n1\n5\n2\n3 3\n", "output": "HL\nT\nT\nHL\n" }, { "input": "3\n2\n4 3...
code_contests
python
0
4523a59b3f77393340b08dddf24d3b7d
Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring s1, the second enters an infinite loop i...
from itertools import permutations from sys import stdin from functools import lru_cache input = stdin.readline s1, s2, s3 = input().strip(), input().strip(), input().strip() @lru_cache(None) def findPattern(s): #print(s) slen = len(s) p = [0]*slen ci = 0 for i in range(1, slen): if(s[ci] ==...
python
code_algorithm
[ { "input": "abacaba\nabaaba\nx\n", "output": "11\n" }, { "input": "ab\nbc\ncd\n", "output": "4\n" }, { "input": "syvncqmfhautvxudqdhggz\nhrpxzeghsocjpicuixskfuzupytsgjsdiyb\nybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehls\n", "output": "100\n" }, { "input": "iefouqzxoyuieqdzal...
code_contests
python
0.3
a00c38abf9e13bc42ed0823e69be7cab
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sendi...
n=int(input()) i=0 x=[] while i<n: x.append(str(input())) i+=1 i=25 r=0 while i: j=i while j: j-=1 t=0 k=n while k: k-=1 y=x[k] z=len(y) ok=1 while z: z-=1 if ord(y[z])-ord('a')!=i: if ord(y[z])-ord('a')!=j:ok=0 if ok:t+=len(y) if r<t:r=t i-=1 print(r)
python
code_algorithm
[ { "input": "4\nabb\ncacc\naaa\nbbb\n", "output": "9\n" }, { "input": "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n", "output": "6\n" }, { "input": "4\nurkop\nvisualac\ngnutl\nwtf\n", "output": "0\n" }, { "input": "7\npavel\nerika\nalexxxxxxx\ngracio\nzhenya\nsudarev\nchelyaba\n...
code_contests
python
0
1cd9a7171581ccd2b89056392e6611e3
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Amo...
n=int(input()) lst=[] for i in range(n): n=input() lst.append(n[4:]) for i in lst: l=len(i) i=int(i) #print(i) g=0 p=10 c=1 while(c<l): g+=p p*=10 c+=1 #print(g,p) while(i<1989+g): i+=p print(i)
python
code_algorithm
[ { "input": "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0\n", "output": "2015\n12015\n1991\n1989\n1990\n" }, { "input": "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999\n", "output": "1989\n1999\n2999\n9999\n" }, { "input": "1\nIAO'123456789\n", "output": "123456789\n" }, { "input": "1\nIAO'1...
code_contests
python
0
6d0ce826de36ddc55b4f07a45f340587
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square k × k in size, divided into blocks 1 × 1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie k in size. Fan...
import math print(math.ceil(3**(int(input())-1))%1000003)
python
code_algorithm
[ { "input": "3\n", "output": "9\n" }, { "input": "696\n", "output": "695035\n" }, { "input": "6\n", "output": "243\n" }, { "input": "928\n", "output": "794863\n" }, { "input": "589\n", "output": "889192\n" }, { "input": "657\n", "output": "874011\n"...
code_contests
python
0
74bbc647acde2a884f8b4a42312543b7
Polycarp is a beginner programmer. He is studying how to use a command line. Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the patte...
n,m=map(int,input().split()) a=[] b=[] for i in range(n): a.append(input()) t=list(map(int,input().split())) flag=0 x=len(a[t[0]-1]) for i in t: b.append(a[i-1]) if len(a[i-1])!=x: flag=1 break s='' if flag!=1: for i in range(x): l=b[0][i] abc=0 for j in range(m): if b[j][i]!=l: abc=1 break...
python
code_algorithm
[ { "input": "3 2\nab\nac\ncd\n1 2\n", "output": "Yes\na?\n" }, { "input": "4 4\na\nb\nc\ndd\n1 2 3 4\n", "output": "No\n" }, { "input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3\n", "output": "Yes\n.???\n" }, { "input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5\n", "outpu...
code_contests
python
0.8
c5b4c06c5ae3ded039c7c69c95c46baa
Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them. At first, he need to download t chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. ...
import re import copy t = int(input()) for i in range(t): n = int(input()) senderList = [] for x in input().split(): senderList.append(x) m = int(input()) msg = [None] * m resSenders = [None] * m possibleSenders = [] for i in range(m): possibleSenders.append(copy.copy(senderList)) for i in range(m): ...
python
code_algorithm
[ { "input": "1\n2\nnetman vladik\n3\nnetman:how are you?\n?:wrong message\nvladik:im fine\n", "output": "Impossible\n" }, { "input": "1\n2\nVladik netman\n2\n?: Hello, Vladik!\n?: Hi\n", "output": "netman: Hello, Vladik!\nVladik: Hi\n" }, { "input": "2\n3\nnetman vladik Fedosik\n2\n?: use...
code_contests
python
0.1
7e1c95f739d814e436c1ba6cd30d7c5e
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 find ...
n, a=map(int, input().split()) alp = 180*(n-2)/n minR=181 x=3 angle=0 for i in range (3, n+1): angle = (180*(i-2) - alp*(i-2))/2 if abs(angle-a)<minR: minR=abs(angle-a) x=i print("2 1", x)
python
code_algorithm
[ { "input": "4 68\n", "output": "2 1 4\n" }, { "input": "4 67\n", "output": "2 1 3\n" }, { "input": "3 15\n", "output": "2 1 3\n" }, { "input": "100000 148\n", "output": "2 1 82224\n" }, { "input": "68459 88\n", "output": "2 1 33471\n" }, { "input": "10...
code_contests
python
0
1fa6af1342b20ab653811234dd8f3722
You are given an array of n integer numbers. Let sum(l, r) be the sum of all numbers on positions from l to r non-inclusive (l-th element is counted, r-th element is not counted). For indices l and r holds 0 ≤ l ≤ r ≤ n. Indices in array are numbered from 0. For example, if a = [ - 5, 3, 9, 4], then sum(0, 1) = - 5, ...
n=int(input()) a=[5]+list(map(int,input().split())) dp=[[[i,0] for i in range(n+1)] for j in range(4)] end=n indx_a,indx_b,indx_c=0,0,0 for i in range(1,n+1): dp[0][i][1]=dp[0][i-1][1]+a[i] dp[1][i][1]=max(dp[0][i-1][1],dp[1][i-1][1])-a[i] dp[2][i][1]=max(dp[1][i-1][1],dp[2][i-1][1])+a[i] dp[3][i][1]=ma...
python
code_algorithm
[ { "input": "1\n10000\n", "output": "0 0 1\n" }, { "input": "4\n0 0 -1 0\n", "output": "0 0 0\n" }, { "input": "3\n-1 2 3\n", "output": "0 1 3\n" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0\n", "output": "0 0 0\n" }, { "input": "10\n-6 -4 -7 0 7 9 8 3 8 7\n", "outpu...
code_contests
python
0.5
b7ad897e5ac2498d19f0d1c3ba0ce372
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are reg...
n = int(input()) arr = [] for i in range(n): arr.append(input()) l ={} r = {} z=0 for i in arr: s = 0 g = 0 for j in i: if j =='(': s+=1 else: s-=1 if s <0: g+=1 s=0 if s==0 and g==0: z+=1 if s<=0 and g: if g...
python
code_algorithm
[ { "input": "3\n)\n()\n(\n", "output": "2\n" }, { "input": "2\n()\n()\n", "output": "4\n" }, { "input": "10\n()()(\n)((\n)()(((()(\n(((()(\n)(()((\n))\n()()()()\n))()))((\n)\n))())(\n", "output": "2\n" }, { "input": "2\n((\n))\n", "output": "1\n" }, { "input": "3\n...
code_contests
python
0
d18af78a9494cae1b29a7a798cdb721c
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem: You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him. Input The first line contains an int...
import sys,collections as cc input = sys.stdin.readline I = lambda : list(map(int,input().split())) def div(b): an=[] for i in range(1,int(b**0.5)+1): if b%i==0: an.append(i) if i!=b//i: an.append(b//i) return an n,=I() ar=[] vis=[-1]*(10**5+2) for i in range(n): a,b=I() an=0 dv=div(a) #print(dv,v...
python
code_algorithm
[ { "input": "6\n4 0\n3 1\n5 2\n6 2\n18 4\n10000 3\n", "output": "3\n1\n1\n2\n2\n22\n" }, { "input": "10\n54972 0\n48015 1\n7114 1\n68273 2\n53650 4\n1716 1\n16165 2\n96062 5\n57750 1\n21071 5\n", "output": "24\n21\n3\n3\n21\n22\n6\n6\n62\n3\n" }, { "input": "20\n68260 0\n819 1\n54174 1\n2...
code_contests
python
0
2d1f3060643d2ffafe0bbee08399e80e
Nauuo is a girl who loves playing cards. One day she was playing cards but found that the cards were mixed with some empty ones. There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n...
def index(l): for i in range(n): if l[i]>0: j=(i+1)-l[i] l1.append(j) return(l1) n=int(input()) hand=[int(g) for g in input().split()] deck=[int(g) for g in input().split()] if 1 in deck: index2=deck.index(1) l1=[] buffer=deck[:] buffer.sort() l2=index(deck) if len(set(deck))...
python
code_algorithm
[ { "input": "3\n0 2 0\n3 0 1\n", "output": "2\n" }, { "input": "3\n0 2 0\n1 0 3\n", "output": "4\n" }, { "input": "11\n0 0 0 5 0 0 0 4 0 0 11\n9 2 6 0 8 1 7 0 3 0 10\n", "output": "18\n" }, { "input": "2\n0 0\n2 1\n", "output": "4\n" }, { "input": "5\n0 0 0 0 0\n4 ...
code_contests
python
0
f1d4744f89ba1eea3374e153d43f1c18
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handk...
a=int(input()) x=a w=[] while a>=0: b=[] b.append(a) for i in range(a): b.append(str(a-1-i)) b.insert(0,(a-1-i)) b.insert(0,' '*(2*(x-a))) w.append(b) w.insert(0,b) a=a-1 w.pop(x) for j in w: xx=str(j) xxx=xx.replace(',','') xxxx=xxx.replace("'",'') print(xxxx...
python
code_algorithm
[ { "input": "3\n", "output": " 0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0\n" }, { "input": "2\n", "output": " 0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0\n" }, { "input": "4\n", "output": " 0\n 0 1 0\n 0 1 2 1 0\n 0 1 2 3 2 1 0\n0 1 2 3...
code_contests
python
0
41c92b88b82d21bc0d9ff4dbbc3dadb2
You are given a sequence of integers a_1, a_2, ..., a_n. You need to paint elements in colors, so that: * If we consider any color, all elements of this color must be divisible by the minimal element of this color. * The number of used colors must be minimized. For example, it's fine to paint elements [40, 1...
n=int(input()) arr = list(map(int,input().split())) elem = {} arr.sort() for i in arr: f=0 for k in elem: if i%k == 0: elem[k]+=1 f=1 break if not f: elem[i] = 1 print(len(elem))
python
code_algorithm
[ { "input": "6\n10 2 3 5 4 2\n", "output": "3\n" }, { "input": "8\n7 6 5 4 3 2 2 3\n", "output": "4\n" }, { "input": "4\n100 100 100 100\n", "output": "1\n" }, { "input": "20\n6 8 14 8 9 4 7 9 7 6 9 10 14 14 11 7 12 6 11 6\n", "output": "6\n" }, { "input": "10\n7 7...
code_contests
python
0.5
f91be0df824fe62edcf3b4b595ea1a4e
You are given an array a_1, a_2, ..., a_n. You can perform the following operation any number of times: * Choose a pair of two neighboring equal elements a_i = a_{i + 1} (if there is at least one such pair). * Replace them by one element with value a_i + 1. After each such operation, the length of the array w...
# CLONED CPP SOLUTION def rr(): return input().rstrip() def rri(): return int(rr()) def rrm(): return list(map(int, rr().split())) from collections import defaultdict def mus(d=0): return defaultdict(defaultdict(d)) def ms(x, y, d=0): return [[d]*y for i in range(x)] def ar(x, d=0): return [d]*x def ppm(m, n=0, x=0, y=...
python
code_algorithm
[ { "input": "1\n1000\n", "output": "1\n" }, { "input": "7\n3 3 4 4 4 3 3\n", "output": "2\n" }, { "input": "5\n4 3 2 2 3\n", "output": "2\n" }, { "input": "3\n1 3 5\n", "output": "3\n" }, { "input": "50\n1 1 1 1 1 2 1 1 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 2 2 1 2 1 1 2 2...
code_contests
python
0
78d2264e81d043804e987e3378adb48e
Alice and Bob play a game. The game consists of several sets, and each set consists of several rounds. Each round is won either by Alice or by Bob, and the set ends when one of the players has won x rounds in a row. For example, if Bob won five rounds in a row and x = 2, then two sets ends. You know that Alice and Bob...
class BalancingTree: def __init__(self, n): self.N = n self.root = self.node(1<<n, 1<<n) def append(self, v): v += 1 nd = self.root while True: if v == nd.value: return 0 else: mi, ma = min(v, nd.value), max(v, nd....
python
code_algorithm
[ { "input": "5\n01?01\n", "output": "5 1 0 0 0\n" }, { "input": "12\n???1??????1?\n", "output": "12 6 4 3 2 2 1 1 1 1 1 1\n" }, { "input": "6\n11?000\n", "output": "6 3 2 1 0 0\n" }, { "input": "1\n0\n", "output": "1\n" }, { "input": "1\n1\n", "output": "1\n" ...
code_contests
python
0
ae4219d5b09f002fc3b0df196a50df7c
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not. First Petya puts a marble under the glass in position s. Then he performs some (pos...
from collections import Counter import string import math import sys def array_int(): return [int(i) for i in sys.stdin.readline().split()] def vary(arrber_of_variables): if arrber_of_variables==1: return int(sys.stdin.readline()) if arrber_of_variables>=2: return map(int,sys.stdin.readline(...
python
code_algorithm
[ { "input": "4 3 4\n1 2 3 4\n", "output": "-1\n" }, { "input": "4 3 3\n4 1 3 2\n", "output": "0\n" }, { "input": "4 2 1\n2 3 4 1\n", "output": "3\n" }, { "input": "3 1 3\n2 1 3\n", "output": "-1\n" }, { "input": "100 84 83\n30 67 53 89 94 54 92 17 26 57 15 5 74 85 ...
code_contests
python
1
44f04e50ed2ea15df7fd4ad7ea87b40b
The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that a...
from itertools import * import sys m=[32,29,32,31,32,31,32,32,31,32,31,32] s,t=[map(int,input().split('.')) for _ in range(2)] g=False a,b,c=s for d,e,f in permutations(t): g|=b<13 and e<13 and a<m[b-1]+(b==2)*(c%4==0)and d<m[e-1]+(e==2)*(f%4==0)and(c-f>18 or(c-f==18 and(b>e or(b==e and(a>=d))))) print(["NO","YES"][g]...
python
code_algorithm
[ { "input": "20.10.20\n10.02.30\n", "output": "NO\n" }, { "input": "28.02.74\n28.02.64\n", "output": "NO\n" }, { "input": "01.01.98\n01.01.80\n", "output": "YES\n" }, { "input": "02.05.90\n08.03.50\n", "output": "YES\n" }, { "input": "29.02.80\n29.02.60\n", "ou...
code_contests
python
0
6a63d435d6fbc522be85f8924f37bef2
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from...
def main(): s, t = input(), input() n, m = len(s), len(t) t = '$'.join((t, s)) p = [0] k = 0 for i in range(1, n + m + 1): while k and t[k] != t[i]: k = p[k - 1] if t[k] == t[i]: k += 1 p.append(k) ans = [0] * n sums = [0] * (n + 1) cur...
python
code_algorithm
[ { "input": "ababa\naba\n", "output": "5\n" }, { "input": "ddd\nd\n", "output": "12\n" }, { "input": "welcometoroundtwohundredandeightytwo\nd\n", "output": "274201\n" }, { "input": "a\naa\n", "output": "0\n" }, { "input": "a\na\n", "output": "1\n" }, { ...
code_contests
python
0
e92af808c5163aeee794107a88d27f2a
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game. The rules are following. On each turn a fi...
'''input 4 2 1 3 2 4 2 ''' n = int(input()) a = tuple(map(int, input().split()))[1:] b = tuple(map(int, input().split()))[1:] c = 0 s = set() res = 0 while (a, b) not in s: if not a: res = 2 break if not b: res = 1 break s.add((a, b)) x, y = a[0], b[0] a, b =...
python
code_algorithm
[ { "input": "4\n2 1 3\n2 4 2\n", "output": "6 2\n" }, { "input": "3\n1 2\n2 1 3\n", "output": "-1\n" }, { "input": "10\n8 1 6 5 3 8 7 10 4\n2 9 2\n", "output": "40 1\n" }, { "input": "9\n8 4 8 5 6 3 2 7 1\n1 9\n", "output": "-1\n" }, { "input": "10\n2 7 5\n8 9 3 2 ...
code_contests
python
0.1
93b94d3fdc822c4581f6a7e0f2759a46
Edo has got a collection of n refrigerator magnets! He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be posit...
from sys import* # def check(u, d, l, r): used = [pointsx[i][1] for i in range(l)] used += [pointsx[-1 - i][1] for i in range(r)] used += [pointsy[i][1] for i in range(u)] used += [pointsy[-1 - i][1] for i in range(d)] if len(set(used)) > k: return DOHERA dx = pointsx[-1 - r][0] - points...
python
code_algorithm
[ { "input": "4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2\n", "output": "64\n" }, { "input": "3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4\n", "output": "1\n" }, { "input": "3 0\n1 1 2 2\n1 1 1000000000 1000000000\n1 3 8 12\n", "output": "249999999000000001\n" }, { "input": "2 1\n1 1 1000000...
code_contests
python
0
b4679cf1d3a066134c576c459a675bb6
You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge...
a = input() b = input() if len(a)>len(b): gap = len(a)-len(b) new = '' for _ in range(gap): new+='0' b = new + b elif len(b)>len(a): gap = len(b) - len(a) new = '' for _ in range(gap): new+='0' a = new + a for i in range(0,len(a)): if(a[i]>b[i]): print('>') ...
python
code_algorithm
[ { "input": "11\n10\n", "output": ">\n" }, { "input": "9\n10\n", "output": "<\n" }, { "input": "0123\n9\n", "output": ">\n" }, { "input": "0123\n111\n", "output": ">\n" }, { "input": "00012345\n12345\n", "output": "=\n" }, { "input": "02\n01\n", "ou...
code_contests
python
0.1
1ba9e69867133b0eed06808d2620cb24
Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, Euclid algorithm. Formally, find the biggest integer d, such that all int...
a,b=map(int,input().split()) print(a) if a==b else print(1)
python
code_algorithm
[ { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n", "output": "61803398874989484820458683436563811772030917980576\n" }, { "input": "1 2\n", "output": "1\n" }, { "input": "12345 67890123456789123457\n", "output": "1\n" ...
code_contests
python
0.6
06cd1dea86798e615d3a28274e574dd4
You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1...
x = input() y = input() z = '' for i in range(len(x)): if x[i] < y[i]: print("-1") exit(0) else: z = z + y[i] print(z)
python
code_algorithm
[ { "input": "ab\naa\n", "output": "aa\n" }, { "input": "ab\nba\n", "output": "-1\n" }, { "input": "nzwzl\nniwel\n", "output": "niwel\n" }, { "input": "vkvkkv\nvkvkkv\n", "output": "vkvkkv\n" }, { "input": "jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebj...
code_contests
python
0.7
50793c65031e221d2b589a84f3776dc5
A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win! On the show a dog needs to eat as many bowls of dog food as poss...
# using the min-heap from heapq import heappush,heappop bowels,Time = map(int,input().split()) myLine = [-int(b) for b in input().split()] gulp = []; eat = 0 for i in range(1,min(bowels+1,Time)): # redundant (now that i look at it. the min does that already) if i >= Time: break while gulp and -gulp...
python
code_algorithm
[ { "input": "1 1\n1\n", "output": "0\n" }, { "input": "3 5\n1 5 3\n", "output": "2\n" }, { "input": "1 2\n1\n", "output": "1\n" }, { "input": "15 15\n2 1 2 3 2 3 4 5 6 5 6 5 6 5 6\n", "output": "13\n" }, { "input": "5 3\n2 3 4 5 6\n", "output": "1\n" }, { ...
code_contests
python
0
463a6f04a2e7b4ab01f22cda2ef1ff34
There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. ...
n,a,b,c,t = map(int,input().split()) arr = list() arr = map(int,input().split()) Sum = int(0) for num in arr: Sum += t - num ans = n * a if b >= c: print(ans) else: print(ans + Sum * int(c - b))
python
code_algorithm
[ { "input": "4 5 5 3 5\n1 5 5 4\n", "output": "20\n" }, { "input": "5 3 1 1 3\n2 2 2 1 1\n", "output": "15\n" }, { "input": "5 5 3 4 5\n1 2 3 4 5\n", "output": "35\n" }, { "input": "32 2 74 772 674\n598 426 358 191 471 667 412 44 183 358 436 654 572 489 79 191 374 33 1 627 154...
code_contests
python
0
634144553bd4af591dfbfe23562bbfa2
After passing a test, Vasya got himself a box of n candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means the process of eating candies is the following: in the beginning Vasya choos...
import sys import math n = int(input()) l = 1 r = 2*n while(l < r): candies = n numeaten = 0 k = (l+r)//2 # print(k) while(candies > 0): if candies > k: numeaten += k candies -= k else: numeaten += candies break c = candies//1...
python
code_algorithm
[ { "input": "68\n", "output": "3\n" }, { "input": "505050505\n", "output": "19827992\n" }, { "input": "999999999999999973\n", "output": "39259424579862572\n" }, { "input": "43\n", "output": "2\n" }, { "input": "67\n", "output": "3\n" }, { "input": "601\...
code_contests
python
0.1
90eeed77fc6e78213751c76b62c1b5cb
Maksim walks on a Cartesian plane. Initially, he stands at the point (0, 0) and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point (0, 0), he can go to any of the following points in one move: * (1, 0); * (0, 1); * (-1, 0); * (0, -...
def dista(a, b): return abs(lista[a][0]-lista[b][0]) + abs(lista[a][1]-lista[b][1]) lista = [] ne = 0 n = int(input()) dist = [0] * (n+1) lista.append((0, 0)) for _ in range(n): x, y = map(int, input().split()) lista.append((x, y)) lista = sorted(lista, key= lambda x: min(x)) lista = sorted(lista, key= lambda x: m...
python
code_algorithm
[ { "input": "5\n2 1\n1 0\n2 0\n3 2\n0 3\n", "output": "9\n" }, { "input": "8\n2 2\n1 4\n2 3\n3 1\n3 4\n1 1\n4 3\n1 2\n", "output": "15\n" }, { "input": "9\n1 4\n2 3\n3 4\n4 3\n2 2\n1 2\n1 1\n3 1\n5 3\n", "output": "16\n" }, { "input": "1\n1000000000 1000000000\n", "output"...
code_contests
python
0
1cc31e25db97f3b21bc7103082f6ab00
International Coding Procedures Company (ICPC) writes all its code in Jedi Script (JS) programming language. JS does not get compiled, but is delivered for execution in its source form. Sources contain comments, extra whitespace (including trailing and leading spaces), and other non-essential features that make them qu...
def main(): t = int(input()) reserved = set(input().split()) lines = int(input()) code = '' for i in range(lines): code += input() + '\n' def is_word(suspect): if suspect[0].isdigit(): return False for x in suspect: if (not x.isalpha()) and (not x in {'_', '$'}) and (not x.isdigit()): return False ...
python
code_algorithm
[ { "input": "16\nfun while return var { } ( ) , ; &gt; = + ++ - --\n9\nfun fib(num) { # compute fibs\n var return_value = 1, prev = 0, temp;\n while (num &gt; 0) {\n temp = return_value; return_value = return_value + prev;\n prev = temp;\n num--;\n }\n return return_value;\n}\n", "output": "fun ...
code_contests
python
0
293f09f2450a9bb2976fb7274a3192cb
Authors have come up with the string s consisting of n lowercase Latin letters. You are given two permutations of its indices (not necessary equal) p and q (both of length n). Recall that the permutation is the array of length n which contains each integer from 1 to n exactly once. For all i from 1 to n-1 the followi...
import sys,math,itertools from collections import Counter,deque,defaultdict from bisect import bisect_left,bisect_right from heapq import heappop,heappush,heapify from copy import deepcopy mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline()...
python
code_algorithm
[ { "input": "3 2\n1 2 3\n1 3 2\n", "output": "YES\nabb\n" }, { "input": "3 2\n3 1 2\n3 2 1\n", "output": "YES\nbba\n" }, { "input": "5 4\n1 3 2 4 5\n2 3 5 1 4\n", "output": "NO\n" }, { "input": "5 2\n5 2 4 3 1\n5 4 3 1 2\n", "output": "YES\nbbbba\n" }, { "input": "...
code_contests
python
0
535f845c9773d3a30d43245c9f8950a2
There are n water tanks in a row, i-th of them contains a_i liters of water. The tanks are numbered from 1 to n from left to right. You can perform the following operation: choose some subsegment [l, r] (1≤ l ≤ r ≤ n), and redistribute water in tanks l, l+1, ..., r evenly. In other words, replace each of a_l, a_{l+1},...
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a...
python
code_algorithm
[ { "input": "4\n7 5 5 7\n", "output": "5.666666666666667\n5.666666666666667\n5.666666666666667\n7\n" }, { "input": "5\n7 8 8 10 12\n", "output": "7\n8\n8\n10\n12\n" }, { "input": "10\n3 9 5 5 1 7 5 3 8 7\n", "output": "3\n5.0\n5.0\n5.0\n5.0\n5.0\n5.0\n5.0\n7.5\n7.5\n" }, { "in...
code_contests
python
0
998df4af6bc4d5c14e97ac5b1ddf7a1a
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the sellin...
n,m,k = [int(s) for s in input().split()] BuyingPrice = [] SellingPrice = [] Number_of_items = [] for i in range(n): input() x = [] y = [] z = [] for j in range(m): a,b,c = [int(s) for s in input().split()] x.append(a) y.append(b) z.append(c) BuyingPrice.append(...
python
code_algorithm
[ { "input": "3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5\n", "output": "16\n" }, { "input": "2 2 1\nQwe\n900 800 1\n5 1 1\nEwq\n1000 999 0\n11 10 0\n", "output": "99\n" }, { "input": "3 2 11\nMars\n15 10 4\n7 6 3\nSnickers\n20 17 2\n10 8 0...
code_contests
python
0.4
0247abfabbdeb93aa5d2ab5de79c86e2
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,...
n = int(input()) lis = list(map(int,input().split())) pre=[0]*(n+1) for i in range(1,n+1): pre[i]=pre[i-1]+lis[i-1] if pre[-1]%3: print(0) else: s=pre[-1]//3 ans=t=0 for i in range(1,n): if pre[i]==2*s: ans+=t if pre[i]==s: t+=1 print(ans) ...
python
code_algorithm
[ { "input": "5\n1 2 3 4 5\n", "output": "0\n" }, { "input": "4\n1 2 3 3\n", "output": "1\n" }, { "input": "5\n-6 3 -1 2 -7\n", "output": "0\n" }, { "input": "4\n-2 3 3 2\n", "output": "0\n" }, { "input": "3\n0 0 0\n", "output": "1\n" }, { "input": "9\n-...
code_contests
python
0.1
444d514055e8bc3c71053fc7f24464b9
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th...
from sys import stdin n = int(stdin.readline()) nums = [int(x) for x in stdin.readline().split()] total = sum(nums)*-1 best = 0 left = 0 right = 0 current = 0 while right < n: while current >= 0 and right < n: current += nums[right] best = max(best,current) right += 1 while curren...
python
code_algorithm
[ { "input": "5\n-4 2 0 5 0\n", "output": "11\n" }, { "input": "3\n-1 -2 -3\n", "output": "6\n" }, { "input": "5\n-1 10 -5 10 -2\n", "output": "18\n" }, { "input": "4\n-83 -87 42 -96\n", "output": "308\n" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
code_contests
python
0
b7ca31191db9c48975892d359c596590
One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (...
###### ### ####### ####### ## # ##### ### ##### # # # # # # # # # # # # # ### # # # # # # # # # # # # # ### ###### ######### # # # # # # ...
python
code_algorithm
[ { "input": "4\n1 1 2 3\n", "output": "20\n" }, { "input": "5\n1 1 1 1 1\n", "output": "62\n" }, { "input": "2\n1 2\n", "output": "4\n" }, { "input": "3\n1 1 3\n", "output": "8\n" }, { "input": "1\n1\n", "output": "2\n" }, { "input": "30\n1 1 2 2 5 6 4 ...
code_contests
python
0
f8f979220f0dd8ca6a7f350d959e24ac
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a stud...
n = int(input()) listd = [] res = 0 for i in range(n): listd.append(tuple(map(int, input().split()))) listd.sort() for a, b in listd: res = b if res<=b else a print(res)
python
code_algorithm
[ { "input": "3\n5 2\n3 1\n4 2\n", "output": "2\n" }, { "input": "3\n6 1\n5 2\n4 3\n", "output": "6\n" }, { "input": "1\n1000000000 999999999\n", "output": "999999999\n" }, { "input": "5\n4 3\n4 2\n4 1\n4 1\n4 1\n", "output": "3\n" }, { "input": "6\n12 11\n10 9\n8 7...
code_contests
python
0.1
e2484bac23836a99acc07e19ec75b35d
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting t...
import operator as op import re import sys from bisect import bisect, bisect_left, insort, insort_left from collections import Counter, defaultdict, deque from copy import deepcopy from decimal import Decimal from functools import reduce from itertools import ( accumulate, combinations, combinations_with_replacemen...
python
code_algorithm
[ { "input": "2 1\n", "output": "2\n" }, { "input": "10 7\n", "output": "6\n" }, { "input": "1000000000000 1\n", "output": "1000000000000\n" }, { "input": "3 2\n", "output": "3\n" }, { "input": "4 2\n", "output": "2\n" }, { "input": "1000 998\n", "ou...
code_contests
python
0.9
9cd5bdc216c45d4ca1364f00890da59a
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string s consisting of lowercase Latin letters. At once you can choose any position in th...
import sys input=sys.stdin.readline s=input().rstrip() n=len(s) ans=[""]*n c={} for i in range(n): c[s[i]]=c.get(s[i],0)+1 idx=0 l=[] for i in range(26): al=chr(ord("a")+i) if al in c: while c[al]-2>=0: ans[idx]=ans[n-1-idx]=al c[al]-=2 idx+=1 if c[al]==1:...
python
code_algorithm
[ { "input": "aabcd\n", "output": "abcba\n" }, { "input": "aabc\n", "output": "abba\n" }, { "input": "bbbcccddd\n", "output": "bbcdcdcbb\n" }, { "input": "asbbsha\n", "output": "abshsba\n" }, { "input": "aabbcccdd\n", "output": "abcdcdcba\n" }, { "input"...
code_contests
python
0
53cf6cc8b752469a2d42237ff1ce5629
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are n citizens in Kekoland, each person has ci coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it to t...
import sys inp = sys.stdin.read().splitlines() n,k = list(map(int,inp[0].split())) lst = list(map(int,inp[1].split())) lst.sort() total = sum(lst) lower = int(total/n) nupper = total%n if nupper == 0: upper = lower; else: upper = lower+1; nlower = n - nupper; i = 0; while i<n and lst[i]<lower: i+=1 low1st = i; ...
python
code_algorithm
[ { "input": "4 1\n1 1 4 2\n", "output": "2\n" }, { "input": "3 1\n2 2 2\n", "output": "0\n" }, { "input": "10 1000\n1000000000 999999994 999999992 1000000000 999999994 999999999 999999990 999999997 999999995 1000000000\n", "output": "1\n" }, { "input": "100 20\n2 5 3 3 2 7 6 2...
code_contests
python
0
ca165b7770003fe4432919710cf0f7af
Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes. Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l1, i, r1, i). Also he has m variants when he will attend programming classes, i-th v...
n = int(input()) refA = [] for i in range(n): refA.append([int(x) for x in input().split()]) m = int(input()) refB = [] for i in range(m): refB.append([int(x) for x in input().split()]) refA_early = sorted(refA,key = lambda x:x[1]) refA_late = sorted(refA,key = lambda x:x[0],reverse = True) refB_early = sorte...
python
code_algorithm
[ { "input": "3\n1 5\n2 6\n2 3\n2\n2 4\n6 8\n", "output": "3\n" }, { "input": "3\n1 5\n2 6\n3 7\n2\n2 4\n1 4\n", "output": "0\n" }, { "input": "1\n200000000 200000001\n1\n200000000 200000001\n", "output": "0\n" }, { "input": "1\n999999995 999999996\n1\n999999998 999999999\n", ...
code_contests
python
0.2
419fca8c3991217a44f1b8a56c1a1009
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points. P...
def list_input(): return list(map(int,input().split())) def map_input(): return map(int,input().split()) def map_string(): return input().split() n,k = map_input() a = list_input() b = list_input() pos = set() pref = [] cur = 0 for i in a: cur += i pref.append(cur) for j in pref: pos.add(b[...
python
code_algorithm
[ { "input": "4 1\n-5 5 0 20\n10\n", "output": "3\n" }, { "input": "2 2\n-2000 -2000\n3998000 4000000\n", "output": "1\n" }, { "input": "2 1\n614 -1943\n3874445\n", "output": "2\n" }, { "input": "1 1\n-577\n1273042\n", "output": "1\n" }, { "input": "1 1\n1\n-4000000...
code_contests
python
0
45919f4209780a4c094be7a95f7a90d2
One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if on...
__author__ = 'Darren' def solve(): def calc(lower, upper, record, eq, eq_i): if lower > upper: return 1 key = lower, eq, eq_i if key in record: return record[key] t = 0 for x in (['0', '1'] if result[lower] == '?' else [result[lower]]): ...
python
code_algorithm
[ { "input": "4 4\n", "output": "0101\n" }, { "input": "3 2\n", "output": "010\n" }, { "input": "50 57129577186267\n", "output": "00001101101110011100010111101100101101111110100110\n" }, { "input": "6 12\n", "output": "001101\n" }, { "input": "50 161245081749292\n",...
code_contests
python
0
186a0e68d5efdd5864d070442fe12e51
There are n dormitories in Berland State University, they are numbered with integers from 1 to n. Each dormitory consists of rooms, there are a_i rooms in i-th dormitory. The rooms in i-th dormitory are numbered from 1 to a_i. A postman delivers letters. Sometimes there is no specific dormitory and room number in it o...
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) # aa = [sum(a[:i+1]) for i in range(len(a))] j = 0 s = a[0] for i in range(len(b)): while b[i] > s: # aa[j]: j += 1 s += a[j] print(j+1, b[i]- (s-a[j]) if j > 0 else b[i])
python
code_algorithm
[ { "input": "2 3\n5 10000000000\n5 6 9999999999\n", "output": "1 5\n2 1\n2 9999999994\n" }, { "input": "3 6\n10 15 12\n1 9 12 23 26 37\n", "output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12\n" }, { "input": "3 10\n1000000000 1000000000 1000000000\n543678543 567869543 1000000000 1000000001 15000000...
code_contests
python
1
b524e77d6f5fa931c9efdd0276281d4e
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti...
n, b = input().split() n = int(n) b = int(b) a = [int(x) for x in input().split()] odd = 0 not_odd = 0 pos = list() for i in range(n-1): if a[i] % 2 == 0: not_odd += 1 else: odd += 1 if not_odd == odd: pos.append(abs(a[i+1] - a[i])) pos.sort() sum = 0 count = 0 for i in range(len(p...
python
code_algorithm
[ { "input": "6 100\n1 2 3 4 5 6\n", "output": "2\n" }, { "input": "6 4\n1 2 5 10 15 20\n", "output": "1\n" }, { "input": "4 10\n1 3 2 4\n", "output": "0\n" }, { "input": "100 50\n1 2 3 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...
code_contests
python
0
a955865b585c1cda7746ee1935e159f0
Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home. In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice ...
n, s = input().split() n = int(n) s = int(s) a = input().split() b = input().split() for j in range(n): a[j] = int(a[j]) b[j] = int(b[j]) if a[0]==1: if a[s-1]==1: print("YES") elif b[s-1]==1: for i in range(s,n): if a[i]==1 and b[i]==1: print("YES") break else: print("NO") else: prin...
python
code_algorithm
[ { "input": "5 4\n1 0 0 0 1\n0 1 1 1 1\n", "output": "YES\n" }, { "input": "5 3\n1 1 1 1 1\n1 1 1 1 1\n", "output": "YES\n" }, { "input": "5 2\n0 1 1 1 1\n1 1 1 1 1\n", "output": "NO\n" }, { "input": "4 2\n1 0 1 0\n0 1 1 0\n", "output": "YES\n" }, { "input": "4 2\n...
code_contests
python
0.1
2c772fccada153fd7049ab52fa1a4036
There is a house with n flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of n integer numbers a_1, a_2, ..., a_n, where a_i = 1 if in the i-th flat the light is on and a_i = 0 otherwise. Vova thinks that people in the i-th flats are distur...
n = int(input()) A = [int(i) for i in input().split()] V = [] for i in range(n-2): if (A[i]==1 and A[i+1]==0 and A[i+2]==1): V.append(i+1) V.append(1000) k = 0 l = 0 n = len(V) for i in range(n): if (V[i]-V[l] != 2): d = i-l k += (d+1)//2 l = i print(k)
python
code_algorithm
[ { "input": "10\n1 1 0 1 1 0 1 0 1 0\n", "output": "2\n" }, { "input": "4\n1 1 1 1\n", "output": "0\n" }, { "input": "5\n1 1 0 0 0\n", "output": "0\n" }, { "input": "5\n0 0 0 0 0\n", "output": "0\n" }, { "input": "5\n1 0 1 0 1\n", "output": "1\n" }, { "...
code_contests
python
0.4
6b92e03129782ac825be76002443a7c5
Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertices on the path from vertex v to the root, as well as h_v — the depth of vert...
# alpha = "abcdefghijklmnopqrstuvwxyz" prime = 998244353 # INF = 100000000000 # from heapq import heappush from collections import defaultdict, deque t = 1#int(input()) from math import sqrt for test in range(t): n = int(input()) p = [0, 0] p.extend(list(map(int, input().split()))) s = [0] s.extend...
python
code_algorithm
[ { "input": "3\n1 2\n2 -1 1\n", "output": "-1\n" }, { "input": "5\n1 1 1 1\n1 -1 -1 -1 -1\n", "output": "1\n" }, { "input": "5\n1 2 3 1\n1 -1 2 -1 -1\n", "output": "2\n" }, { "input": "10\n1 1 2 4 4 5 6 3 3\n0 -1 -1 0 -1 -1 1 2 3 4\n", "output": "7\n" }, { "input":...
code_contests
python
0
f6fec3175662ddbcd0fd362d1d5baadc
Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to A...
from collections import defaultdict def get_neighbors(edges): neighbors = defaultdict(set, {}) for v1, v2 in edges: neighbors[v1].add(v2) neighbors[v2].add(v1) return dict(neighbors) def get_component(neighbors_map, root): if root not in neighbors_map: return {root} hori...
python
code_algorithm
[ { "input": "5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2\n", "output": "27\n" }, { "input": "10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6\n", "output": "61\n" }, { "input": "3 2\n1 1335 2\n2 1\n3 2\n2\n", "output": "1337\n" },...
code_contests
python
0
75fc02d696ccd95247db48f976d0a508
Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binary numbers of the form 2^x + p, where x is a non-negative integer. For example,...
n,p=map(int,input().split()) #print("{0:b}".format(n).count('1')) t=0 while (("{0:b}".format(n).count('1'))>t or n<t) and n>=0: t+=1 n-=p if n<0: print(-1) else: print(t)
python
code_algorithm
[ { "input": "4 -7\n", "output": "2\n" }, { "input": "24 -1\n", "output": "4\n" }, { "input": "24 1\n", "output": "3\n" }, { "input": "24 0\n", "output": "2\n" }, { "input": "1 1\n", "output": "-1\n" }, { "input": "536870812 1\n", "output": "24\n" ...
code_contests
python
0
c7dae3f3b5fab0e21dfa7d35617ca683
Creatnx has n mirrors, numbered from 1 to n. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The i-th mirror will tell Creatnx that he is beautiful with probability (p_i)/(100) for all 1 ≤ i ≤ n. Creatnx asks the mirrors one by one, starting from the 1-st mirror. Every day, if he asks i-th mirror, there ...
N = int(input()) P = list(map(int, input().split())) mod = 998244353 p = 0 q = 1 for i in range(N): p, q = (100 * (p+q)) % mod, (P[i] * q) % mod print((p * pow(q, mod-2, mod))%mod)
python
code_algorithm
[ { "input": "1\n50\n", "output": "2\n" }, { "input": "3\n10 20 50\n", "output": "112\n" }, { "input": "5\n30 48 49 17 25\n", "output": "626083602\n" }, { "input": "4\n42 20 51 84\n", "output": "970992516\n" }, { "input": "100\n60 79 48 35 18 24 87 1 44 65 60 78 11 ...
code_contests
python
0
548b13751c1685f41c8ef6e9e733ecb1
It's a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another. Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P": * "A" corresponds to an angry...
n=int(input()) for i in range(n): m=int(input()) l=list(input()) p=[] c=0 r=len(l) for i in range(r): if l[i]=="P": c+=1 if i==r-1: p.append(c) if l[i]=="A": p.append(c) c=0 if len(p)!=1: if p[0]==0: print(max(p)) else: p.pop(0) print(max(p)) else: print(0)
python
code_algorithm
[ { "input": "1\n4\nPPAP\n", "output": "1\n" }, { "input": "3\n12\nAPPAPPPAPPPP\n3\nAAP\n3\nPPA\n", "output": "4\n1\n0\n" }, { "input": "10\n1\nA\n1\nP\n2\nAP\n2\nPA\n8\nPPPPAPPP\n8\nPPPPPPPA\n8\nAPPPPPPP\n8\nPPPPPPAP\n8\nPPPPPAPP\n8\nPPPAPPPP\n", "output": "0\n0\n1\n0\n3\n0\n7\n1\n2\n...
code_contests
python
0.1
b53ed94386b2dc229a373171d31653be
Dreamoon is a big fan of the Codeforces contests. One day, he claimed that he will collect all the places from 1 to 54 after two more rated contests. It's amazing! Based on this, you come up with the following problem: There is a person who participated in n Codeforces rounds. His place in the first round is a_1, hi...
cycles = int(input()) def find_v(x, places): places = set(places) v = 0 i = 1 while True: if i in places: v = i elif x > 0: v = i x -= 1 else: break i += 1 return v results = [] for cycle in range(cycles): n, x ...
python
code_algorithm
[ { "input": "5\n6 2\n3 1 1 5 7 10\n1 100\n100\n11 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1\n1\n4 57\n80 60 40 20\n", "output": "5\n101\n2\n2\n60\n" }, { "input": "1\n5 2\n3 4 5 6 7\n", "output": "7\n" }, { "input": "1\n6 1\n1 3 4 5 6 7\n", "output": "7\n" }, { "input": "1\n4 3\n4 5 6 7\n...
code_contests
python
0
2c91632b82354cacd86f590a505a94ff
Orac is studying number theory, and he is interested in the properties of divisors. For two positive integers a and b, a is a divisor of b if and only if there exists an integer c, such that a⋅ c=b. For n ≥ 2, we will denote as f(n) the smallest positive divisor of n, except 1. For example, f(7)=7,f(10)=2,f(35)=5. ...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) ans = n for i in range(2, n + 1): if n % i == 0: ans += i break ans += 2 * (k - 1) print(ans)
python
code_algorithm
[ { "input": "3\n5 1\n8 2\n3 4\n", "output": "10\n12\n12\n" }, { "input": "5\n497347 19283\n2568 1000000000\n499979 123987\n93 19\n13 5\n", "output": "536584\n2000002568\n1247930\n132\n34\n" }, { "input": "1\n902059 999999997\n", "output": "2000902980\n" }, { "input": "1\n66605...
code_contests
python
0
fbcd6e7a8f1b8809f74c828b851d925d
Ashish has an array a of size n. A subsequence of a is defined as a sequence that can be obtained from a by deleting some elements (possibly none), without changing the order of the remaining elements. Consider a subsequence s of a. He defines the cost of s as the minimum between: * The maximum among all elements...
import sys import math def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def MI(): return map(int, sys.stdin.readline().split()) def SI(): return sys.stdin.readline().strip() n,k = MI() a = LI() def check(mid,isEven): ans = 0 for i in range(n): if isEven...
python
code_algorithm
[ { "input": "4 2\n1 2 3 4\n", "output": "1\n" }, { "input": "4 3\n1 2 3 4\n", "output": "2\n" }, { "input": "6 4\n5 3 50 2 4 5\n", "output": "3\n" }, { "input": "5 3\n5 3 4 2 6\n", "output": "2\n" }, { "input": "4 2\n93648 34841 31096 95128\n", "output": "31096...
code_contests
python
0
85844b49be26f9a999144d1d68fde3f3
You are given an array a consisting of n non-negative integers. You have to choose a non-negative integer x and form a new array b of size n according to the following rule: for all i from 1 to n, b_i = a_i ⊕ x (⊕ denotes the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)). An inversion i...
import os from sys import stdin, stdout class Input: def __init__(self): self.lines = stdin.readlines() self.idx = 0 def line(self): try: return self.lines[self.idx].strip() finally: self.idx += 1 def array(self, sep = ' ', cast = int): ...
python
code_algorithm
[ { "input": "9\n10 7 9 10 7 5 5 3 5\n", "output": "4 14\n" }, { "input": "3\n8 10 3\n", "output": "0 8\n" }, { "input": "4\n0 1 3 2\n", "output": "1 0\n" }, { "input": "94\n89 100 92 24 4 85 63 87 88 94 68 14 61 59 5 77 82 6 13 13 25 43 80 67 29 42 89 35 72 81 35 0 12 35 53 54...
code_contests
python
0
0397ebc1ab65f42db1823feeb1bc7e7a
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal a instant damage to him, and then heal that enemy b health points at the end of every second, for exactly c seconds, starting one second after the ability is used. That means that if the ability is used at time t, the ...
import sys input = sys.stdin.readline def solve_case(): a, b, c, d = [int(x) for x in input().split()] if a > b * c: print(-1) else: k = a // (b * d) print(a * (k + 1) - k * (k + 1) // 2 * b * d) def main(): for _ in range(int(input())): solve_case() main()
python
code_algorithm
[ { "input": "7\n1 1 1 1\n2 2 2 2\n1 2 3 4\n4 3 2 1\n228 21 11 3\n239 21 11 3\n1000000 1 1000000 1\n", "output": "1\n2\n1\n5\n534\n-1\n500000500000\n" }, { "input": "1\n1000000 1000000 1 1000000\n", "output": "1000000\n" }, { "input": "4\n568133 729913 934882 371491\n916127 997180 932938 2...
code_contests
python
0
d6a34e5ac982b4af239fe758d7f501f8
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Pety...
a,b=input(),input();c,d=0,0 for i in range(len(a)): if a[i]!=b[i]: if a[i]=='4': c+=1 else: d+=1 print(max(c,d))
python
code_algorithm
[ { "input": "774\n744\n", "output": "1\n" }, { "input": "47\n74\n", "output": "1\n" }, { "input": "777\n444\n", "output": "3\n" }, { "input": "74747474\n77777777\n", "output": "4\n" }, { "input": "44447777447744444777777747477444777444447744444\n4744474777477474447...
code_contests
python
0.7
c4d043c2388f399e26cad738b016f5ac
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circl...
n = int(input()) p = n arr = [] while p%2==0: arr.append(2) p = p//2 x = int(p**0.5)+1 for i in range(3,x,2): while p%i==0: arr.append(i) p = p//i if p>2: arr.append(p) if n==1 or len(arr)==1: print(1) print(0) elif len(arr)==2: print(2) else: x = arr[0]*arr[1] print(...
python
code_algorithm
[ { "input": "30\n", "output": "1\n6\n" }, { "input": "1\n", "output": "1\n0\n" }, { "input": "6\n", "output": "2\n" }, { "input": "8587340257\n", "output": "1\n9409\n" }, { "input": "7420738134810\n", "output": "1\n6\n" }, { "input": "2975\n", "outp...
code_contests
python
0
af28de6d802930ca6a8ce5b860d2bf80
Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right f...
import sys ii = lambda: sys.stdin.readline().strip() idata = lambda: [int(x) for x in ii().split()] sdata = lambda: list(ii()) def solve(): n, x, y, c = idata() r = n ** 2 l = -1 while l + 1 < r: middle = (l + r) // 2 ans = 1 + 2 * (middle + 1) * middle ans -= pow(middle - n + y...
python
code_algorithm
[ { "input": "9 3 8 10\n", "output": "2\n" }, { "input": "6 4 3 1\n", "output": "0\n" }, { "input": "1000000000 63 65 384381709\n", "output": "27600\n" }, { "input": "9 4 3 10\n", "output": "2\n" }, { "input": "847251738 695702891 698306947 648440371\n", "output...
code_contests
python
0
ec529b249cf8c2375c8ee3544a89346f
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he ...
n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() ans = 0 for i in range(len(a)): if a[i] < 0: ans += a[i] m -= 1 if m == 0: break print(-1 * ans)
python
code_algorithm
[ { "input": "4 2\n7 0 0 -7\n", "output": "7\n" }, { "input": "5 3\n-6 0 35 -2 4\n", "output": "8\n" }, { "input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -8...
code_contests
python
0.9
f51bc24dc56fea8b5cf94e582a0d1fda
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is ...
#------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUF...
python
code_algorithm
[ { "input": "8\n9\n1\n6\n2\n6\n5\n8\n3\n", "output": "5\n" }, { "input": "8\n2\n5\n7\n6\n9\n8\n4\n2\n", "output": "5\n" }, { "input": "4\n1\n1\n1\n2\n", "output": "3\n" }, { "input": "1\n1\n", "output": "1\n" }, { "input": "100\n678\n771\n96\n282\n135\n749\n168\n66...
code_contests
python
0
07593229c91d099c85debb98d8323593
One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once. The appointed Judge was the most experienced member — Pavel. But since he was the wi...
n,k=map(int,input().split()) a=n*(n-1)//2 if(n*k>a): print(-1) else: print(n*k) for i in range(1,n+1): for j in range(k): print(i,(i+j)%n+1)
python
code_algorithm
[ { "input": "3 1\n", "output": "3\n1 2\n2 3\n3 1\n" }, { "input": "11 6\n", "output": "-1\n" }, { "input": "2 1\n", "output": "-1\n" }, { "input": "10 5\n", "output": "-1\n" }, { "input": "4 1\n", "output": "4\n1 2\n2 3\n3 4\n4 1\n" }, { "input": "1 1\n...
code_contests
python
0
92ff26693f964ab14335a5627efcd197
There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place: * either employee y became the boss of employee x (at that, employee x didn't have a bos...
import sys input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ n, m = map(int, input().split()) ev = [tuple(map(int, input().split())) for _ in range(m)] g = [[] for _ in range(n + 1)] qry = [[] for _ in range(m + 1)] roots = set(range(1, n + 1)) qcnt = 0 for e in ev: if e[0] == 1: g[e[2]].append(...
python
code_algorithm
[ { "input": "4 9\n1 4 3\n2 4\n3 3 1\n1 2 3\n2 2\n3 1 2\n1 3 1\n2 2\n3 1 3\n", "output": "YES\nNO\nYES\n" }, { "input": "5 10\n1 2 1\n1 3 2\n2 3\n1 4 3\n1 5 4\n2 5\n3 1 2\n2 5\n2 5\n2 5\n", "output": "YES\n" }, { "input": "10 10\n2 9\n1 2 1\n1 3 2\n3 1 1\n3 1 1\n2 3\n3 1 1\n3 1 1\n3 1 2\n3...
code_contests
python
0.4
6724b7b3270490a188db59acb546278a
Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with α li...
eps=10**(-9) mn=10 mx=100000000 n=int(input()) arr=list(map(int,input().split())) for i in range(n): mn = max(mn,(arr[i]*10)/(i+1)) mx = min(mx,((arr[i]+1)*10)/(i+1)) ans1=((n+1)*mn)//10 ans2=((n+1)*(mx-eps))//10 if ans2>ans1: print('not unique') else: print('unique') print(int(ans1))
python
code_algorithm
[ { "input": "3\n1 2 4\n", "output": "unique\n5\n" }, { "input": "2\n1 2\n", "output": "not unique\n" }, { "input": "9\n2 5 7 10 12 15 17 20 22\n", "output": "unique\n25\n" }, { "input": "50\n19876 39753 59629 79506 99382 119259 139135 159012 178889 198765 218642 238518 258395 ...
code_contests
python
0
fb74007bdb35db0b82a3db0adeef8d75
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co...
s = input() l = len(s) n = int(input()) u = [] for i in range(n): a = input() #print('Taken input', a,len(a),l) if a[:l] == s: if len(u) == 0: u.append(a if len(a) == l else a[l:]) elif len(a) == l: u = [a] + u else: j = 0 k = 0 while True: if u[k] == s: if k < len(u) - 1: k += 1...
python
code_algorithm
[ { "input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand\n", "output": "find\n" }, { "input": "next\n2\nnextpermutation\nnextelement\n", "output": "nextelement\n" }, { "input": "find\n4\nfind\nfindfirstof\nfindit\nfand\n", "output": "find\n" }, { "input": "find\n4\nfind\nfind...
code_contests
python
1
cc58a8a437809f2a93b44f3a496bfcd9
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers. He wants to know how many subsequences of length three can be selected from a, so that they form a geometric p...
import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') ...
python
code_algorithm
[ { "input": "10 3\n1 2 6 2 3 6 9 18 3 9\n", "output": "6\n" }, { "input": "5 2\n1 1 2 2 4\n", "output": "4\n" }, { "input": "3 1\n1 1 1\n", "output": "1\n" }, { "input": "3 200000\n999999998 999999999 1000000000\n", "output": "0\n" }, { "input": "3 17\n2 34 578\n",...
code_contests
python
0.2
68859ab2938a92e920182ef5f79aadf0
Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i. Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1. Squares are numbered 1, 2, 3 and so on. Vika decided that she will ...
import itertools import math n = int(input()) a = [int(x) for x in input().split()] amin = min(a) b = list(filter(lambda x: x[1] == amin, enumerate(a))) l = len(b) k = max((b[(i+1) % l][0] - b[i][0] - 1)%n for i in range(l)) print(amin*n + k)
python
code_algorithm
[ { "input": "5\n2 4 2 3 3\n", "output": "12\n" }, { "input": "3\n5 5 5\n", "output": "15\n" }, { "input": "6\n10 10 10 1 10 10\n", "output": "11\n" }, { "input": "8\n5 4 3 2 1 1 1 1\n", "output": "12\n" }, { "input": "4\n100 101 101 100\n", "output": "402\n" ...
code_contests
python
0.1
3eb549e663691e113734504287bf9ff5
The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives. A young hacker Vasya disassembled the program and foun...
#Nearly Lucky ''' a=list(map(str,input())) l=0 for i in range(len(a)): if(a[i]=='4' or a[i]=='7'): l+=1 if(l==4 or l==7 or l==44 or l==47 or l==74 or l==77): print("YES") else: print("NO")''' #IQ Test ''' a=int(input()) b=list(map(int,input().strip().split())) e,o=[],[] for i in range(len(b)): i...
python
code_algorithm
[ { "input": "12345\n", "output": "71232\n" }, { "input": "91537\n", "output": "27651\n" }, { "input": "13542\n", "output": "84443\n" }, { "input": "32036\n", "output": "82432\n" }, { "input": "71232\n", "output": "10151\n" }, { "input": "10000\n", "...
code_contests
python
1
91e0b34545b19146919034b34e0519ef
Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a system of coordinates, directing the Ox axis from west to east, and th...
read = lambda: map(int, input().split()) vect = lambda a, b: a[0] * b[1] - a[1] * b[0] vector = lambda A, B: (B[0] - A[0], B[1] - A[1]) n = int(input()) p = [tuple(read()) for i in range(n)] cnt = 0 for i in range(2, n): v1 = vector(p[i], p[i - 1]) v2 = vector(p[i - 1], p[i - 2]) if vect(v1, v2) < 0: ...
python
code_algorithm
[ { "input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1\n", "output": "6\n" }, { "input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0\n", "output": "1\n" }, { "input": "24\n-10000 -10000\n-10000 9998\n9998 9998\n9998 -10000\n-6364 -10000\n-6364 6362\...
code_contests
python
0.2
f7eff3f19810b8619517974027d2ce61
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column ...
from math import ceil,floor n,m = map(int, input().split()) res = 0 for i in range(1,n+1): req = 5 - i%5 res += ((m-req) // 5) +1 print(res)
python
code_algorithm
[ { "input": "5 7\n", "output": "7\n" }, { "input": "1 5\n", "output": "1\n" }, { "input": "21 21\n", "output": "88\n" }, { "input": "6 12\n", "output": "14\n" }, { "input": "11 14\n", "output": "31\n" }, { "input": "3 8\n", "output": "5\n" }, { ...
code_contests
python
0.2
15a1d16964af569dfe982463cd090027
Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them presented to him a string si having the same length n. We denote the beauty of the i-th string by ai. It can happen that ai is negative — that means that Santa doesn't find this s...
import sys import math def solve(): k, n = map(int, input().split()) D = {} for line in sys.stdin: s, a = line.split() if s in D: D[s].append(int(a)) else: D[s] = [int(a)] res = 0 center = 0 for s in D: revs = s[::-1] if not revs ...
python
code_algorithm
[ { "input": "7 3\nabb 2\naaa -3\nbba -1\nzyz -4\nabb 5\naaa 7\nxyx 4\n", "output": "12\n" }, { "input": "2 5\nabcde 10000\nabcde 10000\n", "output": "0\n" }, { "input": "3 1\na 1\na 2\na 3\n", "output": "6\n" }, { "input": "10 10\nnjxbzflaka -1\nfelbvvtkja 6\ngxiuztqkcw 5\naom...
code_contests
python
0
db9a74c18df3cca9f2df9316359e173f
A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through n. Limak recently learned how to jump. He can jump from a vertex to any verte...
""" #If FastIO not needed, used this and don't forget to strip #import sys, math #input = sys.stdin.readline """ import os import sys from io import BytesIO, IOBase import heapq as h from bisect import bisect_left, bisect_right from types import GeneratorType BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 ...
python
code_algorithm
[ { "input": "6 2\n1 2\n1 3\n2 4\n2 5\n4 6\n", "output": "20\n" }, { "input": "3 5\n2 1\n3 1\n", "output": "3\n" }, { "input": "13 3\n1 2\n3 2\n4 2\n5 2\n3 6\n10 6\n6 7\n6 13\n5 8\n5 9\n9 11\n11 12\n", "output": "114\n" }, { "input": "12 3\n5 11\n10 11\n6 4\n8 9\n4 12\n10 7\n4 ...
code_contests
python
0
af70f19b7b3d4e4bacf0ba43adcfd4da
Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. <image> There are n banks, numbered from 1 to n. There are also n - 1 wires connecting the ...
import sys input = sys.stdin.readline from collections import Counter n = int(input()) arr = list(int(i) for i in input().split()) + [-int(1e9+3)] c = Counter(arr) top, sec = sorted(set(arr))[-1:-3:-1] top_cnt = [int(i == top) for i in arr] sec_cnt = [int(i == sec) for i in arr] edges = list(list(map(int, input().spl...
python
code_algorithm
[ { "input": "5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5\n", "output": "5\n" }, { "input": "5\n1 2 7 6 7\n1 5\n5 3\n3 4\n2 4\n", "output": "8\n" }, { "input": "7\n38 -29 87 93 39 28 -55\n1 2\n2 5\n3 2\n2 4\n1 7\n7 6\n", "output": "93\n" }, { "input": "2\n999999999 1000000000\n2 1\n", ...
code_contests
python
0
50f9ced154806b6ecdfd2f21341e365b
You are given an array of n integer numbers a0, a1, ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. Input The first line contains positive integer n (2 ≤ n ≤ 105) — size of the given array. The second line contains n ...
from sys import maxsize n = int(input()) arr = list(map(int,input().split())) m = maxsize res= maxsize ind = [] for i in range(len(arr)): if arr[i] < m: m = arr[i] ind = [i] res=maxsize elif arr[i] == m: ind.append(i) if ind[-1]-ind[-2] < res and len(ind) > 1: ...
python
code_algorithm
[ { "input": "2\n3 3\n", "output": "1\n" }, { "input": "9\n2 1 3 5 4 1 2 3 1\n", "output": "3\n" }, { "input": "3\n5 6 5\n", "output": "2\n" }, { "input": "10\n1 3 2 4 5 5 4 3 2 1\n", "output": "9\n" }, { "input": "11\n2 2 2 2 2 2 1 1 2 2 2\n", "output": "1\n" ...
code_contests
python
0.6
638adc49860d80e2a8f6d428979756d1
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin ...
n = int(input()) a = [] for i in range(n): a.append(input().rstrip()) w = list(input().rstrip()) c = input().rstrip() m = len(w) z = [] i = 0 while i < m: for j in range(n): if w[i].lower() == a[j][0].lower(): if i + len(a[j]) <= m: f = 1 for k in range(i,i+le...
python
code_algorithm
[ { "input": "2\naCa\ncba\nabAcaba\nc\n", "output": "abCacba\n" }, { "input": "3\nbers\nucky\nelu\nPetrLoveLuckyNumbers\nt\n", "output": "PetrLovtTttttNumtttt\n" }, { "input": "4\nhello\nparty\nabefglghjdhfgj\nIVan\npetrsmatchwin\na\n", "output": "petrsmatchwin\n" }, { "input":...
code_contests
python
0.4
7b044e5ad9014d5f00dc6c27f1ff388c
Polycarp likes numbers that are divisible by 3. He has a huge number s. Polycarp wants to cut from it the maximum number of numbers that are divisible by 3. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after m such cuts, there will be m+1 parts in total. Poly...
n = input() buf = 0 c = 0 m = 0 for i in range(len(n)): buf += int(n[i]) m += 1 if int(n[i]) % 3 == 0 or buf % 3 == 0 or m >= 3: buf = 0 c += 1 m = 0 print(c)
python
code_algorithm
[ { "input": "201920181\n", "output": "4\n" }, { "input": "3121\n", "output": "2\n" }, { "input": "1000000000000000000000000000000000\n", "output": "33\n" }, { "input": "6\n", "output": "1\n" }, { "input": "11\n", "output": "0\n" }, { "input": "13\n", ...
code_contests
python
0.1
aa91701e7ca5af7d24a5b732a579766e
You are given a problemset consisting of n problems. The difficulty of the i-th problem is a_i. It is guaranteed that all difficulties are distinct and are given in the increasing order. You have to assemble the contest which consists of some problems of the given problemset. In other words, the contest you have to as...
n=int(input()) a=list(map(int,input().split())) b=[] for _ in range(n-1): if a[_+1]<=a[_]*2: b.append(1) else: b.append(0) b.append(1); s=0; c=[] for i in range(n): if b[i]==1: s+=1 c.append(s) else: s=0 if c[len(c)-1]==max(c) and c.count(max(c))==1: print(max...
python
code_algorithm
[ { "input": "5\n2 10 50 110 250\n", "output": "1\n" }, { "input": "10\n1 2 5 6 7 10 21 23 24 49\n", "output": "4\n" }, { "input": "6\n4 7 12 100 150 199\n", "output": "3\n" }, { "input": "2\n2 3\n", "output": "2\n" }, { "input": "2\n10 20\n", "output": "2\n" ...
code_contests
python
0.9
38ec4dbd4cd765c129880fc6a7deb1e6
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to...
n=int(input()) if n<11 or n>21: print(0) elif n==20: print(15) else: print(4)
python
code_algorithm
[ { "input": "12\n", "output": "4\n" }, { "input": "10\n", "output": "0\n" }, { "input": "20\n", "output": "15\n" }, { "input": "15\n", "output": "4\n" }, { "input": "6\n", "output": "0\n" }, { "input": "13\n", "output": "4\n" }, { "input": "...
code_contests
python
0.1
b93643fb0a182b71fc4f2015f0b73975
You are given an undirected unweighted graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful if for each edge the sum of numbers on vertices connected by this edge is odd. Calculate the number of possible ways t...
from collections import deque from sys import stdin, stdout input = stdin.readline saida = [] t = int(input()) modulo = 998244353 for _ in range(t): ans = 1 part = 0 factor = 0 fila = deque([]) n, m = map(int, input().split()) if m > (n // 2) * ( n // 2 + 1): saida.append('0') ...
python
code_algorithm
[ { "input": "2\n2 1\n1 2\n4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "output": "4\n0\n" }, { "input": "12\n8 7\n2 3\n3 4\n4 5\n5 2\n6 7\n7 8\n8 6\n1 0\n2 1\n1 2\n3 3\n1 2\n2 3\n1 3\n3 2\n2 3\n3 1\n4 4\n1 2\n2 3\n3 4\n4 1\n4 4\n1 2\n2 3\n3 1\n4 1\n6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n100000 0\...
code_contests
python
0
cff5962c7dec54451ce4e76441b432cb
Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn to the Dwarves, Olórin I was in my youth in the West that is forgotten, in t...
s=input() if len(set(s[:len(s)//2]))<=1: print("Impossible");exit() for i in range(1,len(s)): n=s[i:]+s[:i] if(n==n[::-1])and(n!=s): print(1);exit() print(2)
python
code_algorithm
[ { "input": "nolon\n", "output": "2\n" }, { "input": "kinnikkinnik\n", "output": "1\n" }, { "input": "otto\n", "output": "1\n" }, { "input": "qqqq\n", "output": "Impossible\n" }, { "input": "bbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgbbgggbgbggggg...
code_contests
python
0
aee5065f6d18701483c033b20cd7315a
Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right. The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similar...
input() l = [0]*10 s = input() for i in range(len(s)): e = s[i] if e == 'L': l[l.index(0)] = 1 elif e == 'R': l[len(l) - l[::-1].index(0) - 1] = 1 else: l[int(e)] = 0 print(*l, sep = '')
python
code_algorithm
[ { "input": "9\nL0L0LLRR9\n", "output": "1100000010\n" }, { "input": "8\nLLRL1RL1\n", "output": "1010000011\n" }, { "input": "8\nLLLL1LLL\n", "output": "1111110000\n" }, { "input": "4\nRRRL\n", "output": "1000000111\n" }, { "input": "12\nRRRRRRRRRR9L\n", "outpu...
code_contests
python
0
4ce389d3d1b95fb8dee57b4b19620d3b
Let LCM(x, y) be the minimum positive integer that is divisible by both x and y. For example, LCM(13, 37) = 481, LCM(9, 6) = 18. You are given two integers l and r. Find two integers x and y such that l ≤ x < y ≤ r and l ≤ LCM(x, y) ≤ r. Input The first line contains one integer t (1 ≤ t ≤ 10000) — the number of tes...
T=int(input()) for _ in range(T): l,r=map(int,input().split()) if abs(l-r)==1 and l!=1: print(-1,-1) elif 2*l>r : print(-1,-1) else: print(l,2*l)
python
code_algorithm
[ { "input": "4\n1 1337\n13 69\n2 4\n88 89\n", "output": "1 2\n13 26\n2 4\n-1 -1\n" }, { "input": "1\n80000000 160000000\n", "output": "80000000 160000000\n" }, { "input": "1\n78788 157576\n", "output": "78788 157576\n" }, { "input": "1\n1000003 100000000\n", "output": "100...
code_contests
python
0.7
f9926cf5d85cf8ce035a8a943cd0ca95
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s. You have to answer t independent test cases. Input The first line of the input co...
for _ in range(int(input())): n,k=[int(x) for x in input().split()] if n%k==0:print(0) else:print(k-(n%k))
python
code_algorithm
[ { "input": "5\n2 1\n1 1\n500 4\n217871987498122 10\n100000000000000001 1\n", "output": "0\n0\n0\n8\n0\n" }, { "input": "1\n9987 1\n", "output": "0\n" }, { "input": "21\n1 3218\n28 10924\n908802 141084\n82149 9274\n893257 10248\n2750048 802705\n2857 142\n980 209385\n1 3218\n28 10924\n9088...
code_contests
python
0
2acb8818bafb40628caea5f914da8ec0
One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name s, a user can pick number p and character c and delete the p-th occurrence of character c from the name. After the user changed his name, he can't undo th...
# cook your dish here n=int(input()) s=list(input())*n d={} for i in range(len(s)): if s[i] not in d: d[s[i]]=[i] else: d[s[i]].append(i) m=int(input()) for i in range(m): o,c=input().split() s[d[c].pop(int(o)-1)]='' print(''.join(s))
python
code_algorithm
[ { "input": "2\nbac\n3\n2 a\n1 b\n2 c\n", "output": "acb\n" }, { "input": "1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b\n", "output": "baa\n" }, { "input": "10\nccbcabbaca\n40\n2 c\n8 b\n26 b\n12 b\n24 a\n29 a\n20 c\n17 b\n32 c\n9 c\n16 b\n13 b\n19 a\n3 c\n2 b\n18 c\n4 a\n13 c\n8 c\n5 c\n13 a\n19 c\...
code_contests
python
0.7
a7c8d6678b25b136b2503f8add3c0f11
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j. L...
x=int(input()) n=1 while n*n+1<2*x: n+=2 if x==3: n=5 print(n)
python
code_algorithm
[ { "input": "9\n", "output": "5\n" }, { "input": "4\n", "output": "3\n" }, { "input": "6\n", "output": "5\n" }, { "input": "89\n", "output": "15\n" }, { "input": "15\n", "output": "7\n" }, { "input": "91\n", "output": "15\n" }, { "input": "7...
code_contests
python
0
7771ac4549573a2dc3576be0c7cd1122