problem_id stringlengths 3 7 | contestId stringclasses 660
values | problem_index stringclasses 27
values | programmingLanguage stringclasses 3
values | testset stringclasses 5
values | incorrect_passedTestCount float64 0 146 | incorrect_timeConsumedMillis float64 15 4.26k | incorrect_memoryConsumedBytes float64 0 271M | incorrect_submission_id stringlengths 7 9 | incorrect_source stringlengths 10 27.7k | correct_passedTestCount float64 2 360 | correct_timeConsumedMillis int64 30 8.06k | correct_memoryConsumedBytes int64 0 475M | correct_submission_id stringlengths 7 9 | correct_source stringlengths 28 21.2k | contest_name stringclasses 664
values | contest_type stringclasses 3
values | contest_start_year int64 2.01k 2.02k | time_limit float64 0.5 15 | memory_limit float64 64 1.02k | title stringlengths 2 54 | description stringlengths 35 3.16k | input_format stringlengths 67 1.76k | output_format stringlengths 18 1.06k ⌀ | interaction_format null | note stringclasses 840
values | examples stringlengths 34 1.16k | rating int64 800 3.4k ⌀ | tags stringclasses 533
values | testset_size int64 2 360 | official_tests stringlengths 44 19.7M | official_tests_complete bool 1
class | input_mode stringclasses 1
value | generated_checker stringclasses 231
values | executable bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
347/B | 347 | B | Python 3 | TESTS | 17 | 310 | 6,758,400 | 39214212 | n=int(input())
a=[int(num) for num in input().split()]
max=0
flag=0
for i in range(0,n):
if a[i]==i:
max=max+1
elif a[a[i]]==i:
temp=a[i]
a[i]=a[temp]
a[temp]=temp
max=max+1
flag=1
elif flag!=1:
flag=2
if flag==2:
max=max+1
print(max) | 19 | 124 | 7,782,400 | 4929723 | n=int(input())
a=list(map(int,input().split()))
b=0;
c=0;
for i,j in enumerate(a):
if i==j:
b+=1
elif a[j]==i:
c=2
elif c==0:
c=1
print(b+c) | Codeforces Round 201 (Div. 2) | CF | 2,013 | 2 | 256 | Fixed Points | A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation c... | The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | null | null | [{"input": "5\n0 1 3 4 2", "output": "3"}] | 1,100 | ["brute force", "implementation", "math"] | 19 | [{"input": "5\r\n0 1 3 4 2\r\n", "output": "3\r\n"}, {"input": "10\r\n6 9 4 7 8 2 3 5 0 1\r\n", "output": "2\r\n"}, {"input": "100\r\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18... | false | stdio | null | true |
347/B | 347 | B | Python 3 | TESTS | 17 | 436 | 16,588,800 | 89457733 | n = int(input())
lst = list(map(int,input().split(' ')))
maxed = 0
c = 0
maps = {}
for i in range(len(lst)):
maps[lst[i]] = i
for i in range(len(lst)):
if lst[i] == i:
continue
if lst[i] == maps[i]:
temp = lst[i]
lst[i] = i
lst[maps[i]] = temp
c+=1
elif c == 0 and i == len(lst)-1:
temp = lst[i]
lst[i]... | 19 | 154 | 13,107,200 | 183383962 | n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(len(a)):
if i == a[i]:
cnt +=1
ok2 = False
ok1 = False
for i in range(len(a)):
if (i == a[i]):
continue
ok1 = True
if (i == a[a[i]]):
ok2 = True
if ok2 == True:
cnt+= 2
elif ok1 == True:
cnt+= 1... | Codeforces Round 201 (Div. 2) | CF | 2,013 | 2 | 256 | Fixed Points | A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation c... | The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | null | null | [{"input": "5\n0 1 3 4 2", "output": "3"}] | 1,100 | ["brute force", "implementation", "math"] | 19 | [{"input": "5\r\n0 1 3 4 2\r\n", "output": "3\r\n"}, {"input": "10\r\n6 9 4 7 8 2 3 5 0 1\r\n", "output": "2\r\n"}, {"input": "100\r\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18... | false | stdio | null | true |
780/D | 780 | D | Python 3 | PRETESTS | 3 | 46 | 4,915,200 | 25241863 | n = int(input())
blocked = {}
blocked_name = {}
was = {}
for i in range(n):
arr = input().split()
name, city = arr[0], arr[1]
first = name[:3]
second = name[:2] + '_' + city[:1]
try:
v = blocked[first]
v1 = blocked[first[:2] + '_' + first[2:]]
try:
vv = blocke... | 41 | 124 | 409,600 | 49508210 | n = int(input())
ans = 0
o = []
p = []
for i in range(n):
s, g = [str(j) for j in input().split()]
ss = s[0:3]
gg = s[0:2] + g[0]
flag = True
if ss in o:
flag = False
o.append(ss)
if gg in p and ss not in p and flag:
p.append(ss)
elif gg not in p:
... | Технокубок 2017 - Финал (только для онсайт-финалистов) | CF | 2,017 | 2 | 256 | Innokenty and a Football League | Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters.
Each club's full name consist of two wo... | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of clubs in the league.
Each of the next n lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least 3 and at most 20. | It it is not possible to choose short names and satisfy all constraints, print a single line "NO".
Otherwise, in the first line print "YES". Then print n lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input.
If there are multiple answe... | null | In the first sample Innokenty can choose first option for both clubs.
In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs.
In the third example Innokenty can choose the ... | [{"input": "2\nDINAMO BYTECITY\nFOOTBALL MOSCOW", "output": "YES\nDIN\nFOO"}, {"input": "2\nDINAMO BYTECITY\nDINAMO BITECITY", "output": "NO"}, {"input": "3\nPLAYFOOTBALL MOSCOW\nPLAYVOLLEYBALL SPB\nGOGO TECHNOCUP", "output": "YES\nPLM\nPLS\nGOG"}, {"input": "3\nABC DEF\nABC EFG\nABD OOO", "output": "YES\nABD\nABE\nABO... | 1,900 | ["2-sat", "graphs", "greedy", "implementation", "shortest paths", "strings"] | 41 | [{"input": "2\r\nDINAMO BYTECITY\r\nFOOTBALL MOSCOW\r\n", "output": "YES\r\nDIN\r\nFOO\r\n"}, {"input": "2\r\nDINAMO BYTECITY\r\nDINAMO BITECITY\r\n", "output": "NO\r\n"}, {"input": "3\r\nPLAYFOOTBALL MOSCOW\r\nPLAYVOLLEYBALL SPB\r\nGOGO TECHNOCUP\r\n", "output": "YES\r\nPLM\r\nPLS\r\nGOG\r\n"}, {"input": "3\r\nABC DEF... | false | stdio | import sys
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
n = int(f.readline())
clubs = []
for _ in range(n):
team, hometown = f.readline().strip().split()
clubs.append((team, hometown))
ai_list = []
bi_list = []
f... | true |
416/B | 416 | B | Python 3 | TESTS | 5 | 561 | 6,963,200 | 38436552 | #416B
arr = list(map(int, input().split(" ")))
m = arr[0]
n = arr[1]
time = []
timesum = [0]*m
for i in range(m):
if n == 1:
arr = list(map(int, input().split(" ")))
time.append([0, arr[0]])
else:
arr = list(map(int, input().split(" ")))
a = 0
for i in range(n-1):
a += arr[i]
time.append([a, arr[n-1... | 26 | 327 | 12,185,600 | 69259619 | def arr_inp():
return [int(x) for x in stdin.readline().split()]
def get_col(arr, i):
return [row[i] for row in arr]
def arr_sum(ar):
ar.insert(0, 0)
return list(accumulate(ar, lambda x, y: x + y))
from itertools import accumulate
from sys import stdin
m, n = arr_inp()
arr = [arr_inp() for i in r... | Codeforces Round 241 (Div. 2) | CF | 2,014 | 1 | 256 | Art Union | A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows.
Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1... | The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5), where m is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), where tij is the time the j-th painter needs to... | Print the sequence of m integers r1, r2, ..., rm, where ri is the moment when the n-th painter stopped working on the i-th picture. | null | null | [{"input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15"}, {"input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21"}] | 1,300 | ["brute force", "dp", "implementation"] | 26 | [{"input": "5 1\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", "output": "1 3 6 10 15 "}, {"input": "4 2\r\n2 5\r\n3 1\r\n5 3\r\n10 1\r\n", "output": "7 8 13 21 "}, {"input": "1 1\r\n66\r\n", "output": "66 "}, {"input": "2 2\r\n1 1\r\n1 1\r\n", "output": "2 3 "}, {"input": "2 2\r\n10 1\r\n10 1\r\n", "output": "11 21 "}, {"input": "1 5... | false | stdio | null | true |
165/A | 165 | A | Python 3 | TESTS | 10 | 154 | 0 | 193216835 | n = int(input())
pairs = []
for i in range(n):
pairs.append(tuple(map(int, input().split(" "))))
pairs.sort(key=lambda x: 1000 * x[0] + x[1])
pairsY = sorted(pairs, key=lambda y: 1000 * y[1] + y[0])
validX = set()
validY = set()
for i in range(1, n-1):
if(pairs[i-1][0] == pairs[i][0] and pairs[i+1][0] == pair... | 26 | 62 | 0 | 172527676 | dx={}
dy={}
pts=[]
n=int(input())
for i in range(n):
pt=input().split()
x=int(pt[0])
y=int(pt[1])
pts.append([x,y])
if x in dx:
dx[x].append(y)
else:
dx[x] = [y]
if y in dy:
dy[y].append(x)
else:
dy[y] = [x]
res=0
for x,y in pts:
if x <max(dy[y]) and x... | Codeforces Round 112 (Div. 2) | CF | 2,012 | 2 | 256 | Supercentral Point | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
- point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
- point (x', y') is (x, y)'s left neighbor, i... | The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed t... | Print the only number — the number of supercentral points of the given set. | null | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | [{"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2"}, {"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1"}] | 1,000 | ["implementation"] | 26 | [{"input": "8\r\n1 1\r\n4 2\r\n3 1\r\n1 2\r\n0 2\r\n0 1\r\n1 0\r\n1 3\r\n", "output": "2\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n1 0\r\n0 -1\r\n-1 0\r\n", "output": "1\r\n"}, {"input": "9\r\n-565 -752\r\n-184 723\r\n-184 -752\r\n-184 1\r\n950 723\r\n-565 723\r\n950 -752\r\n950 1\r\n-565 1\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
165/A | 165 | A | Python 3 | TESTS | 7 | 122 | 0 | 116209539 | n=int(input())
x,y=[],[]
for i in range(n):
a,b=map(int,input().split())
x.append(a)
y.append(b)
a=0
for i in range(n):
# for k in range(n):
newy=[y[k] for k in range(n) if x[k]==x[i] and k!=i]
if len(newy)!=0:
if y[i]<max(newy) and y[i]>min(newy) :
# print(x[i],y[i])
... | 26 | 62 | 0 | 200942614 | n = int(input())
dx,dy,points = {},{},[]
for i in range(n):
a,b=map(int,input().split())
points.append((a,b))
if a not in dx:
dx[a] = [b]
else:
dx[a].append(b)
if b not in dy:
dy[b] = [a]
else: dy[b].append(a)
# print(dx,dy)
num=0
for pt in points:
if pt[1] > min(d... | Codeforces Round 112 (Div. 2) | CF | 2,012 | 2 | 256 | Supercentral Point | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
- point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
- point (x', y') is (x, y)'s left neighbor, i... | The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed t... | Print the only number — the number of supercentral points of the given set. | null | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | [{"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2"}, {"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1"}] | 1,000 | ["implementation"] | 26 | [{"input": "8\r\n1 1\r\n4 2\r\n3 1\r\n1 2\r\n0 2\r\n0 1\r\n1 0\r\n1 3\r\n", "output": "2\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n1 0\r\n0 -1\r\n-1 0\r\n", "output": "1\r\n"}, {"input": "9\r\n-565 -752\r\n-184 723\r\n-184 -752\r\n-184 1\r\n950 723\r\n-565 723\r\n950 -752\r\n950 1\r\n-565 1\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
169/A | 169 | A | Python 3 | TESTS | 7 | 109 | 0 | 43412425 | a=list(map(int, input().split()))
b=list(map(int, input().split()))
if a[1]<=a[2]:
h=sorted(b,reverse=True)
else:
h=sorted(b,reverse=False)
t=len(h)//2
print (abs(h[t-1]-h[t])) | 29 | 46 | 0 | 144335879 | i=lambda:map(int,input().split())
*_,b=i()
c=sorted(i())
print(c[b]-c[b-1]) | VK Cup 2012 Round 2 (Unofficial Div. 2 Edition) | CF | 2,012 | 2 | 256 | Chores | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger... | The first input line contains three integers n, a and b (2 ≤ n ≤ 2000; a, b ≥ 1; a + b = n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 109), hi is the complexity of the i-th chore. The numbers in t... | Print the required number of ways to choose an integer value of x. If there are no such ways, print 0. | null | In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4. | [{"input": "5 2 3\n6 2 3 100 1", "output": "3"}, {"input": "7 3 4\n1 1 9 1 1 1 1", "output": "0"}] | 800 | ["sortings"] | 29 | [{"input": "5 2 3\r\n6 2 3 100 1\r\n", "output": "3\r\n"}, {"input": "7 3 4\r\n1 1 9 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n10 2\r\n", "output": "8\r\n"}, {"input": "2 1 1\r\n7 7\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1000000000\r\n", "output": "999999999\r\n"}, {"input": "3 1 2\r\n6 5 5\r\n", "... | false | stdio | null | true |
754/D | 754 | D | PyPy 3-64 | TESTS | 2 | 109 | 8,806,400 | 175544051 | '''
https://codeforces.com/problemset/problem/754/D
输入 n, k (1≤k≤n≤3e5) 和 n 个闭区间,区间左右端点在 [-1e9,1e9] 内,区间的编号从 1 开始。
请你选择 k 个区间,使得这 k 个区间的交集的大小尽量大(只考虑整数),
输出这个最大值,以及对应的区间的编号。
思考题:如果改成并集呢?
输入
4 2
1 100
40 70
120 130
125 180
输出
31
1 2
输入
3 2
1 12
15 20
25 30
输出
0
1 2
输入
5 2
1 10
5 15
14 50
30 70
99 100
输出
21
3 4
http... | 77 | 2,121 | 61,337,600 | 174828075 | import sys
from heapq import heappush,heappop
n,m=map(int,input().split())
arr=sorted([*map(int,sys.stdin.readline().split()),i] for i in range(1,n+1))
q,res,idx,poped,areas=[],0,0,[],set()
for i in range(n):
heappush(q,(arr[i][1],i))
if len(q)<m:continue
lr=arr[q[0][1]][1]-arr[i][0]+1
if lr>res:
... | Codeforces Round 390 (Div. 2) | CF | 2,017 | 4 | 256 | Fedor and coupons | All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket.
The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has n discount coupons, the i-th of them can be used with products with i... | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — the number of coupons Fedor has, and the number of coupons he wants to choose.
Each of the next n lines contains two integers li and ri ( - 109 ≤ li ≤ ri ≤ 109) — the description of the i-th coupon. The coupons can be equal. | In the first line print single integer — the maximum number of products with which all the chosen coupons can be used. The products with which at least one coupon cannot be used shouldn't be counted.
In the second line print k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the ids of the coupons which Fedor should c... | null | In the first example if we take the first two coupons then all the products with ids in range [40, 70] can be bought with both coupons. There are 31 products in total.
In the second example, no product can be bought with two coupons, that is why the answer is 0. Fedor can choose any two coupons in this example. | [{"input": "4 2\n1 100\n40 70\n120 130\n125 180", "output": "31\n1 2"}, {"input": "3 2\n1 12\n15 20\n25 30", "output": "0\n1 2"}, {"input": "5 2\n1 10\n5 15\n14 50\n30 70\n99 100", "output": "21\n3 4"}] | 2,100 | ["binary search", "data structures", "greedy", "sortings"] | 77 | [{"input": "4 2\r\n1 100\r\n40 70\r\n120 130\r\n125 180\r\n", "output": "31\r\n1 2 \r\n"}, {"input": "3 2\r\n1 12\r\n15 20\r\n25 30\r\n", "output": "0\r\n1 2 \r\n"}, {"input": "5 2\r\n1 10\r\n5 15\r\n14 50\r\n30 70\r\n99 100\r\n", "output": "21\r\n3 4 \r\n"}, {"input": "7 6\r\n-8 6\r\n7 9\r\n-10 -5\r\n-6 10\r\n-7 -3\r\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n, k = map(int, f.readline().split())
coupons = []
for _ in range(n):
l, r = map(int, f.readline().split())
... | true |
730/G | 730 | G | Python 3 | TESTS | 6 | 62 | 204,800 | 21808523 | n=int(input())
p=1
L=[]
m,M=0,0
for j in range(n):
ch=input().split()
s,d=int(ch[0]),int(ch[1])
if j==0:
m=s
M=s+d-1
print(s,d+s-1)
L.append([s,s+d-1])
else:
B=True
for i in L:
if i[1]>=s>=i[0] or i[0]<=(s+d-1)<=i[1] or (s<=i[0] and (s+d-1)>=i[... | 28 | 140 | 1,433,600 | 21712976 | #!/usr/bin/env python3
def main():
try:
while True:
n = int(input())
req = [tuple(map(int, input().split())) for i in range(n)]
used = [(req[0][0], req[0][0] + req[0][1])]
print(used[0][0], used[0][1] - 1)
for start, dur in req[1:]:
... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Car Repair Shop | Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order... | The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients.
The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number ... | Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car. | null | null | [{"input": "3\n9 2\n7 3\n2 4", "output": "9 10\n1 3\n4 7"}, {"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000", "output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000"}] | 1,600 | ["implementation"] | 28 | [{"input": "3\r\n9 2\r\n7 3\r\n2 4\r\n", "output": "9 10\r\n1 3\r\n4 7\r\n"}, {"input": "4\r\n1000000000 1000000\r\n1000000000 1000000\r\n100000000 1000000\r\n1000000000 1000000\r\n", "output": "1000000000 1000999999\r\n1 1000000\r\n100000000 100999999\r\n1000001 2000000\r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 1\... | false | stdio | null | true |
913/G | 913 | G | Python 3 | TESTS | 8 | 1,730 | 6,041,600 | 34039412 | import sys
import math
from decimal import *
line = lambda: list(int(x) for x in input().split())
def pow(n, k, p):
if k == 0:
return 1 % p
if k % 2 == 1:
return pow(n, k - 1, p) * n % p
t = pow(n, k / 2, p)
return t * t % p;
test = int(input())
for i in range(0, test):
x = int(in... | 31 | 140 | 7,168,000 | 199889664 | L = 11; L_ = 32
P2 = 2**L_
P5 = 5**(L_//2)
P2P5 = P2 * P5
P5_ = 5**L_
P10 = 10**L_
P10_ = 10**(L_-L)
T = P5 // 5 * 4
T_ = P5_ // 5 * 4
def gcd_(a, b):
if b == 0:
return (1, 0)
else:
(x_, y_) = gcd_(b, a % b)
return (y_, x_ - a // b * y_)
def inv(a, md):
(x_, y_) = gcd_(a, md)
i... | Hello 2018 | CF | 2,018 | 2 | 256 | Power Substring | You are given n positive integers a1, a2, ..., an.
For every ai you need to find a positive integer ki such that the decimal notation of 2ki contains the decimal notation of ai as a substring among its last min(100, length(2ki)) digits. Here length(m) is the length of the decimal notation of m.
Note that you don't ha... | The first line contains a single integer n (1 ≤ n ≤ 2 000) — the number of integers ai.
Each of the next n lines contains a positive integer ai (1 ≤ ai < 1011). | Print n lines. The i-th of them should contain a positive integer ki such that the last min(100, length(2ki)) digits of 2ki contain the decimal notation of ai as a substring. Integers ki must satisfy 1 ≤ ki ≤ 1050.
It can be shown that the answer always exists under the given constraints. If there are multiple answers... | null | null | [{"input": "2\n8\n2", "output": "3\n1"}, {"input": "2\n3\n4857", "output": "5\n20"}] | 3,200 | ["math", "number theory"] | 31 | [{"input": "2\r\n8\r\n2\r\n", "output": "3\r\n1\r\n"}, {"input": "2\r\n3\r\n4857\r\n", "output": "5\r\n20\r\n"}, {"input": "7\r\n1\r\n7\r\n9\r\n5\r\n6\r\n10\r\n4\r\n", "output": "9\r\n17\r\n13\r\n21\r\n4\r\n42\r\n2\r\n"}, {"input": "10\r\n384\r\n179\r\n982\r\n466\r\n646\r\n226\r\n759\r\n798\r\n291\r\n852\r\n", "output"... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
lines = f.read().splitlines()
n = int(lines[0])
ais = lines[1:1+n]
with open(submission_path) as f:
submission = f.read().splitlines()
if... | true |
493/A | 493 | A | PyPy 3 | TESTS | 8 | 108 | 20,172,800 | 127315833 | homeTeam = input()
awayTeam = input()
n = int(input())
result=[]
awayMap={}
homeMap={}
for _ in range(n):
a,b,c,d = map(str,input().split())
if b=='a':
if c in awayMap:
if awayMap[c][0]>=2:
pass
else:
if d=='y':
... | 18 | 61 | 0 | 10381058 | h = input()
a = input()
n = int(input())
d = dict()
for i in range(n):
arr = input().split()
mark = (h if arr[1] == 'h' else a) + ' ' + arr[2]
if mark not in d:
d[mark] = 0
if d[mark] < 2:
d[mark] += 1 if arr[3] == 'y' else 2
if d[mark] >= 2:
print(mark, arr[0]) | Codeforces Round 281 (Div. 2) | CF | 2,014 | 2 | 256 | Vasya and Football | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls tha... | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number n (1 ≤ n ≤ 90) — the... | For each event when a player received his first red card in a chronological order print a string containing the following information:
- The name of the team to which the player belongs;
- the player's number in his team;
- the minute when he received the card.
If no player received a card, then you do not need to pr... | null | null | [{"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "output": "MC 25 70\nMC 42 82\nCSKA 13 90"}] | 1,300 | ["implementation"] | 18 | [{"input": "MC\r\nCSKA\r\n9\r\n28 a 3 y\r\n62 h 25 y\r\n66 h 42 y\r\n70 h 25 y\r\n77 a 4 y\r\n79 a 25 y\r\n82 h 42 r\r\n89 h 16 y\r\n90 a 13 r\r\n", "output": "MC 25 70\r\nMC 42 82\r\nCSKA 13 90\r\n"}, {"input": "REAL\r\nBARCA\r\n3\r\n27 h 7 y\r\n44 a 10 y\r\n87 h 3 r\r\n", "output": "REAL 3 87\r\n"}, {"input": "MASFF\... | false | stdio | null | true |
165/A | 165 | A | PyPy 3-64 | TESTS | 9 | 124 | 0 | 167721025 | import sys
input = sys.stdin.readline
test = False
mod1, mod2 = 10 ** 9 + 7, 998244353
inf = 10 ** 18 + 5
lim = 2 * 10 ** 5 + 5
def test_case():
n = int(input())
coor = []
x_coor = [[] for _ in range(1005)]
y_coor = [[] for _ in range(1005)]
for i in range(n):
cur = list(map(int, in... | 26 | 92 | 0 | 137067791 | n=int(input())
a=[]
for i in range(n):
a.append([int(i) for i in input().split()])
a=sorted(a)
ans=0
for i in range(n):
con=[False,False,False,False]
x0=a[i][0]
y0=a[i][1]
for j in range(0,len(a)):
if x0==a[j][0]:
if y0<a[j][1]:
con[2]=True
elif y0>a[j... | Codeforces Round 112 (Div. 2) | CF | 2,012 | 2 | 256 | Supercentral Point | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
- point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
- point (x', y') is (x, y)'s left neighbor, i... | The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed t... | Print the only number — the number of supercentral points of the given set. | null | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | [{"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2"}, {"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1"}] | 1,000 | ["implementation"] | 26 | [{"input": "8\r\n1 1\r\n4 2\r\n3 1\r\n1 2\r\n0 2\r\n0 1\r\n1 0\r\n1 3\r\n", "output": "2\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n1 0\r\n0 -1\r\n-1 0\r\n", "output": "1\r\n"}, {"input": "9\r\n-565 -752\r\n-184 723\r\n-184 -752\r\n-184 1\r\n950 723\r\n-565 723\r\n950 -752\r\n950 1\r\n-565 1\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
294/A | 294 | A | PyPy 3-64 | TESTS | 30 | 92 | 0 | 213798124 | n = int(input())
array = input().split()
array = [int(x) for x in array]
m = int(input())
x = []
y = []
for i in range(m):
a, b = input().split()
x.append(int(a))
y.append(int(b))
if n == 1:
array[0] = 0
else:
for i in range(m):
if x[i] == 1:
array[0+1] += array[0] - y[i]
... | 31 | 62 | 0 | 145704448 | n = int(input())
A = list(map(int, input().split()))
m = int(input())
for i in range(m):
x, y = map(int, input().split()); x -= 1; y -= 1
if x > 0: A[x-1] += y
if x < n-1: A[x+1] += A[x]-y-1
A[x] = 0
for a in A:
print(a) | Codeforces Round 178 (Div. 2) | CF | 2,013 | 2 | 256 | Shaass and Oskols | 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 ... | The first line of the input contains an integer n, (1 ≤ n ≤ 100). The next line contains a list of space-separated integers a1, a2, ..., an, (0 ≤ ai ≤ 100).
The third line contains an integer m, (0 ≤ m ≤ 100). Each of the next m lines contains two integers xi and yi. The integers mean that for the i-th time Shaass sho... | On the i-th line of the output print the number of birds on the i-th wire. | null | null | [{"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16"}, {"input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3"}] | 800 | ["implementation", "math"] | 31 | [{"input": "5\r\n10 10 10 10 10\r\n5\r\n2 5\r\n3 13\r\n2 12\r\n1 13\r\n4 6\r\n", "output": "0\r\n12\r\n5\r\n0\r\n16\r\n"}, {"input": "3\r\n2 4 1\r\n1\r\n2 2\r\n", "output": "3\r\n0\r\n3\r\n"}, {"input": "5\r\n58 51 45 27 48\r\n5\r\n4 9\r\n5 15\r\n4 5\r\n5 8\r\n1 43\r\n", "output": "0\r\n66\r\n57\r\n7\r\n0\r\n"}, {"inpu... | false | stdio | null | true |
294/C | 294 | C | Python 3 | TESTS | 4 | 109 | 307,200 | 68315251 | def fac(x):
pr = 1
for i in range(2, x + 1):
pr *= i
return pr
n, m = map(int, input().split())
a = list(map(int, input().split()))
x = a[0] - 1
y = n - a[-1]
mn1 = 1
mn2 = 1
for i in range(1, m):
mn1 *= fac(a[i] - a[i - 1] - 1)
mn2 *= (2 ** (a[i] - a[i - 1] - 2))
ans = fac(n - m) // (fac(x) * fac(y) * mn1) * ... | 30 | 108 | 307,200 | 102414504 | from sys import stdin, stdout
def main():
p = 1000000007 # Constante brindada por el problema
n, m = readline()
on = sorted(readline()) # Se ordena de menor a mayor los elementos del conjunto de luces encendidas
off = [] # Conjunto de cardinalidades de los segmentos de luces apagadas
sum_ = 0
... | Codeforces Round 178 (Div. 2) | CF | 2,013 | 1 | 256 | Shaass and Lights | There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is alrea... | The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 ≤ n ≤ 1000, 1 ≤ m ≤ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initia... | In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7). | null | null | [{"input": "3 1\n1", "output": "1"}, {"input": "4 2\n1 4", "output": "2"}, {"input": "11 2\n4 8", "output": "6720"}] | 1,900 | ["combinatorics", "number theory"] | 30 | [{"input": "3 1\r\n1\r\n", "output": "1\r\n"}, {"input": "4 2\r\n1 4\r\n", "output": "2\r\n"}, {"input": "11 2\r\n4 8\r\n", "output": "6720\r\n"}, {"input": "4 2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4\r\n", "output": "1\r\n"}, {"input": "4 2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4... | false | stdio | null | true |
294/A | 294 | A | Python 3 | TESTS | 30 | 218 | 307,200 | 93028191 | I = input
n = int(I())
a = list(map(int, I().split()))
m = int(I())
if n==1:
print(0)
else:
for i in range(m):
x, y = map(int, I().split())
if x==1:
a[x]+=(a[x-1]-y)
a[x-1]=0
elif x==n:
a[x-2]+=(y-1)
a[x-1]=0
else:
a[x-2]+=(y-1)
a[x]+=(a[x-1]-y)
a[x-1]=0
for i in range(n):
print(a[i]) | 31 | 62 | 0 | 148939018 | n = int(input())
a = [int(a) for a in input().split()[:n]]
m = int(input())
for line in range(m):
x,y = [int(x) for x in input().split()]
down = a[x-1] - y
up = y-1
a[x-1] = 0
if x < len(a):
a[x] = a[x] + down
if x > 1:
a[x-2] = a[x-2] + up
for i in a:
print(i) | Codeforces Round 178 (Div. 2) | CF | 2,013 | 2 | 256 | Shaass and Oskols | 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 ... | The first line of the input contains an integer n, (1 ≤ n ≤ 100). The next line contains a list of space-separated integers a1, a2, ..., an, (0 ≤ ai ≤ 100).
The third line contains an integer m, (0 ≤ m ≤ 100). Each of the next m lines contains two integers xi and yi. The integers mean that for the i-th time Shaass sho... | On the i-th line of the output print the number of birds on the i-th wire. | null | null | [{"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16"}, {"input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3"}] | 800 | ["implementation", "math"] | 31 | [{"input": "5\r\n10 10 10 10 10\r\n5\r\n2 5\r\n3 13\r\n2 12\r\n1 13\r\n4 6\r\n", "output": "0\r\n12\r\n5\r\n0\r\n16\r\n"}, {"input": "3\r\n2 4 1\r\n1\r\n2 2\r\n", "output": "3\r\n0\r\n3\r\n"}, {"input": "5\r\n58 51 45 27 48\r\n5\r\n4 9\r\n5 15\r\n4 5\r\n5 8\r\n1 43\r\n", "output": "0\r\n66\r\n57\r\n7\r\n0\r\n"}, {"inpu... | false | stdio | null | true |
294/A | 294 | A | Python 3 | TESTS | 30 | 218 | 307,200 | 69433370 | n=int(input())
a=list(map(int,input().split()))
m=int(input())
l=[]
for i in range(m):
k=list(map(int,input().split()))
l.append(k)
if n==1:
print(0)
else:
for i in range(m):
if l[i][0]-1==0:
a[l[i][0]]+= a[l[i][0]-1]-l[i][1]
a[l[i][0]-1]=0
elif l[i][0]-1==n-1:
a[l[i][0]-2]+=l[i][1]-1
a[l[i][0]-1]... | 31 | 62 | 0 | 149637842 | n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
for i in range(m):
wire , bird = [int(j) for j in input().split()]
if wire < n:
a[wire] += a[wire - 1] - bird
if wire - 2 >= 0:
a[wire - 2] += bird - 1
a[wire - 1] = 0
for j in range(n):
print(a[j]) | Codeforces Round 178 (Div. 2) | CF | 2,013 | 2 | 256 | Shaass and Oskols | 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 ... | The first line of the input contains an integer n, (1 ≤ n ≤ 100). The next line contains a list of space-separated integers a1, a2, ..., an, (0 ≤ ai ≤ 100).
The third line contains an integer m, (0 ≤ m ≤ 100). Each of the next m lines contains two integers xi and yi. The integers mean that for the i-th time Shaass sho... | On the i-th line of the output print the number of birds on the i-th wire. | null | null | [{"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16"}, {"input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3"}] | 800 | ["implementation", "math"] | 31 | [{"input": "5\r\n10 10 10 10 10\r\n5\r\n2 5\r\n3 13\r\n2 12\r\n1 13\r\n4 6\r\n", "output": "0\r\n12\r\n5\r\n0\r\n16\r\n"}, {"input": "3\r\n2 4 1\r\n1\r\n2 2\r\n", "output": "3\r\n0\r\n3\r\n"}, {"input": "5\r\n58 51 45 27 48\r\n5\r\n4 9\r\n5 15\r\n4 5\r\n5 8\r\n1 43\r\n", "output": "0\r\n66\r\n57\r\n7\r\n0\r\n"}, {"inpu... | false | stdio | null | true |
294/A | 294 | A | PyPy 3 | TESTS | 30 | 248 | 0 | 106993025 | numWires = int(input())
a = list(map(int, input().split()))
numShots = int(input())
if len(a) == 1:
a = [0]
else:
for i in range(numShots):
shot = list(map(int, input().split()))
if shot[0] == len(a):
a[shot[0] - 2] += shot[1] - 1
elif shot[0] == 1:
a[shot[0]] += ... | 31 | 62 | 0 | 174729836 | import sys
from math import gcd
def inp() : return sys.stdin.readline().strip()
def get_ints(): return map(int, inp().split())
def get_arr(): return list(map(int, inp().split()))
def get_int(): return int(inp())
n=get_int()
os=get_arr()
t=get_int()
for _ in range(t):
x,y=get_ints()
x-=1
if(x-1>=0 and x+1<n):
... | Codeforces Round 178 (Div. 2) | CF | 2,013 | 2 | 256 | Shaass and Oskols | 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 ... | The first line of the input contains an integer n, (1 ≤ n ≤ 100). The next line contains a list of space-separated integers a1, a2, ..., an, (0 ≤ ai ≤ 100).
The third line contains an integer m, (0 ≤ m ≤ 100). Each of the next m lines contains two integers xi and yi. The integers mean that for the i-th time Shaass sho... | On the i-th line of the output print the number of birds on the i-th wire. | null | null | [{"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16"}, {"input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3"}] | 800 | ["implementation", "math"] | 31 | [{"input": "5\r\n10 10 10 10 10\r\n5\r\n2 5\r\n3 13\r\n2 12\r\n1 13\r\n4 6\r\n", "output": "0\r\n12\r\n5\r\n0\r\n16\r\n"}, {"input": "3\r\n2 4 1\r\n1\r\n2 2\r\n", "output": "3\r\n0\r\n3\r\n"}, {"input": "5\r\n58 51 45 27 48\r\n5\r\n4 9\r\n5 15\r\n4 5\r\n5 8\r\n1 43\r\n", "output": "0\r\n66\r\n57\r\n7\r\n0\r\n"}, {"inpu... | false | stdio | null | true |
730/G | 730 | G | PyPy 3 | TESTS | 6 | 155 | 4,812,800 | 160374723 | from bisect import *
from collections import *
import sys
import io, os
import math
import random
from heapq import *
gcd = math.gcd
sqrt = math.sqrt
def ceil(a, b):
a = -a
k = a // b
k = -k
return k
# arr=list(map(int, input().split()))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def s... | 28 | 280 | 307,200 | 101603018 | n = int(input())
l, r = [0] * n, [0] * n
f = lambda x, y: all(x > r[j] or y < l[j] for j in range(i))
for i in range(n):
x, d = map(int, input().split())
y = x + d - 1
if not f(x, y):
k = min(r[j] for j in range(i + 1) if f(r[j] + 1, r[j] + d))
x, y = k + 1, k + d
l[i], r[i] = x, y... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Car Repair Shop | Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order... | The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients.
The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number ... | Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car. | null | null | [{"input": "3\n9 2\n7 3\n2 4", "output": "9 10\n1 3\n4 7"}, {"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000", "output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000"}] | 1,600 | ["implementation"] | 28 | [{"input": "3\r\n9 2\r\n7 3\r\n2 4\r\n", "output": "9 10\r\n1 3\r\n4 7\r\n"}, {"input": "4\r\n1000000000 1000000\r\n1000000000 1000000\r\n100000000 1000000\r\n1000000000 1000000\r\n", "output": "1000000000 1000999999\r\n1 1000000\r\n100000000 100999999\r\n1000001 2000000\r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 1\... | false | stdio | null | true |
45/C | 45 | C | PyPy 3-64 | TESTS | 10 | 77 | 3,072,000 | 182407187 | import sys
input = sys.stdin.readline
from heapq import heappop,heappush
n=int(input())
S=input().strip()
A=list(map(int,input().split()))
LEFT=[i-1 for i in range(n)]
RIGHT=[i+1 for i in range(n)]
USE=[0]*n
H=[]
for i in range(n-1):
if S[i]!=S[i+1]:
heappush(H,(abs(A[i]-A[i+1]),i))
H.sort()
ANS=[]
w... | 31 | 1,106 | 68,505,600 | 216640543 | from heapq import heappush, heappop, heapify
def improve_arrangement(n, b, a):
c = []
d = [0] * n
e = []
ahead = [0] + [i for i in range(n)]
after = [i + 1 for i in range(n)] + [0]
num = 0
for i in range(n - 1):
x = i
y = i + 1
if b[x] != b[y]:
c.append(... | School Team Contest 3 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | Dancing Lessons | There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi... | The first line contains an integer n (1 ≤ n ≤ 2·105) — the number of people. The next line contains n symbols B or G without spaces. B stands for a boy, G stands for a girl. The third line contains n space-separated integers ai (1 ≤ ai ≤ 107) — the dancing skill. People are specified from left to right in the order in ... | Print the resulting number of couples k. Then print k lines containing two numerals each — the numbers of people forming the couple. The people are numbered with integers from 1 to n from left to right. When a couple leaves to dance you shouldn't renumber the people. The numbers in one couple should be sorted in the in... | null | null | [{"input": "4\nBGBG\n4 2 4 3", "output": "2\n3 4\n1 2"}, {"input": "4\nBBGG\n4 6 1 5", "output": "2\n2 3\n1 4"}, {"input": "4\nBGBB\n1 1 2 3", "output": "1\n1 2"}] | 1,900 | ["data structures"] | 31 | [{"input": "4\r\nBGBG\r\n4 2 4 3\r\n", "output": "2\r\n3 4\r\n1 2\r\n"}, {"input": "4\r\nBBGG\r\n4 6 1 5\r\n", "output": "2\r\n2 3\r\n1 4\r\n"}, {"input": "4\r\nBGBB\r\n1 1 2 3\r\n", "output": "1\r\n1 2\r\n"}, {"input": "1\r\nB\r\n490297\r\n", "output": "0\r\n"}, {"input": "2\r\nBB\r\n2518190 6313112\r\n", "output": "0... | false | stdio | null | true |
452/F | 452 | F | Python 3 | TESTS | 0 | 31 | 0 | 177090959 | # LUOGU_RID: 90672285
from random import choice
a = choice(["YES", "NO"])
print(a) | 100 | 374 | 46,694,400 | 122667287 | n = int(input())
v = list(map(int, input().split()))
ans = "NO"
p = []
for i in range(n + 1):
p.append(-1)
for i in range(n):
p[v[i]] = i
for i in range(n - 1):
for j in range(i + 1, min(n, i + 6)):
if v[i] * 2 - v[j] >= 1 and v[i] * 2 - v[j] <= n and p[v[i] * 2 - v[j]] < i:
ans = "YES"
... | MemSQL Start[c]UP 2.0 - Round 1 | CF | 2,014 | 1 | 256 | Permutation | You are given a permutation of numbers from 1 to n. Determine whether there's a pair of integers a, b (1 ≤ a, b ≤ n; a ≠ b) such that the element $${ \frac { ( a + b ) } { 2 } }$$ (note, that it is usual division, not integer one) is between a and b in this permutation. | First line consists of a single integer n (1 ≤ n ≤ 300000) — the size of permutation.
Second line contains n integers — the permutation itself. | Print "YES", if such a pair exists, "NO" otherwise (in both cases without quotes, the answer is case insensitive). | null | In the second example 2 is between 1 and 3. Additionally 4 is between 3 and 5. | [{"input": "4\n1 3 4 2", "output": "NO"}, {"input": "5\n1 5 2 4 3", "output": "YES"}] | 2,700 | ["data structures", "divide and conquer", "hashing"] | 100 | [{"input": "4\r\n1 3 4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 5 2 4 3\r\n", "output": "YES\r\n"}, {"input": "100\r\n17 41 19 23 46 16 10 31 82 12 77 32 11 71 83 25 98 18 34 59 13 73 80 65 37 22 6 2 24 5 94 42 51 63 52 92 97 26 93 38 36 87 64 70 14 43 68 85 33 44 74 89 56 1 69 88 20 49 48 21 84 90 7 47 39 55 81 ... | false | stdio | null | true |
297/A | 297 | A | PyPy 3 | TESTS | 31 | 310 | 0 | 84234237 | a=input()
b=input()
coa=0
cob=0
for i in a:
if i=='1': coa+=1
for i in b:
if i=='1': cob+=1
if coa%2==1:
print('YES')
else:
if cob>coa: print('NO')
else: print('YES') | 79 | 122 | 4,608,000 | 29355698 | ax, bx = 0, 0
for c in input():
if c == '1':
ax += 1
for c in input():
if c == '1':
bx += 1
print("YES" if bx <= ax + ax % 2 else "NO") | Codeforces Round 180 (Div. 1) | CF | 2,013 | 1 | 256 | Parity Game | You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations:
- Write parity(a) ... | The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. | Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. | null | In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 | [{"input": "01011\n0110", "output": "YES"}, {"input": "0011\n1110", "output": "NO"}] | 1,700 | ["constructive algorithms"] | 79 | [{"input": "01011\r\n0110\r\n", "output": "YES\r\n"}, {"input": "0011\r\n1110\r\n", "output": "NO\r\n"}, {"input": "11111\r\n111111\r\n", "output": "YES\r\n"}, {"input": "0110011\r\n01100110\r\n", "output": "YES\r\n"}, {"input": "10000100\r\n011110\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}... | false | stdio | null | true |
547/D | 547 | D | PyPy 3-64 | TESTS | 0 | 46 | 0 | 224154830 | n = int(input())
points = []
for _ in range(n):
x, y = map(int, input().split())
points.append((x, y))
# Sort the points by x-coordinates and then by y-coordinates
points.sort()
colors = [None] * n
red_count = 0
blue_count = 0
for i in range(n):
x, y = points[i]
if red_count <= blue_count:
# ... | 50 | 889 | 112,640,000 | 224152629 | from sys import stdin, stdout
from collections import defaultdict
time = 0
c = 2*10**5
n = 4*10**5+2
col = 0
finished= [0]*n
for_node = [0]*n
f_range=range
f_len=len
def dfs_euler_tour(node: int, graph):
stack = []
global colour
global col
global time
stack.append((node, -1))
while stack:
... | Codeforces Round 305 (Div. 1) | CF | 2,015 | 3 | 256 | Mike and Fish | As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange thing about him is he has an infinite number of blue and red fish.
He has marked n distinct points in the plane. i-th point is point (xi, yi). He wants to put exactly one fish in each of these points such that the diff... | The first line of input contains integer n (1 ≤ n ≤ 2 × 105).
The next n lines contain the information about the points, i-th line contains two integers xi and yi (1 ≤ xi, yi ≤ 2 × 105), the i-th point coordinates.
It is guaranteed that there is at least one valid answer. | Print the answer as a sequence of n characters 'r' (for red) or 'b' (for blue) where i-th character denotes the color of the fish in the i-th point. | null | null | [{"input": "4\n1 1\n1 2\n2 1\n2 2", "output": "brrb"}, {"input": "3\n1 1\n1 2\n2 1", "output": "brr"}] | 2,600 | ["constructive algorithms", "dfs and similar", "graphs"] | 50 | [{"input": "4\r\n1 1\r\n1 2\r\n2 1\r\n2 2\r\n", "output": "brrb\r\n"}, {"input": "3\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "brr\r\n"}, {"input": "3\r\n157210 22861\r\n175396 39466\r\n40933 17093\r\n", "output": "rrr\r\n"}, {"input": "5\r\n55599 84144\r\n169207 98421\r\n1909 186625\r\n31525 147710\r\n7781 82078\r\n", "out... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
n = int(f.readline())
points = []
for _ in range(n):
x, y = map(int, f.readline().split())
points.append((x, y))
... | true |
58/C | 58 | C | PyPy 3 | TESTS | 5 | 280 | 0 | 91777469 | n=int(input())
l=list(map(int,input().split()))
x=n-1
ans=float('inf')
for i in range((n>>1)):
j=i
k=i-1
front=l[i]
back=l[i]
c=0
while j<(n>>1):
if l[j]==front:
if l[x-j]!=front:
c+=1
else:
c+=1
if l[x-j]!=front:
... | 40 | 342 | 7,577,600 | 188863469 | # LUOGU_RID: 99389245
n = int(input())
s = 0
t = [0]*100005
ms = list(map(int,input().split()))
a = 0
for i in ms:
a += 1
i -= min(a,n-a+1)
if i >= 0:
t[i-1] += 1
s = max(s,t[i-1])
print(n-s) | Codeforces Beta Round 54 (Div. 2) | CF | 2,011 | 2 | 256 | Trees | On Bertown's main street n trees are growing, the tree number i has the height of ai meters (1 ≤ i ≤ n). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a beautiful sequence. This means that the heights of trees on ends (the 1st one and the n-th one) should... | The first line contains integer n (1 ≤ n ≤ 105) which is the number of trees. The second line contains integers ai (1 ≤ ai ≤ 105) which are the heights of the trees. | Print a single number which is the minimal number of trees whose heights will have to be changed for the sequence to become beautiful. | null | null | [{"input": "3\n2 2 2", "output": "1"}, {"input": "4\n1 2 2 1", "output": "0"}] | 1,800 | ["brute force"] | 40 | [{"input": "3\r\n2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 2 2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n61452 50974 73849\r\n", "output": "2\r\n"}, {"input": "4\r\n86002 1199 86003 86002\r\n", "output": "1\r\n"}, {"input": "5\r\n92605 92606 41969 98774 92605\r\n", "output": "2\r\n"}, {"input": "10\r\n1 1 2 3... | false | stdio | null | true |
730/G | 730 | G | Python 3 | TESTS | 6 | 46 | 204,800 | 21708503 | import sys
lines = iter(sys.stdin.read().splitlines())
next(lines)
s,d = map(int,next(lines).split())
dates = [[0,0],[s, s + d -1],[1000000001,1000000001]]
res = [[s, s + d -1]]
for line in lines:
s,d = map(int,line.split())
nhueco = True
for i in range(len(dates)):
if s > dates[i][1] and s+d-1 < dates[i... | 28 | 1,232 | 0 | 49084217 | n = int(input())
cur = []
def good(s, e):
if s < 1:
return False
assert s <= e
for l, r in cur:
if max(l, s) <= min(r, e):
return False
return True
for i in range(n):
s, d = map(int, input().split())
e = s+d-1
if not good(s, e):
s = int(2e9)
if good(1, d):
s = 1
for l, r in cur:
if good(l-d,... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Car Repair Shop | Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order... | The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients.
The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number ... | Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car. | null | null | [{"input": "3\n9 2\n7 3\n2 4", "output": "9 10\n1 3\n4 7"}, {"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000", "output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000"}] | 1,600 | ["implementation"] | 28 | [{"input": "3\r\n9 2\r\n7 3\r\n2 4\r\n", "output": "9 10\r\n1 3\r\n4 7\r\n"}, {"input": "4\r\n1000000000 1000000\r\n1000000000 1000000\r\n100000000 1000000\r\n1000000000 1000000\r\n", "output": "1000000000 1000999999\r\n1 1000000\r\n100000000 100999999\r\n1000001 2000000\r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 1\... | false | stdio | null | true |
730/G | 730 | G | Python 3 | TESTS | 6 | 62 | 204,800 | 21808751 | n=int(input())
p=1
L=[]
m,M=0,0
for j in range(n):
ch=input().split()
s,d=int(ch[0]),int(ch[1])
if j==0:
m=s
M=s+d-1
print(s,d+s-1)
L.append([s,s+d-1])
L.sort()
else:
B=True
C=True
for i in range(len(L)):
if i<(len(... | 28 | 77 | 307,200 | 21705313 | from bisect import bisect_left, insort_left
a = []
n = int(input())
for _ in range(n):
#print(a)
s, d = map(int, input().split())
if len(a) == 0:
print(s, s+d - 1)
a.append((s, s + d - 1))
continue
p = bisect_left(a, (s, s + d - 1))
#print('p', p)
ok = True
if p > 0 a... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Car Repair Shop | Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order... | The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients.
The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number ... | Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car. | null | null | [{"input": "3\n9 2\n7 3\n2 4", "output": "9 10\n1 3\n4 7"}, {"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000", "output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000"}] | 1,600 | ["implementation"] | 28 | [{"input": "3\r\n9 2\r\n7 3\r\n2 4\r\n", "output": "9 10\r\n1 3\r\n4 7\r\n"}, {"input": "4\r\n1000000000 1000000\r\n1000000000 1000000\r\n100000000 1000000\r\n1000000000 1000000\r\n", "output": "1000000000 1000999999\r\n1 1000000\r\n100000000 100999999\r\n1000001 2000000\r\n"}, {"input": "1\r\n1 1\r\n", "output": "1 1\... | false | stdio | null | true |
493/A | 493 | A | Python 3 | TESTS | 8 | 109 | 0 | 61548468 | team = {"h" : input(),
"a" : input()}
n = int(input())
d = {}
for x in range(n):
t, ha, num, card = input().split()
if (ha,num) not in d:
d[(ha,num)] = (t,card)
else:
if d[(ha,num)][1] == "y":
d[(ha,num)] = (t,"r")
lis = d.items()
nlis = [x for x in... | 18 | 61 | 0 | 16709746 | teams = dict()
teams['h'] = input()
teams['a'] = input()
n = int(input())
data = {}
report = []
for _ in range(n):
time, team, num, card = input().split()
name = team+num
if name not in data:
data[name] = card
if card == 'r':
report.append("{} {} {}".format(teams[team], num, time... | Codeforces Round 281 (Div. 2) | CF | 2,014 | 2 | 256 | Vasya and Football | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls tha... | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number n (1 ≤ n ≤ 90) — the... | For each event when a player received his first red card in a chronological order print a string containing the following information:
- The name of the team to which the player belongs;
- the player's number in his team;
- the minute when he received the card.
If no player received a card, then you do not need to pr... | null | null | [{"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r", "output": "MC 25 70\nMC 42 82\nCSKA 13 90"}] | 1,300 | ["implementation"] | 18 | [{"input": "MC\r\nCSKA\r\n9\r\n28 a 3 y\r\n62 h 25 y\r\n66 h 42 y\r\n70 h 25 y\r\n77 a 4 y\r\n79 a 25 y\r\n82 h 42 r\r\n89 h 16 y\r\n90 a 13 r\r\n", "output": "MC 25 70\r\nMC 42 82\r\nCSKA 13 90\r\n"}, {"input": "REAL\r\nBARCA\r\n3\r\n27 h 7 y\r\n44 a 10 y\r\n87 h 3 r\r\n", "output": "REAL 3 87\r\n"}, {"input": "MASFF\... | false | stdio | null | true |
298/B | 298 | B | Python 3 | TESTS | 30 | 404 | 1,126,400 | 15184842 | from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
from collections import *
setrecursionlimit(10**7)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
RI=lambda: list(map(int,input().split()))
RS=lambda: input().rstrip().split()
#####################... | 43 | 122 | 102,400 | 205879989 | m,a,ay,b,by=map(int,input().split());s=input()+'0'
x='W'if a>b else 'E'
y='S'if ay>by else 'N'
c,d=abs(a-b),abs(ay-by)
for i in range(m):
if s[i]==x and c>0:c-=1
if s[i]==y and d>0:d-=1
if c==d==0:print(i+1);break
else:print(-1) | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Sail | The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).
- If the wind blows to the east, the boat will move to (x + 1, y).
- If... | The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105, - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.
The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E... | If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | null | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | [{"input": "5 0 0 1 1\nSESNW", "output": "4"}, {"input": "10 5 3 3 6\nNENSWESNEE", "output": "-1"}] | 1,200 | ["brute force", "greedy", "implementation"] | 43 | [{"input": "5 0 0 1 1\r\nSESNW\r\n", "output": "4\r\n"}, {"input": "10 5 3 3 6\r\nNENSWESNEE\r\n", "output": "-1\r\n"}, {"input": "19 -172106364 -468680119 -172106365 -468680119\r\nSSEEESSSESESWSEESSS\r\n", "output": "13\r\n"}, {"input": "39 -1000000000 -1000000000 -999999997 -1000000000\r\nENEENWSWSSWESNSSEESNSESWSWNS... | false | stdio | null | true |
429/B | 429 | B | PyPy 3 | TESTS | 2 | 140 | 22,630,400 | 115454700 | from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, log2, sqrt
import bisect
import copy
from itertools import combinations
import sys
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().spli... | 30 | 327 | 65,536,000 | 199930474 | import sys
input = sys.stdin.readline
def f(i1, i2, i3, j1, j2, j3):
w = [[0]*(m+2) for _ in range(n+2)]
for i in range(i1, i2, i3):
for j in range(j1, j2, j3):
w[i][j] = max(w[i-i3][j], w[i][j-j3]) + g[i-1][j-1]
return w
n, m = map(int, input().split())
g = [list(map(int, input().sp... | Codeforces Round 245 (Div. 1) | CF | 2,014 | 2 | 256 | Working out | Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column.
Iahub starts with ... | The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000). Each of the next n lines contains m integers: j-th number from i-th line denotes element a[i][j] (0 ≤ a[i][j] ≤ 105). | The output contains a single number — the maximum total gain possible. | null | Iahub will choose exercises a[1][1] → a[1][2] → a[2][2] → a[3][2] → a[3][3]. Iahubina will choose exercises a[3][1] → a[2][1] → a[2][2] → a[2][3] → a[1][3]. | [{"input": "3 3\n100 100 100\n100 1 100\n100 100 100", "output": "800"}] | 1,600 | ["dp"] | 30 | [{"input": "3 3\r\n100 100 100\r\n100 1 100\r\n100 100 100\r\n", "output": "800"}, {"input": "4 5\r\n87882 40786 3691 85313 46694\r\n28884 16067 3242 97367 78518\r\n4250 35501 9780 14435 19004\r\n64673 65438 56977 64495 27280\r\n", "output": "747898"}, {"input": "3 3\r\n3 1 2\r\n3 2 0\r\n2 3 2\r\n", "output": "16"}, {"... | false | stdio | null | true |
298/B | 298 | B | PyPy 3-64 | TESTS | 15 | 124 | 1,843,200 | 216531827 | t, x, y, xx, yy = map(int, input().split())
string = input()
count = 0
for i in string:
if xx > x:
if i == "E": x+=1
count += 1
elif xx < x:
if i == "W": x-=1
count += 1
elif yy < y:
if i == "S": y -= 1
count += 1
elif yy > y:
if i == "N": y += 1
... | 43 | 122 | 102,400 | 221732850 | def solve():
t,s,s1,e,e1=map(int,input().split())
di=input()
to=0
for i in di:
if(s==e and s1==e1):
print(to)
return
if(s>e):
if i=='W':
s-=1
elif(s<e):
if i=='E':
s+=1
if(s1>e1):
... | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Sail | The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).
- If the wind blows to the east, the boat will move to (x + 1, y).
- If... | The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105, - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.
The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E... | If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | null | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | [{"input": "5 0 0 1 1\nSESNW", "output": "4"}, {"input": "10 5 3 3 6\nNENSWESNEE", "output": "-1"}] | 1,200 | ["brute force", "greedy", "implementation"] | 43 | [{"input": "5 0 0 1 1\r\nSESNW\r\n", "output": "4\r\n"}, {"input": "10 5 3 3 6\r\nNENSWESNEE\r\n", "output": "-1\r\n"}, {"input": "19 -172106364 -468680119 -172106365 -468680119\r\nSSEEESSSESESWSEESSS\r\n", "output": "13\r\n"}, {"input": "39 -1000000000 -1000000000 -999999997 -1000000000\r\nENEENWSWSSWESNSSEESNSESWSWNS... | false | stdio | null | true |
297/A | 297 | A | Python 3 | TESTS | 9 | 218 | 0 | 42464327 | a=input()
b=input()
acount=0
bcount=0
for i in range(len(b), 0, -1):
if(b[i-1]=='0'):
bcount+=1
else:
break
if (bcount != 0):
b=b[:-bcount]
for i in range(len(a), 0, -1):
if(a[i-1]=='0'):
acount+=1
else:
break
if (acount != 0):
a=a[:-acount]
if (b == ''):
print('YES')
elif(b.count('1')%2==0):
if(b==... | 79 | 124 | 0 | 11884627 | a = (input().count('1') + 1) // 2
b = (input().count('1') + 1) // 2
print('YES' if a >= b else 'NO') | Codeforces Round 180 (Div. 1) | CF | 2,013 | 1 | 256 | Parity Game | You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations:
- Write parity(a) ... | The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. | Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. | null | In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 | [{"input": "01011\n0110", "output": "YES"}, {"input": "0011\n1110", "output": "NO"}] | 1,700 | ["constructive algorithms"] | 79 | [{"input": "01011\r\n0110\r\n", "output": "YES\r\n"}, {"input": "0011\r\n1110\r\n", "output": "NO\r\n"}, {"input": "11111\r\n111111\r\n", "output": "YES\r\n"}, {"input": "0110011\r\n01100110\r\n", "output": "YES\r\n"}, {"input": "10000100\r\n011110\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}... | false | stdio | null | true |
984/A | 984 | A | PyPy 3-64 | TESTS | 5 | 46 | 1,638,400 | 220942154 | a = int(input())
d = input().split()
c = 0
p = a
while a>1:
n = max(d)
d.remove(n)
c+=1
a-=1
if c!=p-1:
l = min(d)
d.remove(l)
c+=1
a-=1
print(*d) | 35 | 46 | 0 | 135926021 | n = int(input())
x = list(map(int, input().split()))
x = sorted(x)
if n % 2 == 1:
print(x[n//2])
elif n % 2 == 0:
print(x[n//2-1]) | Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] | CF | 2,018 | 2 | 256 | Game | Two players play a game.
Initially there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $$$n - 1$$$ turns are made. The first player makes the first move, t... | The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of numbers on the board.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$). | Print one number that will be left on the board. | null | In the first sample, the first player erases $$$3$$$ and the second erases $$$1$$$. $$$2$$$ is left on the board.
In the second sample, $$$2$$$ is left on the board regardless of the actions of the players. | [{"input": "3\n2 1 3", "output": "2"}, {"input": "3\n2 2 2", "output": "2"}] | 800 | ["sortings"] | 35 | [{"input": "3\r\n2 1 3\r\n", "output": "2"}, {"input": "3\r\n2 2 2\r\n", "output": "2"}, {"input": "9\r\n44 53 51 80 5 27 74 79 94\r\n", "output": "53"}, {"input": "10\r\n38 82 23 37 96 4 81 60 67 86\r\n", "output": "60"}, {"input": "10\r\n58 26 77 15 53 81 68 48 22 65\r\n", "output": "53"}, {"input": "1\r\n124\r\n", "... | false | stdio | null | true |
298/B | 298 | B | Python 3 | TESTS | 30 | 466 | 204,800 | 44844213 | BLOW = {'E': [1, 0],
'S': [0, -1],
'W': [-1, 0],
'N': [0, 1]}
t, x, y, a, b = map(int, input().split())
wind = input()
go = []
if x < a:
go.append('E')
if x > a:
go.append('W')
if y < b:
go.append('N')
if y > b:
go.append('S')
position = [x, y]
found = False
for i in range(... | 43 | 122 | 921,600 | 219378432 | t, sx, sy, ex, ey = map(int,input().split())
l = list(input())
x = ex - sx
y = ey - sy
xP = ""
yP = ""
if x > 0:
xP = "E"
else:
x = abs(x)
xP = "W"
if y > 0:
yP = "N"
else:
y = abs(y)
yP = "S"
loc = -1
for i,a in enumerate(l):
if a == xP and x > 0 : x -= 1
if a == yP and y > 0 : y -... | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Sail | The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).
- If the wind blows to the east, the boat will move to (x + 1, y).
- If... | The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105, - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.
The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E... | If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | null | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | [{"input": "5 0 0 1 1\nSESNW", "output": "4"}, {"input": "10 5 3 3 6\nNENSWESNEE", "output": "-1"}] | 1,200 | ["brute force", "greedy", "implementation"] | 43 | [{"input": "5 0 0 1 1\r\nSESNW\r\n", "output": "4\r\n"}, {"input": "10 5 3 3 6\r\nNENSWESNEE\r\n", "output": "-1\r\n"}, {"input": "19 -172106364 -468680119 -172106365 -468680119\r\nSSEEESSSESESWSEESSS\r\n", "output": "13\r\n"}, {"input": "39 -1000000000 -1000000000 -999999997 -1000000000\r\nENEENWSWSSWESNSSEESNSESWSWNS... | false | stdio | null | true |
297/A | 297 | A | PyPy 3-64 | TESTS | 23 | 186 | 512,000 | 142825339 | a=input()
b=input()
l=len(b)
a1=a.count('1')
b1=b.count('1')
r=0
c=False
for i in b:
if(i=='0'):
if((a1+r)%2==0):
l-=1
else:
a1-=1
l-=1
if(a1==0 and r!=b1):
c=True
break
else:
if((a1+r)%2==0):
... | 79 | 124 | 0 | 18871802 | def main():
a, b = (input().count('1') for _ in "ab")
print(("NO", "YES")[a + (a & 1) >= b])
if __name__ == '__main__':
main() | Codeforces Round 180 (Div. 1) | CF | 2,013 | 1 | 256 | Parity Game | You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations:
- Write parity(a) ... | The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. | Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. | null | In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 | [{"input": "01011\n0110", "output": "YES"}, {"input": "0011\n1110", "output": "NO"}] | 1,700 | ["constructive algorithms"] | 79 | [{"input": "01011\r\n0110\r\n", "output": "YES\r\n"}, {"input": "0011\r\n1110\r\n", "output": "NO\r\n"}, {"input": "11111\r\n111111\r\n", "output": "YES\r\n"}, {"input": "0110011\r\n01100110\r\n", "output": "YES\r\n"}, {"input": "10000100\r\n011110\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}... | false | stdio | null | true |
298/B | 298 | B | PyPy 3-64 | TESTS | 15 | 124 | 1,638,400 | 209295662 | n,sx,sy,ex,ey=list(map(int,input().split()))
r=input()
a,b=sx-ex,sy-ey
flag1,flag2,flag3,flag4=0,0,0,0
if a==0: flag1=1
if b==0:flag2=1
if a>0:flag3=1
if b>0 :flag4=1
i=0
if flag1 and flag2:
print(0)
elif flag1 and flag4:
while i<n and b!=0:
if r[i]=="S":
b-=1
i+=1
elif flag1 and no... | 43 | 124 | 102,400 | 220329146 | def timing():
t, sx, sy, ex, ey = map(int, input().split())
s = input()
for x in range(len(s)):
if s[x] == "E" and ex > sx:
sx = sx + 1
sy = sy
if s[x] == "S" and ey < sy:
sx = sx
sy = sy - 1
if s[x] == "W" and ex < sx:
sx =... | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Sail | The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).
- If the wind blows to the east, the boat will move to (x + 1, y).
- If... | The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105, - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.
The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E... | If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | null | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | [{"input": "5 0 0 1 1\nSESNW", "output": "4"}, {"input": "10 5 3 3 6\nNENSWESNEE", "output": "-1"}] | 1,200 | ["brute force", "greedy", "implementation"] | 43 | [{"input": "5 0 0 1 1\r\nSESNW\r\n", "output": "4\r\n"}, {"input": "10 5 3 3 6\r\nNENSWESNEE\r\n", "output": "-1\r\n"}, {"input": "19 -172106364 -468680119 -172106365 -468680119\r\nSSEEESSSESESWSEESSS\r\n", "output": "13\r\n"}, {"input": "39 -1000000000 -1000000000 -999999997 -1000000000\r\nENEENWSWSSWESNSSEESNSESWSWNS... | false | stdio | null | true |
297/A | 297 | A | Python 3 | TESTS | 10 | 216 | 0 | 42463964 | a=input()
b=input()
count=0
for i in range(len(b), 0, -1):
if(b[i-1]=='0'):
count+=1
else:
break
if (count != 0):
b=b[:-count]
count=0
for i in range(len(a), 0, -1):
if(a[i-1]=='0'):
count+=1
else:
break
if (count != 0):
a=a[:-count]
if (b == ''):
print('YES')
elif(b.count('1')%2==0):
if(b==(a[-len(... | 79 | 124 | 0 | 30093905 | a=input()
print('YES'if a.count('1')+(a.count('1')&1)>=input().count('1')else'NO') | Codeforces Round 180 (Div. 1) | CF | 2,013 | 1 | 256 | Parity Game | You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations:
- Write parity(a) ... | The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x. | Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise. | null | In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 | [{"input": "01011\n0110", "output": "YES"}, {"input": "0011\n1110", "output": "NO"}] | 1,700 | ["constructive algorithms"] | 79 | [{"input": "01011\r\n0110\r\n", "output": "YES\r\n"}, {"input": "0011\r\n1110\r\n", "output": "NO\r\n"}, {"input": "11111\r\n111111\r\n", "output": "YES\r\n"}, {"input": "0110011\r\n01100110\r\n", "output": "YES\r\n"}, {"input": "10000100\r\n011110\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}... | false | stdio | null | true |
429/B | 429 | B | Python 3 | TESTS | 2 | 109 | 0 | 45491862 | n, m = map(int, input().split())
a = [[int(x) for x in input().split()] for _ in range(n)]
tmp1 = [[None] * m for _ in range(n)]
tmp1[n - 1][m - 1] = a[n - 1][m - 1]
for i in range(n - 2, -1, -1):
tmp1[i][m - 1] = a[i][m - 1] + tmp1[i + 1][m - 1]
for j in range(m - 2, -1, -1):
tmp1[n - 1][j] = a[n - 1][j] + tm... | 30 | 358 | 122,777,600 | 146702661 | import os, sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd
from _collections import deque
import heapq as hp
from bisect import bisect_left, bisect_right
from math import cos, sin
from itertools import permutations
from operator import itemgetter
sys.setrecursionlimit(5 * 10 ** 4)
BUFSIZE = 8... | Codeforces Round 245 (Div. 1) | CF | 2,014 | 2 | 256 | Working out | Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column.
Iahub starts with ... | The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000). Each of the next n lines contains m integers: j-th number from i-th line denotes element a[i][j] (0 ≤ a[i][j] ≤ 105). | The output contains a single number — the maximum total gain possible. | null | Iahub will choose exercises a[1][1] → a[1][2] → a[2][2] → a[3][2] → a[3][3]. Iahubina will choose exercises a[3][1] → a[2][1] → a[2][2] → a[2][3] → a[1][3]. | [{"input": "3 3\n100 100 100\n100 1 100\n100 100 100", "output": "800"}] | 1,600 | ["dp"] | 30 | [{"input": "3 3\r\n100 100 100\r\n100 1 100\r\n100 100 100\r\n", "output": "800"}, {"input": "4 5\r\n87882 40786 3691 85313 46694\r\n28884 16067 3242 97367 78518\r\n4250 35501 9780 14435 19004\r\n64673 65438 56977 64495 27280\r\n", "output": "747898"}, {"input": "3 3\r\n3 1 2\r\n3 2 0\r\n2 3 2\r\n", "output": "16"}, {"... | false | stdio | null | true |
298/B | 298 | B | PyPy 3-64 | TESTS | 15 | 124 | 1,945,600 | 216540243 | t, x, y, xx, yy = map(int, input().split())
string = input()
count = 0
time = 0
n = 0
for i in (string):
if xx > x:
if i == "E": x+=1
count += 1
elif xx < x:
if i == "W": x-=1
count += 1
elif yy < y:
if i == "S": y -= 1
count += 1
elif yy > y:
if i... | 43 | 124 | 102,400 | 228184516 | t,sx,sy,ex,ey=map(int,input().split())
s=input()
h,v="Z","Z"
if(sx>ex):h="W"
elif(sx<ex):h="E"
if(sy>ey):v="S"
elif(sy<ey):v="N"
a,b=abs(sx-ex),abs(sy-ey);c=0
for i in s:
if(a or b):c+=1
if(h==i and a>0):
a-=1
if(v==i and b>0):
b-=1
if(a!=0 or b!=0):print(-1)
else:print(c) | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Sail | The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).
- If the wind blows to the east, the boat will move to (x + 1, y).
- If... | The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105, - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.
The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E... | If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | null | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | [{"input": "5 0 0 1 1\nSESNW", "output": "4"}, {"input": "10 5 3 3 6\nNENSWESNEE", "output": "-1"}] | 1,200 | ["brute force", "greedy", "implementation"] | 43 | [{"input": "5 0 0 1 1\r\nSESNW\r\n", "output": "4\r\n"}, {"input": "10 5 3 3 6\r\nNENSWESNEE\r\n", "output": "-1\r\n"}, {"input": "19 -172106364 -468680119 -172106365 -468680119\r\nSSEEESSSESESWSEESSS\r\n", "output": "13\r\n"}, {"input": "39 -1000000000 -1000000000 -999999997 -1000000000\r\nENEENWSWSSWESNSSEESNSESWSWNS... | false | stdio | null | true |
298/B | 298 | B | PyPy 3 | TESTS | 15 | 154 | 2,048,000 | 142587099 | t, sx, sy, ex, ey = [int(x) for x in input().split()]
wind_direction = input()
distance_x = ex - sx
distance_y = ey - sy
only_east = distance_x > 0
only_north = distance_y > 0
time = 0
for direction in wind_direction:
if distance_x == 0 and distance_y == 0:
break
dx = 0
dy = 0
if distance_... | 43 | 124 | 102,400 | 231316668 | t, sx, sy, ex, ey = list(map(int, input().split()))
s = input()
for _ in range(len(s)):
i = s[_]
if i == 'E':
if sx < ex:
sx += 1
elif i == 'S':
if sy > ey:
sy -= 1
elif i == 'W':
if sx > ex:
sx -= 1
else:
if sy < ey:
... | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Sail | The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).
- If the wind blows to the east, the boat will move to (x + 1, y).
- If... | The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105, - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.
The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E... | If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | null | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | [{"input": "5 0 0 1 1\nSESNW", "output": "4"}, {"input": "10 5 3 3 6\nNENSWESNEE", "output": "-1"}] | 1,200 | ["brute force", "greedy", "implementation"] | 43 | [{"input": "5 0 0 1 1\r\nSESNW\r\n", "output": "4\r\n"}, {"input": "10 5 3 3 6\r\nNENSWESNEE\r\n", "output": "-1\r\n"}, {"input": "19 -172106364 -468680119 -172106365 -468680119\r\nSSEEESSSESESWSEESSS\r\n", "output": "13\r\n"}, {"input": "39 -1000000000 -1000000000 -999999997 -1000000000\r\nENEENWSWSSWESNSSEESNSESWSWNS... | false | stdio | null | true |
803/F | 803 | F | PyPy 3 | TESTS | 10 | 170 | 1,740,800 | 59779640 | # 803F
import math
import collections
def do():
n = int(input())
nums = map(int, input().split(" "))
count = collections.defaultdict(int)
for num in nums:
for i in range(1, int(math.sqrt(num))+1):
cp = num // i
if num % i == 0:
count[i] += 1
if... | 35 | 124 | 14,950,400 | 220022104 | mod = 1000000007
N = 100001
is_prime = [True] * N
primes = []
mu = [0] * N
mu[1] = 1
pow2 = [0] * N
pow2[0] = 1
pow2[1] = 2
for i in range(2, N):
if is_prime[i]:
primes.append(i)
mu[i] = -1
for p in primes:
t = i * p
if t >= N:
break
is_prime[t] = False
... | Educational Codeforces Round 20 | ICPC | 2,017 | 2 | 256 | Coprime Subsequences | Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common divisor of all elements of this sequence is equal to 1.
Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 109 + 7.
Note th... | The first line contains one integer number n (1 ≤ n ≤ 100000).
The second line contains n integer numbers a1, a2... an (1 ≤ ai ≤ 100000). | Print the number of coprime subsequences of a modulo 109 + 7. | null | In the first example coprime subsequences are:
1. 1
2. 1, 2
3. 1, 3
4. 1, 2, 3
5. 2, 3
In the second example all subsequences are coprime. | [{"input": "3\n1 2 3", "output": "5"}, {"input": "4\n1 1 1 1", "output": "15"}, {"input": "7\n1 3 5 15 3 105 35", "output": "100"}] | 2,000 | ["bitmasks", "combinatorics", "number theory"] | 35 | [{"input": "3\r\n1 2 3\r\n", "output": "5\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "15\r\n"}, {"input": "7\r\n1 3 5 15 3 105 35\r\n", "output": "100\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n100000\r\n", "output": "0\r\n"}, {"input": "5\r\n10 8 6 4 6\r\n", "output": "0\r\n"}, {"input": "5... | false | stdio | null | true |
984/A | 984 | A | Python 3 | TESTS | 5 | 46 | 0 | 167451595 | n = int(input())
arr = list(input().split(" "))
arr.sort()
if(n % 2 == 0):
x = int(n/2)
print(arr[x-1])
else:
x = int((n+1)/2)
print(arr[x-1]) | 35 | 46 | 0 | 135985301 | n=int(input())
arr=list(map(int,input().split()))
arr.sort()
ans=arr[(n-1)//2]
print(ans) | Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] | CF | 2,018 | 2 | 256 | Game | Two players play a game.
Initially there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $$$n - 1$$$ turns are made. The first player makes the first move, t... | The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of numbers on the board.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$). | Print one number that will be left on the board. | null | In the first sample, the first player erases $$$3$$$ and the second erases $$$1$$$. $$$2$$$ is left on the board.
In the second sample, $$$2$$$ is left on the board regardless of the actions of the players. | [{"input": "3\n2 1 3", "output": "2"}, {"input": "3\n2 2 2", "output": "2"}] | 800 | ["sortings"] | 35 | [{"input": "3\r\n2 1 3\r\n", "output": "2"}, {"input": "3\r\n2 2 2\r\n", "output": "2"}, {"input": "9\r\n44 53 51 80 5 27 74 79 94\r\n", "output": "53"}, {"input": "10\r\n38 82 23 37 96 4 81 60 67 86\r\n", "output": "60"}, {"input": "10\r\n58 26 77 15 53 81 68 48 22 65\r\n", "output": "53"}, {"input": "1\r\n124\r\n", "... | false | stdio | null | true |
984/A | 984 | A | Python 3 | TESTS | 5 | 46 | 204,800 | 106509779 | c=int(input())
ar=(input().split())[:c]
##print(ar)
arr_sorted=sorted(ar)
##print(arr_sorted)
mid=int(c/2)
##print(*arr_sorted[mid],sep='')
if(c%2!=0):
print(*arr_sorted[mid],sep='')
else:
print(*arr_sorted[mid-1],sep='') | 35 | 46 | 0 | 136023668 | x = int(input())
arr = [int(q) for q in input().split()]
arr = sorted(arr)
while len(arr) != 1:
arr.pop(len(arr)-1)
if len(arr) != 1:
arr.pop(0)
print(arr[0]) | Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] | CF | 2,018 | 2 | 256 | Game | Two players play a game.
Initially there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $$$n - 1$$$ turns are made. The first player makes the first move, t... | The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of numbers on the board.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$). | Print one number that will be left on the board. | null | In the first sample, the first player erases $$$3$$$ and the second erases $$$1$$$. $$$2$$$ is left on the board.
In the second sample, $$$2$$$ is left on the board regardless of the actions of the players. | [{"input": "3\n2 1 3", "output": "2"}, {"input": "3\n2 2 2", "output": "2"}] | 800 | ["sortings"] | 35 | [{"input": "3\r\n2 1 3\r\n", "output": "2"}, {"input": "3\r\n2 2 2\r\n", "output": "2"}, {"input": "9\r\n44 53 51 80 5 27 74 79 94\r\n", "output": "53"}, {"input": "10\r\n38 82 23 37 96 4 81 60 67 86\r\n", "output": "60"}, {"input": "10\r\n58 26 77 15 53 81 68 48 22 65\r\n", "output": "53"}, {"input": "1\r\n124\r\n", "... | false | stdio | null | true |
429/B | 429 | B | PyPy 3 | TESTS | 2 | 77 | 409,600 | 215672038 | from collections import defaultdict
import math
import sys
from bisect import bisect_right
mod = pow(10,8)
def clc():
n,m = map(int,input().split())
a = []
for _ in range(n):
x = list(map(int,input().split()))
a.append(x)
b = [[0 for i in range(m)] for j in range(n)]
c = [[0 for i i... | 30 | 389 | 46,592,000 | 163195251 | import sys
input = sys.stdin.readline
M = int(1e9) + 7
n, m = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(n)]
dp11 = [[0 for _ in range(m+2)] for _ in range(n+2)]
for i in range(1, n+1):
for j in range(1, m+1):
dp11[i][j] = grid[i-1][j-1] + max(dp11[i-1][j], dp11[i][j... | Codeforces Round 245 (Div. 1) | CF | 2,014 | 2 | 256 | Working out | Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column.
Iahub starts with ... | The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000). Each of the next n lines contains m integers: j-th number from i-th line denotes element a[i][j] (0 ≤ a[i][j] ≤ 105). | The output contains a single number — the maximum total gain possible. | null | Iahub will choose exercises a[1][1] → a[1][2] → a[2][2] → a[3][2] → a[3][3]. Iahubina will choose exercises a[3][1] → a[2][1] → a[2][2] → a[2][3] → a[1][3]. | [{"input": "3 3\n100 100 100\n100 1 100\n100 100 100", "output": "800"}] | 1,600 | ["dp"] | 30 | [{"input": "3 3\r\n100 100 100\r\n100 1 100\r\n100 100 100\r\n", "output": "800"}, {"input": "4 5\r\n87882 40786 3691 85313 46694\r\n28884 16067 3242 97367 78518\r\n4250 35501 9780 14435 19004\r\n64673 65438 56977 64495 27280\r\n", "output": "747898"}, {"input": "3 3\r\n3 1 2\r\n3 2 0\r\n2 3 2\r\n", "output": "16"}, {"... | false | stdio | null | true |
298/B | 298 | B | PyPy 3 | TESTS | 30 | 310 | 22,118,400 | 88882456 | time, x1, y1, x2, y2 = map(int, input().split())
word = input()
up = True
east = True
required = abs(x2 - x1) + abs(y2 - y1)
if x2 - x1 < 0:
east = False
if y2 - y1 < 0:
up = False
if x2 - x1 == 0:
if up:
for spend, val in enumerate(word):
if val == 'N':
required -= 1
... | 43 | 124 | 614,400 | 108562921 | t,x1,y1,x2,y2 = map(int,input().split())
s = str(input())
a = x2 - x1
b = y2 - y1
from itertools import islice
def nth_index(iterable, value, n):
matches = (idx for idx, val in enumerate(iterable) if val == value)
return next(islice(matches, n-1, n), None)
if a > 0 and b > 0:
f = nth_index(s,'E',a)
l ... | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Sail | The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).
- If the wind blows to the east, the boat will move to (x + 1, y).
- If... | The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105, - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.
The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E... | If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | null | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | [{"input": "5 0 0 1 1\nSESNW", "output": "4"}, {"input": "10 5 3 3 6\nNENSWESNEE", "output": "-1"}] | 1,200 | ["brute force", "greedy", "implementation"] | 43 | [{"input": "5 0 0 1 1\r\nSESNW\r\n", "output": "4\r\n"}, {"input": "10 5 3 3 6\r\nNENSWESNEE\r\n", "output": "-1\r\n"}, {"input": "19 -172106364 -468680119 -172106365 -468680119\r\nSSEEESSSESESWSEESSS\r\n", "output": "13\r\n"}, {"input": "39 -1000000000 -1000000000 -999999997 -1000000000\r\nENEENWSWSSWESNSSEESNSESWSWNS... | false | stdio | null | true |
984/A | 984 | A | Python 3 | TESTS | 7 | 124 | 409,600 | 71547259 | def test_0():
# A -
import math
from collections import Counter
n = list(map(int, input().split(" ")))[0]
data = list(map(int, input().split(" ")))
data.sort()
if n == 1:
print(data[0])
# print(data)
k = n//2-1 if n %2==0 else n//2
print(data[k])
test_0() | 35 | 46 | 0 | 136385941 | n = int(input())
nums = list(map(int,input().split()))
nums.sort()
print(nums[(len(nums)-1)//2]) | Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] | CF | 2,018 | 2 | 256 | Game | Two players play a game.
Initially there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $$$n - 1$$$ turns are made. The first player makes the first move, t... | The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of numbers on the board.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$). | Print one number that will be left on the board. | null | In the first sample, the first player erases $$$3$$$ and the second erases $$$1$$$. $$$2$$$ is left on the board.
In the second sample, $$$2$$$ is left on the board regardless of the actions of the players. | [{"input": "3\n2 1 3", "output": "2"}, {"input": "3\n2 2 2", "output": "2"}] | 800 | ["sortings"] | 35 | [{"input": "3\r\n2 1 3\r\n", "output": "2"}, {"input": "3\r\n2 2 2\r\n", "output": "2"}, {"input": "9\r\n44 53 51 80 5 27 74 79 94\r\n", "output": "53"}, {"input": "10\r\n38 82 23 37 96 4 81 60 67 86\r\n", "output": "60"}, {"input": "10\r\n58 26 77 15 53 81 68 48 22 65\r\n", "output": "53"}, {"input": "1\r\n124\r\n", "... | false | stdio | null | true |
984/A | 984 | A | Python 3 | TESTS | 5 | 31 | 0 | 166401416 | n=int(input())
s=[]
f=[]
u=input()
s=u.split()
s=sorted(s)
for _ in range(1):
if(len(s)%2==1):
y=len(s)//2
f.append(s[y])
else:
z=(len(s)//2)-1
f.append(s[z])
print(*f) | 35 | 46 | 0 | 140945136 | n = int(input())
a = [int(i) for i in input().split()]
a.sort()
print(a[(n//2-1 if n % 2 == 0 else n//2)]) | Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] | CF | 2,018 | 2 | 256 | Game | Two players play a game.
Initially there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $$$n - 1$$$ turns are made. The first player makes the first move, t... | The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of numbers on the board.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$). | Print one number that will be left on the board. | null | In the first sample, the first player erases $$$3$$$ and the second erases $$$1$$$. $$$2$$$ is left on the board.
In the second sample, $$$2$$$ is left on the board regardless of the actions of the players. | [{"input": "3\n2 1 3", "output": "2"}, {"input": "3\n2 2 2", "output": "2"}] | 800 | ["sortings"] | 35 | [{"input": "3\r\n2 1 3\r\n", "output": "2"}, {"input": "3\r\n2 2 2\r\n", "output": "2"}, {"input": "9\r\n44 53 51 80 5 27 74 79 94\r\n", "output": "53"}, {"input": "10\r\n38 82 23 37 96 4 81 60 67 86\r\n", "output": "60"}, {"input": "10\r\n58 26 77 15 53 81 68 48 22 65\r\n", "output": "53"}, {"input": "1\r\n124\r\n", "... | false | stdio | null | true |
298/B | 298 | B | PyPy 3 | TESTS | 30 | 310 | 24,678,400 | 80546323 | f_line = input().split()
t = int(f_line[0])
sx = int(f_line[1])
sy = int(f_line[2])
ex = int(f_line[3])
ey = int(f_line[4])
dx = ex-sx
dy = ey-sy
tx = 0
ty = 0
dir_lst = list(input())
min_time = 0
for i in dir_lst:
if dx == tx and dy == ty:
break
else:
min_time += 1
if i == 'E':
... | 43 | 124 | 2,048,000 | 168725046 | allnums = input()
allnumslist = allnums.split()
x1 = int(allnumslist[1])
y1 = int(allnumslist[2])
x2 = int(allnumslist[3])
y2 = int(allnumslist[4])
count = 0
direction = input()
for i in range(len(direction)):
if x1 != x2 or y1 != y2:
count += 1
if x1 < x2:
if direction[i] == 'E':
x... | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Sail | The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).
- If the wind blows to the east, the boat will move to (x + 1, y).
- If... | The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105, - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.
The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E... | If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | null | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | [{"input": "5 0 0 1 1\nSESNW", "output": "4"}, {"input": "10 5 3 3 6\nNENSWESNEE", "output": "-1"}] | 1,200 | ["brute force", "greedy", "implementation"] | 43 | [{"input": "5 0 0 1 1\r\nSESNW\r\n", "output": "4\r\n"}, {"input": "10 5 3 3 6\r\nNENSWESNEE\r\n", "output": "-1\r\n"}, {"input": "19 -172106364 -468680119 -172106365 -468680119\r\nSSEEESSSESESWSEESSS\r\n", "output": "13\r\n"}, {"input": "39 -1000000000 -1000000000 -999999997 -1000000000\r\nENEENWSWSSWESNSSEESNSESWSWNS... | false | stdio | null | true |
490/B | 490 | B | PyPy 3-64 | TESTS | 2 | 46 | 0 | 185035822 | left_by_right = dict()
right_by_left = dict()
n = int(input())
for _ in range(n):
a, b = map(int, input().split())
right_by_left[a] = b
left_by_right[b] = a
res = [''] * n
pref = 0
for i in range(1, n, 2):
next_man = right_by_left[pref]
res[i] = str(next_man)
pref = next_man
pref = 0
for i ... | 61 | 608 | 92,364,800 | 215124672 | import sys
input = sys.stdin.readline
n = int(input())
graph = dict(input()[:-1].split() for _ in range(n))
ans = [None] * n
values = set(graph.values())
ans[0] = next(k for k in graph if k not in values)
ans[1] = graph['0']
for i in range(2, n):
ans[i] = graph[ans[i - 2]]
print(*ans) | Codeforces Round 279 (Div. 2) | CF | 2,014 | 2 | 256 | Queue | During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of... | The first line contains integer n (2 ≤ n ≤ 2·105) — the number of students in the queue.
Then n lines follow, i-th line contains the pair of integers ai, bi (0 ≤ ai, bi ≤ 106), where ai is the ID number of a person in front of a student and bi is the ID number of a person behind a student. The lines are given in the a... | Print a sequence of n integers x1, x2, ..., xn — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one. | null | The picture illustrates the queue for the first sample. | [{"input": "4\n92 31\n0 7\n31 0\n7 141", "output": "92 7 31 141"}] | 1,500 | ["dsu", "implementation"] | 61 | [{"input": "4\r\n92 31\r\n0 7\r\n31 0\r\n7 141\r\n", "output": "92 7 31 141 \r\n"}, {"input": "2\r\n0 1\r\n2 0\r\n", "output": "2 1 \r\n"}, {"input": "3\r\n0 2\r\n1 3\r\n2 0\r\n", "output": "1 2 3 \r\n"}, {"input": "4\r\n101 0\r\n0 102\r\n102 100\r\n103 101\r\n", "output": "103 102 101 100 \r\n"}, {"input": "5\r\n0 1\r... | false | stdio | null | true |
490/B | 490 | B | Python 3 | TESTS | 2 | 46 | 102,400 | 179043482 | def solution():
from collections import defaultdict
n = int(input())
lst = [0 for _ in range(n)]
front = defaultdict(int)
back = defaultdict(int)
start = 0
end = 0
unvisited = []
for _ in range(n):
front_p,back_p = input().split()
if front_p == "0":
star... | 61 | 732 | 48,537,600 | 202532657 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict
N = int(input())
P = defaultdict(int)
ins = defaultdict(int)
A = set()
ans = [0]*N
for _ in range(N):
a,b = map(int, input().split())
if a==0:
ans[1] = b
continue
elif b==0:
ans[-2]=a
... | Codeforces Round 279 (Div. 2) | CF | 2,014 | 2 | 256 | Queue | During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of... | The first line contains integer n (2 ≤ n ≤ 2·105) — the number of students in the queue.
Then n lines follow, i-th line contains the pair of integers ai, bi (0 ≤ ai, bi ≤ 106), where ai is the ID number of a person in front of a student and bi is the ID number of a person behind a student. The lines are given in the a... | Print a sequence of n integers x1, x2, ..., xn — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one. | null | The picture illustrates the queue for the first sample. | [{"input": "4\n92 31\n0 7\n31 0\n7 141", "output": "92 7 31 141"}] | 1,500 | ["dsu", "implementation"] | 61 | [{"input": "4\r\n92 31\r\n0 7\r\n31 0\r\n7 141\r\n", "output": "92 7 31 141 \r\n"}, {"input": "2\r\n0 1\r\n2 0\r\n", "output": "2 1 \r\n"}, {"input": "3\r\n0 2\r\n1 3\r\n2 0\r\n", "output": "1 2 3 \r\n"}, {"input": "4\r\n101 0\r\n0 102\r\n102 100\r\n103 101\r\n", "output": "103 102 101 100 \r\n"}, {"input": "5\r\n0 1\r... | false | stdio | null | true |
298/B | 298 | B | Python 3 | TESTS | 30 | 404 | 614,400 | 69844636 | t, sx, sy, ex, ey = [int(x) for x in input().split()]
dir = input()
allow = []
if ex - sx > 0:
allow.append('E')
elif ex - sx < 0:
allow.append('W')
if ey - sy > 0:
allow.append('N')
elif ey - sy < 0:
allow.append('S')
curr = [sx, sy]
end = [ex, ey]
mov = {'E':(1, 0), 'W':(-1, 0), 'N':(0, 1), 'S':(0,... | 43 | 124 | 2,252,800 | 178420251 | def find():
time_counter = 0
xtravel = ex-sx
ytravel = ey-sy
for i in inp2:
if i == "N" and ytravel > 0:
ytravel -= 1
if i == "E" and xtravel > 0:
xtravel -= 1
if i == "S" and ytravel < 0:
ytravel += 1
if i == "W" and xtravel < 0:
xtravel += 1
time_counter += 1
if... | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Sail | The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).
- If the wind blows to the east, the boat will move to (x + 1, y).
- If... | The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105, - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.
The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E... | If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | null | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | [{"input": "5 0 0 1 1\nSESNW", "output": "4"}, {"input": "10 5 3 3 6\nNENSWESNEE", "output": "-1"}] | 1,200 | ["brute force", "greedy", "implementation"] | 43 | [{"input": "5 0 0 1 1\r\nSESNW\r\n", "output": "4\r\n"}, {"input": "10 5 3 3 6\r\nNENSWESNEE\r\n", "output": "-1\r\n"}, {"input": "19 -172106364 -468680119 -172106365 -468680119\r\nSSEEESSSESESWSEESSS\r\n", "output": "13\r\n"}, {"input": "39 -1000000000 -1000000000 -999999997 -1000000000\r\nENEENWSWSSWESNSSEESNSESWSWNS... | false | stdio | null | true |
33/A | 33 | A | Python 3 | TESTS | 8 | 218 | 0 | 81854070 | n,m,k=map(int,input().split())
tot=0; t={}
for i in range(n):
r,c=map(int,input().split())
t[r]=min(t.get(r,1000001),c)
for i in range(1,m+1):
tot+=min(t[i],k)
k-=t[i]
print(tot) | 31 | 92 | 0 | 151265763 | n, m, k = [int(item) for item in input().split(' ')]
my_dict = dict()
for i in range(n):
r, health = [int(item) for item in input().split(' ')]
if r in my_dict and my_dict[r] > health or r not in my_dict:
my_dict[r] = health
summary = sum(my_dict.values())
print(summary if summary <= k else k) | Codeforces Beta Round 33 (Codeforces format) | CF | 2,010 | 2 | 256 | What is for dinner? | In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
... | The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c... | In the first line output the maximum amount of crucians that Valerie can consume for dinner. | null | null | [{"input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11"}, {"input": "2 2 13\n1 13\n2 12", "output": "13"}] | 1,200 | ["greedy", "implementation"] | 31 | [{"input": "4 3 18\r\n2 3\r\n1 2\r\n3 6\r\n2 3\r\n", "output": "11\r\n"}, {"input": "2 2 13\r\n1 13\r\n2 12\r\n", "output": "13\r\n"}, {"input": "5 4 8\r\n4 6\r\n4 5\r\n1 3\r\n2 0\r\n3 3\r\n", "output": "8\r\n"}, {"input": "1 1 0\r\n1 3\r\n", "output": "0\r\n"}, {"input": "7 1 30\r\n1 8\r\n1 15\r\n1 5\r\n1 17\r\n1 9\r\... | false | stdio | null | true |
449/B | 449 | B | PyPy 3-64 | TESTS | 4 | 1,326 | 131,584,000 | 188171661 | import gc
import heapq
import itertools
import math
from collections import Counter, deque, defaultdict
from sys import stdout
import time
from math import factorial, log, gcd
import sys
from decimal import Decimal
import threading
from heapq import *
from fractions import Fraction
import bisect
def S():
return sys.... | 45 | 1,886 | 133,222,400 | 202495416 | import os
import sys
import threading
from io import BytesIO, IOBase
from heapq import heappush, heappop, heapify
from collections import defaultdict, deque, Counter
from bisect import bisect_left as bl
from bisect import bisect_right as br
# threading.stack_size(10**8)
# sys.setrecursionlimit(10**6)
def ri(): return... | Codeforces Round 257 (Div. 1) | CF | 2,014 | 2 | 256 | Jzzhu and Cities | Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One ... | The first line contains three integers n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105).
Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ n; ui ≠ vi; 1 ≤ xi ≤ 109).
Each of the next k lines contains two integers si and yi (2 ≤ si ≤ n; 1 ≤ yi ≤ 109).
It is guaranteed that there is at least o... | Output a single integer representing the maximum number of the train routes which can be closed. | null | null | [{"input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "output": "2"}, {"input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3", "output": "2"}] | 2,000 | ["graphs", "greedy", "shortest paths"] | 45 | [{"input": "5 5 3\r\n1 2 1\r\n2 3 2\r\n1 3 3\r\n3 4 4\r\n1 5 5\r\n3 5\r\n4 5\r\n5 5\r\n", "output": "2\r\n"}, {"input": "2 2 3\r\n1 2 2\r\n2 1 3\r\n2 1\r\n2 2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "5 4 3\r\n1 2 999999999\r\n2 3 1000000000\r\n3 4 529529529\r\n5 1 524524524\r\n5 524444444\r\n5 529999999\r\n2 1000000... | false | stdio | null | true |
690/C1 | 690 | C1 | PyPy 3 | TESTS | 14 | 217 | 4,915,200 | 118715248 | def dfs(start,vis,end,ans):
global graph
#print(start,end)
vis[start] = True
if start == end:
ans[0] = True
return
for node in graph[start]:
if node not in vis:
dfs(node,vis,end,ans)
from collections import defaultdict
n,m = map(int,input().split())
graph =... | 18 | 62 | 307,200 | 19010610 | import sys
sys.setrecursionlimit(1000000)
def dfs(v, pr):
global used
global p
global f
if not f:
return None
if used[v]:
f = False
used[v] = True
for i in range(len(p[v])):
if p[v][i] != pr:
dfs(p[v][i], v)
n, m = map(int, input().split())
... | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 2 | 256 | Brain Network (easy) | One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite!... | The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 1000) denoting the number of brains (which are conveniently numbered from 1 to n) and the number of brain connectors in the nervous system, respectively. In the next m lines, descriptions of brain connectors follow. Every connector is... | The output consists of one line, containing either yes or no depending on whether the nervous system is valid. | null | null | [{"input": "4 4\n1 2\n2 3\n3 1\n4 1", "output": "no"}, {"input": "6 5\n1 2\n2 3\n3 4\n4 5\n3 6", "output": "yes"}] | 1,300 | [] | 18 | [{"input": "4 4\r\n1 2\r\n2 3\r\n3 1\r\n4 1\r\n", "output": "no\r\n"}, {"input": "6 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n3 6\r\n", "output": "yes\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "yes\r\n"}, {"input": "3 3\r\n2 1\r\n1 3\r\n3 2\r\n", "output": "no\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n", "output": "yes\r\n"}, {... | false | stdio | null | true |
260/C | 260 | C | Python 3 | TESTS | 3 | 93 | 307,200 | 76331305 | import sys
lines = sys.stdin.readlines()
(n,x) = map(int, lines[0].strip().split(" "))
nums = list(map(int, lines[1].strip().split(" ")))
minSoFar = min(nums)
index = -1
for i in range(x+n-2, x-2, -1):
if nums[i%n] == minSoFar:
index = i%n; break
tmp = nums[index]
num = tmp * n + (x-1+n-index) % n
for i i... | 38 | 108 | 15,462,400 | 215078802 | n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
m = min(A)
mi = A.index(m)
for i in range(n):
A[i] -= m
j = x - 1
val = n * m
while(A[j]):
A[j] -= 1
val += 1
j = ((j - 1) % n + n) % n
A[j] = val
print(*A) | Codeforces Round 158 (Div. 2) | CF | 2,012 | 1 | 256 | Balls and Boxes | Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right.
Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ... | The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 0) represents ... | Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them. | null | null | [{"input": "4 4\n4 3 1 6", "output": "3 2 5 4"}, {"input": "5 2\n3 2 0 2 7", "output": "2 1 4 1 6"}, {"input": "3 3\n2 3 1", "output": "1 2 3"}] | 1,700 | ["constructive algorithms", "greedy", "implementation"] | 38 | [{"input": "4 4\r\n4 3 1 6\r\n", "output": "3 2 5 4 "}, {"input": "5 2\r\n3 2 0 2 7\r\n", "output": "2 1 4 1 6 "}, {"input": "3 3\r\n2 3 1\r\n", "output": "1 2 3 "}, {"input": "10 3\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0 0 1000... | false | stdio | null | true |
429/B | 429 | B | Python 3 | TESTS | 2 | 46 | 6,963,200 | 125012463 | n,m = map(int,input().split())
matrix =[]
for i in range(n):
arr = list(map(int,input().split()))
matrix.append(arr)
dp1 =[[0]*(m+2) for ele in range(n+2)]
dp2 =[[0]*(m+2) for ele in range(n+2)]
dp3 =[[0]*(m+2) for ele in range(n+2)]
dp4 =[[0]*(m+2) for ele in range(n+2)]
for i in range(1,n+1):
for j in range(1,... | 30 | 405 | 52,736,000 | 169404412 | from collections import defaultdict as dd, deque as dq, Counter as ctr
from itertools import accumulate
from re import findall
import re
import sys
input = lambda: sys.stdin.buffer.readline().decode('utf-8').rstrip('\r\n')
from bisect import bisect_left as bl
from bisect import bisect_right as br
from array import... | Codeforces Round 245 (Div. 1) | CF | 2,014 | 2 | 256 | Working out | Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column.
Iahub starts with ... | The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000). Each of the next n lines contains m integers: j-th number from i-th line denotes element a[i][j] (0 ≤ a[i][j] ≤ 105). | The output contains a single number — the maximum total gain possible. | null | Iahub will choose exercises a[1][1] → a[1][2] → a[2][2] → a[3][2] → a[3][3]. Iahubina will choose exercises a[3][1] → a[2][1] → a[2][2] → a[2][3] → a[1][3]. | [{"input": "3 3\n100 100 100\n100 1 100\n100 100 100", "output": "800"}] | 1,600 | ["dp"] | 30 | [{"input": "3 3\r\n100 100 100\r\n100 1 100\r\n100 100 100\r\n", "output": "800"}, {"input": "4 5\r\n87882 40786 3691 85313 46694\r\n28884 16067 3242 97367 78518\r\n4250 35501 9780 14435 19004\r\n64673 65438 56977 64495 27280\r\n", "output": "747898"}, {"input": "3 3\r\n3 1 2\r\n3 2 0\r\n2 3 2\r\n", "output": "16"}, {"... | false | stdio | null | true |
449/B | 449 | B | Python 3 | TESTS | 4 | 1,559 | 63,283,200 | 52225606 | import sys
from heapq import heappush, heappop
input=sys.stdin.readline
def main():
n,m,k = map(int,input().split())
g=[[] for _ in range(1+n)]
for _ in range(m):
u,v,x = map(int,input().split())
g[u].append((x,v,-1))
g[v].append((x,u,-1))
for _ in range(k):
s,y=map(int,input().split())
g[1].append((y,s,s... | 45 | 1,871 | 131,072,000 | 167802107 | import sys
import math
import collections
from heapq import heappush, heappop
input = sys.stdin.readline
ints = lambda: list(map(int, input().split()))
n, m, k = ints()
graph = [[] for _ in range(n + 1)]
for _ in range(m):
a, b, c = ints()
graph[a].append((b, c, 0))
graph[b].append((a, c, 0))
trains = ... | Codeforces Round 257 (Div. 1) | CF | 2,014 | 2 | 256 | Jzzhu and Cities | Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One ... | The first line contains three integers n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105).
Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ n; ui ≠ vi; 1 ≤ xi ≤ 109).
Each of the next k lines contains two integers si and yi (2 ≤ si ≤ n; 1 ≤ yi ≤ 109).
It is guaranteed that there is at least o... | Output a single integer representing the maximum number of the train routes which can be closed. | null | null | [{"input": "5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5", "output": "2"}, {"input": "2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3", "output": "2"}] | 2,000 | ["graphs", "greedy", "shortest paths"] | 45 | [{"input": "5 5 3\r\n1 2 1\r\n2 3 2\r\n1 3 3\r\n3 4 4\r\n1 5 5\r\n3 5\r\n4 5\r\n5 5\r\n", "output": "2\r\n"}, {"input": "2 2 3\r\n1 2 2\r\n2 1 3\r\n2 1\r\n2 2\r\n2 3\r\n", "output": "2\r\n"}, {"input": "5 4 3\r\n1 2 999999999\r\n2 3 1000000000\r\n3 4 529529529\r\n5 1 524524524\r\n5 524444444\r\n5 529999999\r\n2 1000000... | false | stdio | null | true |
298/B | 298 | B | Python 3 | TESTS | 30 | 278 | 716,800 | 104419424 | from collections import *
t, sx, sy, ex, ey = map(int, input().split())
s = input()
cnte = 0
cntw = 0
cntn = 0
cnts = 0
if sx == ex and sy == ey:
print(0)
elif sx == ex:
if ey > sy:
diff = abs(ey - sy)
for i in range(t):
if s[i] == "N":
cntn += 1
if cntn ... | 43 | 124 | 2,355,200 | 193611395 | l=list(map(int,input().split()))
t,x,y,p,q=l[0],l[1],l[2],l[3],l[4]
s,n,e,w=0,0,0,0
babe=input()
if p-x>=0:
e=p-x
else:
w=x-p
if q-y>=0:
n=q-y
else:
s=y-q
if (p-x==0) and (q-y==0):
print(0)
else:
for i in range(t):
if babe[i]=="S":
if s>0:
s-=1
eli... | Codeforces Round 180 (Div. 2) | CF | 2,013 | 1 | 256 | Sail | The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).
- If the wind blows to the east, the boat will move to (x + 1, y).
- If... | The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105, - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.
The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E... | If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). | null | In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.
In the second sample, they cannot sail to the destination. | [{"input": "5 0 0 1 1\nSESNW", "output": "4"}, {"input": "10 5 3 3 6\nNENSWESNEE", "output": "-1"}] | 1,200 | ["brute force", "greedy", "implementation"] | 43 | [{"input": "5 0 0 1 1\r\nSESNW\r\n", "output": "4\r\n"}, {"input": "10 5 3 3 6\r\nNENSWESNEE\r\n", "output": "-1\r\n"}, {"input": "19 -172106364 -468680119 -172106365 -468680119\r\nSSEEESSSESESWSEESSS\r\n", "output": "13\r\n"}, {"input": "39 -1000000000 -1000000000 -999999997 -1000000000\r\nENEENWSWSSWESNSSEESNSESWSWNS... | false | stdio | null | true |
74/A | 74 | A | Python 3 | TESTS | 7 | 92 | 6,963,200 | 115764899 | import sys
def get_single_int ():
return int (sys.stdin.readline ().strip ())
def get_string ():
return sys.stdin.readline ().strip ()
def get_ints ():
return map (int, sys.stdin.readline ().strip ().split ())
def get_list ():
return list (map (str, sys.stdin.readline ().strip ().split ()))
#code start... | 32 | 92 | 0 | 162484826 | def room_leader():
a = int(input())
tabela_participantes = [input().split() for _ in range(a)]
scores = []
for p in tabela_participantes:
scores.append(calcula_pontuacao(p))
scores.sort(reverse=True, key=lambda y: y[1])
print(scores[0][0])
def calcula_pontuacao(participante):
atual = 0
nome = ""... | Codeforces Beta Round 68 | CF | 2,011 | 2 | 256 | Room Leader | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.
In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five proble... | The first line contains an integer n, which is the number of contestants in the room (1 ≤ n ≤ 50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" — it is the handle of a contestant, the number of successful hacks, the number of unsuccessf... | Print on the single line the handle of the room leader. | null | The number of points that each participant from the example earns, are as follows:
- Petr — 3860
- tourist — 4140
- Egor — 4030
- c00lH4x0R — - 350
- some_participant — 2220
Thus, the leader of the room is tourist. | [{"input": "5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0", "output": "tourist"}] | 1,000 | ["implementation"] | 32 | [{"input": "5\r\nPetr 3 1 490 920 1000 1200 0\r\ntourist 2 0 490 950 1100 1400 0\r\nEgor 7 0 480 900 950 0 1000\r\nc00lH4x0R 0 10 150 0 0 0 0\r\nsome_participant 2 1 450 720 900 0 0\r\n", "output": "tourist"}, {"input": "1\r\nA 0 0 200 0 0 0 0\r\n", "output": "A"}, {"input": "2\r\n12345678901234567890 1 0 200 0 0 0 0\r... | false | stdio | null | true |
490/B | 490 | B | PyPy 3-64 | TESTS | 2 | 62 | 0 | 232687168 | import sys
def main() -> None:
read = sys.stdin.readline
n = int(read())
l_neigh = {}
r_neigh = {}
left_pairings, right_pairings = [None] * n, [None] * n
left_most, right_most = None, None
for _ in range(n):
left, right = (int(i) for i in read().split())
if left == 0:
left_mos... | 61 | 748 | 42,496,000 | 177473864 | import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
l = dict()
r = dict()
x = -1
for i in range(n):
a, b = map(int, input().split())
l[b] = a
r[a] = b
if n % 2 == 0:
if x == -1:
x = a
else:
if a == 0:
x = b
if n % 2 == 0:
... | Codeforces Round 279 (Div. 2) | CF | 2,014 | 2 | 256 | Queue | During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of... | The first line contains integer n (2 ≤ n ≤ 2·105) — the number of students in the queue.
Then n lines follow, i-th line contains the pair of integers ai, bi (0 ≤ ai, bi ≤ 106), where ai is the ID number of a person in front of a student and bi is the ID number of a person behind a student. The lines are given in the a... | Print a sequence of n integers x1, x2, ..., xn — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one. | null | The picture illustrates the queue for the first sample. | [{"input": "4\n92 31\n0 7\n31 0\n7 141", "output": "92 7 31 141"}] | 1,500 | ["dsu", "implementation"] | 61 | [{"input": "4\r\n92 31\r\n0 7\r\n31 0\r\n7 141\r\n", "output": "92 7 31 141 \r\n"}, {"input": "2\r\n0 1\r\n2 0\r\n", "output": "2 1 \r\n"}, {"input": "3\r\n0 2\r\n1 3\r\n2 0\r\n", "output": "1 2 3 \r\n"}, {"input": "4\r\n101 0\r\n0 102\r\n102 100\r\n103 101\r\n", "output": "103 102 101 100 \r\n"}, {"input": "5\r\n0 1\r... | false | stdio | null | true |
925/B | 925 | B | PyPy 3 | TESTS | 4 | 186 | 1,228,800 | 100875333 | import bisect
n,x1,x2=map(int,input().split())
cc=sorted(enumerate(list(map(int,input().split()))),key=lambda x:x[1])
c=[]
real_inds=[]
for inda,num in cc:
c.append(num)
real_inds.append(inda+1)
flag=0
if x2<x1:
flag=1
x1,x2=x2,x1
k=1
rr=n
while k<n:
w=x1/k
start=bisect.bisect_left(c,w)
tak... | 40 | 748 | 42,700,800 | 159295631 | I = lambda:list(map(int, input().split()))
n,x1,x2 = I()
servers = I()
idx = list(range(n))
idx.sort(key = lambda i : servers[i])
def solve(a, b, rev):
j = len(idx)-1
while j >= 0 and (n-j)*servers[idx[j]] < b:
j -= 1
if j < 0:
return
i = j-1
while i >= 0 and (j-i)*servers[idx[i]] <... | VK Cup 2018 - Round 3 | CF | 2,018 | 2 | 256 | Resource Distribution | One department of some software company has $$$n$$$ servers of different specifications. Servers are indexed with consecutive integers from $$$1$$$ to $$$n$$$. Suppose that the specifications of the $$$j$$$-th server may be expressed with a single integer number $$$c_j$$$ of artificial resource units.
In order for pro... | The first line contains three integers $$$n$$$, $$$x_1$$$, $$$x_2$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq x_1, x_2 \leq 10^9$$$) — the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains $$$n$$$ space-separated integers $$$c_1, c_2, \ldo... | If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers $$$k_1$$$ and $$$k_2$$$ ($$$1 \leq k_1, k_2 \leq n$$$) — the number of servers used for each of the services.
... | null | In the first sample test each of the servers 1, 2 and 6 will will provide $$$8 / 3 = 2.(6)$$$ resource units and each of the servers 5, 4 will provide $$$16 / 2 = 8$$$ resource units.
In the second sample test the first server will provide $$$20$$$ resource units and each of the remaining servers will provide $$$32 / ... | [{"input": "6 8 16\n3 5 2 9 8 7", "output": "Yes\n3 2\n1 2 6\n5 4"}, {"input": "4 20 32\n21 11 11 12", "output": "Yes\n1 3\n1\n2 3 4"}, {"input": "4 11 32\n5 5 16 16", "output": "No"}, {"input": "5 12 20\n7 8 4 11 9", "output": "No"}] | 1,700 | ["binary search", "implementation", "sortings"] | 40 | [{"input": "6 8 16\r\n3 5 2 9 8 7\r\n", "output": "Yes\r\n4 2\r\n3 1 2 6\r\n5 4\r\n"}, {"input": "4 20 32\r\n21 11 11 12\r\n", "output": "Yes\r\n1 3\r\n1\r\n2 3 4\r\n"}, {"input": "4 11 32\r\n5 5 16 16\r\n", "output": "No\r\n"}, {"input": "5 12 20\r\n7 8 4 11 9\r\n", "output": "No\r\n"}, {"input": "2 1 1\r\n1 1\r\n", "... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n, x1, x2 = map(int, f.readline().split())
c = list(map(int, f.readline().split()))
with open(output_path) as f:
ref_lines = [line.strip() for line in f]
with open(submission_path) a... | true |
925/B | 925 | B | PyPy 3-64 | TESTS | 6 | 1,387 | 47,001,600 | 213797987 | import sys
import math
import collections
from heapq import heappush, heappop
input = sys.stdin.readline
ints = lambda: list(map(int, input().split()))
n, x1, x2 = ints()
a = ints()
for i in range(n): a[i] = [a[i], i]
a.sort()
j = n
for i in range(n):
k = math.ceil(x1/a[i][0])
while j - i > k:
j -= 1... | 40 | 795 | 50,995,200 | 37714382 | n, a, b = [int(x) for x in input().split()]
hs = [int(x) for x in input().split()]
hs = sorted(enumerate(hs), key=lambda x: x[1])
for i in range(1, n+1):
if hs[-i][1] * i >= a:
break
else:
print('No')
exit()
for j in range(i+1, n+1):
if hs[-j][1] * (j - i) >= b:
print('Yes')
... | VK Cup 2018 - Round 3 | CF | 2,018 | 2 | 256 | Resource Distribution | One department of some software company has $$$n$$$ servers of different specifications. Servers are indexed with consecutive integers from $$$1$$$ to $$$n$$$. Suppose that the specifications of the $$$j$$$-th server may be expressed with a single integer number $$$c_j$$$ of artificial resource units.
In order for pro... | The first line contains three integers $$$n$$$, $$$x_1$$$, $$$x_2$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq x_1, x_2 \leq 10^9$$$) — the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains $$$n$$$ space-separated integers $$$c_1, c_2, \ldo... | If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers $$$k_1$$$ and $$$k_2$$$ ($$$1 \leq k_1, k_2 \leq n$$$) — the number of servers used for each of the services.
... | null | In the first sample test each of the servers 1, 2 and 6 will will provide $$$8 / 3 = 2.(6)$$$ resource units and each of the servers 5, 4 will provide $$$16 / 2 = 8$$$ resource units.
In the second sample test the first server will provide $$$20$$$ resource units and each of the remaining servers will provide $$$32 / ... | [{"input": "6 8 16\n3 5 2 9 8 7", "output": "Yes\n3 2\n1 2 6\n5 4"}, {"input": "4 20 32\n21 11 11 12", "output": "Yes\n1 3\n1\n2 3 4"}, {"input": "4 11 32\n5 5 16 16", "output": "No"}, {"input": "5 12 20\n7 8 4 11 9", "output": "No"}] | 1,700 | ["binary search", "implementation", "sortings"] | 40 | [{"input": "6 8 16\r\n3 5 2 9 8 7\r\n", "output": "Yes\r\n4 2\r\n3 1 2 6\r\n5 4\r\n"}, {"input": "4 20 32\r\n21 11 11 12\r\n", "output": "Yes\r\n1 3\r\n1\r\n2 3 4\r\n"}, {"input": "4 11 32\r\n5 5 16 16\r\n", "output": "No\r\n"}, {"input": "5 12 20\r\n7 8 4 11 9\r\n", "output": "No\r\n"}, {"input": "2 1 1\r\n1 1\r\n", "... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n, x1, x2 = map(int, f.readline().split())
c = list(map(int, f.readline().split()))
with open(output_path) as f:
ref_lines = [line.strip() for line in f]
with open(submission_path) a... | true |
44/A | 44 | A | Python 3 | TESTS | 28 | 62 | 0 | 144856923 | n=int(input())
d=set()
for i in range(n):
s,k=map(str,input().split())
d.add(s+k)
print(len(d)) | 29 | 62 | 0 | 144809605 | lst = []
for i in range(int(input())):
input2 = input().split()
lst.append(input2[0]+" "+input2[1])
print(len(set(lst))) | School Team Contest 2 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | Indian Summer | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 ... | Output the single number — the number of Alyona's leaves. | null | null | [{"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4"}, {"input": "3\noak yellow\noak yellow\noak yellow", "output": "1"}] | 900 | ["implementation"] | 29 | [{"input": "5\r\nbirch yellow\r\nmaple red\r\nbirch yellow\r\nmaple yellow\r\nmaple green\r\n", "output": "4\r\n"}, {"input": "3\r\noak yellow\r\noak yellow\r\noak yellow\r\n", "output": "1\r\n"}, {"input": "5\r\nxbnbkzn hp\r\nkaqkl vrgzbvqstu\r\nj aqidx\r\nhos gyul\r\nwefxmh tygpluae\r\n", "output": "5\r\n"}, {"input"... | false | stdio | null | true |
69/E | 69 | E | PyPy 3 | TESTS | 12 | 233 | 6,144,000 | 78369401 | from collections import defaultdict, deque
from bisect import bisect
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from sys import stdout
print = stdout.write
n, k = map(int, input().split())
a = deque()
count = defaultdict(int)
te = []
for _ in range(k):
x = int(input())
a.append(x)
co... | 49 | 529 | 17,100,800 | 206692985 | # for I/O for local system
import sys
from os import path
if(path.exists('Input.txt')):
sys.stdin = open("Input.txt","r")
sys.stdout = open("Output.txt","w")
# For fast I/O
input = sys.stdin.buffer.readline
# input = sys.stdin.readline
print = sys.stdout.write
# Import libraries here whenever required
from he... | Codeforces Beta Round 63 (Div. 2) | CF | 2,011 | 1 | 256 | Subsegments | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in $${\mathcal {O}}(\log n)$$, which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed lengt... | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment.
Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | null | null | [{"input": "5 3\n1\n2\n2\n3\n3", "output": "1\n3\n2"}, {"input": "6 4\n3\n3\n3\n4\n4\n2", "output": "4\nNothing\n3"}] | 1,800 | ["data structures", "implementation"] | 49 | [{"input": "5 3\r\n1\r\n2\r\n2\r\n3\r\n3\r\n", "output": "1\r\n3\r\n2\r\n"}, {"input": "6 4\r\n3\r\n3\r\n3\r\n4\r\n4\r\n2\r\n", "output": "4\r\nNothing\r\n3\r\n"}, {"input": "10 3\r\n-55\r\n-35\r\n-80\r\n91\r\n-96\r\n-93\r\n-39\r\n-77\r\n4\r\n29\r\n", "output": "-35\r\n91\r\n91\r\n91\r\n-39\r\n-39\r\n4\r\n29\r\n"}, {"i... | false | stdio | null | true |
501/D | 501 | D | PyPy 3 | TESTS | 4 | 124 | 0 | 96055495 | def sum(BIT, i):
s = 0
while i > 0:
s += BIT[i]
i -= i & (-i)
return s
def update(BIT, i, v):
while i < len(BIT):
BIT[i] += v
i += i & (-i)
def find(fen, k):
curr = 0
ans = 0
prevsum = 0
for i in range(19, -1, -1):
if ((curr + (1 << i) < n) an... | 44 | 811 | 27,340,800 | 68433253 | import sys
class SegmTree():
def __init__(self, array=None):
size = len(array)
N = 1
while N < size:
N <<= 1
self.N = N
self.tree = [0] * (2*self.N)
for i in range(size):
self.tree[i+self.N] = array[i]
self.build()
def build(self)... | Codeforces Round 285 (Div. 2) | CF | 2,015 | 2 | 256 | Misha and Permutations Summation | Let's define the sum of two permutations p and q of numbers 0, 1, ..., (n - 1) as permutation $${\it Perm}((\mathit{Ord}(p)+\mathit{Ord}(q))\bmod n!)$$, where Perm(x) is the x-th lexicographically permutation of numbers 0, 1, ..., (n - 1) (counting from zero), and Ord(p) is the number of permutation p in the lexicograp... | The first line contains an integer n (1 ≤ n ≤ 200 000).
The second line contains n distinct integers from 0 to n - 1, separated by a space, forming permutation p.
The third line contains n distinct integers from 0 to n - 1, separated by spaces, forming permutation q. | Print n distinct integers from 0 to n - 1, forming the sum of the given permutations. Separate the numbers by spaces. | null | Permutations of numbers from 0 to 1 in the lexicographical order: (0, 1), (1, 0).
In the first sample Ord(p) = 0 and Ord(q) = 0, so the answer is $$Perm((0+0) \bmod 2) = Perm(0) = (0,1)$$.
In the second sample Ord(p) = 0 and Ord(q) = 1, so the answer is $${ \it Perm}((0+1){\bmod {2}})={\it Perm}(1)=(1,0)$$.
Permutat... | [{"input": "2\n0 1\n0 1", "output": "0 1"}, {"input": "2\n0 1\n1 0", "output": "1 0"}, {"input": "3\n1 2 0\n2 1 0", "output": "1 0 2"}] | 2,000 | ["data structures"] | 44 | [{"input": "2\r\n0 1\r\n0 1\r\n", "output": "0 1\r\n"}, {"input": "2\r\n0 1\r\n1 0\r\n", "output": "1 0\r\n"}, {"input": "3\r\n1 2 0\r\n2 1 0\r\n", "output": "1 0 2\r\n"}, {"input": "2\r\n0 1\r\n1 0\r\n", "output": "1 0\r\n"}, {"input": "5\r\n2 1 3 0 4\r\n2 0 4 3 1\r\n", "output": "4 2 0 3 1\r\n"}, {"input": "3\r\n0 2 ... | false | stdio | null | true |
456/A | 456 | A | Python 3 | TESTS | 39 | 218 | 9,932,800 | 219594024 | n = int(input())
prices = []
quality = []
for i in range(n):
data = input()
price, qual = map(int, data.split())
prices.append(price)
quality.append(qual)
alex = False
for i in range(1, n):
if ((prices[i - 1] < prices[i]) and (quality[i - 1] > quality[i])):
alex = True
break
... | 46 | 124 | 0 | 205306972 | a="Poor"
for i in range(int(input())):
b,c=input().split()
if b!=c:a="Happy"
print(a,"Alex") | Codeforces Round 260 (Div. 2) | CF | 2,014 | 1 | 256 | Laptops | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops.
Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality).
All ai ar... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | null | null | [{"input": "2\n1 2\n2 1", "output": "Happy Alex"}] | 1,100 | ["sortings"] | 46 | [{"input": "2\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n3 3\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "1\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"inp... | false | stdio | null | true |
456/A | 456 | A | Python 3 | TESTS | 39 | 124 | 0 | 226489744 | from sys import stdin
stream = None
try:
stream = open('file.txt', 'r')
except:
stream = stdin
n = int(stream.readline())
curr_price = 0
curr_quality = 0
result = False
for i in range(n):
price, quality = [int(i) for i in stream.readline().split()]
if (curr_price > price and curr_quality < quality) o... | 46 | 124 | 0 | 209949482 | for _ in range(int(input())):
i,j=input().split()
if i!=j:
print('Happy Alex')
exit()
print('Poor Alex') | Codeforces Round 260 (Div. 2) | CF | 2,014 | 1 | 256 | Laptops | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops.
Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality).
All ai ar... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | null | null | [{"input": "2\n1 2\n2 1", "output": "Happy Alex"}] | 1,100 | ["sortings"] | 46 | [{"input": "2\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n3 3\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "1\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"inp... | false | stdio | null | true |
44/A | 44 | A | Python 3 | TESTS | 28 | 92 | 0 | 210752767 | T=int(input())
lis=[]
for _ in range(T):
s=input()
s=s.replace(" ","")
if(s not in lis):
lis.append(s)
print(len(lis)) | 29 | 62 | 0 | 144856262 | ans=set()
for _ in range(int(input())):
a=input()
ans.add(a)
print(len(ans)) | School Team Contest 2 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | Indian Summer | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 ... | Output the single number — the number of Alyona's leaves. | null | null | [{"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4"}, {"input": "3\noak yellow\noak yellow\noak yellow", "output": "1"}] | 900 | ["implementation"] | 29 | [{"input": "5\r\nbirch yellow\r\nmaple red\r\nbirch yellow\r\nmaple yellow\r\nmaple green\r\n", "output": "4\r\n"}, {"input": "3\r\noak yellow\r\noak yellow\r\noak yellow\r\n", "output": "1\r\n"}, {"input": "5\r\nxbnbkzn hp\r\nkaqkl vrgzbvqstu\r\nj aqidx\r\nhos gyul\r\nwefxmh tygpluae\r\n", "output": "5\r\n"}, {"input"... | false | stdio | null | true |
44/A | 44 | A | Python 3 | TESTS | 28 | 92 | 0 | 204007070 | n=int(input())
t=[]
count=0
for i in range(n):
spe,col=input().split()
a=spe+col
if a not in t:
t.append(a)
count+=1
print(count) | 29 | 62 | 0 | 144857118 | n=int(input())
d=set()
for i in range(n):
s,k=map(str,input().split())
j=s+"-"+k
d.add(j)
print(len(d)) | School Team Contest 2 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | Indian Summer | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 ... | Output the single number — the number of Alyona's leaves. | null | null | [{"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4"}, {"input": "3\noak yellow\noak yellow\noak yellow", "output": "1"}] | 900 | ["implementation"] | 29 | [{"input": "5\r\nbirch yellow\r\nmaple red\r\nbirch yellow\r\nmaple yellow\r\nmaple green\r\n", "output": "4\r\n"}, {"input": "3\r\noak yellow\r\noak yellow\r\noak yellow\r\n", "output": "1\r\n"}, {"input": "5\r\nxbnbkzn hp\r\nkaqkl vrgzbvqstu\r\nj aqidx\r\nhos gyul\r\nwefxmh tygpluae\r\n", "output": "5\r\n"}, {"input"... | false | stdio | null | true |
44/A | 44 | A | Python 3 | TESTS | 28 | 92 | 0 | 203972022 | n=int(input())
l=[]
count=0
for i in range(n):
fruit,colour=input().split()
if l.count(fruit+colour)==0:
l.append(fruit+colour)
count+=1
print(count) | 29 | 62 | 0 | 144857960 | n=int(input())
l=[]
for i in range(0,n):
s=input()
l.append(s)
l=set(l)
print(len(l)) | School Team Contest 2 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | Indian Summer | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 ... | Output the single number — the number of Alyona's leaves. | null | null | [{"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4"}, {"input": "3\noak yellow\noak yellow\noak yellow", "output": "1"}] | 900 | ["implementation"] | 29 | [{"input": "5\r\nbirch yellow\r\nmaple red\r\nbirch yellow\r\nmaple yellow\r\nmaple green\r\n", "output": "4\r\n"}, {"input": "3\r\noak yellow\r\noak yellow\r\noak yellow\r\n", "output": "1\r\n"}, {"input": "5\r\nxbnbkzn hp\r\nkaqkl vrgzbvqstu\r\nj aqidx\r\nhos gyul\r\nwefxmh tygpluae\r\n", "output": "5\r\n"}, {"input"... | false | stdio | null | true |
154/A | 154 | A | PyPy 3 | TESTS | 4 | 154 | 307,200 | 186979529 | from collections import defaultdict
from sys import stdin
input = stdin.readline
s = input().strip()
k = int(input())
mp = defaultdict(set)
for _ in range(k):
t = input().strip()
mp[t[0]].add(t[1])
mp[t[1]].add(t[0])
ans = 0; last = ''
for c in s:
if c in mp[last]:
ans += 1
else:
l... | 42 | 216 | 4,300,800 | 218083045 | s = input()
k = int(input())
res = 0
for _ in range(k):
f = input()
ins = False
first, second = 0, 0
for i in s:
if not ins and i != f[0] and i != f[1]:
continue
if ins and i != f[0] and i != f[1]:
ins = False
MIN = min(first, second)
res +... | Codeforces Round 109 (Div. 1) | CF | 2,012 | 2 | 256 | Hometask | Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks.
Sergey totally forgot about ... | The first line contains a non-empty string s, consisting of lowercase Latin letters — that's the initial sentence in N-ish, written by Sergey. The length of string s doesn't exceed 105.
The next line contains integer k (0 ≤ k ≤ 13) — the number of forbidden pairs of letters.
Next k lines contain descriptions of forbi... | Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters. | null | In the first sample you should remove two letters b.
In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution. | [{"input": "ababa\n1\nab", "output": "2"}, {"input": "codeforces\n2\ndo\ncs", "output": "1"}] | 1,600 | ["greedy"] | 42 | [{"input": "ababa\r\n1\r\nab\r\n", "output": "2\r\n"}, {"input": "codeforces\r\n2\r\ndo\r\ncs\r\n", "output": "1\r\n"}, {"input": "nllnrlrnll\r\n1\r\nrl\r\n", "output": "1\r\n"}, {"input": "aludfbjtwnkgnfl\r\n1\r\noy\r\n", "output": "0\r\n"}, {"input": "pgpgppgggpbbnnn\r\n2\r\npg\r\nnb\r\n", "output": "7\r\n"}, {"input... | false | stdio | null | true |
995/A | 995 | A | PyPy 3 | TESTS | 3 | 124 | 0 | 61332619 | n,k=map(int,input().split())
was=int(k)
m=[]
for i in range(4):
m.append(list(map(int,input().split())))
res=[]
for i in range(n):
if m[1][i] != 0:
if m[1][i] == m[0][i]:
res.append([m[1][i],1,i+1])
m[1][i] = 0
k-=1
for i in range(n):
if m[2][i] != 0:
if m... | 57 | 202 | 3,276,800 | 39642428 | k, n = [int(x) for x in input().split()]
a = []
for i in range(4):
a.append([int(x) - 1 for x in input().split()])
pos = []
for i in range(k):
pos.append([1, i])
for i in range(k):
pos.append([2, k - i - 1])
lft = n
ans = []
for i in range(2 * k):
for j in range(2 * k):
if (a[pos[j][0]][pos[j][1]] != -1) and ... | Codeforces Round 492 (Div. 1) [Thanks, uDebug!] | CF | 2,018 | 3 | 256 | Tesla | Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem.
Allen's future parking lot can be repres... | The first line of the input contains two space-separated integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 50$$$, $$$1 \le k \le 2n$$$), representing the number of columns and the number of cars, respectively.
The next four lines will contain $$$n$$$ integers each between $$$0$$$ and $$$k$$$ inclusive, representing the ini... | If there is a sequence of moves that brings all of the cars to their parking spaces, with at most $$$20000$$$ car moves, then print $$$m$$$, the number of moves, on the first line. On the following $$$m$$$ lines, print the moves (one move per line) in the format $$$i$$$ $$$r$$$ $$$c$$$, which corresponds to Allen movin... | null | In the first sample test case, all cars are in front of their spots except car $$$5$$$, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most $$$20000$$$ will be accepted.
In the second sample test case, there is only one column, a... | [{"input": "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3", "output": "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2"}, {"input": "1 2\n1\n2\n1\n2", "output": "-1"}, {"input": "1 2\n1\n1\n2\n2", "output": "2\n1 1 1\n2 4 1"}] | 2,100 | ["constructive algorithms", "implementation"] | 57 | [{"input": "4 5\r\n1 2 0 4\r\n1 2 0 4\r\n5 0 0 3\r\n0 5 0 3\r\n", "output": "6\r\n1 1 1\r\n2 1 2\r\n4 1 4\r\n3 4 4\r\n5 3 2\r\n5 4 2\r\n"}, {"input": "1 2\r\n1\r\n2\r\n1\r\n2\r\n", "output": "-1\r\n"}, {"input": "1 2\r\n1\r\n1\r\n2\r\n2\r\n", "output": "2\r\n1 1 1\r\n2 4 1\r\n"}, {"input": "2 2\r\n1 0\r\n0 2\r\n0 1\r\n... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n, k = map(int, f.readline().split())
grid = []
for _ in range(4):
grid.append(list(map(int, f.readline().split())))
initial = {}
target = {}
for row_idx in [1, 2]:
fo... | true |
456/A | 456 | A | Python 3 | TESTS | 39 | 124 | 0 | 225696213 | prev = ["0","0"]
for i in range(int(input())):
t = input().split()
if (t[0]<prev[0]) ^ (t[1]<prev[1]):
print("Happy Alex")
break
prev = t
else:
print("Poor Alex") | 46 | 124 | 0 | 214022873 | a="Poor"
for i in range(int(input())):
b,c=input().split()
if b!=c:a="Happy"
print(a,"Alex") | Codeforces Round 260 (Div. 2) | CF | 2,014 | 1 | 256 | Laptops | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops.
Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality).
All ai ar... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | null | null | [{"input": "2\n1 2\n2 1", "output": "Happy Alex"}] | 1,100 | ["sortings"] | 46 | [{"input": "2\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"input": "3\r\n3 3\r\n1 2\r\n2 1\r\n", "output": "Happy Alex\r\n"}, {"input": "1\r\n1 1\r\n", "output": "Poor Alex\r\n"}, {"inp... | false | stdio | null | true |
44/A | 44 | A | Python 3 | TESTS | 28 | 62 | 0 | 147786053 | v=[]
n=int(input())
for i in range(n):
tree,color=map(str,input().split())
leaf=tree+color
v.append(leaf)
k=set(v)
print(len(k)) | 29 | 62 | 0 | 144971447 | n = int(input())
data = []
for i in range(n):
I = input().split()
data.append((I[0], I[1]))
results = []
for i in data:
if i not in results:
results.append(i)
print(len(results)) | School Team Contest 2 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | Indian Summer | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 ... | Output the single number — the number of Alyona's leaves. | null | null | [{"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4"}, {"input": "3\noak yellow\noak yellow\noak yellow", "output": "1"}] | 900 | ["implementation"] | 29 | [{"input": "5\r\nbirch yellow\r\nmaple red\r\nbirch yellow\r\nmaple yellow\r\nmaple green\r\n", "output": "4\r\n"}, {"input": "3\r\noak yellow\r\noak yellow\r\noak yellow\r\n", "output": "1\r\n"}, {"input": "5\r\nxbnbkzn hp\r\nkaqkl vrgzbvqstu\r\nj aqidx\r\nhos gyul\r\nwefxmh tygpluae\r\n", "output": "5\r\n"}, {"input"... | false | stdio | null | true |
44/A | 44 | A | Python 3 | TESTS | 28 | 92 | 0 | 223827159 | lst = []
for i in range(int(input())):
x, y = input().split()
z = x + y
lst.append(z)
print(len(set(lst))) | 29 | 62 | 0 | 147785727 | t=int(input())
k1={}
for i in range(t):
s=input()
k1[s]=1
print(len(k1)) | School Team Contest 2 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | Indian Summer | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 ... | Output the single number — the number of Alyona's leaves. | null | null | [{"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4"}, {"input": "3\noak yellow\noak yellow\noak yellow", "output": "1"}] | 900 | ["implementation"] | 29 | [{"input": "5\r\nbirch yellow\r\nmaple red\r\nbirch yellow\r\nmaple yellow\r\nmaple green\r\n", "output": "4\r\n"}, {"input": "3\r\noak yellow\r\noak yellow\r\noak yellow\r\n", "output": "1\r\n"}, {"input": "5\r\nxbnbkzn hp\r\nkaqkl vrgzbvqstu\r\nj aqidx\r\nhos gyul\r\nwefxmh tygpluae\r\n", "output": "5\r\n"}, {"input"... | false | stdio | null | true |
44/A | 44 | A | Python 3 | TESTS | 28 | 62 | 0 | 147787621 | n=int(input())
l=[]
for i in range(n):
s=input().split()
s1="".join(s)
l.append(s1)
print(len(set(l))) | 29 | 62 | 0 | 147786010 | lst1=[]
lst2=[]
test=int(input())
for i in range(test):
x=input()
if x not in lst1:
lst1.append(x)
else:
lst2.append(x)
print(len(lst1)) | School Team Contest 2 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | Indian Summer | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 ... | Output the single number — the number of Alyona's leaves. | null | null | [{"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4"}, {"input": "3\noak yellow\noak yellow\noak yellow", "output": "1"}] | 900 | ["implementation"] | 29 | [{"input": "5\r\nbirch yellow\r\nmaple red\r\nbirch yellow\r\nmaple yellow\r\nmaple green\r\n", "output": "4\r\n"}, {"input": "3\r\noak yellow\r\noak yellow\r\noak yellow\r\n", "output": "1\r\n"}, {"input": "5\r\nxbnbkzn hp\r\nkaqkl vrgzbvqstu\r\nj aqidx\r\nhos gyul\r\nwefxmh tygpluae\r\n", "output": "5\r\n"}, {"input"... | false | stdio | null | true |
44/A | 44 | A | Python 3 | TESTS | 28 | 62 | 0 | 147785792 | s=set()
for i in range(int(input())):
x,y=map(str,input().split())
s.add(x+y)
print(len(s)) | 29 | 62 | 0 | 147786611 | a=[]
for i in range(int(input())):
p=input()
a.append(p)
print(len(list(set(a)))) | School Team Contest 2 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | Indian Summer | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 ... | Output the single number — the number of Alyona's leaves. | null | null | [{"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4"}, {"input": "3\noak yellow\noak yellow\noak yellow", "output": "1"}] | 900 | ["implementation"] | 29 | [{"input": "5\r\nbirch yellow\r\nmaple red\r\nbirch yellow\r\nmaple yellow\r\nmaple green\r\n", "output": "4\r\n"}, {"input": "3\r\noak yellow\r\noak yellow\r\noak yellow\r\n", "output": "1\r\n"}, {"input": "5\r\nxbnbkzn hp\r\nkaqkl vrgzbvqstu\r\nj aqidx\r\nhos gyul\r\nwefxmh tygpluae\r\n", "output": "5\r\n"}, {"input"... | false | stdio | null | true |
690/C1 | 690 | C1 | PyPy 3-64 | TESTS | 11 | 93 | 1,228,800 | 140691425 | import sys
n, m = map(int, sys.stdin.readline().split())
if m == n - 1:
graph = [[] for i in range(n + 1)]
for _ in range(m):
a = list(map(int, sys.stdin.readline().split()))
graph[a[0]].append(a[1])
graph[a[1]].append(a[0])
found = {}
unvisited = [-1 for i in range(n + 1)]
... | 18 | 62 | 614,400 | 18999611 | l = []
were = []
def dfs(v):
global l, were
if not were:
were = len(l) * [False]
were[v] = True
for i in l[v]:
if not were[i]:
dfs(i)
n, m = map(int, input().split())
if m != n - 1:
print("no")
else:
l = [[] for i in range(n)]
for i in range(m):
a, b =... | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 2 | 256 | Brain Network (easy) | One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite!... | The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 1000) denoting the number of brains (which are conveniently numbered from 1 to n) and the number of brain connectors in the nervous system, respectively. In the next m lines, descriptions of brain connectors follow. Every connector is... | The output consists of one line, containing either yes or no depending on whether the nervous system is valid. | null | null | [{"input": "4 4\n1 2\n2 3\n3 1\n4 1", "output": "no"}, {"input": "6 5\n1 2\n2 3\n3 4\n4 5\n3 6", "output": "yes"}] | 1,300 | [] | 18 | [{"input": "4 4\r\n1 2\r\n2 3\r\n3 1\r\n4 1\r\n", "output": "no\r\n"}, {"input": "6 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n3 6\r\n", "output": "yes\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "yes\r\n"}, {"input": "3 3\r\n2 1\r\n1 3\r\n3 2\r\n", "output": "no\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n", "output": "yes\r\n"}, {... | false | stdio | null | true |
69/E | 69 | E | Python 3 | TESTS | 13 | 155 | 6,758,400 | 33465402 | from sys import *
from bisect import *
from collections import *
p = list(map(int, stdin.read().split()))
n, k = p[0], p[1]
d = Counter(p[2:2 + k])
t = sorted(q for q in d if d[q] < 2)
g = lambda: print(t[-1] if t else 'Nothing')
g()
for a, b in zip(p[2:], p[2 + k:]):
for q in [a, b]:
if d[q] == 1: t.pop(bi... | 49 | 623 | 17,510,400 | 129463203 | from sys import *
from bisect import *
from collections import *
#using inbuit libraries
p = list(map(int, stdin.read().split()))
n, k = p[0], p[1]
s, d = [], Counter(p[2:2 + k])
t = sorted(q for q in d if d[q] == 1)
def sub(q):
if d[q] == 1: t.pop(bisect(t, q) - 1)
def add(q):
if d[q] == 1: insort(t, q)
def ge... | Codeforces Beta Round 63 (Div. 2) | CF | 2,011 | 1 | 256 | Subsegments | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in $${\mathcal {O}}(\log n)$$, which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed lengt... | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment.
Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | null | null | [{"input": "5 3\n1\n2\n2\n3\n3", "output": "1\n3\n2"}, {"input": "6 4\n3\n3\n3\n4\n4\n2", "output": "4\nNothing\n3"}] | 1,800 | ["data structures", "implementation"] | 49 | [{"input": "5 3\r\n1\r\n2\r\n2\r\n3\r\n3\r\n", "output": "1\r\n3\r\n2\r\n"}, {"input": "6 4\r\n3\r\n3\r\n3\r\n4\r\n4\r\n2\r\n", "output": "4\r\nNothing\r\n3\r\n"}, {"input": "10 3\r\n-55\r\n-35\r\n-80\r\n91\r\n-96\r\n-93\r\n-39\r\n-77\r\n4\r\n29\r\n", "output": "-35\r\n91\r\n91\r\n91\r\n-39\r\n-39\r\n4\r\n29\r\n"}, {"i... | false | stdio | null | true |
260/C | 260 | C | PyPy 3-64 | TESTS | 3 | 62 | 28,979,200 | 133295991 | list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
boxes = list(map(int, input().split()))
x = x - 1
balls = 0
#while (boxes[(x % n)] != 0):
# boxes[x % n] -= 1
# balls += 1
# x -= 1
#boxes[x % n] = balls
min1 = [boxes[0] , 0]
for i in range(n) :
if boxes[i] < min1[0] or (boxes[i] == min... | 38 | 109 | 15,155,200 | 199574332 | n,x = map(int, input().split())
a = list(map(int, input().split()))
m = min(a)
a = [i-m for i in a]
x = x-1
d = m*n
while a[x]>0:
d+=1
a[x]-=1
x-=1
if x<0:
x=n-1
a[x]=d
print(*a) | Codeforces Round 158 (Div. 2) | CF | 2,012 | 1 | 256 | Balls and Boxes | Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right.
Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ... | The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 0) represents ... | Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them. | null | null | [{"input": "4 4\n4 3 1 6", "output": "3 2 5 4"}, {"input": "5 2\n3 2 0 2 7", "output": "2 1 4 1 6"}, {"input": "3 3\n2 3 1", "output": "1 2 3"}] | 1,700 | ["constructive algorithms", "greedy", "implementation"] | 38 | [{"input": "4 4\r\n4 3 1 6\r\n", "output": "3 2 5 4 "}, {"input": "5 2\r\n3 2 0 2 7\r\n", "output": "2 1 4 1 6 "}, {"input": "3 3\r\n2 3 1\r\n", "output": "1 2 3 "}, {"input": "10 3\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0 0 1000... | false | stdio | null | true |
260/C | 260 | C | Python 3 | TESTS | 10 | 31 | 0 | 172832133 | n, x = map(int, input().split())
x -= 1
A = [int(t) for t in input().split()]
i = A.index(min(A))
ans = [0] * len(A)
if all([t == A[0] for t in A]):
ans[x] = n*A[0]
print(' '.join([str(t) for t in ans]))
exit()
if x >= i:
for ind, a in enumerate(A):
if ind == i:
ans[ind] = x-i+n*A[i... | 38 | 171 | 14,028,800 | 28818655 | from math import inf
n, x = map(int, input().split())
a = list(map(int, input().split()))
x -= 1
mx = inf
mi = None
for i in range(x, x - n, -1):
if a[i] < mx:
mx = a[i]
mi = i
mi %= n
for i in range(n):
a[i] -= mx
a[mi] = mx * n + (x - mi) % n
for i in range(mi + 1 - (n if x < mi else 0),... | Codeforces Round 158 (Div. 2) | CF | 2,012 | 1 | 256 | Balls and Boxes | Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right.
Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting ... | The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 0) represents ... | Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them. | null | null | [{"input": "4 4\n4 3 1 6", "output": "3 2 5 4"}, {"input": "5 2\n3 2 0 2 7", "output": "2 1 4 1 6"}, {"input": "3 3\n2 3 1", "output": "1 2 3"}] | 1,700 | ["constructive algorithms", "greedy", "implementation"] | 38 | [{"input": "4 4\r\n4 3 1 6\r\n", "output": "3 2 5 4 "}, {"input": "5 2\r\n3 2 0 2 7\r\n", "output": "2 1 4 1 6 "}, {"input": "3 3\r\n2 3 1\r\n", "output": "1 2 3 "}, {"input": "10 3\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0 0 1000... | false | stdio | null | true |
439/B | 439 | B | Python 3 | TESTS | 5 | 124 | 0 | 41611565 | n=input().split()
n[0]=int(n[0])
n[1]=int(n[1])
l=input().split()
l.sort()
p=0
for x in range(n[0]):
if n[1]==1:
p+=int(l[x])
else:
p+=n[1]*int(l[x])
n[1]=n[1]-1
print(p) | 31 | 93 | 11,366,400 | 168477571 | n, m = map(int, input().split())
res = 0
l = sorted([int(i) for i in input().split()])
for i in range(n):
if m == 1:
res += l[i]
else:
res += l[i] * m
m -= 1
print(res) | Codeforces Round 251 (Div. 2) | CF | 2,014 | 1 | 256 | Devu, the Dumb Guy | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is x hours. In other words he can... | The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). | Output a single integer representing the answer to the problem. | null | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ... | [{"input": "2 3\n4 1", "output": "11"}, {"input": "4 2\n5 1 2 1", "output": "10"}, {"input": "3 3\n1 1 1", "output": "6"}] | 1,200 | ["implementation", "sortings"] | 31 | [{"input": "2 3\r\n4 1\r\n", "output": "11\r\n"}, {"input": "4 2\r\n5 1 2 1\r\n", "output": "10\r\n"}, {"input": "3 3\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "20 4\r\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3\r\n", "output": "65\r\n"}, {"input": "20 10\r\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3\r\n", "output": "196\... | false | stdio | null | true |
690/B1 | 690 | B1 | Python 3 | TESTS | 7 | 93 | 7,065,600 | 37352938 | n = int(input())
grid = []
flag = True
ans = -1
while(n):
n-=1
grid.append(str(int(input())))
for i in grid:
if(i!='0'):
if(ans==-1 or len(i)==ans):
ans = len(i)
else:
flag = False
if(flag):
print('Yes')
else:... | 21 | 140 | 21,401,600 | 84934143 | n = int(input())
A = [input() for i in range(n)]
def early_exit():
print("No")
exit()
if n < 3:
early_exit()
# first find the corner
corner_row = []
for i in range(n):
if '1' in A[i]:
corner_row.append(i)
if len(corner_row) != 2:
early_exit()
# now for each of the corner row, find the corre... | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 2 | 256 | Recover Polygon (easy) | The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good.
Heidi knows that the lair can be represented as a rectangle on a lattice, with si... | The first line of each test case contains one integer N, the size of the lattice grid (5 ≤ N ≤ 50). The next N lines each contain N characters, describing the level of Zombie Contamination of each cell in the lattice. Every character of every line is a digit between 0 and 4.
Cells are given in the same order as they a... | The first line of the output should contain Yes if there exists a single non-zero area rectangular lair with corners on the grid for which checking the levels of Zombie Contamination gives the results given in the input, and No otherwise. | null | The lair, if it exists, has to be rectangular (that is, have corners at some grid points with coordinates (x1, y1), (x1, y2), (x2, y1), (x2, y2)), has a non-zero area and be contained inside of the grid (that is, 0 ≤ x1 < x2 ≤ N, 0 ≤ y1 < y2 ≤ N), and result in the levels of Zombie Contamination as reported in the inpu... | [{"input": "6\n000000\n000000\n012100\n024200\n012100\n000000", "output": "Yes"}] | 1,700 | [] | 21 | [{"input": "6\r\n000000\r\n000000\r\n012100\r\n024200\r\n012100\r\n000000\r\n", "output": "Yes\r\n"}, {"input": "6\r\n000000\r\n012210\r\n024420\r\n012210\r\n000000\r\n000000\r\n", "output": "Yes\r\n"}, {"input": "6\r\n000100\r\n001210\r\n002420\r\n001210\r\n000000\r\n000000\r\n", "output": "No\r\n"}, {"input": "10\r\n... | false | stdio | null | true |
490/B | 490 | B | PyPy 3-64 | TESTS | 2 | 78 | 0 | 177470631 | import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
d = defaultdict(list)
for i in range(n):
a, b = map(int, input().split())
if a == 0:
x = b
elif b == 0:
y = a
else:
d[a].append((0, b))
d[b].append((1, a))
l = [0, x]
r = [0, y]
w... | 61 | 795 | 44,851,200 | 216194526 | n = int(input())
A, B = set(), set()
d = {}
for i in range(n):
a, b = map(int, input().split())
d[a] = b
A.add(a)
B.add(b)
sol = [0] * n
sol[0] = (A - B).pop()
sol[1] = d[0]
for i in range(2, n):
sol[i] = d[sol[i - 2]]
print(*sol) | Codeforces Round 279 (Div. 2) | CF | 2,014 | 2 | 256 | Queue | During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of... | The first line contains integer n (2 ≤ n ≤ 2·105) — the number of students in the queue.
Then n lines follow, i-th line contains the pair of integers ai, bi (0 ≤ ai, bi ≤ 106), where ai is the ID number of a person in front of a student and bi is the ID number of a person behind a student. The lines are given in the a... | Print a sequence of n integers x1, x2, ..., xn — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one. | null | The picture illustrates the queue for the first sample. | [{"input": "4\n92 31\n0 7\n31 0\n7 141", "output": "92 7 31 141"}] | 1,500 | ["dsu", "implementation"] | 61 | [{"input": "4\r\n92 31\r\n0 7\r\n31 0\r\n7 141\r\n", "output": "92 7 31 141 \r\n"}, {"input": "2\r\n0 1\r\n2 0\r\n", "output": "2 1 \r\n"}, {"input": "3\r\n0 2\r\n1 3\r\n2 0\r\n", "output": "1 2 3 \r\n"}, {"input": "4\r\n101 0\r\n0 102\r\n102 100\r\n103 101\r\n", "output": "103 102 101 100 \r\n"}, {"input": "5\r\n0 1\r... | false | stdio | null | true |
44/A | 44 | A | Python 3 | TESTS | 28 | 62 | 0 | 148184816 | import sys
t=int(input())
l=[]
for i in range(t):
n=input()
x=n.split()
p=x[0]+x[1]
l.append(p)
l=set(l)
print(len(l)) | 29 | 62 | 0 | 147786794 | t = int(input())
l = []
for i in range(t):
a = input()
l.append(a)
print(len(set(l))) | School Team Contest 2 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | Indian Summer | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 ... | Output the single number — the number of Alyona's leaves. | null | null | [{"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4"}, {"input": "3\noak yellow\noak yellow\noak yellow", "output": "1"}] | 900 | ["implementation"] | 29 | [{"input": "5\r\nbirch yellow\r\nmaple red\r\nbirch yellow\r\nmaple yellow\r\nmaple green\r\n", "output": "4\r\n"}, {"input": "3\r\noak yellow\r\noak yellow\r\noak yellow\r\n", "output": "1\r\n"}, {"input": "5\r\nxbnbkzn hp\r\nkaqkl vrgzbvqstu\r\nj aqidx\r\nhos gyul\r\nwefxmh tygpluae\r\n", "output": "5\r\n"}, {"input"... | false | stdio | null | true |
56/B | 56 | B | PyPy 3 | TESTS | 7 | 184 | 0 | 106491210 | n = int(input())
arr = list(map(int, input().split()))
l, r = -1, -1
i = 0
while(i+1<n and arr[i]+1==arr[i+1]):
i+=1
l = i
i+=1
while(i+1<n and arr[i]-1==arr[i+1]):
i+=1
r = i
i+=1
while(i+1<n and arr[i]+1==arr[i+1]):
i+=1
if(r != -1 and i>= n-1):
print(l+2, r+1)
else:
print(0, 0) | 33 | 92 | 0 | 144285648 | n = int(input())
s = input().split()
s = [int(i) for i in s]
sorted_s = sorted(s)
i = 0
flag = 0
while(i<n):
if(s[i] != sorted_s[i]):
flag = 1
sub1 = s[:i]
sub2 = s[i:s[i]][::-1]
sub3 = s[s[i]:]
tot = sub1 + sub2 + sub3
#print(tot)
if(tot == sorted_s):
print(i+1,s[i])
break
else:
print(0,0... | Codeforces Beta Round 52 (Div. 2) | CF | 2,011 | 2 | 256 | Spoilt Permutation | Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order... | The first line contains an integer n (1 ≤ n ≤ 1000) which is the number of coins in Vasya's collection. The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is u... | If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one. | null | null | [{"input": "8\n1 6 5 4 3 2 7 8", "output": "2 6"}, {"input": "4\n2 3 4 1", "output": "0 0"}, {"input": "4\n1 2 3 4", "output": "0 0"}] | 1,300 | ["implementation"] | 33 | [{"input": "8\r\n1 6 5 4 3 2 7 8\r\n", "output": "2 6\r\n"}, {"input": "4\r\n2 3 4 1\r\n", "output": "0 0\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 2 4 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 4 2 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "1\r\n1\r\n", "output": "... | false | stdio | null | true |
44/A | 44 | A | Python 3 | TESTS | 28 | 92 | 0 | 172926703 | t = int(input())
lst = []
for i in range(t):
a, b = input().split()
lst.append(a + b)
print(len(set(lst))) | 29 | 62 | 0 | 147786951 | x = int(input())
lst = []
for i in range(x):
s = input()
lst.append(s)
lst = list(set(lst))
print(len(lst)) | School Team Contest 2 (Winter Computer School 2010/11) | ICPC | 2,010 | 2 | 256 | Indian Summer | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 ... | Output the single number — the number of Alyona's leaves. | null | null | [{"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4"}, {"input": "3\noak yellow\noak yellow\noak yellow", "output": "1"}] | 900 | ["implementation"] | 29 | [{"input": "5\r\nbirch yellow\r\nmaple red\r\nbirch yellow\r\nmaple yellow\r\nmaple green\r\n", "output": "4\r\n"}, {"input": "3\r\noak yellow\r\noak yellow\r\noak yellow\r\n", "output": "1\r\n"}, {"input": "5\r\nxbnbkzn hp\r\nkaqkl vrgzbvqstu\r\nj aqidx\r\nhos gyul\r\nwefxmh tygpluae\r\n", "output": "5\r\n"}, {"input"... | false | stdio | null | true |
56/B | 56 | B | Python 3 | TESTS | 14 | 92 | 0 | 209778092 | import sys
n = int(input())
a = list(map(int, input().split()))
check = [i+1 for i in range(n)]
if a == check:
print(0, 0)
sys.exit(0)
l,r = 0, 0
for i in range(1, n):
if a[i] > a[i-1]:
l = i
break
for i in range(n-1,-1,-1):
if a[i] < a[i-1]:
r = i
break
c1,c2 = l,r
wh... | 33 | 92 | 0 | 145116479 | n = int(input())
data = input().split()
data2 = []
for i in range(n):
if str(i+1) != data[i]:
data2.append((data[i], i))
data2.reverse()
if data2:
o = list(range(1, n+1))
can = True
for i in range(len(data2)):
if o.index(int(data2[i][0])) != int(data2[-i-1][1]):
can = False
... | Codeforces Beta Round 52 (Div. 2) | CF | 2,011 | 2 | 256 | Spoilt Permutation | Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order... | The first line contains an integer n (1 ≤ n ≤ 1000) which is the number of coins in Vasya's collection. The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is u... | If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one. | null | null | [{"input": "8\n1 6 5 4 3 2 7 8", "output": "2 6"}, {"input": "4\n2 3 4 1", "output": "0 0"}, {"input": "4\n1 2 3 4", "output": "0 0"}] | 1,300 | ["implementation"] | 33 | [{"input": "8\r\n1 6 5 4 3 2 7 8\r\n", "output": "2 6\r\n"}, {"input": "4\r\n2 3 4 1\r\n", "output": "0 0\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 2 4 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 4 2 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "1\r\n1\r\n", "output": "... | false | stdio | null | true |
154/A | 154 | A | PyPy 3 | TESTS | 4 | 216 | 0 | 114251403 | def f(a,bad):
i=0
cnt=0
while a and i+1<len(a):
if bad.get(a[i],None)==a[i+1]:
cnt+=1
a.pop(i+1)
else:
i+=1
return cnt
a=list(input())
n=int(input())
bad={}
for i in range(n):
l=list(input())
bad[l[0]]=l[1]
bad[l[1]]=l[0]
print(f(a,bad)) | 42 | 218 | 2,457,600 | 116908726 | import sys
input=sys.stdin.readline
s=input().rstrip()
k=int(input())
cannot=[input().rstrip() for i in range(k)]
ans=0
for t in cannot:
a,b=0,0
for i in range(len(s)):
if s[i]==t[0]:
a+=1
elif s[i]==t[1]:
b+=1
else:
ans+=min(a,b)
a=b=0
ans+=min(a,b)
print(ans) | Codeforces Round 109 (Div. 1) | CF | 2,012 | 2 | 256 | Hometask | Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks.
Sergey totally forgot about ... | The first line contains a non-empty string s, consisting of lowercase Latin letters — that's the initial sentence in N-ish, written by Sergey. The length of string s doesn't exceed 105.
The next line contains integer k (0 ≤ k ≤ 13) — the number of forbidden pairs of letters.
Next k lines contain descriptions of forbi... | Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters. | null | In the first sample you should remove two letters b.
In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution. | [{"input": "ababa\n1\nab", "output": "2"}, {"input": "codeforces\n2\ndo\ncs", "output": "1"}] | 1,600 | ["greedy"] | 42 | [{"input": "ababa\r\n1\r\nab\r\n", "output": "2\r\n"}, {"input": "codeforces\r\n2\r\ndo\r\ncs\r\n", "output": "1\r\n"}, {"input": "nllnrlrnll\r\n1\r\nrl\r\n", "output": "1\r\n"}, {"input": "aludfbjtwnkgnfl\r\n1\r\noy\r\n", "output": "0\r\n"}, {"input": "pgpgppgggpbbnnn\r\n2\r\npg\r\nnb\r\n", "output": "7\r\n"}, {"input... | false | stdio | null | true |
696/A | 696 | A | PyPy 3-64 | TESTS | 2 | 77 | 3,891,200 | 178250499 | q=int(input())
eta={}
for j in range(q):
c=[int(k) for k in input().split()]
if c[0]==1:
a, b=bin(c[1])[2:], bin(c[2])[2:]
#print(a, b)
zeta=len(a)
for k in range(min(len(a), len(b))):
if a[k]==b[k]:
zeta-=1
for k in range(zeta):
if... | 49 | 140 | 11,366,400 | 198925231 | d={}
def pro(x,y,w):
res=0
while x!=y:
if x<y: x,y=y,x
d[x]=d.get(x,0)+w
res+=d[x];
x//=2
return res
q=int(input())
while q>0:
q-=1
s=list(map(int,input().split()))
if s[0]==1:
pro(s[1],s[2],s[3])
else:
print(pro(s[1],s[2],0)) | Codeforces Round 362 (Div. 1) | CF | 2,016 | 1 | 256 | Lorenzo Von Matterhorn | Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two... | The first line of input contains a single integer q (1 ≤ q ≤ 1 000).
The next q lines contain the information about the events in chronological order. Each event is described in form 1 v u w if it's an event when government makes a new rule about increasing the passing fee of all roads on the shortest path from u to v... | For each event of second type print the sum of passing fee of all roads Barney passes in this event, in one line. Print the answers in chronological order of corresponding events. | null | In the example testcase:
Here are the intersections used:
1. Intersections on the path are 3, 1, 2 and 4.
2. Intersections on the path are 4, 2 and 1.
3. Intersections on the path are only 3 and 6.
4. Intersections on the path are 4, 2, 1 and 3. Passing fee of roads on the path are 32, 32 and 30 in order. So answer e... | [{"input": "7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4", "output": "94\n0\n32"}] | 1,500 | ["brute force", "data structures", "implementation", "trees"] | 49 | [{"input": "7\r\n1 3 4 30\r\n1 4 1 2\r\n1 3 6 8\r\n2 4 3\r\n1 6 1 40\r\n2 3 7\r\n2 2 4\r\n", "output": "94\r\n0\r\n32\r\n"}, {"input": "1\r\n2 666077344481199252 881371880336470888\r\n", "output": "0\r\n"}, {"input": "10\r\n1 1 63669439577744021 396980128\r\n1 2582240553355225 63669439577744021 997926286\r\n1 258224055... | false | stdio | null | true |
70/B | 70 | B | PyPy 3 | TESTS | 10 | 93 | 20,172,800 | 130632694 | n = int(input())
s = input()
a = [""]
for c in s:
if a[-1] == "" and c == ' ':
continue
a[-1] += c;
if c == '?' or c == '!' or c == '.':
a.append("");
ans = 0
last = 0
for i in range(len(a)-1):
if len(a[i]) > n:
print('Impossible')
exit(0)
elif i == 0 or (last + len(a... | 48 | 171 | 1,331,200 | 78864704 | import sys
n = int(input())
s = str(input())
m = len(s)
cnt = 0
gd = False
ans = 0
lst = 0
end = ['.', '?', '!']
rem = 0
for i in range(m):
cnt += 1
if(s[i] in end):
gd = True
lst = cnt # store the last good one
if(cnt == n):
if(not gd):
print("Impossible")
ex... | Codeforces Beta Round 64 | CF | 2,011 | 1 | 256 | Text Messaging | Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split!
Fangy did not like ... | The first line contains an integer n, which is the size of one message (2 ≤ n ≤ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. | On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. | null | Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". | [{"input": "25\nHello. I am a little walrus.", "output": "2"}, {"input": "2\nHow are you?", "output": "Impossible"}, {"input": "19\nHello! Do you like fish? Why?", "output": "3"}] | 1,600 | ["expression parsing", "greedy", "strings"] | 48 | [{"input": "25\r\nHello. I am a little walrus.\r\n", "output": "2\r\n"}, {"input": "2\r\nHow are you?\r\n", "output": "Impossible\r\n"}, {"input": "19\r\nHello! Do you like fish? Why?\r\n", "output": "3\r\n"}, {"input": "4\r\na. A.\r\n", "output": "2\r\n"}, {"input": "146\r\niIQVkDsPqzAJyBrtHk EhBSN gzDoigItCMzETerb cI... | false | stdio | null | true |
455/B | 455 | B | PyPy 3-64 | TESTS | 2 | 61 | 0 | 206137785 | import sys
from collections import defaultdict
input = sys.stdin.readline
n, k = map(int, input().split())
class BorNode:
def __init__(self, prefix=''):
self.prefix = prefix
self.children = defaultdict(int)
self.is_terminal = False
self.is_win = None
self.is_lose = None
... | 75 | 920 | 6,451,200 | 7386129 | """
Codeforces Contest 260 Div 1 Problem B
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
n,k = read()
s = set()
for i in range(n): s.add(read(0))
s = list(s)
s.sort()
s = treeify(s)
res = solve(s)
if res == 0: # neither: second player win
print("Second")
if r... | Codeforces Round 260 (Div. 1) | CF | 2,014 | 1 | 256 | A Lot of Games | Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players.
Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the re... | The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 109).
Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn't exceed 105. Each string of the group consists only of lowercase English letters. | If the player who moves first wins, print "First", otherwise print "Second" (without the quotes). | null | null | [{"input": "2 3\na\nb", "output": "First"}, {"input": "3 1\na\nb\nc", "output": "First"}, {"input": "1 2\nab", "output": "Second"}] | 1,900 | ["dfs and similar", "dp", "games", "implementation", "strings", "trees"] | 75 | [{"input": "2 3\r\na\r\nb\r\n", "output": "First\r\n"}, {"input": "3 1\r\na\r\nb\r\nc\r\n", "output": "First\r\n"}, {"input": "1 2\r\nab\r\n", "output": "Second\r\n"}, {"input": "5 6\r\nabas\r\ndsfdf\r\nabacaba\r\ndartsidius\r\nkolobok\r\n", "output": "Second\r\n"}, {"input": "4 2\r\naaaa\r\nbbbb\r\nccccc\r\ndumbavumba... | false | stdio | null | true |
56/B | 56 | B | Python 3 | TESTS | 14 | 154 | 0 | 117491308 | import math
n=int(input())
lst = list(map(int, input().strip().split(' ')))
l=-1
r=-1
k=0
if n%2==0:
k=n//2
else:
k=n//2 + 1
for i in range(k):
if l==-1 and lst[i]!=i+1:
l=i
if r==-1 and lst[n-i-1]!=n-i:
r=n-i-1
if l!=-1 and r!=-1:
break
if l==-1 and r==-1:
print('0 0')
e... | 33 | 92 | 0 | 153768422 | N=int(input())
A=list(map(int,input().split()))
mn,mx=N+1,-1
for i in range(N):
if(i+1!=A[i]):
mn=min(mn,i)
mx=max(mx,i)
if(mx==-1):
print('0 0')
else:
#print('/yiw')
A=A[:mn]+A[mn:(mx+1)][::-1]+A[(mx+1):]
#print('/kk')
#sorted(A)==A
#print('>')
if(sorted(A)==A):
... | Codeforces Beta Round 52 (Div. 2) | CF | 2,011 | 2 | 256 | Spoilt Permutation | Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order... | The first line contains an integer n (1 ≤ n ≤ 1000) which is the number of coins in Vasya's collection. The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is u... | If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one. | null | null | [{"input": "8\n1 6 5 4 3 2 7 8", "output": "2 6"}, {"input": "4\n2 3 4 1", "output": "0 0"}, {"input": "4\n1 2 3 4", "output": "0 0"}] | 1,300 | ["implementation"] | 33 | [{"input": "8\r\n1 6 5 4 3 2 7 8\r\n", "output": "2 6\r\n"}, {"input": "4\r\n2 3 4 1\r\n", "output": "0 0\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 2 4 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 4 2 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "1\r\n1\r\n", "output": "... | false | stdio | null | true |
439/B | 439 | B | Python 3 | TESTS | 6 | 62 | 6,758,400 | 122937082 | n, t = map(int, input().split())
a = sorted(map(int, input().split()))
count = 0
for i in range(0, n):
if t > 1:
count += t*a[i]
t -= 1
else:
count += a[i]
print(count%1000001) | 31 | 93 | 11,366,400 | 224691998 | n,x = map(int,input().split())
l = [int(x) for x in input().split()]
l.sort()
# pre = [0]*n
# pre[0]=l[0]
# for i in range(1,n):
# pre[i]=pre[i-1]+l[i]
t = 0
for j in range(n):
t+=(l[j]*x)
if x>1:
x-=1
print(t) | Codeforces Round 251 (Div. 2) | CF | 2,014 | 1 | 256 | Devu, the Dumb Guy | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is x hours. In other words he can... | The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105). | Output a single integer representing the answer to the problem. | null | Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ... | [{"input": "2 3\n4 1", "output": "11"}, {"input": "4 2\n5 1 2 1", "output": "10"}, {"input": "3 3\n1 1 1", "output": "6"}] | 1,200 | ["implementation", "sortings"] | 31 | [{"input": "2 3\r\n4 1\r\n", "output": "11\r\n"}, {"input": "4 2\r\n5 1 2 1\r\n", "output": "10\r\n"}, {"input": "3 3\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "20 4\r\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3\r\n", "output": "65\r\n"}, {"input": "20 10\r\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3\r\n", "output": "196\... | false | stdio | null | true |
154/A | 154 | A | Python 3 | TESTS | 4 | 124 | 0 | 9284800 | import sys
import math
s = sys.stdin.readline()
k = int(sys.stdin.readline())
v = {}
for i in range(k):
st = sys.stdin.readline()
v[st[0]] = st[1]
v[st[1]] = st[0]
i = 1
tt = s[0]
res = 0
while(s[i] != '\n'):
if s[i] in v:
if(tt == v[s[i]]):
res += 1
else:
... | 42 | 248 | 512,000 | 5544564 | p, t = {}, input()
a, n = False, len(t)
x = y = s = 0
q = [input() for i in range(int(input()))]
for a, b in q: p[a], p[b] = b, a
for i in t:
if a:
if i == a: x += 1
elif i == b: y += 1
else:
s += min(x, y)
if i in p:
a, b = i, p[i]
x, ... | Codeforces Round 109 (Div. 1) | CF | 2,012 | 2 | 256 | Hometask | Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks.
Sergey totally forgot about ... | The first line contains a non-empty string s, consisting of lowercase Latin letters — that's the initial sentence in N-ish, written by Sergey. The length of string s doesn't exceed 105.
The next line contains integer k (0 ≤ k ≤ 13) — the number of forbidden pairs of letters.
Next k lines contain descriptions of forbi... | Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters. | null | In the first sample you should remove two letters b.
In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution. | [{"input": "ababa\n1\nab", "output": "2"}, {"input": "codeforces\n2\ndo\ncs", "output": "1"}] | 1,600 | ["greedy"] | 42 | [{"input": "ababa\r\n1\r\nab\r\n", "output": "2\r\n"}, {"input": "codeforces\r\n2\r\ndo\r\ncs\r\n", "output": "1\r\n"}, {"input": "nllnrlrnll\r\n1\r\nrl\r\n", "output": "1\r\n"}, {"input": "aludfbjtwnkgnfl\r\n1\r\noy\r\n", "output": "0\r\n"}, {"input": "pgpgppgggpbbnnn\r\n2\r\npg\r\nnb\r\n", "output": "7\r\n"}, {"input... | false | stdio | null | true |
56/B | 56 | B | Python 3 | TESTS | 7 | 124 | 307,200 | 108974240 | n=int(input())
ls=list(map(int,input().split()))
flag=0
if ls==ls[::-1] and len(ls)!=1:
print("1"+" "+str(n))
else:
ans=list(range(1,n+1))
for i in range(n-1):
for j in range(i+1,n):
if ls[:i]+ls[j:i-1:-1]+ls[(j+1):]==ans:
print(str(i+1)+" "+str(j+1))
flag... | 33 | 92 | 0 | 183313085 | n=int(input())
a=list(map(int,input().split()))
l,r=-1,-1
for i in range(n):
if a[i]!=i+1:
l=i
break
for i in range(n-1,-1,-1):
if a[i]!=i+1:
r=i
break
j=r+1
for i in range(l,r+1):
if a[i]==j:
j-=1
continue
else:
print(0,0)
exit(0)
pri... | Codeforces Beta Round 52 (Div. 2) | CF | 2,011 | 2 | 256 | Spoilt Permutation | Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order... | The first line contains an integer n (1 ≤ n ≤ 1000) which is the number of coins in Vasya's collection. The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is u... | If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one. | null | null | [{"input": "8\n1 6 5 4 3 2 7 8", "output": "2 6"}, {"input": "4\n2 3 4 1", "output": "0 0"}, {"input": "4\n1 2 3 4", "output": "0 0"}] | 1,300 | ["implementation"] | 33 | [{"input": "8\r\n1 6 5 4 3 2 7 8\r\n", "output": "2 6\r\n"}, {"input": "4\r\n2 3 4 1\r\n", "output": "0 0\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 2 4 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 4 2 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "1\r\n1\r\n", "output": "... | false | stdio | null | true |
739/A | 739 | A | PyPy 3 | TESTS | 4 | 77 | 20,172,800 | 127795929 | starts=[]
ans=[]
mn=10**18
n,m=map(int,input().split())
for i in range(m):
x,y=map(int,input().split())
mn=min(mn,y-x+1)
starts.append(x)
i=0
num=0
counter=0
while(i<n):
i+=1
if(starts[counter]==i):
counter+=1
counter=min(counter,m-1)
num=0
else:
num+=1
ans.ap... | 69 | 374 | 36,659,200 | 124730404 | import sys
input=sys.stdin.readline
n,m=map(int,input().split())
seg=[list(map(int,input().split())) for i in range(m)]
min_l=10**18
for l,r in seg:
min_l=min(min_l,r-l+1)
ans=[i for i in range(min_l)]*((n+min_l-1)//min_l)
ans=ans[:n]
print(min_l)
print(*ans) | Codeforces Round 381 (Div. 1) | CF | 2,016 | 2 | 256 | Alyona and mex | Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, ... | The first line contains two integers n and m (1 ≤ n, m ≤ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n), that describe the subarray a[li], a[li + 1], ..., a[ri]. | In the first line print single integer — the maximum possible minimum mex.
In the second line print n integers — the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, prin... | null | The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | [{"input": "5 3\n1 3\n2 5\n4 5", "output": "2\n1 0 2 1 0"}, {"input": "4 2\n1 4\n2 4", "output": "3\n5 2 0 1"}] | 1,700 | ["constructive algorithms", "greedy"] | 69 | [{"input": "5 3\r\n1 3\r\n2 5\r\n4 5\r\n", "output": "2\r\n0 1 0 1 0\r\n"}, {"input": "4 2\r\n1 4\r\n2 4\r\n", "output": "3\r\n0 1 2 0\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n0\r\n"}, {"input": "2 1\r\n2 2\r\n", "output": "1\r\n0 0\r\n"}, {"input": "5 6\r\n2 4\r\n2 3\r\n1 4\r\n3 4\r\n2 5\r\n1 3\r\n", "output... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path, 'r') as f:
n, m = map(int, f.readline().split())
subarrays = [tuple(map(int, line.strip().split())) for line in f]
# Read reference output... | true |
490/B | 490 | B | PyPy 3-64 | TESTS | 3 | 46 | 0 | 179040721 | no_stu = int(input())
pairs = {}
queue = [0]*no_stu
back_set = set()
for i in range(no_stu):
front, back = list(map(int, input().split()))
if front==0:
queue[1]=back
elif back==0:
queue[-2]=front
else:
pairs[front] = back
back_set.add(back)
for i in pairs:
if i not in... | 61 | 888 | 29,491,200 | 165675179 | n = int(input())
cd = set()
trace = {}
nodes = set()
for _ in range(n):
a, b = input().split()
if a == '0':
a = 'start'
if b == '0':
b = 'end'
cd.add(b)
nodes.add(a)
nodes.add(b)
trace[a] = b
first, second = -1, trace.get('start')
for nd in nodes:
if nd not in cd and nd... | Codeforces Round 279 (Div. 2) | CF | 2,014 | 2 | 256 | Queue | During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of... | The first line contains integer n (2 ≤ n ≤ 2·105) — the number of students in the queue.
Then n lines follow, i-th line contains the pair of integers ai, bi (0 ≤ ai, bi ≤ 106), where ai is the ID number of a person in front of a student and bi is the ID number of a person behind a student. The lines are given in the a... | Print a sequence of n integers x1, x2, ..., xn — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one. | null | The picture illustrates the queue for the first sample. | [{"input": "4\n92 31\n0 7\n31 0\n7 141", "output": "92 7 31 141"}] | 1,500 | ["dsu", "implementation"] | 61 | [{"input": "4\r\n92 31\r\n0 7\r\n31 0\r\n7 141\r\n", "output": "92 7 31 141 \r\n"}, {"input": "2\r\n0 1\r\n2 0\r\n", "output": "2 1 \r\n"}, {"input": "3\r\n0 2\r\n1 3\r\n2 0\r\n", "output": "1 2 3 \r\n"}, {"input": "4\r\n101 0\r\n0 102\r\n102 100\r\n103 101\r\n", "output": "103 102 101 100 \r\n"}, {"input": "5\r\n0 1\r... | false | stdio | null | true |
501/C | 501 | C | PyPy 3-64 | TESTS | 2 | 46 | 0 | 178272399 | n=int(input())
w=[]
eta=[]
for j in range(n):
w.append([int(k) for k in input().split()])
for j in range(n):
if w[j][0]==1:
eta.append([j, w[j][1]])
w[w[j][1]][1]=w[w[j][1]][1]^j
w[w[j][1]][0]-=1
w[j][0]=0
w[j][1]=0
iota=w[j][1]
while w[iota][0]==1:
... | 49 | 233 | 26,009,600 | 188040560 | import sys
def read(T):
return [T(i) for i in sys.stdin.readline().split()]
def main():
n=read(int)[0]
a=[read(int) for i in range(n)]
stack,res=[],[]
for i in range(n):
if a[i][0]==1:
stack.append(i)
while len(stack):
cur=stack.pop()
if not a[cur][0]:
continue
res.append([cur,a[cur][1]])
a[cur... | Codeforces Round 285 (Div. 2) | CF | 2,015 | 1 | 256 | Misha and Forest | Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the secon... | The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph.
The i-th of the next lines contains numbers degreei and si (0 ≤ degreei ≤ n - 1, 0 ≤ si < 216), separated by a space. | In the first line print number m, the number of edges of the graph.
Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b).
Edges can be printed in any order; vertices of the edge can also be printed in any order. | null | The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor". | [{"input": "3\n2 3\n1 0\n1 0", "output": "2\n1 0\n2 0"}, {"input": "2\n1 1\n1 0", "output": "1\n0 1"}] | 1,500 | ["constructive algorithms", "data structures", "greedy", "sortings", "trees"] | 49 | [{"input": "3\r\n2 3\r\n1 0\r\n1 0\r\n", "output": "2\r\n1 0\r\n2 0\r\n"}, {"input": "2\r\n1 1\r\n1 0\r\n", "output": "1\r\n0 1\r\n"}, {"input": "10\r\n3 13\r\n2 6\r\n1 5\r\n3 5\r\n1 3\r\n2 2\r\n2 6\r\n1 6\r\n1 3\r\n2 3\r\n", "output": "9\r\n2 5\r\n4 3\r\n7 6\r\n8 3\r\n5 0\r\n6 1\r\n3 9\r\n1 0\r\n9 0\r\n"}, {"input": "... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2] # not used
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
lines = [line.strip() for line in f if line.strip()]
n = int(lines[0])
degrees = []
s_list = []
for l... | true |
56/B | 56 | B | Python 3 | TESTS | 7 | 218 | 6,963,200 | 86098035 | n=int(input())
a=list(map(int,input().split()))
L=0
if a[L]==1:
while L<n-1:
if a[L+1]-a[L]!=1:
break
L+=1
if L==n-1:
print(0,0)
exit()
L+=1
R=a.index(L+1)
a=a[:L]+a[R:L-1:-1]+a[R+1:]
b=[x for x in range(1,n+1)]
if a==b:
print(L+1,R+1)
else:
print(0,0) | 33 | 92 | 4,505,600 | 161868235 | n = int(input())
arr = list(map(int,input().split()))
l,r = -1,-1
for i in range(n):
if arr[i] != i+1:
l = i
break
for i in range(n-1,-1,-1):
if arr[i] != i+1:
r = i
break
s = r+1
for i in range(l,s):
if arr[i]==s:
s -= 1
continue
else:
print(0,0)
exit(0)
print(l+1,r+1) | Codeforces Beta Round 52 (Div. 2) | CF | 2,011 | 2 | 256 | Spoilt Permutation | Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order... | The first line contains an integer n (1 ≤ n ≤ 1000) which is the number of coins in Vasya's collection. The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is u... | If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one. | null | null | [{"input": "8\n1 6 5 4 3 2 7 8", "output": "2 6"}, {"input": "4\n2 3 4 1", "output": "0 0"}, {"input": "4\n1 2 3 4", "output": "0 0"}] | 1,300 | ["implementation"] | 33 | [{"input": "8\r\n1 6 5 4 3 2 7 8\r\n", "output": "2 6\r\n"}, {"input": "4\r\n2 3 4 1\r\n", "output": "0 0\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 2 4 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 4 2 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "1\r\n1\r\n", "output": "... | false | stdio | null | true |
56/B | 56 | B | PyPy 3 | TESTS | 7 | 218 | 23,040,000 | 20031253 | def s():
input()
a = list(map(int,input().split()))
b = list(range(1,len(a)+1))
l,r = 0,0
for i,v in enumerate(a):
if v != b[i]:
l = i
break
for i,v in reversed(list(enumerate(a))):
if v != b[i]:
r = i
break
a[l:r+1] = a[r:l-1:-1]
if a == b:
print(l+1,r+1)
else:
print(0,0)
s() | 33 | 122 | 4,505,600 | 135321089 | import sys
n = int(sys.stdin.readline())
seq = sys.stdin.readline().split(' ')
left = 0
right = 0
isPermFound = False
for i in range(1, n):
if int(seq[i]) - int(seq[i-1]) > 1:
if left == 0:
left = i + 1
elif isPermFound:
print("0 0")
exit(0)
else:
... | Codeforces Beta Round 52 (Div. 2) | CF | 2,011 | 2 | 256 | Spoilt Permutation | Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order... | The first line contains an integer n (1 ≤ n ≤ 1000) which is the number of coins in Vasya's collection. The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is u... | If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one. | null | null | [{"input": "8\n1 6 5 4 3 2 7 8", "output": "2 6"}, {"input": "4\n2 3 4 1", "output": "0 0"}, {"input": "4\n1 2 3 4", "output": "0 0"}] | 1,300 | ["implementation"] | 33 | [{"input": "8\r\n1 6 5 4 3 2 7 8\r\n", "output": "2 6\r\n"}, {"input": "4\r\n2 3 4 1\r\n", "output": "0 0\r\n"}, {"input": "4\r\n1 2 3 4\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 2 4 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "8\r\n1 3 4 2 6 5 7 8\r\n", "output": "0 0\r\n"}, {"input": "1\r\n1\r\n", "output": "... | false | stdio | null | true |
698/B | 698 | B | PyPy 3-64 | TESTS | 4 | 61 | 0 | 189687081 | n=int(input())
arr=[int(h) for h in input().split()]
visited=[0]*n
change=[]
root=[]
for i in range(1,n+1):
if arr[i-1]==i:
root.append(i)
j=i
if visited[i-1]==1:
continue
h=set()
while j not in h:
h.add(j)
visited[j-1]=1
j=arr[j-1]
if j in h:
cha... | 101 | 405 | 26,521,600 | 36753020 | n = int(input())
arr = list(map(int, input().split(' ')))
root=-1
for i,a in enumerate(arr) :
if i == a-1 :
root = i
break
v = [False]*len(arr)
if root>-1 :
v[root]=True
ans = 0
for i,a in enumerate(arr) :
if v[i] :
continue
v[i]= True
l=[i]
a-=1
while not v[a] :
... | Codeforces Round 363 (Div. 1) | CF | 2,016 | 2 | 256 | Fix a Tree | A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons... | The first line of the input contains an integer n (2 ≤ n ≤ 200 000) — the number of vertices in the tree.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n). | In the first line print the minimum number of elements to change, in order to get a valid sequence.
In the second line, print any valid sequence possible to get from (a1, a2, ..., an) in the minimum number of changes. If there are many such sequences, any of them will be accepted. | null | In the first sample, it's enough to change one element. In the provided output, a sequence represents a tree rooted in a vertex 4 (because p4 = 4), which you can see on the left drawing below. One of other correct solutions would be a sequence 2 3 3 2, representing a tree rooted in vertex 3 (right drawing below). On bo... | [{"input": "4\n2 3 3 4", "output": "1\n2 3 4 4"}, {"input": "5\n3 2 2 5 3", "output": "0\n3 2 2 5 3"}, {"input": "8\n2 3 5 4 1 6 6 7", "output": "2\n2 3 7 8 1 6 6 7"}] | 1,700 | ["constructive algorithms", "dfs and similar", "dsu", "graphs", "trees"] | 101 | [{"input": "4\r\n2 3 3 4\r\n", "output": "1\r\n2 3 4 4 \r\n"}, {"input": "5\r\n3 2 2 5 3\r\n", "output": "0\r\n3 2 2 5 3 \r\n"}, {"input": "8\r\n2 3 5 4 1 6 6 7\r\n", "output": "2\r\n2 3 7 8 1 6 6 7\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n2 2 \r\n"}, {"input": "7\r\n4 3 2 6 3 5 2\r\n", "output": "1\r\n4 3 3 6 ... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_output_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
assert len(a) == n
# Read submission's output
with open(submission_output_path... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.