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
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are n books on sale from one of m genres. In the bookshop, Jack decides to buy two books of different genres. Based on the genre of books on sale in the shop, find the nu...
n, m = list(map(int, input().split())) a = list(map(int, input().split())) t = 0 for i in range(m): cnt = a.count(i + 1) t += cnt * (n - cnt) n -= cnt print(t)
python
code_algorithm
[ { "input": "7 4\n4 2 3 1 2 4 3\n", "output": "18\n" }, { "input": "4 3\n2 1 3 1\n", "output": "5\n" }, { "input": "100 10\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 ...
code_contests
python
1
173cb75d60084a7e4745591d70e49607
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one cannot find the power using ...
n=int(input()) if(n==0): print(1) elif(n==1): print(5) else: print(25)
python
code_algorithm
[ { "input": "2\n", "output": "25\n" }, { "input": "7\n", "output": "25\n" }, { "input": "2000000000000000000\n", "output": "25\n" }, { "input": "1000000000000000000\n", "output": "25\n" }, { "input": "987654321012345678\n", "output": "25\n" } ]
code_contests
python
1
a5a6df6ce18ad564cfa1eaab0467c83b
Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it! Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has n pieces numbered from 1 to n from le...
""" Python 3 compatibility tools. """ from __future__ import division, print_function import itertools import sys import os from io import BytesIO, IOBase if sys.version_info[0] < 3: input = raw_input range = xrange filter = itertools.ifilter map = itertools.imap zip = itertools.izip def is_it_local(): ...
python
code_algorithm
[ { "input": "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b\n", "output": "3\n4\n5\n7\n8\n1\n2\n3\n4\n5\n" }, { "input": "6\nkoyomi\n3\n1 o\n4 o\n4 m\n", "output": "3\n6\n5\n" }, { "input": "10\naaaaaaaaaa\n2\n10 b\n10 z\n", "output": "10\n10\n" }, { ...
code_contests
python
0.5
5945a8ee6a9d4abaa492707b52bceb7b
You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest. The track's map is represented by a rectangle n × m in size divi...
import sys from array import array # noqa: F401 from itertools import combinations from collections import deque def input(): return sys.stdin.buffer.readline().decode('utf-8') n, m, k = map(int, input().split()) chars = ( ['}' * (m + 2)] + ['}' + ''.join('{' if c == 'S' else '|' if c == 'T' else c for...
python
code_algorithm
[ { "input": "5 3 2\nSba\nccc\naac\nccc\nabT\n", "output": "bcccc\n" }, { "input": "3 4 1\nSxyy\nyxxx\nyyyT\n", "output": "xxxx\n" }, { "input": "1 3 3\nTyS\n", "output": "y\n" }, { "input": "1 4 1\nSxyT\n", "output": "-1\n" }, { "input": "20 10 3\nebebccacdb\neeebc...
code_contests
python
0
066e7e8bfeaf543e639457de33d708a1
You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right. You perform a sequence of operations on this set of p...
name = input() blocks = [] now = name[0] counter = 1 for x in range(1, len(name)): if name[x] != now: blocks.append((now, counter)) now = name[x] counter = 1 else: counter += 1 blocks.append((now, counter)) counter = 0 temp = [] while len(blocks) > 1: counter += 1 temp ...
python
code_algorithm
[ { "input": "aabb\n", "output": "2\n" }, { "input": "aabcaa\n", "output": "1\n" }, { "input": "bbbbbbbbaaaaaaaaaaaccccccaaaaaaaaaaaaaaccccccccaaaaaaaaabbbbbbccbbbaaaaaabccccccaaaacaaacccccccccccb\n", "output": "10\n" }, { "input": "ccccccccccccccccccccccccccccccccaaaaaaaaaaaaa...
code_contests
python
0
afccf4f9a19a4643f7cb2b46841a94a8
You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to <image>. In one step you can mov...
import re import math import decimal import bisect def read(): return input().strip() n = int(read()) ps = [0 for i in range(1, n+1)] nadd = 10 for x in sorted([int(_) for _ in read().split()]): ps[x-1] = nadd nadd += 10 nadd = 15 for i, p in enumerate(ps): if p == 0: ps[i] = nadd nadd += 10 # print(ps) swap...
python
code_algorithm
[ { "input": "10\n1 2 3 4 5\n", "output": "10\n" }, { "input": "6\n1 2 6\n", "output": "2\n" }, { "input": "10\n9 8 7 6 5\n", "output": "7\n" }, { "input": "100\n41 13 29 11 25 15 6 23 28 50 48 17 3 9 44 24 5 19 34 22 33 32 20 16 35 37 4 10 46 2 39 40 47 49 36 42 1 30 43 21 14 ...
code_contests
python
0.5
4d37cb6d21cd4f6293fa683d1bedf58d
Polycarp has n coins, the value of the i-th coin is a_i. It is guaranteed that all the values are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d). Polycarp wants to know answers on q queries. The j-th query is described as integer number b_j. The answer to the query is the minimum number of...
# @oj: codeforces # @id: hitwanyang # @email: 296866643@qq.com # @date: 2020-10-14 16:44 # @url:https://codeforc.es/contest/1003/problem/D import sys,os from io import BytesIO, IOBase import collections,itertools,bisect,heapq,math,string from decimal import * # region fastio BUFSIZE = 8192 BUFSIZE = 8192 class FastI...
python
code_algorithm
[ { "input": "5 4\n2 4 8 2 4\n8\n5\n14\n10\n", "output": "1\n-1\n3\n2\n" }, { "input": "1 10\n8\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n1\n-1\n-1\n" }, { "input": "1 10\n4\n1\n2\n3\n4\n5\n6\n7\n8\n9\n16\n", "output": "-1\n-1\n-1\n1\n-1\n-1\n-1\n-1\n-1\...
code_contests
python
0.4
7193468c361076f34d815dacacb28c00
You have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the l...
t = int(input()) tests = [] for i in range(t): length = int(input()) tests.append(input()) def solve(s): streak1 = 0 streak2 = 0 for i in range(len(s)): if s[i] == "<": streak1 +=1 else: break for i in range(len(s)): if s[-i-1] == ">": ...
python
code_algorithm
[ { "input": "3\n2\n&lt;&gt;\n3\n&gt;&lt;&lt;\n1\n&gt;\n", "output": "0\n0\n0\n" }, { "input": "1\n9\n>>>>>>>><\n", "output": "0\n" }, { "input": "13\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n1\n>\n", "output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n" ...
code_contests
python
0
b52b25f748519ae107d8650ae97f27cc
There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swo...
n= int(input()) s = list(map(int,input().split())) s.sort() maxm = s[n-1] ans = 0 def computeGCD(x, y): while(y): x, y = y, x % y return x a = maxm-s[0] for i in range(1,n-1): a = computeGCD(a,maxm-s[i]) for i in range(0,n-1): ans += maxm - s[i] print(ans//a,a)
python
code_algorithm
[ { "input": "2\n2 9\n", "output": "1 7\n" }, { "input": "3\n3 12 6\n", "output": "5 3\n" }, { "input": "7\n2 1000000000 4 6 8 4 2\n", "output": "2999999987 2\n" }, { "input": "6\n13 52 0 13 26 52\n", "output": "12 13\n" }, { "input": "10\n100000000 200000000 300000...
code_contests
python
1
08a50eab51107db49012aaaf35c92a34
Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and one stick. Each tool can be sold for exactly one emerald. How many...
import math t=int(input()) for i in range(t): a,b=map(int,input().split()) m=min(a,b,(a+b)/3) print(math.floor(m))
python
code_algorithm
[ { "input": "4\n4 4\n1000000000 0\n7 15\n8 7\n", "output": "2\n0\n7\n5\n" }, { "input": "1\n656 656\n", "output": "437\n" }, { "input": "1\n666 666\n", "output": "444\n" }, { "input": "2\n7 4\n1 5\n", "output": "3\n1\n" }, { "input": "1\n33993 5\n", "output": "...
code_contests
python
0.9
b8b09c2039ef818ff11b86db3bf1012e
Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number...
n = int(input()) r = lambda : list(map(int, input().split())) arr = [] for i in range(n): a = r() arr.append(a) row = [sum(i) for i in arr] col = [] for i in range(n): c = 0 for j in range(n): c+=arr[j][i] col.append(c) ans = 0 for i in range(n): for j in range(n): if row[i] < col[j...
python
code_algorithm
[ { "input": "1\n1\n", "output": "0\n" }, { "input": "2\n1 2\n3 4\n", "output": "2\n" }, { "input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n", "output": "6\n" }, { "input": "9\n53 80 94 41 58 49 88 24 42\n85 11 32 64 40 56 63 95 73\n17 85 60 41 13 71 54 67 87\n38 14 21 81 66 59...
code_contests
python
0.9
88077015b9c347c80a1bc37000f6869d
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequenc...
n = int(input()) a = [int(t) for t in input().split()] c = 0 for i in range(n - 1): if a[i] > 0: c += a[i] print(c) j = 0 while 2 ** j + i < n: j += 1 a[2 ** (j - 1) + i] += a[i] a[i] = 0 else: print(c)
python
code_algorithm
[ { "input": "8\n1 2 3 4 5 6 7 8\n", "output": "1\n3\n6\n10\n16\n24\n40\n" }, { "input": "4\n1 0 1 2\n", "output": "1\n1\n3\n" }, { "input": "80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 73 9 90 25 19 26 15 12 29 33 19 85 92 91 66 83 39 100 53 20 99 11 81 26 41 36 51 21 72 28 100 34 3 2...
code_contests
python
0.2
043f64ecc6672429ce73691532d7cb26
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on n wooden ...
k = int(input()) lo=ro=rc=lc=0 for _ in range(k): n , m = map(int,input().split()) if(n==0): lo+=1 else: lc=lc+1 if(m==0): ro+=1 else : rc=rc+1 print(min(lo,lc)+min(ro,rc))
python
code_algorithm
[ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1\n", "output": "3\n" }, { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0\n", "output": "7\n" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1\n", "output": "6\n" }, { "input": "2\n0 0\n0 0\n", "output": "0\n" }, { ...
code_contests
python
0.9
2bacf8b7f1c4b3d874f27f3c8caf42e7
There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step. You're given the initial arrangeme...
n, t = int(input()), list(map(int, input().split())) p, s, r = [0] * n, [0] * n, t[0] for i in range(n - 1): j = i + 1 x = t[j] if x > r: r = x else: while t[i] < x: s[j], i = max(s[j], s[i]), p[i] p[j] = i s[j] += 1 print(max(s)) # Made By Mostafa_Khaled
python
code_algorithm
[ { "input": "6\n1 2 3 4 5 6\n", "output": "0\n" }, { "input": "10\n10 9 7 8 6 5 3 4 2 1\n", "output": "2\n" }, { "input": "2\n1 2\n", "output": "0\n" }, { "input": "100\n61 96 25 10 50 71 38 77 76 75 59 100 89 66 6 99 2 13 3 23 91 93 22 92 4 86 90 44 39 31 9 47 28 95 18 54 1 7...
code_contests
python
0.4
d16648603970d0f4c311bc0ec410e99c
A chessboard n × m in size is given. During the zero minute we repaint all the black squares to the 0 color. During the i-th minute we repaint to the i color the initially black squares that have exactly four corner-adjacent squares painted i - 1 (all such squares are repainted simultaneously). This process continues a...
import itertools import math n, m = [int(k) for k in input().split()] x = int(input()) if n-2*(x-1) < 1 or m-2*(x-1) < 1: print(0) elif n-2*(x-1) == 1 or m-2*(x-1) == 1: print((n+m-4*(x-1))//2) else: print(n+m-2 - 4*(x-1))
python
code_algorithm
[ { "input": "1 1\n1\n", "output": "1\n" }, { "input": "3 3\n2\n", "output": "1\n" }, { "input": "3 3\n1\n", "output": "4\n" }, { "input": "2016 4549\n433\n", "output": "4835\n" }, { "input": "5000 1\n3\n", "output": "0\n" }, { "input": "4035 369\n26\n",...
code_contests
python
0
2a0d736e185c39854f07d5f7f1b16d91
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().sp...
python
code_algorithm
[ { "input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n", "output": "400\n" }, { "input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3\n", "output": "40\n" }, { "input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n", "output": "160\n" }, { "input": "1 0\...
code_contests
python
0.2
07d8462047c243442e07264c93533486
You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends. In addition, the fir...
c1,c2,x,y=map(int,input().split()) def fn(val): f=[val//x,val//y] both=val//(x*y) f=[i-both for i in f] oth=val-f[0]-f[1]-both cnt=[c1-f[1],c2-f[0]] if cnt[0]<0:cnt[0]=0 if cnt[1] < 0: cnt[1] = 0 return (sum(cnt)<=oth) l=0;r=int(1e18) while r-l>1: m=(r+l)//2 if fn(m): r=m...
python
code_algorithm
[ { "input": "3 1 2 3\n", "output": "5\n" }, { "input": "1 3 2 3\n", "output": "4\n" }, { "input": "1 999999999 29983 29989\n", "output": "1000033345\n" }, { "input": "9999999 10000 29983 29989\n", "output": "10009999\n" }, { "input": "808351 17767 433 509\n", "...
code_contests
python
0
2115b4932a146c78cf16e22bcce77ce9
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ...
import math #.sqrt def ceil (a, b): return -(-a // b) def answer(r, x, y, xp, yp): d = math.sqrt((xp-x)**2 + (yp-y)**2) num_rs = ceil(d, 2*r) return int(num_rs) def main(): r, x, y, xp, yp = [int(i) for i in input().split()] print(answer(r, x, y, xp, yp)) return main()
python
code_algorithm
[ { "input": "1 1 1 4 4\n", "output": "3\n" }, { "input": "2 0 0 0 4\n", "output": "1\n" }, { "input": "4 5 6 5 6\n", "output": "0\n" }, { "input": "1 100000 100000 100000 -100000\n", "output": "100000\n" }, { "input": "46456 -2621 -23623 -98302 -99305\n", "outp...
code_contests
python
0.5
c4710dd176f3139447812234ab2bf8de
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ...
n, m = [int(x) for x in input().split()] a = [] for i in range(m): a.append([int(x) for x in input().split()][1:]) b = [] curt = 0 for i in a: j = 0 b.append([]) while (j < len(i)) and (i[j] == (j + 1)): j += 1 if j != 0: b[-1] = [j] b[-1] += [1] * (len(i) - j) curt += len(b[...
python
code_algorithm
[ { "input": "3 2\n2 1 2\n1 3\n", "output": "1\n" }, { "input": "7 3\n3 1 3 7\n2 2 5\n2 4 6\n", "output": "10\n" }, { "input": "100 3\n45 1 2 3 4 5 6 7 8 9 19 21 24 27 28 30 34 35 37 39 40 41 42 43 46 47 48 51 52 55 58 59 61 63 64 66 69 71 76 80 85 86 88 89 94 99\n26 10 11 15 18 23 29 31 3...
code_contests
python
0
79bf7f500f21798b22d8d1485fcd0f54
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a...
t=list(map(int,input().split())) w=list(map(int,input().split())) q,z=map(int,input().split()) c=0 v=0 for i in range(500,3000,500): x=(1-(t[v]/250))*i-50*w[v] a=max(0.3*i,x) c=c+a v=v+1 f=q*100-z*50 dp=c+f print(int(dp))
python
code_algorithm
[ { "input": "20 40 60 80 100\n0 1 2 3 4\n1 0\n", "output": "4900\n" }, { "input": "119 119 119 119 119\n0 0 0 0 0\n10 0\n", "output": "4930\n" }, { "input": "36 102 73 101 19\n5 9 2 2 6\n4 13\n", "output": "4292\n" }, { "input": "119 0 0 0 0\n2 0 0 0 0\n5 5\n", "output": "...
code_contests
python
0.2
1e17c893d4f6d907e30bbf040edd65a9
Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at the last station. Let ρi, j be the minimum number of tickets one needs to buy in order to get from stations i to station j....
n=int(input()) a=list(map(int, input().split())) a=[ai-1 for ai in a] a[n:n] = [n - 1] dp=[0]*n ans=0 i=n-2 nmax=2**17 tree=[[0,0]]*2*nmax; #Build Segment tree j=0 while j<n: tree[nmax + j] = [a[j], j] j=j+1 j=nmax-1 while j>0: tree[j]=max(tree[j*2],tree[j*2+1]) j=j-1 #get max of a interval [lef...
python
code_algorithm
[ { "input": "4\n4 4 4\n", "output": "6\n" }, { "input": "5\n2 3 5 5\n", "output": "17\n" }, { "input": "7\n7 3 4 6 6 7\n", "output": "35\n" }, { "input": "4\n3 3 4\n", "output": "8\n" }, { "input": "6\n3 3 6 6 6\n", "output": "21\n" }, { "input": "5\n4 ...
code_contests
python
0
87ab33121856ba7e691a1a03a11e9661
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most k pebbles in each pocket at the same time....
import math n,k = map(int,input().split()) stones = list(map(int, input().split())) days = 0 for i in range(n): days += math.ceil(stones[i]/k) print(math.ceil(days/2))
python
code_algorithm
[ { "input": "5 4\n3 1 8 9 7\n", "output": "5\n" }, { "input": "3 2\n2 3 4\n", "output": "3\n" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1\n", "output": "5\n" }, { "input": "3 57\n78 165 54\n", "output": "3\n" }, { "input": "1 1\n10000\n", "output": "5000\n" }, ...
code_contests
python
0.7
d79bcedf33695f73e4e6bd5b20c3b8ce
The year of 2012 is coming... According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us...
# -*- coding: utf-8 -*- """ Created on Fri Nov 1 14:28:37 2019 @author: PC-4 """ from itertools import combinations, product Teams = [[1, 1, 5], [1, 2, 4], [1, 3, 3], [2, 2, 3]] Names = {} Names["Anka"] = 0 Names["Chapay"] = 1 Names["Cleo"] = 2 Names["Dracul"] = 3 Names["Hexadecimal"] = 4...
python
code_algorithm
[ { "input": "3\nTroll likes Dracul\nDracul likes Anka\nSnowy likes Hexadecimal\n210 200 180\n", "output": "30 3\n" }, { "input": "2\nAnka likes Chapay\nChapay likes Anka\n10000 50 50\n", "output": "1950 2\n" }, { "input": "0\n2000000000 2000000000 1\n", "output": "666666665 0\n" }, ...
code_contests
python
0.3
13f1e81a11ccd1ab31de3ec406cb5846
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 millis...
s, v1, v2, t1, t2 = list(map(int, input().split())) a = 2*t1 + s*v1 b = 2*t2 + s*v2 if a > b: print("Second") elif a < b: print("First") else: print("Friendship")
python
code_algorithm
[ { "input": "4 5 3 1 5\n", "output": "Friendship\n" }, { "input": "5 1 2 1 2\n", "output": "First\n" }, { "input": "3 3 1 1 1\n", "output": "Second\n" }, { "input": "2 313 856 964 421\n", "output": "Friendship\n" }, { "input": "61 464 623 89 548\n", "output": "...
code_contests
python
0.8
98601dceb0028d8d0c970e94416c1398
Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below...
types = {'void':'void', 'errtype':'errtype'} def getRealType(type_expr): expr_type = type_expr.strip('&*') full_type_name = type_expr.replace(expr_type, types.get(expr_type, "errtype")) base_type = full_type_name.strip('&*') if base_type == "void": addr_count = full_type_name.count('*') deref_c...
python
code_algorithm
[ { "input": "17\ntypedef void* b\ntypedef b* c\ntypeof b\ntypeof c\ntypedef &amp;b b\ntypeof b\ntypeof c\ntypedef &amp;&amp;b* c\ntypeof c\ntypedef &amp;b* c\ntypeof c\ntypedef &amp;void b\ntypeof b\ntypedef b******* c\ntypeof c\ntypedef &amp;&amp;b* c\ntypeof c\n", "output": "void*\nvoid**\nerrtype\nvoid**\...
code_contests
python
0.1
170d63d000456c767e682b013c074005
Let's denote a function <image> You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. Input The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a. The second line contains n integers a1, a2, ..., ...
from sys import stdin, stdout n = int(stdin.readline()) a = [int(i) for i in stdin.readline().split()] d = dict() ans, sm = 0, 0 for i in range(n): if a[i] not in d.keys(): d[a[i]] = 0 d[a[i]] += 1 ans += i * a[i] - sm if (a[i] + 1) in d.keys(): ans += 1 * d[a[i] + 1] if (a[i] - 1) i...
python
code_algorithm
[ { "input": "4\n6 6 5 5\n", "output": "0" }, { "input": "5\n1 2 3 1 3\n", "output": "4" }, { "input": "4\n6 6 4 4\n", "output": "-8" }, { "input": "100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788...
code_contests
python
0
e262ab32d5ab40e2b051a12279826e7e
Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A f...
def dfs(v, comp): used[v] = comp for u in graph[v]: if not used[u]: dfs(u, comp) n, m = map(int, input().split()) graph = [[] for i in range(n)] for i in range(m): v, u = map(int, input().split()) graph[v - 1].append(u - 1) graph[u - 1].append(v - 1) used = [0] * n ncomp = 0 fo...
python
code_algorithm
[ { "input": "3 2\n1 2\n2 3\n", "output": "YES\n1\n1 3\n" }, { "input": "42 28\n7 19\n15 24\n3 42\n18 5\n32 27\n26 20\n40 30\n35 2\n14 8\n22 10\n36 4\n16 14\n21 29\n37 40\n2 12\n30 21\n19 17\n39 34\n31 28\n20 3\n4 33\n11 42\n26 21\n9 10\n4 32\n6 1\n1 14\n14 12\n", "output": "NO\n" }, { "in...
code_contests
python
0
e723cf1f41573b81a3aabfebcbb4d521
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages. There are n stages available. The rock...
n,k = list(map(int,input().split())) data = sorted(list(input())) data = list(map(lambda x:ord(x)-ord('a')+1,data)) result = 0 used = 0 idx =0 prev = -2 # print(data) for d in data: if d > prev+1: result+= d prev = d used += 1 if used == k: break if used < k: print(-...
python
code_algorithm
[ { "input": "7 4\nproblem\n", "output": "34\n" }, { "input": "2 2\nab\n", "output": "-1\n" }, { "input": "5 3\nxyabd\n", "output": "29\n" }, { "input": "12 1\nabaabbaaabbb\n", "output": "1\n" }, { "input": "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n...
code_contests
python
0.5
bc8d4cae6039a0521a24b68e2f148e81
Vasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized n regular customers, the i-th of which comes after t_{i} minutes after the beginning of the day, and his service consumes l_{i} minutes. It is guaranteed that no customer will arrive while Vasya is...
n,l,a = map(int,input().split()) b =[] for i in range(n): b.append([int(e) for e in input().split()]) ans = 0 for i in range(n-1): ans += (b[i+1][0] - b[i][1] - b[i][0])//a if(n > 0): ans += b[0][0]//a ans += (l - b[n-1][1] - b[n-1][0])//a else: ans += l//a print(ans)
python
code_algorithm
[ { "input": "2 11 3\n0 1\n1 1\n", "output": "3\n" }, { "input": "0 5 2\n", "output": "2\n" }, { "input": "1 3 2\n1 2\n", "output": "0\n" }, { "input": "0 1 1\n", "output": "1\n" }, { "input": "1 5 3\n3 1\n", "output": "1\n" }, { "input": "0 1000000000 1...
code_contests
python
0.7
23ef561789f11ae7305803e2740beec7
All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the respon...
__author__ = 'Darren' def solve(): n, k = map(int, input().split()) group = map(int, input().split()) available = [[k, 1][:] for _ in range(k+1)] center = (k + 1) // 2 for m in group: closest, best_row, best_col = 10000, -1, -1 for row in range(1, k+1): col = 0 ...
python
code_algorithm
[ { "input": "4 3\n1 2 3 1\n", "output": "2 2 2\n1 1 2\n3 1 3\n2 1 1\n" }, { "input": "2 1\n1 1\n", "output": "1 1 1\n-1\n" }, { "input": "2 3\n3 3\n", "output": "2 1 3\n1 1 3\n" }, { "input": "80 29\n19 15 15 27 2 25 2 5 29 11 6 4 20 11 27 16 6 6 10 2 5 12 8 23 11 7 11 13 19 2...
code_contests
python
0.4
f1aef2dfdde62974df1766ac27e989a9
Everybody knows that the m-coder Tournament will happen soon. m schools participate in the tournament, and only one student from each school participates. There are a total of n students in those schools. Before the tournament, all students put their names and the names of their schools into the Technogoblet of Fire. ...
n,m,k=map(int,input().split()) p=list(map(int,input().split())) s=list(map(int,input().split())) c=set(map(int,input().split())) d={} for i in range(n): if s[i] not in d: d[s[i]]=[-1] if p[i]>d[s[i]][0]: d[s[i]]=(p[i],i) st=set() for i in d: st.add(d[i][1]+1) #print(c,st) c=c.difference(st) ...
python
code_algorithm
[ { "input": "8 4 4\n1 2 3 4 5 6 7 8\n4 3 2 1 4 3 2 1\n3 4 5 6\n", "output": "2\n" }, { "input": "7 3 1\n1 5 3 4 6 7 2\n1 3 1 2 1 2 3\n3\n", "output": "1\n" }, { "input": "2 1 1\n1 2\n1 1\n1\n", "output": "1\n" }, { "input": "2 1 1\n1 2\n1 1\n2\n", "output": "0\n" }, { ...
code_contests
python
0.8
7498db4523629d099543bc46d180784e
The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequence of integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the show, the episode of which will be shown in i-th day. The...
x = int(input()) for i in range(x): n, k, d = map(int, input().split(' ')) l = map(int, input().split(' ')) l = list(l) ar = [] for j in range(n-d+1): ar.append(len(set(l[j:(j+d)]))) print(min(ar))
python
code_algorithm
[ { "input": "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "output": "2\n1\n4\n5\n" }, { "input": "1\n100 20 1\n10 17 9 8 11 8 8 3 7 20 11 10 7 7 2 13 10 7 7 10 7 8 4 17 20 9 5 18 12 8 3 5 19 1 18 14 9 11 12 11 11 12 12 9 13 8 20 3 8 1 15...
code_contests
python
1
8faae6e617348fd56aed5a26214976a3
You are given a board of size n × n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure. In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i, j) you can move...
I = input for _ in range(int(I())): n = int(I())+1 s = 0 for i in range(1,n//2): s += 8*i*i print(s)
python
code_algorithm
[ { "input": "3\n1\n5\n499993\n", "output": "0\n40\n41664916690999888\n" }, { "input": "3\n5\n3005\n3005\n", "output": "40\n9045074040\n9045074040\n" }, { "input": "1\n69791\n", "output": "113312287936960\n" }, { "input": "1\n214541\n", "output": "3291619655775960\n" }, ...
code_contests
python
0
9884f87a4188cd662887f5b0488516f9
Alica and Bob are playing a game. Initially they have a binary string s consisting of only characters 0 and 1. Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent char...
from sys import stdin,stdout t=int(stdin.readline().strip()) for _ in range(t): s=stdin.readline().strip() stdout.write(("NET","DA")[min(s.count('0'),s.count('1')) % 2]+"\n")
python
code_algorithm
[ { "input": "3\n01\n1111\n0011\n", "output": "DA\nNET\nNET\n" }, { "input": "1\n00000000000\n", "output": "NET\n" }, { "input": "1\n111111111111111110000000000000000\n", "output": "NET\n" }, { "input": "1\n11111111111\n", "output": "NET\n" }, { "input": "1\n1\n", ...
code_contests
python
0
ff6c9d109e13c3a6ba8235b4a94b4e6d
The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princess immediately. Looks like there's no chance to success, but the princess ...
vp = int(input()) vd = int(input()) t = int(input()) f = int(input()) c = int(input()) distance = t * vp time = t treasure = 0 if vp == vd: if t == 0: print(1) else: print(0) elif vp > vd: print(0) else: while distance < c: timeadd = distance/(vd - vp) distance += vp * ti...
python
code_algorithm
[ { "input": "1\n2\n1\n1\n10\n", "output": "2\n" }, { "input": "1\n2\n1\n1\n8\n", "output": "1\n" }, { "input": "71\n19\n2\n10\n645\n", "output": "0\n" }, { "input": "6\n24\n9\n8\n628\n", "output": "3\n" }, { "input": "26\n36\n4\n7\n318\n", "output": "0\n" }, ...
code_contests
python
0
e2aa98cc5b6f7b5beb5a3dbb6558c6e7
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store: * The store has an infinite number of items of every product. * All products have the same price: 2 rubles per item. * ...
n = int(input()) arr = [] for _ in range(n): arr.append(list(map(int, input().split()))) arr.sort(key=lambda x:x[1]) # print(arr) lo, hi = 0, n-1 ans, counter = 0, 0 while lo<=hi: # print(lo, hi, counter) to_buy, req = arr[lo] if counter>=req or to_buy==0: counter += to_buy ans += to_bu...
python
code_algorithm
[ { "input": "5\n2 7\n2 8\n1 2\n2 4\n1 8\n", "output": "12\n" }, { "input": "3\n3 4\n1 3\n1 5\n", "output": "8\n" }, { "input": "8\n1 8\n1 6\n1 5\n1 3\n1 3\n1 8\n1 7\n1 3\n", "output": "11\n" }, { "input": "4\n4 1\n2 2\n1 6\n1 2\n", "output": "9\n" }, { "input": "7\...
code_contests
python
0
210c60a540e404aa67dc364e05856620
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two give...
n, k = map(int, input().split()) table =[] table_dic = dict() for i in range(n): p, t = map(int, input().split()) table_dic[i + 1] = [p,t] table.append([p, 50 - t]) ranking = sorted(table, key=lambda table: (table[0], table[1]), reverse=True) for i in range(n): ranking[i][1] = 50 - ranking[i][1] coun...
python
code_algorithm
[ { "input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n", "output": "4\n" }, { "input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "output": "3\n" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n...
code_contests
python
0.2
eba9115079535d72033b24fdaf44e820
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been pa...
n, k = 0, int(input()) p = [['0'] * 100 for i in range(100)] while k: for i in range(n): if i > k: break p[n][i] = p[i][n] = '1' k -= i n += 1 print(n) for i in range(n): print(''.join(p[i][:n]))
python
code_algorithm
[ { "input": "10\n", "output": "5\n01111\n10111\n11011\n11101\n11110\n" }, { "input": "1\n", "output": "3\n011\n101\n110\n" }, { "input": "99016\n", "output": "87\n011111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n101111111111111111111111111111111...
code_contests
python
0
7196c76cdd45398e44079caa2dc398c1
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. h...
import sys input = lambda: sys.stdin.readline() n = int(input()) S = 0 ans = '' for i in range(n): a, g = [int(x) for x in input().split(' ')] if abs(S + a) <= 500: S += a ans += 'A' else: S -= g ans += 'G' print(ans)
python
code_algorithm
[ { "input": "2\n1 999\n999 1\n", "output": "AG\n" }, { "input": "3\n400 600\n400 600\n400 600\n", "output": "AGA\n" }, { "input": "1\n500 500\n", "output": "A\n" }, { "input": "2\n500 500\n500 500\n", "output": "AG\n" }, { "input": "1\n1 999\n", "output": "A\n"...
code_contests
python
0.2
b30c9807772a1bff49a00302a05df104
Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the n coders on the meeting said: 'I know for sure that either x or y did it!' The head of the company d...
from collections import defaultdict from bisect import bisect_left as lower import sys input = sys.stdin.readline def put(): return map(int, input().split()) try: n,m = put() cnt, mp, ans = [0]*n, defaultdict(), [0]*n for _ in range(n): x,y = put() x,y = x-1,y-1 key = (min(x,y),...
python
code_algorithm
[ { "input": "8 6\n5 6\n5 7\n5 8\n6 2\n2 1\n7 3\n1 3\n1 4\n", "output": "1\n" }, { "input": "4 2\n2 3\n1 4\n1 4\n2 1\n", "output": "6\n" }, { "input": "10 3\n6 3\n6 10\n2 5\n5 7\n6 2\n9 2\n8 1\n10 5\n5 10\n7 6\n", "output": "34\n" }, { "input": "4 2\n3 4\n4 3\n4 2\n3 1\n", ...
code_contests
python
0.2
55e363b3395d789a30dc27c47f026b5d
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix...
s = input() t = input() ind = 0 for x in t: ind = s.find(x, ind) + 1 if ind <= 0: break if ind > 0 or len(t) == 0: print('automaton') else: ss = list(s) tt = list(t) bb1 = True if len(ss) >= len(tt): for x in tt: bb = False for y in ss: ...
python
code_algorithm
[ { "input": "need\ntree\n", "output": "need tree\n" }, { "input": "automaton\ntomat\n", "output": "automaton\n" }, { "input": "array\narary\n", "output": "array\n" }, { "input": "both\nhot\n", "output": "both\n" }, { "input": "hxsvvydmzhxrswvhkvrbjrfqkazbkjabnrdghp...
code_contests
python
0.4
a1e270e3dcfc0ff4fd338e2ce6e959f9
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to...
n, x, y = map(int, input().split()) for _ in range(n): a = int(input()) c1, c2 = ((a + 1) * x // (x + y)) / x, ((a + 1) * y // (x + y)) / y if c1 == c2: print('Both') elif c1 > c2: print('Vanya') else: print('Vova')
python
code_algorithm
[ { "input": "2 1 1\n1\n2\n", "output": "Both\nBoth\n" }, { "input": "4 3 2\n1\n2\n3\n4\n", "output": "Vanya\nVova\nVanya\nBoth\n" }, { "input": "10 13 27\n3\n21\n23\n17\n15\n23\n16\n7\n24\n20\n", "output": "Vanya\nVanya\nVova\nVova\nVanya\nVova\nVova\nVova\nVanya\nVova\n" }, { ...
code_contests
python
0
8525bd0f5a192a4cbd463fb201a51a0f
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an. While Vasya was walking, his little brother Stepan played with Vasya's cubes and chan...
n,l,r = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) if(a[:l - 1] == b[:l - 1] and a[r:] == b[r:]): print("TRUTH") else: print("LIE")
python
code_algorithm
[ { "input": "4 2 4\n1 1 1 1\n1 1 1 1\n", "output": "TRUTH\n" }, { "input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1\n", "output": "TRUTH\n" }, { "input": "3 1 2\n1 2 3\n3 1 2\n", "output": "LIE\n" }, { "input": "5 1 3\n2 2 2 1 2\n2 2 2 1 2\n", "output": "TRUTH\n" }, { "input":...
code_contests
python
1
482cbe03fa19ed7dd845e997349ac876
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is considered lucky if the sum of first three digits equals to the sum of las...
def main(): s = input() print(solver(s)) def solver(s): L1 = [int(x) for x in s[0:3]] L2 = [int(x) for x in s[3:6]] diff = sum(L2) - sum(L1) if diff == 0: return 0 elif diff < 0: L1, L2 = L2, L1 diff = -diff changes = [9 - L1[i] for i in range(3)] + [L2[i] - 0 for i in range(3)] changes.sort(reverse =...
python
code_algorithm
[ { "input": "111000\n", "output": "1\n" }, { "input": "000000\n", "output": "0\n" }, { "input": "123456\n", "output": "2\n" }, { "input": "191578\n", "output": "2\n" }, { "input": "877542\n", "output": "2\n" }, { "input": "977330\n", "output": "2\n"...
code_contests
python
0
59a2476b897553251ccbe3ec1527b782
You can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you...
from heapq import * N = int(input()) price = [int(i) for i in input().split()] total = 0 inf = (10**6) + 1 h = [inf] #Assume we bought and sold optimally for the first k prices. #We adjust our answer for the (k+1)th price that comes up. for p in price: if p > h[0]: total += (p - heappop(h)) #We p...
python
code_algorithm
[ { "input": "9\n10 5 4 7 9 12 6 2 10\n", "output": "20\n" }, { "input": "20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4\n", "output": "41\n" }, { "input": "100\n411 642 560 340 276 440 515 519 182 314 35 227 390 136 97 5 502 584 567 79 543 444 413 463 455 316 545 329 437 443 9 435 291 384 32...
code_contests
python
0
5c55d79e471054a5b62c0645ba09927e
Vasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in this cell (more formally, how many grams of mushrooms grow in this cell each minute). Vasya spends...
n = int(input()) u1 = list(map(int, input().split())) u2 = list(map(int, input().split())) a1 = u1[:n] a2 = u2[:n] for i in range(1, n): a1[i] += a1[i - 1] a2[i] += a2[i - 1] q1 = [0] * (2 * n) q2 = [0] * (2 * n) for i in range(1, n): q1[i] = u1[i] * (i) + q1[i - 1] q2[i] = u2[i] * (i) + q2[i - 1] for i...
python
code_algorithm
[ { "input": "3\n1 2 3\n6 5 4\n", "output": "70\n" }, { "input": "3\n1 1000 10000\n10 100 100000\n", "output": "543210\n" }, { "input": "6\n12 8 12 17 20 5\n17 4 8 8 8 4\n", "output": "705\n" }, { "input": "6\n4 1 12 9 3 11\n12 20 19 12 19 11\n", "output": "917\n" }, { ...
code_contests
python
0
744ae33c115c70dd917b868aec1add27
The Fair Nut found a string s. The string consists of lowercase Latin letters. The Nut is a curious guy, so he wants to find the number of strictly increasing sequences p_1, p_2, …, p_k, such that: 1. For each i (1 ≤ i ≤ k), s_{p_i} = 'a'. 2. For each i (1 ≤ i < k), there is such j that p_i < j < p_{i + 1} and s...
s=input() sss='' for i in s: if i in ['a','b']: sss+=i from itertools import groupby xxx=[''.join(g) for _, g in groupby(sss)] xxx=[len(i)+1 for i in xxx if 'a' in i] ans=1 if len(xxx)==1: print((xxx[0]-1)%1000000007) else: for i in xxx: ans*=i print((ans-1)%1000000007)
python
code_algorithm
[ { "input": "agaa\n", "output": "3\n" }, { "input": "baaaa\n", "output": "4\n" }, { "input": "abbaa\n", "output": "5\n" }, { "input": "aaaaabb\n", "output": "5\n" }, { "input": "aabaaaa\n", "output": "14\n" }, { "input": "babbabaabbbbabwbvbhbbbaaabbabbb...
code_contests
python
0
882c318bace45523e58f9028249935b4
On a random day, Neko found n treasure chests and m keys. The i-th chest has an integer a_i written on it and the j-th key has an integer b_j on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible. The j-th key can be used to unlock the ...
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) aeven = 0 aodd = 0 beven = 0 bodd = 0 for i in range(n): if a[i] % 2 == 0: aeven += 1 else: aodd += 1 for i in range(m): if b[i] % 2 == 0: beven += 1 else: bodd += 1 ...
python
code_algorithm
[ { "input": "5 1\n2 4 6 8 10\n5\n", "output": "1\n" }, { "input": "1 4\n10\n20 30 40 50\n", "output": "0\n" }, { "input": "5 4\n9 14 6 2 11\n8 4 7 20\n", "output": "3\n" }, { "input": "4 1\n3 5 7 8\n2\n", "output": "1\n" }, { "input": "5 1\n2 2 2 3 3\n3\n", "ou...
code_contests
python
1
f1f14bc602cb2f7d6d9da5c4ad841cbd
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed o...
from collections import deque n,m,k=list(map(int,input().split())) arr=list(map(int,input().split())) d=deque() for i in arr: d.append(i) chances=curr=tot=0 # print("WORKING") while tot<m: # print("S") if (d[0]-curr)%k==0: p=(d[0]-curr)//k else:p=((d[0]-curr)//k)+1 temp=curr while tot<m...
python
code_algorithm
[ { "input": "13 4 5\n7 8 9 10\n", "output": "1\n" }, { "input": "10 4 5\n3 5 7 10\n", "output": "3\n" }, { "input": "10 5 5\n2 3 4 5 6\n", "output": "2\n" }, { "input": "1 1 1\n1\n", "output": "1\n" }, { "input": "1000000000000000000 10 68\n9818112234872670 2332452...
code_contests
python
0
f905e505c1508f529048de622c3bf9df
Dawid has four bags of candies. The i-th of them contains a_i candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total? Note, that you can't keep bags for yourself or thro...
list1 = list(map(int, input().split())) list1.sort() if list1[0] + list1[3] == list1[1] + list1[2]: print("YES") elif list1[0] + list1[2] +list1[1] == list1[3]: print("YES") else: print("NO")
python
code_algorithm
[ { "input": "1 7 11 5\n", "output": "YES\n" }, { "input": "7 3 2 5\n", "output": "NO\n" }, { "input": "44 58 90 53\n", "output": "NO\n" }, { "input": "20 14 37 71\n", "output": "YES\n" }, { "input": "4 2 4 2\n", "output": "YES\n" }, { "input": "1 2 5 5\...
code_contests
python
0.1
80b0623685a5c1d5696f1ae45b1023bd
VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications. The latest A/B test suggests that users are reading recommended publications more actively ...
# Код программы написал на языке Python 3 import sys from heapq import heappush, heappop def main(): n = int(sys.stdin.readline()) h = sorted(list(zip([int(i) for i in sys.stdin.readline().split()], [int(i) for i in sys.stdin.readline().split()]))) z, w, o, res = [], 0, 0, 0 while o < n: ...
python
code_algorithm
[ { "input": "5\n3 7 9 7 8\n5 2 5 7 5\n", "output": "6\n" }, { "input": "5\n1 2 3 4 5\n1 1 1 1 1\n", "output": "0\n" }, { "input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n100000 100000 100000 100000 100000\n", "output": "1000000\n" }, { "input": "10\n14 31 5...
code_contests
python
0
406f59ca0c42acfab93e8a30a04271eb
Alice and Bob are playing yet another card game. This time the rules are the following. There are n cards lying in a row in front of them. The i-th card has value a_i. First, Alice chooses a non-empty consecutive segment of cards [l; r] (l ≤ r). After that Bob removes a single card j from that segment (l ≤ j ≤ r). Th...
import math import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(31): s = 0 for j in a: if j <= i: s = max(0, s + j) else: s = 0 ans = max(ans, s - i) print(ans)
python
code_algorithm
[ { "input": "3\n-10 6 -15\n", "output": "0\n" }, { "input": "8\n5 2 5 3 -30 -30 6 9\n", "output": "10\n" }, { "input": "5\n5 -2 10 -1 4\n", "output": "6\n" }, { "input": "10\n-3 4 -4 1 1 -4 -5 3 -4 -2\n", "output": "1\n" }, { "input": "10\n8 9 -10 -10 -4 -3 5 9 -9 ...
code_contests
python
0
14460e3f1d903100b118e0acc276edbc
Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on t...
n = int(input()) a = list(map(int,input().split())) m = int(input()) b = list(map(int,input().split())) count = [] for i in range(n): for j in range(m): if((b[j]/a[i])==int(b[j]/a[i])): count.append(int(b[j]/a[i])) o = max(count) print(count.count(o))
python
code_algorithm
[ { "input": "4\n1 2 3 4\n5\n10 11 12 13 14\n", "output": "1\n" }, { "input": "2\n4 5\n3\n12 13 15\n", "output": "2\n" }, { "input": "1\n1\n2\n1 2\n", "output": "1\n" }, { "input": "50\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 ...
code_contests
python
0.9
fa51ba373dbf9aa051f3cd1c3030057b
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
def werify_message(words, message): true_message = ''.join(['<3', '<3'.join(words), '<3']) # index in true_message i = 0 for litera in message: if len(true_message) != i: if litera == true_message[i]: i += 1 else: # Дошли до конца исходного сообще...
python
code_algorithm
[ { "input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n&lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3\n", "output": "no\n" }, { "input": "3\ni\nlove\nyou\n&lt;3i&lt;3love&lt;23you&lt;3\n", "output": "no\n" }, { "input": "3\ni\nlove\nyou\n<3i<3love<23you<3ww\n",...
code_contests
python
0
dc0a13c08e03549d7528dc5c7dac97f0
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ...
n = int(input("")) cards=list(map(int,input().split())) sereja = 0 dima = 0 temp = 0 turn = 1 while cards != []: nMax=max(cards[0],cards[-1]) if turn==1: temp = sereja + nMax sereja+=nMax turn=2 else: temp = dima + nMax dima+=nMax turn=1 cards.remo...
python
code_algorithm
[ { "input": "7\n1 2 3 4 5 6 7\n", "output": "16 12\n" }, { "input": "4\n4 1 2 10\n", "output": "12 5\n" }, { "input": "1\n1\n", "output": "1 0\n" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 3...
code_contests
python
0.1
49e2a9295e66cbf3dfdf869e8212c770
We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba". Given a string, you have to find two values: 1. the number of good substrings of even length; 2. the number of good ...
s = input() blocks = [] evenA = [0] oddA = [0] evenB = [0] oddB = [0] even = True for x in s: evenA.append(evenA[-1]) oddA.append(oddA[-1]) evenB.append(evenB[-1]) oddB.append(oddB[-1]) if x == 'a': if even: evenA[-1] += 1 else: oddA[-1] += 1 else: ...
python
code_algorithm
[ { "input": "babaa\n", "output": "2 7\n" }, { "input": "bb\n", "output": "1 2\n" }, { "input": "baab\n", "output": "2 4\n" }, { "input": "babb\n", "output": "2 5\n" }, { "input": "bbabaaabaaaabaabbababbbabababaabaaaaabbaabbbbbaababaabbbaabaabaaaababaabaabbabaaabaab...
code_contests
python
0.5
5f4e83de39e4dfbb8c3b33b743f99c25
Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has n regiments, each consisting of 4 moles. Initially, each mole i (1 ≤ i ≤ 4n) is placed at some position (xi, yi) in the Cartesian plane. Captain Marmot wants to move some moles to make the regiments com...
#a+b-y #x+b-a #1 - import sys input=sys.stdin.readline def distSq(p1,p2): return (p1[0]-p2[0])*(p1[0]-p2[0])+(p1[1]-p2[1])*(p1[1]-p2[1]) def isSquare(p1, p2, p3, p4): d2 = distSq(p1, p2) # from p1 to p2 d3 = distSq(p1, p3) # from p1 to p3 d4 = distSq(p1, p4) # from p1 to p4 # If length...
python
code_algorithm
[ { "input": "4\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-2 1 0 0\n-1 1 0 0\n1 -1 0 0\n1 1 0 0\n-1 1 0 0\n-1 1 0 0\n-1 1 0 0\n2 2 0 1\n-1 0 0 -2\n3 0 0 -2\n-1 1 -2 0\n", "output": "1\n-1\n3\n3\n" }, { "input": "1\n1 0 2 0\n-1 0 -2 0\n0 1 0 2\n0 -1 0 -2\n", "output": "0\n" }, { "inp...
code_contests
python
0
9e0bb7f56c38321e479755646c97b805
Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so that the result was a correct arithmetic expression; formally, no ...
n, k = map(int, input().split()) t = list(map(int, input())) p, d = 1, 10 ** 9 + 7 s, f = 0, [1] * n for i in range(2, n): f[i] = (i * f[i - 1]) % d c = lambda a, b: 0 if a > b else (f[b] * pow(f[a] * f[b - a], d - 2, d)) % d if k: u = [0] * (n + 1) p = [1] * (n + 1) for i in range(n): u[i...
python
code_algorithm
[ { "input": "3 1\n108\n", "output": "27\n" }, { "input": "3 2\n108\n", "output": "9\n" }, { "input": "57 13\n177946005798852216692528643323484389368821547834013121843\n", "output": "734611754\n" }, { "input": "16 15\n8086179429588546\n", "output": "90\n" }, { "inpu...
code_contests
python
0
90cb0c549f1651d0f653e7c1d8dbd4d5
A super computer has been built in the Turtle Academy of Sciences. The computer consists of n·m·k CPUs. The architecture was the paralellepiped of size n × m × k, split into 1 × 1 × 1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbers from the layer nu...
def main(): s = input().split() n, m, k = int(s[0]), int(s[1]), int(s[2]) processor = [] for x in range(n): for y in range(m): s = input() for z in s: processor.append(int(z) == 1) if x < n - 1: emptyLine = input() counter = 0 m...
python
code_algorithm
[ { "input": "1 1 10\n0101010101\n", "output": "0\n" }, { "input": "2 2 3\n000\n000\n\n111\n111\n", "output": "2\n" }, { "input": "3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111\n", "output": "19\n" }, { "input": "1 1 3\n111\n", "output": "1\n" }, { "input":...
code_contests
python
0
d222b94868f2974fc737679b9fbb1c8d
Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage. ...
n = int(input()) print(n // 2 + n % 2)
python
code_algorithm
[ { "input": "1\n", "output": "1\n" }, { "input": "4\n", "output": "2\n" }, { "input": "1000000000\n", "output": "500000000\n" }, { "input": "536870912\n", "output": "268435456\n" }, { "input": "16\n", "output": "8\n" }, { "input": "6\n", "output": "...
code_contests
python
0.7
f9908f6609c1243354bd9f489510d444
There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city. Soon, monsters became hungry and began to eat each other. One monster can eat other monster if its weight is strictly greater than the weight of the monste...
def main(): n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) sum1, sum2 = 0, 0 for i in a: sum1 += i for i in b: sum2 += i # validar que podemos obtener solucion if sum1 != sum2: print('NO') ret...
python
code_algorithm
[ { "input": "5\n1 1 1 3 3\n3\n2 1 6\n", "output": "NO\n" }, { "input": "6\n1 2 2 2 1 2\n2\n5 5\n", "output": "YES\n2 L\n1 R\n2 R\n2 R\n" }, { "input": "5\n1 2 3 4 5\n1\n15\n", "output": "YES\n5 L\n4 L\n3 L\n2 L\n" }, { "input": "3\n2 1 3\n1\n6\n", "output": "YES\n3 L\n2 L\...
code_contests
python
0
19aec0c197f874ec691c45d0679623dc
In Berland each high school student is characterized by academic performance — integer value between 1 and 5. In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known — integer value between 1 and 5. Th...
n = int(input()) linea = list(map(int, input().split())) lineb = list(map(int, input().split())) lines = linea + lineb c1 = lines.count(1) c2 = lines.count(2) c3 = lines.count(3) c4 = lines.count(4) c5 = lines.count(5) cc1 = linea.count(1) cc2 = linea.count(2) cc3 = linea.count(3) cc4 = linea.count(4) cc5 = linea.count...
python
code_algorithm
[ { "input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5\n", "output": "3\n" }, { "input": "4\n5 4 4 4\n5 5 4 5\n", "output": "1\n" }, { "input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n", "output": "4\n" }, { "input": "1\n5\n3\n", "output": "-1\n" }, { "input": "100\n3 4 5 3 5 ...
code_contests
python
0.2
319b2b70ba6d6a51694118ce9a9499c1
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected. You should assign labels to all vertices in such a way that: * Labels form a valid permutation of length n — an integer sequence such that each integ...
#!/usr/local/bin/python3 from collections import defaultdict import heapq num_nodes, num_edges = map(int, input().split()) ins = defaultdict(set) out = defaultdict(int) for _ in range(num_edges): node_out, node_in = map(int, input().split()) ins[node_in].add(node_out) out[node_out] += 1 zeros = [-node ...
python
code_algorithm
[ { "input": "3 3\n1 2\n1 3\n3 2\n", "output": "1 3 2\n" }, { "input": "4 5\n3 1\n4 1\n2 3\n3 4\n2 4\n", "output": "4 1 2 3\n" }, { "input": "5 4\n3 1\n2 1\n2 3\n4 5\n", "output": "3 1 2 4 5\n" }, { "input": "2 1\n2 1\n", "output": "2 1\n" }, { "input": "100 10\n73 ...
code_contests
python
0
ca6fbac70c6f64b0477a0b543e1abccd
You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? Input The first line contains two integers n and m (1 ≤ n, m ≤ 9) — the length...
a,b=map(int,input().split()) s=input().split() x=list(map(int,s)) s=input().split() y=list(map(int,s)) o=10 for i in range(a): for j in range(b): if x[i]==y[j]: if x[i]<o: o=x[i] x1=min(x) y1=min(y) if o<10: print(o) else: print(min(y1,x1)*10+max(x1,y1))
python
code_algorithm
[ { "input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n", "output": "1\n" }, { "input": "2 3\n4 2\n5 7 6\n", "output": "25\n" }, { "input": "4 3\n1 3 5 9\n2 8 9\n", "output": "9\n" }, { "input": "1 2\n5\n2 5\n", "output": "5\n" }, { "input": "2 4\n8 9\n1 2 3 9\n", ...
code_contests
python
0.3
56e49bc6adcc2f679e59fa41ef6d1a6e
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters. <image> Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested th...
n=int(input()) a,b,r=1,2,'' for i in range(1,n+1): if i==a: r+='O';a,b=b,a+b else: r+='o' print(r)
python
code_algorithm
[ { "input": "8\n", "output": "OOOoOooO\n" }, { "input": "15\n", "output": "OOOoOooOooooOoo\n" }, { "input": "381\n", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooo...
code_contests
python
0.9
206cc25a2e3c8c7900126ba445d2389f
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1, 3, 2, 1} is 2. Diame...
n,d = map(int,input().split()) a=list(map(int,input().split())) a.sort(); i=0 cnt=0 cnt1=0 if n==1: print("0") else: for i in range(n): cnt=0 for j in range(i+1,n): d1=a[j]-a[i] if d1>d: break; cnt+=1 if(cnt1<cnt): cnt1=cnt...
python
code_algorithm
[ { "input": "6 3\n1 3 4 6 9 10\n", "output": "3\n" }, { "input": "3 1\n2 1 4\n", "output": "1\n" }, { "input": "3 0\n7 7 7\n", "output": "0\n" }, { "input": "1 100\n22\n", "output": "0\n" }, { "input": "3 2\n1 50 99\n", "output": "2\n" }, { "input": "10...
code_contests
python
1
4b78a93292fbc59136c7be6a04d61cb5
You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume. You have sufficient number of analog computers, each with enough processors for any task. Each computer can execute up to one task at a time, and no more than two tasks total. The first task ca...
# Codeforces Round #488 by NEAR (Div. 2) import collections from functools import cmp_to_key #key=cmp_to_key(lambda x,y: 1 if x not in y else -1 ) import math import sys def getIntList(): return list(map(int, input().split())) import bisect def makePair(z): return [(z[i], z[i+1]) for i in range(0,le...
python
code_algorithm
[ { "input": "6\n8 10 9 9 8 10\n1 1 1 1 1 1\n", "output": "9000\n" }, { "input": "6\n8 10 9 9 8 10\n1 10 5 5 1 10\n", "output": "1160\n" }, { "input": "5\n21581303 73312811 99923326 93114466 53291492\n32 75 75 33 5\n", "output": "1070425495\n" }, { "input": "10\n7 9 8 9 4 8 5 2...
code_contests
python
0
71b5212e05606199c16bcdf17c2fb7ab
Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array. The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0...
n = int(input()) data = input().split() max = 0 for i in range(n): back = max if max<int(data[i]): max=int(data[i]) if i==0 and data[i]!="0": print(1) exit() elif int(data[i])>back+1: print(i+1) exit() if int(data[i])<=back+1: print(-1)
python
code_algorithm
[ { "input": "3\n1 0 1\n", "output": "1\n" }, { "input": "4\n0 1 2 1\n", "output": "-1\n" }, { "input": "4\n0 1 2 239\n", "output": "4\n" }, { "input": "2\n0 1\n", "output": "-1\n" }, { "input": "3\n0 1 1000000000\n", "output": "3\n" }, { "input": "3\n0 ...
code_contests
python
1
bea3702f4ca8b64d851c95726eb7ce9e
You are given an integer number n. The following algorithm is applied to it: 1. if n = 0, then end algorithm; 2. find the smallest prime divisor d of n; 3. subtract d from n and go to step 1. Determine the number of subtrations the algorithm will make. Input The only line contains a single integer n (2 ≤...
from collections import deque as de import math class My_stack(): def __init__(self): self.data = [] def my_push(self, x): return (self.data.append(x)) def my_pop(self): return (self.data.pop()) def my_peak(self): return (self.data[-1]) def my_contains(self, x): ...
python
code_algorithm
[ { "input": "4\n", "output": "2\n" }, { "input": "5\n", "output": "1\n" }, { "input": "9999999999\n", "output": "4999999999\n" }, { "input": "10000000000\n", "output": "5000000000\n" }, { "input": "9999999967\n", "output": "1\n" }, { "input": "2\n", ...
code_contests
python
0
b3c6d8752dd517c3e02dbfe17111e7b5
Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero: <image> Petr called his car dealer, who in...
n = int(input()) a = [0] for _ in range(n): curr = int(input()) mods = [] for o in a: mods.extend([o + curr, o - curr]) a = mods[:] #print(a) print("YES" if any(x%360 == 0 for x in a) else "NO")
python
code_algorithm
[ { "input": "3\n10\n10\n10\n", "output": "NO\n" }, { "input": "3\n120\n120\n120\n", "output": "YES\n" }, { "input": "3\n10\n20\n30\n", "output": "YES\n" }, { "input": "5\n179\n179\n179\n179\n4\n", "output": "YES\n" }, { "input": "5\n179\n170\n160\n111\n100\n", ...
code_contests
python
0.7
ff6b0220add66602900a0df63b40522f
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland....
def ip(): n=int(input()) a=list(map(int,input().split())) rem=set([i for i in range(1,n+1)])-set(a) if n==1: return 0 o=e=0 for i in rem: if i%2==0: e+=1 else: o+=1 ct=0 i=0 while i<len(a) and a[i]==0: i+=1 if i==len(a): ...
python
code_algorithm
[ { "input": "7\n1 0 0 5 0 0 2\n", "output": "1\n" }, { "input": "5\n0 5 0 2 3\n", "output": "2\n" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 69 63 77 67 28 7 23 97 99 20 42 50 43 27 81 18 76 87 79 52 37 29 24 65 85 83 68 25 10 ...
code_contests
python
0
ee6bfc232475c52144302492db8e5427
Slime and his n friends are at a party. Slime has designed a game for his friends to play. At the beginning of the game, the i-th player has a_i biscuits. At each second, Slime will choose a biscuit randomly uniformly among all a_1 + a_2 + … + a_n biscuits, and the owner of this biscuit will give it to a random unifor...
import os import sys input = sys.stdin.buffer.readline #sys.setrecursionlimit(int(2e5)) from collections import deque import math # list(map(int, input().split())) ##################################################################################### class CF(object): def __init__(self): self.mod = 998244...
python
code_algorithm
[ { "input": "2\n1 2\n", "output": "3\n" }, { "input": "5\n8 4 2 0 1\n", "output": "801604029\n" }, { "input": "2\n1 1\n", "output": "1\n" }, { "input": "5\n0 0 0 0 35\n", "output": "0\n" }, { "input": "36\n110 7 51 3 36 69 30 7 122 22 11 96 98 17 133 44 38 75 7 10 ...
code_contests
python
0
095abeddd8f16768d6a4c85eccd435f6
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it...
def untor(a, c): res = '' while a or c: a, ma = divmod(a, 3) c, mc = divmod(c, 3) x = 0 while (ma + x)%3 != mc: x += 1 res = str(x) + res try: return int(res, 3) except Exception as e: return 0 a, c = map(int, input().split()) print(un...
python
code_algorithm
[ { "input": "387420489 225159023\n", "output": "1000000001\n" }, { "input": "14 34\n", "output": "50\n" }, { "input": "50 34\n", "output": "14\n" }, { "input": "5 5\n", "output": "0\n" }, { "input": "976954722 548418041\n", "output": "862925051\n" }, { ...
code_contests
python
0.5
784eb82d071bd2a8cf0833dc06c31b5d
You are given n points on a plane. All points are different. Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC. The groups of three points are considered unordered, that is, if point B is the middle of segment AC, then groups (A, B, C) and (C, B, A) are consi...
n = int(input()) points_array = [] cords = [] for i in range(2001): cords.append([False] * 2001) for i in range(n): x, y = [a for a in input().split()] points_array.append([int(x), int(y)]) cords[int(x)+1000][int(y)+1000] = True count = 0 for i in range(n): for j in range(i+1, n): x1, y1...
python
code_algorithm
[ { "input": "3\n0 0\n-1 0\n0 1\n", "output": "0\n" }, { "input": "3\n1 1\n2 2\n3 3\n", "output": "1\n" }, { "input": "10\n-2 1\n2 -2\n-1 -2\n0 0\n2 -1\n0 -2\n2 2\n0 2\n-1 -1\n1 -2\n", "output": "4\n" }, { "input": "40\n-8 24\n2 -1\n1 -18\n72 -70\n5 -4\n-308 436\n-19 40\n36 -35...
code_contests
python
0.3
5202b99edc40630c3d073f26bdcc9c5b
The Little Elephant has found a ragged old black-and-white string s on the attic. The characters of string s are numbered from the left to the right from 1 to |s|, where |s| is the length of the string. Let's denote the i-th character of string s as si. As the string is black-and-white, each character of the string is...
Mod=1000000007 n,k=map(int,input().split(' ')) s=' '+input() f,fs,g,gs,w=[0]*1000005,[0]*1000005,[0]*1000005,[0]*1000005,[0]*1000005 qx,qw,qb=[0]*1000005,[0]*1000005,[0]*1000005 q=0 f[0]=fs[0]=1 for i in range(1,n+1): lg=(i-k if i-k>=q else q) if s[i]!='B': f[i]=fs[i-1]-fs[lg-1]+Mod f[i]-=(Mod if f[i]>=Mod else 0...
python
code_algorithm
[ { "input": "10 2\nXXBXXWXXXX\n", "output": "166\n" }, { "input": "3 2\nXXX\n", "output": "0\n" }, { "input": "4 2\nXXXX\n", "output": "1\n" }, { "input": "4 2\nXXBW\n", "output": "0\n" }, { "input": "2 1\nWB\n", "output": "0\n" }, { "input": "128 100\n...
code_contests
python
0
b722da3cd56845526cd24b13e9200a99
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems. You've got the titles of n last problems — the strings, consisting of lowercase English letters. Your...
from itertools import * alphabet="abcdefghijklmnopqrstuvwxyz"; def isValid(s, names): for name in names: if name.find(s)!=-1: return False return True def newProblem(names): for i in range(1,3): for s in product(alphabet, repeat=i): st="" for c in s: ...
python
code_algorithm
[ { "input": "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n", "output": "ab\n" }, { "input": "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n", "output": "j\n" }, { "input": "3\nrjnflsbpxqivrcdjptj\nvpojopbwbwbswdu\nrydkiwnugwddcgcrng\n", "output": "a\n" }, { "inp...
code_contests
python
0.6
d3c8d01bc01bf8532ec18706605d5a89
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: * the Euclidean distance between A and B is one unit and neither A nor B is blocked; * or there is some inte...
from math import sqrt n = int(input()) if n == 0: print(1) else: print(4 * int(n * sqrt(2)))
python
code_algorithm
[ { "input": "2\n", "output": "8\n" }, { "input": "3\n", "output": "16\n" }, { "input": "1\n", "output": "4\n" }, { "input": "11\n", "output": "60\n" }, { "input": "0\n", "output": "1\n" }, { "input": "17\n", "output": "96\n" }, { "input": "1...
code_contests
python
0
735dd1dcd8428468109a1a076dd40a85
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
n = int(input()) a = list(map(int, input().split())) i = 0 ans = 0 while i < n: ans += 1 i1 = i while i1 < n and a[i1] == -1: i1 += 1 if i1 == n: break i2 = i1 + 1 while i2 < n and a[i2] == -1: i2 += 1 if i2 == n: break dist = i2 - i1 step = (a[i2] - a...
python
code_algorithm
[ { "input": "9\n-1 6 -1 2 -1 4 7 -1 2\n", "output": "3\n" }, { "input": "5\n-1 -1 -1 -1 -1\n", "output": "1\n" }, { "input": "7\n-1 -1 4 5 1 2 3\n", "output": "2\n" }, { "input": "9\n8 6 4 2 1 4 7 10 2\n", "output": "3\n" }, { "input": "3\n-1 1 -1\n", "output":...
code_contests
python
0
e12299c658e08ea2930c63ccc22d6339
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string. Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be? See notes for definition of a tandem repeat. I...
s=input() k=int(input()) n=len(s) if k>=n: print(int(2*((n+k)//2))) raise SystemExit ll=0 for i in range(k+1): for l in range((n+i)//2,i-1,-1): if s[n-(l-i):n]==s[n+i-2*l:n-l]: if l>ll: ll=l break j=ll while 2*j<=n: j=j+1 for i in range(n-2*j): if s[i:i+j]==s[...
python
code_algorithm
[ { "input": "aaabbbb\n2\n", "output": "6\n" }, { "input": "aaba\n2\n", "output": "6\n" }, { "input": "abracadabra\n10\n", "output": "20\n" }, { "input": "jtifziirovbklaioslunwvtdavraandnzcwqbealbvqonoxufqrsewwrzvkrecrfqhdduwmcdcdhdtvpyshfhgdwdkmglskidhzayvouwhumzhcphocqyfcdddh...
code_contests
python
0
43d946a1e3e722734967c0dc2fd9f267
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m...
n = int(input()) b = list(map(int, input().split())) m = int(input()) g = list(map(int, input().split())) b.sort() g.sort() res = 0 i = 0 j = 0 while i < n and j < m: if abs(b[i]-g[j]) <= 1: res += 1 i += 1 j += 1 elif b[i] > g[j]: j += 1 else: i += 1 print(res)...
python
code_algorithm
[ { "input": "4\n1 2 3 4\n4\n10 11 12 13\n", "output": "0\n" }, { "input": "4\n1 4 6 2\n5\n5 1 5 7 9\n", "output": "3\n" }, { "input": "5\n1 1 1 1 1\n3\n1 2 3\n", "output": "2\n" }, { "input": "1\n4\n3\n4 4 4\n", "output": "1\n" }, { "input": "3\n7 7 7\n4\n2 7 2 4\n...
code_contests
python
0.9
1caed8bba9439bff7c343d1d6fb33035
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls f...
n1 , n2 , k1 , k2 = map(int , (input().split(" "))) if n1 <= n2: print('Second') else: print('First')
python
code_algorithm
[ { "input": "2 1 1 1\n", "output": "First\n" }, { "input": "2 2 1 2\n", "output": "Second\n" }, { "input": "50 50 50 50\n", "output": "Second\n" }, { "input": "49 49 4 1\n", "output": "Second\n" }, { "input": "48 50 12 11\n", "output": "Second\n" }, { "...
code_contests
python
0
76cc9bdca78d6d780d48e4a2bdc51229
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers. Input The first line contains a single...
import math a = input() d = int(max(a)) print(d) dec = math.ceil(math.log10(int(a))) c = [0]*d if int(a) != 10**dec: for i in a: for j in range(int(i)): c[j] = c[j]+10**(dec-1) dec = dec - 1 d='' for i in c: d += str(i)+' ' if int(a) == 10**dec: print(a) else: print(d.strip()...
python
code_algorithm
[ { "input": "32\n", "output": "3\n11 11 10\n" }, { "input": "9\n", "output": "9\n1 1 1 1 1 1 1 1 1\n" }, { "input": "111111\n", "output": "1\n111111\n" }, { "input": "100009\n", "output": "9\n100001 1 1 1 1 1 1 1 1\n" }, { "input": "10011\n", "output": "1\n1001...
code_contests
python
0.8
1ed4789aad00947c02a7a7ed89600e69
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is ...
str1 = input().split() n = int(str1[0]) k = int(str1[1]) q = int(str1[2]) friends = list(map(lambda x: int(x), input().split())) online = set() for i in range(q): str1 = input().split() if str1[0] == '2': if int(str1[1]) in online: print("YES") else: print("NO") els...
python
code_algorithm
[ { "input": "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n", "output": "NO\nYES\nNO\nYES\n" }, { "input": "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n", "output": "NO\nYES\nNO\nYES\nYES\n" }, { "input": "1 1 1\n1000000000\n2 1\n", "output...
code_contests
python
0.8
f6150e392f463db467c2695e2591077c
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3....
#!/usr/bin/env python3 import sys # 1 8 27 64 125 216 343 512 729 1000 # 1-7: blocks of size 1 # 8-15: 1 block of size 2, blocks of size 1 # 16-23: 2 blocks of size 2, blocks of size 1 # 24-26: 3 blocks of size 2, blocks of size 1 # 27-34: 1 block of size 3, blocks of size 1 # Maximum will always be when you have th...
python
code_algorithm
[ { "input": "6\n", "output": "6 6\n" }, { "input": "48\n", "output": "9 42\n" }, { "input": "1000000000000000\n", "output": "18 999999993541753\n" }, { "input": "994\n", "output": "12 941\n" }, { "input": "200385\n", "output": "14 200355\n" }, { "input"...
code_contests
python
0
79fd8a7e83559f23b4de4e35ccef6434
There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to ...
n, q = map(int, input().split()) servers = [i for i in range(1, n+1)] res, used = [], {} for i in range(q): t, s, d = map(int, input().split()) finish = t + d for i in list(used.keys()): if t >= i: servers += used[i] servers.sort() del used[i] if s > len(serv...
python
code_algorithm
[ { "input": "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n", "output": "6\n9\n30\n-1\n15\n36\n" }, { "input": "4 3\n1 3 2\n2 2 1\n3 4 3\n", "output": "6\n-1\n10\n" }, { "input": "3 2\n3 2 3\n5 1 2\n", "output": "3\n3\n" }, { "input": "100 1\n1000000 100 1000\n", "out...
code_contests
python
0.2
59caba36a8b66c6e49e33a419559bd07
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor ea...
from sys import * f = lambda: sorted(stdin.readline()[:-1]) a, b = f(), f() n = len(a) u = v = '' i, j = 0, -1 x, y = n - 1 >> 1, n - 2 >> 1 while x != -1: if a[i] < b[j]: u += a[i] i += 1 else: v += a[i + x] x -= 1 if y == -1: break elif a[i] < b[j]: u += b[j] j -= 1...
python
code_algorithm
[ { "input": "xxxxxx\nxxxxxx\n", "output": "xxxxxx\n" }, { "input": "tinkoff\nzscoder\n", "output": "fzfsirk\n" }, { "input": "ioi\nimo\n", "output": "ioi\n" }, { "input": "bcdef\nabbbc\n", "output": "bccdb\n" }, { "input": "z\ny\n", "output": "z\n" }, { ...
code_contests
python
0
6101d01668be5113f177d437c3850ee1
Absent-minded Masha got set of n cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x. To make a number Masha can rotate her cubes and put them in a row. Aft...
n = int(input()) lst = [] for i in range(n): a = list(map(int,input().split())) lst.append(a) cnt = 0 ans = 0 if n == 1: i = 1 while 1: if i == 10: break if i in lst[0]: i += 1 else: print(i - 1) break elif n == 2: i = 1 f = 0 whil...
python
code_algorithm
[ { "input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n", "output": "98\n" }, { "input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n", "output": "87\n" }, { "input": "2\n2 6 8 1 3 1\n2 1 3 8 6 7\n", "output": "3\n" }, { "input": "2\n1 8 9 1 1 0\n2 3 4 5 6 7\n", "output": "...
code_contests
python
0
a730d56f00277cd47d410b89e3ea0de8
An African crossword is a rectangular table n × m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a lette...
n, m = [int(x) for x in input().split()] lr = [] lc = [] lst = [] for i in range(n): l = list(input()) lr.append(l) for i in range(m): l = [] for j in range(n): s = lr[j][i] l.append(s) lc.append(l) for i in range(n): for j in range(m): s = lr[i][j] if lr[i].count...
python
code_algorithm
[ { "input": "3 3\ncba\nbcd\ncbc\n", "output": "abcd\n" }, { "input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n", "output": "codeforces\n" }, { "input": "1 2\nfg\n", "output": "fg\n" }, { "input": "3 2\nxe\ner\nwb\n", "output": "xeerwb\n" }, { "input": "7 6\neklgxi\...
code_contests
python
0.6
30c5492e64669b47b66dc2a7c34c7acd
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of n integer numbers — saturation of the color of each pencil. Now Mishka wants to ...
n, k, d = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) b = [0] * n i = j = 0 for i in range(n): while a[i] - a[j] > d: j += 1 b[i] = j c = [0] * n for i in range(k - 1, n): c[i] = c[i - 1] + int(i - b[i] + 1 >= k and (b[i] == 0 or c[i - k] > c[b[i] - 2] or (b[i] == 1 a...
python
code_algorithm
[ { "input": "6 3 10\n7 2 7 7 4 2\n", "output": "YES\n" }, { "input": "3 2 5\n10 16 22\n", "output": "NO\n" }, { "input": "6 2 3\n4 5 3 13 4 10\n", "output": "YES\n" }, { "input": "4 2 12\n10 16 22 28\n", "output": "YES\n" }, { "input": "10 3 1\n5 5 5 6 6 7 8 8 8 9\...
code_contests
python
0.1
a36e6dde64bbeab8cf4b5fdf1498aef7
Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees! Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and s...
from math import gcd import random,time,sys input=sys.stdin.buffer.readline def main(): n=int(input()) a=list(map(int,input().split())) #a=[2*random.randint(1,10**9) for i in range(n)] start=time.time() a+=[0] dp=[[False for j in range(n)] for i in range(n)] GCD=[0 for i in range(n+1)] ...
python
code_algorithm
[ { "input": "9\n4 8 10 12 15 18 33 44 81\n", "output": "Yes\n" }, { "input": "6\n3 6 9 18 36 108\n", "output": "Yes\n" }, { "input": "2\n7 17\n", "output": "No\n" }, { "input": "4\n3 5 7 105\n", "output": "No\n" }, { "input": "13\n2 12 60 300 900 6300 44100 176400 ...
code_contests
python
0
15693c9a15f9103bc5b486b6de3b0838
There are n students and m clubs in a college. The clubs are numbered from 1 to m. Each student has a potential p_i and is a member of the club with index c_i. Initially, each student is a member of exactly one club. A technical fest starts in the college, and it will run for the next d days. There is a coding competit...
import sys input = sys.stdin.readline n, m = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) d = int(input()) disable = [False] * n base = 5001 ds = [int(input())-1 for _ in range(d)] for ele in ds: disable[ele] = True # Create Graph childs = [[] for i in range(...
python
code_algorithm
[ { "input": "5 5\n0 1 2 4 5\n1 2 3 4 5\n4\n2\n3\n5\n4\n", "output": "1\n1\n1\n1\n" }, { "input": "5 3\n0 1 2 2 0\n1 2 2 3 2\n5\n3\n2\n4\n5\n1\n", "output": "3\n1\n1\n1\n0\n" }, { "input": "5 3\n0 1 2 2 1\n1 3 2 3 2\n5\n4\n2\n3\n5\n1\n", "output": "3\n2\n2\n1\n0\n" }, { "input"...
code_contests
python
0
4b58e061ed00b5dabdbb3a121b4cfeba
In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and writes a string s2, consisting of exactly nine digits and representi...
a, b, m = map(int, input().split()) k = s = 10 ** 9 % m i = 0 while k and i < a: i += 1 if k < m - b: exit(print(1, str(i).zfill(9))) k += s if k >= m: k -= m print(2)
python
code_algorithm
[ { "input": "4 0 9\n", "output": "1 000000001\n" }, { "input": "1 10 7\n", "output": "2\n" }, { "input": "1 2 11\n", "output": "2\n" }, { "input": "576695 1234562 1234567\n", "output": "1 000576695\n" }, { "input": "138 11711 11829\n", "output": "2\n" }, { ...
code_contests
python
0
8ab6c209900e82eb6158555a9f45c210
You are given a sequence a_1, a_2, ..., a_n consisting of n non-zero integers (i.e. a_i ≠ 0). You have to calculate two following values: 1. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a_{l + 1} ... a_{r - 1} ⋅ a_r is negative; 2. the number of pairs of indices (l, r) (l ≤ r) such that a_l ⋅ a...
input() a=list(map(int,input().split())) q,w,e,t,y=0,0,1,0,0 for i in a: if e>0: q+=1 if i>0: e=1 else: e=-1 else: w+=1 if i>0: e=-1 else: e=1 if e>0: t+=q y+=w else: t+=w y+=q...
python
code_algorithm
[ { "input": "10\n4 2 -4 3 1 2 -4 3 2 3\n", "output": "28 27\n" }, { "input": "5\n-1 -2 -3 -4 -5\n", "output": "9 6\n" }, { "input": "5\n5 -3 3 -1 1\n", "output": "8 7\n" }, { "input": "2\n-703630698 870277542\n", "output": "2 1\n" }, { "input": "3\n-1 -1 1\n", ...
code_contests
python
0.1
0b942feae9db6aa4a777c5bc3bbc16a6
After years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend it. The only inconvenience is highly unusual management. For that very reason the developers decided to leave the e-read...
n=int(input()) T=[] for i in range(n): T.append(input()[::-1]) Val=['0','1'] S=0 L1=[0]*n C1=[0]*n for diag in range(n-1): for i in range(diag+1): l,c=L1[i],C1[diag-i] if T[i][diag-i]!=Val[(l+c)%2]: S+=1 L1[i]=1-l C1[diag-i]=1-c L2=[0]*n C2=[0]...
python
code_algorithm
[ { "input": "5\n01110\n10010\n10001\n10011\n11110\n", "output": "4\n" }, { "input": "3\n000\n000\n000\n", "output": "0\n" }, { "input": "10\n1111100000\n0010100000\n0110111000\n0000001000\n1011001010\n0010100001\n0010111000\n0011001010\n0000110010\n0000001100\n", "output": "20\n" },...
code_contests
python
0
1e83fe6706e437b0948794766f0b0bf2
You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes). String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the ...
import atexit import io import sys _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ _OUTPUT_BUFFER = io.StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) import bisect from datetime import datetime def main(): ...
python
code_algorithm
[ { "input": "60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected\n", "output": "2012-03-16 16:16:43\n" }, { ...
code_contests
python
0
3a0a8b0c82229784f4455f955809143e
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant o...
n, m = [int(x) for x in input().split()] d = [0 for i in range(m)] for i in range(n): c, x = [x for x in input().split()] c = int(c) d[c-1] = max(d[:c])+1 print(n-max(d))
python
code_algorithm
[ { "input": "3 3\n1 5.0\n2 5.5\n3 6.0\n", "output": "0\n" }, { "input": "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125\n", "output": "2\n" }, { "input": "3 2\n2 1\n1 2.0\n1 3.100\n", "output": "1\n" }, { "input": "20 10\n1 0.000000\n2 0.0000...
code_contests
python
0.4
7f118c75fa355d464acb7ba662c08f6a
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols ...
n = int(input()) l = list(map(int,input().split())) n1 = int(input()) for i in range(n1): x,y = map(int,input().split()) if len(l)==1: l[0]=0 elif x==1: l[x]+=l[x-1]-y l[x-1]=0 elif x==len(l): l[x-2]+=y-1 l[x-1]=0 else: l[x-2]+=y-1 l[x]+=l[x-1]-y l[x-1]=0 for i in l: print(i)
python
code_algorithm
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "output": "0\n12\n5\n0\n16\n" }, { "input": "3\n2 4 1\n1\n2 2\n", "output": "3\n0\n3\n" }, { "input": "1\n100\n1\n1 100\n", "output": "0\n" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43\n", ...
code_contests
python
0.6
ba8618e4305620ed08c6c089b579beba
Vasya and Petya wrote down all integers from 1 to n to play the "powers" game (n can be quite large; however, Vasya and Petya are not confused by this fact). Players choose numbers in turn (Vasya chooses first). If some number x is chosen at the current turn, it is forbidden to choose x or all of its other positive in...
from sys import stdin, stdout import math, collections mod = 10**9+7 def isPower(n): if (n <= 1): return True for x in range(2, (int)(math.sqrt(n)) + 1): p = x while (p <= n): p = p * x if (p == n): return True return False n = int(input()) a...
python
code_algorithm
[ { "input": "8\n", "output": "Petya\n" }, { "input": "1\n", "output": "Vasya\n" }, { "input": "2\n", "output": "Petya\n" }, { "input": "10154\n", "output": "Vasya\n" }, { "input": "19000881\n", "output": "Vasya\n" }, { "input": "6\n", "output": "Vas...
code_contests
python
0
405d3be9c39568d7d13394bc0db6c1a4
Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a). Input The first line contains integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 9). The i-th ...
import sys x=input().split() n=int(x[0]) k=int(x[1]) list=[] for i in range(0,n): y=input() list.append(y) l=0 for j in list: flag=1 for z in range(0,k+1): if str(z) not in j: flag=0 break if flag==1: l=l+1 print(l)
python
code_algorithm
[ { "input": "2 1\n1\n10\n", "output": "1\n" }, { "input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n", "output": "10\n" }, { "input": "1 0\n1000000000\n", "output": "1\n" }, { "input": "1 3\n1\n", "output": "0\n" }, ...
code_contests
python
1
f046badc98836d2fef052f084febc7d9
Salve, mi amice. Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus. Rp: I Aqua Fortis I Aqua Regia II Amalgama VII Minium IV Vitriol Misce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci invia est via. Fac...
b =[1,1,2,7,4] a =list(map(int,input().split())) ans = 100 for i in range(5): ans = min(a[i]//b[i],ans) print(ans)
python
code_algorithm
[ { "input": "2 4 6 8 10\n", "output": "1\n" }, { "input": "18 13 91 64 22\n", "output": "5\n" }, { "input": "31 38 47 26 13\n", "output": "3\n" }, { "input": "65 46 3 77 81\n", "output": "1\n" }, { "input": "94 21 36 89 20\n", "output": "5\n" }, { "inpu...
code_contests
python
0
ae7dcedfbbd3c78e270e0be43b74e19e