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
419/A
420
A
Python 3
TESTS
48
62
307,200
105117901
a = "AHIMNOUYTXWV" b = True c = input() for x in c: if x not in a: b = False break else: if c[::-1] != c: b = False if b == True: print("YES") else: print("NO")
80
46
0
173252354
name = input() valid_letters = "AHIMOTUVWXY" for i in name: if not i in valid_letters: print('NO') exit() reverted_name = name[::-1] if not reverted_name == name: print('NO') exit() print('YES')
Coder-Strike 2014 - Finals
CF
2,014
1
256
Start Up
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
null
null
[{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}]
1,000
[]
80
[{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUI...
false
stdio
null
true
419/A
420
A
Python 3
TESTS
48
46
204,800
173256106
if __name__ == "__main__": execao = ["B","C","D","E","F","G","J","K","L","P","Q","R","S","Z"] palavra = input() reverso = palavra[::-1] reversivel = True for x in execao: if x in palavra: reversivel = False break if reversivel and palavra == reverso: ...
80
46
0
173256104
if __name__ == '__main__': # Ler entrada str_input = input() # Deve possuir apenas caracteres simétricos symmetrics = "AHIMOTUVWXY" for char in "".join(set(str_input)): if not char in symmetrics: print("NO") exit(0) # Obter reverso rev_input = str_input[::-1] ...
Coder-Strike 2014 - Finals
CF
2,014
1
256
Start Up
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
null
null
[{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}]
1,000
[]
80
[{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUI...
false
stdio
null
true
670/F
670
F
PyPy 3
TESTS
106
389
11,776,000
119572321
import sys sys.stderr = sys.stdout from collections import Counter K = (0, 11, 102, 1003, 10004, 100005, 1000006) def number(D, S): m = len(D) for i in range(len(K)): if K[i] > m: k = m - i break sK = str(k) if len(S) == k: return S C = Counter(D) C.s...
118
420
6,451,200
20372824
import sys def main(): a = sys.stdin.readline().strip() b = sys.stdin.readline().strip() if a == "01" or a == "10": print("0") return cnt = [0] * 256 for i in map(ord, a): cnt[i] += 1 n = sum(cnt) l = 0 for i in range(1, 8): if i == le...
Codeforces Round 350 (Div. 2)
CF
2,016
2
256
Restore a Number
Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n. Magically, all the numbers were shuffled in arbitrary order while this note was passed to Kate. The only thing that Vasya remembers, is a non-empty substri...
The first line of the input contains the string received by Kate. The number of digits in this string does not exceed 1 000 000. The second line contains the substring of n which Vasya remembers. This string can contain leading zeroes. It is guaranteed that the input data is correct, and the answer always exists.
Print the smalles integer n which Vasya could pass to Kate.
null
null
[{"input": "003512\n021", "output": "30021"}, {"input": "199966633300\n63", "output": "3036366999"}]
2,300
["brute force", "constructive algorithms", "strings"]
118
[{"input": "003512\r\n021\r\n", "output": "30021\r\n"}, {"input": "199966633300\r\n63\r\n", "output": "3036366999\r\n"}, {"input": "01\r\n0\r\n", "output": "0\r\n"}, {"input": "0000454312911\r\n9213544\r\n", "output": "92135440000\r\n"}, {"input": "13\r\n3\r\n", "output": "3\r\n"}, {"input": "00010454312921\r\n9213544\...
false
stdio
null
true
419/A
420
A
PyPy 3
TESTS
48
93
1,126,400
150458861
import math from collections import deque alfabet = {'a': 1, 'b': 2,'c': 3,'d': 4,'e': 5,'f': 6,'g': 7,'h': 8,'i': 9,'j': 10,'k': 11,'l': 12,'m': 13,'n': 14,'o': 15,'p': 16,'q': 17,'r': 18,'s': 19,'t': 20,'u': 21,'v': 22,'w': 23,'x': 24,'y': 25,'z': 26} rasp='' #c=int(input()) for i in range(0,1): #n,m=map(int,input...
80
46
0
173331116
symmetricalLetters = "AHIMOTUVWXY" name = input() for letter in name: if letter not in symmetricalLetters: print("NO") exit(0) if (name == name[::-1]): print("YES") else: print("NO")
Coder-Strike 2014 - Finals
CF
2,014
1
256
Start Up
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
null
null
[{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}]
1,000
[]
80
[{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUI...
false
stdio
null
true
489/B
489
B
Python 3
TESTS
36
46
0
224677719
n = int(input()) a = list(map(int, input().split(' '))) m = int(input()) b = list(map(int, input().split(' '))) a1 = [0] * (max(a)+1) b1 = [0] * (max(b)+1) pair_count = 0 for i in range(n): a1[a[i]] += 1 for j in range(m): b1[b[j]] += 1 for i in range(len(a1)): while(0<a1[i]): if((i in range(len(b1...
81
46
0
195178401
def sopostavim(a,b): if 0 <= abs(a-b) <= 1: return True else: return False n = int(input()) p = list(map(int, input().split())) m = int(input()) d = list(map(int, input().split())) p.sort() d.sort() res = 0 for i in range(0, len(p)): for j in range(0, len(d)): if sopostavim(p[i],...
Codeforces Round 277.5 (Div. 2)
CF
2,014
1
256
BerSU Ball
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m...
The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ...
Print a single number — the required maximum possible number of pairs.
null
null
[{"input": "4\n1 4 6 2\n5\n5 1 5 7 9", "output": "3"}, {"input": "4\n1 2 3 4\n4\n10 11 12 13", "output": "0"}, {"input": "5\n1 1 1 1 1\n3\n1 2 3", "output": "2"}]
1,200
["dfs and similar", "dp", "graph matchings", "greedy", "sortings", "two pointers"]
81
[{"input": "4\r\n1 4 6 2\r\n5\r\n5 1 5 7 9\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 3 4\r\n4\r\n10 11 12 13\r\n", "output": "0\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n3\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n1\r\n9\r\n", "output": "1\r\n"}, {"in...
false
stdio
null
true
489/B
489
B
Python 3
TESTS
36
46
0
225727520
num_b=int(input()) boys=list(map(int,input().split())) boys.sort() num_g=int(input()) girls=list(map(int,input().split())) if len(boys)<=len(girls): initial=len(girls) for i in boys: if i in girls: girls.remove(i) elif i-1 in girls: girls.remove(i-1) elif i+1 in g...
81
46
0
195210578
n = int(input()) a = list(map(int, input().split())) m = int(input()) b = list(map(int, input().split())) a.sort() b.sort() i = 0 j = 0 count = 0 while i < n and j < m: if abs(a[i] - b[j]) <= 1: count += 1 i += 1 j += 1 elif a[i] < b[j]: i += 1 else: j += 1 print(coun...
Codeforces Round 277.5 (Div. 2)
CF
2,014
1
256
BerSU Ball
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m...
The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ...
Print a single number — the required maximum possible number of pairs.
null
null
[{"input": "4\n1 4 6 2\n5\n5 1 5 7 9", "output": "3"}, {"input": "4\n1 2 3 4\n4\n10 11 12 13", "output": "0"}, {"input": "5\n1 1 1 1 1\n3\n1 2 3", "output": "2"}]
1,200
["dfs and similar", "dp", "graph matchings", "greedy", "sortings", "two pointers"]
81
[{"input": "4\r\n1 4 6 2\r\n5\r\n5 1 5 7 9\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 3 4\r\n4\r\n10 11 12 13\r\n", "output": "0\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n3\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n1\r\n9\r\n", "output": "1\r\n"}, {"in...
false
stdio
null
true
961/D
961
D
PyPy 3-64
TESTS
24
202
13,721,600
185204815
import sys from array import array from math import gcd input = lambda: sys.stdin.readline().rstrip("\r\n") inp = lambda dtype: [dtype(x) for x in input().split()] debug = lambda *x: print(*x, file=sys.stderr) ceil1 = lambda a, b: (a + b - 1) // b Mint, Mlong = 2 ** 31 - 1, 2 ** 63 - 1 out, tests = [], 1 def slop(i,...
121
374
41,062,400
153775698
import sys input=sys.stdin.readline n=int(input()) if n<=3: print('YES') exit() x=[[0,0] for i in range(n)] for i in range(n): x[i][0],x[i][1]=map(int,input().split()) def check(a,b): ans=0 remove=2 remain=[] xx=x[0:a]+x[a+1:b]+x[b+1:] x1,x2,y1,y2=x[a][0],x[b][0],x[a][1],x[b][1] for ...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Pair Of Lines
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
null
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
2,000
["geometry"]
121
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1...
false
stdio
null
true
95/B
95
B
Python 3
TESTS
51
404
921,600
67603168
n = input() l = len(n) if l % 2 == 1: print('4' * (l // 2 + 1) + '7' * (l // 2 + 1)) exit(0) if n > ('7' * (l // 2) + '4' * (l // 2)): print('4' * (l // 2 + 1) + '7' * (l // 2 + 1)) exit(0) def set_range(p, start, end, num): for i in range(start, end): p[i] = num result = [None] * l for i in range(l): d = i...
86
122
1,843,200
170544207
def f(i,c,n4,n7):return s[:i]+c+'4'*n4+'7'*n7 P=print;s=input();n=len(s);n4=n7=n//2;z=(0,'4',n4,n7+1) if n&1==1:exit(P(f(*z))) for i,c in enumerate(s): if c>'7':break if c == "7": if n7 == 0:break n7 -= 1;continue if n7 > 0:z = (i, "7", n4, n7 - 1) if c > "4":break if c == "4": if n4 == 0:break ...
Codeforces Beta Round 77 (Div. 1 Only)
CF
2,011
2
256
Lucky Numbers
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output the least super lucky number that is more than or equal to n.
null
null
[{"input": "4500", "output": "4747"}, {"input": "47", "output": "47"}]
1,800
["dp", "greedy"]
86
[{"input": "4500\r\n", "output": "4747\r\n"}, {"input": "47\r\n", "output": "47\r\n"}, {"input": "1\r\n", "output": "47"}, {"input": "12\r\n", "output": "47\r\n"}, {"input": "4587\r\n", "output": "4747\r\n"}, {"input": "100\r\n", "output": "4477"}, {"input": "1007\r\n", "output": "4477\r\n"}, {"input": "99999999\r\n", ...
false
stdio
null
true
638/B
638
B
PyPy 3
TESTS
17
436
29,798,400
16842279
def is_sub(s1, s2): s = s1 + "#" + s2 n = len(s) z = [0] * n for i in range(1, n): l, r = 0, 0 z[i] = max(0, min(r - i, z[i - l])) while i+z[i] < n and s[z[i]] == s[i+z[i]]: z[i] += 1 if i+z[i] >= r: l = i r = i + z[i] for i in...
67
46
0
215563383
d = {} aa = [input() for _ in range(int(input()))] for ele in aa: for a, b in zip(ele, ele[1:]): d[a] = b # map with next character s = "" for ss in set("".join(aa)) - set(d.values()): s += ss while ss in d: ss = d[ss] s += ss print(s)
VK Cup 2016 - Qualification Round 2
CF
2,016
1
256
Making Genome in Berland
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En...
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are d...
In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.
null
null
[{"input": "3\nbcd\nab\ncdef", "output": "abcdef"}, {"input": "4\nx\ny\nz\nw", "output": "xyzw"}]
1,500
["*special", "dfs and similar", "strings"]
67
[{"input": "3\r\nbcd\r\nab\r\ncdef\r\n", "output": "abcdef\r\n"}, {"input": "4\r\nx\r\ny\r\nz\r\nw\r\n", "output": "xyzw\r\n"}, {"input": "25\r\nef\r\nfg\r\ngh\r\nhi\r\nij\r\njk\r\nkl\r\nlm\r\nmn\r\nno\r\nab\r\nbc\r\ncd\r\nde\r\nop\r\npq\r\nqr\r\nrs\r\nst\r\ntu\r\nuv\r\nvw\r\nwx\r\nxy\r\nyz\r\n", "output": "abcdefghijk...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) fragments = [line.strip() for line in f] with open(output_path) as f: correct_output = f.read().strip() ...
true
220/A
220
A
PyPy 3-64
TESTS
28
124
8,704,000
162913096
import sys input = sys.stdin.readline n = int(input()) w = list(map(int, input().split())) c = 0 d = [] for i in range(n-1): if w[i] <= w[i+1]: continue elif c == 0 and w[i] > w[i+1]: c = 1 d.append(i) else: d.append(i+1) c += 1 if c == 3: print('...
96
77
13,721,600
172778582
""" sort array and count the differences against unsorted, if there are more than 2 differences, it wasn't an accident """ def was_accident(n: int, array: list[int]) -> bool: """ time O(n log n) space O(n) """ # O(n log n) sorted_array = sorted(array) diffs = 0 # O(n) for i in ra...
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
220/A
220
A
PyPy 3
TESTS
28
248
10,956,800
57320916
class CodeforcesTask220ASolution: def __init__(self): self.result = '' self.array_len = 0 self.array = [] def read_input(self): self.array_len = int(input()) self.array = [int(x) for x in input().split(" ")] def process_task(self): to_swap1 = -1 to_s...
96
77
14,131,200
195980730
n = int(input()) a = list(map(int,input().split())) b = sorted(a) cnt = 0 for i in range(n): if a[i] != b[i]: cnt += 1 if cnt < 3: 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
220/A
220
A
Python 3
TESTS
28
218
9,420,800
5037967
n, t = int(input()), [0] + list(map(int, input().split())) + [1000000001] p = [i for i in range(n + 1) if t[i] > t[i + 1]] ans, l = 'NO', len(p) if l == 0: ans = 'YES' elif l < 3: if l == 1: x, y = p[0], p[0] + 1 while t[x] == t[x - 1]: x -= 1 else: x, y = p[0], p[1] + 1 if t[x - 1] <= t[y] ...
96
77
14,131,200
226367683
n = int(input()) a = list(map(int, input().split())) b = a[:] a.sort() cnt = 0 for i in range(n): if a[i] != b[i]: cnt += 1 if cnt <= 2: 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
714/B
714
B
Python 3
TESTS
25
109
9,011,200
111631536
# link: https://codeforces.com/contest/714/problem/B if __name__ == "__main__": n = int(input()) a = list(map(int, input().split())) unique = set(a) # now I have the unique elements in sorted order if len(unique) <= 2: print("YES") exit(0) n = len(unique) if sum(unique) % n...
79
77
9,113,600
167902807
n=int(input()) arr=set(map(int,input().split())) if len(arr)<=3: if len(arr)==3: arr1=[] for i in arr: arr1.append(i) arr1.sort() if arr1[1]-arr1[0]==arr1[2]-arr1[1]: print("YES") else: print("NO") else: print("YES") else:print("NO")
Codeforces Round 371 (Div. 2)
CF
2,016
1
256
Filya and Homework
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers a1, a2, ..., an. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x ...
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — elements of the array.
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
null
In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
[{"input": "5\n1 3 3 2 1", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}]
1,200
["implementation", "sortings"]
79
[{"input": "5\r\n1 3 3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1000000000\r\n", "output": "YES\r\n"}, {"input...
false
stdio
null
true
748/B
748
B
Python 3
TESTS
42
62
4,608,000
23302040
s = str(input()) t = str(input()) letters,letters_swp = {},{} new_t = '' for i in range(len(s)): if s[i] != t[i] and t[i] not in letters.values() and t[i] not in letters.keys(): letters.setdefault(s[i],t[i]) letters_swp.setdefault(t[i],s[i]) for q in range(len(t)): if t[q] in letters_swp.keys(): new_t += lett...
86
46
0
180975754
""" https://codeforces.com/problemset/problem/748/B """ a = input() b = input() dico = dict() dicoinv = dict() correct = True for x, y in zip(a, b): if x not in dico: dico[x] = dico.get(x, []) if y not in dico[x]: dico[x].append(y) if len(dico[x])>1: correct=False ...
Technocup 2017 - Elimination Round 3
CF
2,016
2
256
Santa Claus and Keyboard Check
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. I...
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines ...
null
null
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
1,500
["implementation", "strings"]
86
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaa...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: s, t = f.read().split() s = s.strip() t = t.strip() with open(submission_path, 'r') as f: lines = [line.strip() for line in f.readlines(...
true
220/A
220
A
PyPy 3
TESTS
28
202
9,216,000
121478750
n = int(input()) a = [] b = input() i = 0 while i < len(b): to_add = "" while i < len(b) and b[i] != " ": to_add += b[i] i += 1 a.append(int(to_add)) i += 1 two_times = False first = second = -1 for i in range(1, n): if a[i] < a[i - 1]: if first == -1: first = i...
96
92
12,800,000
211858580
n = int(input()) l = list(map(int,input().split())) l2 = sorted(l) counter = 0 res = "YES" for i in range(n) : if l[i] != l2[i] : counter += 1 if counter > 2 : res= "NO" break print(res)
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
748/B
748
B
Python 3
TESTS
68
62
4,608,000
23410307
s = input() t = input() used, ln = set(), 0 for i in range(len(s)): if (s[i] != t[i]) and (not (tuple(sorted([s[i], t[i]])) in used)): ln += 1 used.add(tuple(sorted([s[i], t[i]]))) a = [i[0] for i in used] b = [i[1] for i in used] if len(a) != len(set(a)) or len(b) != len(set(b)): print(-1) elif len...
86
62
4,608,000
23291438
s=input() s2=input() a=[set() for i in range(97)] for i in range(len(s)): a[ord(s[i])-97].add(ord(s2[i])-97) a[ord(s2[i])-97].add(ord(s[i])-97) if max([len(i) for i in a])>1: print(-1) else: t=set() for i in range(26): if a[i]!=set(): o=tuple(sorted([chr(i+97),chr(list(a[i])[0]+9...
Technocup 2017 - Elimination Round 3
CF
2,016
2
256
Santa Claus and Keyboard Check
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. I...
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines ...
null
null
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
1,500
["implementation", "strings"]
86
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaa...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: s, t = f.read().split() s = s.strip() t = t.strip() with open(submission_path, 'r') as f: lines = [line.strip() for line in f.readlines(...
true
961/D
961
D
Python 3
TESTS
48
482
11,161,600
190607971
def pairoflines(n, p): if n <= 3: return True def getkb(x1, y1, x2, y2): if x1 == x2: return None, x1 return (y1 - y2) / (x1 - x2), (x1 * y2 - x2 * y1) / (x1 - x2) def inline(k, b, x, y): if k is None: return x == b else: ...
121
404
18,022,400
71933707
import sys input = sys.stdin.readline class vector2: def __init__(self, x, y): self.x = x self.y = y def __sub__(self, other): return vector2(self.x - other.x, self.y - other.y) def __mul__(self, other): return self.x * other.y - self.y * other.x def oneline(a, b, c): ...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Pair Of Lines
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
null
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
2,000
["geometry"]
121
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1...
false
stdio
null
true
961/D
961
D
PyPy 3
TESTS
37
404
34,611,200
86183077
import sys import math from collections import defaultdict,deque import heapq mod=10**9+7 def check(others): p1=others[0] p2=others[1] m=0 if p1[0]==p2[0]: m=1e9 else: m=(p1[1]-p2[1])/(p1[0]-p2[0]) n=len(others) for i in range(1,n): p2=others[i] if p1==p2: continue if p1[0]==p2[0]: nm=1e9 else...
121
514
18,534,400
36969966
#!/usr/bin/env python3 import sys from itertools import combinations n = int(sys.stdin.readline().strip()) xys = [tuple(map(int, sys.stdin.readline().strip().split())) for _ in range(n)] xys = list(set(xys)) if len(xys) < 5: print ('YES') sys.exit(0) def is_on_line(p0, p1, p2): return ((p1[0] - p0[0]) * (p2[1] -...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Pair Of Lines
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
null
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
2,000
["geometry"]
121
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1...
false
stdio
null
true
961/D
961
D
PyPy 3
TESTS
14
404
28,057,600
109486261
import sys,math,itertools from collections import Counter,deque,defaultdict from bisect import bisect_left,bisect_right from heapq import heappop,heappush,heapify, nlargest from copy import deepcopy mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin....
121
514
19,456,000
36971955
from itertools import combinations from fractions import gcd def main(): n = int(input()) p = [list(map(int, input().split())) for _ in range(n)] print(solve(n, p)) def solve(n, p): if n < 5: return "YES" p5 = p[:5] ## for p1, p2 in combinations(p5, 2): ## print(p1, p2, line(p1, ...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Pair Of Lines
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
null
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
2,000
["geometry"]
121
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1...
false
stdio
null
true
993/C
993
C
PyPy 3
TESTS
77
1,450
1,638,400
39800799
n, m = map(int, input().split()) y1 = list(map(int, input().split())) y2 = list(map(int, input().split())) ps = {} for i in range(n): for j in range(m): p = y1[i] q = y2[j] a = p * 2 b = q * 2 inter = (a + b) // 2 if not inter in ps: ps[inter] = [] ...
88
1,294
11,468,800
100325174
n, m = map(int, input().strip().split()) y1 = list(map(int, input().strip().split())) y2 = list(map(int, input().strip().split())) y1.sort() y2.sort() u1 = list() u2 = list() p = 0 while p < n: q = p while q < n and y1[q] == y1[p]: q += 1 u1.append((y1[p], q - p)) p = q p = 0 while p < m: q...
Codeforces Round 488 by NEAR (Div. 1)
CF
2,018
2
256
Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $$$y$$$-coordinates, and their $$$x$$$-coordinate is equal to $$$-100$$$, while the second group is posit...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 60$$$), the number of enemy spaceships with $$$x = -100$$$ and the number of enemy spaceships with $$$x = 100$$$, respectively. The second line contains $$$n$$$ integers $$$y_{1,1}, y_{1,2}, \ldots, y_{1,n}$$$ ($$$|y_{1,i}| \le 10\,000$$$) — t...
Print a single integer – the largest number of enemy spaceships that can be destroyed.
null
In the first example the first spaceship can be positioned at $$$(0, 2)$$$, and the second – at $$$(0, 7)$$$. This way all the enemy spaceships in the first group and $$$6$$$ out of $$$9$$$ spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at $$$(0, 3)$$$, an...
[{"input": "3 9\n1 2 3\n1 2 3 7 8 9 11 12 13", "output": "9"}, {"input": "5 5\n1 2 3 4 5\n1 2 3 4 5", "output": "10"}]
2,100
["bitmasks", "brute force", "geometry"]
88
[{"input": "3 9\r\n1 2 3\r\n1 2 3 7 8 9 11 12 13\r\n", "output": "9\r\n"}, {"input": "5 5\r\n1 2 3 4 5\r\n1 2 3 4 5\r\n", "output": "10\r\n"}, {"input": "50 50\r\n744 333 562 657 680 467 357 376 759 311 371 327 369 172 286 577 446 922 16 69 350 92 627 852 878 733 148 857 663 969 131 250 563 665 67 169 178 625 975 457 4...
false
stdio
null
true
489/B
489
B
PyPy 3-64
TESTS
37
124
0
201966978
from collections import Counter size1 = int(input()) boys = list(map(int, input().split())) size2 = int(input()) girls = list(map(int, input().split())) girls.sort() pairs = 0 members = Counter(boys) for g in girls: if members[g] > 0: members[g] -= 1 pairs += 1 elif members[g-1] > 0: m...
81
46
0
196610946
n = int(input()) boys = list(map(int,input().split())) m = int(input()) girls = list(map(int,input().split())) boys = sorted(boys) girls = sorted(girls) c = 0 i = 0 j = 0 while i <n and j<m: if abs(boys[i]-girls[j])<2: c += 1 i += 1 j += 1 elif boys[i]>girls[j]: j += 1 elif b...
Codeforces Round 277.5 (Div. 2)
CF
2,014
1
256
BerSU Ball
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m...
The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ...
Print a single number — the required maximum possible number of pairs.
null
null
[{"input": "4\n1 4 6 2\n5\n5 1 5 7 9", "output": "3"}, {"input": "4\n1 2 3 4\n4\n10 11 12 13", "output": "0"}, {"input": "5\n1 1 1 1 1\n3\n1 2 3", "output": "2"}]
1,200
["dfs and similar", "dp", "graph matchings", "greedy", "sortings", "two pointers"]
81
[{"input": "4\r\n1 4 6 2\r\n5\r\n5 1 5 7 9\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 3 4\r\n4\r\n10 11 12 13\r\n", "output": "0\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n3\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n1\r\n9\r\n", "output": "1\r\n"}, {"in...
false
stdio
null
true
724/B
724
B
Python 3
TESTS
13
46
0
205675286
''' Online Python Compiler. Code, Compile, Run and Debug python program online. Write your code in this editor and press "Run" button to execute it. ''' n,m=map(int,input().split()) mat=[] for _ in range(n): mat.append(list(map(int,input().split()))) for c1 in range(...
86
62
4,915,200
21296483
from sys import stdin n, m = (int(x) for x in stdin.readline().split()) table = [] for _ in range(n): table.append([int(x) for x in stdin.readline().split()]) def tr(l): return list(map(list, zip(*l))) def need_one_or_zero_swap(l): swap = 2 for i, item in enumerate(l): if item != i + 1: ...
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
CF
2,016
2
256
Batch Sort
You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table. Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m.
If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
null
In the first sample, one can act in the following way: 1. Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2 2. In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4
[{"input": "2 4\n1 3 2 4\n1 3 4 2", "output": "YES"}, {"input": "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3", "output": "NO"}, {"input": "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5", "output": "YES"}]
1,500
["brute force", "greedy", "implementation", "math"]
86
[{"input": "2 4\r\n1 3 2 4\r\n1 3 4 2\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 2 3 4\r\n2 3 4 1\r\n3 4 1 2\r\n4 1 2 3\r\n", "output": "NO\r\n"}, {"input": "3 6\r\n2 1 3 4 5 6\r\n1 2 4 3 5 6\r\n1 2 3 4 6 5\r\n", "output": "YES\r\n"}, {"input": "3 10\r\n1 2 3 4 5 6 7 10 9 8\r\n5 2 3 4 1 6 7 8 9 10\r\n1 2 3 4 5 6 7...
false
stdio
null
true
961/D
961
D
Python 3
TESTS
7
61
716,800
190438472
from __future__ import division import copy import random import heapq import math import sys import bisect import re import time import datetime from functools import lru_cache from collections import deque from collections import Counter from collections import defaultdict from itertools import combinations from iter...
121
514
20,889,600
36962215
import atexit import io import sys # Buffering IO _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ _OUTPUT_BUFFER = io.StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) def ff(p, q, pp): npp = [] for r...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Pair Of Lines
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
null
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
2,000
["geometry"]
121
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1...
false
stdio
null
true
748/B
748
B
PyPy 3
TESTS
41
140
0
47269281
string1 = input() string2 = input() map = dict() for i in range(len(string1)): if string1[i] != string2[i]: map[string1[i]] = string2[i] map[string2[i]] = string1[i] tmp = "" for c in string2: if c in map: tmp += map[c] else: tmp += c printed = set() if string1 == tmp: ...
86
62
4,608,000
23295189
s = input() t = input() pairs = set() good = set() letters = set() for i in range(len(s)): pair = tuple(sorted([s[i], t[i]])) if pair not in pairs: if s[i] not in letters and t[i] not in letters: pairs.add(pair) letters.add(s[i]) letters.add(t[i]) else: ...
Technocup 2017 - Elimination Round 3
CF
2,016
2
256
Santa Claus and Keyboard Check
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. I...
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines ...
null
null
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
1,500
["implementation", "strings"]
86
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaa...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: s, t = f.read().split() s = s.strip() t = t.strip() with open(submission_path, 'r') as f: lines = [line.strip() for line in f.readlines(...
true
984/B
984
B
PyPy 3
TESTS
5
77
0
177262587
line = input() n, m = int(line[0]), int(line[-1]) grid = [] for i in range(n): grid.append([k for k in input()]) def k_neighbors(k, arr, x, y): total = 0 for i in range(x - 1, x + 2): for j in range(y - 1, y + 2): if (0 <= i < len(arr)) and (0 <= j < len(arr[i])): ...
84
77
4,505,600
231123888
a, b = map(int, input().split()) mas = [['0'] * (b + 2)] for i in range(a): mas.append(['0'] + list(input()) + ['0']) mas.append(['0'] * (b + 2)) osh = 0 for i in range(1, a + 1): for j in range(1, b + 1): if mas[i][j] == '.': mas[i][j] = '0' if mas[i][j] != '*': otn = 0 ...
Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
CF
2,018
1
256
Minesweeper
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won. Alex has grown up since then, so he easily wins the most difficu...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the sizes of the field. The next $$$n$$$ lines contain the description of the field. Each line contains $$$m$$$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $$$1$$$ to ...
Print "YES", if the field is valid and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrarily.
null
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1. You can read more about Minesweeper in Wikipedia's article.
[{"input": "3 3\n111\n1*1\n111", "output": "YES"}, {"input": "2 4\n*.*.\n1211", "output": "NO"}]
1,100
["implementation"]
84
[{"input": "3 3\r\n111\r\n1*1\r\n111\r\n", "output": "YES"}, {"input": "2 4\r\n*.*.\r\n1211\r\n", "output": "NO"}, {"input": "1 10\r\n.....1*1..\r\n", "output": "YES"}, {"input": "1 1\r\n4\r\n", "output": "NO"}, {"input": "10 10\r\n..........\r\n...111111.\r\n..13*21*1.\r\n.12**2111.\r\n.1*542..11\r\n.13**1..1*\r\n..2*...
false
stdio
null
true
748/B
748
B
Python 3
TESTS
67
62
307,200
105066688
import sys s=input() t=input() st1=[] st2=[] checked=[] right=[] for i in range(len(s)): if s[i] in checked and t[i] not in checked: print('-1') sys.exit() if s[i] not in checked and t[i] in checked: print('-1') sys.exit() if s[i] in right and t[i] not in ri...
86
62
4,608,000
23298959
s = input() t = input() change = dict() for i in range(len(s)): if s[i] in change: change[s[i]].add(t[i]) else: change[s[i]] = set(t[i]) if t[i] in change: change[t[i]].add(s[i]) else: change[t[i]] = set(s[i]) calc = 0 #print(change) for elem in change: calc += (len(c...
Technocup 2017 - Elimination Round 3
CF
2,016
2
256
Santa Claus and Keyboard Check
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. I...
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines ...
null
null
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
1,500
["implementation", "strings"]
86
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaa...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: s, t = f.read().split() s = s.strip() t = t.strip() with open(submission_path, 'r') as f: lines = [line.strip() for line in f.readlines(...
true
858/B
858
B
Python 3
TESTS
6
46
0
230101057
n, m = map(int, input().split()) s = [] for _ in range(m): k, f = map(int, input().split()) s.append((k, f)) s.sort(key=lambda x:x[1]) nums = [] for c in range(1, 20): for k, f in s: if not f * c - c + 1 <= k <= f * c: break else: nums.append(c) res = 0 for num in nums: t = (n - 1) // num + 1 ...
101
62
307,200
30486361
#!/usr/bin/env python3 # encoding: utf-8 FLOW_COUNT = 100 APARTMENT_COUNT = 100 AF_COUNT = 100 def build_for(app_per_flow): b = dict() for f in range(FLOW_COUNT): for a in range(app_per_flow): app = f * app_per_flow + a if app >= APARTMENT_COUNT: return b ...
Технокубок 2018 - Отборочный Раунд 1
CF
2,017
1
256
Which floor?
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o...
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 1...
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
null
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-...
[{"input": "10 3\n6 2\n2 1\n7 3", "output": "4"}, {"input": "8 4\n3 1\n6 2\n5 2\n2 1", "output": "-1"}]
1,500
["brute force", "implementation"]
101
[{"input": "10 3\r\n6 2\r\n2 1\r\n7 3\r\n", "output": "4\r\n"}, {"input": "8 4\r\n3 1\r\n6 2\r\n5 2\r\n2 1\r\n", "output": "-1\r\n"}, {"input": "8 3\r\n7 2\r\n6 2\r\n1 1\r\n", "output": "2\r\n"}, {"input": "4 2\r\n8 3\r\n3 1\r\n", "output": "2\r\n"}, {"input": "11 4\r\n16 4\r\n11 3\r\n10 3\r\n15 4\r\n", "output": "3\r\...
false
stdio
null
true
147/A
147
A
PyPy 3-64
TESTS
8
124
0
166675991
def helper(char, ans): for i in char: if i.isalpha(): ans += i else: ans = ans.rstrip() ans += i ans += ' ' return ans def checker(text): text = text.split() ans = '' for char in text: if char.isalpha(): ...
85
124
2,560,000
166866520
from sys import stdin def inta(arr): return [int(x) for x in arr] def sr(): return stdin.readline().strip() s = sr() k = [] p = list(',!?.') for t in s: if len(k) == 0: k.append(t) continue if k[-1] == ' ' and t == ' ': continue if t in p and k[-1] == ' ': wh...
Codeforces Testing Round 4
CF
2,012
2
256
Punctuation
You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters. Your task is to add spaces to the text by the following rules: - if there is no punctuation mark between two words...
The input data contains of a single non-empty line — the text whose length is no more than 10000 characters.
Print the text, edited according to the rules. In this problem you should follow the output format very strictly. For example, extra space at the end of the output line is considered as wrong answer. Note that a newline character at the end of the line doesn't matter.
null
null
[{"input": "galileo galilei was an italian physicist ,mathematician,astronomer", "output": "galileo galilei was an italian physicist, mathematician, astronomer"}, {"input": "galileo was born in pisa", "output": "galileo was born in pisa"}]
1,300
["implementation", "strings"]
85
[{"input": "galileo galilei was an italian physicist ,mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "galileo was born in pisa\r\n", "output": "galileo was born in pisa\r\n"}, {"input": "jkhksdfhsdfsf\r\n", "output": "jkhksdfhsdfsf\r...
false
stdio
null
true
220/A
220
A
PyPy 3
TESTS
32
155
11,980,800
147467123
n = int(input()) a = list(map(int,input().split())) sorted = [] for x in a: sorted.append(x) sorted.sort() ctr = 0 ans = "YES" for i in range(n): if a[i] != sorted[i]: ctr += 1 if ctr // 2 > 1: ans = "NO" break print(ans)
96
93
7,884,800
158835557
def solve(): n = int(input()) l = list(map(int, input().split())) ls = sorted(l) diff = 0 for idx in range(n): if l[idx] != ls[idx]: diff += 1 if diff > 2: return False return True def main(): ret = solve() ans = "YES" if ret else "NO" print(a...
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
593/B
593
B
Python 3
TESTS
68
764
16,076,800
14065405
N=int(input()) x1,x2=tuple(map(int,input().split())) a=[] b=[] for _ in range(N): m,c=tuple(map(int,input().split())) a.append((m*(x1+0.000001)+c,_)) b.append((m*(x2-0.000001)+c,_)) a.sort() b.sort() x=[] y=[] for i in range(N): x.append(a[i][1]) y.append(b[i][1]) if(x==y): print("NO") else: print("YES")
93
404
18,739,200
194474158
import sys input = sys.stdin.readline n = int(input()) a, b = map(int, input().split()) d = sorted([(a*i +j, b*i+j) for i, j in [list(map(int, input().split())) for _ in range(n)]]) for i in range(1, n): if d[i][0] > d[i - 1][0] and d[i][1] < d[i - 1][1]: print('YES') break else: print('NO')
Codeforces Round 329 (Div. 2)
CF
2,015
1
256
Anton and Lines
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessary to determine whether there is at least one point of intersection of two of these lines,...
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x1 and x2 ( - 1 000 000 ≤ x1 < x2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines. The following n lines co...
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
null
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it.
[{"input": "4\n1 2\n1 2\n1 0\n0 1\n0 2", "output": "NO"}, {"input": "2\n1 3\n1 0\n-1 3", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 2", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 3", "output": "NO"}]
1,600
["geometry", "sortings"]
93
[{"input": "4\r\n1 2\r\n1 2\r\n1 0\r\n0 1\r\n0 2\r\n", "output": "NO"}, {"input": "2\r\n1 3\r\n1 0\r\n-1 3\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 2\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 3\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n-1000000 1000000\r\n1000000 -1000000\r\n", "output"...
false
stdio
null
true
762/C
762
C
Python 3
TESTS
3
108
0
58819066
s1 = input() s2 = input() a = {} s = "" found = 0 for i in s1: if i not in a: a[i] = 1 else: a[i] = a[i]+1 for j in s2: if j in a and a[j]>=1: a[j] = a[j]-1 found = 1 s = s+j if found==1: print(s) else: print("-")
99
186
5,529,600
27122423
from macpath import curdir import bisect a=input() b=input() la=len(a) lb=len(b) forb=[la]*lb cur=0 for i in range(lb): while cur<la and a[cur]!=b[i]: cur+=1 if cur<la: forb[i]=cur cur+=1 else: break cur=la-1 bacb=[-1]*lb for i in range(lb-1,-1,-1): while cur>=0 and a[cur...
Educational Codeforces Round 17
ICPC
2,017
2
256
Two strings
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of th...
The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters.
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters. If the answer consists of zero characters, output «-» (a minus sign).
null
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty. In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
[{"input": "hi\nbob", "output": "-"}, {"input": "abca\naccepted", "output": "ac"}, {"input": "abacaba\nabcdcba", "output": "abcba"}]
2,100
["binary search", "hashing", "strings", "two pointers"]
99
[{"input": "hi\r\nbob\r\n", "output": "-\r\n"}, {"input": "abca\r\naccepted\r\n", "output": "ac\r\n"}, {"input": "abacaba\r\nabcdcba\r\n", "output": "abcba\r\n"}, {"input": "lo\r\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\r\n", "output": "-\r\n"}, {"input": "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\r\nmlmarpivirqbxcyhyer...
false
stdio
null
true
748/B
748
B
PyPy 3
TESTS
41
109
23,347,200
23292638
s = input() t = input() d = dict() for i in range(len(s)): if s[i] != t[i]: d[s[i]] = t[i] d[t[i]] = s[i] st = list(t) for i in range(len(s)): if d.get(st[i]) != None: st[i] = d[st[i]] st = ''.join(st) if st == s: *it, = d.items() for i in range(len(it)): if it[i][0] >...
86
62
4,608,000
23299799
def main(): abra, shacked = str(input()), str(input()) dictionary = dict() for i in range(len(shacked)): if not (shacked[i] == abra[i]): if abra[i] in dictionary.values() and dictionary[abra[i]] != shacked[i]: print(-1) return dictionary[abra[i...
Technocup 2017 - Elimination Round 3
CF
2,016
2
256
Santa Claus and Keyboard Check
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. I...
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines ...
null
null
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
1,500
["implementation", "strings"]
86
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaa...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: s, t = f.read().split() s = s.strip() t = t.strip() with open(submission_path, 'r') as f: lines = [line.strip() for line in f.readlines(...
true
757/B
757
B
PyPy 3-64
TESTS
48
358
13,209,600
176117153
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281...
134
218
13,209,600
115771847
mx = 10**5 + 1 cnt = [0] * mx n = int(input()) for c in map(int, input().split()): cnt[c] += 1 f = [0] * mx ans = 1 for i in range(2, mx): if f[i] == 0: f[i] = 1 for j in range(i + i, mx, i): f[j] = 1 cnt[i] += cnt[j] ans = max(ans, cnt[i]) print(ans)
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
CF
2,017
2
512
Bash's Big Day
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2, ...
The input consists of two lines. The first line contains an integer n (1 ≤ n ≤ 105), the number of Pokemon in the lab. The next line contains n space separated integers, where the i-th of them denotes si (1 ≤ si ≤ 105), the strength of the i-th Pokemon.
Print single integer — the maximum number of Pokemons Bash can take.
null
gcd (greatest common divisor) of positive integers set {a1, a2, ..., an} is the maximum positive integer that divides all the integers {a1, a2, ..., an}. In the first sample, we can take Pokemons with strengths {2, 4} since gcd(2, 4) = 2. In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there ...
[{"input": "3\n2 3 4", "output": "2"}, {"input": "5\n2 3 4 6 7", "output": "3"}]
1,400
["greedy", "math", "number theory"]
134
[{"input": "3\r\n2 3 4\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 6 7\r\n", "output": "3\r\n"}, {"input": "3\r\n5 6 4\r\n", "output": "2\r\n"}, {"input": "8\r\n41 74 4 27 85 39 100 36\r\n", "output": "4\r\n"}, {"input": "6\r\n89 20 86 81 62 23\r\n", "output": "3\r\n"}, {"input": "71\r\n23 84 98 8 14 4 42 56 83 87 ...
false
stdio
null
true
95/B
95
B
Python 3
TESTS
49
248
512,000
73432114
p = input() k='';n=len(p);a=b=0 if n%2 : k='4'*((n+1)//2)+'7'*((n+1)//2) elif p<='4'*(n//2)+'7'*(n//2): k='4'*(n//2)+'7'*(n//2) elif p<='7'*(n//2)+'4'*(n//2): f=0 for i in range(n): x,y = (4-int(p[i]))%10,(7-int(p[i]))%10 if int(p[i])>=8 and f==0: x=i-1 a-=k[x]=='...
86
186
1,945,600
218279964
def nextLuckyNumber(digits: str) -> str: n = len(digits) halfLen = n >> 1 if n & 1 or digits > f"{'7' * halfLen}{'4' * halfLen}": halfLen += 1 return f"{'4' * halfLen}{'7' * halfLen}" result = [0 for i in range(n)] remaining = [halfLen, halfLen] # number of 4s and 7s to add in resu...
Codeforces Beta Round 77 (Div. 1 Only)
CF
2,011
2
256
Lucky Numbers
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output the least super lucky number that is more than or equal to n.
null
null
[{"input": "4500", "output": "4747"}, {"input": "47", "output": "47"}]
1,800
["dp", "greedy"]
86
[{"input": "4500\r\n", "output": "4747\r\n"}, {"input": "47\r\n", "output": "47\r\n"}, {"input": "1\r\n", "output": "47"}, {"input": "12\r\n", "output": "47\r\n"}, {"input": "4587\r\n", "output": "4747\r\n"}, {"input": "100\r\n", "output": "4477"}, {"input": "1007\r\n", "output": "4477\r\n"}, {"input": "99999999\r\n", ...
false
stdio
null
true
95/B
95
B
PyPy 3
TESTS
49
186
5,734,400
152676216
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = list(input().rstrip()) l = len(n) if l % 2: c = l // 2 + 1 ans = ["4"] * c + ["7"] * c else: c = l // 2 x = [7] * c + [4] * c f = 1 for i, j in zip(n, x): if i - 48 < j: f = 2 bre...
86
622
20,480,000
206003189
from sys import stdin, stdout from collections import deque MOD = 10 ** 9 + 7 INF = float('inf') sze = 10 ** 4 + 1 EPS = 10 ** -6 s = stdin.readline().strip() challenger = [] for i in range(len(s)): if s[i] in '47': challenger.append(s[i]) elif s[i] in '89': update = [] ...
Codeforces Beta Round 77 (Div. 1 Only)
CF
2,011
2
256
Lucky Numbers
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output the least super lucky number that is more than or equal to n.
null
null
[{"input": "4500", "output": "4747"}, {"input": "47", "output": "47"}]
1,800
["dp", "greedy"]
86
[{"input": "4500\r\n", "output": "4747\r\n"}, {"input": "47\r\n", "output": "47\r\n"}, {"input": "1\r\n", "output": "47"}, {"input": "12\r\n", "output": "47\r\n"}, {"input": "4587\r\n", "output": "4747\r\n"}, {"input": "100\r\n", "output": "4477"}, {"input": "1007\r\n", "output": "4477\r\n"}, {"input": "99999999\r\n", ...
false
stdio
null
true
748/B
748
B
Python 3
TESTS
35
701
307,200
78386303
s=input() t=input() l=len(s) dict1={} dict2={} if(s==t): print(0) exit(0) list1=[] for i in range(l): flag1=0 if(s[i]!=t[i]): flag1=1 key,value=s[i],t[i] flag=0 for j in range(l): if(s[j]==key): if(t[j]!=value): flag=1 break if(s[j]==value): if(t[j]!=key): flag=1 break fo...
86
62
4,608,000
23301252
q=input() w=input() l=len(q) a=[] s=[0 for i in range(0,130)] t=[] for i in range(0,l): if q[i]==w[i]: t.append(q[i]) for i in range(0,l): if q[i]!=w[i]: a.append([q[i],w[i]]) s[ord(q[i])]+=1 s[ord(w[i])]+=1 c=q[i] if (q[i] in t) | (w[i] in t): s[0]=10...
Technocup 2017 - Elimination Round 3
CF
2,016
2
256
Santa Claus and Keyboard Check
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. I...
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines ...
null
null
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
1,500
["implementation", "strings"]
86
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaa...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: s, t = f.read().split() s = s.strip() t = t.strip() with open(submission_path, 'r') as f: lines = [line.strip() for line in f.readlines(...
true
95/B
95
B
Python 3
TESTS
49
218
1,126,400
67604057
def run(n): l = len(n) if l % 2 == 1: result = '4' * (l // 2 + 1) + '7' * (l // 2 + 1) print(result) return result if n > ('7' * (l // 2) + '4' * (l // 2)): result = '4' * (l // 2 + 1) + '7' * (l // 2 + 1) print(result) return result def set_range(p, start, end, num): for i in range(start, end): ...
86
780
1,536,000
5293258
b=input() a=[int(i) for i in b] l=len(a) flag=0 s=0 f=0 if l%2==1: flag=1 else: for i in range(l): if a[i]>7: flag=1 if(s==l//2 or s==i+1): break for j in range(i,-1,-1): if a[j]==4: a[j]=7 f-=1 ...
Codeforces Beta Round 77 (Div. 1 Only)
CF
2,011
2
256
Lucky Numbers
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.
Output the least super lucky number that is more than or equal to n.
null
null
[{"input": "4500", "output": "4747"}, {"input": "47", "output": "47"}]
1,800
["dp", "greedy"]
86
[{"input": "4500\r\n", "output": "4747\r\n"}, {"input": "47\r\n", "output": "47\r\n"}, {"input": "1\r\n", "output": "47"}, {"input": "12\r\n", "output": "47\r\n"}, {"input": "4587\r\n", "output": "4747\r\n"}, {"input": "100\r\n", "output": "4477"}, {"input": "1007\r\n", "output": "4477\r\n"}, {"input": "99999999\r\n", ...
false
stdio
null
true
979/B
979
B
Python 3
TESTS
86
139
8,908,800
38329168
import re s=[] abc=[] l=[] f=0 m=0 r=0 last=0 p=['Kuro','Shiro','Katie'] #ввод n=int(input()) for i in range(3): s.append(input()) #заполнение массива-алфавита for i in range(97,123): abc.append(chr(i)) for i in range(65,91): abc.append(chr(i)) #число повторов в 1 строке for i in range(len(abc))...
184
109
7,680,000
38233880
n=int(input()); m1=0; m2=0; m3=0; s1=input() s2=input() s3=input() x=len(s1) for t in 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM': m1=max(m1, s1.count(t)) m2=max(m2, s2.count(t)) m3=max(m3, s3.count(t)) d=[[m1,'Kuro'], [m2, 'Shiro'], [m3,'Katie']] d.sort() if (d[2][0]==x) and (n==1): if (d[...
Codeforces Round 482 (Div. 2)
CF
2,018
1
256
Treasure Hunt
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her. The three friends are very smart so they passed all the challenges very quickly and finally reached the destination...
The first line contains an integer $$$n$$$ ($$$0 \leq n \leq 10^{9}$$$) — the number of turns. Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $$$10^{5}$$$ uppercase and lowercase Latin letters and is not empty. It is guaranteed th...
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
null
In the first example, after $$$3$$$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $$$5$$$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $$$4$$$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon int...
[{"input": "3\nKuroo\nShiro\nKatie", "output": "Kuro"}, {"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces", "output": "Shiro"}, {"input": "1\nabcabc\ncbabac\nababca", "output": "Katie"}, {"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE", "output": "Draw"}]
1,800
["greedy"]
184
[{"input": "3\r\nKuroo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "7\r\ntreasurehunt\r\nthreefriends\r\nhiCodeforces\r\n", "output": "Shiro\r\n"}, {"input": "1\r\nabcabc\r\ncbabac\r\nababca\r\n", "output": "Katie\r\n"}, {"input": "15\r\nfoPaErcvJ\r\nmZaxowpbt\r\nmkuOlaHRE\r\n", "output": "Draw\r\n"}, {"in...
false
stdio
null
true
961/D
961
D
PyPy 3
TESTS
41
451
40,140,800
93960391
import sys from collections import Counter, defaultdict from math import gcd n = int(sys.stdin.buffer.readline().decode('utf-8')) points = [list(map(int, line.decode('utf-8').split())) for line in sys.stdin.buffer] if n <= 2: print('YES') exit() cnt = Counter() idx = defaultdict(list) for i, (x2, y...
121
514
21,094,400
104723938
from sys import stdin, stdout def pair_of_lines(n, xy_a): if len(xy_a) <= 3: return 'YES' p1, p2, p3 = xy_a[0], xy_a[1], xy_a[2] if judge(p1, kstr(p1, p2),xy_a): return 'YES' if judge(p1, kstr(p1, p3),xy_a): return 'YES' if judge(p2, kstr(p2, p3), xy_a): return 'YES...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Pair Of Lines
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
null
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
2,000
["geometry"]
121
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1...
false
stdio
null
true
730/I
730
I
PyPy 3
TESTS
22
156
0
96608454
from heapq import heappush, heappop def func(a, b, arr1, arr2): q = [] ret1 = [] ret2 = [] total = 0 for i in range(len(arr1)): heappush(q, [-arr1[i], arr2[i], i+1]) while a: p = heappop(q) ret1.append(p[2]) total += -p[0] a -= 1 q2 = [] for val in...
152
77
6,246,400
25329824
#!/usr/bin/env python3 from itertools import accumulate from heapq import heappop, heappush def top(ppl_indices, vals, start): Q = [] res = [0 for i in range(len(ppl_indices))] for k, idx in enumerate(ppl_indices): heappush(Q, -vals[idx]) if k >= start: res[k] = res[k-1] - heap...
2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,016
2
512
Olympiad in Programming and Sports
There are n students at Berland State University. Every student has two skills, each measured as a number: ai — the programming skill and bi — the sports skill. It is announced that an Olympiad in programming and sports will be held soon. That's why Berland State University should choose two teams: one to take part in...
The first line contains three positive integer numbers n, p and s (2 ≤ n ≤ 3000, p + s ≤ n) — the number of students, the size of the programming team and the size of the sports team. The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 3000), where ai is the programming skill of the i-th student. T...
In the first line, print the the maximum strength of the university on the Olympiad. In the second line, print p numbers — the members of the programming team. In the third line, print s numbers — the members of the sports team. The students are numbered from 1 to n as they are given in the input. All numbers printed ...
null
null
[{"input": "5 2 2\n1 3 4 5 2\n5 3 2 1 4", "output": "18\n3 4\n1 5"}, {"input": "4 2 2\n10 8 8 3\n10 7 9 4", "output": "31\n1 2\n3 4"}, {"input": "5 3 1\n5 2 5 1 7\n6 3 1 6 3", "output": "23\n1 3 5\n4"}]
2,000
["dp", "flows", "graphs", "greedy"]
152
[{"input": "5 2 2\r\n1 3 4 5 2\r\n5 3 2 1 4\r\n", "output": "18\r\n3 4 \r\n1 5 \r\n"}, {"input": "4 2 2\r\n10 8 8 3\r\n10 7 9 4\r\n", "output": "31\r\n1 2 \r\n3 4 \r\n"}, {"input": "5 3 1\r\n5 2 5 1 7\r\n6 3 1 6 3\r\n", "output": "23\r\n1 3 5 \r\n4 \r\n"}, {"input": "2 1 1\r\n100 101\r\n1 100\r\n", "output": "200\r\n1 ...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] # Read input with open(input_path) as f: input_data = f.read().splitlines() n, p, s = map(int, input_data[0].split()) a = list(map(int, input_data[1].split())) ...
true
858/B
858
B
Python 3
TESTS
6
62
0
31316402
n, m=map(int, input().split()) a=[0]*100 for i in range (m): l, k=map(int, input().split()) if k==1: b=k c=100 else: c=(l-1)//(k-1) b=(l+1)//k for j in range(b-1, c): a[j]+=1 x=0 y=0 b=[0]*100 for i in range(100): if (a[i]==m): x+=1 y=i+1 ...
101
62
307,200
30660431
import math def find_3(): etazh = [] for p in range(1, 101): if all((memory[0] + p - 1) // p == memory[1] for memory in mass): etazh.append(p) return etazh def find_2(): etazh = [] p = 1 while p < 100: for i in range (m): if math.ceil(mass[i][0]/p) != ma...
Технокубок 2018 - Отборочный Раунд 1
CF
2,017
1
256
Which floor?
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o...
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory. m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 1...
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
null
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-...
[{"input": "10 3\n6 2\n2 1\n7 3", "output": "4"}, {"input": "8 4\n3 1\n6 2\n5 2\n2 1", "output": "-1"}]
1,500
["brute force", "implementation"]
101
[{"input": "10 3\r\n6 2\r\n2 1\r\n7 3\r\n", "output": "4\r\n"}, {"input": "8 4\r\n3 1\r\n6 2\r\n5 2\r\n2 1\r\n", "output": "-1\r\n"}, {"input": "8 3\r\n7 2\r\n6 2\r\n1 1\r\n", "output": "2\r\n"}, {"input": "4 2\r\n8 3\r\n3 1\r\n", "output": "2\r\n"}, {"input": "11 4\r\n16 4\r\n11 3\r\n10 3\r\n15 4\r\n", "output": "3\r\...
false
stdio
null
true
979/B
979
B
Python 3
TESTS
7
93
7,065,600
38266265
n = int(input()) a = input() b = input() c = input() aa = 26*[0] ab = 26*[0] ac = 26*[0] ba = 26*[0] bb = 26*[0] bc = 26*[0] r = len(a) for i in range(r): if 'a'<=a[i]<='z': aa[ord(a[i])%97]+=1 else: ba[ord(a[i])%65]+=1 if 'a'<=b[i]<='z': ab[ord(b[i])%97]+=1 else: bb[ord(b[i])%65]+=1 if 'a'<=c[i]<='z': ...
184
109
7,680,000
38234705
n = int(input()) ku, sh, ka = input(), input(), input() l_ku, l_sh, l_ka = max([ku.count(i) for i in list(set(ku))]), max([sh.count(i) for i in list(set(sh))]), max([ka.count(i) for i in list(set(ka))]) if len(ku) - l_ku > n: l_ku += n elif l_ku == len(ku) and n == 1: l_ku -= 1 else: l_ku = len(ku) if len(s...
Codeforces Round 482 (Div. 2)
CF
2,018
1
256
Treasure Hunt
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her. The three friends are very smart so they passed all the challenges very quickly and finally reached the destination...
The first line contains an integer $$$n$$$ ($$$0 \leq n \leq 10^{9}$$$) — the number of turns. Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $$$10^{5}$$$ uppercase and lowercase Latin letters and is not empty. It is guaranteed th...
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
null
In the first example, after $$$3$$$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $$$5$$$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $$$4$$$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon int...
[{"input": "3\nKuroo\nShiro\nKatie", "output": "Kuro"}, {"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces", "output": "Shiro"}, {"input": "1\nabcabc\ncbabac\nababca", "output": "Katie"}, {"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE", "output": "Draw"}]
1,800
["greedy"]
184
[{"input": "3\r\nKuroo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "7\r\ntreasurehunt\r\nthreefriends\r\nhiCodeforces\r\n", "output": "Shiro\r\n"}, {"input": "1\r\nabcabc\r\ncbabac\r\nababca\r\n", "output": "Katie\r\n"}, {"input": "15\r\nfoPaErcvJ\r\nmZaxowpbt\r\nmkuOlaHRE\r\n", "output": "Draw\r\n"}, {"in...
false
stdio
null
true
961/D
961
D
Python 3
TESTS
8
46
6,963,200
122578461
n = int(input()) p = [list(map(int, input().split())) for i in range(n)] if n < 5: for bit in range(1 << n): a = [] b = [] for i in range(n): if bit & (1 << i): a.append(p[i]) else: b.append(p[i]) flag = True if len(a...
121
514
71,680,000
93965622
import sys from collections import Counter, defaultdict from math import gcd n = int(sys.stdin.buffer.readline().decode('utf-8')) points = [list(map(int, line.decode('utf-8').split())) for line in sys.stdin.buffer] if n <= 4: print('YES') exit() for i in range(3): cnt = Counter() idx = defa...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Pair Of Lines
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
null
In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2", "output": "YES"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3", "output": "NO"}]
2,000
["geometry"]
121
[{"input": "5\r\n0 0\r\n0 1\r\n1 1\r\n1 -1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n-1000000000 1000000000\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 -1\r\n-4 1\r\n0 -9\r\n5 -9\r\n9 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n6 1...
false
stdio
null
true
711/B
711
B
PyPy 3
TESTS
6
124
0
92177023
n = int(input()) matrix = [] for i in range(n): matrix.append([int(i) for i in input().split()]) zero_col = zero_row = 0 if n == 1: print(1) else: for i in range(n): for j in range(n): if matrix[i][j] == 0: zero_col = j zero_row = i cur = (zero_row + 1...
147
155
8,499,200
172260280
n=int(input()) # import sys # for i in range(int(input())): # n=int(input()) # arr=list(map(int,input().split())) if n==1: print(1) exit() ans=set() diag1=0;d1=0;d2=0;diag2=0;sum1=0;sum2=0 res=set();zero=set();matrix=[] for i in range(n): row=list(map(int,input().split())) matrix.append(row) ...
Codeforces Round 369 (Div. 2)
CF
2,016
2
256
Chris and Magic Square
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell. Chris tried filling in ran...
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid. n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If ...
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead. If there are multiple solutions, you may print any of them.
null
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed, The sum of numbers in each row is: 4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15. The sum of numbers in each column is: 4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15. The sum of numbers in the two diagonals is: 4 +...
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
1,400
["constructive algorithms", "implementation"]
147
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 ...
false
stdio
null
true
593/B
593
B
Python 3
TESTS
58
560
27,648,000
31544045
def main(): N = int(input()) X1, X2 = [int(i) for i in input().split()] X1 += 0.00001 X2 -= 0.00001 retas = [] for n in range(N): retas.append([int(i) for i in input().split()]) B1 = {} B2 = {} for n in range(N): k = retas[n][0] b = retas[n][1] B1[k*X1 + b] = n B2[k*X2 + b] = n L1 = list(B1.keys()) ...
93
405
26,521,600
204154895
from collections import defaultdict import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) x1, x2 = map(int, input().split()) d = defaultdict(lambda : []) for _ in range(n): k, b = map(int, input().split()) u, v = k * x1 + b, k * x2 + b d[u].append(v) ans = "NO" in...
Codeforces Round 329 (Div. 2)
CF
2,015
1
256
Anton and Lines
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessary to determine whether there is at least one point of intersection of two of these lines,...
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x1 and x2 ( - 1 000 000 ≤ x1 < x2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines. The following n lines co...
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
null
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it.
[{"input": "4\n1 2\n1 2\n1 0\n0 1\n0 2", "output": "NO"}, {"input": "2\n1 3\n1 0\n-1 3", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 2", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 3", "output": "NO"}]
1,600
["geometry", "sortings"]
93
[{"input": "4\r\n1 2\r\n1 2\r\n1 0\r\n0 1\r\n0 2\r\n", "output": "NO"}, {"input": "2\r\n1 3\r\n1 0\r\n-1 3\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 2\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 3\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n-1000000 1000000\r\n1000000 -1000000\r\n", "output"...
false
stdio
null
true
593/B
593
B
Python 3
TESTS
58
702
14,643,200
14253503
def check(y1, y2, n): for i in range(n): if y1[i][1] != y2[i][1]: return "YES" return "NO" n = int(input()) eps = 10**(-5) x1, x2 = map(int, input().split()) y1 = list() y2 = list() for i in range(n): k, b = map(int, input().split()) f = lambda x: k * x + b y1.append((f(x1 + ep...
93
420
13,414,400
100307298
import sys import collections import math if __name__ == "__main__" : points = [] n = int(sys.stdin.readline()) [x1, x2] = [int(i) for i in sys.stdin.readline().split()] for x in range(n): [k, b] = [int(i) for i in sys.stdin.readline().split()] points.append((k * x1 + b, k * x2 + b)) ...
Codeforces Round 329 (Div. 2)
CF
2,015
1
256
Anton and Lines
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessary to determine whether there is at least one point of intersection of two of these lines,...
The first line of the input contains an integer n (2 ≤ n ≤ 100 000) — the number of lines in the task given to Anton. The second line contains integers x1 and x2 ( - 1 000 000 ≤ x1 < x2 ≤ 1 000 000) defining the strip inside which you need to find a point of intersection of at least two lines. The following n lines co...
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
null
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it.
[{"input": "4\n1 2\n1 2\n1 0\n0 1\n0 2", "output": "NO"}, {"input": "2\n1 3\n1 0\n-1 3", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 2", "output": "YES"}, {"input": "2\n1 3\n1 0\n0 3", "output": "NO"}]
1,600
["geometry", "sortings"]
93
[{"input": "4\r\n1 2\r\n1 2\r\n1 0\r\n0 1\r\n0 2\r\n", "output": "NO"}, {"input": "2\r\n1 3\r\n1 0\r\n-1 3\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 2\r\n", "output": "YES"}, {"input": "2\r\n1 3\r\n1 0\r\n0 3\r\n", "output": "NO"}, {"input": "2\r\n0 1\r\n-1000000 1000000\r\n1000000 -1000000\r\n", "output"...
false
stdio
null
true
711/B
711
B
PyPy 3
TESTS
6
92
0
193494479
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())) for _ in range(n)] if n == 1: ans = 1 print(ans) exit() for i in range(n): if min(a[i]): s = sum(a[i]) break for i in range(n): if not min(a[i]): ...
147
202
12,800,000
127917429
#See the constraints; check if Brute force is useful #Figure out a realtion or general formula if possible #Find the corner cases #dp,prefix sum, greedy solution or logical #Ek baar aur kr bro #Be organised #Think hard you can do it def singleinput():R = int(input());return R def strinput():R = str(input());return R...
Codeforces Round 369 (Div. 2)
CF
2,016
2
256
Chris and Magic Square
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell. Chris tried filling in ran...
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid. n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If ...
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead. If there are multiple solutions, you may print any of them.
null
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed, The sum of numbers in each row is: 4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15. The sum of numbers in each column is: 4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15. The sum of numbers in the two diagonals is: 4 +...
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
1,400
["constructive algorithms", "implementation"]
147
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 ...
false
stdio
null
true
714/B
714
B
Python 3
TESTS
28
77
8,806,400
200449908
n= int(input()) a= list(map(int, input().split())) if len(set(a)) <= 2: print('YES') elif len(set(a))>3: print('NO') else: m= min(a) p= max(a) r= p-m if r%2: print('NO') else: print('YES')
79
77
13,619,200
220073936
n=int(input()) l=list(map(int,input().split())) mi=min(l) ma=max(l) if len(set(l))>3: print('NO') elif len(set(l))<3: print('YES') else: for i in set(l): if i!=ma and i!=mi: me=i if ma-me==me-mi: print("YES") else: print("NO")
Codeforces Round 371 (Div. 2)
CF
2,016
1
256
Filya and Homework
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers a1, a2, ..., an. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x ...
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — elements of the array.
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
null
In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
[{"input": "5\n1 3 3 2 1", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}]
1,200
["implementation", "sortings"]
79
[{"input": "5\r\n1 3 3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1000000000\r\n", "output": "YES\r\n"}, {"input...
false
stdio
null
true
714/B
714
B
PyPy 3
TESTS
28
171
11,776,000
105430819
n = int(input()) A = [int(a) for a in input().split()] m = max(A) D = [0] * n for i in range(n): D[i] = m - A[i] flag = False D = set(D) l = len(D) if l <= 2: flag = True elif l == 3: if (max(D) - min(D)) % 2 == 0: D = D.difference({max(D), min(D)}) s = {} new = (max(D) + min(D)) /...
79
77
13,619,200
230085863
# Wadea # n = int(input()) arr = list(map(int,input().split())) if len(set(arr)) > 3: print("NO") else: arr = list(set(arr)) arr.sort() l = min(arr);r = max(arr) if len(arr) == 3: c = (r - l)//2 l += c r -= c if l == arr[1] and r == arr[1]: print("YES") ...
Codeforces Round 371 (Div. 2)
CF
2,016
1
256
Filya and Homework
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers a1, a2, ..., an. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x ...
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — elements of the array.
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
null
In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
[{"input": "5\n1 3 3 2 1", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}]
1,200
["implementation", "sortings"]
79
[{"input": "5\r\n1 3 3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1000000000\r\n", "output": "YES\r\n"}, {"input...
false
stdio
null
true
356/C
356
C
Python 3
TESTS
9
280
14,643,200
92567036
def fun(arr): if(sum(arr)<3 or sum(arr)==5): return -1 # n3 = arr.count(3) # n4 = arr.count(4) n2 = arr.count(2) n1 = arr.count(1) if n1 >=n2 : n1 = n1-n2 else: n1 = 0 return n2+int(n1/3)*2+n1%3 n = int(input()) arr = list(map(int,input().split(" "))) print(fun...
141
607
14,745,600
42135284
#! /usr/bin/env python n = int(input()) counts = [0] * 5 nums = [int(x) for x in input().split()] for x in nums: counts[x] += 1 s = sum(nums) if s > 2 and s != 5: ans = 0 if counts[1] >= counts[2]: ans += counts[2] counts[3] += counts[2] counts[1] -= counts[2] ans += 2 * (c...
Codeforces Round 207 (Div. 1)
CF
2,013
1
256
Compartments
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ge...
The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.
If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.
null
null
[{"input": "5\n1 2 2 4 3", "output": "2"}, {"input": "3\n4 1 1", "output": "2"}, {"input": "4\n0 3 0 4", "output": "0"}]
2,100
["combinatorics", "constructive algorithms", "greedy", "implementation"]
141
[{"input": "5\r\n1 2 2 4 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n0 3 0 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 4\r\n", "output": "1\r\n"}, {"input": "10\r\n2 1 2 3 4 1 3 4 4 4\r\n", "output": "2\r\n"}, {"...
false
stdio
null
true
623/A
623
A
Python 3
TESTS
20
436
12,288,000
15813151
n, m = map(int, input().split()) graph = [set() for _ in range(n+1)] for _ in range(m): u, v = map(int, input().split()) graph[u].add(v) graph[v].add(u) letter = {"a": set(), "b": set(), "c": set()} remaining = set() for u in range(1, n+1): # if u is b if len(graph[u]) == n-1: letter["b"].ad...
106
170
10,137,600
138001764
import sys import os from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writabl...
AIM Tech Round (Div. 1)
CF
2,016
2
256
Graph and String
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties: - G has exactly n vertices, numbered from 1 to n....
The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively. Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It ...
In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise. If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the gra...
null
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions. In the second sample the first vertex is connected to al...
[{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}]
1,800
["constructive algorithms", "graphs"]
106
[{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] # Read input with open(input_path) as f: n, m = map(int, f.readline().split()) edges = [] for _ in range(m): u, v = map(int, f.readline().split()) ...
true
623/A
623
A
PyPy 3-64
TESTS
50
311
146,944,000
140243046
import sys zz=1 sys.setrecursionlimit(10**5) if zz: input=sys.stdin.readline else: sys.stdin=open('input.txt', 'r') sys.stdout=open('all.txt','w') di=[[-1,0],[1,0],[0,1],[0,-1]] def fori(n): return [fi() for i in range(n)] def inc(d,c,x=1): d[c]=d[c]+x if c in d else x def ii(): return input().rstrip() def...
106
404
1,228,800
16542882
def main(): n, m = map(int, input().split()) links = [[False] * n for i in range(n)] for i in range(n): links[i][i] = True for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 links[u][v] = links[v][u] = True res = [0] * n ref1 = ref3 = None ...
AIM Tech Round (Div. 1)
CF
2,016
2
256
Graph and String
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties: - G has exactly n vertices, numbered from 1 to n....
The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively. Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It ...
In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise. If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the gra...
null
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions. In the second sample the first vertex is connected to al...
[{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}]
1,800
["constructive algorithms", "graphs"]
106
[{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] # Read input with open(input_path) as f: n, m = map(int, f.readline().split()) edges = [] for _ in range(m): u, v = map(int, f.readline().split()) ...
true
419/A
420
A
PyPy 3-64
TESTS
62
62
30,412,800
192188318
s = str(input()) alp = 'AHIMOTUVWXY' count = 0 if(len(s) == 1): if(s in alp): print('YES') else: print('NO') else: if(len(s) % 2 == 0): part1 = s[ : len(s) // 2] part2 = s[len(s)//2 : ] part2 = part2[::-1] for el in range(len(part1)): if(part1[el]...
80
46
0
179134237
n=input() if n==n[::-1] and "Z" not in n and "S" not in n and "R" not in n and "Q" not in n and "P" not in n and "N" not in n and "L" not in n and "K" not in n and "J" not in n and "G" not in n and "F" not in n and "E" not in n and "D" not in n and "C" not in n and "B" not in n: print("YES") else: print("NO")
Coder-Strike 2014 - Finals
CF
2,014
1
256
Start Up
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
null
null
[{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}]
1,000
[]
80
[{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUI...
false
stdio
null
true
757/A
757
A
Python 3
TESTS
55
77
307,200
120062236
input_str = input() sample_str = str("Bulbasaur") sample_dict = dict() temp_dict = dict() # Initialize for i in sample_str: sample_dict[i] = 0 for i in sample_str: sample_dict[i] = sample_dict[i] + 1 for i in range(65,91): text = chr(i) temp_dict[text] = 0 for i in range(97,123): text = chr(...
107
46
0
151629051
s = input() t = "Bulbasaur" frq = [s.count(c)//t.count(c) for c in t] print(min(frq))
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
CF
2,017
1
256
Gotta Catch Em' All!
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas...
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s. The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
Output a single integer, the answer to the problem.
null
In the first case, you could pick: Bulbbasaur. In the second case, there is no way to pick even a single Bulbasaur. In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
1,000
["implementation"]
107
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuu...
false
stdio
null
true
762/C
762
C
Python 3
TESTS
4
61
4,915,200
27939150
a, b = str(input()), str(input()) p, s, pp, sp = [0] * len(b), [0] * len(b), 0, len(a) - 1 p[0] = a.find(b[0]) while sp >= 0 and a[sp] != b[-1]: sp -= 1 s[len(b) - 1] = sp pp, sp = p[0] + 1, sp - 1 for i in range(1, len(b)): if p[i - 1] == -1: p[i] = -1 else: while pp < len(a) and a[pp] != b[i]: pp ...
99
311
6,144,000
82586553
# cook your dish here a = list(input()) b = list(input()) m = len(a) n = len(b) s = [-1] i = 0 j = 0 while i<m and j<n: if(a[i]==b[j]): s.append(i) j+=1 i+=1 e = [1000000] i = m-1 j= n-1 while i>=0 and j>=0: if(a[i]==b[j]): e.append(i) j-=1 i-=1 ...
Educational Codeforces Round 17
ICPC
2,017
2
256
Two strings
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of th...
The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters.
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters. If the answer consists of zero characters, output «-» (a minus sign).
null
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty. In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
[{"input": "hi\nbob", "output": "-"}, {"input": "abca\naccepted", "output": "ac"}, {"input": "abacaba\nabcdcba", "output": "abcba"}]
2,100
["binary search", "hashing", "strings", "two pointers"]
99
[{"input": "hi\r\nbob\r\n", "output": "-\r\n"}, {"input": "abca\r\naccepted\r\n", "output": "ac\r\n"}, {"input": "abacaba\r\nabcdcba\r\n", "output": "abcba\r\n"}, {"input": "lo\r\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\r\n", "output": "-\r\n"}, {"input": "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\r\nmlmarpivirqbxcyhyer...
false
stdio
null
true
711/B
711
B
PyPy 3
TESTS
92
233
11,673,600
109836816
import sys,os,io import math,bisect,operator inf,mod = float('inf'),10**9+7 # sys.setrecursionlimit(10 ** 6) from itertools import groupby,accumulate from heapq import heapify,heappop,heappush from collections import deque,Counter,defaultdict input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ Neo = la...
147
217
7,372,800
20402497
n = int(input()) a = 0 r,c = 0,-1 dl = [] for i in range(n): tl = list(map(int, input().split())) if c<0 and tl.count(0): r = i c = tl.index(0) dl+=[tl] s = sum(dl[(r+1)%n]) a = s-sum(dl[r]) dl[r][c] = a if n>1 and a<1: print(-1) exit() # print(dl) for i in range(n):...
Codeforces Round 369 (Div. 2)
CF
2,016
2
256
Chris and Magic Square
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell. Chris tried filling in ran...
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid. n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If ...
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead. If there are multiple solutions, you may print any of them.
null
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed, The sum of numbers in each row is: 4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15. The sum of numbers in each column is: 4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15. The sum of numbers in the two diagonals is: 4 +...
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
1,400
["constructive algorithms", "implementation"]
147
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 ...
false
stdio
null
true
540/B
540
B
PyPy 3-64
TESTS
40
62
28,774,400
225517032
def check(x, y, arr: list, i_median): sum_ = sum(arr) arr1 = arr.copy() arr1.sort() return sum_ <= x and arr1[i_median] >= y def main(): n, k, p, x, y = map(int, input().split()) i_median = (n + 1) // 2 - 1 high_median = 0 arr = [] x_new = x if x < y: return -1 if ...
78
62
0
223776009
n, k, p, x, y = map(int, input().split()) a = list(map(int, input().split())) start_sum = sum(a) major = 0 for i in range(k): if a[i] >= y: major += 1 count_max = (n + 1) // 2 - major if k - major > n // 2: print(-1) else: cnt_mx = (n + 1) // 2 - major # кол-во макс оценок которые осталось дописат...
Codeforces Round 301 (Div. 2)
CF
2,015
2
256
School Marks
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests...
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total n...
If Vova cannot achieve the desired result, print "-1". Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
null
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai. In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the med...
[{"input": "5 3 5 18 4\n3 5 4", "output": "4 1"}, {"input": "5 3 5 16 4\n5 5 5", "output": "-1"}]
1,700
["greedy", "implementation"]
78
[{"input": "5 3 5 18 4\r\n3 5 4\r\n", "output": "4 1\r\n"}, {"input": "5 3 5 16 4\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "5 3 5 17 4\r\n5 5 5\r\n", "output": "1 1\r\n"}, {"input": "5 3 5 12 1\r\n5 5 1\r\n", "output": "-1\r\n"}, {"input": "5 3 5 13 1\r\n5 5 1\r\n", "output": "1 1\r\n"}, {"input": "7 4 5 26 5\r\n5...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path, 'r') as f_in: n, k, p, x, y = map(int, f_in.readline().split()) existing = list(map(int, f_in.readline().split())) with open(submission_path, 'r') as f_sub: submission_line = f_sub.read().strip() ...
true
748/B
748
B
Python 3
TESTS
23
342
4,608,000
23293128
s = input() g = input() n = len(s) k = 0 letters = [] flag = True for i in range(n): t = s[i] m = g[i] for j in range(n): if s[j] == m: if g[j] != t: flag = False if s[j] == t: if g[j] != m: flag = False if flag: if [t, ...
86
62
4,608,000
23301916
s, t = input(), input() #d = dict(zip(s, t)) d = {} no = False for i, j in zip(s, t): if i in d and d[i] != j: no = True d[i] = j # print(d) d2 = {} for key in d: if (d[key] in d and key != d[d[key]]) or d[key] in d2.values(): no = True break else: if key != d[key] and ke...
Technocup 2017 - Elimination Round 3
CF
2,016
2
256
Santa Claus and Keyboard Check
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. I...
The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines ...
null
null
[{"input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z"}, {"input": "hastalavistababy\nhastalavistababy", "output": "0"}, {"input": "merrychristmas\nchristmasmerry", "output": "-1"}]
1,500
["implementation", "strings"]
86
[{"input": "helloworld\r\nehoolwlroz\r\n", "output": "3\r\nh e\r\nl o\r\nd z\r\n"}, {"input": "hastalavistababy\r\nhastalavistababy\r\n", "output": "0\r\n"}, {"input": "merrychristmas\r\nchristmasmerry\r\n", "output": "-1\r\n"}, {"input": "kusyvdgccw\r\nkusyvdgccw\r\n", "output": "0\r\n"}, {"input": "bbbbbabbab\r\naaaa...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: s, t = f.read().split() s = s.strip() t = t.strip() with open(submission_path, 'r') as f: lines = [line.strip() for line in f.readlines(...
true
895/A
895
A
Python 3
TESTS
49
62
5,529,600
32714122
n = int(input()) a = [int(i) for i in input().split()] a.sort(reverse = True) pe = 0 va = a[0] for i in range(1,len(a)): if pe<va: pe+=a[i] else: va+=a[i] print(abs(va-pe))
93
62
5,632,000
32698789
from itertools import cycle n=int(input()) a=list(map(int,input().split())) s,m=0,360 j=cycle(a) for ai in a: while s<180: s+=next(j) m=min(m,s) s-=ai print(2*m-360)
Codeforces Round 448 (Div. 2)
CF
2,017
1
256
Pizza Separation
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all piece...
The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
null
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Pety...
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
1,200
["brute force", "implementation"]
93
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", ...
false
stdio
null
true
895/A
895
A
Python 3
TESTS
49
62
5,529,600
32743576
n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) sumr=a[0] suml=0 for i in range(1,n): #print(sumr,suml) if sumr>suml: suml+=a[i] else: sumr+=a[i] print(abs(sumr-suml))
93
62
5,632,000
32839935
def diff(val): return 2 * abs(180 - val) n = int(input()) arr = input().split(' ') arr = [int(x) for x in arr] sum = 0 min_diff = 360 last_idx = 0 for a in arr: sum += a min_diff = min(min_diff, diff(sum)) while sum > 180: sum -= arr[last_idx] last_idx += 1 min_diff = min(min...
Codeforces Round 448 (Div. 2)
CF
2,017
1
256
Pizza Separation
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all piece...
The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
null
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Pety...
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
1,200
["brute force", "implementation"]
93
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", ...
false
stdio
null
true
214/B
214
B
Python 3
TESTS
10
186
4,403,200
143773505
n = int(input()) s = input().split() s = [int(i) for i in s] if(n == 1 and s[0] == 0): print(0) elif(0 not in s): print(-1) else: a = sum(s) s.sort(reverse = True) #print(s,a) if(a%3 == 0): if(1 in s or 2 in s or 3 in s or 4 in s or 5 in s or 6 in s or 7 in s or 8 in s or 9 in s): t = ''.join([str(i) for i...
101
186
13,004,800
197826043
input() a = sorted(map(int, input().split())) if a[0] != 0: a = [-1] else: s = sum(a) if s % 3 != 0: flag = False for i in a: if i % 3 == s % 3: flag = True a.remove(i) break if(flag == False): for i in a: ...
Codeforces Round 131 (Div. 2)
CF
2,012
2
256
Hometask
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a set of digits, your task is to find the maximum integer that you can mak...
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
null
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.
[{"input": "1\n0", "output": "0"}, {"input": "11\n3 4 5 4 5 3 5 3 4 4 0", "output": "5554443330"}, {"input": "8\n3 2 5 1 5 2 2 3", "output": "-1"}]
1,600
["brute force", "constructive algorithms", "greedy", "math"]
101
[{"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "11\r\n3 4 5 4 5 3 5 3 4 4 0\r\n", "output": "5554443330\r\n"}, {"input": "8\r\n3 2 5 1 5 2 2 3\r\n", "output": "-1\r\n"}, {"input": "12\r\n5 3 3 3 2 5 5 1 2 1 4 1\r\n", "output": "-1\r\n"}, {"input": "8\r\n5 5 4 1 5 5 5 3\r\n", "output": "-1\r\n"}, {"input": "12\r...
false
stdio
null
true
984/B
984
B
Python 3
TESTS
4
46
0
155234325
n,m=map(int,input().split()) b=['.' for i in range(m+2)] a=[b] num='123456789' def provjera(i,j): if a[i][j] in num: x=int(a[i][j]) else: x=0 br=0 if a[i-1][j-1]=='*': br+=1 if a[i-1][j]=='*': br+=1 if a[i-1][j+1]=='*': br+=1 if a[i][j+1]=='*': ...
84
93
0
156188341
n, m = map(int, input().split()) g = [input().replace('.', '0') for i in [0] * n] b = [[0] * m for i in [0] * n] for i in range(n): for j in range(m): if g[i][j] != '*' : b[i][j] += int(g[i][j]) else : for x in range(max(i-1,0),min(i+2,n)): for y in range(max(j-1,0),min(...
Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
CF
2,018
1
256
Minesweeper
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won. Alex has grown up since then, so he easily wins the most difficu...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the sizes of the field. The next $$$n$$$ lines contain the description of the field. Each line contains $$$m$$$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $$$1$$$ to ...
Print "YES", if the field is valid and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrarily.
null
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1. You can read more about Minesweeper in Wikipedia's article.
[{"input": "3 3\n111\n1*1\n111", "output": "YES"}, {"input": "2 4\n*.*.\n1211", "output": "NO"}]
1,100
["implementation"]
84
[{"input": "3 3\r\n111\r\n1*1\r\n111\r\n", "output": "YES"}, {"input": "2 4\r\n*.*.\r\n1211\r\n", "output": "NO"}, {"input": "1 10\r\n.....1*1..\r\n", "output": "YES"}, {"input": "1 1\r\n4\r\n", "output": "NO"}, {"input": "10 10\r\n..........\r\n...111111.\r\n..13*21*1.\r\n.12**2111.\r\n.1*542..11\r\n.13**1..1*\r\n..2*...
false
stdio
null
true
984/B
984
B
PyPy 3
TESTS
4
124
0
116205125
def is_safe(x, y, n, m): return 0 <= x < n and 0 <= y < m n, m = map(int, input().split()) grid = [] for i in range(n): grid.append(list(input())) new_grid = [[0]*m for i in range(n)] directions = [[1, 0], [0, 1], [-1, 0], [0, -1], [-1, -1], [1, 1], [-1, 1], [1, -1]] for i in range(n): fo...
84
93
2,969,600
146893279
def solve(matrix, n, m): for r in range(n): for c in range(m): if matrix[r][c] == '*': continue bombCnt = 0 if r>0 and matrix[r-1][c] == '*': bombCnt += 1 if r>0 and c<m-1 and matrix[r-1][c+1] == '*': bombCnt += 1 if c<m-1 and matrix[r][c+1] == '*...
Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
CF
2,018
1
256
Minesweeper
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won. Alex has grown up since then, so he easily wins the most difficu...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the sizes of the field. The next $$$n$$$ lines contain the description of the field. Each line contains $$$m$$$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $$$1$$$ to ...
Print "YES", if the field is valid and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrarily.
null
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1. You can read more about Minesweeper in Wikipedia's article.
[{"input": "3 3\n111\n1*1\n111", "output": "YES"}, {"input": "2 4\n*.*.\n1211", "output": "NO"}]
1,100
["implementation"]
84
[{"input": "3 3\r\n111\r\n1*1\r\n111\r\n", "output": "YES"}, {"input": "2 4\r\n*.*.\r\n1211\r\n", "output": "NO"}, {"input": "1 10\r\n.....1*1..\r\n", "output": "YES"}, {"input": "1 1\r\n4\r\n", "output": "NO"}, {"input": "10 10\r\n..........\r\n...111111.\r\n..13*21*1.\r\n.12**2111.\r\n.1*542..11\r\n.13**1..1*\r\n..2*...
false
stdio
null
true
638/B
638
B
Python 3
TESTS
24
62
5,120,000
16853686
def cross(s1, s2): # check lengths if len(s1) > len(s2): s1, s2 = s2, s1 if s1 in s2: return True, s2 a = s2.find(s1[-1]) if a != -1: return True, s1 + s2[(a + 1)::] a = s2.rfind(s1[0]) if a != -1: return True, s2[:a] + s1 return False, "" def cross_all(...
67
61
5,120,000
16842176
n = int(input()) a = {} b = {} w, e = set(), set() for i in range(n): s = input() q = s[0] if s[0] not in b.keys(): b[s[0]] = -1 e.add(s[0]) if s[-1] not in a.keys(): a[s[-1]] = -1 w.add(s[-1]) for j in range(1, len(s)): if s[j-1] in w: w.remove(s[...
VK Cup 2016 - Qualification Round 2
CF
2,016
1
256
Making Genome in Berland
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En...
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are d...
In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.
null
null
[{"input": "3\nbcd\nab\ncdef", "output": "abcdef"}, {"input": "4\nx\ny\nz\nw", "output": "xyzw"}]
1,500
["*special", "dfs and similar", "strings"]
67
[{"input": "3\r\nbcd\r\nab\r\ncdef\r\n", "output": "abcdef\r\n"}, {"input": "4\r\nx\r\ny\r\nz\r\nw\r\n", "output": "xyzw\r\n"}, {"input": "25\r\nef\r\nfg\r\ngh\r\nhi\r\nij\r\njk\r\nkl\r\nlm\r\nmn\r\nno\r\nab\r\nbc\r\ncd\r\nde\r\nop\r\npq\r\nqr\r\nrs\r\nst\r\ntu\r\nuv\r\nvw\r\nwx\r\nxy\r\nyz\r\n", "output": "abcdefghijk...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) fragments = [line.strip() for line in f] with open(output_path) as f: correct_output = f.read().strip() ...
true
895/A
895
A
Python 3
TESTS
49
62
5,529,600
32961828
n=int(input()) a=list(map(int,input().split())) a.sort() s1,s2=0,0 for x in a[::-1]: if s1>s2: s2+=x else: s1+=x print(abs(s1-s2))
93
62
5,632,000
32839991
n=int(input()) l=[int(x) for x in input().split()] ans=360 sum=0 j=0 i=0 while(i<n): sum+=l[i] while(sum>=180): ans=min(ans,2*abs(180-sum)) sum-=l[j] j+=1 ans=min(ans,2*abs(180-sum)) i+=1 print(ans)
Codeforces Round 448 (Div. 2)
CF
2,017
1
256
Pizza Separation
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all piece...
The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
null
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Pety...
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
1,200
["brute force", "implementation"]
93
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", ...
false
stdio
null
true
895/A
895
A
Python 3
TESTS
49
62
5,632,000
32712634
n=int(input()) a=[int (i) for i in input().split()] a=sorted(a) x=0 y=a[-1] a=a[:-1:] for i in range(n-1): if x>=y: y+=a[-1] else: x+=a[-1] a=a[:-1:] print(x-y) if x>y else print(y-x)
93
77
0
182147142
#https://codeforces.com/contest/895/problem/A?f0a28=2 ##important observation: continuous sectors , better approach using 2 pointers from collections import deque import sys n=int(input()) A=list(map(int,input().split())) def angle_diff(x): return 2*abs(x-180) mini=360 total=0 l,r=0,0 while r<n: total+=A...
Codeforces Round 448 (Div. 2)
CF
2,017
1
256
Pizza Separation
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all piece...
The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
null
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Pety...
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
1,200
["brute force", "implementation"]
93
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", ...
false
stdio
null
true
895/A
895
A
Python 3
TESTS
49
62
5,529,600
32731313
# -*- coding: utf-8 -*- """ Created on Mon Nov 27 22:34:44 2017 @author: rohit """ n = int(input()) angles = [int(x) for x in input().split()] angles.sort(reverse=True) A = 0 B = 0 for e in angles: if A>B: B+=e else: A+=e print(abs(A-B))
93
77
0
216390389
#print('hello') n = int(input()) lst = input() array = list(map(int,lst.split())) sum = 0 trac = [] trac.append(0) for i in range(0,n): trac.append(trac[i]+array[i]) res = [] sz = len(trac) trac.sort() #print(sz) #print(trac) fn = 360 for i in range(0,sz): for j in range(0,sz): r1 = trac[j]- trac[i-1] ...
Codeforces Round 448 (Div. 2)
CF
2,017
1
256
Pizza Separation
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all piece...
The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
null
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Pety...
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
1,200
["brute force", "implementation"]
93
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", ...
false
stdio
null
true
895/A
895
A
Python 3
TESTS
49
77
5,529,600
32986165
n=int(input()) a=list(map(int,input().split())) a.sort() a.reverse() k=[] sum1=a[0] sum2=0 for i in range(1,n): if sum1>sum2 : sum2+=a[i] elif sum2>sum1 : sum1+=a[i] elif sum1==sum2 : k.append(a[i]) for i in range(len(k)): if sum1>sum2 : sum2+=k[i] else : sum1...
93
77
1,740,800
161385163
import sys input = sys.stdin.readline n = int(input()) w = list(map(int, input().split())) c = 1e9 x = sum(w) k = n while k: s = 0 for i in w: s += i c = min(c, abs(x-2*s)) k -= 1 w = w[1:] + [w[0]] print(c)
Codeforces Round 448 (Div. 2)
CF
2,017
1
256
Pizza Separation
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all piece...
The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
null
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Pety...
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
1,200
["brute force", "implementation"]
93
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", ...
false
stdio
null
true
895/A
895
A
Python 3
TESTS
49
62
5,632,000
32700080
import math n = int(input()) a = [int(i) for i in input().split()] a.sort() left, right = 0, 0 for i in range(len(a) - 1, -1, -1): if left <= right: left += a[i] else: right += a[i] print(abs(left - right))
93
77
2,252,800
216134212
import sys, math, itertools, functools, collections input = sys.stdin.readline def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().strip().split()) def msi(): return map(str,input().strip().split()) def li(): return list(mi()) def solve(): n = ii() arr = li() ans = ...
Codeforces Round 448 (Div. 2)
CF
2,017
1
256
Pizza Separation
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all piece...
The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
null
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Pety...
[{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}]
1,200
["brute force", "implementation"]
93
[{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", ...
false
stdio
null
true
984/B
984
B
PyPy 3
TESTS
4
140
0
71548017
n, m = list(map(int, input().strip().split())) nums = [] for i in range(n): row = input().strip() nums.append(row) ok = True for i in range(n): for j in range(m): # # continue cur = 0 for x in range(-1, 2): for y in range(-1, 2): if x == 0 and ...
84
93
3,584,000
147619465
r,c=map(int,input().split()) l=[] for i in range(r): s=input() l.append(s) f=0 for i in range(r): for j in range(c): temp=[] if(l[i][j]!='*'): if(i!=0): temp.append(l[i-1][j]) if(i!=0 and j!=0): temp.append(l[i-1][j-1]) if...
Codeforces Round 483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
CF
2,018
1
256
Minesweeper
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won. Alex has grown up since then, so he easily wins the most difficu...
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the sizes of the field. The next $$$n$$$ lines contain the description of the field. Each line contains $$$m$$$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $$$1$$$ to ...
Print "YES", if the field is valid and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrarily.
null
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1. You can read more about Minesweeper in Wikipedia's article.
[{"input": "3 3\n111\n1*1\n111", "output": "YES"}, {"input": "2 4\n*.*.\n1211", "output": "NO"}]
1,100
["implementation"]
84
[{"input": "3 3\r\n111\r\n1*1\r\n111\r\n", "output": "YES"}, {"input": "2 4\r\n*.*.\r\n1211\r\n", "output": "NO"}, {"input": "1 10\r\n.....1*1..\r\n", "output": "YES"}, {"input": "1 1\r\n4\r\n", "output": "NO"}, {"input": "10 10\r\n..........\r\n...111111.\r\n..13*21*1.\r\n.12**2111.\r\n.1*542..11\r\n.13**1..1*\r\n..2*...
false
stdio
null
true
793/A
793
A
Python 3
TESTS
22
202
9,523,200
75937617
# -*- coding: utf-8 -*- """ Created on Wed Apr 8 18:26:13 2020 @author: alexi """ #https://codeforces.com/problemset/problem/793/A --- Alexis Galvan def check_disible(divisor, array): aux = array[0] % divisor zero = False if aux == 0: zero = True for i in range(len(array)): ...
88
77
13,414,400
228827551
def main(): n, k = map(int, input().split()) prices = list(map(int, input().split())) min_price = min(prices) for price in prices: diff = price - min_price if diff % k != 0: print(-1) break else: print(sum((price - min_price) // k for price in prices...
Tinkoff Challenge - Elimination Round
CF
2,017
1
256
Oleg and shares
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg...
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
null
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There...
[{"input": "3 3\n12 9 15", "output": "3"}, {"input": "2 2\n10 9", "output": "-1"}, {"input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997"}]
900
["implementation", "math"]
88
[{"input": "3 3\r\n12 9 15\r\n", "output": "3"}, {"input": "2 2\r\n10 9\r\n", "output": "-1"}, {"input": "4 1\r\n1 1000000000 1000000000 1000000000\r\n", "output": "2999999997"}, {"input": "1 11\r\n123\r\n", "output": "0"}, {"input": "20 6\r\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14\r\n", "output": "151...
false
stdio
null
true
847/D
847
D
PyPy 3
TESTS
5
93
23,040,000
33250428
from heapq import heappush, heappop n, m = [int(i) for i in input().split()] food = 0 tummy = [] dish = [ -int(i) for i in input().split()] for i in range(1, min(m, n+1)): while tummy and -tummy[0] >= m- i: heappop(tummy) if max(-dish[i-1], i) < m: heappush(tummy, -(dish[i-1] - i)) food = m...
151
342
16,998,400
173291126
import heapq n, m = map(int, input().split()) arr, res, ans = [], 0, 0 in_arr = [int(x) for x in input().split()] for i in range(1, min(m, n + 1)): if in_arr[i-1] >= m: continue while arr and -arr[0] >= m - i: heapq.heappop(arr) res -= 1 heapq.heappush(arr, -(in_arr[i-1] - i)) re...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
2
256
Dog Show
A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win! On the show a dog needs to eat as many bowls of dog food as poss...
Two integer numbers are given in the first line - n and T (1 ≤ n ≤ 200 000, 1 ≤ T ≤ 2·109) — the number of bowls of food and the time when the dog is stopped. On the next line numbers t1, t2, ..., tn (1 ≤ ti ≤ 109) are given, where ti is the moment of time when the i-th bowl of food is ready for eating.
Output a single integer — the maximum number of bowls of food the dog will be able to eat in T seconds.
null
In the first example the dog should skip the second bowl to eat from the two bowls (the first and the third).
[{"input": "3 5\n1 5 3", "output": "2"}, {"input": "1 2\n1", "output": "1"}, {"input": "1 1\n1", "output": "0"}]
2,200
["constructive algorithms", "data structures", "greedy"]
151
[{"input": "3 5\r\n1 5 3\r\n", "output": "2\r\n"}, {"input": "1 2\r\n1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n2 3\r\n", "output": "0\r\n"}, {"input": "2 3\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3 3\r\n2 3 2\r\n", "outp...
false
stdio
null
true
762/C
762
C
PyPy 3
TESTS
3
92
0
103983470
class word: def __init__(self,strin): self.palabra=strin def countLetter(self,letter): return self.palabra.count(letter) def letterBelongTo(self,letter): return letter in self.palabra stringa=input() stringb=input() word1=word(stringa) word2=word(stringb) staticword=word2.palabra ...
99
342
5,939,200
55412519
a = list(input()) b = list(input()) s = [-1] i = 0 j = 0 while i < len(a) and j < len(b): if a[i] == b[j]: s.append(i) j += 1 i += 1 e = [10**6] i = len(a) - 1 j = len(b) - 1 while i >= 0 and j >= 0: if a[i] == b[j]: e.append(i) j -= 1 i -= 1 ans_len = 0 ans = ['-'] i = len(s) - 1 j = 0 while i >= 0 a...
Educational Codeforces Round 17
ICPC
2,017
2
256
Two strings
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of th...
The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters.
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters. If the answer consists of zero characters, output «-» (a minus sign).
null
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty. In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
[{"input": "hi\nbob", "output": "-"}, {"input": "abca\naccepted", "output": "ac"}, {"input": "abacaba\nabcdcba", "output": "abcba"}]
2,100
["binary search", "hashing", "strings", "two pointers"]
99
[{"input": "hi\r\nbob\r\n", "output": "-\r\n"}, {"input": "abca\r\naccepted\r\n", "output": "ac\r\n"}, {"input": "abacaba\r\nabcdcba\r\n", "output": "abcba\r\n"}, {"input": "lo\r\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\r\n", "output": "-\r\n"}, {"input": "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\r\nmlmarpivirqbxcyhyer...
false
stdio
null
true
416/A
416
A
Python 3
TESTS
62
186
1,024,000
73505774
from enum import Enum from collections import namedtuple class Operator(Enum): LT = "<" LTE = "<=" GT = ">" GTE = ">=" def inverse(self): inverses = { self.LT: self.GTE, self.LTE: self.GT, self.GT: self.LTE, self.GTE: self.LT } ...
66
46
0
156241499
t = int(input()) lower_bound = -2*10**9 upper_bound = 2*10**9 for iq in range(t): X = input().split() if X[2] == 'Y': if X[0] == '>=': lower_bound = max(int(X[1]), lower_bound) # print('lower bound:', lower_bound) elif X[0] == '<=': upper_bound = min(int(...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Guess a number!
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions: - Is it true that y is strictl...
The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is: - ">" (for the first type queries), - "<" (for the second type queries)...
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
null
null
[{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}]
1,400
["greedy", "implementation", "two pointers"]
66
[{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.readlines() n = int(lines[0].strip()) queries = [line.strip().split() for line in lines[1:n+1]] low = -2 * 10**9 high = 2 * 10**9 for sign, x_str, ans in queries: x = i...
true
711/B
711
B
Python 3
TESTS
92
358
12,800,000
86637839
n = int(input()) mat = [] for i in range(n): tmp = list(map(int, input().split())) mat.append(tmp) sums = [] p_dia = 0 s_dia = 0 col_sum = 0 row_sum = 0 done = False if n == 1: print(1) done = True for i in range(n): row_sum = 0 col_sum = 0 p_dia += mat[i][i] s_dia += mat[i][n-1-i] ...
147
218
6,041,600
109377968
def sum_row(arr): ans = sum(arr[0]) for i in range(1,len(arr)): if sum(arr[i])!=ans: return [False] return [True,ans] def sum_col(arr): ans = None for i in range(len(arr)): temp = 0 for j in range(len(arr[0])): temp+=arr[j][i] if ans==None: ...
Codeforces Round 369 (Div. 2)
CF
2,016
2
256
Chris and Magic Square
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell. Chris tried filling in ran...
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid. n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If ...
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead. If there are multiple solutions, you may print any of them.
null
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed, The sum of numbers in each row is: 4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15. The sum of numbers in each column is: 4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15. The sum of numbers in the two diagonals is: 4 +...
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
1,400
["constructive algorithms", "implementation"]
147
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 ...
false
stdio
null
true
711/B
711
B
PyPy 3
TESTS
92
358
29,900,800
128397629
n = int(input()) mat=[] a=-1 b=-1 for i in range(n): l = list(map(int,input().split())) mat.append(l) s =set() for i in range(n): sum=0 for j in range(n): sum+=mat[i][j] s.add(sum) for i in range(n): sum=0 for j in range(n): sum+=mat[j][i] s.add(sum) sum=0 for i in range(...
147
218
6,144,000
20744630
from sys import exit def check_all(l, exclude): result = 0 x, y = exclude for i in range(n): if i == x: continue s = sum(l[i]) if not result: result = s elif s != result: return False, 0 for j in range(n): if j == y: ...
Codeforces Round 369 (Div. 2)
CF
2,016
2
256
Chris and Magic Square
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell. Chris tried filling in ran...
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid. n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If ...
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead. If there are multiple solutions, you may print any of them.
null
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed, The sum of numbers in each row is: 4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15. The sum of numbers in each column is: 4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15. The sum of numbers in the two diagonals is: 4 +...
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
1,400
["constructive algorithms", "implementation"]
147
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 ...
false
stdio
null
true
757/A
757
A
Python 3
TESTS
28
46
0
156771823
a = "Bulsar"#au A = input() D = {"B":0,"u":0,"l":0,"s":0,"a":0,"r":0} for k in A: if k in a: D[k]+=1 D["a"]//=2 D["u"]//=2 print(min(D.values()))
107
46
0
165632834
num_inp=lambda: int(input()) arr_inp=lambda: list(map(int,input().split())) sp_inp=lambda: map(int,input().split()) str_inp=lambda:input() w = input() c = [w.count(l) for l in "Bulbasr"] c[1] //= 2 c[4] //= 2 print(min(c))
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
CF
2,017
1
256
Gotta Catch Em' All!
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas...
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s. The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
Output a single integer, the answer to the problem.
null
In the first case, you could pick: Bulbbasaur. In the second case, there is no way to pick even a single Bulbasaur. In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
1,000
["implementation"]
107
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuu...
false
stdio
null
true
793/C
793
C
Python 3
TESTS
6
93
6,246,400
26625883
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy from itertools import chain, dropwhile, permutations, combinations from collections import defaultdict, deque # Guide: # 1. construct complex data types while reading (e.g. graph adj list) # 2. avoid any non-necessary time/memory usage #...
80
607
15,360,000
26702595
# In the name of Allah def main() : n = int(input()) x1, y1, x2, y2 = map(int, input().split()) st = [0] ed = [1e11] if x1 == x2 or y1 == y2 : print(-1) exit() for i in range(n) : a, b, c, d = map(int, input().split()) for x, v, s, e in ((a, c, x1, x2), (b, d,...
Tinkoff Challenge - Elimination Round
CF
2,017
2
256
Mice problem
Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located i...
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≤ x1 ≤ x2 ≤ 100 000), (0 ≤ y1 ≤ y2 ≤ 100 000) — the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mic...
In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6. Formall...
null
Here is a picture of the first sample Points A, B, C, D - start mice positions, segments are their paths. Then, at first time when all mice will be in rectangle it will be looks like this: Here is a picture of the second sample Points A, D, B will never enter rectangle.
[{"input": "4\n7 7 9 8\n3 5 7 5\n7 5 2 4\n3 3 7 8\n6 6 3 2", "output": "0.57142857142857139685"}, {"input": "4\n7 7 9 8\n0 3 -5 4\n5 0 5 4\n9 9 -1 -6\n10 5 -7 -10", "output": "-1"}]
2,300
["geometry", "implementation", "math", "sortings"]
80
[{"input": "4\r\n7 7 9 8\r\n3 5 7 5\r\n7 5 2 4\r\n3 3 7 8\r\n6 6 3 2\r\n", "output": "0.57142857142857139685\r\n"}, {"input": "4\r\n7 7 9 8\r\n0 3 -5 4\r\n5 0 5 4\r\n9 9 -1 -6\r\n10 5 -7 -10\r\n", "output": "-1\r\n"}, {"input": "4\r\n8 42 60 54\r\n9 54 -58 -62\r\n46 47 52 -76\r\n15 50 -37 -40\r\n54 51 78 64\r\n", "outp...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(output_path, 'r') as f: ref_line = f.readline().strip() with open(submission_path, 'r') as f: sub_line = f.readline().strip() if ref_line == '-1': print(1 if sub_line == '-1' else 0) return ...
true
416/A
416
A
Python 3
TESTS
63
93
0
6336422
n = int(input()) mi = -2*10**9 ma = 2*10**9 for i in range(n): tp,nn,ans = input().split() nn = int(nn) if tp=="<": if ans == "Y": ma = min(ma,nn-1) else: mi = max(mi,nn) elif tp == "<=": if ans == "Y": ma = min(ma,nn) else: ...
66
62
0
10532029
import sys import math n = int(input()) k1 = -2 * (10 ** 9) k2 = 2 * (10 ** 9) for i in range(n): st = (sys.stdin.readline()).split() if(st[2] == "N"): if(st[0] == ">"): st[0] = "<=" elif(st[0] == "<"): st[0] = ">=" elif(st[0] == "<="): st[0] = ">" ...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Guess a number!
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions: - Is it true that y is strictl...
The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is: - ">" (for the first type queries), - "<" (for the second type queries)...
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
null
null
[{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}]
1,400
["greedy", "implementation", "two pointers"]
66
[{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.readlines() n = int(lines[0].strip()) queries = [line.strip().split() for line in lines[1:n+1]] low = -2 * 10**9 high = 2 * 10**9 for sign, x_str, ans in queries: x = i...
true
158/B
158
B
Python 3
TESTS
63
92
409,600
231386059
number_of_groups = int(input()) kids_per_group = input() groups_with_four_kids = kids_per_group.count('4') groups_with_three_kids = kids_per_group.count('3') groups_with_two_kids = kids_per_group.count('2') groups_with_one_kid = kids_per_group.count('1') number_of_cars = groups_with_four_kids + groups_with_two_kids /...
105
92
409,600
226742382
a=[*open(0)][1].count;print(a('4')+a('3')+(a('2')*2+max(0,a('1')-a('3'))+3)//4)
VK Cup 2012 Qualification Round 1
CF
2,012
3
256
Taxi
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
null
In the first test we can sort the children into four cars like this: - the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly). There are o...
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
1,100
["*special", "greedy", "implementation"]
105
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r...
false
stdio
null
true
158/B
158
B
PyPy 3-64
TESTS
60
154
12,492,800
227160926
import math n=int(input()) l=list(map(int,input().split())) if sum(l)%4==0: if l.count(3)>=math.ceil(len(l)/2) and l.count(1)==0: print((sum(l)//4)+1) else: print((sum(l)//4)) else:print((sum(l)//4)+1)
105
92
409,600
231325047
n=int(input()) a,b,c,d=map(input().count,('1','2','3','4')) print(d+c+(b*2+max(0,a-c)+3)//4)
VK Cup 2012 Qualification Round 1
CF
2,012
3
256
Taxi
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
null
In the first test we can sort the children into four cars like this: - the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly). There are o...
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
1,100
["*special", "greedy", "implementation"]
105
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r...
false
stdio
null
true
158/B
158
B
PyPy 3
TESTS
63
248
7,065,600
228060291
# 4 = 1 # 3 = 1, 3 # 2 = 2, 2 1, 2 2, 1, 1 from collections import Counter from math import ceil n = int(input()) lst = list(map(int, input().split())) lst_count = dict(Counter(lst)) taxies = lst_count.get(4, 0) for i in range(lst_count.get(3, 0)): taxies += 1 if 1 in lst_count: lst_count[1] = max(...
105
124
2,560,000
227965580
import math n=int(input()) li=[int(_) for _ in input().split()] ans=li.count(4) b,c,d=li.count(3),li.count(2),li.count(1) ans+=b+math.ceil(c/2) forone=b if c%2 !=0: forone+=2 if forone < d: ans+=math.ceil((d-forone)/4) print(ans)
VK Cup 2012 Qualification Round 1
CF
2,012
3
256
Taxi
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
null
In the first test we can sort the children into four cars like this: - the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly). There are o...
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
1,100
["*special", "greedy", "implementation"]
105
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r...
false
stdio
null
true
711/B
711
B
PyPy 3
TESTS
92
342
9,728,000
231060961
import sys input = sys.stdin.readline l2=[] lsum=[] n=int(input()) ld1=[] ld2=[] for i in range(n): l1=list(map(int,input().split())) ld1.append(l1[i]) ld2.append(l1[n-i-1]) l2.append(l1) lsum.append(sum(l1)) for j in range(n): s=0 for k in range(n): s=s+l2[k][j] lsum.append(s) ...
147
218
6,246,400
20310383
n = int(input()) MagKvad = list(list(map(int, input().split())) for i in range(n)) def f(sm): global n global MagKvad s1,s2 = 0,0 for i in range(n): s1 += MagKvad[i][i] s2 += MagKvad[i][n-i-1] if s1 != s2: return False if s1 != sm: return False ...
Codeforces Round 369 (Div. 2)
CF
2,016
2
256
Chris and Magic Square
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell. Chris tried filling in ran...
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid. n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If ...
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead. If there are multiple solutions, you may print any of them.
null
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed, The sum of numbers in each row is: 4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15. The sum of numbers in each column is: 4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15. The sum of numbers in the two diagonals is: 4 +...
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
1,400
["constructive algorithms", "implementation"]
147
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 ...
false
stdio
null
true
757/A
757
A
Python 3
TESTS
28
77
4,710,400
23796337
s=input() d=[] d.append(s.count('B')) d.append(int((s.count('u'))/2)) d.append(s.count('l')) d.append(int((s.count('a'))/2)) d.append(s.count('s')) d.append(s.count('r')) print(int(min(d)))
107
46
102,400
205326592
s = input().strip() counts = {'B': 0, 'u': 0, 'l': 0, 'b': 0, 'a': 0, 's': 0, 'r': 0} for c in s: if c in counts: counts[c] += 1 counts['u'] //= 2 counts['a'] //= 2 print(min(counts.values()))
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
CF
2,017
1
256
Gotta Catch Em' All!
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas...
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s. The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
Output a single integer, the answer to the problem.
null
In the first case, you could pick: Bulbbasaur. In the second case, there is no way to pick even a single Bulbasaur. In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
1,000
["implementation"]
107
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuu...
false
stdio
null
true
757/A
757
A
Python 3
TESTS
28
62
4,710,400
23796378
s=input() d=[] d.append(s.count('B')) d.append(int((s.count('u'))/2)) d.append(s.count('l')) d.append(int((s.count('a'))/2)) d.append(s.count('s')) d.append(s.count('r')) min=d[0] for i in range(len(d)): if d[i] >= min: min=min else: min=d[i] print(min)
107
46
102,400
208494590
def solve(s): letter_to_count = build_letter_to_count(s) return min(letter_to_count.get(letter, 0) // count for letter, count in build_letter_to_count("Bulbasaur").items()) def build_letter_to_count(string): letter_to_count = {} for letter in string: letter_to_count[letter] = letter_to_count.g...
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
CF
2,017
1
256
Gotta Catch Em' All!
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas...
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s. The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
Output a single integer, the answer to the problem.
null
In the first case, you could pick: Bulbbasaur. In the second case, there is no way to pick even a single Bulbasaur. In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
1,000
["implementation"]
107
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuu...
false
stdio
null
true
416/A
416
A
Python 3
TESTS
63
77
4,608,000
29248480
n = int(input()) min_y = -2000000000 max_y = 2000000000 Impossible = False def opposite(sign): if sign == '>': return '<=' if sign == '<': return '>=' if sign == '<=': return '>' if sign == '<=': return '<' for i in range(n): sign, number, ans = input().split(' ') if ans == 'N': sign =...
66
62
0
138344556
n=int(input()) k=-2000000000 l=2000000000 for x in range(n): a,z,b=input().split() a=a z=int(z) b=b if(a=='>'and b=='Y'and k<z+1): k=z+1 elif(a=='>='and b=='Y'and k<z): k=z elif(a=='>'and b=='N'and l>z): l=z elif(a=='>='and b=='N'and l>z-1): l=z-1 elif(a=='<'and b=='Y'and l>z-1): l=z-1 elif(a=='<='a...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Guess a number!
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions: - Is it true that y is strictl...
The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is: - ">" (for the first type queries), - "<" (for the second type queries)...
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
null
null
[{"input": "4\n>= 1 Y\n< 3 N\n<= -3 N\n> 55 N", "output": "17"}, {"input": "2\n> 100 Y\n< -100 Y", "output": "Impossible"}]
1,400
["greedy", "implementation", "two pointers"]
66
[{"input": "4\r\n>= 1 Y\r\n< 3 N\r\n<= -3 N\r\n> 55 N\r\n", "output": "17\r\n"}, {"input": "2\r\n> 100 Y\r\n< -100 Y\r\n", "output": "Impossible\r\n"}, {"input": "4\r\n< 1 N\r\n> 1 N\r\n> 1 N\r\n> 1 N\r\n", "output": "1\r\n"}, {"input": "4\r\n<= 1 Y\r\n>= 1 Y\r\n>= 1 Y\r\n<= 1 Y\r\n", "output": "1\r\n"}, {"input": "4\r...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path) as f: lines = f.readlines() n = int(lines[0].strip()) queries = [line.strip().split() for line in lines[1:n+1]] low = -2 * 10**9 high = 2 * 10**9 for sign, x_str, ans in queries: x = i...
true
158/B
158
B
Python 3
TESTS
36
92
0
232083603
user = input() group = input().split(" ") sum = 0 for i in group: sum+=int(i) if sum%4 == 0: print(sum//4) else: cal = sum//4 print(cal+1)
105
124
2,560,000
231402681
n = int(input()) e = list(map(int, input().split())) x = [0] * 5 for var in e: x[var] += 1 t = x[4] + x[3] + (x[2] + 1) // 2 x[1] -= x[3] if x[2] % 2 == 1: x[1] -= 2 if x[1] > 0: t += (x[1] + 3) // 4 print(t)
VK Cup 2012 Qualification Round 1
CF
2,012
3
256
Taxi
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
null
In the first test we can sort the children into four cars like this: - the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly). There are o...
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
1,100
["*special", "greedy", "implementation"]
105
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r...
false
stdio
null
true
158/B
158
B
Python 3
TESTS
36
92
0
231653193
x=int(input()) y=list(map(int,input().split())) if sum(y)%4==0: print(sum(y)//4) else: print((sum(y)//4)+1)
105
124
2,560,000
231421768
def min_taxis(n, s): counts = [0]*5 for i in s: counts[i] += 1 taxis = counts[4] + counts[3] + counts[2] // 2 counts[1] -= counts[3] if counts[2] % 2: taxis += 1 counts[1] -= 2 if counts[1] > 0: taxis += (counts[1] + 3) // 4 return taxis n = int(input()) s = ...
VK Cup 2012 Qualification Round 1
CF
2,012
3
256
Taxi
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
null
In the first test we can sort the children into four cars like this: - the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly). There are o...
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
1,100
["*special", "greedy", "implementation"]
105
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r...
false
stdio
null
true
220/A
220
A
PyPy 3-64
TESTS
32
139
237,465,600
157426627
import math import sys sys.setrecursionlimit(150000) def main(): n = int(input()) a = [int(x) for x in input().split()] dips = [] for i in range(n-1): if a[i+1] < a[i]: dips.append(i) #print(dips) if len(dips) > 2: print("NO") elif len(dips) == 2: n2 = a...
96
93
8,396,800
161712159
input();a=list(map(int,input().split())) print("YNEOS"[sum(i!=j for i,j in zip(a,sorted(a)))>2::2])
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
623/A
623
A
Python 3
TESTS
25
608
12,185,600
15823362
n, m = (int(_) for _ in input().split()) e = [set() for i in range(n + 1)] deg = [0 for i in range(n + 1)] for i in range(m): x, y = (int(_) for _ in input().split()) deg[x] += 1 deg[y] += 1 e[x].add(y) e[y].add(x) s = ['' for i in range(n + 1)] b = [] ans = 2 for i in range(1, n + 1): if deg[i]...
106
405
4,505,600
66424406
def bfs(k): fila=[k] flag=[0]*(n+1) flag[k]=1 while len(fila) != 0: v=fila[0] mark[v]=mark[k] fila.pop(0) for i in g[v]: if flag[i]==0 and mark[i]!='b': fila.append(i) flag[i]=1 n,m=[int(x) for x in input().split()] g=[[] for i in range(n+1)] res=1 for i in range(m): u,v=...
AIM Tech Round (Div. 1)
CF
2,016
2
256
Graph and String
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties: - G has exactly n vertices, numbered from 1 to n....
The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively. Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It ...
In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise. If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the gra...
null
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions. In the second sample the first vertex is connected to al...
[{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}]
1,800
["constructive algorithms", "graphs"]
106
[{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] # Read input with open(input_path) as f: n, m = map(int, f.readline().split()) edges = [] for _ in range(m): u, v = map(int, f.readline().split()) ...
true
158/B
158
B
Python 3
TESTS
36
92
0
227188726
n = int(input()) ss = input().split() s = 0 for e in ss: s += int(e) if s % 4 == 0: print(int(s / 4)) else: print(int(s/4)+1)
105
124
3,686,400
232586128
def min_number_of_taxis(n, groups): count = [0] * 5 for group in groups: count[group] += 1 taxis = count[4] taxis += count[3] count[1] = max(0, count[1] - count[3]) taxis += count[2] // 2 count[2] %= 2 if count[2] == 1: taxis += 1 count[1] = max(0, count[1] - 2)...
VK Cup 2012 Qualification Round 1
CF
2,012
3
256
Taxi
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
null
In the first test we can sort the children into four cars like this: - the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly). There are o...
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
1,100
["*special", "greedy", "implementation"]
105
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r...
false
stdio
null
true
158/B
158
B
Python 3
TESTS
36
92
0
231496629
a=int(input()) b=list(map(int,input().split())) n=sum(b) if n%4>0: print(n//4+1) else: print(n//4)
105
154
819,200
20557842
l = int(input()) s = str(input()) a = int(s.count("1")) b = s.count("2") c = s.count("3") count = int(s.count("4")) count += c a -= c if b%2 == 0: count += b/2 else: count += (b+1)/2 a -= 2 if a > 0: if a%4 == 0: count += a/4 else: count += (a - a%4 + 4)/4 print(i...
VK Cup 2012 Qualification Round 1
CF
2,012
3
256
Taxi
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
null
In the first test we can sort the children into four cars like this: - the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly). There are o...
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
1,100
["*special", "greedy", "implementation"]
105
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r...
false
stdio
null
true
158/B
158
B
Python 3
TESTS
36
92
0
231614513
n,count,su = int(input()),0,0 c = list(map(int,input().split())) for i in c: if i==4: count+=1 else: su=su+i a=su//4 b=su-a*4 if b>0: print(count+a+1) else: print(count+a)
105
154
2,560,000
227788953
group_num=int(input()) num_1=0 num_2=0 num_3=0 num_4=0 num=0 for i in input().split(): num_i=int(i) if num_i == 1: num_1 += 1 elif num_i == 2: num_2 += 1 elif num_i == 3: num_3 += 1 elif num_i == 4: num_4 += 1 """数学思路写这道题""" if num_2 % 2 == 0: num_2_modified = nu...
VK Cup 2012 Qualification Round 1
CF
2,012
3
256
Taxi
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
null
In the first test we can sort the children into four cars like this: - the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly). There are o...
[{"input": "5\n1 2 4 3 3", "output": "4"}, {"input": "8\n2 3 4 4 2 1 3 1", "output": "5"}]
1,100
["*special", "greedy", "implementation"]
105
[{"input": "5\r\n1 2 4 3 3\r\n", "output": "4\r\n"}, {"input": "8\r\n2 3 4 4 2 1 3 1\r\n", "output": "5\r\n"}, {"input": "5\r\n4 4 4 4 4\r\n", "output": "5\r\n"}, {"input": "12\r\n1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n3 2 1 3\r\n", "output": "3\r...
false
stdio
null
true
540/B
540
B
Python 3
TESTS
11
124
409,600
84122725
import sys INF = 10**20 MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) from math import gcd from math import ceil from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br n, k, p, x, y = I() a = I() s = max(0, x - sum(a)) for i in range(n - k): a.append(m...
78
62
1,740,800
210829379
n,k,p,x,y=list(map(int,input().split())) a=list(map(int,input().split())) tot=sum(a) if (n-k)+tot>x: print(-1) else: a.sort() pre,post=0,0 for i in range(k): if a[i]>=y: post+=1 else: pre+=1 req=n-k lim=n//2 if pre>lim: print(-1) else: ...
Codeforces Round 301 (Div. 2)
CF
2,015
2
256
School Marks
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests...
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total n...
If Vova cannot achieve the desired result, print "-1". Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
null
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai. In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the med...
[{"input": "5 3 5 18 4\n3 5 4", "output": "4 1"}, {"input": "5 3 5 16 4\n5 5 5", "output": "-1"}]
1,700
["greedy", "implementation"]
78
[{"input": "5 3 5 18 4\r\n3 5 4\r\n", "output": "4 1\r\n"}, {"input": "5 3 5 16 4\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "5 3 5 17 4\r\n5 5 5\r\n", "output": "1 1\r\n"}, {"input": "5 3 5 12 1\r\n5 5 1\r\n", "output": "-1\r\n"}, {"input": "5 3 5 13 1\r\n5 5 1\r\n", "output": "1 1\r\n"}, {"input": "7 4 5 26 5\r\n5...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path, 'r') as f_in: n, k, p, x, y = map(int, f_in.readline().split()) existing = list(map(int, f_in.readline().split())) with open(submission_path, 'r') as f_sub: submission_line = f_sub.read().strip() ...
true
757/A
757
A
Python 3
TESTS
27
109
5,324,800
24516197
from collections import Counter c=Counter({'a': 0, 'l': 0, 'r': 0, 'B': 0, 's': 0, 'b': 0, 'u': 0}) c.update(input()) c["a"]=c["a"]//2 c["u"]=c["u"]//2 print(min(c.values()))
107
61
0
164714793
#import io, os #input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline s=input() B=s.count("B") b=s.count("b") u=s.count("u") l=s.count("l") a=s.count("a") st=s.count("s") r=s.count("r") print(min(B,u//2,l,b,a//2,st,r))
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
CF
2,017
1
256
Gotta Catch Em' All!
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas...
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s. The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
Output a single integer, the answer to the problem.
null
In the first case, you could pick: Bulbbasaur. In the second case, there is no way to pick even a single Bulbasaur. In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
1,000
["implementation"]
107
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuu...
false
stdio
null
true
757/B
757
B
Python 3
TESTS
70
1,653
11,980,800
23828867
n = int(input()) pkmns = list(map(int, input().split())) primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 26...
134
218
32,972,800
115835583
import math def seive(a): l=[0]*a for i in range(a): l[i]=i for i in range(2,a,2): l[i]=2 for i in range(3,int(math.sqrt(a))+1): if(l[i]==i): for j in range(i*i,a,i): if(l[j]==j): l[j]=i return l def cal(a,d...
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
CF
2,017
2
512
Bash's Big Day
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2, ...
The input consists of two lines. The first line contains an integer n (1 ≤ n ≤ 105), the number of Pokemon in the lab. The next line contains n space separated integers, where the i-th of them denotes si (1 ≤ si ≤ 105), the strength of the i-th Pokemon.
Print single integer — the maximum number of Pokemons Bash can take.
null
gcd (greatest common divisor) of positive integers set {a1, a2, ..., an} is the maximum positive integer that divides all the integers {a1, a2, ..., an}. In the first sample, we can take Pokemons with strengths {2, 4} since gcd(2, 4) = 2. In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there ...
[{"input": "3\n2 3 4", "output": "2"}, {"input": "5\n2 3 4 6 7", "output": "3"}]
1,400
["greedy", "math", "number theory"]
134
[{"input": "3\r\n2 3 4\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 6 7\r\n", "output": "3\r\n"}, {"input": "3\r\n5 6 4\r\n", "output": "2\r\n"}, {"input": "8\r\n41 74 4 27 85 39 100 36\r\n", "output": "4\r\n"}, {"input": "6\r\n89 20 86 81 62 23\r\n", "output": "3\r\n"}, {"input": "71\r\n23 84 98 8 14 4 42 56 83 87 ...
false
stdio
null
true
900/A
900
A
Python 3
TESTS
26
295
1,740,800
117486166
from collections import Counter n=int(input()) l1=[] l2=[] for i in range(n): a,b=map(int,input().split()) if a<0: l1.append('n') else: l1.append('p') if b<0: l2.append('n') else: l2.append('p') l1=list(Counter(l1).values()) l2=list(Counter(l2).values()) if 1 in l1 or 1 in l2 or (len(l1)==1 and len(l2))==1...
71
109
6,553,600
179373864
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) u, v = 0, 0 for _ in range(n): x, y = map(int, input().split()) if x < 0: u += 1 else: v += 1 ans = "Yes" if min(u, v) <= 1 else "No" print(ans)
Codeforces Round 450 (Div. 2)
CF
2,017
1
256
Find Extra One
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
null
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
[{"input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes"}, {"input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No"}, {"input": "3\n1 2\n2 1\n4 60", "output": "Yes"}]
800
["geometry", "implementation"]
71
[{"input": "3\r\n1 1\r\n-1 -1\r\n2 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 2\r\n-1 1\r\n-2 2\r\n", "output": "No"}, {"input": "3\r\n1 2\r\n2 1\r\n4 60\r\n", "output": "Yes"}, {"input": "10\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n-1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1000000...
false
stdio
null
true
711/B
711
B
Python 3
TESTS
91
124
5,734,400
138306321
# Time Complexity: O(n^2) # Space Complexity: O(n^2) # The program checks the next row and next column to determine the number to # fill in and, then, it checks if the diagonal sums are correct. n = int(input()) if n == 1: print(1) exit() mat = [] i, j = 0, 0 for x in range(n): row = list(map(int, input().s...
147
218
6,348,800
20247363
def main(): n = int(input()) matrix = [] s = None found = False col = 0 row = 0 if n == 1: i = input() return 1 for i in range(n): line = [int(k) for k in input().split(' ')] matrix.append(line) if not found: try: index ...
Codeforces Round 369 (Div. 2)
CF
2,016
2
256
Chris and Magic Square
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell. Chris tried filling in ran...
The first line of the input contains a single integer n (1 ≤ n ≤ 500) — the number of rows and columns of the magic grid. n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes ai, j (1 ≤ ai, j ≤ 109 or ai, j = 0), the number in the i-th row and j-th column of the magic grid. If ...
Output a single integer, the positive integer x (1 ≤ x ≤ 1018) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead. If there are multiple solutions, you may print any of them.
null
In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed, The sum of numbers in each row is: 4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15. The sum of numbers in each column is: 4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15. The sum of numbers in the two diagonals is: 4 +...
[{"input": "3\n4 0 2\n3 5 7\n8 1 6", "output": "9"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1", "output": "1"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1", "output": "-1"}]
1,400
["constructive algorithms", "implementation"]
147
[{"input": "3\r\n4 0 2\r\n3 5 7\r\n8 1 6\r\n", "output": "9\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 0 1\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 ...
false
stdio
null
true
757/A
757
A
PyPy 3
TESTS
75
140
512,000
91686808
st = input() B = st.count("B") # 1 u = st.count("u") # 2 l = st.count("l") # 1 b = st.count("b") # 1 a = st.count("a") # 2 r = st.count("r") # 1 s = st.count("s") # 1 print(int(min(2*B,u,2*b,a,2*r,s*2)/2))
107
62
0
183823124
s = input() c = [s.count(x) for x in "Bulbasur"] c[1] //= 2 c[4] //= 2 print(min(c))
Codecraft-17 and Codeforces Round 391 (Div. 1 + Div. 2, combined)
CF
2,017
1
256
Gotta Catch Em' All!
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas...
Input contains a single line containing a string s (1 ≤ |s| ≤ 105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s. The string s contains lowercase and uppercase English letters, i.e. $$s_i \in \{a,b,\ldots,z,A,B,\ldots,Z\}$$.
Output a single integer, the answer to the problem.
null
In the first case, you could pick: Bulbbasaur. In the second case, there is no way to pick even a single Bulbasaur. In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
[{"input": "Bulbbasaur", "output": "1"}, {"input": "F", "output": "0"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2"}]
1,000
["implementation"]
107
[{"input": "Bulbbasaur\r\n", "output": "1\r\n"}, {"input": "F\r\n", "output": "0\r\n"}, {"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb\r\n", "output": "2\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr\r\n", "output": "5\r\n"}, {"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuu...
false
stdio
null
true
419/A
420
A
Python 3
TESTS
28
62
716,800
173334285
import re regex = re.compile('[B|C|D|E|F|G|J|K|L|N|P|Q|R|S|Z]') s = input() if regex.match(s): print("NO") else: length = len(s) middle = length // 2 if length % 2 == 0: left = s[0:middle] right = s[middle:length][::-1] if s[0:middle] == s[middle:length][::-1]: pri...
80
46
0
179761557
#Ana Clara Lacaze #193858 name = input() mirrorLetters = ['A','H','I','M','O','T','U','V','W','X','Y'] isMirror = True for letter in name: if letter not in mirrorLetters: isMirror = False break if isMirror and name==name[::-1]: print("YES") else: print("NO")
Coder-Strike 2014 - Finals
CF
2,014
1
256
Start Up
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
null
null
[{"input": "AHA", "output": "YES"}, {"input": "Z", "output": "NO"}, {"input": "XO", "output": "NO"}]
1,000
[]
80
[{"input": "AHA\r\n", "output": "YES\r\n"}, {"input": "Z\r\n", "output": "NO\r\n"}, {"input": "XO\r\n", "output": "NO\r\n"}, {"input": "AAA\r\n", "output": "YES\r\n"}, {"input": "AHHA\r\n", "output": "YES\r\n"}, {"input": "BAB\r\n", "output": "NO\r\n"}, {"input": "OMMMAAMMMO\r\n", "output": "YES\r\n"}, {"input": "YYHUI...
false
stdio
null
true