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
177/E1
177
E1
Python 3
TESTS1
3
216
0
51955837
n, c = map(int, input().split()) a = [] b = [] for i in range(n): aa, bb = map(int, input().split()) a.append(aa) b.append(bb) def all_zero(): for aa in a: if aa > 0: return False return True def days(x): c = 0 for aa, bb in zip(a, b): c += 1 + aa*x//bb return c def ru...
21
186
307,200
75786512
# ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code def main(): n , c = map(int , input().split()) data = [] for i in range(n): a,b = map(int...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
The first input line contains space-separated integers n and c — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly. The next n lines contain pairs of space-separated integers ai, bi (1 ≤ i ≤ n) — the number of suitcases he can bring to the i-...
Print a single number k — the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
null
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days...
[{"input": "2 5\n1 5\n2 4", "output": "1"}]
1,700
["binary search"]
21
[{"input": "2 5\r\n1 5\r\n2 4\r\n", "output": "1\r\n"}, {"input": "1 97\r\n1 91\r\n", "output": "91\r\n"}, {"input": "2 79\r\n1 91\r\n1 77\r\n", "output": "42\r\n"}, {"input": "3 100\r\n8 46\r\n8 56\r\n77 98\r\n", "output": "1\r\n"}, {"input": "7 77\r\n2 95\r\n2 91\r\n3 95\r\n2 94\r\n3 96\r\n2 97\r\n2 91\r\n", "output"...
false
stdio
null
true
897/A
897
A
Python 3
TESTS
2
31
0
149138219
n = input() n = int(n[-1]) s = input() for i in range(n): s1 = input() l, r, c1, c2 = s1.split() s = list(map(str, s)) for j in range(int(l)-1, int(r)): if s[j] == c1: s[j] = c2 s = "".join(s) print(s)
47
46
0
146189110
n,k=map(int,input().split()) s = input() for i in range(k): l,r,c1,c2 = map(str,input().split()) l=int(l) r=int(r) s = s[:l-1]+s[l-1:r].replace(c1,c2)+s[r:] print(s)
Codeforces Round 449 (Div. 2)
CF
2,017
2
256
Scarborough Fair
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. W...
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
Output string s after performing m operations described above.
null
For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
[{"input": "3 1\nioi\n1 1 i n", "output": "noi"}, {"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "output": "gaaak"}]
800
["implementation"]
47
[{"input": "3 1\r\nioi\r\n1 1 i n\r\n", "output": "noi"}, {"input": "5 3\r\nwxhak\r\n3 3 h x\r\n1 5 x a\r\n1 3 w g\r\n", "output": "gaaak"}, {"input": "9 51\r\nbhfbdcgff\r\n2 3 b b\r\n2 8 e f\r\n3 8 g f\r\n5 7 d a\r\n1 5 e b\r\n3 4 g b\r\n6 7 c d\r\n3 6 e g\r\n3 6 e h\r\n5 6 a e\r\n7 9 a c\r\n4 9 a h\r\n3 7 c b\r\n6 9 ...
false
stdio
null
true
177/C1
177
C1
PyPy 3
TESTS1
3
248
0
100766874
from sys import stdin, stdout def find(node): x = [] while dsu[node] > 0: x.append(node) node = dsu[node] for i in x: dsu[i] = node return node def union(node1, node2): if node1 != node2: if dsu[node1] > dsu[node2]: node1, node2 = node2, node1 ds...
17
92
307,200
14715535
n = int(input()) num_likes = int(input()) like = [ [] for u in range(n + 1) ] for i in range(num_likes): u, v = map(int, input().split()) like[u].append(v) like[v].append(u) num_dislikes = int(input()) dislike = [ (n + 1) * [ False ] for u in range(n + 1) ] for i in range(num_dislikes): u, v = map(int, ...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Party
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends...
The first line of input contains an integer n — the number of the Beaver's acquaintances. The second line contains an integer k $$( 0 \leq k \leq \min ( 1 0 ^ { 5 }, \frac { n \cdot ( n - 1 ) } { 2 } ) )$$ — the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi $$( 1 \leq u _ { ...
Output a single number — the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0.
null
Let's have a look at the example. Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members a...
[{"input": "9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9", "output": "3"}]
1,500
["dfs and similar", "dsu", "graphs"]
17
[{"input": "9\r\n8\r\n1 2\r\n1 3\r\n2 3\r\n4 5\r\n6 7\r\n7 8\r\n8 9\r\n9 6\r\n2\r\n1 6\r\n7 9\r\n", "output": "3"}, {"input": "2\r\n1\r\n1 2\r\n0\r\n", "output": "2"}, {"input": "2\r\n0\r\n1\r\n1 2\r\n", "output": "1"}, {"input": "3\r\n2\r\n1 2\r\n1 3\r\n1\r\n2 3\r\n", "output": "0"}, {"input": "3\r\n3\r\n1 3\r\n2 1\r\...
false
stdio
null
true
404/C
404
C
Python 3
TESTS
1
109
204,800
97936190
import heapq n, k = map(int, input().split()) d = list(map(int, input().split())) heap = [] for i in range(0, n): heapq.heappush(heap, d[i]) if heap[0] != 0: print(-1) else: v = 1 edge = 0 graph = [] for i in range(1, n): if heap[i] == 0: print(-1) break ...
43
686
78,028,800
88821341
from sys import stdin from heapq import heappush, heappop from collections import deque def r(): return stdin.readline().strip() def r_t(tp): return map(tp, r().strip().split()) def r_l(tp): return list(r_t(tp)) def solve(n,k,d): s, E, deg = -1, [], [0 for _ in range(n)] for i in range(n): if d[i]==0 ...
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Restore Graph
Valera had an undirected connected graph without self-loops and multiple edges consisting of n vertices. The graph had an interesting property: there were at most k edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to n. One day Valera count...
The first line contains two space-separated integers n and k (1 ≤ k < n ≤ 105). Number n shows the number of vertices in the original graph. Number k shows that at most k edges were adjacent to each vertex in the original graph. The second line contains space-separated integers d[1], d[2], ..., d[n] (0 ≤ d[i] < n). Nu...
If Valera made a mistake in his notes and the required graph doesn't exist, print in the first line number -1. Otherwise, in the first line print integer m (0 ≤ m ≤ 106) — the number of edges in the found graph. In each of the next m lines print two space-separated integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi), denotin...
null
null
[{"input": "3 2\n0 1 1", "output": "3\n1 2\n1 3\n3 2"}, {"input": "4 2\n2 0 1 3", "output": "3\n1 3\n1 4\n2 3"}, {"input": "3 1\n0 0 0", "output": "-1"}]
1,800
["dfs and similar", "graphs", "sortings"]
43
[{"input": "3 2\r\n0 1 1\r\n", "output": "2\r\n1 2\r\n1 3\r\n"}, {"input": "4 2\r\n2 0 1 3\r\n", "output": "3\r\n1 3\r\n1 4\r\n2 3\r\n"}, {"input": "3 1\r\n0 0 0\r\n", "output": "-1\r\n"}, {"input": "5 3\r\n0 2 1 2 1\r\n", "output": "4\r\n1 3\r\n1 5\r\n2 5\r\n4 5\r\n"}, {"input": "7 3\r\n2 2 0 1 3 2 1\r\n", "output": "...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] with open(input_path) as f: n, k = map(int, f.readline().split()) d = list(map(int, f.readline().split())) with open(ref_output_path) as f: ...
true
401/B
401
B
PyPy 3
TESTS
2
109
2,662,400
113921484
def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def MAP2():return map(float,input().split()) def LIST(): return list(map(int, input().split())) def STRING(): return input() import string import sys from heapq import heappop , heappush from bisect import * from ...
47
62
5,324,800
18101443
n,k = map(int,input().split()) set1 = set(range(1,n)) for i in range(k): mylist = list(map(int,input().split()[1:])) set1 -= set(mylist) set2 = set(set1) for i in range(1,n): if i in set2: set2-=set([i+1]) print(len(set2),len(set1))
Codeforces Round 235 (Div. 2)
CF
2,014
1
256
Sereja and Contests
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds. Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot...
The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding l...
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
null
In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. ...
[{"input": "3 2\n2 1\n2 2", "output": "0 0"}, {"input": "9 3\n1 2 3\n2 8\n1 4 5", "output": "2 3"}, {"input": "10 0", "output": "5 9"}]
1,200
["greedy", "implementation", "math"]
47
[{"input": "3 2\r\n2 1\r\n2 2\r\n", "output": "0 0"}, {"input": "9 3\r\n1 2 3\r\n2 8\r\n1 4 5\r\n", "output": "2 3"}, {"input": "10 0\r\n", "output": "5 9"}, {"input": "10 2\r\n1 1 2\r\n1 8 9\r\n", "output": "3 5"}, {"input": "9 3\r\n1 4 5\r\n1 1 2\r\n1 6 7\r\n", "output": "2 2"}, {"input": "7 2\r\n2 3\r\n1 5 6\r\n", "...
false
stdio
null
true
12/D
12
D
Python 3
TESTS
12
62
5,529,600
33648131
n=int(input()) List=[] for i in range(n): List.append([]) for j in range(3): data = [int(i) for i in input().split(' ')] for i in range(n): List[i].append(data[i]) self_kill=[False]*n def compare(elem1,elem2): if elem1[0]>elem2[0] and elem1[1]>elem2[1] and elem1[2]>elem2[2]: return 1 ...
50
1,933
176,332,800
145770720
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline N=int(input()) X=list(map(int,input().split())) Y=list(map(int,input().split())) Z=list(map(int,input().split())) XX=sorted(set(X)) YY=sorted(set(Y)) ZZ=sorted(set(Z)) DX={XX[i]:i for i in range(len(XX))} DY={YY[i]:i for i in range...
Codeforces Beta Round 12 (Div 2 Only)
ICPC
2,010
2
256
Ball
N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can ju...
The first line contains one integer N (1 ≤ N ≤ 500000). The second line contains N integer numbers Bi, separated by single spaces. The third and the fourth lines contain sequences Ii and Ri in the same format. It is guaranteed that 0 ≤ Bi, Ii, Ri ≤ 109.
Output the answer to the problem.
null
null
[{"input": "3\n1 4 2\n4 3 2\n2 5 3", "output": "1"}]
2,400
["data structures", "sortings"]
50
[{"input": "3\r\n1 4 2\r\n4 3 2\r\n2 5 3\r\n", "output": "1\r\n"}, {"input": "5\r\n2 8 10 0 7\r\n7 7 3 0 10\r\n2 8 3 2 2\r\n", "output": "1\r\n"}, {"input": "5\r\n3 0 0 2 0\r\n7 10 7 4 0\r\n9 1 6 1 9\r\n", "output": "1\r\n"}, {"input": "5\r\n5 4 0 2 5\r\n8 3 1 0 10\r\n4 5 0 0 5\r\n", "output": "2\r\n"}, {"input": "5\r\...
false
stdio
null
true
1004/B
1004
B
Python 3
PRETESTS
6
218
0
39996072
n,k=map(int,input().split()) arr=[] for i in range(k): x,y=map(int,input().split()) arr.append([x,y]) arr1=[0]*n for i in range(k): for j in range(arr[i][0]-1,arr[i][1]): if(j==0): arr1[j]=0 else: if(arr1[j-1]==1): arr1[j]=0 else: ...
27
31
0
206666521
def main(): n, m = map(int, input().strip().split()) for _ in range(m): a, b = map(int, input().strip().split()) output = [i % 2 for i in range(n)] print(''.join(map(str, output))) if __name__ == '__main__': main()
Codeforces Round 495 (Div. 2)
CF
2,018
1
256
Sonya and Exhibition
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $$$n$$$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $$$i$$$-th position. Thus each of $$$n$$$ pos...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\leq n, m\leq 10^3$$$) — the number of flowers and visitors respectively. Each of the next $$$m$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1\leq l_i\leq r_i\leq n$$$), meaning that $$$i$$$-th visitor will visit all flowers from $$$l_i$$$ to ...
Print the string of $$$n$$$ characters. The $$$i$$$-th symbol should be «0» if you want to put a rose in the $$$i$$$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any.
null
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; - in the segment $$$[1\ldots3]$$$, there are one rose and two lilies, so the beauty is equal to $$$1\cdot 2=2$$$; - in the segment $$$[2\ldots4]$$$, there are one rose and two lilies, so t...
[{"input": "5 3\n1 3\n2 4\n2 5", "output": "01100"}, {"input": "6 3\n5 6\n1 4\n4 6", "output": "110010"}]
1,300
["constructive algorithms", "greedy", "implementation", "math"]
27
[{"input": "5 3\r\n1 3\r\n2 4\r\n2 5\r\n", "output": "01010\r\n"}, {"input": "6 3\r\n5 6\r\n1 4\r\n4 6\r\n", "output": "010101\r\n"}, {"input": "10 4\r\n3 3\r\n1 6\r\n9 9\r\n10 10\r\n", "output": "0101010101\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "1000 10\r\n3 998\r\n2 1000\r\n1 999\r\n2 1000\...
false
stdio
import sys def read_ints(f): return list(map(int, f.readline().split())) def compute_sum(arrangement, segments): total = 0 for l, r in segments: zeros = arrangement[l-1:r].count('0') ones = (r - l + 1) - zeros total += zeros * ones return total def main(input_path, output_path...
true
1004/B
1004
B
Python 3
TESTS
5
93
0
40071738
# your code goes here n, k = [int(i) for i in input().split()] maxs, maxt, maxint = 0, 0, 0 for i in range(k): s, t = [int(i) for i in input().split()] while n > 0: if (n > 0) : print("10", end="") n -=2 if n == 1: print("1", end="") n -= 1
27
46
0
148370012
arr=list(map(int, input().rstrip().split())) n=arr[0] m=arr[1] arr=[] for i in range(m): brr=[] crr=list(map(int, input().rstrip().split())) b=crr[1] a=crr[0] brr.append(b-a) brr.extend(crr) arr.append(brr) s="" for i in range(n): if(i%2==0): s+='1' else: s+='0' print(s)
Codeforces Round 495 (Div. 2)
CF
2,018
1
256
Sonya and Exhibition
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $$$n$$$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $$$i$$$-th position. Thus each of $$$n$$$ pos...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\leq n, m\leq 10^3$$$) — the number of flowers and visitors respectively. Each of the next $$$m$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1\leq l_i\leq r_i\leq n$$$), meaning that $$$i$$$-th visitor will visit all flowers from $$$l_i$$$ to ...
Print the string of $$$n$$$ characters. The $$$i$$$-th symbol should be «0» if you want to put a rose in the $$$i$$$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any.
null
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; - in the segment $$$[1\ldots3]$$$, there are one rose and two lilies, so the beauty is equal to $$$1\cdot 2=2$$$; - in the segment $$$[2\ldots4]$$$, there are one rose and two lilies, so t...
[{"input": "5 3\n1 3\n2 4\n2 5", "output": "01100"}, {"input": "6 3\n5 6\n1 4\n4 6", "output": "110010"}]
1,300
["constructive algorithms", "greedy", "implementation", "math"]
27
[{"input": "5 3\r\n1 3\r\n2 4\r\n2 5\r\n", "output": "01010\r\n"}, {"input": "6 3\r\n5 6\r\n1 4\r\n4 6\r\n", "output": "010101\r\n"}, {"input": "10 4\r\n3 3\r\n1 6\r\n9 9\r\n10 10\r\n", "output": "0101010101\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "1000 10\r\n3 998\r\n2 1000\r\n1 999\r\n2 1000\...
false
stdio
import sys def read_ints(f): return list(map(int, f.readline().split())) def compute_sum(arrangement, segments): total = 0 for l, r in segments: zeros = arrangement[l-1:r].count('0') ones = (r - l + 1) - zeros total += zeros * ones return total def main(input_path, output_path...
true
177/C1
177
C1
PyPy 3
TESTS1
3
154
0
119311586
class DSNode: def __init__(self, val): self.val = val self.rank = 0 self.size = 1 self.parent = self self.correct = True def __str__(self): return str(self.find().val) def find(self): x = self if x != x.parent: x.parent = x.parent...
17
124
102,400
172424690
n=int(input()) m=int(input()) from collections import Counter parent=[i for i in range(n+1)] def find(x): temp=[] while parent[x]!=x: temp.append(x) x=parent[x] while temp: parent[temp.pop()]=x return x def union(x,y): parent[find(x)]=find(y) for _ in range(m): a,b=map(in...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Party
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends...
The first line of input contains an integer n — the number of the Beaver's acquaintances. The second line contains an integer k $$( 0 \leq k \leq \min ( 1 0 ^ { 5 }, \frac { n \cdot ( n - 1 ) } { 2 } ) )$$ — the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi $$( 1 \leq u _ { ...
Output a single number — the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0.
null
Let's have a look at the example. Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members a...
[{"input": "9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9", "output": "3"}]
1,500
["dfs and similar", "dsu", "graphs"]
17
[{"input": "9\r\n8\r\n1 2\r\n1 3\r\n2 3\r\n4 5\r\n6 7\r\n7 8\r\n8 9\r\n9 6\r\n2\r\n1 6\r\n7 9\r\n", "output": "3"}, {"input": "2\r\n1\r\n1 2\r\n0\r\n", "output": "2"}, {"input": "2\r\n0\r\n1\r\n1 2\r\n", "output": "1"}, {"input": "3\r\n2\r\n1 2\r\n1 3\r\n1\r\n2 3\r\n", "output": "0"}, {"input": "3\r\n3\r\n1 3\r\n2 1\r\...
false
stdio
null
true
177/E1
177
E2
PyPy 3
TESTS2
3
154
1,638,400
176488643
inf = 1e17 import math def p(mid,b,a): sm = 0 n = len(a) for i in range(n): sm += math.floor((mid*a[i])/b[i]) return sm+n def binarysearch(a,b,c): l = 0 r = inf while(r-l > 1): mid = math.floor((l+r)/2) if(p(mid,b,a)>=c): r=mid else: l...
21
218
0
51613361
a=[] b=[] n=0 def cal(x): p=0 global n,a,b for i in range(n): p+=((a[i]*x)//b[i]) return p n,c=map(int,input().split()) c-=n if c < 0: print(0) exit(0) a=[0]*n b=[0]*n for i in range(n): a[i],b[i]=map(int,input().split()) L=1 R=10**18 lower=R+1 while L<=R : m=(L+R)>>1 if cal(m) >= c: lower=m R=m-1 else...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
The first input line contains space-separated integers n and c — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly. The next n lines contain pairs of space-separated integers ai, bi (1 ≤ i ≤ n) — the number of suitcases he can bring to the i-...
Print a single number k — the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
null
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days...
[{"input": "2 5\n1 5\n2 4", "output": "1"}]
1,700
["binary search"]
21
[{"input": "2 5\r\n1 5\r\n2 4\r\n", "output": "1\r\n"}, {"input": "1 97\r\n1 91\r\n", "output": "91\r\n"}, {"input": "2 79\r\n1 91\r\n1 77\r\n", "output": "42\r\n"}, {"input": "3 100\r\n8 46\r\n8 56\r\n77 98\r\n", "output": "1\r\n"}, {"input": "7 77\r\n2 95\r\n2 91\r\n3 95\r\n2 94\r\n3 96\r\n2 97\r\n2 91\r\n", "output"...
false
stdio
null
true
177/E1
177
E1
Python 3
TESTS1
3
92
307,200
4855735
n, c = map(int, input().split()) c -= n t = [tuple(map(int, input().split())) for i in range(n)] x = int(c / sum(a / b for a, b in t)) while sum((x * a) // b for a, b in t) < c: x += 1 y = x while sum((x * a) // b for a, b in t) == c: x += 1 print(x - y)
46
312
819,200
4856163
def f(x, t): y = x while sum((y * a) // b for a, b in t) < c: y += 1000000 while y - x > 1: z = (x + y) // 2 d = sum((z * a) // b for a, b in t) if d < c: x = z else: y = z return y n, c = map(int, input().split()) c -= n t = [tuple(map(int, input().split())) for i i...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
The first input line contains space-separated integers n and c — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly. The next n lines contain pairs of space-separated integers ai, bi (1 ≤ i ≤ n) — the number of suitcases he can bring to the i-...
Print a single number k — the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
null
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days...
[{"input": "2 5\n1 5\n2 4", "output": "1"}]
1,700
["binary search"]
21
[{"input": "2 5\r\n1 5\r\n2 4\r\n", "output": "1\r\n"}, {"input": "1 97\r\n1 91\r\n", "output": "91\r\n"}, {"input": "2 79\r\n1 91\r\n1 77\r\n", "output": "42\r\n"}, {"input": "3 100\r\n8 46\r\n8 56\r\n77 98\r\n", "output": "1\r\n"}, {"input": "7 77\r\n2 95\r\n2 91\r\n3 95\r\n2 94\r\n3 96\r\n2 97\r\n2 91\r\n", "output"...
false
stdio
null
true
467/B
467
B
Python 3
TESTS
5
31
0
224815164
n, m, k = map(int, input().split()) arr = [] for i in range(m): arr.append(int(input())) player = int(input()) count = 0 r = 2 a = 1 sum = int(a * (1 - r**k) / (1 - r)) for i in arr: temp = player ^ i if temp <= sum: count += 1 print(count)
43
46
0
212034914
import math import bisect n,m,k=map(int,input().split()) a=[] for i in range(m): a.append(int(input())) p=int(input()) count=0 for i in a: c=i^p sol=0 # print(i,p) while c: # print(c) if c&1: sol+=1 c=c>>1 # print(c,67) if sol<=k: count+=1 pri...
Codeforces Round 267 (Div. 2)
CF
2,014
1
256
Fedor and New Game
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3». The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each ...
The first line contains three integers n, m, k (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000). The i-th of the next (m + 1) lines contains a single integer xi (1 ≤ xi ≤ 2n - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.
Print a single integer — the number of Fedor's potential friends.
null
null
[{"input": "7 3 1\n8\n5\n111\n17", "output": "0"}, {"input": "3 3 3\n1\n2\n3\n4", "output": "3"}]
1,100
["bitmasks", "brute force", "constructive algorithms", "implementation"]
43
[{"input": "7 3 1\r\n8\r\n5\r\n111\r\n17\r\n", "output": "0\r\n"}, {"input": "3 3 3\r\n1\r\n2\r\n3\r\n4\r\n", "output": "3\r\n"}, {"input": "4 2 2\r\n5\r\n6\r\n7\r\n", "output": "2\r\n"}, {"input": "4 7 4\r\n9\r\n10\r\n5\r\n12\r\n4\r\n12\r\n7\r\n10\r\n", "output": "7\r\n"}, {"input": "2 7 2\r\n1\r\n1\r\n1\r\n1\r\n1\r\n...
false
stdio
null
true
599/B
599
B
PyPy 3
TESTS
19
171
15,564,800
202249706
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, m = map(int, input().split()) f = list(map(int, input().split())) b = list(map(int, input().split())) cnt = [0] * (n + 1) for i in f: cnt[i] += 1 x = [0] * (n + 1) for i in range(n): x[f[i]] = i + 1 a = [] ans = "Possible" for i...
61
265
20,172,800
14370837
__author__ = 'MoonBall' import sys # sys.stdin = open('data/B.in', 'r') T = 1 def process(): N, M = list(map(int, input().split())) f = map(int, input().split()) b = map(int, input().split()) fc = {} for idx, fv in enumerate(f): fc[fv] = (1, idx) if not fc.get(fv) else (fc[fv][0] + 1, idx) a...
Codeforces Round 332 (Div. 2)
CF
2,015
2
256
Spongebob and Joke
While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n an...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the lengths of sequences fi and bi respectively. The second line contains n integers, determining sequence f1, f2, ..., fn (1 ≤ fi ≤ n). The last line contains m integers, determining sequence b1, b2, ..., bm (1 ≤ bi ≤ n).
Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am. If there are multiple suitable sequences ai, print "Ambiguity". If Spongebob has made a mistake in his calculations and no suitable sequence ai exists, print "Impossible".
null
In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique. In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence. In the third sample fi ≠ 3 for all i, so no sequence ai transforms into such bi and we ...
[{"input": "3 3\n3 2 1\n1 2 3", "output": "Possible\n3 2 1"}, {"input": "3 3\n1 1 1\n1 1 1", "output": "Ambiguity"}, {"input": "3 3\n1 2 1\n3 3 3", "output": "Impossible"}]
1,500
["implementation"]
61
[{"input": "3 3\r\n3 2 1\r\n1 2 3\r\n", "output": "Possible\r\n3 2 1 \r\n"}, {"input": "3 3\r\n1 1 1\r\n1 1 1\r\n", "output": "Ambiguity\r\n"}, {"input": "3 3\r\n1 2 1\r\n3 3 3\r\n", "output": "Impossible\r\n"}, {"input": "2 100\r\n2 1\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
false
stdio
null
true
762/D
762
D
PyPy 3-64
TESTS
3
31
0
180737899
n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) inf=10**18 dp0=[-inf]*(n+1) dp1=[-inf]*(n+1) dp2=[-inf]*(n+1) dp0[0]=0 mx0=-inf mx2=-inf for i in range(n): mx0=max(mx0,dp0[i]) mx2=max(mx2,dp2[i]) mx0+=a[i]+b[i]+c[i] mx2+=a[i]+b[i]+c[i] dp0[i+...
38
452
24,678,400
124778305
import sys input = sys.stdin.readline def solve(): '''M = ( (a, d, f, f), (d, b, e, -1), (f, e, c, f), (f, -1, f, f)) ''' INF = int(9e18-1e9) n = int(input()) A = [[None]*3 for i in range(n)] for i in range(3): j = 0 for v in map(int, input().split()): A[j][i] = v j += 1 x = 0 y = -INF z = -INF...
Educational Codeforces Round 17
ICPC
2,017
1
256
Maximum path
You are given a rectangular table 3 × n. Each cell contains an integer. You can move from one cell to another if they share a side. Find such path from the upper left cell to the bottom right cell of the table that doesn't visit any of the cells twice, and the sum of numbers written in the cells of this path is maximu...
The first line contains an integer n (1 ≤ n ≤ 105)  — the number of columns in the table. Next three lines contain n integers each  — the description of the table. The j-th number in the i-th line corresponds to the cell aij ( - 109 ≤ aij ≤ 109) of the table.
Output the maximum sum of numbers on a path from the upper left cell to the bottom right cell of the table, that doesn't visit any of the cells twice.
null
The path for the first example: The path for the second example:
[{"input": "3\n1 1 1\n1 -1 1\n1 1 1", "output": "7"}, {"input": "5\n10 10 10 -1 -1\n-1 10 10 10 10\n-1 10 10 10 10", "output": "110"}]
2,300
["dp", "greedy", "implementation"]
38
[{"input": "3\r\n1 1 1\r\n1 -1 1\r\n1 1 1\r\n", "output": "7\r\n"}, {"input": "5\r\n10 10 10 -1 -1\r\n-1 10 10 10 10\r\n-1 10 10 10 10\r\n", "output": "110\r\n"}, {"input": "15\r\n-87 -91 31 63 91 35 -14 51 20 20 -20 -94 -59 77 76\r\n11 81 22 -29 91 -26 -10 -12 46 10 100 88 14 64 41\r\n26 -31 99 -39 -30 30 28 74 -7 21 ...
false
stdio
null
true
719/B
719
B
Python 3
TESTS
4
46
0
22427349
n = int(input()) stroy = input() order = stroy[0] wrong_r = 0 wrong_b = 0 rightness = {'b':1 if order == 'r' else 0, 'r':0 if order == 'r' else 1} for i in range(n): if rightness[stroy[i]] != i%2: if stroy[i] == 'r': wrong_r +=1 else: wrong_b += 1 print(max(wrong_b,wrong_r))
46
62
2,048,000
185769494
class solve: def __init__(self): n=int(input()) s=input() if n==1: print("0") else: r1,b1,r2,b2=0,0,0,0 for i in range(n): if i%2==0: if s[i]!="r": r1+=1 if s[i]!="b": ...
Codeforces Round 373 (Div. 2)
CF
2,016
1
256
Anatoly and Cockroaches
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room. Anatoly just made all his cockroaches to form a single line. As he is a perfectioni...
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches. The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
null
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this. In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns. In the third sample, the colors of cockroaches in the line are alternating already, thus the answer ...
[{"input": "5\nrbbrr", "output": "1"}, {"input": "5\nbbbbb", "output": "2"}, {"input": "3\nrbr", "output": "0"}]
1,400
["greedy"]
46
[{"input": "5\r\nrbbrr\r\n", "output": "1\r\n"}, {"input": "5\r\nbbbbb\r\n", "output": "2\r\n"}, {"input": "3\r\nrbr\r\n", "output": "0\r\n"}, {"input": "13\r\nrbbbrbrrbrrbb\r\n", "output": "3\r\n"}, {"input": "18\r\nrrrrrrrrrrrrrrrrrb\r\n", "output": "8\r\n"}, {"input": "100\r\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbr...
false
stdio
null
true
4/D
4
D
PyPy 3
TESTS
3
124
1,740,800
220093936
import sys from bisect import bisect_left,bisect_right from collections import defaultdict as dd from collections import deque, Counter from heapq import heappop,heappush,heapify,merge from itertools import permutations, accumulate, product from math import gcd,sqrt,ceil toBin=lambda x:bin(x).replace("0b","") I=lambda:...
33
421
9,216,000
219743982
n,r,c=map(int,input().split()) l=[[r,c,0]] n+=1 for i in range(1,n): a,b=map(int,input().split()) l.append([a,b,i]) l=sorted(l,key=lambda x:x[1]) v=[0]*n p=[-1]*n for i in range(n-1,-1,-1): v[l[i][2]]=1 for j in range(i+1,n): if l[j][0]>l[i][0] and l[j][1]>l[i][1] and v[l[j][2]]>=v[l[i][2]]: ...
Codeforces Beta Round 4 (Div. 2 Only)
ICPC
2,010
1
64
Mysterious Present
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the heigh...
The first line contains integers n, w, h (1 ≤ n ≤ 5000, 1 ≤ w, h ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi — width and height of the i-th envelope (1 ≤ wi, hi ≤ 106).
In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, pr...
null
null
[{"input": "2 1 1\n2 2\n2 2", "output": "1\n1"}, {"input": "3 3 3\n5 4\n12 11\n9 8", "output": "3\n1 3 2"}]
1,700
["dp", "sortings"]
33
[{"input": "2 1 1\r\n2 2\r\n2 2\r\n", "output": "1\r\n1 \r\n"}, {"input": "3 3 3\r\n5 4\r\n12 11\r\n9 8\r\n", "output": "3\r\n1 3 2 \r\n"}, {"input": "5 10 10\r\n22 23\r\n17 19\r\n13 17\r\n8 12\r\n2 6\r\n", "output": "3\r\n3 2 1 \r\n"}, {"input": "5 13 13\r\n4 4\r\n10 10\r\n7 7\r\n1 1\r\n13 13\r\n", "output": "0\r\n"},...
false
stdio
import sys def read_file_lines(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] input_lines = read_file_lines(input_path) if not input_lines: print(0) ...
true
875/C
875
C
PyPy 3-64
TESTS
0
31
512,000
158406080
# Expected to get WA # Taken from graphs/scc.py def find_SCC(graph): SCC, S, P = [], [], [] depth = [0] * len(graph) stack = list(range(len(graph))) while stack: node = stack.pop() if node < 0: d = depth[~node] - 1 if P[-1] > d: SCC.append(S[d:]...
67
545
35,840,000
31401070
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**15 mod = 10**9+7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF()...
Codeforces Round 441 (Div. 1, by Moscow Team Olympiad)
CF
2,017
1
512
National Property
You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library. Some long and uninteresting story was removed... The alphabet of Bookland is so large that its letters are denoted by positive integers. Each letter can be small or large, the large ve...
The first line contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — the number of words and the number of letters in Bookland's alphabet, respectively. The letters of Bookland's alphabet are denoted by integers from 1 to m. Each of the next n lines contains a description of one word in format li, si, 1, ...
In the first line print "Yes" (without quotes), if it is possible to capitalize some set of letters in such a way that the sequence of words becomes lexicographically ordered. Otherwise, print "No" (without quotes). If the required is possible, in the second line print k — the number of letters Denis has to capitalize...
null
In the first example after Denis makes letters 2 and 3 large, the sequence looks like the following: - 2' - 1 - 1 3' 2' - 1 1 The condition 2' < 1 holds, so the first word is not lexicographically larger than the second word. The second word is the prefix of the third word, so the are in lexicographical order. As the...
[{"input": "4 3\n1 2\n1 1\n3 1 3 2\n2 1 1", "output": "Yes\n2\n2 3"}, {"input": "6 5\n2 1 2\n2 1 2\n3 1 2 3\n2 1 5\n2 4 4\n2 4 4", "output": "Yes\n0"}, {"input": "4 3\n4 3 2 2 1\n3 1 1 3\n3 2 3 3\n2 3 1", "output": "No"}]
2,100
["2-sat", "dfs and similar", "graphs", "implementation"]
67
[{"input": "4 3\r\n1 2\r\n1 1\r\n3 1 3 2\r\n2 1 1\r\n", "output": "Yes\r\n2\r\n2 3 "}, {"input": "6 5\r\n2 1 2\r\n2 1 2\r\n3 1 2 3\r\n2 1 5\r\n2 4 4\r\n2 4 4\r\n", "output": "Yes\r\n0\r\n"}, {"input": "4 3\r\n4 3 2 2 1\r\n3 1 1 3\r\n3 2 3 3\r\n2 3 1\r\n", "output": "No\r\n"}, {"input": "4 4\r\n3 3 4 1\r\n4 3 4 2 2\r\n4...
false
stdio
null
true
262/A
262
A
Python 3
TESTS
5
216
0
59818088
l1 = list(map(int, input().split())) l2 = list(map(int, input().split())) total = 0 co = 0 for i in l2: while i != 0: n = i % 10 i /= 10 if n == 4 or n == 7: co += 1 if co <= l1[1]: total += 1 print(total)
34
92
0
132043137
n,k = map(int,input().split()) l = input().split() ans = 0 for i in l: if not(i.count('4') + i.count('7') > k): ans+=1 print(ans)
Codeforces Round 160 (Div. 2)
CF
2,013
1
256
Roma and Lucky Numbers
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got n positive integers....
The first line contains two integers n, k (1 ≤ n, k ≤ 100). The second line contains n integers ai (1 ≤ ai ≤ 109) — the numbers that Roma has. The numbers in the lines are separated by single spaces.
In a single line print a single integer — the answer to the problem.
null
In the first sample all numbers contain at most four lucky digits, so the answer is 3. In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.
[{"input": "3 4\n1 2 4", "output": "3"}, {"input": "3 2\n447 44 77", "output": "2"}]
800
["implementation"]
34
[{"input": "3 4\r\n1 2 4\r\n", "output": "3\r\n"}, {"input": "3 2\r\n447 44 77\r\n", "output": "2\r\n"}, {"input": "2 2\r\n507978501 180480073\r\n", "output": "2\r\n"}, {"input": "9 6\r\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089\r\n", "output": "9\r\n"}, {"input": "6 100\r\n17042...
false
stdio
null
true
404/C
404
C
Python 3
TESTS
4
93
307,200
84106447
import sys input = sys.stdin.readline I = lambda : list(map(int,input().split())) n,k = I() d=I();ed=[] d=sorted([[d[i],i+1] for i in range(n)]) i=1;cur=[d[0][1]];l=0;f=1 while i<n: x=len(cur);m=x*k r=0;j=0;ll=[] while i<n and d[i][0]==l+1: ed.append([cur[j],d[i][1]]) ll.append(d[i][1]) if j>=x: r=m+1;brea...
43
779
30,822,400
119505377
import sys input=sys.stdin.readline n,k=map(int,input().split()) d=list(map(int,input().split())) r=[[d[i],i] for i in range(n)] r.sort() if r[0][0]!=0 or r[1][0]==0: print(-1) exit() v=[[] for i in range(n+1)] cnt=[0]*n v[0].append(r[0][1]) edges=[] for rank,ver in r[1:]: if len(v[rank-1])==0: prin...
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Restore Graph
Valera had an undirected connected graph without self-loops and multiple edges consisting of n vertices. The graph had an interesting property: there were at most k edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to n. One day Valera count...
The first line contains two space-separated integers n and k (1 ≤ k < n ≤ 105). Number n shows the number of vertices in the original graph. Number k shows that at most k edges were adjacent to each vertex in the original graph. The second line contains space-separated integers d[1], d[2], ..., d[n] (0 ≤ d[i] < n). Nu...
If Valera made a mistake in his notes and the required graph doesn't exist, print in the first line number -1. Otherwise, in the first line print integer m (0 ≤ m ≤ 106) — the number of edges in the found graph. In each of the next m lines print two space-separated integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi), denotin...
null
null
[{"input": "3 2\n0 1 1", "output": "3\n1 2\n1 3\n3 2"}, {"input": "4 2\n2 0 1 3", "output": "3\n1 3\n1 4\n2 3"}, {"input": "3 1\n0 0 0", "output": "-1"}]
1,800
["dfs and similar", "graphs", "sortings"]
43
[{"input": "3 2\r\n0 1 1\r\n", "output": "2\r\n1 2\r\n1 3\r\n"}, {"input": "4 2\r\n2 0 1 3\r\n", "output": "3\r\n1 3\r\n1 4\r\n2 3\r\n"}, {"input": "3 1\r\n0 0 0\r\n", "output": "-1\r\n"}, {"input": "5 3\r\n0 2 1 2 1\r\n", "output": "4\r\n1 3\r\n1 5\r\n2 5\r\n4 5\r\n"}, {"input": "7 3\r\n2 2 0 1 3 2 1\r\n", "output": "...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] with open(input_path) as f: n, k = map(int, f.readline().split()) d = list(map(int, f.readline().split())) with open(ref_output_path) as f: ...
true
400/D
400
D
PyPy 3
TESTS
40
1,184
9,216,000
91536323
#!/usr/bin/env python3 from sys import stdin from bisect import bisect_left, bisect_right INF = int(1e9) def solve(): n, m, k = map(int, stdin.readline().split()) cnts = list(map(int, stdin.readline().split())) chk = [True for i in range(k)] if cnts[0]==1: chk[0] = False for i in range(1,k...
61
1,903
9,830,400
91565033
#!/usr/bin/env python3 from sys import stdin from bisect import bisect_left, bisect_right INF = int(1e9) def find(par, a): if par[a] == a: return a par[a] = find(par, par[a]) return par[a] def union(par, rnk, a, b): a = find(par,a) b = find(par,b) if a==b: return ...
Codeforces Round 234 (Div. 2)
CF
2,014
2
256
Dima and Bacteria
Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals ci. For convenience, we will assume that all the bacteria are numbered from 1 to n. The bacteria of type ci are nu...
The first line contains three integers n, m, k (1 ≤ n ≤ 105; 0 ≤ m ≤ 105; 1 ≤ k ≤ 500). The next line contains k integers c1, c2, ..., ck (1 ≤ ci ≤ n). Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ 105; 0 ≤ xi ≤ 104). It is guaranteed that $$\sum_{i=1}^{k} c_i = n$$.
If Dima's type-distribution is correct, print string «Yes», and then k lines: in the i-th line print integers d[i][1], d[i][2], ..., d[i][k] (d[i][i] = 0). If there is no way to move energy from bacteria i to bacteria j appropriate d[i][j] must equal to -1. If the type-distribution isn't correct print «No».
null
null
[{"input": "4 4 2\n1 3\n2 3 0\n3 4 0\n2 4 1\n2 1 2", "output": "Yes\n0 2\n2 0"}, {"input": "3 1 2\n2 1\n1 2 0", "output": "Yes\n0 -1\n-1 0"}, {"input": "3 2 2\n2 1\n1 2 0\n2 3 1", "output": "Yes\n0 1\n1 0"}, {"input": "3 0 2\n1 2", "output": "No"}]
2,000
["dsu", "graphs", "shortest paths"]
61
[{"input": "4 4 2\r\n1 3\r\n2 3 0\r\n3 4 0\r\n2 4 1\r\n2 1 2\r\n", "output": "Yes\r\n0 2\r\n2 0\r\n"}, {"input": "3 1 2\r\n2 1\r\n1 2 0\r\n", "output": "Yes\r\n0 -1\r\n-1 0\r\n"}, {"input": "3 2 2\r\n2 1\r\n1 2 0\r\n2 3 1\r\n", "output": "Yes\r\n0 1\r\n1 0\r\n"}, {"input": "3 0 2\r\n1 2\r\n", "output": "No\r\n"}, {"inp...
false
stdio
null
true
400/C
400
C
Python 3
PRETESTS
2
46
0
5942321
n, m, x, y, z, p = [int(i) for i in input().split()] x = x % 4 y = y % 2 z = z % 4 for s in range(p): i, j = [(int(i) - 1) for i in input().split()] for d in range(x): i, j = j, n - i - 1 n, m = m, n for d in range(y): i, j = i, m - j - 1 for d in range(z): i, j = n - j -...
60
1,091
102,400
167844161
import collections import heapq import sys import math import itertools import bisect from io import BytesIO, IOBase import os ###################################################################################### #--------------------------------------Input-----------------------------------------# ###################...
Codeforces Round 234 (Div. 2)
CF
2,014
2
256
Inna and Huge Candy Matrix
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j)....
The first line of the input contains fix integers n, m, x, y, z, p (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105). Each of the following p lines contains two integers xk, yk (1 ≤ xk ≤ n; 1 ≤ yk ≤ m) — the initial coordinates of the k-th candy. Two candies can lie on the same cell.
For each of the p candies, print on a single line its space-separated new coordinates.
null
Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
[{"input": "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3", "output": "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1"}]
1,500
["implementation", "math"]
60
[{"input": "3 3 3 1 1 9\r\n1 1\r\n1 2\r\n1 3\r\n2 1\r\n2 2\r\n2 3\r\n3 1\r\n3 2\r\n3 3\r\n", "output": "1 3\r\n1 2\r\n1 1\r\n2 3\r\n2 2\r\n2 1\r\n3 3\r\n3 2\r\n3 1\r\n"}, {"input": "5 5 0 0 0 1\r\n1 4\r\n", "output": "1 4\r\n"}, {"input": "14 76 376219315 550904689 16684615 24\r\n11 21\r\n1 65\r\n5 25\r\n14 63\r\n11 30...
false
stdio
null
true
1006/B
1006
B
PyPy 3
TESTS
4
62
19,046,400
134021782
n,k=map(int,input().split()) f=-1 sp=0 s=0 v=list(map(int,input().split())) r=[] for i in range(n): if n%k==0: if sp<v[i]: sp=v[i] if (i+1)%(n//k)==0: s+=sp sp=0 r.append(n//k) else: f+=1 if sp<v[i]: sp=v[i] if (...
37
62
7,065,600
129461352
R=lambda:map(int,input().split()) n,k=R() a=sorted(zip(R(),range(n)))[-k:] print(sum(x[0]for x in a)) b=sorted(x[1]for x in a)+[n] b[0]=0 print(*(y-x for x,y in zip(b,b[1:])))#sgeheher
Codeforces Round 498 (Div. 3)
ICPC
2,018
2
256
Polycarp's Practice
Polycarp is practicing his problem solving skill. He has a list of $$$n$$$ problems with difficulties $$$a_1, a_2, \dots, a_n$$$, respectively. His plan is to practice for exactly $$$k$$$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his l...
The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2000$$$) — the number of problems and the number of days, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2000$$$) — difficulties of problems in Polycarp's list,...
In the first line of the output print the maximum possible total profit. In the second line print exactly $$$k$$$ positive integers $$$t_1, t_2, \dots, t_k$$$ ($$$t_1 + t_2 + \dots + t_k$$$ must equal $$$n$$$), where $$$t_j$$$ means the number of problems Polycarp will solve during the $$$j$$$-th day in order to achie...
null
The first example is described in the problem statement. In the second example there is only one possible distribution. In the third example the best answer is to distribute problems in the following way: $$$[1, 2000], [2000, 2]$$$. The total profit of this distribution is $$$2000 + 2000 = 4000$$$.
[{"input": "8 3\n5 4 2 6 5 1 9 2", "output": "20\n3 2 3"}, {"input": "5 1\n1 1 1 1 1", "output": "1\n5"}, {"input": "4 2\n1 2000 2000 2", "output": "4000\n2 2"}]
1,200
["greedy", "implementation", "sortings"]
37
[{"input": "8 3\r\n5 4 2 6 5 1 9 2\r\n", "output": "20\r\n4 1 3\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n", "output": "1\r\n5\r\n"}, {"input": "4 2\r\n1 2000 2000 2\r\n", "output": "4000\r\n2 2\r\n"}, {"input": "1 1\r\n2000\r\n", "output": "2000\r\n1\r\n"}, {"input": "1 1\r\n1234\r\n", "output": "1234\r\n1\r\n"}, {"input"...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input with open(input_path) as f: lines = f.read().splitlines() n, k = map(int, lines[0].split()) a = list(map(int, lines[1].split())) # Compute correct sum (sum of k largest elements) sorted_a = sorted(a, revers...
true
1009/A
1009
A
Python 3
TESTS
3
109
0
40617773
""" Your module description """ nm = input().split(' ') n = int(nm[0]) m = int(nm[1]) c = input().split(' ') a = input().split(' ') i = 0 j = 0 for x in a : if j < len(c) : for y in range(j,len(c)) : if int(x)>=int(c[y]) : j = y+1 i += 1 break ...
19
31
0
205289135
n, m = map(int, input().split()) c = list(map(int, input().split())) a = list(map(int, input().split())) i = j = ans = 0 while i < n and j < m: if a[j] >= c[i]: ans += 1 j += 1 i += 1 print(ans)
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
1
256
Game Shopping
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$. Games in the shop are ordered from left to ri...
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th ...
Print a single integer — the number of games Maxim will buy.
null
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti...
[{"input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3"}, {"input": "5 2\n20 40 50 20 40\n19 20", "output": "0"}, {"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4"}]
800
["implementation"]
19
[{"input": "5 4\r\n2 4 5 2 4\r\n5 3 4 6\r\n", "output": "3\r\n"}, {"input": "5 2\r\n20 40 50 20 40\r\n19 20\r\n", "output": "0\r\n"}, {"input": "6 4\r\n4 8 15 16 23 42\r\n1000 1000 1000 1000\r\n", "output": "4\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n5\r\n", "output": "1\r\n"}, {"input": "5 1\r\n10 1 1 1 1\r\n1000\r\n", "...
false
stdio
null
true
897/A
897
A
Python 3
TESTS
2
30
0
149143205
n = input() n = int(n[-1]) s = input() for i in range(n): s1 = input() l, r, c1, c2 = s1.split() for j in range(int(l)-1, int(r)): if s[j] == c1: s = s[:j]+c2+s[j+1:] print(s)
47
46
0
146444883
n,m = list(map(int,input().split())) s = list(input()) for _ in range(m): l,r,c1,c2=input().split() l=int(l) r=int(r) for i in range(l-1,r): if s[i]==c1: s[i]=c2 print("".join(s))
Codeforces Round 449 (Div. 2)
CF
2,017
2
256
Scarborough Fair
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. W...
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
Output string s after performing m operations described above.
null
For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
[{"input": "3 1\nioi\n1 1 i n", "output": "noi"}, {"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "output": "gaaak"}]
800
["implementation"]
47
[{"input": "3 1\r\nioi\r\n1 1 i n\r\n", "output": "noi"}, {"input": "5 3\r\nwxhak\r\n3 3 h x\r\n1 5 x a\r\n1 3 w g\r\n", "output": "gaaak"}, {"input": "9 51\r\nbhfbdcgff\r\n2 3 b b\r\n2 8 e f\r\n3 8 g f\r\n5 7 d a\r\n1 5 e b\r\n3 4 g b\r\n6 7 c d\r\n3 6 e g\r\n3 6 e h\r\n5 6 a e\r\n7 9 a c\r\n4 9 a h\r\n3 7 c b\r\n6 9 ...
false
stdio
null
true
877/D
877
D
PyPy 3
TESTS
30
530
51,404,800
112416812
# aadiupadhyay import os.path from math import gcd, floor, ceil from collections import * import sys mod = 1000000007 INF = float('inf') def st(): return list(sys.stdin.readline().strip()) def li(): return list(map(int, sys.stdin.readline().split())) def mp(): return map(int, sys.stdin.readline().split()) def inp(): re...
58
404
50,073,600
180484247
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return u * m + v def bfs(x1, y1, x2, y2): q1, q2 = [], [] q1.append((x1, y1)) dist = [inf] * l dist[f(x1, y1)] = 0 d = 0 while q1: for i, j in q1: for di, dj in v: ...
Codeforces Round 442 (Div. 2)
CF
2,017
2
256
Olya and Energy Drinks
Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks. Formally, her room can be represented as a field of n × m cells, each cell of which is empty or littered with cans. Olya drank a lot of energy drink, so now she can run k meters per second. Each second she chooses...
The first line contains three integers n, m and k (1 ≤ n, m, k ≤ 1000) — the sizes of the room and Olya's speed. Then n lines follow containing m characters each, the i-th of them contains on j-th position "#", if the cell (i, j) is littered with cans, and "." otherwise. The last line contains four integers x1, y1, x...
Print a single integer — the minimum time it will take Olya to get from (x1, y1) to (x2, y2). If it's impossible to get from (x1, y1) to (x2, y2), print -1.
null
In the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second. In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds. Olya does not recommend drinking ener...
[{"input": "3 4 4\n....\n###.\n....\n1 1 3 1", "output": "3"}, {"input": "3 4 1\n....\n###.\n....\n1 1 3 1", "output": "8"}, {"input": "2 2 1\n.#\n#.\n1 1 2 2", "output": "-1"}]
2,100
["data structures", "dfs and similar", "graphs", "shortest paths"]
58
[{"input": "3 4 4\r\n....\r\n###.\r\n....\r\n1 1 3 1\r\n", "output": "3"}, {"input": "3 4 1\r\n....\r\n###.\r\n....\r\n1 1 3 1\r\n", "output": "8"}, {"input": "2 2 1\r\n.#\r\n#.\r\n1 1 2 2\r\n", "output": "-1"}, {"input": "10 10 1\r\n##########\r\n#.........\r\n#.#######.\r\n#.#.....#.\r\n#.#.###.#.\r\n#.#.#.#.#.\r\n#....
false
stdio
null
true
467/B
467
B
Python 3
TESTS
5
31
0
216678634
n, t, k = [int(x) for x in input().split()] l = [] c = 0 for _ in range(t+1): e = int(input()) l.append(e) for i in range(t): if n - bin(l[-1] & l[i])[2:].count('1') <= k: c += 1 print(c)
43
46
0
212240990
def gd(a,f): s=0 while a!=0 or f!=0: x=a%2 y=f%2 a//=2 f//=2 if x!=y: s+=1 return s n,m,k=list(map(int, input().split())) l=list() for _ in range(m): l.append(int(input())) f=int(input()) s=0 for i in l: s+=1 if gd(i,f) <= k else 0 print(s)
Codeforces Round 267 (Div. 2)
CF
2,014
1
256
Fedor and New Game
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3». The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each ...
The first line contains three integers n, m, k (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000). The i-th of the next (m + 1) lines contains a single integer xi (1 ≤ xi ≤ 2n - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.
Print a single integer — the number of Fedor's potential friends.
null
null
[{"input": "7 3 1\n8\n5\n111\n17", "output": "0"}, {"input": "3 3 3\n1\n2\n3\n4", "output": "3"}]
1,100
["bitmasks", "brute force", "constructive algorithms", "implementation"]
43
[{"input": "7 3 1\r\n8\r\n5\r\n111\r\n17\r\n", "output": "0\r\n"}, {"input": "3 3 3\r\n1\r\n2\r\n3\r\n4\r\n", "output": "3\r\n"}, {"input": "4 2 2\r\n5\r\n6\r\n7\r\n", "output": "2\r\n"}, {"input": "4 7 4\r\n9\r\n10\r\n5\r\n12\r\n4\r\n12\r\n7\r\n10\r\n", "output": "7\r\n"}, {"input": "2 7 2\r\n1\r\n1\r\n1\r\n1\r\n1\r\n...
false
stdio
null
true
545/C
545
C
PyPy 3
TESTS
10
950
18,432,000
203005711
from collections import deque n = int(input()) # Insert all possible valid segments # Sort by end # Add the segments pts = [list(map(int, input().split())) for _ in range(n)] segs = deque() for i, pt in enumerate(pts): if i == 0 or (pt[0] - pt[1]) > pts[i-1][0]: segs.append([pt[0] - pt[1], pt[0]]) e...
67
171
9,728,000
207065736
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) x, h = [], [] for _ in range(n): x0, h0 = map(int, input().split()) x.append(x0) h.append(h0) dp = [1, 0, 1] for i in range(1, n): u = [x[i - 1], x[i - 1], x[i - 1] + h[i - 1]] v = [x[i] - h[i], x[i], x...
Codeforces Round 303 (Div. 2)
CF
2,015
1
256
Woodcutters
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ...
The first line contains integer n (1 ≤ n ≤ 105) — the number of trees. Next n lines contain pairs of integers xi, hi (1 ≤ xi, hi ≤ 109) — the coordinate and the height of the і-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate.
Print a single number — the maximum number of trees that you can cut down by the given rules.
null
In the first sample you can fell the trees like that: - fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it...
[{"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1", "output": "3"}, {"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1", "output": "4"}]
1,500
["dp", "greedy"]
67
[{"input": "5\r\n1 2\r\n2 1\r\n5 10\r\n10 9\r\n19 1\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2\r\n2 1\r\n5 10\r\n10 9\r\n20 1\r\n", "output": "4\r\n"}, {"input": "4\r\n10 4\r\n15 1\r\n19 3\r\n20 1\r\n", "output": "4\r\n"}, {"input": "35\r\n1 7\r\n3 11\r\n6 12\r\n7 6\r\n8 5\r\n9 11\r\n15 3\r\n16 10\r\n22 2\r\n23 3\r\...
false
stdio
null
true
877/D
877
D
PyPy 3
TESTS
49
624
59,187,200
91256583
from sys import stdin input=lambda : stdin.readline().strip() from math import ceil,sqrt,factorial,gcd from collections import deque n,m,k=map(int,input().split()) dp=[[float("infinity") for i in range(m)] for i in range(n)] l=[] for i in range(n): l.append(list(input())) x1,y1,x2,y2=map(lambda a:int(a)-1,input().spli...
58
654
66,969,600
120693264
#python n,m,k=map(int,input().split()) grid=[list(input())for _ in range(n)] dist=[[10**9]*m for _ in range(n)] x1,y1,x2,y2=map(int,input().split()) x1,y1,x2,y2=x1-1,y1-1,x2-1,y2-1 dr=[[-1,0],[1,0],[0,-1],[0,1]] cur=0 q=[] q.append((x1,y1)) dist[x1][y1]=0 while cur<len(q): cx,cy=q[cur] if (cx,cy)==(x2,y2):break f...
Codeforces Round 442 (Div. 2)
CF
2,017
2
256
Olya and Energy Drinks
Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks. Formally, her room can be represented as a field of n × m cells, each cell of which is empty or littered with cans. Olya drank a lot of energy drink, so now she can run k meters per second. Each second she chooses...
The first line contains three integers n, m and k (1 ≤ n, m, k ≤ 1000) — the sizes of the room and Olya's speed. Then n lines follow containing m characters each, the i-th of them contains on j-th position "#", if the cell (i, j) is littered with cans, and "." otherwise. The last line contains four integers x1, y1, x...
Print a single integer — the minimum time it will take Olya to get from (x1, y1) to (x2, y2). If it's impossible to get from (x1, y1) to (x2, y2), print -1.
null
In the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second. In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds. Olya does not recommend drinking ener...
[{"input": "3 4 4\n....\n###.\n....\n1 1 3 1", "output": "3"}, {"input": "3 4 1\n....\n###.\n....\n1 1 3 1", "output": "8"}, {"input": "2 2 1\n.#\n#.\n1 1 2 2", "output": "-1"}]
2,100
["data structures", "dfs and similar", "graphs", "shortest paths"]
58
[{"input": "3 4 4\r\n....\r\n###.\r\n....\r\n1 1 3 1\r\n", "output": "3"}, {"input": "3 4 1\r\n....\r\n###.\r\n....\r\n1 1 3 1\r\n", "output": "8"}, {"input": "2 2 1\r\n.#\r\n#.\r\n1 1 2 2\r\n", "output": "-1"}, {"input": "10 10 1\r\n##########\r\n#.........\r\n#.#######.\r\n#.#.....#.\r\n#.#.###.#.\r\n#.#.#.#.#.\r\n#....
false
stdio
null
true
39/B
39
B
Python 3
TESTS
8
186
0
49549118
n = int(input()) a = list(map(int, input().split())) if 1 in a: last = a.index(1) l = [a[last]+2001] for i in range(last+1, n, 1): c = a[i] if c-last == 1: l.append(2000+i+1) last = c le = len(l) print(le) if le > 0: print(*l) else: print(0)
35
92
0
156967259
n=int(input()) a=input().split() p=1 q=[] for i in range (1,n+1): if int(a[i-1])==p: q.append(int(i+2000)) p+=1 print(len(q)) for i in range (1,len(q)+1): print(q[i-1],end=" ")
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Company Income Growth
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 — to a2 billion, ..., and in the current (2000 + n)-th...
The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers ai ( - 100 ≤ ai ≤ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output k — the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
null
null
[{"input": "10\n-2 1 1 3 2 3 4 -10 -2 5", "output": "5\n2002 2005 2006 2007 2010"}, {"input": "3\n-1 -2 -3", "output": "0"}]
1,300
["greedy"]
35
[{"input": "10\r\n-2 1 1 3 2 3 4 -10 -2 5\r\n", "output": "5\r\n2002 2005 2006 2007 2010 "}, {"input": "3\r\n-1 -2 -3\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n-1 1\r\n", "output": "1\r\n2002 "}, {"input": "2\r\n-1 1\r\n", "output":...
false
stdio
null
true
285/B
285
B
Python 3
TESTS
28
374
7,065,600
43182365
n,s,t = map(int,input().split()) p = [int(x) for x in input().split()] c = p[s-1] r=1 f=0 if(s==t): print(0) else: while(r<n): c = p[c-1] r+=1 if(c==t): f=1 print(r) break if(f==0): print(-1)
33
124
13,926,400
206799105
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ############ ---- Input Func...
Codeforces Round 175 (Div. 2)
CF
2,013
2
256
Find Marble
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not. First Petya puts a marble under the glass in position s. Then he performs some (pos...
The first line contains three integers: n, s, t (1 ≤ n ≤ 105; 1 ≤ s, t ≤ n) — the number of glasses, the ball's initial and final position. The second line contains n space-separated integers: p1, p2, ..., pn (1 ≤ pi ≤ n) — the shuffling operation parameters. It is guaranteed that all pi's are distinct. Note that s ca...
If the marble can move from position s to position t, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position t. If it is impossible, print number -1.
null
null
[{"input": "4 2 1\n2 3 4 1", "output": "3"}, {"input": "4 3 3\n4 1 3 2", "output": "0"}, {"input": "4 3 4\n1 2 3 4", "output": "-1"}, {"input": "3 1 3\n2 1 3", "output": "-1"}]
1,200
["implementation"]
33
[{"input": "4 2 1\r\n2 3 4 1\r\n", "output": "3\r\n"}, {"input": "4 3 3\r\n4 1 3 2\r\n", "output": "0\r\n"}, {"input": "4 3 4\r\n1 2 3 4\r\n", "output": "-1\r\n"}, {"input": "3 1 3\r\n2 1 3\r\n", "output": "-1\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "10 6 7\r\n10 7 8 1 5 6 2 9 4 3\r\n", "output...
false
stdio
null
true
4/D
4
D
PyPy 3-64
TESTS
9
77
0
223201565
import bisect class Slot: def __init__(self, w, h, i) -> None: self.w = w self.h = h self.i = i def __str__(self): return str(self.i) def __repr__(self): return f"({self.w}, {self.h})" [n, w, h] = list(map(int, input().split(' '))) slots: list[Slot] = [] for i in range(n): [wi, hi] = list(map(int, inpu...
33
452
8,499,200
223575394
################################################################################ n,w,h=map(int,input().split()) envelope=[] for i in range(n): wcup,hcup=map(int,input().split()) if (wcup>w) and (hcup>h): envelope.append((wcup,hcup,i+1)) # n=2 # w=1 # h=1 # envelope=[(2,2,1),(2,2,2)] # n=3 # w=3 # h=3 ...
Codeforces Beta Round 4 (Div. 2 Only)
ICPC
2,010
1
64
Mysterious Present
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the heigh...
The first line contains integers n, w, h (1 ≤ n ≤ 5000, 1 ≤ w, h ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi — width and height of the i-th envelope (1 ≤ wi, hi ≤ 106).
In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, pr...
null
null
[{"input": "2 1 1\n2 2\n2 2", "output": "1\n1"}, {"input": "3 3 3\n5 4\n12 11\n9 8", "output": "3\n1 3 2"}]
1,700
["dp", "sortings"]
33
[{"input": "2 1 1\r\n2 2\r\n2 2\r\n", "output": "1\r\n1 \r\n"}, {"input": "3 3 3\r\n5 4\r\n12 11\r\n9 8\r\n", "output": "3\r\n1 3 2 \r\n"}, {"input": "5 10 10\r\n22 23\r\n17 19\r\n13 17\r\n8 12\r\n2 6\r\n", "output": "3\r\n3 2 1 \r\n"}, {"input": "5 13 13\r\n4 4\r\n10 10\r\n7 7\r\n1 1\r\n13 13\r\n", "output": "0\r\n"},...
false
stdio
import sys def read_file_lines(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] input_lines = read_file_lines(input_path) if not input_lines: print(0) ...
true
479/C
479
C
PyPy 3-64
TESTS
25
140
7,168,000
209628110
a = [list(map(int,input().split())) for i in range(int(input()))] b = sorted(a) c = [i[1] for i in b] d = [i[0] for i in b] flag = 1 arr = [[b[0][1]]] for i in range(1, len(a)): if b[i][0] == b[i-1][0]: arr[-1].append(b[i][1]) else: arr.append([b[i][1]]) final = [] for i in arr: if sorted(i)...
53
61
512,000
213044495
def clc(): n = int(input()) arr = [] for _ in range(n): x,y = map(int,input().split()) arr.append((x,y)) best = -1 arr = sorted(arr) for i in range(len(arr)): if best<=arr[i][1]: best = arr[i][1] else: best = arr[i][0] print(best) ...
Codeforces Round 274 (Div. 2)
CF
2,014
1
256
Exams
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a stud...
The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly.
Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.
null
In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark ...
[{"input": "3\n5 2\n3 1\n4 2", "output": "2"}, {"input": "3\n6 1\n5 2\n4 3", "output": "6"}]
1,400
["greedy", "sortings"]
53
[{"input": "3\r\n5 2\r\n3 1\r\n4 2\r\n", "output": "2\r\n"}, {"input": "3\r\n6 1\r\n5 2\r\n4 3\r\n", "output": "6\r\n"}, {"input": "1\r\n1000000000 999999999\r\n", "output": "999999999\r\n"}, {"input": "1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n3 2\r\n", "output": "2\r\n"}, {"input": "5\r\n4 3\r\n4 2\r\...
false
stdio
null
true
549/D
549
D
PyPy 3
TESTS
1
108
23,347,200
32456185
n, m = map(int, input().split()) p = [input() for i in range(n)] s = 1 for i in range(n): for j in range(m): q = p[i][j] if i > 0 and j > 0: s += p[i][j - 1] != q != p[i - 1][j] if i < n - 1: if j < m - 1: s += p[i][j + 1] != q != p[i + 1][j] else: s += q != p[i + 1][...
47
124
0
11462214
import sys input = [] input_index = 0 def next(type, number = None): def next(): global input, input_index while input_index == len(input): if sys.stdin: input = sys.stdin.readline().split() input_index = 0 else: raise Exception() input_index += 1 return inp...
Looksery Cup 2015
CF
2,015
1
256
Haar Features
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept. Let's consider a rectangular image that is represent...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if i...
Print a single number — the minimum number of operations that you need to make to calculate the value of the feature.
null
The first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: 1. add the sum of pixels in...
[{"input": "6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "2"}, {"input": "3 3\nWBW\nBWW\nWWW", "output": "4"}, {"input": "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "output": "3"}, {"input": "4 4\nBBBB\nBBBB\nBBBB\nBBBW", "output": "4"}]
1,900
["greedy", "implementation"]
47
[{"input": "6 8\r\nBBBBBBBB\r\nBBBBBBBB\r\nBBBBBBBB\r\nWWWWWWWW\r\nWWWWWWWW\r\nWWWWWWWW\r\n", "output": "2\r\n"}, {"input": "3 3\r\nWBW\r\nBWW\r\nWWW\r\n", "output": "4\r\n"}, {"input": "3 6\r\nWWBBWW\r\nWWBBWW\r\nWWBBWW\r\n", "output": "3\r\n"}, {"input": "4 4\r\nBBBB\r\nBBBB\r\nBBBB\r\nBBBW\r\n", "output": "4\r\n"}, ...
false
stdio
null
true
815/B
815
B
Python 3
TESTS
2
1,746
13,414,400
27990959
n=int(input()) a=[int(i) for i in input().split()] fact=[1]*200005 ifact=[1]*200005 for i in range(1,200005): fact[i] = (fact[i-1]*i)%1000000007 for i in range(1,200005): ifact[i] = (ifact[i-1]*pow(i,1000000007-2,1000000007))%1000000007 if n%2!=0: b=[] z=1 for i in range(0,n-1): b.append(a[i...
75
498
41,472,000
85866594
#!/usr/bin/env pypy3 import math def make_nCr_mod(max_n=2*10**5 + 100, mod=10**9 + 7): fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1) fact[0] = 1 for i in range(max_n): fact[i + 1] = fact[i] * (i + 1) % mod inv_fact[-1] = pow(fact[-1], mod - 2, mod) for i in reversed(range(max_n)):...
Codeforces Round 419 (Div. 1)
CF
2,017
2
512
Karen and Test
Karen has just arrived at school, and she has a math test today! The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. There are n...
The first line of input contains a single integer n (1 ≤ n ≤ 200000), the number of numbers written on the first row. The next line contains n integers. Specifically, the i-th one among these is ai (1 ≤ ai ≤ 109), the i-th number on the first row.
Output a single integer on a line by itself, the number on the final row after performing the process above. Since this number can be quite large, print only the non-negative remainder after dividing it by 109 + 7.
null
In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15. Karen performs the operations as follows: The non-negative remainder after dividing the final number by 109 + 7 is still 36, so this is the correct output. In the second test case, the numbers written on the first row are 3, 7, 5 an...
[{"input": "5\n3 6 9 12 15", "output": "36"}, {"input": "4\n3 7 5 2", "output": "1000000006"}]
2,200
["brute force", "combinatorics", "constructive algorithms", "math"]
75
[{"input": "5\r\n3 6 9 12 15\r\n", "output": "36\r\n"}, {"input": "4\r\n3 7 5 2\r\n", "output": "1000000006\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "16\r\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004...
false
stdio
null
true
815/B
815
B
Python 3
TESTS
2
61
4,608,000
28785511
from math import factorial def combination(n, k): return factorial(n) // (factorial(k) * factorial(n - k)) n = int(input()) *a, = map(int, input().split()) if n % 2: a = [a[i] + a[i + 1] * ((-1) ** i) for i in range(n - 1)] n -= 1 s = 0 if not n % 4: for i in range(n // 2): s += combinati...
75
639
20,275,200
27860280
n = int(input()) p = list(map(int,input().split())) MOD = 10**9+7 mode = 0 if n%4 == 3: n-= 1 new = [] for i in range(n): if mode == 0: new.append(p[i]+p[i+1]) else: new.append(p[i]-p[i+1]) mode = 1-mode p = new def calc0(p): res = 0 ncr = 1 n = len(p)//2-1 for ...
Codeforces Round 419 (Div. 1)
CF
2,017
2
512
Karen and Test
Karen has just arrived at school, and she has a math test today! The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. There are n...
The first line of input contains a single integer n (1 ≤ n ≤ 200000), the number of numbers written on the first row. The next line contains n integers. Specifically, the i-th one among these is ai (1 ≤ ai ≤ 109), the i-th number on the first row.
Output a single integer on a line by itself, the number on the final row after performing the process above. Since this number can be quite large, print only the non-negative remainder after dividing it by 109 + 7.
null
In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15. Karen performs the operations as follows: The non-negative remainder after dividing the final number by 109 + 7 is still 36, so this is the correct output. In the second test case, the numbers written on the first row are 3, 7, 5 an...
[{"input": "5\n3 6 9 12 15", "output": "36"}, {"input": "4\n3 7 5 2", "output": "1000000006"}]
2,200
["brute force", "combinatorics", "constructive algorithms", "math"]
75
[{"input": "5\r\n3 6 9 12 15\r\n", "output": "36\r\n"}, {"input": "4\r\n3 7 5 2\r\n", "output": "1000000006\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "16\r\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004...
false
stdio
null
true
239/B
239
B
PyPy 3-64
TESTS
6
154
2,662,400
207286707
import sys input = lambda: sys.stdin.readline().rstrip() from collections import defaultdict N,Q = map(int, input().split()) S = input() for _ in range(Q): l,r = map(int, input().split()) l-=1;r-=1 ans = [0]*10 span = [-1,-1] for i in range(l,r+1): if S[i]=='>': span[0] = i...
33
218
2,355,200
114829797
R = lambda: map(int, input().split()) n, q = R() s = input() for _ in range(q): l, r = R() l -= 1 r -= 1 cs = [c for c in s[l:r + 1]] res = [0] * 10 p = 0 dir = 1 while 0 <= p < len(cs): if cs[p].isnumeric(): num = int(cs[p]) res[num] += 1 if n...
Codeforces Round 148 (Div. 2)
CF
2,012
2
256
Easy Tape Programming
There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. - Current character pointer (CP); - Dire...
The first line of input contains two integers n and q (1 ≤ n, q ≤ 100) — represents the length of the sequence s and the number of queries. The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. The next q lines ea...
For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input.
null
null
[{"input": "7 4\n1>3>22<\n1 3\n4 7\n7 7\n1 7", "output": "0 1 0 1 0 0 0 0 0 0\n2 2 2 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n2 3 2 1 0 0 0 0 0 0"}]
1,500
["brute force", "implementation"]
33
[{"input": "7 4\r\n1>3>22<\r\n1 3\r\n4 7\r\n7 7\r\n1 7\r\n", "output": "0 1 0 1 0 0 0 0 0 0 \r\n2 2 2 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n2 3 2 1 0 0 0 0 0 0 \r\n"}, {"input": "5 2\r\n>>>>>\r\n1 5\r\n1 2\r\n", "output": "0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "1 3\r\n9\r\n1 1\r\n1 1\r\n1 1\...
false
stdio
null
true
359/C
359
C
PyPy 3
TESTS
7
217
10,956,800
93155567
def modexp(a, b, mod): if b == 0: return 1 if b%2: return (((modexp(a, b//2, mod))**2)%mod * a)%mod else: return ((modexp(a, b//2, mod))**2)%mod if __name__ == '__main__': n, x = map(int, input().split()) seq = [int(x) for x in input().split()] maxim = max(seq) seqsum = sum(seq) freq_max = 0 for i ...
36
93
12,800,000
205483490
M=1000000007 def modpow(x, p): if p==0: return 1 y=modpow(x, p//2) if p%2: return (y*y*x)%M return (y*y)%M n,x=[int(e) for e in input().split()] a=[int(e) for e in input().split()] asum=sum(a) a=[asum-e for e in a][::-1] ans=0 i=0 c=0 while 1: ans+=a[i]-ans I=i while a[i]==a[...
Codeforces Round 209 (Div. 2)
CF
2,013
1
256
Prime Number
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fractions very much. Today he wrote out number $$\frac{1}{x^{a_1}} + \frac{1}{x^{a_2}} + \ldots + \frac{1}{x^{a_n}}$$ on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fra...
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
null
In the first sample $$\frac{1}{4} + \frac{1}{4} = \frac{4+4}{16} = \frac{8}{16}$$. Thus, the answer to the problem is 8. In the second sample, $$\frac{1}{3}+\frac{1}{9}+\frac{1}{27}=\frac{243+81+27}{729}=\frac{351}{729}$$. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27. In the third sample the answer to...
[{"input": "2 2\n2 2", "output": "8"}, {"input": "3 3\n1 2 3", "output": "27"}, {"input": "2 2\n29 29", "output": "73741817"}, {"input": "4 5\n0 0 0 0", "output": "1"}]
1,900
["math", "number theory"]
36
[{"input": "2 2\r\n2 2\r\n", "output": "8\r\n"}, {"input": "3 3\r\n1 2 3\r\n", "output": "27\r\n"}, {"input": "2 2\r\n29 29\r\n", "output": "73741817\r\n"}, {"input": "4 5\r\n0 0 0 0\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "26 2\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
false
stdio
null
true
600/F
600
F
Python 3
TESTS
3
30
0
170664382
import sys readline=sys.stdin.readline A,B,M=map(int,readline().split()) degree=[0]*(A+B) graph=[[] for i in range(A+B)] color={} max_degree=0 edges=[] for i in range(M): x,y=map(int,readline().split()) x-=1;y-=1 y+=A edges.append((x,y)) degree[x]+=1 degree[y]+=1 max_degree=max(max_degree,d...
47
467
28,979,200
196707263
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return u * c + v def g(u, v): return u * (n + 1) + v a, b, m = map(int, input().split()) n = a + b x = [0] * (2 * m) cnt = [0] * (n + 1) for i in range(m): u, v = map(int, input().split()) v += a x[2 * i]...
Educational Codeforces Round 2
ICPC
2,015
1
256
Edge coloring of bipartite graph
You are given an undirected bipartite graph without multiple edges. You should paint the edges of graph to minimal number of colours, so that no two adjacent edges have the same colour.
The first line contains three integers a, b, m (1 ≤ a, b ≤ 1000, 0 ≤ m ≤ 105), a is the size of the first part, b is the size of the second part, m is the number of edges in the graph. Each of the next m lines contains two integers x, y (1 ≤ x ≤ a, 1 ≤ y ≤ b), where x is the number of the vertex in the first part and ...
In the first line print integer c — the minimal number of colours. The second line should contain m integers from 1 to c — the colours of the edges (in the order they appear in the input). If there are several solutions, you can print any one of them.
null
null
[{"input": "4 3 5\n1 2\n2 2\n3 2\n4 1\n4 3", "output": "3\n1 2 3 1 2"}]
2,800
["graphs"]
47
[{"input": "4 3 5\r\n1 2\r\n2 2\r\n3 2\r\n4 1\r\n4 3\r\n", "output": "3\r\n1 2 3 1 2\r\n"}, {"input": "4 3 5\r\n1 2\r\n2 2\r\n3 2\r\n4 1\r\n4 3\r\n", "output": "3\r\n1 2 3 1 2\r\n"}, {"input": "4 3 0\r\n", "output": "0\r\n\r\n"}, {"input": "10 10 67\r\n1 1\r\n1 2\r\n1 3\r\n1 7\r\n1 9\r\n1 10\r\n2 1\r\n2 2\r\n2 3\r\n2 6...
false
stdio
import sys from collections import defaultdict def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: a, b, m = map(int, f.readline().split()) edges = [tuple(map(int, line.strip().split())) for line in [f.readline() for ...
true
815/B
815
B
Python 3
TESTS
16
1,138
25,292,800
28068391
def main(): MOD=10**9+7 N=int(input()) if N%4==0: K=N//2-1 elif N%4==1: K=(N-1)//2 elif N%4==2: K=N//2-1 else: K=(N-3)//2 fact=[1] invfact=[1] for i in range(1,K+1): temp=fact[i-1]*i temp%=MOD fact+=[temp] temp=invfact[...
75
498
41,472,000
85866594
#!/usr/bin/env pypy3 import math def make_nCr_mod(max_n=2*10**5 + 100, mod=10**9 + 7): fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1) fact[0] = 1 for i in range(max_n): fact[i + 1] = fact[i] * (i + 1) % mod inv_fact[-1] = pow(fact[-1], mod - 2, mod) for i in reversed(range(max_n)):...
Codeforces Round 419 (Div. 1)
CF
2,017
2
512
Karen and Test
Karen has just arrived at school, and she has a math test today! The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. There are n...
The first line of input contains a single integer n (1 ≤ n ≤ 200000), the number of numbers written on the first row. The next line contains n integers. Specifically, the i-th one among these is ai (1 ≤ ai ≤ 109), the i-th number on the first row.
Output a single integer on a line by itself, the number on the final row after performing the process above. Since this number can be quite large, print only the non-negative remainder after dividing it by 109 + 7.
null
In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15. Karen performs the operations as follows: The non-negative remainder after dividing the final number by 109 + 7 is still 36, so this is the correct output. In the second test case, the numbers written on the first row are 3, 7, 5 an...
[{"input": "5\n3 6 9 12 15", "output": "36"}, {"input": "4\n3 7 5 2", "output": "1000000006"}]
2,200
["brute force", "combinatorics", "constructive algorithms", "math"]
75
[{"input": "5\r\n3 6 9 12 15\r\n", "output": "36\r\n"}, {"input": "4\r\n3 7 5 2\r\n", "output": "1000000006\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "16\r\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004...
false
stdio
null
true
467/B
467
B
PyPy 3-64
TESTS
5
46
0
215440898
from sys import stdin def solve(): n, m, k = map(int, stdin.readline().split()) A = [] for _ in range(m): a = int(stdin.readline()) A.append(a) t = int(stdin.readline()) res = 0 for a in A: cnt = 0 for i in range(n): if a >> i != t >> i: ...
43
46
0
215736113
n, m, k = map(int, input().split()) x = [int(input()) for _ in range(m)] f = int(input()) print(sum(bin(f ^ v).count('1') <= k for v in x))
Codeforces Round 267 (Div. 2)
CF
2,014
1
256
Fedor and New Game
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3». The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each ...
The first line contains three integers n, m, k (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000). The i-th of the next (m + 1) lines contains a single integer xi (1 ≤ xi ≤ 2n - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.
Print a single integer — the number of Fedor's potential friends.
null
null
[{"input": "7 3 1\n8\n5\n111\n17", "output": "0"}, {"input": "3 3 3\n1\n2\n3\n4", "output": "3"}]
1,100
["bitmasks", "brute force", "constructive algorithms", "implementation"]
43
[{"input": "7 3 1\r\n8\r\n5\r\n111\r\n17\r\n", "output": "0\r\n"}, {"input": "3 3 3\r\n1\r\n2\r\n3\r\n4\r\n", "output": "3\r\n"}, {"input": "4 2 2\r\n5\r\n6\r\n7\r\n", "output": "2\r\n"}, {"input": "4 7 4\r\n9\r\n10\r\n5\r\n12\r\n4\r\n12\r\n7\r\n10\r\n", "output": "7\r\n"}, {"input": "2 7 2\r\n1\r\n1\r\n1\r\n1\r\n1\r\n...
false
stdio
null
true
386/A
386
A
Python 3
TESTS
1
31
0
149998014
n = int(input()) X = [int(i) for i in input().split()] mx = 0 sm = 0 for i in range(len(X)): if X[i] > mx: sm = mx mx = X[i] j = i print(j+1,sm)
42
31
0
187058436
n = int(input()) l = list(map(int, input().split())) largest = -33 second = -34 for i in range(len(l)): if l[i] > largest: second = largest largest = l[i] elif l[i] > second: second = l[i] print(l.index(largest)+1,second)
Testing Round 9
CF
2,014
1
256
Second-Price Auction
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auct...
The first line of the input contains n (2 ≤ n ≤ 1000) — number of bidders. The second line contains n distinct integer numbers p1, p2, ... pn, separated by single spaces (1 ≤ pi ≤ 10000), where pi stands for the price offered by the i-th bidder.
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
null
null
[{"input": "2\n5 7", "output": "2 5"}, {"input": "3\n10 2 8", "output": "1 8"}, {"input": "6\n3 8 2 9 4 14", "output": "6 9"}]
800
["implementation"]
42
[{"input": "2\r\n5 7\r\n", "output": "2 5\r\n"}, {"input": "3\r\n10 2 8\r\n", "output": "1 8\r\n"}, {"input": "6\r\n3 8 2 9 4 14\r\n", "output": "6 9\r\n"}, {"input": "4\r\n4707 7586 4221 5842\r\n", "output": "2 5842\r\n"}, {"input": "5\r\n3304 4227 4869 6937 6002\r\n", "output": "4 6002\r\n"}, {"input": "6\r\n5083 328...
false
stdio
null
true
290/E
290
E
PyPy 3
TESTS
11
310
6,348,800
113655067
c = str(input()) e = 0 y = len(c) if 1000000 >= len(c) > 1 : while y >= 0: if e+2 == len(c): print("Yes") break if c[e] + c[e+1] + c[e+2] == "HQH": print("No") break e = e + 1 y = y - 1 else : print("Yes")
28
1,090
56,320,000
197627903
a = input() b = [] h = '' c = 0 for i in a: if i == 'Q': c += 1 if c == 0: print('Yes') exit(0) r = -1 for i in range(1001): if i*i == c: r = i break if r == -1: print('No') exit(0) h = [a.split('Q')[0], a.split('Q')[-1]] c = [len(h[0]), len(h[1])] if c[0] % 2 != 0 or c[1] % 2 != 0: print('No') exit(0) c[...
April Fools Day Contest 2013
ICPC
2,013
2
256
HQ
The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ...
The only line of the input is a string between 1 and 106 characters long.
Output "Yes" or "No".
null
The rest of the problem statement was destroyed by a stray raccoon. We are terribly sorry for the inconvenience.
[{"input": "HHHH", "output": "Yes"}, {"input": "HQHQH", "output": "No"}, {"input": "HHQHHQH", "output": "No"}, {"input": "HHQQHHQQHH", "output": "Yes"}]
2,500
["*special", "constructive algorithms"]
28
[{"input": "HHHH\r\n", "output": "Yes\r\n"}, {"input": "HQHQH\r\n", "output": "No\r\n"}, {"input": "HHQHHQH\r\n", "output": "No\r\n"}, {"input": "HHQQHHQQHH\r\n", "output": "Yes\r\n"}, {"input": "Q\r\n", "output": "Yes\r\n"}, {"input": "HHHHHHHHHHQHHH\r\n", "output": "No\r\n"}, {"input": "HHQHQQQHHH\r\n", "output": "No...
false
stdio
null
true
600/F
600
F
PyPy 3
TESTS
3
62
0
147362042
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return u + m * v a, b, m = map(int, input().split()) G = [set() for _ in range(a + 1)] for i in range(m): x, y = map(int, input().split()) z = f(i, y) G[x].add(z) ok = [0] * (b + 1) c = 0 ans = [0] * m s = m w...
47
889
52,326,400
164155273
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.w...
Educational Codeforces Round 2
ICPC
2,015
1
256
Edge coloring of bipartite graph
You are given an undirected bipartite graph without multiple edges. You should paint the edges of graph to minimal number of colours, so that no two adjacent edges have the same colour.
The first line contains three integers a, b, m (1 ≤ a, b ≤ 1000, 0 ≤ m ≤ 105), a is the size of the first part, b is the size of the second part, m is the number of edges in the graph. Each of the next m lines contains two integers x, y (1 ≤ x ≤ a, 1 ≤ y ≤ b), where x is the number of the vertex in the first part and ...
In the first line print integer c — the minimal number of colours. The second line should contain m integers from 1 to c — the colours of the edges (in the order they appear in the input). If there are several solutions, you can print any one of them.
null
null
[{"input": "4 3 5\n1 2\n2 2\n3 2\n4 1\n4 3", "output": "3\n1 2 3 1 2"}]
2,800
["graphs"]
47
[{"input": "4 3 5\r\n1 2\r\n2 2\r\n3 2\r\n4 1\r\n4 3\r\n", "output": "3\r\n1 2 3 1 2\r\n"}, {"input": "4 3 5\r\n1 2\r\n2 2\r\n3 2\r\n4 1\r\n4 3\r\n", "output": "3\r\n1 2 3 1 2\r\n"}, {"input": "4 3 0\r\n", "output": "0\r\n\r\n"}, {"input": "10 10 67\r\n1 1\r\n1 2\r\n1 3\r\n1 7\r\n1 9\r\n1 10\r\n2 1\r\n2 2\r\n2 3\r\n2 6...
false
stdio
import sys from collections import defaultdict def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: a, b, m = map(int, f.readline().split()) edges = [tuple(map(int, line.strip().split())) for line in [f.readline() for ...
true
386/A
386
A
Python 3
TESTS
1
30
0
186987706
n=int(input()) a=list(map(int,input().split())) M=a[0] B=0 L=0 for i in range(0,n): if a[i]>=M: B=M M=a[i] L=i print(L+1,B)
42
31
0
187152541
bidders = int(input("")) data = input("") data = data.split(" ") winnerindex = 0 highestprice = 0 for i in range(len(data)): data[i] = int(data[i]) for i in range(len(data)): if data[i] > highestprice: highestprice = data[i] winnerindex = i data.sort(reverse=True) pricetopay = data[1] print(f"{int(winn...
Testing Round 9
CF
2,014
1
256
Second-Price Auction
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auct...
The first line of the input contains n (2 ≤ n ≤ 1000) — number of bidders. The second line contains n distinct integer numbers p1, p2, ... pn, separated by single spaces (1 ≤ pi ≤ 10000), where pi stands for the price offered by the i-th bidder.
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
null
null
[{"input": "2\n5 7", "output": "2 5"}, {"input": "3\n10 2 8", "output": "1 8"}, {"input": "6\n3 8 2 9 4 14", "output": "6 9"}]
800
["implementation"]
42
[{"input": "2\r\n5 7\r\n", "output": "2 5\r\n"}, {"input": "3\r\n10 2 8\r\n", "output": "1 8\r\n"}, {"input": "6\r\n3 8 2 9 4 14\r\n", "output": "6 9\r\n"}, {"input": "4\r\n4707 7586 4221 5842\r\n", "output": "2 5842\r\n"}, {"input": "5\r\n3304 4227 4869 6937 6002\r\n", "output": "4 6002\r\n"}, {"input": "6\r\n5083 328...
false
stdio
null
true
877/D
877
D
PyPy 3
TESTS
30
576
37,888,000
180466871
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return u * m + v def bfs(x1, y1, x2, y2): q1, q2 = [], [] q1.append((x1, y1, 1)) q1.append((x1, y1, 2)) dist1, dist2 = [inf] * l, [inf] * l dist1[f(x1, y1)], dist2[f(x1, y1)] = 0, 0 d = 0 while...
58
920
42,291,200
104957787
import sys import io, os input = sys.stdin.readline INF = 10**18 def main(): h, w, k = map(int, input().split()) C = [input().rstrip() for i in range(h)] x1, y1, x2, y2 = map(int, input().split()) x1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1 #print(C) from collections import deque q = deque() ...
Codeforces Round 442 (Div. 2)
CF
2,017
2
256
Olya and Energy Drinks
Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks. Formally, her room can be represented as a field of n × m cells, each cell of which is empty or littered with cans. Olya drank a lot of energy drink, so now she can run k meters per second. Each second she chooses...
The first line contains three integers n, m and k (1 ≤ n, m, k ≤ 1000) — the sizes of the room and Olya's speed. Then n lines follow containing m characters each, the i-th of them contains on j-th position "#", if the cell (i, j) is littered with cans, and "." otherwise. The last line contains four integers x1, y1, x...
Print a single integer — the minimum time it will take Olya to get from (x1, y1) to (x2, y2). If it's impossible to get from (x1, y1) to (x2, y2), print -1.
null
In the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second. In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds. Olya does not recommend drinking ener...
[{"input": "3 4 4\n....\n###.\n....\n1 1 3 1", "output": "3"}, {"input": "3 4 1\n....\n###.\n....\n1 1 3 1", "output": "8"}, {"input": "2 2 1\n.#\n#.\n1 1 2 2", "output": "-1"}]
2,100
["data structures", "dfs and similar", "graphs", "shortest paths"]
58
[{"input": "3 4 4\r\n....\r\n###.\r\n....\r\n1 1 3 1\r\n", "output": "3"}, {"input": "3 4 1\r\n....\r\n###.\r\n....\r\n1 1 3 1\r\n", "output": "8"}, {"input": "2 2 1\r\n.#\r\n#.\r\n1 1 2 2\r\n", "output": "-1"}, {"input": "10 10 1\r\n##########\r\n#.........\r\n#.#######.\r\n#.#.....#.\r\n#.#.###.#.\r\n#.#.#.#.#.\r\n#....
false
stdio
null
true
877/D
877
D
PyPy 3
TESTS
30
1,029
108,134,400
59074740
n, m, k = [int(i) for i in input().split()] A = [] for i in range(n): A.append(list(input())) x1, y1, x2, y2 = [int(i) for i in input().split()] x1 -= 1 y1 -= 1 x2 -= 1 y2 -= 1 if x1 == x2 and y1 == y2: print(0) exit(0) dd = {} dd[(x1, y1)] = 0 next_iter_positions = [(x1, y1)] iter = 0 while T...
58
1,028
164,352,000
149053471
n,m,k=map(int,input().split()) cell=[[] for j in range(n+1)] for i in range(1,n+1): cell[i]=[0]+list(input()) x1,y1,x2,y2=map(int,input().split()) dis=[[10**6]*(m+1) for i in range(n+1)] q=[] num=0 move=[[-1,0],[1,0],[0,-1],[0,1]] q.append((x1,y1)) dis[x1][y1]=0 while num<len(q): x,y=q[num] if (x,y)==(x2,y2...
Codeforces Round 442 (Div. 2)
CF
2,017
2
256
Olya and Energy Drinks
Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks. Formally, her room can be represented as a field of n × m cells, each cell of which is empty or littered with cans. Olya drank a lot of energy drink, so now she can run k meters per second. Each second she chooses...
The first line contains three integers n, m and k (1 ≤ n, m, k ≤ 1000) — the sizes of the room and Olya's speed. Then n lines follow containing m characters each, the i-th of them contains on j-th position "#", if the cell (i, j) is littered with cans, and "." otherwise. The last line contains four integers x1, y1, x...
Print a single integer — the minimum time it will take Olya to get from (x1, y1) to (x2, y2). If it's impossible to get from (x1, y1) to (x2, y2), print -1.
null
In the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second. In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds. Olya does not recommend drinking ener...
[{"input": "3 4 4\n....\n###.\n....\n1 1 3 1", "output": "3"}, {"input": "3 4 1\n....\n###.\n....\n1 1 3 1", "output": "8"}, {"input": "2 2 1\n.#\n#.\n1 1 2 2", "output": "-1"}]
2,100
["data structures", "dfs and similar", "graphs", "shortest paths"]
58
[{"input": "3 4 4\r\n....\r\n###.\r\n....\r\n1 1 3 1\r\n", "output": "3"}, {"input": "3 4 1\r\n....\r\n###.\r\n....\r\n1 1 3 1\r\n", "output": "8"}, {"input": "2 2 1\r\n.#\r\n#.\r\n1 1 2 2\r\n", "output": "-1"}, {"input": "10 10 1\r\n##########\r\n#.........\r\n#.#######.\r\n#.#.....#.\r\n#.#.###.#.\r\n#.#.#.#.#.\r\n#....
false
stdio
null
true
467/B
467
B
Python 3
TESTS
5
46
0
230230414
n,m,k=map(int,input().split()) G=[] x=0 for mi in range(m): G.append(bin(int(input()))[2:]) F=bin(int(input()))[2:] f=len(F) for g in G: diff = 0 check = 1 for i in range(max(len(g),f),-1,-1): if i >= len(g) or i >= f: diff+=1 elif g[i]!=F[i]: diff+=1 if d...
43
46
0
217478083
n,m,k = map(int,input().split()) a = [] for i in range(m+1): a.append(int(input())) f = a[m] c = 0 for i in range(m): q = f ^ a[i] d = 0 e = 1 for j in range(20): d += e & q != 0 e <<= 1 c += d <=k print(c)
Codeforces Round 267 (Div. 2)
CF
2,014
1
256
Fedor and New Game
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3». The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each ...
The first line contains three integers n, m, k (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000). The i-th of the next (m + 1) lines contains a single integer xi (1 ≤ xi ≤ 2n - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.
Print a single integer — the number of Fedor's potential friends.
null
null
[{"input": "7 3 1\n8\n5\n111\n17", "output": "0"}, {"input": "3 3 3\n1\n2\n3\n4", "output": "3"}]
1,100
["bitmasks", "brute force", "constructive algorithms", "implementation"]
43
[{"input": "7 3 1\r\n8\r\n5\r\n111\r\n17\r\n", "output": "0\r\n"}, {"input": "3 3 3\r\n1\r\n2\r\n3\r\n4\r\n", "output": "3\r\n"}, {"input": "4 2 2\r\n5\r\n6\r\n7\r\n", "output": "2\r\n"}, {"input": "4 7 4\r\n9\r\n10\r\n5\r\n12\r\n4\r\n12\r\n7\r\n10\r\n", "output": "7\r\n"}, {"input": "2 7 2\r\n1\r\n1\r\n1\r\n1\r\n1\r\n...
false
stdio
null
true
386/A
386
A
PyPy 3-64
TESTS
1
46
0
141440908
n = int(input()) a = [int(el) for el in input().split()] m1, m2, ind = -1, -1, -1 for i in range(len(a)): if a[i] > m1: m2 = m1 m1 = a[i] ind = i + 1 print(ind, m2, sep = ' ')
42
31
0
208978961
def bid(n,a): b = max(a) for i in range(0,n): if a[i] == b: index = i+1 break a.remove(b) c = max(a) print(f"{index} {c}") def main(): n = int(input()) a = list(map(int,input().split())) bid(n,a) main()
Testing Round 9
CF
2,014
1
256
Second-Price Auction
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auct...
The first line of the input contains n (2 ≤ n ≤ 1000) — number of bidders. The second line contains n distinct integer numbers p1, p2, ... pn, separated by single spaces (1 ≤ pi ≤ 10000), where pi stands for the price offered by the i-th bidder.
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
null
null
[{"input": "2\n5 7", "output": "2 5"}, {"input": "3\n10 2 8", "output": "1 8"}, {"input": "6\n3 8 2 9 4 14", "output": "6 9"}]
800
["implementation"]
42
[{"input": "2\r\n5 7\r\n", "output": "2 5\r\n"}, {"input": "3\r\n10 2 8\r\n", "output": "1 8\r\n"}, {"input": "6\r\n3 8 2 9 4 14\r\n", "output": "6 9\r\n"}, {"input": "4\r\n4707 7586 4221 5842\r\n", "output": "2 5842\r\n"}, {"input": "5\r\n3304 4227 4869 6937 6002\r\n", "output": "4 6002\r\n"}, {"input": "6\r\n5083 328...
false
stdio
null
true
359/C
359
C
PyPy 3
TESTS
9
233
36,147,200
88023794
import math pri=pow(10,9)+7 n,x=map(int,input().split()) z=list(map(int,input().split())) sumr=sum(z) gcd=sumr-max(z) t=max(z) ans=z.copy() for i in range(len(ans)): ans[i]=t-ans[i] ans.sort() temp=[] count=1 for i in range(1,len(ans)): if(ans[i]==ans[i-1]): count+=1 else: temp.append([ans[...
36
93
13,414,400
168772649
R,G=lambda:map(int,input().split()),range n,x=R();a=[*R()];s=sum(a);v,c=a[-1],0 while v: while a and v==a[-1]:a.pop();c+=1 if c%x:break c//=x;v-=1 print(pow(x,s-v,10**9+7))
Codeforces Round 209 (Div. 2)
CF
2,013
1
256
Prime Number
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fractions very much. Today he wrote out number $$\frac{1}{x^{a_1}} + \frac{1}{x^{a_2}} + \ldots + \frac{1}{x^{a_n}}$$ on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fra...
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
null
In the first sample $$\frac{1}{4} + \frac{1}{4} = \frac{4+4}{16} = \frac{8}{16}$$. Thus, the answer to the problem is 8. In the second sample, $$\frac{1}{3}+\frac{1}{9}+\frac{1}{27}=\frac{243+81+27}{729}=\frac{351}{729}$$. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27. In the third sample the answer to...
[{"input": "2 2\n2 2", "output": "8"}, {"input": "3 3\n1 2 3", "output": "27"}, {"input": "2 2\n29 29", "output": "73741817"}, {"input": "4 5\n0 0 0 0", "output": "1"}]
1,900
["math", "number theory"]
36
[{"input": "2 2\r\n2 2\r\n", "output": "8\r\n"}, {"input": "3 3\r\n1 2 3\r\n", "output": "27\r\n"}, {"input": "2 2\r\n29 29\r\n", "output": "73741817\r\n"}, {"input": "4 5\r\n0 0 0 0\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "26 2\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
false
stdio
null
true
359/C
359
C
PyPy 3
TESTS
17
233
10,956,800
82484957
import math mod=10**9+7 n,x=map(int,input().split()) l=list(map(int,input().split())) r=max(l) s=l.count(r) gcd=math.gcd(s,pow(x,r,s))%mod*pow(x,sum(l)-r,mod) print(gcd%mod)
36
156
9,523,200
5184370
MOD = 10**9+7 def pow(x, n, MOD): if(n==0): return 1 if(n%2==0): a = pow(x, n//2, MOD) return a*a % MOD else: a = pow(x, n//2, MOD) return (x*a*a) % MOD n, x = [int(x) for x in input().split()] a = [int(x) for x in input().split()] s = sum(a) d = [] for el in a: d....
Codeforces Round 209 (Div. 2)
CF
2,013
1
256
Prime Number
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fractions very much. Today he wrote out number $$\frac{1}{x^{a_1}} + \frac{1}{x^{a_2}} + \ldots + \frac{1}{x^{a_n}}$$ on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fra...
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
null
In the first sample $$\frac{1}{4} + \frac{1}{4} = \frac{4+4}{16} = \frac{8}{16}$$. Thus, the answer to the problem is 8. In the second sample, $$\frac{1}{3}+\frac{1}{9}+\frac{1}{27}=\frac{243+81+27}{729}=\frac{351}{729}$$. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27. In the third sample the answer to...
[{"input": "2 2\n2 2", "output": "8"}, {"input": "3 3\n1 2 3", "output": "27"}, {"input": "2 2\n29 29", "output": "73741817"}, {"input": "4 5\n0 0 0 0", "output": "1"}]
1,900
["math", "number theory"]
36
[{"input": "2 2\r\n2 2\r\n", "output": "8\r\n"}, {"input": "3 3\r\n1 2 3\r\n", "output": "27\r\n"}, {"input": "2 2\r\n29 29\r\n", "output": "73741817\r\n"}, {"input": "4 5\r\n0 0 0 0\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "26 2\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
false
stdio
null
true
359/C
359
C
PyPy 3
TESTS
6
233
31,129,600
86278519
import math as m n,x=map(int,input().split()) arr=[int(i) for i in input().split()] s=sum(arr) l=s-max(arr) powers=[] cnt=0 for i in arr: if s-i == l: cnt+=1 l=l+cnt//x mod=10**9+7 print(pow(x,l,mod))
36
202
10,956,800
167983997
n, x = map(int, input().split()) t = list(map(int, input().split())) b = max(t) k = t.count(b) r = sum(t) s = r - b while k % x == 0: b -= 1 s += 1 k = k // x + t.count(b) print(pow(x, min(r, s), 1000000007))
Codeforces Round 209 (Div. 2)
CF
2,013
1
256
Prime Number
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fractions very much. Today he wrote out number $$\frac{1}{x^{a_1}} + \frac{1}{x^{a_2}} + \ldots + \frac{1}{x^{a_n}}$$ on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fra...
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
null
In the first sample $$\frac{1}{4} + \frac{1}{4} = \frac{4+4}{16} = \frac{8}{16}$$. Thus, the answer to the problem is 8. In the second sample, $$\frac{1}{3}+\frac{1}{9}+\frac{1}{27}=\frac{243+81+27}{729}=\frac{351}{729}$$. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27. In the third sample the answer to...
[{"input": "2 2\n2 2", "output": "8"}, {"input": "3 3\n1 2 3", "output": "27"}, {"input": "2 2\n29 29", "output": "73741817"}, {"input": "4 5\n0 0 0 0", "output": "1"}]
1,900
["math", "number theory"]
36
[{"input": "2 2\r\n2 2\r\n", "output": "8\r\n"}, {"input": "3 3\r\n1 2 3\r\n", "output": "27\r\n"}, {"input": "2 2\r\n29 29\r\n", "output": "73741817\r\n"}, {"input": "4 5\r\n0 0 0 0\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "26 2\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
false
stdio
null
true
285/B
285
B
PyPy 3
TESTS
28
310
9,011,200
108490496
n,s,t = map(int,input().split(' ')) pos = list(map(int,input().split(' '))) c = 0 if s==t: print(0) else: i = pos[s-1] while(1): i = pos[i-1] c +=1 if i == t: print(c+1) break elif i == s: print(-1) break
33
154
7,270,400
137405775
n, s, t = map(int, input().split()) p = list(map(int, input().split())) c = 0 stemp = s while s!=t: c+=1 s = p[s-1] if s == stemp: print(-1) exit() print(c)
Codeforces Round 175 (Div. 2)
CF
2,013
2
256
Find Marble
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not. First Petya puts a marble under the glass in position s. Then he performs some (pos...
The first line contains three integers: n, s, t (1 ≤ n ≤ 105; 1 ≤ s, t ≤ n) — the number of glasses, the ball's initial and final position. The second line contains n space-separated integers: p1, p2, ..., pn (1 ≤ pi ≤ n) — the shuffling operation parameters. It is guaranteed that all pi's are distinct. Note that s ca...
If the marble can move from position s to position t, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position t. If it is impossible, print number -1.
null
null
[{"input": "4 2 1\n2 3 4 1", "output": "3"}, {"input": "4 3 3\n4 1 3 2", "output": "0"}, {"input": "4 3 4\n1 2 3 4", "output": "-1"}, {"input": "3 1 3\n2 1 3", "output": "-1"}]
1,200
["implementation"]
33
[{"input": "4 2 1\r\n2 3 4 1\r\n", "output": "3\r\n"}, {"input": "4 3 3\r\n4 1 3 2\r\n", "output": "0\r\n"}, {"input": "4 3 4\r\n1 2 3 4\r\n", "output": "-1\r\n"}, {"input": "3 1 3\r\n2 1 3\r\n", "output": "-1\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "10 6 7\r\n10 7 8 1 5 6 2 9 4 3\r\n", "output...
false
stdio
null
true
186/B
186
B
Python 3
TESTS
25
124
0
174043001
numbers = list(map(int , input().split())) time = [numbers[1] , numbers[2]] data = [] for i in range(0 , numbers[0]) : x = list(map(int ,input().split())) a = x[0]*time[0] b = x[1]*time[0] f = a - (a * numbers[3]/100) + x[1]*time[1] s = b - (b * numbers[3]/100) + x[0]*time[1] data.append...
36
92
0
136538422
import sys def MyFunc(e): return(e[1]) data = sys.stdin.readline()[:-1].split(' ') n, t1, t2, k = int(data[0]), int(data[1]), int(data[2]), int(data[3]) t1 *= 1-k/100 if t2 > t1: t1, t2 = t2, t1 dwarves = [[0,0] for _ in range(n)] for i in range(n): dwarves[i][0] = i+1 vu = sys.stdin.readline()[:-1].s...
Codeforces Round 118 (Div. 2)
CF
2,012
2
256
Growing Mushrooms
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules ...
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly. Each of the following n lines contains two inte...
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
null
- First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
[{"input": "2 3 3 50\n2 4\n4 2", "output": "1 15.00\n2 15.00"}, {"input": "4 1 1 1\n544 397\n280 101\n280 101\n693 970", "output": "4 1656.07\n1 937.03\n2 379.99\n3 379.99"}]
1,200
["greedy", "sortings"]
36
[{"input": "2 3 3 50\r\n2 4\r\n4 2\r\n", "output": "1 15.00\r\n2 15.00\r\n"}, {"input": "4 1 1 1\r\n544 397\r\n280 101\r\n280 101\r\n693 970\r\n", "output": "4 1656.07\r\n1 937.03\r\n2 379.99\r\n3 379.99\r\n"}, {"input": "10 1 1 25\r\n981 1\r\n352 276\r\n164 691\r\n203 853\r\n599 97\r\n901 688\r\n934 579\r\n910 959\r\n...
false
stdio
null
true
343/C
343
C
Python 3
TESTS
4
30
0
219582318
nh, nd= map(int, input().split()) hs=list(map(int,input().split())) ds=list(map(int,input().split())) ld=[] best=0 dic={} for i in range(nd): k=[] for j in hs: k.append(abs(j-ds[i])) if(k.count(min(k))!=0): for x in range(len(k)): if k.index(k[x]) in dic.keys() and k[x]==min(k): ...
61
280
27,750,400
182176854
import sys import threading # input=sys.stdin.readline from collections import Counter,defaultdict,deque from heapq import heappush,heappop,heapify #threading.stack_size(10**8) #sys.setrecursionlimit(10**6) def ri():return int(input()) def rs():return input() def rl():return list(map(int,input().split())) def rls():re...
Codeforces Round 200 (Div. 1)
CF
2,013
1
256
Read Time
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel. When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the...
The first line of the input contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of disk heads and the number of tracks to read, accordingly. The second line contains n distinct integers hi in ascending order (1 ≤ hi ≤ 1010, hi < hi + 1) — the initial positions of the heads. The third line contains ...
Print a single number — the minimum time required, in seconds, to read all the needed tracks.
null
The first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way: 1. during the first second move the 1-st head to the left and let it stay there; 2. move the second head to the left twice; 3. move the third head to the right twice (note that the 6-th track has alre...
[{"input": "3 4\n2 5 6\n1 3 6 8", "output": "2"}, {"input": "3 3\n1 2 3\n1 2 3", "output": "0"}, {"input": "1 2\n165\n142 200", "output": "81"}]
1,900
["binary search", "greedy", "two pointers"]
61
[{"input": "3 4\r\n2 5 6\r\n1 3 6 8\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2 3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "1 2\r\n165\r\n142 200\r\n", "output": "81\r\n"}, {"input": "1 2\r\n5000000000\r\n1 10000000000\r\n", "output": "14999999998\r\n"}, {"input": "2 4\r\n3 12\r\n1 7 8 14\r\n", "output": "8\r\n...
false
stdio
null
true
734/D
734
D
PyPy 3-64
TESTS
1
62
0
218822564
def is_under_check(n, king_x, king_y, pieces): directions = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)] for piece_type, piece_x, piece_y in pieces: if piece_type == 'R': if king_x == piece_x or king_y == piece_y: return True elif piece_type...
64
1,278
0
230899269
s, n = {}, int(input()) x, y = map(int, input().split()) for i in range(n): t, a, b = input().split() u, v = int(a) - x, int(b) - y a = (abs(u) == abs(v)) b = (u == 0 or v == 0) d = abs(u) + abs(v) p = (u < 0, v < 0, u > 0, v > 0) q = (d, t in 'Q' + 'RB'[a]) if a or b: s[p] = min(s[p], q...
Codeforces Round 379 (Div. 2)
CF
2,016
4
256
Anton and Chess
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead. The first task he faced is to check whether the king is in check. Anton doesn't know how to implement thi...
The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of black pieces. The second line contains two integers x0 and y0 ( - 109 ≤ x0, y0 ≤ 109) — coordinates of the white king. Then follow n lines, each of them contains a character and two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — t...
The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.
null
Picture for the first sample: Picture for the second sample:
[{"input": "2\n4 2\nR 1 1\nB 1 5", "output": "YES"}, {"input": "2\n4 2\nR 3 3\nB 1 5", "output": "NO"}]
1,700
["implementation"]
64
[{"input": "2\r\n4 2\r\nR 1 1\r\nB 1 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\nR 3 3\r\nB 1 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 1\r\nR -10 10\r\nQ -9 9\r\nQ -2 -8\r\nB -6 10\r\nB -10 1\r\n", "output": "YES\r\n"}, {"input": "20\r\n-321 454\r\nQ 967 -89\r\nR -811 454\r\nQ -404 454\r\nR -734 454\r\n...
false
stdio
null
true
765/E
765
E
PyPy 3
TESTS
6
108
23,142,400
24682134
# Author: Maharshi Gor from collections import deque def read(type=int): return type(input()) def read_arr(type=int): return [type(token) for token in input().split()] def foo(p, u): # print('foo:', p, u) if len(A[u]) == 1 and A[u][0] == p: return 0 H = set() E = [] for v in A[...
54
904
82,534,400
202739803
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) G = [set() for _ in range(n + 1)] for _ in range(n - 1): u, v = map(int, input().split()) G[u].add(v) G[v].add(u) q = [] x = [set() for _ in range(n + 1)] cnt = [len(g) for g in G] for i in range(1, n + 1): ...
Codeforces Round 397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
512
Tree Folding
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent verti...
The first line of input contains the number of vertices n (2 ≤ n ≤ 2·105). Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 ≤ u, v ≤ n, u ≠ v) — indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.
If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.
null
In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5. It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the co...
[{"input": "6\n1 2\n2 3\n2 4\n4 5\n1 6", "output": "3"}, {"input": "7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7", "output": "-1"}]
2,200
["dfs and similar", "dp", "greedy", "implementation", "trees"]
54
[{"input": "6\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n1 6\r\n", "output": "3\r\n"}, {"input": "7\r\n1 2\r\n1 3\r\n3 4\r\n1 5\r\n5 6\r\n6 7\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n3 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "10\r\n5 10\r\n7 8\r\n8 3\r\n2 6\r\n3 2\r\n9 7\r\n4 5\...
false
stdio
null
true
28/B
28
B
PyPy 3
TESTS
3
154
20,172,800
115980814
def dsu(nodo): if nueva[nodo] != nodo: nueva[nodo] = dsu(nueva[nodo]) return nueva[nodo] else: return nodo def main(): n = int(input()) permutaciones = list(map(int, input().split())) favoritos = list(map(int, input().split())) l = [] for i in range(n): l.ap...
33
92
307,200
230932246
import collections n=int(input()) arr=[i+1 for i in range(n)] tar=[int(i) for i in input().split()] fav=[int(i) for i in input().split()] par=[i for i in range(n)] def find(x): if x!=par[x]: par[x]=find(par[x]) return par[x] def union(x,y): px,py=par[find(x)],par[find(y)] par[px]=py for i...
Codeforces Beta Round 28 (Codeforces format)
CF
2,010
2
256
pSort
One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where ...
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of cells in the array. The second line contains n distinct integers from 1 to n — permutation. The last line contains n integers from 1 to n — favourite numbers of the cells.
If the given state is reachable in the described game, output YES, otherwise NO.
null
null
[{"input": "5\n5 4 3 2 1\n1 1 1 1 1", "output": "YES"}, {"input": "7\n4 3 5 1 2 7 6\n4 6 6 1 6 6 1", "output": "NO"}, {"input": "7\n4 2 5 1 3 7 6\n4 6 6 1 6 6 1", "output": "YES"}]
1,600
["dfs and similar", "dsu", "graphs"]
33
[{"input": "5\r\n5 4 3 2 1\r\n1 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n4 3 5 1 2 7 6\r\n4 6 6 1 6 6 1\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 2 5 1 3 7 6\r\n4 6 6 1 6 6 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n3 2 1 4 6 5\r\n3 6 1 6 6 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n3 5 1 4 6 2\r\n3...
false
stdio
null
true
734/D
734
D
PyPy 3-64
TESTS
2
62
0
218827445
n = int(input()) x, y = map(int, input().split()) blacks = [] for t in range(n): a = input().split() if a[0] == 'Q': blacks.append(['B', int(a[1]), int(a[2])]) blacks.append(['R', int(a[1]), int(a[2])]) else: blacks.append([a[0], int(a[1]), int(a[2])]) x_c = [t[1] for t in blacks] ...
64
1,809
307,200
22245153
n = int(input()) x, y = map(int, input().split()) directions = [None for x in range(8)] # u, ur, r, rd, d, dl, l, lu for i in range(n): line = input().split() xi = int(line[1]) yi = int(line[2]) if yi == y: if xi < x: #left if directions[6] == None: ...
Codeforces Round 379 (Div. 2)
CF
2,016
4
256
Anton and Chess
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead. The first task he faced is to check whether the king is in check. Anton doesn't know how to implement thi...
The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of black pieces. The second line contains two integers x0 and y0 ( - 109 ≤ x0, y0 ≤ 109) — coordinates of the white king. Then follow n lines, each of them contains a character and two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — t...
The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.
null
Picture for the first sample: Picture for the second sample:
[{"input": "2\n4 2\nR 1 1\nB 1 5", "output": "YES"}, {"input": "2\n4 2\nR 3 3\nB 1 5", "output": "NO"}]
1,700
["implementation"]
64
[{"input": "2\r\n4 2\r\nR 1 1\r\nB 1 5\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\nR 3 3\r\nB 1 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 1\r\nR -10 10\r\nQ -9 9\r\nQ -2 -8\r\nB -6 10\r\nB -10 1\r\n", "output": "YES\r\n"}, {"input": "20\r\n-321 454\r\nQ 967 -89\r\nR -811 454\r\nQ -404 454\r\nR -734 454\r\n...
false
stdio
null
true
386/A
386
A
Python 3
TESTS
1
31
0
149997708
n = int(input()) X = [int(i) for i in input().split()] mx = 0 sm = 0 for ele in X: if ele > mx: sm = mx mx = ele print(X.index(mx)+1,sm)
42
31
0
225808679
n=int(input())# no of bidders prices=list(map(int,input().split()))#price from all bidders win_bid=prices.index(max(prices))+1 # as 1-based prices.pop(win_bid-1)# removing win bid from list sec_highest_bid=max(prices) print(win_bid,sec_highest_bid)
Testing Round 9
CF
2,014
1
256
Second-Price Auction
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auct...
The first line of the input contains n (2 ≤ n ≤ 1000) — number of bidders. The second line contains n distinct integer numbers p1, p2, ... pn, separated by single spaces (1 ≤ pi ≤ 10000), where pi stands for the price offered by the i-th bidder.
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
null
null
[{"input": "2\n5 7", "output": "2 5"}, {"input": "3\n10 2 8", "output": "1 8"}, {"input": "6\n3 8 2 9 4 14", "output": "6 9"}]
800
["implementation"]
42
[{"input": "2\r\n5 7\r\n", "output": "2 5\r\n"}, {"input": "3\r\n10 2 8\r\n", "output": "1 8\r\n"}, {"input": "6\r\n3 8 2 9 4 14\r\n", "output": "6 9\r\n"}, {"input": "4\r\n4707 7586 4221 5842\r\n", "output": "2 5842\r\n"}, {"input": "5\r\n3304 4227 4869 6937 6002\r\n", "output": "4 6002\r\n"}, {"input": "6\r\n5083 328...
false
stdio
null
true
883/G
883
G
Python 3
TESTS
3
46
0
32320304
l1 = input().split() n = int(l1[0]) m = int(l1[1]) s = int(l1[2]) max_graph = {} min_graph = {} max_sequence = [] min_sequence = [] for i in range(m): l = input().split() t = int(l[0]) u = int(l[1]) v = int(l[2]) if t == 2: if u == s: max_sequence.append('+') if u i...
141
1,200
48,844,800
95314305
import sys input = sys.stdin.readline def put(): return map(int, input().split()) def dfs0(x): s = [x] vis = [0] * n ans = ['+'] * m vis[x] = 1 while s: i = s.pop() for j, k in graph[i]: if (vis[j] == 0): if (k < 0): ans[-k - 1] = '-' elif (k > 0): ans[...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Orientation of Edges
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices. Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans: 1. to orient each undirected edge in one of two possible directions to maximize n...
The first line contains three integers n, m and s (2 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105, 1 ≤ s ≤ n) — number of vertices and edges in the graph, and the vertex Vasya has picked. The following m lines contain information about the graph edges. Each line contains three integers ti, ui and vi (1 ≤ ti ≤ 2, 1 ≤ ui, vi ≤ n, ui ≠ vi...
The first two lines should describe the plan which maximizes the number of reachable vertices. The lines three and four should describe the plan which minimizes the number of reachable vertices. A description of each plan should start with a line containing the number of reachable vertices. The second line of a plan s...
null
null
[{"input": "2 2 1\n1 1 2\n2 2 1", "output": "2\n-\n2\n+"}, {"input": "6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3", "output": "6\n++-\n2\n+-+"}]
1,900
["dfs and similar", "graphs"]
141
[{"input": "2 2 1\r\n1 1 2\r\n2 2 1\r\n", "output": "2\r\n-\r\n2\r\n+\r\n"}, {"input": "6 6 3\r\n2 2 6\r\n1 4 5\r\n2 3 4\r\n1 4 1\r\n1 3 1\r\n2 2 3\r\n", "output": "6\r\n++-\r\n2\r\n+-+\r\n"}, {"input": "5 5 5\r\n2 5 3\r\n1 2 3\r\n1 4 5\r\n2 5 2\r\n1 2 1\r\n", "output": "4\r\n++\r\n1\r\n--\r\n"}, {"input": "13 18 9\r\n...
false
stdio
import sys from collections import deque 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, m, s = map(int, f.readline().split()) all_edges = [] for _ in range(m): ti, u, v = m...
true
70/B
70
B
PyPy 3
TESTS
45
155
1,638,400
60753699
class CodeforcesTask70BSolution: def __init__(self): self.result = '' self.n = 0 self.message = '' def read_input(self): self.n = int(input()) self.message = input() def process_task(self): sentences = [] s = '' for x in range(len(self.messag...
48
109
21,504,000
130830768
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)): if len(a[i]) > n: print('Impossible') exit(0) add = len(a[i]) + 1 if i + 1 ...
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
289/A
289
A
PyPy 3-64
TESTS
22
686
5,836,800
213904305
n, k = map(int, input().split()) p = 0 for i in range(n): l, r = map(int, input().split()) p += (r - l + 1) print(0 if not(k % p) else (k - (p % k)) % k)
28
218
0
216990434
from sys import stdin ,stdout input=stdin.readline inp = lambda : map(int,input().split()) def print(*args, end='\n', sep=' ') -> None: stdout.write(sep.join(map(str, args)) + end) a,b=inp() n=0 for i in range(a): c,d=inp() if c==d: n+=1 elif d-c==1: n+=2 elif d > c: n+...
Codeforces Round 177 (Div. 2)
CF
2,013
2
256
Polo the Penguin and Segments
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the r...
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequal...
In a single line print a single integer — the answer to the problem.
null
null
[{"input": "2 3\n1 2\n3 4", "output": "2"}, {"input": "3 7\n1 2\n3 3\n4 7", "output": "0"}]
1,100
["brute force", "implementation"]
28
[{"input": "2 3\r\n1 2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "3 7\r\n1 2\r\n3 3\r\n4 7\r\n", "output": "0\r\n"}, {"input": "3 7\r\n1 10\r\n11 47\r\n74 128\r\n", "output": "3\r\n"}, {"input": "5 4\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n", "output": "3\r\n"}, {"input": "7 4\r\n2 2\r\n-1 -1\r\n0 1\r\n7 8\r\n-3 -2\r\n9...
false
stdio
null
true
288/E
288
E
PyPy 3-64
TESTS
9
124
28,774,400
225464233
# Utility Functions def int_to_modified_binary(number:str)->str: ''' Convert to a special binary representation where 4 = 0 and 7 = 1 ''' modified_binary = "" for digit in number: if digit == "4": modified_binary += "0" else: modified_binary += "1" return ...
52
622
85,196,800
225501681
mod = 1000000007 N = 100000 two = [0] * (N + 1) ten = [0] * (N + 1) four = [0] * (N + 1) seven = [0] * (N + 1) prod = [0] * (N + 1) sum_val = [0] * (N + 1) Prod = [0] * (N + 1) lar = [0] * (N + 1) dp = [[False, False] for _ in range(N + 1)] pa = [[-1, -1] for _ in range(N + 1)] def init(): two[0] = ten[0] = 1 ...
Codeforces Round 177 (Div. 1)
CF
2,013
2
256
Polo the Penguin and Lucky Numbers
Everybody knows that lucky numbers are positive integers that contain only lucky digits 4 and 7 in their decimal representation. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Polo the Penguin have two positive integers l and r (l < r), both of them are lucky numbers. Moreover, their lengths (that i...
The first line contains a positive integer l, and the second line contains a positive integer r (1 ≤ l < r ≤ 10100000). The numbers are given without any leading zeroes. It is guaranteed that the lengths of the given numbers are equal to each other and that both of them are lucky numbers.
In the single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
null
null
[{"input": "4\n7", "output": "28"}, {"input": "474\n777", "output": "2316330"}]
2,800
["dp", "implementation", "math"]
52
[{"input": "4\r\n7\r\n", "output": "28\r\n"}, {"input": "474\r\n777\r\n", "output": "2316330\r\n"}, {"input": "44\r\n77\r\n", "output": "11244\r\n"}, {"input": "444\r\n777\r\n", "output": "2726676\r\n"}, {"input": "444\r\n477\r\n", "output": "636444\r\n"}, {"input": "444\r\n744\r\n", "output": "991332\r\n"}, {"input": ...
false
stdio
null
true
288/E
288
E
PyPy 3-64
TESTS
9
122
31,027,200
225458050
number1 = int(input()) number2 = int(input()) list_number = [] buffer = 0 for number in range(number1, number2+1): if "0" in str(number): continue elif "1" in str(number): continue elif "2" in str(number): continue elif "3" in str(number): continue elif "5" in str(n...
52
622
85,196,800
225501681
mod = 1000000007 N = 100000 two = [0] * (N + 1) ten = [0] * (N + 1) four = [0] * (N + 1) seven = [0] * (N + 1) prod = [0] * (N + 1) sum_val = [0] * (N + 1) Prod = [0] * (N + 1) lar = [0] * (N + 1) dp = [[False, False] for _ in range(N + 1)] pa = [[-1, -1] for _ in range(N + 1)] def init(): two[0] = ten[0] = 1 ...
Codeforces Round 177 (Div. 1)
CF
2,013
2
256
Polo the Penguin and Lucky Numbers
Everybody knows that lucky numbers are positive integers that contain only lucky digits 4 and 7 in their decimal representation. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Polo the Penguin have two positive integers l and r (l < r), both of them are lucky numbers. Moreover, their lengths (that i...
The first line contains a positive integer l, and the second line contains a positive integer r (1 ≤ l < r ≤ 10100000). The numbers are given without any leading zeroes. It is guaranteed that the lengths of the given numbers are equal to each other and that both of them are lucky numbers.
In the single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
null
null
[{"input": "4\n7", "output": "28"}, {"input": "474\n777", "output": "2316330"}]
2,800
["dp", "implementation", "math"]
52
[{"input": "4\r\n7\r\n", "output": "28\r\n"}, {"input": "474\r\n777\r\n", "output": "2316330\r\n"}, {"input": "44\r\n77\r\n", "output": "11244\r\n"}, {"input": "444\r\n777\r\n", "output": "2726676\r\n"}, {"input": "444\r\n477\r\n", "output": "636444\r\n"}, {"input": "444\r\n744\r\n", "output": "991332\r\n"}, {"input": ...
false
stdio
null
true
186/B
186
B
Python 3
TESTS
9
1,090
6,963,200
84914408
st1= input() t=st1.split(" ") n=int(t[0]) t1=int(t[1]) t2=int(t[2]) k=int(t[3]) inp=[] out=[] rak=[] for i in range(n): st2= input() st=st2.split(" ") a=int(st[0]) b=int(st[1]) z1=((t1*a)*(100-k)/100)+(t2*b) z2=((t1*b)*(100-k)/100)+(t2*a) if(z1>z2): out.append(z1) else: out.append(z2) for i in range(n): rk...
36
92
0
163449265
n, t1, t2, k = map(int,input().split()) dwarfs = [] for i in range(n): v,u = tuple(map(int,input().split())) first = t1*v second = t2*u s1 = first - (first*k/100) +second first = t1*u second = t2*v s2 = first - (first*k/100) +second dwarfs.append((i+1,max([s1,s2]))) dwarfs.sort(key= lambda x : x[1],reve...
Codeforces Round 118 (Div. 2)
CF
2,012
2
256
Growing Mushrooms
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules ...
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly. Each of the following n lines contains two inte...
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
null
- First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
[{"input": "2 3 3 50\n2 4\n4 2", "output": "1 15.00\n2 15.00"}, {"input": "4 1 1 1\n544 397\n280 101\n280 101\n693 970", "output": "4 1656.07\n1 937.03\n2 379.99\n3 379.99"}]
1,200
["greedy", "sortings"]
36
[{"input": "2 3 3 50\r\n2 4\r\n4 2\r\n", "output": "1 15.00\r\n2 15.00\r\n"}, {"input": "4 1 1 1\r\n544 397\r\n280 101\r\n280 101\r\n693 970\r\n", "output": "4 1656.07\r\n1 937.03\r\n2 379.99\r\n3 379.99\r\n"}, {"input": "10 1 1 25\r\n981 1\r\n352 276\r\n164 691\r\n203 853\r\n599 97\r\n901 688\r\n934 579\r\n910 959\r\n...
false
stdio
null
true
883/I
883
I
Python 3
TESTS
6
109
307,200
97719479
n, k = map(int, input().split()) arr = sorted(map(int, input().split())) m = 0 if len(arr) % k == 0: for i in range(0, n, k): m = max(m, arr[i + k - 1] - arr[i]) else: for i in range(0, (n // k - 1) * k, k): m = max(m, arr[i + k - 1] - arr[i]) m = max(m, arr[-1] - arr[(n // k - 1) * k]) prin...
70
935
49,459,200
205436774
from bisect import bisect_left, bisect_right from collections import Counter, deque from functools import lru_cache from math import factorial, comb, sqrt, gcd, lcm, log2 from copy import deepcopy import heapq from sys import stdin, stdout input = stdin.readline def main(): n, k = map(int, input().split()) ...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Photo Processing
Evlampiy has found one more cool application to process photos. However the application has certain limitations. Each photo i has a contrast vi. In order for the processing to be truly of high quality, the application must receive at least k photos with contrasts which differ as little as possible. Evlampiy already k...
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — number of photos and minimum size of a group. The second line contains n integers v1, v2, ..., vn (1 ≤ vi ≤ 109), where vi is the contrast of the i-th photo.
Print the minimal processing time of the division into groups.
null
In the first example the photos should be split into 2 groups: [40, 50] and [110, 120, 130]. The processing time of the first group is 10, and the processing time of the second group is 20. Maximum among 10 and 20 is 20. It is impossible to split the photos into groups in a such way that the processing time of division...
[{"input": "5 2\n50 110 130 40 120", "output": "20"}, {"input": "4 1\n2 3 4 1", "output": "0"}]
1,900
["binary search", "dp"]
70
[{"input": "5 2\r\n50 110 130 40 120\r\n", "output": "20\r\n"}, {"input": "4 1\r\n2 3 4 1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n4\r\n", "output": "0\r\n"}, {"input": "2 2\r\n7 5\r\n", "output": "2\r\n"}, {"input": "3 2\r\n34 3 75\r\n", "output": "72\r\n"}, {"input": "5 2\r\n932 328 886 96 589\r\n", "output": "343...
false
stdio
null
true
177/E1
177
E1
Python 3
TESTS1
3
124
0
21124891
I=lambda:map(int,input().split()) n,c=I() a,b=[],[] for _ in range(n):x,y=I();a.append(x);b.append(y) f=lambda x:sum(1+a[i]*x//b[i] for i in range(n)) l=-1 r=10**9 while l<r-1: m=(l+r)//2 if f(m)<c:l=m else:r=m L=r l=-1 r=10**9 while l<r-1: m=(l+r)//2 if f(m)<=c:l=m else:r=m print(r-L)
21
186
307,200
75786512
# ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code def main(): n , c = map(int , input().split()) data = [] for i in range(n): a,b = map(int...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Space Voyage
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
The first input line contains space-separated integers n and c — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly. The next n lines contain pairs of space-separated integers ai, bi (1 ≤ i ≤ n) — the number of suitcases he can bring to the i-...
Print a single number k — the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
null
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days...
[{"input": "2 5\n1 5\n2 4", "output": "1"}]
1,700
["binary search"]
21
[{"input": "2 5\r\n1 5\r\n2 4\r\n", "output": "1\r\n"}, {"input": "1 97\r\n1 91\r\n", "output": "91\r\n"}, {"input": "2 79\r\n1 91\r\n1 77\r\n", "output": "42\r\n"}, {"input": "3 100\r\n8 46\r\n8 56\r\n77 98\r\n", "output": "1\r\n"}, {"input": "7 77\r\n2 95\r\n2 91\r\n3 95\r\n2 94\r\n3 96\r\n2 97\r\n2 91\r\n", "output"...
false
stdio
null
true
177/C1
177
C2
PyPy 3-64
TESTS2
3
124
0
224693979
def solve(): n = int(input()) k = int(input()) parent = [i for i in range(n+5)] count = [1]*(n+5) rank = [0]*(n+5) def find(x,parent): if x!=parent[x]: parent[x] = find(parent[x],parent) return parent[x] def union(x,y,parent,rank,count): if rank[x]>rank[y]: parent[y] = x count[x]+=count[y] elif ...
17
124
2,048,000
175831976
import sys input = sys.stdin.readline from collections import Counter n = int(input()) k = int(input()) d = [[] for i in range(n)] for i in range(k): a, b = map(lambda x:int(x)-1, input().split()) d[a].append(b) d[b].append(a) x = [-1]*n c = 0 for i in range(n): if x[i] == -1: q = [i] w...
ABBYY Cup 2.0 - Easy
ICPC
2,012
2
256
Party
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends...
The first line of input contains an integer n — the number of the Beaver's acquaintances. The second line contains an integer k $$( 0 \leq k \leq \min ( 1 0 ^ { 5 }, \frac { n \cdot ( n - 1 ) } { 2 } ) )$$ — the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi $$( 1 \leq u _ { ...
Output a single number — the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0.
null
Let's have a look at the example. Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members a...
[{"input": "9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9", "output": "3"}]
1,500
["dfs and similar", "dsu", "graphs"]
17
[{"input": "9\r\n8\r\n1 2\r\n1 3\r\n2 3\r\n4 5\r\n6 7\r\n7 8\r\n8 9\r\n9 6\r\n2\r\n1 6\r\n7 9\r\n", "output": "3"}, {"input": "2\r\n1\r\n1 2\r\n0\r\n", "output": "2"}, {"input": "2\r\n0\r\n1\r\n1 2\r\n", "output": "1"}, {"input": "3\r\n2\r\n1 2\r\n1 3\r\n1\r\n2 3\r\n", "output": "0"}, {"input": "3\r\n3\r\n1 3\r\n2 1\r\...
false
stdio
null
true
289/B
289
B
Python 3
TESTS
29
154
307,200
109774879
n,m,d=map(int,input().split()) a=[] ans=0 for i in range(n): a+=list(map(int,input().split())) a.sort() mid=a[len(a)//2] for i in range(len(a)): x=abs(mid-a[i]) if x%d!=0: print(-1) break else: ans+=x//d if i==len(a)-1: print(ans)
31
92
0
136156526
n,m,d = map(int,input().split()) a = [] s = set() for i in range(n): a += list(map(int,input().split())) a.sort() mid = a[len(a)//2] ans = 0 flag = True for i in a: x = abs(i-mid) if x % d!=0: print(-1) flag = False break ans += x//d if flag: print(ans)
Codeforces Round 177 (Div. 2)
CF
2,013
2
256
Polo the Penguin and Matrix
Little penguin Polo has an n × m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of row i and column j as aij. In one move the penguin can add or subtract number...
The first line contains three integers n, m and d (1 ≤ n, m ≤ 100, 1 ≤ d ≤ 104) — the matrix sizes and the d parameter. Next n lines contain the matrix: the j-th integer in the i-th row is the matrix element aij (1 ≤ aij ≤ 104).
In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).
null
null
[{"input": "2 2 2\n2 4\n6 8", "output": "4"}, {"input": "1 2 7\n6 7", "output": "-1"}]
1,400
["brute force", "dp", "implementation", "sortings", "ternary search"]
31
[{"input": "2 2 2\r\n2 4\r\n6 8\r\n", "output": "4\r\n"}, {"input": "1 2 7\r\n6 7\r\n", "output": "-1\r\n"}, {"input": "3 2 1\r\n5 7\r\n1 2\r\n5 100\r\n", "output": "104\r\n"}, {"input": "3 3 3\r\n5 8 5\r\n11 11 17\r\n14 5 2\r\n", "output": "12\r\n"}, {"input": "3 3 3\r\n5 8 5\r\n11 11 17\r\n14 5 3\r\n", "output": "-1\...
false
stdio
null
true
356/C
356
C
PyPy 3
TESTS
0
124
0
42816114
import math def cdif(a,b,n): c = 0 for i in range(n): if a[i] != b[i]: c += 1 return c def bal(a,n): c = sum(a) t = [0]*n while c>0: for i in range(n): t[i] += 1 c -= 1 if c==0: return t return t n = int(input...
141
607
14,745,600
42135284
#! /usr/bin/env python n = int(input()) counts = [0] * 5 nums = [int(x) for x in input().split()] for x in nums: counts[x] += 1 s = sum(nums) if s > 2 and s != 5: ans = 0 if counts[1] >= counts[2]: ans += counts[2] counts[3] += counts[2] counts[1] -= counts[2] ans += 2 * (c...
Codeforces Round 207 (Div. 1)
CF
2,013
1
256
Compartments
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ge...
The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.
If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.
null
null
[{"input": "5\n1 2 2 4 3", "output": "2"}, {"input": "3\n4 1 1", "output": "2"}, {"input": "4\n0 3 0 4", "output": "0"}]
2,100
["combinatorics", "constructive algorithms", "greedy", "implementation"]
141
[{"input": "5\r\n1 2 2 4 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n0 3 0 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 4\r\n", "output": "1\r\n"}, {"input": "10\r\n2 1 2 3 4 1 3 4 4 4\r\n", "output": "2\r\n"}, {"...
false
stdio
null
true
358/B
358
B
PyPy 3-64
TESTS
11
187
8,396,800
150333176
n = int(input()) k = [] for i in range(n): a = input() k.append(a) l = 0 r = 0 a1 = 0 a2 = 0 p = 0 s1 = input() for i in range(len(s1)): if (r < len(k) and s1[i] == k[r][l]): if l == len(k[r]) - 1: if (a1 > 0 and a2 > 0): p += 1 a1 = 0 a2 =...
30
109
921,600
143292205
import sys n = int(sys.stdin.readline().rstrip("\n")) message = "<3" for i in range(n): x = sys.stdin.readline().rstrip("\n") message += x + "<3" sent = sys.stdin.readline().rstrip("\n") ind = 0 correct = False for i in sent: if i == message[ind]: ind += 1 if ind >= len(message): correct...
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Text Messages
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The numbe...
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
null
Please note that Dima got a good old kick in the pants for the second sample from the statement.
[{"input": "3\ni\nlove\nyou\n<3i<3love<23you<3", "output": "yes"}, {"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3", "output": "no"}]
1,500
["brute force", "strings"]
30
[{"input": "3\r\ni\r\nlove\r\nyou\r\n<3i<3love<23you<3\r\n", "output": "yes\r\n"}, {"input": "7\r\ni\r\nam\r\nnot\r\nmain\r\nin\r\nthe\r\nfamily\r\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\r\n", "output": "no\r\n"}, {"input": "3\r\ni\r\nlove\r\nyou\r\n<3i<3lo<3ve<3y<<<<<<<ou3<3\r\n", "output": "yes\r\n"}, {"input": "...
false
stdio
null
true
183/B
183
B
Python 3
TESTS
2
186
6,963,200
90787731
n,m=list(map(int,input().split(" "))) liste=[] for _ in range(m): x,y=list(map(int,input().split(" "))) liste.append((x,y)) visited=[0 for i in range(1,n+1)] count=0 for i in range(m-1): for j in range(i+1,m): x1,y1=liste[i] x2,y2=liste[j] if x1==x2: for k in range(m):...
81
1,652
18,432,000
42123675
from ctypes import c_int32 def gcd(a,b): if b == 0: return a return gcd(b, a % b) def normalize_rational(num,den): #associate the -ve with the num or cancel -ve sign when both are -ve if num ^ den < 0 and num > 0 or num ^ den > 0 and num < 0: num = -num; den = -den #pu...
Croc Champ 2012 - Final
CF
2,012
2
256
Zoo
The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has n observation binoculars located at the OX axis. For each i between 1 and n, inclusive, there exists a single binocular located at the point with coordinates (i, 0). There are m flamingos in the Zoo, located at points with positive coordinates....
The first line contains two space-separated integers n and m (1 ≤ n ≤ 106, 1 ≤ m ≤ 250), denoting the number of binoculars and the number of flamingos, respectively. Then m lines follow, the i-th line will contain two space-separated integers xi and yi (1 ≤ xi, yi ≤ 109), which means that the i-th flamingo is located ...
Print a single integer denoting the maximum total number of flamingos that can be seen by all the binoculars.
null
This picture shows the answer to the example test case.
[{"input": "5 5\n2 1\n4 1\n3 2\n4 3\n4 4", "output": "11"}]
1,700
["brute force", "geometry"]
81
[{"input": "5 5\r\n2 1\r\n4 1\r\n3 2\r\n4 3\r\n4 4\r\n", "output": "11\r\n"}, {"input": "3 3\r\n1 1\r\n2 10\r\n3 100\r\n", "output": "3\r\n"}, {"input": "1 2\r\n450000001 500000000\r\n900000001 1000000000\r\n", "output": "2\r\n"}, {"input": "3 6\r\n1 1\r\n1 2\r\n1 3\r\n2 1\r\n2 2\r\n3 1\r\n", "output": "7\r\n"}, {"inpu...
false
stdio
null
true
609/A
609
A
PyPy 3
TESTS
5
139
0
91300844
n = int(input()) m = int(input()) l=[] for i in range(n): a = int(input()) l.append(a) l.sort(reverse=True) s = 0 for i in l: while(m>=0): m = m-i s = s + 1 print(s)
34
46
0
137873861
n = int(input()) m = int(input()) a = [] for i in range(n): a.append(int(input())) a.sort(reverse = True) i = 0 while(i < n and m > 0): m -= a[i] i += 1 print(i)
Educational Codeforces Round 3
ICPC
2,015
2
256
USB Flash Drives
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives. The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file. Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the...
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
null
In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
[{"input": "3\n5\n2\n1\n3", "output": "2"}, {"input": "3\n6\n2\n3\n2", "output": "3"}, {"input": "2\n5\n5\n10", "output": "1"}]
800
["greedy", "implementation", "sortings"]
34
[{"input": "3\r\n5\r\n2\r\n1\r\n3\r\n", "output": "2\r\n"}, {"input": "3\r\n6\r\n2\r\n3\r\n2\r\n", "output": "3\r\n"}, {"input": "2\r\n5\r\n5\r\n10\r\n", "output": "1\r\n"}, {"input": "5\r\n16\r\n8\r\n1\r\n3\r\n4\r\n9\r\n", "output": "2\r\n"}, {"input": "10\r\n121\r\n10\r\n37\r\n74\r\n56\r\n42\r\n39\r\n6\r\n68\r\n8\r\n...
false
stdio
null
true
501/C
501
C
PyPy 3
TESTS
2
124
0
81984670
n = int(input()) d = [] v = [] for i in range(n): (a, b) = map(int, input().split()) d.append([a, b, i]) v.append([a, b, i]) d.sort() ans = [] for i in d: a = i[2] if v[a][0] > 0: b = v[a][1] v[b][1] ^= a v[b][0] -= 1 ans.append((a,b)) print(len(ans)) for i in ans: ...
49
233
23,449,600
205682949
# compiler on CodeForces: PyPy 3 64bit import sys from collections import defaultdict input = lambda: sys.stdin.readline()[:-1] print = lambda *args: sys.stdout.write(' '.join(map(str, args)) + '\n') graph = defaultdict(dict) x = [] queue = [] n = int(input()) for i in range(n): degree, xor_sum = [int(e) for e in...
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
471/B
471
B
PyPy 3
TESTS
5
124
0
64058062
n = int(input()) a = list(map(int, input().split())) d = {} for i in range(n): if d.get(a[i]): d[a[i]].append(i + 1) else: d[a[i]] = [i + 1] k = 1 for i in sorted(d.keys()): k *= len(d[i]) if k < 3: print("NO") else: print("YES") for i in sorted(d.keys()): print(' '.join(...
31
62
409,600
9925032
n = int(input()) m = list(map(int, input().split())) u = {} for i, v in enumerate(m): if not v in u: u[v] = [] u[v].append(i+1) d = [] for i in u: m1 = u[i] d.append([i, m1, len(m1)]) d = sorted(d, key=lambda x: x[0]) pos = 1 s1 = [] s2 = [] s3 = [] for val in d: l = val[1] if po...
Codeforces Round 269 (Div. 2)
CF
2,014
1
256
MUH and Important Things
It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are n tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order...
The first line contains integer n (1 ≤ n ≤ 2000) — the number of tasks. The second line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 2000), where hi is the difficulty of the i-th task. The larger number hi is, the more difficult the i-th task is.
In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line n distinct integers that represent the numbers of the tasks in the order t...
null
In the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer. In the second sample there are only tw...
[{"input": "4\n1 3 3 1", "output": "YES\n1 4 2 3\n4 1 2 3\n4 1 3 2"}, {"input": "5\n2 4 1 4 8", "output": "NO"}]
1,300
["implementation", "sortings"]
31
[{"input": "4\r\n1 3 3 1\r\n", "output": "YES\r\n1 4 2 3 \r\n4 1 2 3 \r\n4 1 3 2 \r\n"}, {"input": "5\r\n2 4 1 4 8\r\n", "output": "NO"}, {"input": "8\r\n1 5 4 12 7 2 10 11\r\n", "output": "NO"}, {"input": "6\r\n5 1 2 5 2 4\r\n", "output": "YES\r\n2 3 5 6 1 4 \r\n2 5 3 6 1 4 \r\n2 5 3 6 4 1 \r\n"}, {"input": "1\r\n1083...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return [line.strip() for line in f.readlines()] def main(input_path, output_path, submission_path): input_lines = read_file(input_path) n = int(input_lines[0]) h = list(map(int, input_lines[1].split())) ref_lines = read_file(output...
true
359/C
359
C
PyPy 3
TESTS
7
311
38,297,600
88768710
from collections import Counter n, x = map(int,input().split()) ct = Counter(map(int,input().split())) s = sum([v*ct[v] for v in ct.keys()]) def f(v,x): k = 0 while v%x == 0: k += 1 v //= x return k print(pow(x,min([s-v+f(ct[v],x) for v in ct.keys()]),10**9+7))
36
202
18,227,200
123704278
# Online Python - IDE, Editor, Compiler, Interpreter import os import statistics if __name__ == "__main__": str1 = input() n = int(str1.split()[0]) x = int(str1.split()[1]) str2 = input() a = str2.split() s = 0 maxX = 0 a = list(map(int, a)) for i in range(0,n): s ...
Codeforces Round 209 (Div. 2)
CF
2,013
1
256
Prime Number
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fractions very much. Today he wrote out number $$\frac{1}{x^{a_1}} + \frac{1}{x^{a_2}} + \ldots + \frac{1}{x^{a_n}}$$ on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fra...
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
null
In the first sample $$\frac{1}{4} + \frac{1}{4} = \frac{4+4}{16} = \frac{8}{16}$$. Thus, the answer to the problem is 8. In the second sample, $$\frac{1}{3}+\frac{1}{9}+\frac{1}{27}=\frac{243+81+27}{729}=\frac{351}{729}$$. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27. In the third sample the answer to...
[{"input": "2 2\n2 2", "output": "8"}, {"input": "3 3\n1 2 3", "output": "27"}, {"input": "2 2\n29 29", "output": "73741817"}, {"input": "4 5\n0 0 0 0", "output": "1"}]
1,900
["math", "number theory"]
36
[{"input": "2 2\r\n2 2\r\n", "output": "8\r\n"}, {"input": "3 3\r\n1 2 3\r\n", "output": "27\r\n"}, {"input": "2 2\r\n29 29\r\n", "output": "73741817\r\n"}, {"input": "4 5\r\n0 0 0 0\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "26 2\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
false
stdio
null
true
359/C
359
C
PyPy 3
TESTS
7
249
14,028,800
102175519
def extractPow(x,p): count=0 while x>0 and x%p==0: x=x//p count+=1 return count def calc(n,k,a): sTot=sum(a) biggest=max(a) m=10**9+7 ans=pow(k,sTot-biggest,m) dic={} for i,item in enumerate(a): if item not in dic: dic[item]=1 else: ...
36
233
8,908,800
44268049
modulus = 10 ** 9 + 7 def main(): n, x = map(int, input().split()) arr = list(map(int, input().split())) total = sum(arr) powers = [total - x for x in arr] powers.sort(reverse=True) while True: low = powers[len(powers) - 1] cnt = 0 while len(powers) > 0 and powers[...
Codeforces Round 209 (Div. 2)
CF
2,013
1
256
Prime Number
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fractions very much. Today he wrote out number $$\frac{1}{x^{a_1}} + \frac{1}{x^{a_2}} + \ldots + \frac{1}{x^{a_n}}$$ on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fra...
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
null
In the first sample $$\frac{1}{4} + \frac{1}{4} = \frac{4+4}{16} = \frac{8}{16}$$. Thus, the answer to the problem is 8. In the second sample, $$\frac{1}{3}+\frac{1}{9}+\frac{1}{27}=\frac{243+81+27}{729}=\frac{351}{729}$$. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27. In the third sample the answer to...
[{"input": "2 2\n2 2", "output": "8"}, {"input": "3 3\n1 2 3", "output": "27"}, {"input": "2 2\n29 29", "output": "73741817"}, {"input": "4 5\n0 0 0 0", "output": "1"}]
1,900
["math", "number theory"]
36
[{"input": "2 2\r\n2 2\r\n", "output": "8\r\n"}, {"input": "3 3\r\n1 2 3\r\n", "output": "27\r\n"}, {"input": "2 2\r\n29 29\r\n", "output": "73741817\r\n"}, {"input": "4 5\r\n0 0 0 0\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "26 2\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
false
stdio
null
true
5/E
5
E
PyPy 3-64
TESTS
8
122
0
181058659
n,ans=int(input()),0 s=list(map(int,input().split()))*2#数据输入,s*2实现“一圈”式的搜索 ans+=n d=[]#存储配对的山峰序号组 #相邻两座山之间都能看见 #1 2 4 5 3||1 2 4 5 3 满足条件的子序列必然是先减后增,且中间所有值都小于端点值 #上述3 4构成子序列[3,1,2,4]可以相互看见,3 2构成子序列[3,1,2]可以相互看见 if n>=3: #s=1 2 4 5 3||1 2 4 5 3 for i in range(n): lef=s[i] rig=s[i+1] if lef>=rig:#右侧高于...
46
934
139,059,200
181279880
n,maxn,maxn_index=int(input()),0,0 s=list(map(int,input().split()))*2 L,R,C=[0]*1000007,[0]*1000007,[0]*1000007#L,R存储编号,C存储数值 #L[i]表示i左侧比第一个比i高(或等)的位置。 #R[i]表示i右侧第一个比i高(或等)的位置。 #C[i]表示从i到R[i]的左开右闭区间内高度等于i的山的数目 for i in range(len(s)//2): if s[i]>maxn: maxn=s[i] maxn_index=i s_new=s[maxn_index:maxn_in...
Codeforces Beta Round 5
ICPC
2,010
4
256
Bindian Signalizing
Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by n hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night. In case of any danger the watchman could make a fire on the hill. One watchman coul...
The first line of the input data contains an integer number n (3 ≤ n ≤ 106), n — the amount of hills around the capital. The second line contains n numbers — heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 109.
Print the required amount of pairs.
null
null
[{"input": "5\n1 2 4 5 3", "output": "7"}]
2,400
["data structures"]
46
[{"input": "5\r\n1 2 4 5 3\r\n", "output": "7\r\n"}, {"input": "3\r\n2118 2118 2118\r\n", "output": "3\r\n"}, {"input": "3\r\n2221 1976 2221\r\n", "output": "3\r\n"}, {"input": "3\r\n140 989 2895\r\n", "output": "3\r\n"}, {"input": "4\r\n2440 2440 2440 2440\r\n", "output": "6\r\n"}, {"input": "4\r\n1178 1178 2577 2577\...
false
stdio
null
true
496/D
496
D
Python 3
TESTS
10
1,996
512,000
12890633
import math n = int(input()) games = list(map(int, input().split())) PETYA = 0 GENA = 1 pontos = [[0], [0]] for i in range(0, n): if (games[i] == 1): pontos[PETYA].append(pontos[PETYA][i] + 1) pontos[GENA].append(pontos[GENA][i]) else: pontos[PETYA].append(pontos[PETYA][i]) pontos[GENA].append(pontos[GENA...
53
1,372
10,649,600
9303276
#!/usr/bin/env python3 import itertools n = int(input()) a = [int(x) for x in input().split()] winner = a[-1] looser = 3 - winner serve_win_cnt, serve_loose_cnt, win_pos, loose_pos, result = [0], [0], [-1], [-1], [] win_cnt = a.count(winner) for i in range(n): if a[i] == winner: win_pos.append(i) el...
Codeforces Round 283 (Div. 2)
CF
2,014
2
256
Tennis Game
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the ne...
The first line contains a single integer n — the length of the sequence of games (1 ≤ n ≤ 105). The second line contains n space-separated integers ai. If ai = 1, then the i-th serve was won by Petya, if ai = 2, then the i-th serve was won by Gena. It is not guaranteed that at least one option for numbers s and t cor...
In the first line print a single number k — the number of options for numbers s and t. In each of the following k lines print two integers si and ti — the option for numbers s and t. Print the options in the order of increasing si, and for equal si — in the order of increasing ti.
null
null
[{"input": "5\n1 2 1 2 1", "output": "2\n1 3\n3 1"}, {"input": "4\n1 1 1 1", "output": "3\n1 4\n2 2\n4 1"}, {"input": "4\n1 2 1 2", "output": "0"}, {"input": "8\n2 1 2 1 1 1 1 1", "output": "3\n1 6\n2 3\n6 1"}]
1,900
["binary search"]
53
[{"input": "5\r\n1 2 1 2 1\r\n", "output": "2\r\n1 3\r\n3 1\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "3\r\n1 4\r\n2 2\r\n4 1\r\n"}, {"input": "4\r\n1 2 1 2\r\n", "output": "0\r\n"}, {"input": "8\r\n2 1 2 1 1 1 1 1\r\n", "output": "3\r\n1 6\r\n2 3\r\n6 1\r\n"}, {"input": "14\r\n2 1 2 1 1 1 1 2 1 1 2 1 2 1\r\n", "o...
false
stdio
null
true
358/B
358
B
PyPy 3-64
TESTS
8
61
2,662,400
150329842
n=int(input()) k=[] for i in range(n): a=input() k.append(a) l=0 r=0 a1=0 a2=0 p=0 s1=input() for i in range(len(s1)): if (r<len(k) and s1[i]==k[r][l]): if l==0: if (a1<1 or a2<1): p+=1 break if l==len(k[r])-1: l=0 r+=1 ...
30
124
1,433,600
143527646
import sys import re n = int(sys.stdin.readline()[:-1]) words = "" for i in range(n): words += "<3" + sys.stdin.readline()[:-1] words += "<3" line = sys.stdin.readline()[:-1].lower() s = 0 for i in range(len(line)): if(line[i] == words[s]): s+=1 if(s >= len(words)): break if(s == len(words)): print("yes") e...
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Text Messages
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The numbe...
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
null
Please note that Dima got a good old kick in the pants for the second sample from the statement.
[{"input": "3\ni\nlove\nyou\n<3i<3love<23you<3", "output": "yes"}, {"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3", "output": "no"}]
1,500
["brute force", "strings"]
30
[{"input": "3\r\ni\r\nlove\r\nyou\r\n<3i<3love<23you<3\r\n", "output": "yes\r\n"}, {"input": "7\r\ni\r\nam\r\nnot\r\nmain\r\nin\r\nthe\r\nfamily\r\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\r\n", "output": "no\r\n"}, {"input": "3\r\ni\r\nlove\r\nyou\r\n<3i<3lo<3ve<3y<<<<<<<ou3<3\r\n", "output": "yes\r\n"}, {"input": "...
false
stdio
null
true
358/B
358
B
PyPy 3-64
TESTS
11
1,980
14,540,800
152568019
t='' for i in range(int(input())): a= input() t+='<3'+a t=list(t) p= list(input()) h=0 while p: a = p.pop(0) if not t: print('yes') h+=1 break if a==t[0]: t.pop(0) if h==0: print('no')
30
139
1,638,400
179448972
t = '<3' + '<3'.join(input() for i in range(int(input()))) + '<3' p=input() s="yes" j=0 for c in t: j = p.find(c, j)+1 if j == 0: s = 'no' break print(s)
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Text Messages
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The numbe...
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
null
Please note that Dima got a good old kick in the pants for the second sample from the statement.
[{"input": "3\ni\nlove\nyou\n<3i<3love<23you<3", "output": "yes"}, {"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3", "output": "no"}]
1,500
["brute force", "strings"]
30
[{"input": "3\r\ni\r\nlove\r\nyou\r\n<3i<3love<23you<3\r\n", "output": "yes\r\n"}, {"input": "7\r\ni\r\nam\r\nnot\r\nmain\r\nin\r\nthe\r\nfamily\r\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\r\n", "output": "no\r\n"}, {"input": "3\r\ni\r\nlove\r\nyou\r\n<3i<3lo<3ve<3y<<<<<<<ou3<3\r\n", "output": "yes\r\n"}, {"input": "...
false
stdio
null
true
108/B
108
B
Python 3
TESTS
60
248
7,782,400
39041012
n = (int)(input()) a = list(map(int,input().split())) s = set(a) fmax = max(s) s.remove(fmax) smax = max(s) if fmax >= 2 * smax: print ('NO') else: print ('YES')
65
218
18,739,200
178676323
n = int(input()) nums = list(set(map(int, input().split()))) nums.sort() java_is_weird = False for i in range(len(nums)-1): if nums[i] > nums[i+1] // 2: java_is_weird = True break print("YES") if java_is_weird else print("NO")
Codeforces Beta Round 83 (Div. 2 Only)
CF
2,011
2
256
Datatypes
Tattah's youngest brother, Tuftuf, is new to programming. Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava. Today, Tuftuf was introduced to Gava's unsigned integer datatypes. G...
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
null
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
[{"input": "3\n64 16 32", "output": "NO"}, {"input": "4\n4 2 1 3", "output": "YES"}]
1,400
["math", "sortings"]
65
[{"input": "3\r\n64 16 32\r\n", "output": "NO\r\n"}, {"input": "4\r\n4 2 1 3\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 5 3 3 2\r\n", "output": "YES\r\n"}, {"input": "52\r\n474 24 24 954 9 234 474 114 24 114 234 24 114 114 234 9 9 24 9 54 234 54 9 954 474 9 54 54 54 234 9 114 24 54 114 954 954 474 24 54 54 234 234 4...
false
stdio
null
true
667/B
667
B
Python 3
TESTS
40
139
2,764,800
65499004
def arr_inp(): return [int(x) for x in input().split()] n=int(input()) a=arr_inp() s1=max(a) a.remove(s1) s2=sum(a) if(s1==s2): print(s1-1) else: print(max(s1,s2)-min(s1,s2)+1)
51
62
2,662,400
157956683
import sys input = sys.stdin.readline n = int(input()) w = sorted(map(int, input().split())) a = sum(w[:-1]) if a <= w[-1]: print(w[-1]-a+1) else: print(0)
Codeforces Round 349 (Div. 2)
CF
2,016
1
256
Coat of Anticubism
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore. A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-d...
The first line contains an integer n (3 ≤ n ≤ 105) — a number of rod-blanks. The second line contains n integers li (1 ≤ li ≤ 109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with n vertices and nonzero area using the rods Cicasso already has.
Print the only integer z — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (n + 1) vertices and nonzero area from all of the rods.
null
In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}. In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}.
[{"input": "3\n1 2 1", "output": "1"}, {"input": "5\n20 4 3 2 1", "output": "11"}]
1,100
["constructive algorithms", "geometry"]
51
[{"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n20 4 3 2 1\r\n", "output": "11\r\n"}, {"input": "7\r\n77486105 317474713 89523018 332007362 7897847 949616701 54820086\r\n", "output": "70407571\r\n"}, {"input": "14\r\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 8...
false
stdio
null
true
358/B
358
B
Python 3
TESTS
11
171
2,048,000
4885809
n = int(input()) A = [0 for i in range(n)] for q in range(n): A[q] = list(input()) s = input() i = 0 cur = 0 ind = 0 p = 1 while i < len(s) and s[i] != '3': if s[i] == '<': while i < len(s) and s[i] != '3': i += 1 else: i += 1 i += 1 if i >= len(s): p = 0 while p and i < len(...
30
140
716,800
5055032
''' Created on Oct 31, 2013 @author: Ismael ''' import sys def nextCharRequired(): for word in lWords: yield '<' yield '3' for c in word: yield c yield '<' yield '3' def check(): pos = 0 for c in nextCharRequired(): posFound = sentence.find(c,pos) ...
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Text Messages
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The numbe...
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
null
Please note that Dima got a good old kick in the pants for the second sample from the statement.
[{"input": "3\ni\nlove\nyou\n<3i<3love<23you<3", "output": "yes"}, {"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3", "output": "no"}]
1,500
["brute force", "strings"]
30
[{"input": "3\r\ni\r\nlove\r\nyou\r\n<3i<3love<23you<3\r\n", "output": "yes\r\n"}, {"input": "7\r\ni\r\nam\r\nnot\r\nmain\r\nin\r\nthe\r\nfamily\r\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\r\n", "output": "no\r\n"}, {"input": "3\r\ni\r\nlove\r\nyou\r\n<3i<3lo<3ve<3y<<<<<<<ou3<3\r\n", "output": "yes\r\n"}, {"input": "...
false
stdio
null
true
358/B
358
B
Python 3
TESTS
11
124
921,600
66511369
n = int(input()) s = "" for i in range(n): s += input() # s is all the words mashed together s += 'P' # this is a padding to help with indexing, hopefully text does not have this character # print(s) text = input() c1 = 0 c2 = 0 p1 = 0 baretext = "" for i in range(len(text)): if text[i] == '<': c1 +=...
30
140
921,600
216729351
n = int(input()) t = '<3' for i in range(n): t += input() + '<3' p = input() s = "yes" j = 0 for c in t: j = p.find(c, j)+1 if j == 0: s = 'no' break print(s)
Codeforces Round 208 (Div. 2)
CF
2,013
2
256
Dima and Text Messages
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. ...
The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The numbe...
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
null
Please note that Dima got a good old kick in the pants for the second sample from the statement.
[{"input": "3\ni\nlove\nyou\n<3i<3love<23you<3", "output": "yes"}, {"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3", "output": "no"}]
1,500
["brute force", "strings"]
30
[{"input": "3\r\ni\r\nlove\r\nyou\r\n<3i<3love<23you<3\r\n", "output": "yes\r\n"}, {"input": "7\r\ni\r\nam\r\nnot\r\nmain\r\nin\r\nthe\r\nfamily\r\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\r\n", "output": "no\r\n"}, {"input": "3\r\ni\r\nlove\r\nyou\r\n<3i<3lo<3ve<3y<<<<<<<ou3<3\r\n", "output": "yes\r\n"}, {"input": "...
false
stdio
null
true
131/B
131
B
Python 3
TESTS
2
62
0
222516296
from bisect import bisect_right '''def BinarySearch(a,x): index = bisect_right(a,x) if index != len(a) and a[i-1] == x: return i return -1 ''' def BinarySearch(data, low, high, target): if high >= low: mid = (high + low) // 2 if data[mid] == target: return mid ...
43
156
9,523,200
222152524
input() lst = input() lst =[int(x) for x in lst.split(" ")] from math import comb hsh = {} pairs = 0 for x in lst: if x not in hsh: hsh[x] = 0 hsh[x] +=1 if 0 in hsh: z = hsh.pop(0) pairs += comb(z,2) k = list(hsh.keys()) for x in k: if x in hsh: if -x in hsh: n = hsh.p...
Codeforces Beta Round 95 (Div. 2)
CF
2,011
2
256
Opposites Attract
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ≤ 10). Of course, one number can be assigned to any number of cust...
The first line of the input data contains an integer n (1 ≤ n ≤ 105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers t1, t2, ..., tn ( - 10 ≤ ti ≤ 10), ti — is the parameter of the i-th customer that has been assigned to the customer by the res...
Print the number of couples of customs with opposite t. The opposite number for x is number - x (0 is opposite to itself). Couples that only differ in the clients' order are considered the same. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, ...
null
In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4). In the second sample any couple of clients is opposite.
[{"input": "5\n-3 3 0 0 3", "output": "3"}, {"input": "3\n0 0 0", "output": "3"}]
1,200
["implementation", "math"]
43
[{"input": "5\r\n-3 3 0 0 3\r\n", "output": "3\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n5\r\n", "output": "0\r\n"}, {"input": "2\r\n0 0\r\n", "output": "1\r\n"}, {"input": "2\r\n-3 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 5\r\n", "output": "...
false
stdio
null
true
108/B
108
B
Python 3
TESTS
9
124
5,529,600
33454356
n = int(input()) l = [int(x) for x in input().split()] flag = 0 for i in l: if 2*i+1 in l or 2*i+2 in l: flag = 1 print('YES') break if not flag: print('NO')
65
278
10,752,000
108622358
input() b={int(x)for x in input().split()} b=sorted(list(b)) for i in range(1,len(b)): if 2*b[i-1]>b[i]: print("YES") break else:print("NO")
Codeforces Beta Round 83 (Div. 2 Only)
CF
2,011
2
256
Datatypes
Tattah's youngest brother, Tuftuf, is new to programming. Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava. Today, Tuftuf was introduced to Gava's unsigned integer datatypes. G...
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
null
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
[{"input": "3\n64 16 32", "output": "NO"}, {"input": "4\n4 2 1 3", "output": "YES"}]
1,400
["math", "sortings"]
65
[{"input": "3\r\n64 16 32\r\n", "output": "NO\r\n"}, {"input": "4\r\n4 2 1 3\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 5 3 3 2\r\n", "output": "YES\r\n"}, {"input": "52\r\n474 24 24 954 9 234 474 114 24 114 234 24 114 114 234 9 9 24 9 54 234 54 9 954 474 9 54 54 54 234 9 114 24 54 114 954 954 474 24 54 54 234 234 4...
false
stdio
null
true
109/D
109
D
Python 3
TESTS
2
186
307,200
69941921
def good(n): while n > 0: if n % 10 != 4 & n % 10 != 7: return False n //= 10 return True n = int(input()) a = list(map(int, input().split())) b = [i for i in range(n)] b.sort(key = lambda i:a[i]) g = -1 for i in range(n): if good(a[i]): g = i break ans = [] ok = True if g ...
76
966
38,502,400
182925810
from collections import defaultdict import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) a = [0] + list(map(int, input().split())) x = list(a) x.sort() s = 0 for i in range(1, n + 1): u = [0] * 10 for j in str(a[i]): u[int(j)] = 1 ok = 1 for j in rang...
Codeforces Beta Round 84 (Div. 1 Only)
CF
2,011
3
256
Lucky Sorting
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya got an array consisting of n numbers, it is the gift for his birthday. Now he wants to sort it...
The first line contains an integer n (1 ≤ n ≤ 105) — the number of elements in the array. The second line contains n positive integers, not exceeding 109 — the array that needs to be sorted in the non-decreasing order.
On the first line print number k (0 ≤ k ≤ 2n) — the number of the swaps in the sorting. On the following k lines print one pair of distinct numbers (a pair per line) — the indexes of elements to swap. The numbers in the array are numbered starting from 1. If it is impossible to sort the given sequence, print the single...
null
null
[{"input": "2\n4 7", "output": "0"}, {"input": "3\n4 2 1", "output": "1\n1 3"}, {"input": "7\n77 66 55 44 33 22 11", "output": "7\n1 7\n7 2\n2 6\n6 7\n3 4\n5 3\n4 5"}]
2,000
["constructive algorithms", "sortings"]
76
[{"input": "2\r\n4 7\r\n", "output": "0\r\n"}, {"input": "3\r\n4 2 1\r\n", "output": "1\r\n1 3\r\n"}, {"input": "7\r\n77 66 55 44 33 22 11\r\n", "output": "9\r\n4 7\r\n1 7\r\n1 6\r\n2 6\r\n2 5\r\n3 5\r\n2 3\r\n1 2\r\n1 4\r\n"}, {"input": "7\r\n1 2 3 4 5 6 7\r\n", "output": "0\r\n"}, {"input": "4\r\n47 1 7 2\r\n", "outp...
false
stdio
import sys def is_lucky(num): s = str(num) for c in s: if c not in {'4', '7'}: return False return True def can_be_sorted(arr): sorted_arr = sorted(arr) if arr == sorted_arr: return True return any(is_lucky(num) for num in arr) def main(input_path, output_path, sub...
true
324/A1
331
A2
Python 3
TESTS2
4
92
0
155639477
from math import inf def solve_task5(): n = int(input()) trees = tuple(map(int, input().split(" "))) d = {} max_rating = -1 * inf begin_tree = 0 end_tree = 0 current_sum = 0 for i in range(n): if trees[i] in d: d[trees[i]][1], d[trees[i]][2] = i, current_sum - d[tre...
18
93
102,400
4092733
N=int(input()) def sum_pos(L): n=len(L) ans=L[0]+L[-1] for i in range(1,n-1): if(L[i]>0): ans+=L[i] return ans A=input().split() Removed=[] Positive=[] cost=0 for i in range(N): A[i]=int(A[i]) k=True for i in range(N): for j in range(N-1,i,-1): if(A[i]==A[j]): ...
ABBYY Cup 3.0 - Finals
ICPC
2,013
2
256
Oh Sweet Beaverette
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming ...
The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers ai — the esthetic appeals of each tree. All esthetic appeals do not exceed 109 in their absolute value. - to get 30 points, you need to solve the problem with constrai...
In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to righ...
null
null
[{"input": "5\n1 2 3 1 2", "output": "8 1\n1"}, {"input": "5\n1 -2 3 1 -2", "output": "5 2\n2 5"}]
1,400
[]
18
[{"input": "5\r\n1 2 3 1 2\r\n", "output": "8 1\r\n1 "}, {"input": "5\r\n1 -2 3 1 -2\r\n", "output": "5 2\r\n2 5 "}, {"input": "2\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "3\r\n0 -1 0\r\n", "output": "0 1\r\n2 "}, {"input": "3\r\n1 1 1\r\n", "output": "3 0\r\n"}, {"input": "4\r\n-1 1 1 -1\r\n", "output": "2 2\r\n1 ...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path) as f: lines = f.readlines() if not lines: ...
true
61/D
61
D
PyPy 3
TESTS
42
1,106
36,147,200
88047795
n = int(input()) tree = [[] for _ in range(n+1)] ans = 10 ** 18 tot = 0 for _ in range(n-1): u,v,w = map(int, input().split()) tree[u].append((v,w)) tree[v].append((u,w)) tot += 2 * w def dfs(node, par, curr_val): global ans global tot ans = min(ans, tot - curr_val) for child in t...
56
405
40,243,200
207708959
# LUOGU_RID: 111555286 from sys import stdin input = stdin.readline def get() : return map(int,input().split()) def dfs(u, fa) : f[u] = 0 for v in Map[u].keys() : if v == fa : continue dfs(v, u) f[u] += f[v] + Map[u][v] def find(u, fa, tot) : global res res = ma...
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Eternal Victory
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all n cities of Persia to find the best available mountain, but after the recent war he was too ti...
First line contains a single natural number n (1 ≤ n ≤ 105) — the amount of cities. Next n - 1 lines contain 3 integer numbers each xi, yi and wi (1 ≤ xi, yi ≤ n, 0 ≤ wi ≤ 2 × 104). xi and yi are two ends of a road and wi is the length of that road.
A single integer number, the minimal length of Shapur's travel. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
null
null
[{"input": "3\n1 2 3\n2 3 4", "output": "7"}, {"input": "3\n1 2 3\n1 3 3", "output": "9"}]
1,800
["dfs and similar", "graphs", "greedy", "shortest paths", "trees"]
56
[{"input": "3\r\n1 2 3\r\n2 3 4\r\n", "output": "7\r\n"}, {"input": "3\r\n1 2 3\r\n1 3 3\r\n", "output": "9\r\n"}, {"input": "5\r\n5 3 60\r\n4 3 63\r\n2 1 97\r\n3 1 14\r\n", "output": "371\r\n"}, {"input": "3\r\n2 1 63\r\n3 1 78\r\n", "output": "204\r\n"}, {"input": "13\r\n8 2 58\r\n2 1 49\r\n13 10 41\r\n11 9 67\r\n6 4...
false
stdio
null
true
33/B
33
B
Python 3
TESTS
8
124
307,200
21218211
proverka=[] S=input() T=input() n=int(input()) P={} #res=[] res="" summ=0 for i in range(n): a=input().split() try: proverka.index(a[1]) except: proverka.append(a[1]) if a[0]+a[1] not in P: P[a[0]+a[1]]=int(a[2]) elif int(a[2])<P[a[0]+a[1]]: P[a[0]+a[1]]=int(a[2]) l=len(proverka) if len(S)==len(T): for...
61
1,714
614,400
7408961
# http://codeforces.com/problemset/problem/33/B # 33b: String Problem. #input = raw_input def calc_path(a): ''' this function uses floyd-warshall alg to compute all pairs shortest path weight among alphabet characters. input: a: a 2d list which gives the weighted edge data. e.g., a = [['a', 'x', 42]]:...
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
String Problem
Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to make them identical. According to the game rules, with each move Valera can change one arbitrary ch...
The first input line contains two initial non-empty strings s and t, consisting of lower case Latin letters. The length of each string doesn't exceed 105. The following line contains integer n (0 ≤ n ≤ 500) — amount of possible changings. Then follow n lines, each containing characters Ai and Bi (lower case Latin lette...
If the answer exists, output the answer to the problem, and the resulting string. Otherwise output -1 in the only line. If the answer is not unique, output any.
null
null
[{"input": "uayd\nuxxd\n3\na x 8\nx y 13\nd c 3", "output": "21\nuxyd"}, {"input": "a\nb\n3\na b 2\na b 3\nb a 5", "output": "2\nb"}, {"input": "abc\nab\n6\na b 4\na b 7\nb a 8\nc b 11\nc a 3\na c 0", "output": "-1"}]
1,800
["shortest paths"]
61
[{"input": "uayd\r\nuxxd\r\n3\r\na x 8\r\nx y 13\r\nd c 3\r\n", "output": "21\r\nuxyd\r\n"}, {"input": "a\r\nb\r\n3\r\na b 2\r\na b 3\r\nb a 5\r\n", "output": "2\r\nb\r\n"}, {"input": "abc\r\nab\r\n6\r\na b 4\r\na b 7\r\nb a 8\r\nc b 11\r\nc a 3\r\na c 0\r\n", "output": "-1\r\n"}, {"input": "xhtuopq\r\nrtutbz\r\n10\r\n...
false
stdio
import sys from collections import defaultdict import heapq def main(input_path, output_path, submission_path): with open(input_path) as f: s = f.readline().strip() t = f.readline().strip() n = int(f.readline().strip()) transforms = [] for _ in range(n): line = f...
true
765/A
765
A
Python 3
TESTS
7
46
4,608,000
24670432
n = int(input()) home = input() i = 0 lst = [] while i < n: lst.append(input()) i += 1 last_fly = lst.count(lst[len(lst) - 1]) last = lst[len(lst) - 1][:3] first = lst[len(lst) - 1][-3:] cnt = lst.count(first + "->" + last) if cnt == last_fly: print("home") else: print("contest")
23
31
0
146007920
n=int(input()) s=input() l=[] for _ in range(n): l.append(input()) res="home" if(n%2!=0): res="contest" print(res)
Codeforces Round 397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
512
Neverending competitions
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name ...
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
null
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
[{"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home"}, {"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest"}]
900
["implementation", "math"]
23
[{"input": "4\r\nSVO\r\nSVO->CDG\r\nLHR->SVO\r\nSVO->LHR\r\nCDG->SVO\r\n", "output": "home\r\n"}, {"input": "3\r\nSVO\r\nSVO->HKT\r\nHKT->SVO\r\nSVO->RAP\r\n", "output": "contest\r\n"}, {"input": "1\r\nESJ\r\nESJ->TSJ\r\n", "output": "contest\r\n"}, {"input": "2\r\nXMR\r\nFAJ->XMR\r\nXMR->FAJ\r\n", "output": "home\r\n"...
false
stdio
null
true
609/C
609
C
PyPy 3-64
TESTS
9
77
512,000
137833690
import sys, math input=sys.stdin.readline INF=int(1e9)+7 def solve(): n=int(input()) data=list(map(int,input().split())) s=sum(data) if n==100: print(414866) return if s%n==0: ans=0 k=s//n for i in data: ans+=abs(i-k) print((...
58
109
7,372,800
146279316
n = int(input()) arr = list(map(int,input().split())) l_time = 0 r_time = 0 total = sum(arr) avg = total//n for i in range(n): if(arr[i] <= avg): l_time = l_time + avg - arr[i] else: r_time = r_time + arr[i] - (avg + 1) # print(arr[i],time) if(l_time >= r_time): print(l_time) els...
Educational Codeforces Round 3
ICPC
2,015
2
256
Load Balancing
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server. In order to balance the load for each server, you want to reassign some tasks to make the difference betw...
The first line contains positive number n (1 ≤ n ≤ 105) — the number of the servers. The second line contains the sequence of non-negative integers m1, m2, ..., mn (0 ≤ mi ≤ 2·104), where mi is the number of tasks assigned to the i-th server.
Print the minimum number of seconds required to balance the load.
null
In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2. In the second example the load is already balanced. A possible sequence of task movements for the third example is: ...
[{"input": "2\n1 6", "output": "2"}, {"input": "7\n10 11 10 11 10 11 11", "output": "0"}, {"input": "5\n1 2 3 4 5", "output": "3"}]
1,500
["implementation", "math"]
58
[{"input": "2\r\n1 6\r\n", "output": "2\r\n"}, {"input": "7\r\n10 11 10 11 10 11 11\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n20000\r\n", "output": "0\r\n"}, {"i...
false
stdio
null
true
61/B
61
B
Python 3
TESTS
34
109
307,200
103526962
s1 = input().replace('_','').replace(';', '').replace('-','').lower() s2 = input().replace('_','').replace(';', '').replace('-', '').lower() s3 = input().replace('_','').replace(';', '').replace('-', '').lower() n1 = len(s1) n2 = len(s2) n3 = len(s3) for i in range(int(input())): s = input().replace('_','').repl...
43
46
0
143376659
word1 = input().lower() word1 = word1.replace(";", "").replace("-", "").replace("_", "") word2 = input().lower() word2 = word2.replace(";", "").replace("-", "").replace("_", "") word3 = input().lower() word3 = word3.replace(";", "").replace("-", "").replace("_", "") possibilities = [word1+word2+word3, word3+word2+wo...
Codeforces Beta Round 57 (Div. 2)
CF
2,011
2
256
Hard Work
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer! Some days before the contest, the teacher took a very simple-looking exam and all his n students took part in the exam. The teacher...
The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively. In the fourth line there is a single integer n (0 ≤ n ≤ 1000), the number of students. N...
For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.
null
null
[{"input": "Iran_\nPersian;\nW_o;n;d;e;r;f;u;l;\n7\nWonderfulPersianIran\nwonderful_PersIAN_IRAN;;_\nWONDERFUL___IRAN__PERSIAN__;;\nIra__Persiann__Wonderful\nWonder;;fulPersian___;I;r;a;n;\n__________IranPersianWonderful__________\nPersianIran_is_Wonderful", "output": "ACC\nACC\nACC\nWA\nACC\nACC\nWA"}, {"input": "Shap...
1,300
["strings"]
43
[{"input": "Iran_\r\nPersian;\r\nW_o;n;d;e;r;f;u;l;\r\n7\r\nWonderfulPersianIran\r\nwonderful_PersIAN_IRAN;;_\r\nWONDERFUL___IRAN__PERSIAN__;;\r\nIra__Persiann__Wonderful\r\nWonder;;fulPersian___;I;r;a;n;\r\n__________IranPersianWonderful__________\r\nPersianIran_is_Wonderful\r\n", "output": "ACC\r\nACC\r\nACC\r\nWA\r\...
false
stdio
null
true
131/B
131
B
Python 3
TESTS
5
92
0
223150398
size = int(input()) couples = input().split(" ") couples = [int(x) for x in couples] matches = {} zero = 0 polarity = 0 for number in couples: if number != 0: matches[number] = matches.get(number, 0) + 1 else: zero += 1 for num, count in matches.items(): if num != 0: opposite_count =...
43
184
10,649,600
223148213
# Asif Islam - asifislam510 # Input an integer 'n' n = int(input()) # Input 'n' numbers and create a list numbers = [int(x) for x in input().split()[:n]] # Initialize a dictionary to count occurrences of numbers number_count = {} # Count occurrences of each number in the list for num in numbers: number_count[num...
Codeforces Beta Round 95 (Div. 2)
CF
2,011
2
256
Opposites Attract
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ≤ 10). Of course, one number can be assigned to any number of cust...
The first line of the input data contains an integer n (1 ≤ n ≤ 105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers t1, t2, ..., tn ( - 10 ≤ ti ≤ 10), ti — is the parameter of the i-th customer that has been assigned to the customer by the res...
Print the number of couples of customs with opposite t. The opposite number for x is number - x (0 is opposite to itself). Couples that only differ in the clients' order are considered the same. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, ...
null
In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4). In the second sample any couple of clients is opposite.
[{"input": "5\n-3 3 0 0 3", "output": "3"}, {"input": "3\n0 0 0", "output": "3"}]
1,200
["implementation", "math"]
43
[{"input": "5\r\n-3 3 0 0 3\r\n", "output": "3\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n5\r\n", "output": "0\r\n"}, {"input": "2\r\n0 0\r\n", "output": "1\r\n"}, {"input": "2\r\n-3 3\r\n", "output": "1\r\n"}, {"input": "2\r\n1 5\r\n", "output": "...
false
stdio
null
true
359/C
359
C
PyPy 3
TESTS
7
233
17,100,800
44240819
import math modulus = 10 ** 9 + 7 def main(): n, x = map(int, input().split()) arr = list(map(int, input().split())) total = sum(arr) powers = [total - x for x in arr] res = 1 while True: min_powers = min(powers) res *= pow(x, int(min_powers), modulus) cnt = powers....
36
249
36,454,400
84946200
modulus = 10**9 +7 n, x = map(int,input().split()) s = list(map(int,input().split())) tot = sum(s) powers=[tot-x for x in s] powers.sort(reverse=True) while True: low=powers[-1] cnt = 0 while len(powers) > 0 and powers[-1]==low: cnt += 1 powers.pop() if cnt%x==0: cnt=cnt // x...
Codeforces Round 209 (Div. 2)
CF
2,013
1
256
Prime Number
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fractions very much. Today he wrote out number $$\frac{1}{x^{a_1}} + \frac{1}{x^{a_2}} + \ldots + \frac{1}{x^{a_n}}$$ on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fra...
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
null
In the first sample $$\frac{1}{4} + \frac{1}{4} = \frac{4+4}{16} = \frac{8}{16}$$. Thus, the answer to the problem is 8. In the second sample, $$\frac{1}{3}+\frac{1}{9}+\frac{1}{27}=\frac{243+81+27}{729}=\frac{351}{729}$$. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27. In the third sample the answer to...
[{"input": "2 2\n2 2", "output": "8"}, {"input": "3 3\n1 2 3", "output": "27"}, {"input": "2 2\n29 29", "output": "73741817"}, {"input": "4 5\n0 0 0 0", "output": "1"}]
1,900
["math", "number theory"]
36
[{"input": "2 2\r\n2 2\r\n", "output": "8\r\n"}, {"input": "3 3\r\n1 2 3\r\n", "output": "27\r\n"}, {"input": "2 2\r\n29 29\r\n", "output": "73741817\r\n"}, {"input": "4 5\r\n0 0 0 0\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "26 2\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
false
stdio
null
true
359/C
359
C
Python 3
TESTS
7
171
9,216,000
55585764
n, x = map(int, input().split()) A = list(map(int, input().split())) m = max(A) d = sum(A) - m ans = pow(x, d, 10 ** 9 + 7) cnt_m = 0 for i in A: if i == m: cnt_m += 1 if cnt_m % x: print(ans) exit(0) step = 0 while cnt_m % x == 0: cnt_m //= x step += 1 d = {} for i in A: if m - i < step...
36
265
14,336,000
155312010
import sys input = lambda: sys.stdin.buffer.readline().decode().strip() mod = 10 ** 9 + 7 n, x = map(int, input().split()) a, ans = [int(x) for x in input().split()], 1 for i in range(n - 1): ans = (ans * pow(x, a[i], mod)) % mod ma = a[-1] while len(a) > 1: cur, num = a.pop(), 1 while a and a[-1] == cu...
Codeforces Round 209 (Div. 2)
CF
2,013
1
256
Prime Number
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fractions very much. Today he wrote out number $$\frac{1}{x^{a_1}} + \frac{1}{x^{a_2}} + \ldots + \frac{1}{x^{a_n}}$$ on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fra...
The first line contains two positive integers n and x (1 ≤ n ≤ 105, 2 ≤ x ≤ 109) — the size of the array and the prime number. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ a1 ≤ a2 ≤ ... ≤ an ≤ 109).
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
null
In the first sample $$\frac{1}{4} + \frac{1}{4} = \frac{4+4}{16} = \frac{8}{16}$$. Thus, the answer to the problem is 8. In the second sample, $$\frac{1}{3}+\frac{1}{9}+\frac{1}{27}=\frac{243+81+27}{729}=\frac{351}{729}$$. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27. In the third sample the answer to...
[{"input": "2 2\n2 2", "output": "8"}, {"input": "3 3\n1 2 3", "output": "27"}, {"input": "2 2\n29 29", "output": "73741817"}, {"input": "4 5\n0 0 0 0", "output": "1"}]
1,900
["math", "number theory"]
36
[{"input": "2 2\r\n2 2\r\n", "output": "8\r\n"}, {"input": "3 3\r\n1 2 3\r\n", "output": "27\r\n"}, {"input": "2 2\r\n29 29\r\n", "output": "73741817\r\n"}, {"input": "4 5\r\n0 0 0 0\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "26 2\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
false
stdio
null
true
89/A
89
A
PyPy 3
TESTS
8
139
20,172,800
87322056
from sys import stdin n,m,k = [int(x) for x in stdin.readline().split()] d = [int(x) for x in stdin.readline().split()] if n <= 2: print(0) elif d[0] == 0 or d[-1] == 0: print(0) elif n % 2 == 0: print(0) else: if m-1 >= n//2: print(min(k,d[0], d[-1])) else: print(0)
45
124
716,800
9229401
z=lambda: list(map(int,input().split())) n,m,k=z() print(n%2*min(m//(n//2+1)*k, *z()[::2]))
Codeforces Beta Round 74 (Div. 1 Only)
CF
2,011
1
256
Robbery
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right. Unfortunately, Joe ...
The first line contains integers n, m and k (1 ≤ n ≤ 104, 1 ≤ m, k ≤ 109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell — it is an integer from 0 to 105.
Print a single number — the maximum number of diamonds Joe can steal.
null
In the second sample Joe can act like this: The diamonds' initial positions are 4 1 3. During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket. By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference...
[{"input": "2 3 1\n2 3", "output": "0"}, {"input": "3 2 2\n4 1 3", "output": "2"}]
1,800
["greedy"]
45
[{"input": "2 3 1\r\n2 3\r\n", "output": "0"}, {"input": "3 2 2\r\n4 1 3\r\n", "output": "2"}, {"input": "5 10 10\r\n7 0 7 0 7\r\n", "output": "7"}, {"input": "6 10 4\r\n1 2 3 4 5 6\r\n", "output": "0"}, {"input": "7 5 2\r\n1 2 3 4 5 6 7\r\n", "output": "1"}, {"input": "16 100 100\r\n30 89 12 84 62 24 10 59 98 21 13 69...
false
stdio
null
true
445/A
445
A
Python 3
TESTS
12
46
0
155119504
n, m = map(int, input().split()) matrix = [input() for _ in range(n)] prev = 'B' for i in range(n): for j in range(m): if (matrix[i][j] == '-'): print('-', end="") else: print(prev, end="") prev = 'W' if prev == 'B' else 'B' print("\n", end="") if (n % 2 == 0)...
37
46
0
136128644
import sys def print_result(n, m, board): answer = [["" for i in range(m)] for j in range(n)] for i in range(n): for j in range(m): if board[i][j] == ".": if (i % 2 == 0 and j % 2 == 0) or (i % 2 != 0 and j % 2 != 0): answer[i][j] = "W" el...
Codeforces Round 254 (Div. 2)
CF
2,014
1
256
DZY Loves Chessboard
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the sa...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains a string of m characters: the j-th character of the i-th string is either "." or "-". A "." means that the corresponding cell (in the i-th row and the j-th column) is good, while a "-" means it is bad.
Output must contain n lines, each line must contain a string of m characters. The j-th character of the i-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It is guara...
null
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
[{"input": "1 1\n.", "output": "B"}, {"input": "2 2\n..\n..", "output": "BW\nWB"}, {"input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B"}]
1,200
["dfs and similar", "implementation"]
37
[{"input": "1 1\r\n.\r\n", "output": "B\r\n"}, {"input": "2 2\r\n..\r\n..\r\n", "output": "BW\r\nWB\r\n"}, {"input": "3 3\r\n.-.\r\n---\r\n--.\r\n", "output": "B-B\r\n---\r\n--B\r\n"}, {"input": "4 4\r\n....\r\n....\r\n....\r\n....\r\n", "output": "BWBW\r\nWBWB\r\nBWBW\r\nWBWB\r\n"}, {"input": "3 1\r\n-\r\n.\r\n.\r\n",...
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.readlines() n, m = map(int, lines[0].split()) input_grid = [list(line.strip()) for line in lines[1:n+1]] with open(submission_path) as f: ...
true
79/B
79
B
PyPy 3-64
TESTS
22
372
9,830,400
187640444
n, m, k, t = [int(x) for x in input().split()] waste=[0 for _ in range(k)] for i in range(k): a,b=[int(x) for x in input().split()] waste[i]=(a-1)*m+(b-1) waste.sort() for _ in range(t): i,j=[int(x) for x in input().split()] val=(i-1)*m+(j-1) cnt,wt,index=0,waste[0],0 if val>waste[-1]: val-=k else: while(wt...
29
92
409,600
218212375
# جزرة -> كيوي -> عنب h,w,waste,qeu = map(int,input().split()) wst = [] clean = ['Carrots','Kiwis','Grapes'] emp = [] for i in range(waste+qeu): if i<waste: wst.append(list(map(int,input().split()))) else: emp.append(list(map(int,input().split()))) wst.sort() for b in emp: l,r=0,waste-1 ...
Codeforces Beta Round 71
CF
2,011
2
256
Colorful Field
Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following ...
In the first line there are four positive integers n, m, k, t (1 ≤ n ≤ 4·104, 1 ≤ m ≤ 4·104, 1 ≤ k ≤ 103, 1 ≤ t ≤ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k line...
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
null
The sample corresponds to the figure in the statement.
[{"input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1", "output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots"}]
1,400
["implementation", "sortings"]
29
[{"input": "4 5 5 6\r\n4 3\r\n1 3\r\n3 3\r\n2 5\r\n3 2\r\n1 3\r\n1 4\r\n2 3\r\n2 4\r\n1 1\r\n1 1\r\n", "output": "Waste\r\nGrapes\r\nCarrots\r\nKiwis\r\nCarrots\r\nCarrots\r\n"}, {"input": "2 3 2 2\r\n1 1\r\n2 1\r\n1 2\r\n2 1\r\n", "output": "Carrots\r\nWaste\r\n"}, {"input": "31 31 31 4\r\n15 26\r\n29 15\r\n17 31\r\n2...
false
stdio
null
true