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
326/B
335
B
Python 3
TESTS
3
1,560
10,547,200
4229160
s = input() dp = [[0 for i in range(0, len(s))] for i in range(0, len(s))] found = [[False for i in range(0, len(s))] for i in range(0, len(s))] sol = '' mid = '' def L(a, b): if found[a][b]: return dp[a][b] if a==b: dp[a][b] = s[a] elif a + 1 == b: if s[a] == s[b]: dp[a][b] = 2 else: dp...
72
1,996
117,145,600
66242753
from collections import defaultdict s = input() n = len(s) if n >= 2600: print(s[0] * 100) elif n > 2574: count = defaultdict(int) for l in s: count[l] += 1 max_l = s[0] for l, c in count.items(): if c >= 100: max_l = l print(max_l * 100) else: data = defaultdi...
MemSQL start[c]up Round 2
CF
2,013
2
256
Palindrome
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible.
The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) containing only lowercase English letters.
If s contains a palindrome of length exactly 100 as a subsequence, print any palindrome of length 100 which is a subsequence of s. If s doesn't contain any palindromes of length exactly 100, print a palindrome that is a subsequence of s and is as long as possible. If there exists multiple answers, you are allowed to p...
null
A subsequence of a string is a string that can be derived from it by deleting some characters without changing the order of the remaining characters. A palindrome is a string that reads the same forward or backward.
[{"input": "bbbabcbbb", "output": "bbbcbbb"}, {"input": "rquwmzexectvnbanemsmdufrg", "output": "rumenanemur"}]
1,900
[]
72
[{"input": "bbbabcbbb\r\n", "output": "bbbcbbb\r\n"}, {"input": "rquwmzexectvnbanemsmdufrg\r\n", "output": "rumenanemur\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
false
stdio
import sys def is_palindrome(s): return s == s[::-1] def is_subsequence(sub, s): i = 0 for c in sub: i = s.find(c, i) + 1 if i == 0: return False return True input_path, output_path, submission_path = sys.argv[1:4] with open(input_path) as f: s = f.read().strip() wit...
true
837/C
837
C
PyPy 3
TESTS
12
92
17,715,200
132495848
n,a,b = map(int, input().split()) XY = [] for i in range(n): x,y = map(int, input().split()) XY.append((x, y)) ans = 0 for i in range(n-1): x1,y1 = XY[i] s1 = x1*y1 for j in range(i+1, n): x2,y2 = XY[j] s = s1+x2*y2 flag = False if x1 <= a and y1 <= b: if...
51
62
4,608,000
29171876
n, A, B = map(int, input().split()) l = [] for i in range(n): x, y = map(int, input().split()) l.append((x, y)) def checkList(a, b): return (a <= A and b <= B) or (b <= A and a <= B) def checkPear(ax, ay, bx, by): return (checkList(ax + bx, max(ay, by)) or checkList(ax + by, max(ay, bx)) ...
Educational Codeforces Round 26
ICPC
2,017
1
256
Two Seals
One very important person has a piece of paper in the form of a rectangle a × b. Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees). A very importa...
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100). Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
null
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper. In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the large...
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
1,500
["brute force", "implementation"]
51
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"inpu...
false
stdio
null
true
672/B
672
B
Python 3
TESTS
34
109
614,400
77209244
n = int(input()) s = input() d = {} if(len(s)>26): cnt = -1 elif(len(s)==1): cnt = 1 else: for i in range(0,n): if(s[i] in d): d[s[i]] += 1 else: d[s[i]] = 1 cnt = 0 for k,v in d.items(): if(v>1): cnt+=v-1 print(cnt)
47
46
0
137588662
n=int(input()) s=input() if n>26: print(-1) else: lst=[] for i in s: if i not in lst: lst.append(i) print(n-len(lst))
Codeforces Round 352 (Div. 2)
CF
2,016
2
256
Different is Good
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some numb...
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s. The second line contains the string s of length n consisting of only lowercase English letters.
If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
null
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
[{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}]
1,000
["constructive algorithms", "implementation", "strings"]
47
[{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": ...
false
stdio
null
true
832/B
832
B
PyPy 3
TESTS
22
343
21,094,400
131092398
def minicoolf(a, b): if(len(a) != len(b)): return False n = len(a) for i in range(n): if(a[i] != b[i] and a[i] != '?'): return False if(a[i] == '?' and not b[i] in gud): return False return True def coolf(a, b): if(len(b) + 1< len(a)): re...
94
217
9,318,400
116312932
import sys input=sys.stdin.readline c=input().rstrip() can=set(list(c)) cannot=set([chr(i) for i in range(ord("a"),ord("z")+1)])-can pattern=input().rstrip() tmp=("*" in pattern) q=int(input()) for _ in range(q): s=input().rstrip() ls=len(s) p=pattern l=len(p) if tmp: if l<=ls: p=p.replace("*","*"*(...
Codeforces Round 425 (Div. 2)
CF
2,017
2
256
Petya and Exam
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is kno...
The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad. The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 105). It is guaranteed that character "*"...
Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrary.
null
In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter. Explanation of the second example. - The first query: "NO", because character "*" can be replaced wit...
[{"input": "ab\na?a\n2\naaa\naab", "output": "YES\nNO"}, {"input": "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax", "output": "NO\nYES\nNO\nYES"}]
1,600
["implementation", "strings"]
94
[{"input": "ab\r\na?a\r\n2\r\naaa\r\naab\r\n", "output": "YES\r\nNO\r\n"}, {"input": "abc\r\na?a?a*\r\n4\r\nabacaba\r\nabaca\r\napapa\r\naaaaax\r\n", "output": "NO\r\nYES\r\nNO\r\nYES\r\n"}, {"input": "x\r\n?aba*\r\n69\r\nc\r\naaacc\r\nbba\r\nbabcb\r\nac\r\nbccca\r\nca\r\nabbaa\r\nb\r\naacca\r\nccc\r\ncc\r\na\r\naabba\...
false
stdio
null
true
962/B
962
B
Python 3
TESTS
11
202
7,168,000
91456011
a,b,c=map(int,input().split()) s=0;z=input();i=0 while i<a: if z[i]=='.': k=0;o=i if b>=c:b-=1;s+=1 else:c-=1;s+=1;k=1 i+=1 while i<a and z[i]=='.': if k: if b:b-=1;s+=1 else: if c:c-=1;s+=1 k^=1;i+=1 els...
93
78
8,704,000
129781282
import sys input = sys.stdin.readline def solve(): n, a, b = map(int,input().split()) e = 0 o = 0 for i in input().strip().split('*'): l = len(i) e += l // 2 o += l % 2 print(min(o + e + min(e,a,b), b + a)) solve()
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Students in Railway Carriage
There are $$$n$$$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger. The university team for the Olympiad consists of $$$a$$$ student-programmers and $$$b$$$ student-athletes. Determine the largest number of students from all $$$a+b$$$ students, which you can put in t...
The first line contain three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n \le 2\cdot10^{5}$$$, $$$0 \le a, b \le 2\cdot10^{5}$$$, $$$a + b > 0$$$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes. The second line contains a string with len...
Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete.
null
In the first example you can put all student, for example, in the following way: *.AB* In the second example you can put four students, for example, in the following way: *BAB*B In the third example you can put seven students, for example, in the following way: B*ABAB**A*B The letter A means a student-programmer, an...
[{"input": "5 1 1\n*...*", "output": "2"}, {"input": "6 2 3\n*...*.", "output": "4"}, {"input": "11 3 10\n.*....**.*.", "output": "7"}, {"input": "3 2 3\n***", "output": "0"}]
1,300
["constructive algorithms", "greedy", "implementation"]
93
[{"input": "5 1 1\r\n*...*\r\n", "output": "2\r\n"}, {"input": "6 2 3\r\n*...*.\r\n", "output": "4\r\n"}, {"input": "11 3 10\r\n.*....**.*.\r\n", "output": "7\r\n"}, {"input": "3 2 3\r\n***\r\n", "output": "0\r\n"}, {"input": "9 5 3\r\n*...*...*\r\n", "output": "6\r\n"}, {"input": "9 2 4\r\n*...*...*\r\n", "output": "6...
false
stdio
null
true
1009/C
1009
C
Python 3
TESTS
51
482
0
40454170
n, m = map(int, input().split()) res = 0 for i in range(m): x, d = map(int, input().split()) res += x if d < 0: if n % 2 == 0: k = n // 2 - 1 res += d * (k + 1) * (k + 1) / n else: k = n // 2 res += d * k * (k + 1) / n else: res += ...
54
93
3,891,200
211662508
import sys input = sys.stdin.readline n, m = map(int,input().split()) ans = 0 while m : m -= 1 x, y = map(int,input().split()) ans += x*n if y < 0 : if n%2 : ans += (n//2)*(n//2+1)*y else : ans += (((n//2)*(n//2+1))//2)*y ans += (((n//2-1)*(n//2))//2)*...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Annoying Present
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $$$m$$$ changes of the following form. For s...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
null
null
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
1,700
["greedy", "math"]
54
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n"...
false
stdio
import sys import math def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: expected_line = f.readline().strip() expected = float(expected_line) with open(submission_path) as f: submission_line = f.readline()...
true
1009/C
1009
C
PyPy 3-64
TESTS
38
93
4,812,800
172084587
from sys import stdin raw_input = lambda: stdin.readline().rstrip() input = lambda: int(raw_input()) I=lambda: map(int, raw_input().split()) T=lambda x: (x*(x+1))//2 xrange=range n,m = I() res = 0.0 q = T(n-1) q1 = T((n-1)//2) for _ in xrange(m): x,d = I() res += x if d==0: continue elif d>0: res += ((q*d)/fl...
54
93
5,939,200
194079041
import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") #######################################...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Annoying Present
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $$$m$$$ changes of the following form. For s...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
null
null
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
1,700
["greedy", "math"]
54
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n"...
false
stdio
import sys import math def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: expected_line = f.readline().strip() expected = float(expected_line) with open(submission_path) as f: submission_line = f.readline()...
true
1009/C
1009
C
PyPy 3
TESTS
38
155
22,016,000
126667191
import sys p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def BI(): return sys.stdi...
54
124
3,891,200
203055355
import sys input = sys.stdin.readline def f(u): return u*(u+1)//2 n, m = map(int, input().split()) x1, x2 = n//2, (n-1)//2 x, y, c, d = f(x1) + f(x2), f(n-1), 0, 0 for i in range(m): a, b = map(int, input().split()) c += a d += max(b*x, b*y) print((c*n+d)/n)
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Annoying Present
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $$$m$$$ changes of the following form. For s...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
null
null
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
1,700
["greedy", "math"]
54
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n"...
false
stdio
import sys import math def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: expected_line = f.readline().strip() expected = float(expected_line) with open(submission_path) as f: submission_line = f.readline()...
true
672/B
672
B
PyPy 3
TESTS
34
140
22,220,800
88035762
n = int(input()) m = list(input()) if n==1 or n>26: print(-1) else: print(n-len(set(m)))
47
46
0
141478516
print(l-sett if (l:=int(input()),st:=input(),sett:=len(set(st))) and 26-sett>=l-sett else -1)
Codeforces Round 352 (Div. 2)
CF
2,016
2
256
Different is Good
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some numb...
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s. The second line contains the string s of length n consisting of only lowercase English letters.
If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
null
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
[{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}]
1,000
["constructive algorithms", "implementation", "strings"]
47
[{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": ...
false
stdio
null
true
1009/C
1009
C
Python 3
TESTS
38
373
0
40369439
from sys import stdin, stdout a = [int(x) for x in stdin.readline().split()] n = a[0] m = a[1] max_m = n * (n-1)/ 2 if n % 2 == 0: min_m = ((n/2)*(n/2 + 1))/2 + ((n/2 - 1)*(n/2))/2 else: min_m = int(n/2) * (int(n/2 + 1)) curr = 0 for i in range(0, m): a = [int(x) for x in stdin.readline().split()] x...
54
139
11,673,600
218719337
import sys input = lambda: sys.stdin.readline().rstrip() import math from heapq import heappush , heappop from collections import defaultdict,deque,Counter from bisect import * N,M = map(int, input().split()) A = [] for _ in range(M): x,d = map(int, input().split()) A.append((x,d)) ans = 0 for x,d in A: ...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Annoying Present
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $$$m$$$ changes of the following form. For s...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
null
null
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
1,700
["greedy", "math"]
54
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n"...
false
stdio
import sys import math def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: expected_line = f.readline().strip() expected = float(expected_line) with open(submission_path) as f: submission_line = f.readline()...
true
1009/C
1009
C
Python 3
TESTS
38
374
0
59959282
n,m=map(int,input().split()) def su(x): return x*(x+1) s=0 t=0 if(n==1): for i in range(m): x,d=map(int,input().split()) s+=x print(s) else: for i in range(m): x,d=map(int,input().split()) s+=x if(d>=0): t+=d*(su(n-1)/2) else: if(n%...
54
155
5,427,200
112760067
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, m = map(int, input().split()) MAX = 0 MIN = 10**18 for i in range(n): l = i*(i+1)//2 r = (n-1-i)*(n-1-i+1)//2 MAX= max(MAX, l+r) MIN = min(MIN, l+r) ans = 0 for i in range(m): x, d = map(int, input().split()) ...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Annoying Present
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $$$m$$$ changes of the following form. For s...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
null
null
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
1,700
["greedy", "math"]
54
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n"...
false
stdio
import sys import math def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: expected_line = f.readline().strip() expected = float(expected_line) with open(submission_path) as f: submission_line = f.readline()...
true
1009/C
1009
C
PyPy 3
TESTS
38
249
5,939,200
43529176
import sys from sys import stdin,stdout n,m=map(int,stdin.readline().split(' ')) ans=0 for _ in range(m): x,d=map(int,stdin.readline().split(' ')) ans+=x if d>0: ans+=(((n-1)/2)*d) if d<0: if n%2!=0: ans+=((((n//2)*(n//2+1))/n)*d) else: ans+=(((( ( (n-1)//2) * ( (n-1)//2+1) ) +n//2)/n)*d...
54
202
2,355,200
94401502
import sys from array import array def readline(): return sys.stdin.buffer.readline().decode('utf-8') n, m = map(int, readline().split()) total = 0 for _ in range(m): x, d = map(int, readline().split()) total += x*n if d >= 0: total += d * (((n-1) * n) >> 1) else: l = (((n-1) >> 1) ...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Annoying Present
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $$$m$$$ changes of the following form. For s...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
null
null
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
1,700
["greedy", "math"]
54
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n"...
false
stdio
import sys import math def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: expected_line = f.readline().strip() expected = float(expected_line) with open(submission_path) as f: submission_line = f.readline()...
true
1009/C
1009
C
PyPy 3
TESTS
38
264
6,041,600
43533263
import sys from sys import stdin,stdout n,m=map(int,stdin.readline().split(' ')) ans=0 for _ in range(m): x,d=map(int,stdin.readline().split(' ')) ans+=x t3=((n//2)*(n//2+1)); t4=( ( (n-1)//2) * ( (n-1)//2+1) ); if d>0: ans+=(((n-1)/2)*d) if d<0: if n%2!=0: t6=(t3*d) ans+=(t6/n) else...
54
218
25,395,200
128894865
import sys input = sys.stdin.readline def f(a): return a * (a + 1) // 2 n, m = map(int, input().split()) mi, ma = f(n // 2) + f(n // 2 - (n % 2 ^ 1)), f(n - 1) ans = 0 c = 0 for _ in range(m): x, d = map(int, input().split()) if d < 0: ans += d * mi else: ans += d * ma c += x ans +...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Annoying Present
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $$$m$$$ changes of the following form. For s...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
null
null
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
1,700
["greedy", "math"]
54
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n"...
false
stdio
import sys import math def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: expected_line = f.readline().strip() expected = float(expected_line) with open(submission_path) as f: submission_line = f.readline()...
true
1009/C
1009
C
Python 3
TESTS
38
327
0
40388197
from sys import stdin from math import * line = stdin.readline().rstrip().split() n = int(line[0]) m = int(line[1]) bigNum = n*(n-1)/2 smallN = int(floor((n-1)/2)) bigN = (n-1) - smallN smallNum = smallN*(smallN+1)/2 smallNum2 = bigN*(bigN+1)/2 total = 0 for i in range(m): line = stdin.readline().rstrip().split() ...
54
249
6,656,000
137936583
#OMM NAMH SHIVAY #JAI SHREE RAM import sys,math,heapq,queue fast_input=sys.stdin.readline n,m=map(int,fast_input().split()) s=0 r=(n+1)//2 r-=1 for _ in range(m): x,d=map(int,fast_input().split()) s+=n*x if d>=0: s+=d*(n-1)*(n)//2 else: s+=d*(r)*(r+1) if n%2==0: ...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Annoying Present
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $$$m$$$ changes of the following form. For s...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
null
null
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
1,700
["greedy", "math"]
54
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n"...
false
stdio
import sys import math def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: expected_line = f.readline().strip() expected = float(expected_line) with open(submission_path) as f: submission_line = f.readline()...
true
1009/C
1009
C
Python 3
TESTS
38
327
307,200
78990446
n, changes = map(int, input().split()) answer = 0 def summation(n): return ((n - 1) * (n)) / 2 def negative_summation(n): if n % 2 == 1: weigth = summation(n // 2 + 1) * 2 else: weigth = (summation((n // 2 + 1) - 1) * 2) + n // 2 return weigth negative_impact = negative_summation(...
54
265
5,222,400
71522430
import sys input = sys.stdin.readline n, m = map(int, input().split()) S = 0 for _ in range(m): x, d = map(int, input().split()) S += n*x if d>=0: S += n*(n-1)//2*d else: m = n//2 S += 2*(m+1)*m//2*d if n%2==0: S -= m*d print(S/n)
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Annoying Present
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $$$m$$$ changes of the following form. For s...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
null
null
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
1,700
["greedy", "math"]
54
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n"...
false
stdio
import sys import math def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: expected_line = f.readline().strip() expected = float(expected_line) with open(submission_path) as f: submission_line = f.readline()...
true
1009/C
1009
C
Python 3
TESTS
38
358
2,867,200
46817779
n, m = map(int, input().split()) mean = 0 mi = sum([abs(n // 2 - j) for j in range(n)]) ma = (n * (n - 1)) // 2 for i in range(m): x, d = map(int, input().split()) mean += x if d < 0:mean += (d * mi) / n else: mean += (d * ma) / n print('%.15f' % mean)
54
265
6,144,000
121144475
from sys import stdin,stdout from math import gcd,sqrt,factorial,pi,inf from collections import deque,defaultdict from bisect import bisect,bisect_left from time import time from itertools import permutations as per from heapq import heapify,heappush,heappop,heappushpop input=stdin.readline R=lambda:map(int,input().spl...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Annoying Present
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $$$m$$$ changes of the following form. For s...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
null
null
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
1,700
["greedy", "math"]
54
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n"...
false
stdio
import sys import math def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: expected_line = f.readline().strip() expected = float(expected_line) with open(submission_path) as f: submission_line = f.readline()...
true
623/C
623
C
PyPy 3-64
TESTS
1
108
9,420,800
164070867
from sys import stdin, stdout, maxsize from typing import List def sdiameter_axes(axis_one, axes_two): return int(pow(axis_one-axes_two, 2)) def sdiameter_xy(x, y): return int(pow(x, 2))+int(pow(y, 2)) prefix_max_y = None sufix_max_y = None prefix_min_y =None sufix_min_y = None def check(D, n, points): ...
176
1,450
23,449,600
164355894
from sys import stdin, stdout, maxsize from typing import List def sdiameter_axes(axis_one, axes_two): """calcula el diametro**2 entre elementos de un mismo eje""" return int(pow(axis_one-axes_two, 2)) def sdiameter_xy(x, y): """calcula el diametro**2 entre elementos de ambos ejes""" return int(pow(x,...
AIM Tech Round (Div. 1)
CF
2,016
2
256
Electric Charges
Programmer Sasha is a student at MIPT (Moscow Institute of Physics and Technology) and he needs to make a laboratory work to pass his finals. A laboratory unit is a plane with standard coordinate axes marked on it. Physicists from Moscow Institute of Physics and Technology charged the axes by large electric charges: a...
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of points marked on the plane. Each of the next n lines contains two integers xi and yi ( - 108 ≤ xi, yi ≤ 108) — the coordinates of the i-th point. It is guaranteed that no two points coincide.
Print a single integer — the square of the minimum possible diameter of the set.
null
In the first sample Sasha puts electrons at all points, all particles eventually fall at a single point (1, 0). In the second sample Sasha puts an electron at point (1, 10), and a proton at point (10, 1). The result is a set of two points (1, 0) and (0, 1), which has a diameter of $$\sqrt{2}$$.
[{"input": "3\n1 10\n1 20\n1 30", "output": "0"}, {"input": "2\n1 10\n10 1", "output": "2"}]
2,900
["binary search", "dp"]
176
[{"input": "3\r\n1 10\r\n1 20\r\n1 30\r\n", "output": "0\r\n"}, {"input": "2\r\n1 10\r\n10 1\r\n", "output": "2\r\n"}, {"input": "10\r\n1 6\r\n2 2\r\n-1 9\r\n-8 8\r\n-4 10\r\n-10 -6\r\n5 -1\r\n-3 -7\r\n-4 3\r\n9 4\r\n", "output": "100\r\n"}, {"input": "18\r\n-14 -745\r\n87 -4611\r\n89 -3748\r\n-77 273\r\n-21 -4654\r\n-...
false
stdio
null
true
540/C
540
C
Python 3
TESTS
22
841
13,107,200
115861597
dx = [0, 0, -1, 1] dy = [-1, 1, 0, 0] def getNum(cell, n, m): return cell[0] * m + cell[1] def getCell(number, n, m): return [number // m, number % m] def isValidCell(cell, maze): n = len(maze) m = len(maze[0]) return (0 <= cell[0] < n) and (0 <= cell[1] < m) and (maze[cell[0]][cell[1]] == '.') ...
102
155
10,342,400
207369811
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(x, y): q, k = [f(x, y)], 0 visit = [0] * (n * m) visit[f(x, y)] = 1 while len(q) ^ k: x, y = divmod(q[k], m) for dx, dy in v: nx, ny = x + dx, y + dy ...
Codeforces Round 301 (Div. 2)
CF
2,015
2
256
Ice Cave
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists e...
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integer...
If you can reach the destination, print 'YES', otherwise print 'NO'.
null
In the first sample test one possible path is: $$(1,6)\rightarrow(2,6)\rightarrow(3,6)\rightarrow(4,5)\rightarrow(4,4)\rightarrow(4,3)\rightarrow(4,2)\rightarrow(4,1)\rightarrow(3,2)\rightarrow(2,3)\rightarrow(2,2)$$ After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time...
[{"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "output": "YES"}, {"input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "output": "NO"}, {"input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "output": "YES"}]
2,000
["dfs and similar"]
102
[{"input": "4 6\r\nX...XX\r\n...XX.\r\n.X..X.\r\n......\r\n1 6\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n.X..\r\n...X\r\nX.X.\r\n....\r\n.XX.\r\n5 3\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "4 7\r\n..X.XX.\r\n.XX..X.\r\nX...X..\r\nX......\r\n2 2\r\n1 6\r\n", "output": "YES\r\n"}, {"input": "5 3\r\n.XX\r\n...
false
stdio
null
true
721/B
721
B
Python 3
TESTS
12
46
0
185453619
limit = [int(i) for i in input().split(" ")] password_len = {} for i in range(limit[0]): a = str(len(input())) if(a in password_len): password_len[a] += 1 else: password_len[a] = 1 right_password_len = str(len(input())) best = 0 worst = 0 key_sort = sorted(password_len.keys()) for i in k...
66
46
0
156747876
n, k = map(int, input().split()) l_l = list() for _ in range(n): l_l.append(len(input())) p = len(input()) h_t = 0 l_t = 0 for l in l_l: if l < p: h_t += 1 l_t += 1 elif l == p: h_t += 1 l_t += 1 print("%d %d" % (l_t + ((l_t - 1) // k) * 5, h_t + ((h_t - 1) // k) * 5))
Codeforces Round 374 (Div. 2)
CF
2,016
2
256
Passwords
Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrar...
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters a...
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
null
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente...
[{"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15"}, {"input": "4 100\n11\n22\n1\n2\n22", "output": "3 4"}]
1,100
["implementation", "math", "sortings", "strings"]
66
[{"input": "5 2\r\ncba\r\nabc\r\nbb1\r\nabC\r\nABC\r\nabc\r\n", "output": "1 15\r\n"}, {"input": "4 100\r\n11\r\n22\r\n1\r\n2\r\n22\r\n", "output": "3 4\r\n"}, {"input": "1 1\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "1 100\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "2 1\r\nabc\r\nAbc\r\nAbc\r\n", "outpu...
false
stdio
null
true
382/C
382
C
Python 3
TESTS
52
155
8,089,600
199726620
def c(n, s): if n == 1: return -1, [] if n == 2: a, b = s[0], s[1] if b - a == 0: return 1, [a] elif (b - a) % 2: return 2, [a * 2 - b, 2 * b - a] else: return 3, [a * 2 - b, (a + b) // 2, b * 2 - a] d = {} for i in range(1, n):...
59
202
8,499,200
16543710
n = int(input()) a = sorted(list(map(int, input().split(' ')))) if n == 1: print(-1) exit() if n == 2 and (a[1]-a[0])%2 == 0 and a[0] != a[1]: print(3) print(2*a[0]-a[1], (a[0]+a[1])//2, 2*a[1]-a[0]) exit() m = [a[i]-a[i-1] for i in range(1, n)] if len(set(m)) == 1: if m[0] != 0: pri...
Codeforces Round 224 (Div. 2)
CF
2,014
1
256
Arithmetic Progression
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1. For example, sequences [1, 5], [10], [5,...
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples)...
null
null
[{"input": "3\n4 1 7", "output": "2\n-2 10"}, {"input": "1\n10", "output": "-1"}, {"input": "4\n1 3 5 9", "output": "1\n7"}, {"input": "4\n4 3 4 5", "output": "0"}, {"input": "2\n2 4", "output": "3\n0 3 6"}]
1,700
["implementation", "sortings"]
59
[{"input": "3\r\n4 1 7\r\n", "output": "2\r\n-2 10\r\n"}, {"input": "1\r\n10\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 3 5 9\r\n", "output": "1\r\n7\r\n"}, {"input": "4\r\n4 3 4 5\r\n", "output": "0\r\n"}, {"input": "2\r\n2 4\r\n", "output": "3\r\n0 3 6\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "1\r\n2\r\n"}, {...
false
stdio
null
true
808/E
808
E
PyPy 3
TESTS
13
202
3,993,600
68076673
import sys n, m = map(int, input().split()) w1 = [10**9] w2 = [10**9] w3 = [10**9] for w, c in (map(int, l.split()) for l in sys.stdin): if w == 1: w1.append(c) elif w == 2: w2.append(c) else: w3.append(c) w1.sort(reverse=True) w1[0] = 0 for i in range(len(w1)-1): w1[i+1] += w1...
73
358
41,062,400
134594762
import sys input = sys.stdin.readline n, m = map(int, input().split()) w1, w2, w3 = [], [], [] for _ in range(n): w, c = map(int, input().split()) if w == 1: w1.append(c) elif w == 2: w2.append(c) else: w3.append(c) w1.sort(reverse = True) w2.sort(reverse = True) w3.sort(reverse...
Educational Codeforces Round 21
ICPC
2,017
2
256
Selling Souvenirs
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market. This morning, as us...
The first line contains two integers n and m (1 ≤ n ≤ 100000, 1 ≤ m ≤ 300000) — the number of Petya's souvenirs and total weight that he can carry to the market. Then n lines follow. ith line contains two integers wi and ci (1 ≤ wi ≤ 3, 1 ≤ ci ≤ 109) — the weight and the cost of ith souvenir.
Print one number — maximum possible total cost of souvenirs that Petya can carry to the market.
null
null
[{"input": "1 1\n2 1", "output": "0"}, {"input": "2 2\n1 3\n2 2", "output": "3"}, {"input": "4 3\n3 10\n2 7\n2 8\n1 1", "output": "10"}]
2,300
["binary search", "dp", "greedy", "ternary search"]
73
[{"input": "1 1\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "4 3\r\n3 10\r\n2 7\r\n2 8\r\n1 1\r\n", "output": "10\r\n"}, {"input": "5 5\r\n3 5\r\n2 6\r\n3 2\r\n1 1\r\n1 6\r\n", "output": "13\r\n"}, {"input": "6 6\r\n1 6\r\n1 4\r\n1 8\r\n3 2\r\n3 2\r\n2 8\r\n", "outp...
false
stdio
null
true
732/B
732
B
Python 3
TESTS
9
46
0
203738603
n , k = map(int , input().split()) l = list(map(int , input().split())) pt1 , pt2 , add, resadd = 0 , 1 , 0 ,0 while pt2 != n : if l[pt1] +l[pt2] < k : add = k - (l[pt1] +l[pt2]) if l[pt1] < l[pt2] : l[pt1] += add else : l[pt2] += add resadd += add ...
70
46
0
194111857
n,k = map(int,input().split()) lis = list(map(int,input().split())) s1 = 0 s = 0 s += lis[0] s1 += lis[0] for i in range(1,n): z = lis[i-1]+lis[i] if z <=k: s += lis[i] lis[i] = k - lis[i-1] s1 += lis[i] print(s1-s) for i in lis: print(i,end=" ")
Codeforces Round 377 (Div. 2)
CF
2,016
1
256
Cormen — The Best Friend Of a Man
Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk. Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a ...
The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of days and the minimum number of walks with Cormen for any two consecutive days. The second line contains integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned.
In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days. In the second line print n integers b1, b2, ..., bn, where bi — the total number of walks on the i-th day according to the found solutions (ai ≤ bi for all i fro...
null
null
[{"input": "3 5\n2 0 1", "output": "4\n2 3 2"}, {"input": "3 1\n0 0 0", "output": "1\n0 1 0"}, {"input": "4 6\n2 4 3 5", "output": "0\n2 4 3 5"}]
1,000
["dp", "greedy"]
70
[{"input": "3 5\r\n2 0 1\r\n", "output": "4\r\n2 3 2\r\n"}, {"input": "3 1\r\n0 0 0\r\n", "output": "1\r\n0 1 0\r\n"}, {"input": "4 6\r\n2 4 3 5\r\n", "output": "0\r\n2 4 3 5\r\n"}, {"input": "5 1\r\n0 0 0 0 1\r\n", "output": "2\r\n0 1 0 1 1\r\n"}, {"input": "10 500\r\n164 44 238 205 373 249 87 30 239 90\r\n", "output"...
false
stdio
null
true
732/B
732
B
Python 3
TESTS
9
31
0
190829496
a,b=map(int,input().split()) x=[int(i)for i in input().split()] s=0 for i in range(1,len(x)): if x[i]+x[i-1]<b: if x[i]<=x[i-1]: s+=b-x[i-1]-x[i] x[i]=b-x[i-1] else: s+=b-x[i]-x[i+1] x[i-1]=b-x[i] print(s) print(*x)
70
46
0
195054740
a = input().split() b = input().split() k = 0 k1 = '' for i in range(len(a)): a[i] = int(a[i]) for i in range(len(b)): b[i] = int(b[i]) for i in range(len(b)-1): sum2 = b[i]+b[i+1] if sum2 < a[1]: b[i+1] = b[i+1]+(a[1] - sum2) k += (a[1] - sum2) for i in range(len(b)): k1 += str(b[i]...
Codeforces Round 377 (Div. 2)
CF
2,016
1
256
Cormen — The Best Friend Of a Man
Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk. Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a ...
The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of days and the minimum number of walks with Cormen for any two consecutive days. The second line contains integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned.
In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days. In the second line print n integers b1, b2, ..., bn, where bi — the total number of walks on the i-th day according to the found solutions (ai ≤ bi for all i fro...
null
null
[{"input": "3 5\n2 0 1", "output": "4\n2 3 2"}, {"input": "3 1\n0 0 0", "output": "1\n0 1 0"}, {"input": "4 6\n2 4 3 5", "output": "0\n2 4 3 5"}]
1,000
["dp", "greedy"]
70
[{"input": "3 5\r\n2 0 1\r\n", "output": "4\r\n2 3 2\r\n"}, {"input": "3 1\r\n0 0 0\r\n", "output": "1\r\n0 1 0\r\n"}, {"input": "4 6\r\n2 4 3 5\r\n", "output": "0\r\n2 4 3 5\r\n"}, {"input": "5 1\r\n0 0 0 0 1\r\n", "output": "2\r\n0 1 0 1 1\r\n"}, {"input": "10 500\r\n164 44 238 205 373 249 87 30 239 90\r\n", "output"...
false
stdio
null
true
928/B
928
B
PyPy 3
TESTS
101
327
31,027,200
35816823
s = input().split() n = int(s[0]) k = int(s[1]) a = [int(i) for i in input().split()] if n < k+2: print(str(n)+(' ' + str(n))*(n-1)) else: twok = k*2+1 counts = [] for i in range(1, k+1): counts.append(i + k) for i in range(k+1, n-k): if a[i-1] == 0: counts.append(twok)...
118
109
18,636,800
188658526
n, k = map(int, input().split()) a = list(map(int, input().split())) dp = [0] * n for i in range(n): if a[i] == 0: s = min(k, i) + 1 else: s = dp[a[i] - 1] + min(2 * k, i - a[i]) + 1 dp[i] = s an = [] for i in range(n): an.append(str(dp[i] + min(k, n - i - 1))) print(" ".join(an))
VK Cup 2018 - Квалификация 1
CF
2,018
1
256
Chat
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago. More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to...
The first line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ n) — the total amount of messages and the number of previous and next messages visible. The second line features a sequence of integers a1, a2, ..., an (0 ≤ ai < i), where ai denotes the i-th message link destination or zero, if there's no link from i....
Print n integers with i-th denoting the number of distinct messages you can read starting from message i and traversing the links while possible.
null
Consider i = 6 in sample case one. You will read message 6, then 2, then 1 and then there will be no link to go. In the second sample case i = 6 gives you messages 5, 6, 7 since k = 1, then 4, 5, 6, then 2, 3, 4 and then the link sequence breaks. The number of distinct messages here is equal to 6.
[{"input": "6 0\n0 1 1 2 3 2", "output": "1 2 2 3 3 3"}, {"input": "10 1\n0 1 0 3 4 5 2 3 7 0", "output": "2 3 3 4 5 6 6 6 8 2"}, {"input": "2 2\n0 1", "output": "2 2"}]
1,400
["*special", "dp"]
118
[{"input": "6 0\r\n0 1 1 2 3 2\r\n", "output": "1 2 2 3 3 3 \r\n"}, {"input": "10 1\r\n0 1 0 3 4 5 2 3 7 0\r\n", "output": "2 3 3 4 5 6 6 6 8 2 \r\n"}, {"input": "2 2\r\n0 1\r\n", "output": "2 2 \r\n"}, {"input": "1 1\r\n0\r\n", "output": "1 \r\n"}, {"input": "5 2\r\n0 1 2 3 1\r\n", "output": "3 4 5 5 5 \r\n"}, {"input...
false
stdio
null
true
493/B
493
B
Python 3
TESTS
37
405
5,529,600
8960253
n = int(input()) a = [] b = [] last = 0 for i in range(n): q = int(input()) if q > 0: a.append(q) last = 1 else: b.append(-q) last = 2 sum1 = sum(a) sum2 = sum(b) if sum1 > sum2: print('first') elif sum1 < sum2: print('second') else: s1 = ' '.join(map(str, a))...
57
202
14,131,200
125235884
#import collections # import random # import math #import itertools #import math #mport math from collections import defaultdict # import itertools # from sys import stdin, stdout #import math import sys # import operator # from decimal import Decimal # sys.setrecursionlimit(10**6) p2D = lambda x: print(*x, sep="\n")...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Wrestling
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105). The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that mea...
If the first wrestler wins, print string "first", otherwise print "second"
null
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. We use notation |a| to denote lengt...
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
1,400
["implementation"]
57
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-...
false
stdio
null
true
493/B
493
B
Python 3
TESTS
37
374
5,734,400
67468925
f=[] s=[] l=-1 for _ in range(int(input())): x = int(input()) if x<0: s.append(-x) l=1 else: f.append(x) l=0 if sum(f)>sum(s): print('first') elif sum(f)<sum(s): print("second") else: if f == s: print("fsiercsotn d"[l::2]) elif str(f)<str(s): ...
57
249
5,632,000
103979422
import sys input = sys.stdin.buffer.readline n = int(input()) w1=0 w2=0 s1=[] s2=[] last = 0 for i in range(n): pts = int(input()) if pts>0: s1.append(pts) w1+=pts else: s2.append(abs(pts)) w2+=abs(pts) if i==n-1: last = pts mini = min(len(s1),len(s2)) gre = 0 f...
Codeforces Round 281 (Div. 2)
CF
2,014
2
256
Vasya and Wrestling
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105). The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that mea...
If the first wrestler wins, print string "first", otherwise print "second"
null
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. We use notation |a| to denote lengt...
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
1,400
["implementation"]
57
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-...
false
stdio
null
true
849/B
849
B
Python 3
TESTS
25
93
7,065,600
36772636
def solve(curr_slope,s,i): if len(s)==1: return True elif curr_slope==i: return True else: return False n=int(input()) arr=list(map(int,input().split())) d={} for i in range(1,len(arr)): slope=(arr[i]-arr[0])/float(i) if slope in d.keys(): d[slope].add(i) else: d[slope]=set([i]) ans=0 #...
52
62
307,200
29993038
def test(id1,id2,l,n): a = l[id1] - l[id2] b = id2 - id1 c = ((id1)*l[id2]) - ((id2)*l[id1]) d=[] for i in range(n): if a*i+b*l[i]+c!=0: d+=[i] if len(d)==0:return False if len(d)==1:return True aa = l[d[0]] - l[d[1]] bb = d[1] - d[0] cc = ((d[0])*l[d[1]]) - ((d[1])*l[d[0]]) for i in range(len(d)): ...
Codeforces Round 431 (Div. 2)
CF
2,017
1
256
Tell Your World
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, yi). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes th...
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points. The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower).
null
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, ...
[{"input": "5\n7 5 8 6 9", "output": "Yes"}, {"input": "5\n-1 -2 0 0 -5", "output": "No"}, {"input": "5\n5 4 3 2 1", "output": "No"}, {"input": "5\n1000000000 0 0 0 0", "output": "Yes"}]
1,600
["brute force", "geometry"]
52
[{"input": "5\r\n7 5 8 6 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-1 -2 0 0 -5\r\n", "output": "No\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "No\r\n"}, {"input": "5\r\n1000000000 0 0 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1000000000 1 0 -999999999 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "...
false
stdio
null
true
849/B
849
B
Python 3
TESTS
30
62
307,200
30013136
points = int(input()) y = list(map(int, input().split())) def slope(p1, p2): return (p2[1] - p1[1])/(p2[0] - p1[0]) def passes(one, two, point): return 0 == (one[0] * (two[1] - point[1]) + two[0] * (point[1] - one[1]) + point[0] * (one[1] - two[1])) def possible(start, joint, coords): others = list() ...
52
62
307,200
30000585
n=int(input()) y=list(map(int,input().split())) def check(d): return len(set(2*yi-d*i for i,yi in enumerate(y)))==2 print('Yes' if any(check(d) for d in [2*(y[1]-y[0]),2*(y[2]-y[1]),y[2]-y[0]]) else 'No')
Codeforces Round 431 (Div. 2)
CF
2,017
1
256
Tell Your World
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, yi). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes th...
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points. The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower).
null
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, ...
[{"input": "5\n7 5 8 6 9", "output": "Yes"}, {"input": "5\n-1 -2 0 0 -5", "output": "No"}, {"input": "5\n5 4 3 2 1", "output": "No"}, {"input": "5\n1000000000 0 0 0 0", "output": "Yes"}]
1,600
["brute force", "geometry"]
52
[{"input": "5\r\n7 5 8 6 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-1 -2 0 0 -5\r\n", "output": "No\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "No\r\n"}, {"input": "5\r\n1000000000 0 0 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1000000000 1 0 -999999999 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "...
false
stdio
null
true
382/C
382
C
PyPy 3-64
TESTS
8
61
0
221797324
import sys input = sys.stdin.readline s = dict() n = int(input()) w = sorted(map(int, input().split())) if n == 1: print(-1) exit() elif n == 2: a = w[1]-w[0] if a == 0: print(1) print(w[0]) elif a % 2: print(2) print(w[0]-a, w[1]+a) else: print(3) ...
59
217
10,649,600
51560982
n = int(input()) a = list(map(int,input().split())) a.sort() r = 0 res = [] 'Función para revisar si el arreglo es una progresión aritmética' def isAri(a): diff = a[1]-a[0] for i in range(len(a)-1): if not (a[i+1]-a[i]==diff): return False return True if(n==1): print(-1) elif(isAri(a) and a[1]-a[0...
Codeforces Round 224 (Div. 2)
CF
2,014
1
256
Arithmetic Progression
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1. For example, sequences [1, 5], [10], [5,...
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples)...
null
null
[{"input": "3\n4 1 7", "output": "2\n-2 10"}, {"input": "1\n10", "output": "-1"}, {"input": "4\n1 3 5 9", "output": "1\n7"}, {"input": "4\n4 3 4 5", "output": "0"}, {"input": "2\n2 4", "output": "3\n0 3 6"}]
1,700
["implementation", "sortings"]
59
[{"input": "3\r\n4 1 7\r\n", "output": "2\r\n-2 10\r\n"}, {"input": "1\r\n10\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 3 5 9\r\n", "output": "1\r\n7\r\n"}, {"input": "4\r\n4 3 4 5\r\n", "output": "0\r\n"}, {"input": "2\r\n2 4\r\n", "output": "3\r\n0 3 6\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "1\r\n2\r\n"}, {...
false
stdio
null
true
382/C
382
C
PyPy 3-64
TESTS
8
93
4,915,200
199923752
from collections import Counter , defaultdict , deque from bisect import bisect_left , bisect_right from copy import deepcopy from math import ceil , floor , sqrt , lcm , gcd , comb from heapq import heapify , heappop , heappush , nlargest , nsmallest from itertools import accumulate, combinations, permutations from fu...
59
218
31,948,800
124461592
import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) a.sort() if n==1: print(-1) exit() if n==2: d=a[1]-a[0] if d%2==0: ans=[a[0]-d,a[0]+d//2,a[1]+d] ans=list(set(ans)) ans.sort() print(len(ans)) print(*ans) else: ans=[a[...
Codeforces Round 224 (Div. 2)
CF
2,014
1
256
Arithmetic Progression
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1. For example, sequences [1, 5], [10], [5,...
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples)...
null
null
[{"input": "3\n4 1 7", "output": "2\n-2 10"}, {"input": "1\n10", "output": "-1"}, {"input": "4\n1 3 5 9", "output": "1\n7"}, {"input": "4\n4 3 4 5", "output": "0"}, {"input": "2\n2 4", "output": "3\n0 3 6"}]
1,700
["implementation", "sortings"]
59
[{"input": "3\r\n4 1 7\r\n", "output": "2\r\n-2 10\r\n"}, {"input": "1\r\n10\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 3 5 9\r\n", "output": "1\r\n7\r\n"}, {"input": "4\r\n4 3 4 5\r\n", "output": "0\r\n"}, {"input": "2\r\n2 4\r\n", "output": "3\r\n0 3 6\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "1\r\n2\r\n"}, {...
false
stdio
null
true
216/B
216
B
PyPy 3-64
TESTS
23
124
0
217913801
thisSeen = 1 seen = dict() vertcies, edges = list(map(int, input().split())) adj = [[]] for i in range(1, vertcies+1): adj.append([]) seen[i] = 0 for i in range(edges): v, u = list(map(int, input().split())) adj[v].append(u) adj[u].append(v) visited = [False] * (vertcies+1) cycles = 0 for i in range(1, ver...
56
92
0
148234199
def dfs(cur_node, parent_node, reference, visited): if cur_node in visited: return True visited.add(cur_node) for child_node in graph[cur_node]: if child_node != parent_node: reference["count"] += 1 if dfs(child_node, cur_node, reference, visited): ret...
Codeforces Round 133 (Div. 2)
CF
2,012
2
256
Forming Teams
One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people. We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B ...
The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the indexes of the students who are enemi...
Print a single integer — the minimum number of students you will have to send to the bench in order to start the game.
null
null
[{"input": "5 4\n1 2\n2 4\n5 3\n1 4", "output": "1"}, {"input": "6 2\n1 4\n3 4", "output": "0"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "2"}]
1,700
["dfs and similar", "implementation"]
56
[{"input": "5 4\r\n1 2\r\n2 4\r\n5 3\r\n1 4\r\n", "output": "1"}, {"input": "6 2\r\n1 4\r\n3 4\r\n", "output": "0"}, {"input": "6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n", "output": "2"}, {"input": "5 1\r\n1 2\r\n", "output": "1"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 1\r\n", "ou...
false
stdio
null
true
216/B
216
B
PyPy 3-64
TESTS
23
122
0
217904359
thisSeen = 1 seen = dict() vertcies, edges = list(map(int, input().split())) adj = [[]] for i in range(1, vertcies+1): adj.append([]) seen[i] = 0 for i in range(edges): v, u = list(map(int, input().split())) adj[v].append(u) adj[u].append(v) visited = [False] * (vertcies+1) cycles = 0 for i in range(1, ver...
56
92
0
153409902
def detect_cycle(node, parent, visited, graph, ref): visited.add(node) ref["count"] += 1 for neighbor in graph[node]: if neighbor == parent: continue if neighbor not in visited: if detect_cycle(neighbor, node, visited, graph, ref): return True ...
Codeforces Round 133 (Div. 2)
CF
2,012
2
256
Forming Teams
One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people. We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B ...
The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of students and the number of pairs of archenemies correspondingly. Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the indexes of the students who are enemi...
Print a single integer — the minimum number of students you will have to send to the bench in order to start the game.
null
null
[{"input": "5 4\n1 2\n2 4\n5 3\n1 4", "output": "1"}, {"input": "6 2\n1 4\n3 4", "output": "0"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "2"}]
1,700
["dfs and similar", "implementation"]
56
[{"input": "5 4\r\n1 2\r\n2 4\r\n5 3\r\n1 4\r\n", "output": "1"}, {"input": "6 2\r\n1 4\r\n3 4\r\n", "output": "0"}, {"input": "6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n", "output": "2"}, {"input": "5 1\r\n1 2\r\n", "output": "1"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 1\r\n", "ou...
false
stdio
null
true
849/B
849
B
Python 3
TESTS
16
31
0
178625289
def new(iota, k1): z=len(iota) #print(iota, k1) if z==0: pass elif z==1: return 1 else: c1=iota[1][0]-iota[0][0] d1=iota[1][1]-iota[0][1] e1=d1*iota[0][0]-c1*iota[0][1] #print(2*c1, k1*d1) if 2*c1!=k1*d1: pass else: ...
52
62
307,200
30104007
import sys n = int(input()) arr = list(map(int, input().split())) com = [(0,1), (0,2), (1,2)] for i in com: # y = ax + b a = (arr[i[0]] - arr[i[1]]) / (i[0] - i[1]) b1 = arr[i[0]] - a * (i[0] + 1) b2 = b1 flag = True for j in range(len(arr)): if arr[j] != a * (j+1) + b1 and b2 == b1: ...
Codeforces Round 431 (Div. 2)
CF
2,017
1
256
Tell Your World
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, yi). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes th...
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points. The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower).
null
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, ...
[{"input": "5\n7 5 8 6 9", "output": "Yes"}, {"input": "5\n-1 -2 0 0 -5", "output": "No"}, {"input": "5\n5 4 3 2 1", "output": "No"}, {"input": "5\n1000000000 0 0 0 0", "output": "Yes"}]
1,600
["brute force", "geometry"]
52
[{"input": "5\r\n7 5 8 6 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-1 -2 0 0 -5\r\n", "output": "No\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "No\r\n"}, {"input": "5\r\n1000000000 0 0 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1000000000 1 0 -999999999 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "...
false
stdio
null
true
138/A
138
A
PyPy 3-64
TESTS
59
216
6,758,400
211278552
import sys input = lambda: sys.stdin.readline().rstrip() A = {1:'aabb',2:'abab',4:'abba',7:'aaaa'} def check(dat): ans = 0 if dat[0]==dat[1] and dat[2]==dat[3]: ans^=1 if dat[0]==dat[2] and dat[1]==dat[3]: ans^=2 if dat[0]==dat[3] and dat[1]==dat[2]: ans^=4 return ans n,k ...
80
590
6,758,400
114144687
n,k=list(map(int,input().split())) def z(a,b): global k c=0 d='' for i in range(len(a)-1,-1,-1): d+=a[i] if a[i] in ['a','e','i','o','u']: c+=1 if c==k: break f=c==k c=0 e='' for i in range(len(b)-1,-1,-1): e+=b[i] if b[i] i...
Codeforces Beta Round 99 (Div. 1)
CF
2,011
2
256
Literature Lesson
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels. Two lines rhyme if their ...
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104. If we assume that the...
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
null
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
[{"input": "1 1\nday\nmay\nsun\nfun", "output": "aabb"}, {"input": "1 1\nday\nmay\ngray\nway", "output": "aaaa"}, {"input": "2 1\na\na\na\na\na\na\ne\ne", "output": "aabb"}, {"input": "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill", "output": "NO"}]
1,600
["implementation"]
80
[{"input": "1 1\r\nday\r\nmay\r\nsun\r\nfun\r\n", "output": "aabb\r\n"}, {"input": "1 1\r\nday\r\nmay\r\ngray\r\nway\r\n", "output": "aaaa\r\n"}, {"input": "2 1\r\na\r\na\r\na\r\na\r\na\r\na\r\ne\r\ne\r\n", "output": "aabb\r\n"}, {"input": "2 1\r\nday\r\nmay\r\nsun\r\nfun\r\ntest\r\nhill\r\nfest\r\nthrill\r\n", "output...
false
stdio
null
true
731/B
731
B
PyPy 3-64
TESTS
1
46
0
196082422
# 4 # 1 2 1 2 n=int(input()) l=[*map(int,input().split())] i = 0 for i in range(n): if l[i] % 2: if i < n-1: l[i+1] -= 1 else: print('no') exit(0) print('yes')
79
109
22,630,400
196082455
n=int(input()) l=list(map(int,input().split())) for i in range(n-1): if l[i]<0: print('NO') exit() if l[i]%2==1: l[i+1]-=1 if l[-1]%2==1:print('NO') else:print('YES')
Codeforces Round 376 (Div. 2)
CF
2,016
1
256
Coupons and Discounts
The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu...
The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days.
If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes).
null
In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample. In the second sample, Sereja can't use neither the coupon n...
[{"input": "4\n1 2 1 2", "output": "YES"}, {"input": "3\n1 0 1", "output": "NO"}]
1,100
["constructive algorithms", "greedy"]
79
[{"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n179\r\n", "output": "NO\r\n"}, {"input": "10\r\n0 0 5 9 9 3 0 0 0 10\r\n", "output": "YES\r\n"}, {"inpu...
false
stdio
null
true
731/B
731
B
Python 3
TESTS
21
139
12,595,200
202944564
t = int(input()) a = [int(_) for _ in input().split()] h = [] counting = False g = [] for i in a: if i != 0 and not counting: g.append(i) counting = True elif i == 0: counting = False h.append(g) g = [] else: g.append(i) h.append(g) j = sorted(h, key=lambda x:...
79
124
16,793,600
193079684
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) a = list(map(int, input().split())) + [0] c = 0 ans = "YES" for i in a: if not i and c % 2: ans = "NO" break c += i print(ans)
Codeforces Round 376 (Div. 2)
CF
2,016
1
256
Coupons and Discounts
The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu...
The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days.
If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes).
null
In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample. In the second sample, Sereja can't use neither the coupon n...
[{"input": "4\n1 2 1 2", "output": "YES"}, {"input": "3\n1 0 1", "output": "NO"}]
1,100
["constructive algorithms", "greedy"]
79
[{"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n179\r\n", "output": "NO\r\n"}, {"input": "10\r\n0 0 5 9 9 3 0 0 0 10\r\n", "output": "YES\r\n"}, {"inpu...
false
stdio
null
true
220/A
220
A
Python 3
TESTS
32
171
8,704,000
85587818
n = int(input()) *l, = map(int, input().split()) s = [] for i in range(n-1): s.append(l[i] > l[i+1]) t = s.count(True) if t==0 or t==1: print("YES") elif t==2: r1 = s.index(True) r2 = s.index(True, r1+1) if l[r1] >= l[r2+1]: print("YES") else: print("NO") else: print("NO")
96
93
13,516,800
199859703
n=int(input()) l=list(map(int,input().split())) s=sorted(l) c,i=0,0 for i in range(n): if l[i]!=s[i]: c=c+1 if c>2: break if c==2 or c==0: print('YES') else: print('NO')
Codeforces Round 136 (Div. 1)
CF
2,012
2
256
Little Elephant and Problem
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could ...
The first line contains a single integer n (2 ≤ n ≤ 105) — the size of array a. The next line contains n positive integers, separated by single spaces and not exceeding 109, — array a. Note that the elements of the array are not necessarily distinct numbers.
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
null
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES". In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES". In the third sample we ...
[{"input": "2\n1 2", "output": "YES"}, {"input": "3\n3 2 1", "output": "YES"}, {"input": "4\n4 3 2 1", "output": "NO"}]
1,300
["implementation", "sortings"]
96
[{"input": "2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n7 7 8 8 10 10 10 10 1000000000\r\n", "output": "YES\r\n"...
false
stdio
null
true
540/C
540
C
Python 3
TESTS
4
61
5,017,600
161765142
import queue import sys from queue import Queue def FILE_IO(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def get_input(): n, m = map(int, input().strip().split()) cave = [] for i in range(n): cave.append(list(input().strip())) sn, sm = map(int, input()....
102
170
17,612,800
229996302
n, m = map(int, input().split()) cave = [] for _ in range(n): cave.append([c for c in input().strip()]) start_x, start_y = map(int, input().split()) dest_x, dest_y = map(int, input().split()) visited = [] for _ in range(n): visited.append([0] * m) dx = [0, 0, -1, 1] dy = [-1, 1, 0, 0] queue = [] queue.appe...
Codeforces Round 301 (Div. 2)
CF
2,015
2
256
Ice Cave
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists e...
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integer...
If you can reach the destination, print 'YES', otherwise print 'NO'.
null
In the first sample test one possible path is: $$(1,6)\rightarrow(2,6)\rightarrow(3,6)\rightarrow(4,5)\rightarrow(4,4)\rightarrow(4,3)\rightarrow(4,2)\rightarrow(4,1)\rightarrow(3,2)\rightarrow(2,3)\rightarrow(2,2)$$ After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time...
[{"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "output": "YES"}, {"input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "output": "NO"}, {"input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "output": "YES"}]
2,000
["dfs and similar"]
102
[{"input": "4 6\r\nX...XX\r\n...XX.\r\n.X..X.\r\n......\r\n1 6\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n.X..\r\n...X\r\nX.X.\r\n....\r\n.XX.\r\n5 3\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "4 7\r\n..X.XX.\r\n.XX..X.\r\nX...X..\r\nX......\r\n2 2\r\n1 6\r\n", "output": "YES\r\n"}, {"input": "5 3\r\n.XX\r\n...
false
stdio
null
true
540/C
540
C
PyPy 3-64
TESTS
4
93
5,120,000
202469317
from bisect import bisect_left as bl, bisect_right as br, insort_left, insort_right from collections import deque, Counter as counter, defaultdict as dd from copy import copy, deepcopy from functools import cache, cmp_to_key, lru_cache, reduce, partial from heapq import heappush, heappop, heappushpop, heapify, heaprepl...
102
280
18,636,800
121398770
import queue MAX = 500 dr = [0,0,1,-1] dc = [1,-1,0,0] def isValid(r, c): return r in range(m) and c in range(n) def BFS(sr, sc, fr, fc): q = [0] * (MAX * MAX) left = right = 0 q[0] = (sr, sc) while left <= right: ur, uc = q[left] left += 1 for i in range(4): vr = ur + dr[i] vc = u...
Codeforces Round 301 (Div. 2)
CF
2,015
2
256
Ice Cave
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists e...
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integer...
If you can reach the destination, print 'YES', otherwise print 'NO'.
null
In the first sample test one possible path is: $$(1,6)\rightarrow(2,6)\rightarrow(3,6)\rightarrow(4,5)\rightarrow(4,4)\rightarrow(4,3)\rightarrow(4,2)\rightarrow(4,1)\rightarrow(3,2)\rightarrow(2,3)\rightarrow(2,2)$$ After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time...
[{"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "output": "YES"}, {"input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "output": "NO"}, {"input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "output": "YES"}]
2,000
["dfs and similar"]
102
[{"input": "4 6\r\nX...XX\r\n...XX.\r\n.X..X.\r\n......\r\n1 6\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n.X..\r\n...X\r\nX.X.\r\n....\r\n.XX.\r\n5 3\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "4 7\r\n..X.XX.\r\n.XX..X.\r\nX...X..\r\nX......\r\n2 2\r\n1 6\r\n", "output": "YES\r\n"}, {"input": "5 3\r\n.XX\r\n...
false
stdio
null
true
540/C
540
C
PyPy 3
TESTS
4
124
0
90499658
def is_valid_tile(r, c, n, m): return r >= 0 and c >= 0 and r < n and c < m def gen_adjacents(r, c, n, m): adjs = [] possibles = [(r + 1, c), (r - 1, c), (r, c + 1), (r, c - 1)] for possible in possibles: if is_valid_tile(*possible, n, m): adjs.append(possible) return adjs def ...
102
280
27,340,800
142946642
import math import os import sys from io import BytesIO, IOBase from types import GeneratorType from collections import defaultdict BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file...
Codeforces Round 301 (Div. 2)
CF
2,015
2
256
Ice Cave
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists e...
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integer...
If you can reach the destination, print 'YES', otherwise print 'NO'.
null
In the first sample test one possible path is: $$(1,6)\rightarrow(2,6)\rightarrow(3,6)\rightarrow(4,5)\rightarrow(4,4)\rightarrow(4,3)\rightarrow(4,2)\rightarrow(4,1)\rightarrow(3,2)\rightarrow(2,3)\rightarrow(2,2)$$ After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time...
[{"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "output": "YES"}, {"input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "output": "NO"}, {"input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "output": "YES"}]
2,000
["dfs and similar"]
102
[{"input": "4 6\r\nX...XX\r\n...XX.\r\n.X..X.\r\n......\r\n1 6\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n.X..\r\n...X\r\nX.X.\r\n....\r\n.XX.\r\n5 3\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "4 7\r\n..X.XX.\r\n.XX..X.\r\nX...X..\r\nX......\r\n2 2\r\n1 6\r\n", "output": "YES\r\n"}, {"input": "5 3\r\n.XX\r\n...
false
stdio
null
true
613/A
613
A
PyPy 3-64
TESTS
37
717
12,390,400
190207221
import math from math import sqrt, inf, gcd, ceil, tan, pi, sin, cos import queue # -------- info -------- # https://codeforces.com/profile/Wolxy # -------- sys -------- def next_int() -> int: return int(input()) def next_ints() -> map: return map(int, input().split(' ')) def next_list() -> list: r...
60
577
12,185,600
15396149
from math import hypot, pi, copysign def main(): n, a, b = map(int, input().split()) l, res = [], [] for _ in range(n): x0, y0 = map(int, input().split()) l.append((x0 - a, y0 - b)) x0, y0 = l[-1] for x1, y1 in l: res.append(hypot(x1, y1)) dx, dy = x1 - x0, y1 - y0 ...
Codeforces Round 339 (Div. 1)
CF
2,016
2
256
Peter and Snow Blower
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
The first line of the input contains three integers — the number of vertices of the polygon n ($$3 \leq n \leq 100\ 000$$), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three ...
Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac...
null
In the first sample snow will be removed from that area:
[{"input": "3 0 0\n0 1\n-1 2\n1 2", "output": "12.566370614359172464"}, {"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1", "output": "21.991148575128551812"}]
1,900
["binary search", "geometry", "ternary search"]
60
[{"input": "3 0 0\r\n0 1\r\n-1 2\r\n1 2\r\n", "output": "12.566370614359172464\r\n"}, {"input": "4 1 -1\r\n0 0\r\n1 2\r\n2 0\r\n1 1\r\n", "output": "21.991148575128551812\r\n"}, {"input": "3 0 0\r\n-1 1\r\n0 3\r\n1 1\r\n", "output": "25.132741228718344928\r\n"}, {"input": "3 -4 2\r\n-3 2\r\n5 -5\r\n5 3\r\n", "output": ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path, 'r') as f: ref_line = f.readline().strip() try: b = float(ref_line) except: print(0) return with open(submission_path, 'r') as f: ...
true
55/C
55
C
Python 3
TESTS
5
122
0
15486214
n, m, k = map(int, input().split()) win = False for i in range(k): r, c = map(int, input().split()) dr = min(r - 1, n - r) dc = min(c - 1, m - c) if dr <= 2 or dc <= 2: win = True print("YES" if win else "NO")
75
92
0
155232117
n, m, k = map(int, input().split()) flag = False while k > 0: k -= 1 x, y = map(int, input().split()) d = min(x, n - x + 1, y, m - y + 1) if d <= 5: flag = True print("YES" if flag else "NO")
Codeforces Beta Round 51
CF
2,011
2
256
Pie or die
Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the borde...
First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell.
Output only one word: "YES" — if Volodya wins, "NO" — otherwise.
null
null
[{"input": "2 2 1\n1 2", "output": "YES"}, {"input": "3 4 0", "output": "NO"}, {"input": "100 50 2\n50 25\n50 25", "output": "NO"}]
1,900
["games"]
75
[{"input": "2 2 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 4 0\r\n", "output": "NO\r\n"}, {"input": "100 50 2\r\n50 25\r\n50 25\r\n", "output": "NO\r\n"}, {"input": "20 20 4\r\n10 10\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "NO\r\n"}, {"input": "15 15 1\r\n8 8\r\n", "output": "NO\r\n"}, {"input": "8 8 2\r\n4 4...
false
stdio
null
true
841/B
841
B
Python 3
TESTS
51
1,045
76,492,800
146556117
n=int(input()) l=list(map(int,input().split())) sum=l[0] i=1 cnt=0 fl='' while i<n: while not sum%2!=0 and i<n: sum+=l[i] i+=1 sum=0 if i<n: fl='s' while not sum%2==0 and i<n: sum+=l[i] i+=1 sum=0 if i<n: fl='f' if fl=='': print("Second") else:...
88
280
84,992,000
174428621
n = int(input()) a = (map(int,input().split())) for i in a: if i%2==1: print('First') exit() print('Second')
Codeforces Round 429 (Div. 2)
CF
2,017
2
256
Godsend
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a...
First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array. Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
null
In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
[{"input": "4\n1 3 2 3", "output": "First"}, {"input": "2\n2 2", "output": "Second"}]
1,100
["games", "math"]
88
[{"input": "4\r\n1 3 2 3\r\n", "output": "First\r\n"}, {"input": "2\r\n2 2\r\n", "output": "Second\r\n"}, {"input": "4\r\n2 4 6 8\r\n", "output": "Second\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "First\r\n"}, {"input": "4\r\n720074544 345031254 849487632 80870826\r\n", "output": "Second\r\n"}, {"input": "1\r\n0...
false
stdio
null
true
33/C
33
C
Python 3
TESTS
35
310
6,451,200
158129345
n = int(input()) try: A = list(map(int,input().split())) l = 0;r = n - 1 res = 0 min_ = 0 dp = [0]*n dp[0] = A[0] for i in range(1,n): dp[i] = max(dp[i-1] + A[i],A[i]) res = max(res,dp[i]) print(res + res - sum(A)) except: print('输入错误!')
89
248
17,715,200
218027178
n = int(input()) a = [int(i) for i in input().split()] prefs = [0] sufs = [0] min_prefs = [0] min_sufs = [0] s = sum(a) for i in range(n): min_prefs.append(min(min_prefs[-1], prefs[-1] + a[i])) prefs.append(prefs[-1] + a[i]) min_sufs.append(min(min_sufs[-1], a[n - 1 - i] + sufs[-1])) sufs.append(a[n - 1...
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
Wonderful Randomized Sum
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th...
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
The first and the only line of the output should contain the answer to the problem.
null
null
[{"input": "3\n-1 -2 -3", "output": "6"}, {"input": "5\n-4 2 0 5 0", "output": "11"}, {"input": "5\n-1 10 -5 10 -2", "output": "18"}]
1,800
["greedy"]
89
[{"input": "3\r\n-1 -2 -3\r\n", "output": "6\r\n"}, {"input": "5\r\n-4 2 0 5 0\r\n", "output": "11\r\n"}, {"input": "5\r\n-1 10 -5 10 -2\r\n", "output": "18\r\n"}, {"input": "1\r\n-3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 -5 -2\r\n", "output": "12\r\n"}, {"input": "7\r\n-17 6 5 0 1 4 -1\r\n", "output": "34\r\n"}...
false
stdio
null
true
55/C
55
C
Python 3
TESTS
5
125
102,400
3933221
n, m, k = [int(x) for x in input().split()] canwin = False for i in range(k): x, y = [int(x) for x in input().split()] canwin |= x <= 3 or n - x <= 2 canwin |= y <= 3 or m - y <= 2 print("YES" if canwin else "NO")
75
92
0
158335311
def main(): n, m, k = map(int, input().split()) min_ = 100 for j in range(k): a, b = map(int, input().split()) c = min(a-1, b-1, n-a, m-b) min_ = min(c, min_) if min_ <= 4: print("YES") return print("NO") main() #-------- #-------- #-------- # #--- *- --- #--- -* --- # #-------- #-------- #--------
Codeforces Beta Round 51
CF
2,011
2
256
Pie or die
Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the borde...
First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell.
Output only one word: "YES" — if Volodya wins, "NO" — otherwise.
null
null
[{"input": "2 2 1\n1 2", "output": "YES"}, {"input": "3 4 0", "output": "NO"}, {"input": "100 50 2\n50 25\n50 25", "output": "NO"}]
1,900
["games"]
75
[{"input": "2 2 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 4 0\r\n", "output": "NO\r\n"}, {"input": "100 50 2\r\n50 25\r\n50 25\r\n", "output": "NO\r\n"}, {"input": "20 20 4\r\n10 10\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "NO\r\n"}, {"input": "15 15 1\r\n8 8\r\n", "output": "NO\r\n"}, {"input": "8 8 2\r\n4 4...
false
stdio
null
true
605/C
605
C
Python 3
TESTS
13
592
9,932,800
22165998
import sys jobs, xp, money = map(int, input().split()) vecs = [] maxsum = 0 for i in range(jobs): x, m = map(int, input().split()) x *= money m *= xp # ? vecs.append((x, m)) if x+m > maxsum: maxsum = x+m maxvecs = [(x, m)] elif x+m == maxsum: maxvecs.append((x, m)) target = xp * money mindays = 6456489465...
86
1,341
14,643,200
113386000
from fractions import Fraction def higher(x1, y1, x2, y2): if x1 == 0: if x2 == 0: return def min_days(p, q, pr): ma = max(a for a, b in pr) mb = max(b for a, b in pr) pr.sort(key=lambda t: (t[0], -t[1])) ch = [(0, mb)] for a, b in pr: if a == ch[-1][0]: ...
Codeforces Round 335 (Div. 1)
CF
2,015
2
256
Freelancer's Dreams
Mikhail the Freelancer dreams of two things: to become a cool programmer and to buy a flat in Moscow. To become a cool programmer, he needs at least p experience points, and a desired flat in Moscow costs q dollars. Mikhail is determined to follow his dreams and registered at a freelance site. He has suggestions to wo...
The first line of the input contains three integers n, p and q (1 ≤ n ≤ 100 000, 1 ≤ p, q ≤ 1 000 000) — the number of projects and the required number of experience and money. Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 1 000 000) — the daily increase in experience and daily income for work...
Print a real value — the minimum number of days Mikhail needs to get the required amount of experience and money. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consid...
null
First sample corresponds to the example in the problem statement.
[{"input": "3 20 20\n6 2\n1 3\n2 6", "output": "5.000000000000000"}, {"input": "4 1 1\n2 3\n3 2\n2 3\n3 2", "output": "0.400000000000000"}]
2,400
["geometry"]
86
[{"input": "3 20 20\r\n6 2\r\n1 3\r\n2 6\r\n", "output": "5.000000000000000\r\n"}, {"input": "4 1 1\r\n2 3\r\n3 2\r\n2 3\r\n3 2\r\n", "output": "0.400000000000000\r\n"}, {"input": "3 12 12\r\n5 1\r\n2 2\r\n1 5\r\n", "output": "4.000000000000000\r\n"}, {"input": "3 12 12\r\n5 1\r\n4 4\r\n1 5\r\n", "output": "3.000000000...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_output_path = sys.argv[3] # Read correct answer try: with open(output_path, 'r') as f: correct_line = f.readline().strip() b = float(correct_line) except: print(0) ...
true
883/K
883
K
Python 3
TESTS
4
62
5,529,600
31660554
t = [] l = [] r = [] for _ in range(int(input())): s, g = map(int, input().split()) t.append(s) l.append(s) r.append(g + s) for i in range(1, len(l)): if l[i] < l[i - 1]: l[i] = l[i - 1] - 1 if r[i] > r[i - 1]: r[i] = r[i - 1] + 1 for i in range(len(l) - 2, 0, -1): if l[i] < l[i + 1]: l[i] = l[i + 1] ...
109
1,809
15,360,000
230750690
n = int(input()) s = [0]*n g = [0]*n for i in range(n): a,b = map(int,input().split()) s[i] = a g[i] = a+b for i in range(1,n): g[i] = min(g[i],g[i-1]+1) for i in range(n-2,-1,-1): g[i] = min(g[i],g[i+1]+1) ans = 0 for i in range(n): if s[i] <= g[i]: ans += g[i] - s[i] else: ...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Road Widening
Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy! The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time o...
The first line contains integer n (1 ≤ n ≤ 2·105) — number of parts of the street. Each of the following n lines contains two integers si, gi (1 ≤ si ≤ 106, 0 ≤ gi ≤ 106) — current width of road and width of the lawn on the i-th part of the street.
In the first line print the total width of lawns which will be removed. In the second line print n integers s'1, s'2, ..., s'n (si ≤ s'i ≤ si + gi) — new widths of the road starting from the first part and to the last. If there is no solution, print the only integer -1 in the first line.
null
null
[{"input": "3\n4 5\n4 5\n4 10", "output": "16\n9 9 10"}, {"input": "4\n1 100\n100 1\n1 100\n100 1", "output": "202\n101 101 101 101"}, {"input": "3\n1 1\n100 100\n1 1", "output": "-1"}]
1,800
["constructive algorithms", "greedy", "implementation"]
109
[{"input": "3\r\n4 5\r\n4 5\r\n4 10\r\n", "output": "16\r\n9 9 10 \r\n"}, {"input": "4\r\n1 100\r\n100 1\r\n1 100\r\n100 1\r\n", "output": "202\r\n101 101 101 101 \r\n"}, {"input": "3\r\n1 1\r\n100 100\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "10\r\n21005 10850\r\n27020 13372\r\n28183 3724\r\n22874 13564\r\n27446 11...
false
stdio
null
true
326/B
335
B
PyPy 3-64
TESTS
5
154
11,980,800
174009177
from collections import Counter s = input() cnt = Counter(s) for c in cnt: if cnt[c] >= 100: print(c * 100) exit(0) n = len(s) dp = [[None for _ in range(n)] for _ in range(n)] res = '' for i in range(n - 1, -1, -1): for j in range(i, n, 1): if i == j: dp[i][j] = s[i] ...
72
1,996
117,145,600
66242753
from collections import defaultdict s = input() n = len(s) if n >= 2600: print(s[0] * 100) elif n > 2574: count = defaultdict(int) for l in s: count[l] += 1 max_l = s[0] for l, c in count.items(): if c >= 100: max_l = l print(max_l * 100) else: data = defaultdi...
MemSQL start[c]up Round 2
CF
2,013
2
256
Palindrome
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible.
The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) containing only lowercase English letters.
If s contains a palindrome of length exactly 100 as a subsequence, print any palindrome of length 100 which is a subsequence of s. If s doesn't contain any palindromes of length exactly 100, print a palindrome that is a subsequence of s and is as long as possible. If there exists multiple answers, you are allowed to p...
null
A subsequence of a string is a string that can be derived from it by deleting some characters without changing the order of the remaining characters. A palindrome is a string that reads the same forward or backward.
[{"input": "bbbabcbbb", "output": "bbbcbbb"}, {"input": "rquwmzexectvnbanemsmdufrg", "output": "rumenanemur"}]
1,900
[]
72
[{"input": "bbbabcbbb\r\n", "output": "bbbcbbb\r\n"}, {"input": "rquwmzexectvnbanemsmdufrg\r\n", "output": "rumenanemur\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
false
stdio
import sys def is_palindrome(s): return s == s[::-1] def is_subsequence(sub, s): i = 0 for c in sub: i = s.find(c, i) + 1 if i == 0: return False return True input_path, output_path, submission_path = sys.argv[1:4] with open(input_path) as f: s = f.read().strip() wit...
true
605/A
605
A
Python 3
TESTS
10
140
8,908,800
14782471
a=[0 for i in range(100010)] b=[0 for i in range(100010)] c=[0 for i in range(100010)] n, a[1:] = int(input()), map(int,input().split(' ')) for i in range(1,n+1): if b[a[i]-1]: c[a[i]]=c[a[i]-1]+1 else: c[a[i]]=1 b[i]=1 print (n-max(c[1:n+1]))
66
93
13,516,800
196883940
import sys if __name__ == '__main__': n = eval(input()) p = list(map(int, sys.stdin.readline().rstrip().split())) cnt = [0] * (n + 1) # 贪心算法,找到序列中最长的升序子序列(只差1),那么只需要将这之外的数字移动即可 for i in p: cnt[i] = cnt[i - 1] + 1 print(n - max(cnt))
Codeforces Round 335 (Div. 1)
CF
2,015
2
256
Sorting Railway Cars
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it...
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
Print a single integer — the minimum number of actions needed to sort the railway cars.
null
In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
[{"input": "5\n4 1 2 5 3", "output": "2"}, {"input": "4\n4 1 3 2", "output": "2"}]
1,600
["constructive algorithms", "greedy"]
66
[{"input": "5\r\n4 1 2 5 3\r\n", "output": "2\r\n"}, {"input": "4\r\n4 1 3 2\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "6\r\n5 3 6 1 4 2\r\n", "output": "4\r\n"}, {"input": "7\r\n1 2 3 6 7 4...
false
stdio
null
true
600/C
600
C
Python 3
TESTS
4
46
102,400
194307103
from collections import Counter map = Counter(input()) odd = [] for c, cnt in map.items(): if cnt % 2 > 0: odd.append(c) for c in odd[: len(odd) // 2]: map[c] += 1 for c in odd[(len(odd) + 1) // 2: ]: map[c] -= 1 head = ''.join([char * (count // 2) for char, count in map.items()]) mid = odd[len(...
66
62
4,096,000
209539274
# /** # * author: brownfox2k6 # * created: 13/06/2023 15:26:13 Hanoi, Vietnam # **/ from collections import Counter s = input() n = len(s) a = Counter(sorted(s)) odd = [[x, a[x]] for x in a if a[x] & 1] x = len(odd) for i in range(x // 2): a[odd[i][0]] += 1 a[odd[x-i-1][0]] -= 1 codd = '' s = '' fo...
Educational Codeforces Round 2
ICPC
2,015
2
256
Make Palindrome
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string s consisting of lowercase Latin letters. At once you can choose any position in th...
The only line contains string s (1 ≤ |s| ≤ 2·105) consisting of only lowercase Latin letters.
Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes.
null
null
[{"input": "aabc", "output": "abba"}, {"input": "aabcd", "output": "abcba"}]
1,800
["constructive algorithms", "greedy", "strings"]
66
[{"input": "aabc\r\n", "output": "abba\r\n"}, {"input": "aabcd\r\n", "output": "abcba\r\n"}, {"input": "u\r\n", "output": "u\r\n"}, {"input": "ttttt\r\n", "output": "ttttt\r\n"}, {"input": "xxxvvvxxvv\r\n", "output": "vvvxxxxvvv\r\n"}, {"input": "wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrr...
false
stdio
null
true
40/D
40
D
Python 3
TESTS
15
124
307,200
30263955
A = int(input()) T = A x = 0 while (A % 12 == 0): A = A / 12 x = x + 1 b = [0] * 1000 b[1] = 2 b[2] = 13 for i in range(3, 603): b[i] = 13 * b[i - 1] - 12 * b[i - 2] y = 1 while (b[y] < A): y = y + 1 if (b[y] != A): print("NO") else: print("YES\n1") t = 2 * x + y print(t) c = [0] * 1...
74
156
1,843,200
220961106
from fractions import Fraction import sys def calculate_powers(limit): powers = [1] current_power = 1 for _ in range(limit): current_power *= 12 powers.append(current_power) return powers def find_possible_sums(powers, target_sum): results = [] for i in range(len(powers)): ...
Codeforces Beta Round 39
CF
2,010
3
256
Interesting Sequence
Berland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronology starts from the moment when the first two people came to that land (it is considered to have happened in the first year). A...
The first line contains integer A (1 ≤ A < 10300). It is guaranteed that the number doesn't contain leading zeros.
On the first output line print YES, if there could be a year in which the total population of the country equaled A, otherwise print NO. If the answer is YES, then you also have to print number k — the number of years in which the population could equal A. On the next line you have to output precisely k space-separate...
null
null
[{"input": "2", "output": "YES\n1\n1\n0"}, {"input": "3", "output": "NO"}, {"input": "13", "output": "YES\n1\n2\n0"}, {"input": "1729", "output": "YES\n1\n4\n1\n156"}]
2,600
["math"]
74
[{"input": "2\r\n", "output": "YES\r\n1\r\n1\r\n0\r\n"}, {"input": "3\r\n", "output": "NO\r\n"}, {"input": "13\r\n", "output": "YES\r\n1\r\n2\r\n0\r\n"}, {"input": "1729\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n156\r\n"}, {"input": "1\r\n", "output": "NO\r\n"}, {"input": "156\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n1729\r...
false
stdio
null
true
197/B
197
B
Python 3
TESTS
10
248
921,600
39260593
""" *** Author--Saket Saumya *** IIITM """ import math import os import random import re import sys from collections import Counter from itertools import permutations sys.setrecursionlimit(3000) def si(): return str(input()) def ii(): return int(input()) def mi(): return map(int, input().split())...
80
124
0
187657210
import math x,y = map(int,input().split()) a,b = int(input().split()[0]), int(input().split()[0]) if y > x: print("0/1") elif x > y: print(("-" if (int(a < 0) + int(b < 0))%2 == 1 else "") + "Infinity") else: if (int(a < 0)+int(b < 0))%2 == 1: a = -abs(a) b = abs(b) else: a = abs...
Codeforces Round 124 (Div. 2)
CF
2,012
2
256
Limit
You are given two polynomials: - P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and - Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separ...
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the forma...
null
Let's consider all samples: 1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$ 2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$ 3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$ 4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$ 5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$ You c...
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
1,400
["math"]
80
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3...
false
stdio
null
true
584/C
584
C
PyPy 3-64
TESTS
10
77
2,867,200
194545529
from string import ascii_lowercase n, t = list(map(int, input().split())) s1 = input() s2 = input() cnt1, cnt2 = 0, 0 ans = [] i = 0 while cnt1 < n - t or cnt2 < n - t: if i == n: print(-1) break c1, c2 = s1[i], s2[i] if c1 == c2: cnt1 += 1 cnt2 += 1 ans.append(c1) ...
78
124
1,433,600
13458463
def f(s1, s2): return sum(0 if ch1 == ch2 else 1 for ch1, ch2 in zip(s1, s2)) def choose_different(ch1, ch2): if ch1 != 'a' and ch2 != 'a': return 'a' if ch1 != 'b' and ch2 != 'b': return 'b' return 'c' def calc_s3(s1, s2, in_match, out_match): l3 = [] in_match_taken = 0 ...
Codeforces Round 324 (Div. 2)
CF
2,015
1
256
Marina and Vasya
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and ...
The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters.
Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.
null
null
[{"input": "3 2\nabc\nxyc", "output": "ayd"}, {"input": "1 0\nc\nb", "output": "-1"}]
1,700
["constructive algorithms", "greedy", "strings"]
78
[{"input": "3 2\r\nabc\r\nxyc\r\n", "output": "bac"}, {"input": "1 0\r\nc\r\nb\r\n", "output": "-1\r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "b"}, {"input": "2 1\r\naa\r\naa\r\n", "output": "ab"}, {"input": "3 1\r\nbcb\r\nbca\r\n", "output": "bcc"}, {"input": "4 3\r\nccbb\r\ncaab\r\n", "output": "cbca"}, {"input"...
false
stdio
import sys def hamming(s1, s2): return sum(c1 != c2 for c1, c2 in zip(s1, s2)) def solution_exists(n, t, s1, s2): a = sum(c1 == c2 for c1, c2 in zip(s1, s2)) d = n - a min_k = max(d - t, 0) max_k = min(d // 2, a + d - t) return min_k <= max_k def main(): input_path = sys.argv[1] outpu...
true
442/B
442
B
PyPy 3
TESTS
17
124
0
31239197
def dp(N, P): Mem = [] for n in range(N + 1): Mem.append((0.0, 0.0)) Mem[N] = (1.0, 0.0); for i in reversed(range(N)): p = Mem[i + 1]; noHelp, oneHelp = p[0], p[1] useI, result = noHelp*P[i] + oneHelp*(1 - P[i]), oneHelp Mem[i] = p if(result < P[i]): result = P[i] Mem[i] = (1 - P[i], P[i]) if(r...
60
61
0
156238870
input() a,b,c = 1,0,0 for p in sorted(map(float, input().split()))[::-1]: b = a*p + b*(1-p) a *= 1-p c = max(c, b) print(c)
Codeforces Round 253 (Div. 1)
CF
2,014
2
256
Andrey and Problem
Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him. Help Andrey choose...
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of Andrey's friends. The second line contains n real numbers pi (0.0 ≤ pi ≤ 1.0) — the probability that the i-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.
Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10 - 9.
null
In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one. In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1·0.8 + 0.9·0.2 = 0.26.
[{"input": "4\n0.1 0.2 0.3 0.8", "output": "0.800000000000"}, {"input": "2\n0.1 0.2", "output": "0.260000000000"}]
1,800
["greedy", "math", "probabilities"]
60
[{"input": "4\r\n0.1 0.2 0.3 0.8\r\n", "output": "0.800000000000\r\n"}, {"input": "2\r\n0.1 0.2\r\n", "output": "0.260000000000\r\n"}, {"input": "1\r\n0.217266\r\n", "output": "0.217266000000\r\n"}, {"input": "2\r\n0.608183 0.375030\r\n", "output": "0.608183000000\r\n"}, {"input": "3\r\n0.388818 0.399762 0.393874\r\n",...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read submission output with open(submission_path, 'r') as f: submission_lines = f.readlines() if len(submission_lines) != 1: print(0) return submission_str = submission_lines[0].strip() try: sub_val = f...
true
197/B
197
B
Python 3
TESTS
10
218
0
49733782
n,m=map(int,input().split()) a=[int(i) for i in input().split()] b=[int(i) for i in input().split()] if n>m: if (a[0]>=0 and b[0]>=0) or (a[0]<=0 and b[0]<=0): print('Infinity') else: print('-Infinity') elif n<m: print('0/1') else: a1=a[0] b1=b[0] sign=None if a1>=0 and b1<0...
80
124
0
211647410
import math n, m = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) if n > m : if a[0]*b[0] < 0 : print("-Infinity") else : print("Infinity") elif n == m : hcf = math.gcd(a[0],b[0]) if a[0]*b[0] < 0 : print('-', abs(a[0]//hcf),'/',abs...
Codeforces Round 124 (Div. 2)
CF
2,012
2
256
Limit
You are given two polynomials: - P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and - Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separ...
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the forma...
null
Let's consider all samples: 1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$ 2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$ 3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$ 4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$ 5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$ You c...
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
1,400
["math"]
80
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3...
false
stdio
null
true
197/B
197
B
Python 3
TESTS
10
124
5,529,600
28170262
from sys import stdin, stdout def GCD(a, b): if not b: return a if a < b: return GCD(b, a) else: return GCD(b, a % b) n, m = map(int, stdin.readline().split()) a = list(map(int, stdin.readline().split())) b = list(map(int, stdin.readline().split())) if n > m: if a[0] * ...
80
124
0
225061724
def gcd(x,y): if x%y==0: return y return gcd(y,x%y) n,m = map(int,input().split()) lin,lim = [int(i) for i in input().split()],[int(i) for i in input().split()] if n>m : if lin[0]*lim[0]<0: print("-Infinity") else: print("Infinity") elif m>n: print('0/1') else: x,y = ma...
Codeforces Round 124 (Div. 2)
CF
2,012
2
256
Limit
You are given two polynomials: - P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and - Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separ...
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the forma...
null
Let's consider all samples: 1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$ 2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$ 3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$ 4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$ 5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$ You c...
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
1,400
["math"]
80
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3...
false
stdio
null
true
404/A
404
A
Python 3
TESTS
31
46
0
223984634
n = int(input()) pat = [] flag = True for _ in range(n): temp = input() if not 3 > len(list(set(temp))) > 1: flag = False pat.append(temp) if flag: x = pat[0][0] for i in range(n): if i == n // 2: if pat[i].count(x) != 1: flag = False print("NO") break else: if ...
47
46
0
137385662
n=int(input()) a=[] check=1 s=input() if len(set(s))!=2: check=0 else: if s.count(s[0])!=2: check=0 else: if s[0]!=s[-1]: check=0 a=list(set(s)) a.sort() for i in range(1,n): s1=input() if len(set(s1))!=2: check=0 else: if i*2+1==n: if s1.count(s[0])!=1: che...
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Valera and X
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
null
null
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
1,000
["implementation"]
47
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r...
false
stdio
null
true
404/A
404
A
Python 3
TESTS
44
109
0
146008646
n = int(input()) letters = [] checker_one = True checker_two = True checker_three = True letter = [0]*26 for i in range(n): letters.append(input()) letter_check = letters[0][0] for i in range(n): for j in range(n): if j == i: if letters[i][j] != letters[i-1][j-1]: letter_che...
47
46
0
144132009
sq = int(input()) def main(sq: int) : x_array = [] input_array= [] for i in range(sq): input_array.append(str(input())) a = input_array[0][0] b = "" for x in input_array[0]: if x!=a: b = x break last = sq-1 first = 0 for _ in range(sq): ...
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Valera and X
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
null
null
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
1,000
["implementation"]
47
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r...
false
stdio
null
true
404/A
404
A
Python 3
TESTS
42
139
8,396,800
86832622
z=int(input()) s=[] d=[] sd={} c=0 q=0 for i in range(z): x=input() if len(x)==("".join(x)).count(x[0]): c=1203 break for o in x: s.append(o) sd[o]=ord(o) q+=1 for u in range(len(x)): d.append(x[len(x)-u-1]) if c==1203 or len(sd)>=3 : print("NO") el...
47
46
0
148496276
num=int(input()) arr=[input() for i in range(num)] c1,c2=arr[0][0],arr[0][1] tmp=2 for i in range(num): check1=len(arr[i].replace(c1,"")) check2=len(arr[i].replace(c2,"")) if i!=(num-1)/2: if check1!=num-2 or check2!=2: print("NO") quit() else: if check1!=num-1 ...
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Valera and X
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
null
null
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
1,000
["implementation"]
47
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r...
false
stdio
null
true
404/A
404
A
PyPy 3-64
TESTS
31
61
102,400
196599339
n = int(input()) p1 = 0 p2 = n - 1 word = '' other= '' mod_ = n // 2 flag = 'YES' check = 1 for i in range(n): s = input() if i == 0: if s[0] == s[-1]: word = s[0] other= s[1] else: flag = 'NO' if len(set(s)) == 2: if s[p1] == word and s[p2] == wor...
47
46
0
154174106
n = int(input()) matrix = [] for i in range(n): matrix.append(input()) diag_letter = matrix[0][0] off_diag_letter = matrix[0][1] result = 'YES' if (len(set(matrix)) == 1): result = 'NO' for i in range(n): if (matrix[i][i] == matrix[i][n-i-1] == diag_letter): chars = list(matrix[i]) ch...
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Valera and X
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
null
null
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
1,000
["implementation"]
47
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r...
false
stdio
null
true
837/C
837
C
Python 3
TESTS
22
62
4,608,000
29171390
n,a,b = map(int,input().split()) def fit(x1,y1,x2,y2): if a>=x1 and b>=y1: if (a-x1>=x2 and b>=y2) or (a-x1>=y2 and b>=x2) or (a>=x2 and b-y1>=y2) or (a>=y2 and b-y1>=x2): return True elif a>=y1 and b>=x1: if (a-y1>=x2 and b>=y2) or (a-y1>=y2 and b>=x2) or (a>=x2 and b-x1>=y2) or...
51
62
4,915,200
29173478
import sys, math n, a, b = map(int, input().split()) x=[0 for i in range(n)] y=[0 for i in range(n)] for i in range(n): u,v = map(int, input().split()) x[i]=u y[i]=v m=0 for i in range(n): for j in range (n): if i!=j: if (x[i]+x[j]<=a and max(y[i],y[j])<=b) or (x[i]+y[j]<=a and ma...
Educational Codeforces Round 26
ICPC
2,017
1
256
Two Seals
One very important person has a piece of paper in the form of a rectangle a × b. Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees). A very importa...
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100). Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
null
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper. In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the large...
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
1,500
["brute force", "implementation"]
51
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"inpu...
false
stdio
null
true
404/A
404
A
PyPy 3
TESTS
31
155
1,945,600
91789842
t=[] n=int(input()) for k in range(n): a = list(input()) t.append(a) u=[] for j in range(n): u.append(t[j][j]) t[j][j]='0' i = n-1-j if i!=j: u.append(t[i][j]) t[i][j]='0' if len(set(u))==1: h=0 for j in t: if u[0] not in j and len(set(j))==2: ...
47
46
0
155258387
import sys input = sys.stdin.readline n = int(input()) g = [input()[:-1] for _ in range(n)] x = g[0][0] y = g[0][1] if x == y: print("NO") else: w = [] for i in range(n-2, 0, -2): s = (x + y*i + x).center(n,y) w.append(s) w.append(x.center(n,y)) for i in range(1, n, 2): s = ...
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Valera and X
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
null
null
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
1,000
["implementation"]
47
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r...
false
stdio
null
true
404/A
404
A
Python 3
TESTS
31
46
307,200
161502179
def Diagonal1(paper): x = 0 y = 0 while x < len(paper[0]) - 1: if paper[x][y] != paper[x + 1][y + 1]: return False x += 1 y += 1 return True def Diagonal2(paper, num): x = len(paper[0]) - 1 y = 0 while x > 0: if paper[x][y] != paper[x - 1][y + 1]:...
47
46
0
158060690
a=int(input()) s="" for i in range(a): s=s+input() if s[::1]==s[::-1] and s.count(s[0])==(2*a)-1: print('YES') else: print('NO')
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Valera and X
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
null
null
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
1,000
["implementation"]
47
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r...
false
stdio
null
true
197/B
197
B
Python 3
TESTS
7
124
0
203414225
''' Online Python Compiler. Code, Compile, Run and Debug python program online. Write your code in this editor and press "Run" button to execute it. ''' import math n,m=map(int,input().split()) l1=list(map(int,input().split())) l2=list(map(int,input().split())) if n==m: ...
80
154
0
132206792
def gcd(a,b): if b==0: return a return gcd(b,a%b) n,m=map(int,input().split()) p=n-m a=list(map(int,input().split())) b=list(map(int,input().split())) if p==0: g=gcd(a[0],b[0]) print("%d/%d"%(a[0]/g,b[0]/g)) else: if p<0: print("0/1") else: if a[0]*b[0]>0: p...
Codeforces Round 124 (Div. 2)
CF
2,012
2
256
Limit
You are given two polynomials: - P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and - Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separ...
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the forma...
null
Let's consider all samples: 1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$ 2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$ 3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$ 4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$ 5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$ You c...
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
1,400
["math"]
80
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3...
false
stdio
null
true
592/D
592
D
PyPy 3
TESTS
88
1,278
29,798,400
98083507
from heapq import * INF = float('inf') n, m = map(int, input().split()) adj = [[] for _ in range(n+1)] wg = [0 for _ in range(n+1)] for _ in range(n-1): a, b = map(int, input().split()) adj[a].append(b) adj[b].append(a) aaa = set(map(int, input().split())) rm = [] ng = [0] * (n+1) for i in range(n+1): ...
89
280
21,094,400
204355691
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def make_graph(n, m): x, s = [0] * (2 * m), [0] * (n + 3) for i in range(0, 2 * m, 2): u, v = map(int, input().split()) s[u + 2] += 1 s[v + 2] += 1 x[i], x[i + 1] = u, v for i in range(3, n + 3):...
Codeforces Round 328 (Div. 2)
CF
2,015
2
256
Super M
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go ...
The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 123456) - the number of cities in Byteforces, and the number of cities being attacked respectively. Then follow n - 1 lines, describing the road system. Each line contains two city numbers ui and vi (1 ≤ ui, vi ≤ n) - the ends of the road i. The l...
First print the number of the city Super M should teleport to. If there are many possible optimal answers, print the one with the lowest city number. Then print the minimum possible time needed to scare all humans in cities being attacked, measured in Krons. Note that the correct answer is always unique.
null
In the first sample, there are two possibilities to finish the Super M's job in 3 krons. They are: $$2 \rightarrow 1 \rightarrow 3 \rightarrow 7$$ and $$7 \rightarrow 3 \rightarrow 1 \rightarrow 2$$. However, you should choose the first one as it starts in the city with the lower number.
[{"input": "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7", "output": "2\n3"}, {"input": "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6", "output": "2\n4"}]
2,200
["dfs and similar", "dp", "graphs", "trees"]
89
[{"input": "7 2\r\n1 2\r\n1 3\r\n1 4\r\n3 5\r\n3 6\r\n3 7\r\n2 7\r\n", "output": "2\r\n3\r\n"}, {"input": "6 4\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n4 6\r\n2 4 5 6\r\n", "output": "2\r\n4\r\n"}, {"input": "2 1\r\n2 1\r\n1\r\n", "output": "1\r\n0\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n0\r\n"}, {"input": "10 2\r\n6 9\...
false
stdio
null
true
197/B
197
B
Python 3
TESTS
7
92
0
184176023
n,m = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) def computeGCD(x, y): while(y): x, y = y, x % y return abs(x) if n>m: if A[0]>0: print('Infinity') else: print('-Infinity') elif n<m: print('0/1') else: num = ...
80
154
135,270,400
177584015
from collections import defaultdict, deque from functools import lru_cache from heapq import heappush, heappop, heapify from bisect import bisect_right, bisect_left from random import randint from fractions import Fraction as frac import math hpop = heappop hpush = heappush MOD = 10**9 + 7 def gcd(a,b): if a < b: ...
Codeforces Round 124 (Div. 2)
CF
2,012
2
256
Limit
You are given two polynomials: - P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and - Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separ...
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the forma...
null
Let's consider all samples: 1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$ 2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$ 3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$ 4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$ 5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$ You c...
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
1,400
["math"]
80
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3...
false
stdio
null
true
672/B
672
B
Python 3
TESTS
31
61
102,400
144861085
n = int(input()) s = str(input()) set = {'#'} for x in s: set.add(x) if(len(set)==27): print("-1") exit(0) a=n-len(set)+1 if(a>26-len(set)+1): print("-1") else: print(a)
47
46
0
156818113
n = int(input()) s = set(input()) ans = n - len(s) if n > 26: print(-1) else: print(ans)
Codeforces Round 352 (Div. 2)
CF
2,016
2
256
Different is Good
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some numb...
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s. The second line contains the string s of length n consisting of only lowercase English letters.
If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
null
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
[{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}]
1,000
["constructive algorithms", "implementation", "strings"]
47
[{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": ...
false
stdio
null
true
832/B
832
B
PyPy 3-64
TESTS
15
296
5,017,600
142002770
good_letters = input() pattern = input() if '*' in pattern: index_of_ast = pattern.index('*') result = [] number_of_words = int(input()) for i in range(number_of_words): word = input() matches = True if '*' in pattern: pattern_without_ast = pattern.replace('*', '') word_without_ast = wor...
94
530
5,632,000
28843189
#!/usr/local/bin/python3 import sys good_letters = set(input()) pattern = input() input() for line in sys.stdin: query = line.strip() diff = len(query) - len(pattern) + 1 if diff < 0: print("NO") continue query_index = 0 pattern_index = 0 question = None result = "NO"...
Codeforces Round 425 (Div. 2)
CF
2,017
2
256
Petya and Exam
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is kno...
The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad. The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 105). It is guaranteed that character "*"...
Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrary.
null
In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter. Explanation of the second example. - The first query: "NO", because character "*" can be replaced wit...
[{"input": "ab\na?a\n2\naaa\naab", "output": "YES\nNO"}, {"input": "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax", "output": "NO\nYES\nNO\nYES"}]
1,600
["implementation", "strings"]
94
[{"input": "ab\r\na?a\r\n2\r\naaa\r\naab\r\n", "output": "YES\r\nNO\r\n"}, {"input": "abc\r\na?a?a*\r\n4\r\nabacaba\r\nabaca\r\napapa\r\naaaaax\r\n", "output": "NO\r\nYES\r\nNO\r\nYES\r\n"}, {"input": "x\r\n?aba*\r\n69\r\nc\r\naaacc\r\nbba\r\nbabcb\r\nac\r\nbccca\r\nca\r\nabbaa\r\nb\r\naacca\r\nccc\r\ncc\r\na\r\naabba\...
false
stdio
null
true
837/C
837
C
Python 3
TESTS
22
62
0
29691917
# Task3 Codeforces 837c def sm(obj1,obj2): return obj1[0]*obj1[1]+obj2[0]*obj2[1] def rotate(x,y,obj): if obj[0] > x or obj[1] > y: return -1 else: return def can_put(x,y,obj): if obj[0] > x and obj[0] > y or obj[1] > x and obj[1] > y: return False else: return True def can_add(x,y,obj1,obj2): if obj1...
51
62
4,915,200
29183668
n,w,h=map(int,input().split()) def chk(w1,h1,w2,h2): if w1<=w and h1<=h: if w-w1>=w2 and h>=h2 or w-w1>=h2 and h>=w2 or w>=w2 and h-h1>=h2 or w>=h2 and h-h1>=w2: return True if h1<=w and w1<=h: if w-h1>=w2 and h>=h2 or w-h1>=h2 and h>=w2 or w>=w2 and h-w1>=h2 or w>=h2 and h-w1>=w2: ...
Educational Codeforces Round 26
ICPC
2,017
1
256
Two Seals
One very important person has a piece of paper in the form of a rectangle a × b. Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees). A very importa...
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100). Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
null
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper. In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the large...
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
1,500
["brute force", "implementation"]
51
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"inpu...
false
stdio
null
true
837/C
837
C
Python 3
TESTS
19
61
4,915,200
29185995
k, n, m = map(int,input().split()) if n > m: n ^= m m ^= n n ^= m x, y = [],[] for i in range(k): q, p = map(int, input().split()) x.append(min(q, p)) y.append(max(q, p)) MAX = 0 for i in range(k): for j in range(i+1,k): if max(x[i], x[j]) <= n and y[i] + y[j] <= m: MAX =...
51
62
4,915,200
29186287
k, n, m = map(int,input().split()) x, y = [],[] for i in range(k): q, p = map(int, input().split()) x.append(min(q, p)) y.append(max(q, p)) MAX = 0 for i in range(k): for j in range(i+1,k): ok = False if x[i] + x[j] <= n and y[i] <= m and y[j] <= m: ok = True elif x[i...
Educational Codeforces Round 26
ICPC
2,017
1
256
Two Seals
One very important person has a piece of paper in the form of a rectangle a × b. Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees). A very importa...
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100). Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
null
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper. In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the large...
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
1,500
["brute force", "implementation"]
51
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"inpu...
false
stdio
null
true
404/A
404
A
Python 3
TESTS
41
124
8,704,000
80209147
a = int(input()) mid = a//2 b=[] c=[] for i in range(a): t = list(input()) b.append(t) for j in t: c.append(j) if len(set(c))!=2: print('NO') elif c.count(c[0])!=2*a-1: print('NO') elif c.count(c[1])!=a**2-(2*a-1): print('NO') elif b[mid][mid]!=b[0][0] or b[a-1][a-1]!=b[0][0]: print(...
47
46
0
159209670
n = int(input()) s1 = input() s = ''.join(sorted(set(s1))) c = 1 co = 1 mid = (n//2)-1 li = [s1] for i in range(n-1): ss1 = input() li.append(ss1) if i==mid: if ss1 != ss1[::-1]: c = 0 ss = ''.join(sorted(set(ss1))) if ss!=s: c = 0 if ss1 == s1: co += 1 ...
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Valera and X
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
null
null
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
1,000
["implementation"]
47
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r...
false
stdio
null
true
350/A
350
A
PyPy 3
TESTS
22
280
0
94889590
n,m=map(int,input().split()) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) if max(a)<min(b): if min(a)*2<max(a) and min(a)*2<min(b): print(max(a)) elif min(a)*2>max(a) and min(a)*2<min(b): print(min(a)*2) else: print(-1) else: print(-1)
45
62
0
221802631
nm=input().split() n=int(nm[0]) m=int(nm[1]) correct=list(map(int,input().split())) wrong=list(map(int,input().split())) point4=True TL=max(2*min(correct),max(correct)) if min(wrong)<=TL: point4=False if point4: print(TL) else: print(-1)
Codeforces Round 203 (Div. 2)
CF
2,013
2
256
TL
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time...
The first line contains two integers n, m (1 ≤ n, m ≤ 100). The second line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the running time of each of the n correct solutions in seconds. The third line contains m space-separated positive integers b1, b2, ..., bm (1 ≤ bi ≤ 100) — the runni...
If there is a valid TL value, print it. Otherwise, print -1.
null
null
[{"input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5"}, {"input": "3 1\n3 4 5\n6", "output": "-1"}]
1,200
["brute force", "greedy", "implementation"]
45
[{"input": "3 6\r\n4 5 2\r\n8 9 6 10 7 11\r\n", "output": "5"}, {"input": "3 1\r\n3 4 5\r\n6\r\n", "output": "-1\r\n"}, {"input": "2 5\r\n45 99\r\n49 41 77 83 45\r\n", "output": "-1\r\n"}, {"input": "50 50\r\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 ...
false
stdio
null
true
350/A
350
A
PyPy 3
TESTS
22
312
0
67623801
n,m=map(int,input().split()) R=list(map(int,input().split())) W=list(map(int,input().split())) R.sort() W.sort() if max(R)<min(W): for i in R: if i*2<max(R): print(max(R)) break else: for i in R: if max(R)<i*2<min(W): print(i*2) ...
45
92
0
4621548
import sys n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort() ans = a[0] * 2 if ans < a[-1]: ans = a[-1] if ans >= b[0]: print(-1) sys.exit() print(ans)
Codeforces Round 203 (Div. 2)
CF
2,013
2
256
TL
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time...
The first line contains two integers n, m (1 ≤ n, m ≤ 100). The second line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the running time of each of the n correct solutions in seconds. The third line contains m space-separated positive integers b1, b2, ..., bm (1 ≤ bi ≤ 100) — the runni...
If there is a valid TL value, print it. Otherwise, print -1.
null
null
[{"input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5"}, {"input": "3 1\n3 4 5\n6", "output": "-1"}]
1,200
["brute force", "greedy", "implementation"]
45
[{"input": "3 6\r\n4 5 2\r\n8 9 6 10 7 11\r\n", "output": "5"}, {"input": "3 1\r\n3 4 5\r\n6\r\n", "output": "-1\r\n"}, {"input": "2 5\r\n45 99\r\n49 41 77 83 45\r\n", "output": "-1\r\n"}, {"input": "50 50\r\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 ...
false
stdio
null
true
350/A
350
A
PyPy 3
TESTS
22
186
0
107026149
n,m = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) s = max(a) t = min(a) u = min(b) if s>u: print(-1) elif n==1: if s*2<u: print(s*2) else: print(-1) else: if t*2>s and t*2<u: print(t*2) elif t*2<s and s<u: print(s) ...
45
92
0
4621819
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) mi = min(a) ma = max(a) k = min(b) if (2 * mi <= ma): v = ma else: v = 2 * mi if v >= k: print(-1) else: print(v)
Codeforces Round 203 (Div. 2)
CF
2,013
2
256
TL
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time...
The first line contains two integers n, m (1 ≤ n, m ≤ 100). The second line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the running time of each of the n correct solutions in seconds. The third line contains m space-separated positive integers b1, b2, ..., bm (1 ≤ bi ≤ 100) — the runni...
If there is a valid TL value, print it. Otherwise, print -1.
null
null
[{"input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5"}, {"input": "3 1\n3 4 5\n6", "output": "-1"}]
1,200
["brute force", "greedy", "implementation"]
45
[{"input": "3 6\r\n4 5 2\r\n8 9 6 10 7 11\r\n", "output": "5"}, {"input": "3 1\r\n3 4 5\r\n6\r\n", "output": "-1\r\n"}, {"input": "2 5\r\n45 99\r\n49 41 77 83 45\r\n", "output": "-1\r\n"}, {"input": "50 50\r\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 ...
false
stdio
null
true
583/B
583
B
Python 3
TESTS
3
46
0
13511035
n = int(input()) computers = [int(item) for item in input().split()] count = 0 turnCount = -1 index = 0 visited = [] step = 0 while count < n: if index == n-1: step = -1 if len(visited) < n-1 or n-1 in visited: turnCount += 1 elif index == 0: step = 1 if len(visited) ...
56
93
1,536,000
197745534
n=int(input()) a=list(map(int,input().split())) s=0 r=0 i=0 k=1 f=0 while s!=n: if a[i]<=s: s+=1 a[i]=9999 if (s!=n)and((i==n-1)or((i==0)and(f))): r+=1 k*=-1 f=1 i+=k print(r)
Codeforces Round 323 (Div. 2)
CF
2,015
1
256
Robot's Task
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at ...
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
null
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece. In the second sample to...
[{"input": "3\n0 2 0", "output": "1"}, {"input": "5\n4 2 3 0 1", "output": "3"}, {"input": "7\n0 3 1 0 5 2 6", "output": "2"}]
1,200
["greedy", "implementation"]
56
[{"input": "3\r\n0 2 0\r\n", "output": "1\r\n"}, {"input": "5\r\n4 2 3 0 1\r\n", "output": "3\r\n"}, {"input": "7\r\n0 3 1 0 5 2 6\r\n", "output": "2\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n0 1\r\n", "output": "0\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": ...
false
stdio
null
true
899/A
899
A
Python 3
TESTS
18
108
9,113,600
34095135
# -*- coding: utf-8 -*- """ Created on Fri Jan 12 00:45:45 2018 @author: Sand Boa """ def validator(chunk:int)->int: pass if __name__ == "__main__": test_case:int = int(input()) count:int = 0 group_conf:list = list(map(int,input().split())) one_member:int= group_conf.count(1) two_member:i...
67
46
2,969,600
153637962
n=int(input()) s=input().split() print(min(s.count('1'),s.count('2'))+((s.count('1')-min(s.count('1'),s.count('2')))//3))
Codeforces Round 452 (Div. 2)
CF
2,017
1
256
Splitting in Teams
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams...
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
null
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and...
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
800
["constructive algorithms", "greedy", "math"]
67
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1...
false
stdio
null
true
899/A
899
A
Python 3
TESTS
18
124
3,993,600
77999923
n = int(input()) l = list(map(int,input().split())) if l.count(2)!=0 and l.count(1)!=0: print(min(l.count(2),l.count(1))) elif l.count(1)==0: print(0) elif l.count(2)==0: print(l.count(1)//3)
67
61
4,505,600
205263420
n=int(input()) l=input().split() c2=l.count("2") c1=l.count("1") r=min(c2,c1) print(r+(c1-r)//3)
Codeforces Round 452 (Div. 2)
CF
2,017
1
256
Splitting in Teams
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams...
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
null
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and...
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
800
["constructive algorithms", "greedy", "math"]
67
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1...
false
stdio
null
true
899/A
899
A
Python 3
TESTS
18
77
3,686,400
158865077
a1=int(input()) a=list(map(int, input().split())) a2=a.count(1) a3=a.count(2) if a2<a3 and a3!=0: print(a2) elif a3<a2 and a3==0: print(a2//3) elif a3<a2: print(a3) else: print(a2)
67
62
1,228,800
112080410
a=int(input()) b=input() c2=b.count('2') c1=b.count('1') sum=0 sum+=min(c2,c1) c1-=c2 if c1>0: sum+=c1//3 print(sum)
Codeforces Round 452 (Div. 2)
CF
2,017
1
256
Splitting in Teams
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams...
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
null
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and...
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
800
["constructive algorithms", "greedy", "math"]
67
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1...
false
stdio
null
true
899/A
899
A
Python 3
TESTS
18
78
4,096,000
110541185
n=int(input()) nums=list(map(int,input().split(' '))) one=nums.count(1) two=nums.count(2) if one==0: print(0) elif two==0: print(one//3) else: discard=max(one,two)-min(one,two) form=len(nums)-discard print(form//2)
67
62
1,331,200
221678496
n = int(input()) t = input() ones = t.count('1') twos = t.count('2') threes = 0 threes += min(ones,twos) ones -= min(ones,twos) twos -= min(ones,twos) threes += ones//3 print(threes)
Codeforces Round 452 (Div. 2)
CF
2,017
1
256
Splitting in Teams
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams...
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
null
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and...
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
800
["constructive algorithms", "greedy", "math"]
67
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1...
false
stdio
null
true
540/C
540
C
Python 3
TESTS
6
46
102,400
164631456
from collections import deque as dq n, m = map(int, input().split()) matrix = [list(input()) for i in range(n)] x, y = map(int, input().split()) start = (x-1, y-1) x, y = map(int, input().split()) end = (x-1, y-1) d = dq() d.append([start[0], start[1], matrix[:]]) nb = 1 if matrix[end[0]][end[1]] == '.': nb = ...
102
342
24,576,000
103383334
from collections import deque directions = ((1, 0), (0, 1), (-1, 0), (0, -1)) n, m = map(int, input().split()) a = [list(input()) for _ in range(n)] si, sj = map(lambda x:int(x)-1, input().split()) ti, tj = map(lambda x:int(x)-1, input().split()) def is_valid(i, j): return 0 <= i < n and 0 <= j < m def check(i, j...
Codeforces Round 301 (Div. 2)
CF
2,015
2
256
Ice Cave
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists e...
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integer...
If you can reach the destination, print 'YES', otherwise print 'NO'.
null
In the first sample test one possible path is: $$(1,6)\rightarrow(2,6)\rightarrow(3,6)\rightarrow(4,5)\rightarrow(4,4)\rightarrow(4,3)\rightarrow(4,2)\rightarrow(4,1)\rightarrow(3,2)\rightarrow(2,3)\rightarrow(2,2)$$ After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time...
[{"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "output": "YES"}, {"input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "output": "NO"}, {"input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "output": "YES"}]
2,000
["dfs and similar"]
102
[{"input": "4 6\r\nX...XX\r\n...XX.\r\n.X..X.\r\n......\r\n1 6\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n.X..\r\n...X\r\nX.X.\r\n....\r\n.XX.\r\n5 3\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "4 7\r\n..X.XX.\r\n.XX..X.\r\nX...X..\r\nX......\r\n2 2\r\n1 6\r\n", "output": "YES\r\n"}, {"input": "5 3\r\n.XX\r\n...
false
stdio
null
true
899/A
899
A
Python 3
TESTS
18
124
3,584,000
73123067
n=int(input()) li=list(map(int,input().split())) one=li.count(1) two=li.count(2) print(max(min(one,two),int(one//3)))
67
62
2,969,600
153706523
n = int(input()) w = input().split() a = w.count('1') b = w.count('2') print(min(a,b) + (a - min(a,b))//3)
Codeforces Round 452 (Div. 2)
CF
2,017
1
256
Splitting in Teams
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams...
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
null
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and...
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
800
["constructive algorithms", "greedy", "math"]
67
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1...
false
stdio
null
true
899/A
899
A
Python 3
TESTS
18
77
3,686,400
202008928
n = int(input()) group = list(map(int, input().split())) n1 = group.count(1) n2 = group.count(2) if n1 == 0: print(0) elif n2 == 0: print(n1 // 3) else: if n2 > n1: print(n1) else: print(n2)
67
62
3,686,400
149513641
n=int(input());r=[*map(int,input().split())] x=r.count(1);y=n-x print(min(x,y)+max(0,x-y)//3)
Codeforces Round 452 (Div. 2)
CF
2,017
1
256
Splitting in Teams
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams...
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
null
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and...
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
800
["constructive algorithms", "greedy", "math"]
67
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1...
false
stdio
null
true
899/A
899
A
Python 3
TESTS
18
124
2,969,600
44864940
x=int(input()) y1=input().split() s=y1.count("1") s1=y1.count("2") if (s!=0) and (s1==0): print(s//3) elif s>s1: print(s1) elif s<s1: print(s) elif s==s1: print(s)
67
62
5,529,600
223284000
n = int(input()) a = list(map(int, input().split())) groups1 = a.count(1) groups2 = a.count(2) max = 0 max += min(groups1, groups2) groups1 -= max groups2 -= max max += groups1 // 3 print(max)
Codeforces Round 452 (Div. 2)
CF
2,017
1
256
Splitting in Teams
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams...
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
null
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and...
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
800
["constructive algorithms", "greedy", "math"]
67
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1...
false
stdio
null
true
899/A
899
A
PyPy 3
TESTS
18
108
20,172,800
129632760
n, lst, s1, s2 = int(input()), list(map(int, input().split())), 0, 0 for x in lst: if x == 1: s1 += 1 else: s2 += 1 print(max(s1 // 3, min(s1, s2)))
67
62
6,860,800
33398911
if __name__ == '__main__': n = input() a = input() num1 = a.count('1') num2 = a.count('2') ans = min(num1,num2) + max(num1-num2,0)//3 print(ans)
Codeforces Round 452 (Div. 2)
CF
2,017
1
256
Splitting in Teams
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams...
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
null
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and...
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
800
["constructive algorithms", "greedy", "math"]
67
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1...
false
stdio
null
true
899/A
899
A
Python 3
TESTS
18
140
3,993,600
60493630
n = int(input()) l = list(map(int,input().split())) a = l.count(1) b = l.count(2) if b==0: print(len(l)//3) else: print(min(a,b))
67
62
6,963,200
33332425
n = int(input()) A = input() a = A.count('2') b = A.count('1') print(min(a,b)+(b-min(a,b))//3)
Codeforces Round 452 (Div. 2)
CF
2,017
1
256
Splitting in Teams
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams...
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
null
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups. In the second example he can't make a single team. In the third example the coach can form three teams. For example, he can do this in the following way: - The first group (of two people) and...
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
800
["constructive algorithms", "greedy", "math"]
67
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1...
false
stdio
null
true
404/A
404
A
Python 3
TESTS
31
46
0
206932343
n=int(input()) o="YES" g=None for i in range(n): s=list(input()) if (g is None): g=s[0] if(s[i]==s[n-i-1] and s[i]==g and len(set(s))==2 ): if (s==s[::-1]): continue else : o="NO" break else: ...
47
46
0
162679552
n = int(input()) l = 0 d = None o = None for i in range(n): s = input() for i in range(len(s)): if not d: d = s[i] elif not o: o = s[i] if o == d: print("NO") quit() elif l == i or n - l - 1 == i: if s[i] !=...
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Valera and X
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
null
null
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
1,000
["implementation"]
47
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r...
false
stdio
null
true
404/A
404
A
PyPy 3-64
TESTS
35
62
1,945,600
204389810
n = int(input()) ; re = [] ; nn = n ; nnn = n for _ in range(n) : re.append(input()) chk = re[0][0] c = 0 ; i = 0 ; j = 0 while c < n : if re[i][j] == chk : c+=1 ; i+=1 ; j+=1 else : print('NO') ; exit() cc = 0 ; ii = nn-1 ; jj= nn-1 while cc <n : if re[ii][jj] == chk : cc+=1 ; ii-...
47
46
0
172751795
n=int(input()) if n==1: w=input() print("YES") else: check=True st=input() l1=st[0] l2=st[1] if st[n-1]!=l1 or st.count(l2)!=n-2: check=False for i in range(1, n): if not check: break st=input() if st[i]==l1 and st[n-1-i]==l1 and (((i*2)+1==n a...
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Valera and X
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
null
null
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
1,000
["implementation"]
47
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r...
false
stdio
null
true
822/B
822
B
PyPy 3
TESTS
10
77
0
143743779
import math n, m = map(int, input().split()) s = list(input()) t = list(input()) idx = -1 mv = math.inf for i in range(m - n + 1): cnt = 0 for j in range(n): if s[j] != t[i + j]: cnt += 1 if cnt < mv: idx = i mv = cnt print(cnt) for i in range(n): if s[i] != t[idx...
113
77
3,072,000
155796365
n,m=map(int,input().split()) s,t=input(),input() r=[0]*(m+1) for i in range(m-n+1): a=[j+1 for j,x in enumerate(zip(s,t[i:i+n])) if x[0]!=x[1]] if len(a)<len(r):r=a print(len(r)) print(*r)
Codeforces Round 422 (Div. 2)
CF
2,017
1
256
Crossword solving
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple ta...
The first line contains two integers n and m (1 ≤ n ≤ m ≤ 1000) — the length of the string s and the length of the string t correspondingly. The second line contains n lowercase English letters — string s. The third line contains m lowercase English letters — string t.
In the first line print single integer k — the minimal number of symbols that need to be replaced. In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering ...
null
null
[{"input": "3 5\nabc\nxaybz", "output": "2\n2 3"}, {"input": "4 10\nabcd\nebceabazcd", "output": "1\n2"}]
1,000
["brute force", "implementation", "strings"]
113
[{"input": "3 5\r\nabc\r\nxaybz\r\n", "output": "2\r\n2 3 \r\n"}, {"input": "4 10\r\nabcd\r\nebceabazcd\r\n", "output": "1\r\n2 \r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "0\r\n\r\n"}, {"input": "1 1\r\na\r\nz\r\n", "output": "1\r\n1 \r\n"}, {"input": "3 5\r\naaa\r\naaaaa\r\n", "output": "0\r\n\r\n"}, {"input": "...
false
stdio
null
true
825/C
825
C
Python 3
TESTS
6
46
5,632,000
34468709
n,k = map(int,input().split()) dif = list(map(int,input().split())) c = 0 mx = 0 for elem in dif: if elem>k*2 and elem>mx*2: c+=1 break if elem>mx: mx = elem print(c)
61
46
0
186670111
n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() jauap=0 for i in a: while i>k*2: jauap+=1 k=k*2 k=max(k,i) print(jauap)
Educational Codeforces Round 25
ICPC
2,017
1
256
Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Ma...
The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
null
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second ...
[{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}]
1,600
["greedy", "implementation"]
61
[{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 ...
false
stdio
null
true
404/A
404
A
Python 3
TESTS
35
109
7,270,400
127673150
n = int(input()) lst1 = [] J = "" H = 0 for i in range(n): S = input() lst1.append(S) J = J + S for j in range(n): for k in range(n): if j==k: if lst1[j][k]==J[0] and lst1[n-j-1][n-k-1]==J[0]: H = H + 1 Q = J.count(J[1]) if H == n: if Q == (n*n - (2*n-1)) : ...
47
46
0
176497800
a=int(input()) s='' c=0 for i in range(a): x=input() s+=x if s==s[::-1] and s.count(s[0])==a*2-1: print("YES") else: print("NO")
Codeforces Round 237 (Div. 2)
CF
2,014
1
256
Valera and X
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
null
null
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
1,000
["implementation"]
47
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r...
false
stdio
null
true
600/C
600
C
PyPy 3-64
TESTS
4
46
0
194303698
import sys from collections import * input = sys.stdin.readline from math import * def mrd(): return [int(x) for x in input().split()] def rd(): return int(input()) MAXN = 2 * 10**5 + 5 INF = 10**16 * 2 mod = 10**9 + 7 #----------------------------------------------------------------------------------# def solve(): ...
66
77
2,355,200
166596253
from collections import defaultdict def main(): s = input() l = defaultdict(int) for c in s: l[c] += 1 u = sorted(list(filter(lambda x: l[x] % 2, l.keys()))) for i in range(0, int(len(u) / 2)): l[u[i]] += 1 l[u[-i-1]] -= 1 r = "" for c in sorted(l....
Educational Codeforces Round 2
ICPC
2,015
2
256
Make Palindrome
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string s consisting of lowercase Latin letters. At once you can choose any position in th...
The only line contains string s (1 ≤ |s| ≤ 2·105) consisting of only lowercase Latin letters.
Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes.
null
null
[{"input": "aabc", "output": "abba"}, {"input": "aabcd", "output": "abcba"}]
1,800
["constructive algorithms", "greedy", "strings"]
66
[{"input": "aabc\r\n", "output": "abba\r\n"}, {"input": "aabcd\r\n", "output": "abcba\r\n"}, {"input": "u\r\n", "output": "u\r\n"}, {"input": "ttttt\r\n", "output": "ttttt\r\n"}, {"input": "xxxvvvxxvv\r\n", "output": "vvvxxxxvvv\r\n"}, {"input": "wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrr...
false
stdio
null
true
247/A
250
A
PyPy 3
TESTS
25
278
20,172,800
86347018
n=int(input()) a=list(map(int,input().split())) po=0 ne=0 no=0 l=[] for i in range(n): if(a[i]<0): ne=ne+1 if(a[i]>=0): po=po+1 if(ne==2): l.append(po+ne) po=0 ne=0 if(len(l)>0): if(po>0): l[-1]=l[-1]+po if(ne>0): l.append(ne) else: l.append(po+ne) print(len(l)) print(*l)
69
92
0
138867699
n = int(input()) massiv = list(map(int, input().split())) result = [0] count = 0 for num in massiv: if num < 0: if count == 2: count = 0 result.append(0) count += 1 result[-1] += 1 print(len(result)) print(*result)
CROC-MBTU 2012, Final Round
CF
2,012
2
256
Paper Work
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is n...
The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them.
null
Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder.
[{"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "output": "3\n5 3 3"}, {"input": "5\n0 -1 100 -1 0", "output": "1\n5"}]
1,000
[]
69
[{"input": "11\r\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\r\n", "output": "3\r\n5 3 3 "}, {"input": "5\r\n0 -1 100 -1 0\r\n", "output": "1\r\n5 "}, {"input": "1\r\n0\r\n", "output": "1\r\n1 "}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n0 0\r\n", "output": "1\r\n2 "}, {"input": "2\r\n-2 2\r\n", "output": "1\r\n...
false
stdio
import sys def read_input(input_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) return n, a def compute_min_k(n, a): if n == 0: return 0 folders = 0 current_neg = 0 current_size = 0 for ai in a: current_s...
true
192/B
192
B
Python 3
TESTS
14
124
0
139855045
n=int(input()) a=list(map(int,list(input().split()))) l=sorted(a) if l[0]==a[0] or l[0]==a[-1]: print(l[0]) else: v=[] for i in range(n): v.append([a[i],i]) arr=[0]*(n+2) v=sorted(v) for i in range(len(v)): arr[v[i][1]]="#" if v[i][1]-1>=0: if arr[v[i][1]]=="#...
85
92
0
156561148
n=int(input()) L=list(map(int,input().split())) i=0 sol=[L[0]] while i+2<len(L)-1: if L[i+1]>L[i+2]: sol.append(L[i+1]) i+=1 else: sol.append(L[i+2]) i+=2 sol.append(L[len(L)-1]) print(min(sol))
Codeforces Round 121 (Div. 2)
CF
2,012
2
256
Walking in the Rain
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from ...
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles. The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Print a single number — the sought number of days.
null
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it. In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed ...
[{"input": "4\n10 3 5 10", "output": "5"}, {"input": "5\n10 2 8 3 5", "output": "5"}]
1,100
["brute force", "implementation"]
85
[{"input": "4\r\n10 3 5 10\r\n", "output": "5\r\n"}, {"input": "5\r\n10 2 8 3 5\r\n", "output": "5\r\n"}, {"input": "10\r\n10 3 1 6 7 1 3 3 8 1\r\n", "output": "1\r\n"}, {"input": "10\r\n26 72 10 52 2 5 61 2 39 64\r\n", "output": "5\r\n"}, {"input": "100\r\n8 2 1 2 8 3 5 8 5 1 9 3 4 1 5 6 4 2 9 10 6 10 10 3 9 4 10 5 3 ...
false
stdio
null
true
584/C
584
C
PyPy 3-64
TESTS
7
62
0
217503595
import sys input = lambda: sys.stdin.readline().rstrip() import math from heapq import heappush , heappop from collections import defaultdict,deque,Counter ALPHA = 'abcdefghijklmnopqrstuvwxyz' N,T = map(int, input().split()) s = input() t = input() def deal(diffs): for a in ALPHA: if a in diffs:continue ...
78
124
11,776,000
194575939
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 from copy import deepcopy import heapq from sys import stdin, stdout # 加快读入速度, 但是注意后面的换行符(\n) # 如果是使用 input().split() 或者 int(input()) 之类的, 换行符就去掉了 input ...
Codeforces Round 324 (Div. 2)
CF
2,015
1
256
Marina and Vasya
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and ...
The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters.
Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.
null
null
[{"input": "3 2\nabc\nxyc", "output": "ayd"}, {"input": "1 0\nc\nb", "output": "-1"}]
1,700
["constructive algorithms", "greedy", "strings"]
78
[{"input": "3 2\r\nabc\r\nxyc\r\n", "output": "bac"}, {"input": "1 0\r\nc\r\nb\r\n", "output": "-1\r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "b"}, {"input": "2 1\r\naa\r\naa\r\n", "output": "ab"}, {"input": "3 1\r\nbcb\r\nbca\r\n", "output": "bcc"}, {"input": "4 3\r\nccbb\r\ncaab\r\n", "output": "cbca"}, {"input"...
false
stdio
import sys def hamming(s1, s2): return sum(c1 != c2 for c1, c2 in zip(s1, s2)) def solution_exists(n, t, s1, s2): a = sum(c1 == c2 for c1, c2 in zip(s1, s2)) d = n - a min_k = max(d - t, 0) max_k = min(d // 2, a + d - t) return min_k <= max_k def main(): input_path = sys.argv[1] outpu...
true
413/C
413
C
Python 3
TESTS
5
108
0
48322318
n, m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] auc = [] k = 1 for i in b: auc.append(a[i-k]) del(a[i-k]) k += 1 auc.sort() auc = auc[::-1] s = sum(a) for i in auc: if s<i: s+=i else: s+=s print(s)
67
62
0
6423998
n, m = list(map(int, input().split())) prices = list(map(int, input().split())) auci = list(map(int, input().split())) scores = 0 # m auc # n - m default for i in range(len(prices)): if (i+1) not in auci: scores += prices[i] prices[i] = 0 ra = [] for i in prices: if i != 0: ra.appe...
Coder-Strike 2014 - Round 2
CF
2,014
1
256
Jeopardy!
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have n questions, m of them are auction questi...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the prices of the questions. The third line contains m ...
In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
null
null
[{"input": "4 1\n1 3 7 5\n3", "output": "18"}, {"input": "3 2\n10 3 8\n2 3", "output": "40"}, {"input": "2 2\n100 200\n1 2", "output": "400"}]
1,400
["greedy", "math"]
67
[{"input": "4 1\r\n1 3 7 5\r\n3\r\n", "output": "18\r\n"}, {"input": "3 2\r\n10 3 8\r\n2 3\r\n", "output": "40\r\n"}, {"input": "2 2\r\n100 200\r\n1 2\r\n", "output": "400\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n1 5\r\n1 2\r\n", "output": "10\r\n"}, {"input": "5 3\r\n5 8 7 1 9\r\n2 5...
false
stdio
null
true
197/B
197
B
Python 3
TESTS
15
216
6,963,200
86123617
n,m=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) if n>m: if a[0]/b[0]>0: print("Infinity") else: print( "-Infinity") elif n<m: print('0/1') else: p=a[0] q=b[0] s='' if p/q<0: s='-' p=abs(p) q=abs(q) for i...
80
156
6,963,200
122437646
import math R=lambda:list(map(int,input().split())) n,m=R() a=R()[0] b=R()[0] if n>m: print(('-'if a*b<0 else'')+'Infinity') elif n<m: print('0/1') else: g=math.gcd(abs(a),abs(b)) a//=g b//=g if b<0:a,b=-a,-b print(str(a)+'/'+str(b))
Codeforces Round 124 (Div. 2)
CF
2,012
2
256
Limit
You are given two polynomials: - P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and - Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separ...
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the forma...
null
Let's consider all samples: 1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$ 2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$ 3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$ 4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$ 5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$ You c...
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
1,400
["math"]
80
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3...
false
stdio
null
true
825/C
825
C
Python 3
TESTS
6
61
4,915,200
28971506
#!/bin/python3 import sys n,k=map(int,input().split()) num=list(map(int,input().split())) ans=0 if num[0]>2*k: print(1) else: for i in range(1,n): if num[i]>2*num[i-1] and num[i]>2*k: ans=1 break print (ans)
61
61
4,812,800
28607483
n,k = map(int,input().split()) A = list(map(int,input().split())) A.sort() cnt = 0 for a in A: while a > 2 * k: cnt += 1 k *= 2 k = max(k, a) print(cnt)
Educational Codeforces Round 25
ICPC
2,017
1
256
Multi-judge Solving
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Ma...
The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
null
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second ...
[{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}]
1,600
["greedy", "implementation"]
61
[{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 ...
false
stdio
null
true
33/C
33
C
PyPy 3-64
TESTS
15
278
18,841,600
204088312
from logging import exception as ex n = int(input()) a = list(map(int, input().split())) # original sequence s1 = [] # commulative sum of a for i, v in enumerate(a): s1.append(v + (s1[i-1] if i > 0 else 0)) mn = 0 p = -1 # pointer to the min value in s1 for i, v in enumerate(s1): if v < mn: mn = v; p = i a2 = [*a] ...
89
280
7,372,800
14919821
n = int(input()) values = list(map(int, input().split())) best_infix = infix = 0 for x in values: infix = max(0, infix + x) best_infix = max(best_infix, infix) print(2 * best_infix - sum(values))
Codeforces Beta Round 33 (Codeforces format)
CF
2,010
2
256
Wonderful Randomized Sum
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th...
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
The first and the only line of the output should contain the answer to the problem.
null
null
[{"input": "3\n-1 -2 -3", "output": "6"}, {"input": "5\n-4 2 0 5 0", "output": "11"}, {"input": "5\n-1 10 -5 10 -2", "output": "18"}]
1,800
["greedy"]
89
[{"input": "3\r\n-1 -2 -3\r\n", "output": "6\r\n"}, {"input": "5\r\n-4 2 0 5 0\r\n", "output": "11\r\n"}, {"input": "5\r\n-1 10 -5 10 -2\r\n", "output": "18\r\n"}, {"input": "1\r\n-3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 -5 -2\r\n", "output": "12\r\n"}, {"input": "7\r\n-17 6 5 0 1 4 -1\r\n", "output": "34\r\n"}...
false
stdio
null
true
245/E
245
E
PyPy 3
TESTS
19
280
0
76459792
def solve(s): n = len(s) if(n == 1): return 1 else: start = 0 prev = s[0] ans = 0 f = 1 for i in range(1,n): f = 1 if(s[i] == prev): continue else: f = 0 ans = max(ans,i-start) start = i prev = s[i] # print(ans) if(f): ans = max(ans,n-start) start = i prev = s[...
30
92
0
4435266
#!/usr/bin/python3 inside = outside = 0 for c in list(input()): if c == '+': if outside: outside -= 1 inside += 1 else: if inside: inside -= 1 outside += 1 print(inside + outside)
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
ICPC
2,012
2
256
Mishap in Club
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ...
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
null
null
[{"input": "+-+-+", "output": "1"}, {"input": "---", "output": "3"}]
1,400
["greedy", "implementation"]
77
[{"input": "+-+-+\r\n", "output": "1\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "-\r\n", "output": "1\r\n"}, {"input": "--\r\n", "output": "2\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "----\r\n", "output": "4\r\n"}, {"input": "---+\r\n", "output": "3\r\n"}, {"input": "--+\r\n", "output": ...
false
stdio
null
true
204/B
204
B
Python 3
TESTS
36
686
17,612,800
128172358
size = int(input()) fcards = [] bcards = [] for i in range(size): front, back = input().split() fcards.append(front) bcards.append(back) fcount = {} bcount = {} for i in range(size): if fcards[i] not in fcount: fcount[fcards[i]]= 1 else: fcount[fcards[i]] += 1 if fcards[i] not i...
90
466
27,238,400
163173392
import sys input = sys.stdin.readline M = int(1e9) + 7 def solve(): n = int(input()) d = dict() for _ in range(n): x, y = map(int, input().split()) if x not in d: d[x] = [0, 0] if y not in d: d[y] = [0, 0] d[x][0] += 1 if x != y: ...
Codeforces Round 129 (Div. 1)
CF
2,012
2
256
Little Elephant and Cards
The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks...
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the ...
On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.
null
In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
[{"input": "3\n4 7\n4 7\n7 4", "output": "0"}, {"input": "5\n4 7\n7 4\n2 11\n9 7\n1 1", "output": "2"}]
1,500
["binary search", "data structures"]
90
[{"input": "3\r\n4 7\r\n4 7\r\n7 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 7\r\n7 4\r\n2 11\r\n9 7\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n", "output": "-1\r\n...
false
stdio
null
true