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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
868/C | 868 | C | Python 3 | TESTS | 39 | 623 | 8,396,800 | 45178937 | m=[]
n,k=[int(x) for x in input().split()]
for i in range(n):
m.append(list(map(int,input().split())))
s=0
a=[0]*k
for i in range(n):
for j in range(k):
s+=m[i][j]
if m[i][j]==1:
a[j]+=1
m[i].append(s)
if s==0:
print("YES")
exit()
s=0
for i in range(k):
... | 143 | 187 | 0 | 142931497 | n,k = map(int,input().split())
l = [0]*100
for i in range(n):
l[int(''.join(input().split()),2)] =1
for i in range(16):
for j in range(16):
if(l[i] and l[j] and i&j == 0):
print("YES")
exit(0)
print("NO") | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Qualification Rounds | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems... | The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | null | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | [{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}] | 1,500 | ["bitmasks", "brute force", "constructive algorithms", "dp"] | 143 | [{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\... | false | stdio | null | true |
127/B | 127 | B | Python 3 | TESTS | 40 | 62 | 307,200 | 107147955 | import math
n = int(input())
x = [int(x) for x in input().split()]
d = {}
cnt = 0
for i in x:
d[i] = x.count(i)
for atsl in d:
if(d[atsl]%2 != 0):
cnt = cnt+d[atsl]//2
elif(d[atsl] >= 4 and d[atsl]%2 == 0):
cnt = cnt+math.sqrt(d[atsl])
else:
cnt+=1
print(int(cnt//2)) | 93 | 46 | 0 | 167081265 | n = int(input())
a = list(map(int, input().split()))
x = set()
for e in a:
if a.count(e)%2:
x.add(e)
for e in x:
a.remove(e)
print(len(a)//4) | Codeforces Beta Round 93 (Div. 2 Only) | CF | 2,011 | 1 | 256 | Canvas Frames | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | null | null | [{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}] | 1,000 | ["implementation"] | 93 | [{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "... | false | stdio | null | true |
734/C | 734 | C | PyPy 3-64 | TESTS | 0 | 46 | 0 | 218776165 | n, m, k = map(int, input().split())
x, s = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
min_time = n * x # Время, если варить все зелья без заклинаний
for i in range(m):
if b[i] <= s:
... | 119 | 748 | 34,304,000 | 22241548 | def main():
from bisect import bisect
n, m, k = map(int, input().split())
t, s = map(int, input().split()) # time per stuff,mana
aa = list(map(int, input().split())) # x->t[i] for stuff
aa.append(t)
bb = list(map(int, input().split())) # price of t[i]
bb.append(0)
cc = [0, *map(int, i... | Codeforces Round 379 (Div. 2) | CF | 2,016 | 4 | 256 | Anton and Making Potions | Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions.
Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions.
1. Spells of t... | The first line of the input contains three integers n, m, k (1 ≤ n ≤ 2·109, 1 ≤ m, k ≤ 2·105) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type.
The second line of the input contains two integers x and s (2 ≤ x ≤ 2·109, 1 ≤ s ≤ 2·109) — the i... | Print one integer — the minimum time one has to spent in order to prepare n potions. | null | In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints... | [{"input": "20 3 2\n10 99\n2 4 3\n20 10 40\n4 15\n10 80", "output": "20"}, {"input": "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n100 800", "output": "200"}] | 1,600 | ["binary search", "dp", "greedy", "two pointers"] | 119 | [{"input": "20 3 2\r\n10 99\r\n2 4 3\r\n20 10 40\r\n4 15\r\n10 80\r\n", "output": "20\r\n"}, {"input": "20 3 2\r\n10 99\r\n2 4 3\r\n200 100 400\r\n4 15\r\n100 800\r\n", "output": "200\r\n"}, {"input": "10 3 3\r\n10 33\r\n1 7 6\r\n17 25 68\r\n2 9 10\r\n78 89 125\r\n", "output": "10\r\n"}, {"input": "94 1 1\r\n26 324\r\n... | false | stdio | null | true |
603/A | 603 | A | PyPy 3 | TESTS | 12 | 248 | 26,624,000 | 105988277 | from sys import stdin,stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int,stdin.readline().split()))
for _ in range(1):#nmbr()):
n=nmbr()
a=[int(ch) for ch in input()]
n=len(a)
dp=[[[0 for _ in range(2)]for _ in range(3)]for _ in range(n)]
dp[0][0][a[0]]=1
dp[0][0][1^a[0]]=0
... | 116 | 62 | 0 | 193915042 | import sys
input = sys.stdin.readline
n = int(input())
s = input()[:-1]
a = s.count('10')*2
if s[-1] == '1':
a += 1
b = s.count('01')*2
if s[-1] == '0':
b += 1
print(min(n, max(a+2, b+2))) | Codeforces Round 334 (Div. 1) | CF | 2,015 | 2 | 256 | Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).
The following line contains a binary string of length n representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | null | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | [{"input": "8\n10000011", "output": "5"}, {"input": "2\n01", "output": "2"}] | 1,600 | ["dp", "greedy", "math"] | 116 | [{"input": "8\r\n10000011\r\n", "output": "5\r\n"}, {"input": "2\r\n01\r\n", "output": "2\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "75\r\n010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "75\r\n"}, {"input": "11\r\n00000000000\r\n", "output": "3\r\n"}, ... | false | stdio | null | true |
603/A | 603 | A | PyPy 3 | TESTS | 12 | 155 | 7,884,800 | 63535853 | n = int(input())
s = list(input())
ans = len([s[i] for i in range(len(s)-1) if s[i] != s[i+1]])+1
for i in range(n-1):
if s[i] == s[i+1]:
s[i] = -1
s[i+1] = -1
ans += 1
break
for i in range(n-1, 0, -1):
if s[i] == -1:
break
elif s[i] == s[i-1]:
ans += 1
... | 116 | 62 | 204,800 | 15840776 | def main():
n, t, a = int(input()), 0, '*'
for b in input():
if a == b:
t += 1
else:
a = b
print(n - max(t - 2, 0))
if __name__ == '__main__':
main() | Codeforces Round 334 (Div. 1) | CF | 2,015 | 2 | 256 | Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).
The following line contains a binary string of length n representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | null | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | [{"input": "8\n10000011", "output": "5"}, {"input": "2\n01", "output": "2"}] | 1,600 | ["dp", "greedy", "math"] | 116 | [{"input": "8\r\n10000011\r\n", "output": "5\r\n"}, {"input": "2\r\n01\r\n", "output": "2\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "75\r\n010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "75\r\n"}, {"input": "11\r\n00000000000\r\n", "output": "3\r\n"}, ... | false | stdio | null | true |
603/A | 603 | A | PyPy 3 | TESTS | 12 | 62 | 20,787,200 | 33998935 | #!/usr/bin/env python
input()
str=input()
print(1+str.count('01')+str.count('10')+min(2,str.count('00')+str.count('11'))) | 116 | 62 | 3,584,000 | 177955669 | n = int(input())
binary = input()
inc, dec = [1] * len(binary), [1] * len(binary)
for i in range(1, len(binary)):
if binary[i] > binary[i - 1]:
inc[i] = dec[i - 1] + 1
dec[i] = dec[i - 1]
elif binary[i] < binary[i - 1]:
dec[i] = inc[i - 1] + 1
inc[i] = inc[i - 1]
else:
... | Codeforces Round 334 (Div. 1) | CF | 2,015 | 2 | 256 | Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).
The following line contains a binary string of length n representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | null | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | [{"input": "8\n10000011", "output": "5"}, {"input": "2\n01", "output": "2"}] | 1,600 | ["dp", "greedy", "math"] | 116 | [{"input": "8\r\n10000011\r\n", "output": "5\r\n"}, {"input": "2\r\n01\r\n", "output": "2\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "75\r\n010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "75\r\n"}, {"input": "11\r\n00000000000\r\n", "output": "3\r\n"}, ... | false | stdio | null | true |
603/A | 603 | A | Python 3 | TESTS | 12 | 140 | 204,800 | 43274071 | n = int(input())
consec= 1
changes = 0
oppo = 0
rep = False
cons = False
s = input().strip()
prev = s[0]
for x in s[1:]:
if prev != x:
changes += 1
consec = 1
rep = False
elif not rep:
rep = True
oppo += 1
else:
consec += 1
if consec == 3:
cons = T... | 116 | 62 | 5,836,800 | 34808933 | n, s = int(input()), input()
print(min(n, s.count("01") + s.count("10") + 3)) | Codeforces Round 334 (Div. 1) | CF | 2,015 | 2 | 256 | Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).
The following line contains a binary string of length n representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | null | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | [{"input": "8\n10000011", "output": "5"}, {"input": "2\n01", "output": "2"}] | 1,600 | ["dp", "greedy", "math"] | 116 | [{"input": "8\r\n10000011\r\n", "output": "5\r\n"}, {"input": "2\r\n01\r\n", "output": "2\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "75\r\n010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "75\r\n"}, {"input": "11\r\n00000000000\r\n", "output": "3\r\n"}, ... | false | stdio | null | true |
858/C | 858 | C | PyPy 3-64 | TESTS | 41 | 77 | 2,252,800 | 202646815 | import sys
input = lambda: sys.stdin.readline().rstrip()
S = input()
ans = ['']
cnt,seen = 0,set()
for c in S:
if c in ('a','e','i','o','u'):
ans[-1]+=c
cnt = 0
seen = set()
else:
cnt+=1
seen.add(c)
if cnt>2 and len(seen)>1:
ans.append('')
... | 108 | 46 | 102,400 | 227746851 | # brownfox2k6
import sys
s = input()
vowels = "aeiou"
spaces = []
i = 1
while i < len(s) - 1:
if s[i-1] not in vowels\
and s[i] not in vowels\
and s[i+1] not in vowels\
and len(set(s[i-1:i+2])) != 1:
spaces.append(i+1)
i += 2
else:
i += 1
ind = 0
f... | Технокубок 2018 - Отборочный Раунд 1 | CF | 2,017 | 1 | 256 | Did you mean... | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | null | null | [{"input": "hellno", "output": "hell no"}, {"input": "abacaba", "output": "abacaba"}, {"input": "asdfasdf", "output": "asd fasd f"}] | 1,500 | ["dp", "greedy", "implementation"] | 108 | [{"input": "hellno\r\n", "output": "hell no \r\n"}, {"input": "abacaba\r\n", "output": "abacaba \r\n"}, {"input": "asdfasdf\r\n", "output": "asd fasd f \r\n"}, {"input": "ooo\r\n", "output": "ooo \r\n"}, {"input": "moyaoborona\r\n", "output": "moyaoborona \r\n"}, {"input": "jxegxxx\r\n", "output": "jxegx xx \r\n"}, {"i... | false | stdio | null | true |
858/C | 858 | C | PyPy 3-64 | TESTS | 39 | 93 | 1,126,400 | 146961561 | s=input()
ans=""
seen=set()
p=0
for i,ch in enumerate(s):
if ch in "aeiou":
ans+=ch
seen=set()
p=0
elif i<2:
seen.add(ch)
ans+=ch
p+=1
elif p==2:
seen.add(ch)
if len(seen)>=2:
ans+=" "
ans+=ch
seen=set()
... | 108 | 46 | 102,400 | 231070166 | s=input()
n=len(s)
yuan=['a','e','i','o','u']
i=0
ans=[]
while i<n-2:
if not(s[i] in yuan) and not(s[i+1] in yuan) and not(s[i+2] in yuan) and not(s[i]==s[i+1]==s[i+2]):
ans.append(i+2)
i+=1
i+=1
pos=0
for i in ans:
print(s[pos:i],end=" ")
pos=i
print(s[pos:]) | Технокубок 2018 - Отборочный Раунд 1 | CF | 2,017 | 1 | 256 | Did you mean... | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | null | null | [{"input": "hellno", "output": "hell no"}, {"input": "abacaba", "output": "abacaba"}, {"input": "asdfasdf", "output": "asd fasd f"}] | 1,500 | ["dp", "greedy", "implementation"] | 108 | [{"input": "hellno\r\n", "output": "hell no \r\n"}, {"input": "abacaba\r\n", "output": "abacaba \r\n"}, {"input": "asdfasdf\r\n", "output": "asd fasd f \r\n"}, {"input": "ooo\r\n", "output": "ooo \r\n"}, {"input": "moyaoborona\r\n", "output": "moyaoborona \r\n"}, {"input": "jxegxxx\r\n", "output": "jxegx xx \r\n"}, {"i... | false | stdio | null | true |
858/C | 858 | C | Python 3 | TESTS | 41 | 62 | 4,608,000 | 30481409 | result, seq, same, prev = [], 0, True, ''
for c in input():
seq = 0 if c in 'aeiou' else seq + 1
same = seq == 1 or (same and (c == prev))
prev = c
if seq >= 3 and not same:
result.append(' ')
seq = 1
result.append(c)
print(''.join(result)) | 108 | 46 | 2,150,400 | 144368783 | def insert (source_str, insert_str, pos):
return source_str[:pos]+insert_str+source_str[pos:]
def isVowel(c):
vowels = ["a", "i", "o", "u", "e"]
if (c in vowels):
return True
return False
word = input()
newWord = word
conCount, cutCount = 0, 0
block = set()
isTypo = False
for i in range(len(wo... | Технокубок 2018 - Отборочный Раунд 1 | CF | 2,017 | 1 | 256 | Did you mean... | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | null | null | [{"input": "hellno", "output": "hell no"}, {"input": "abacaba", "output": "abacaba"}, {"input": "asdfasdf", "output": "asd fasd f"}] | 1,500 | ["dp", "greedy", "implementation"] | 108 | [{"input": "hellno\r\n", "output": "hell no \r\n"}, {"input": "abacaba\r\n", "output": "abacaba \r\n"}, {"input": "asdfasdf\r\n", "output": "asd fasd f \r\n"}, {"input": "ooo\r\n", "output": "ooo \r\n"}, {"input": "moyaoborona\r\n", "output": "moyaoborona \r\n"}, {"input": "jxegxxx\r\n", "output": "jxegx xx \r\n"}, {"i... | false | stdio | null | true |
993/C | 993 | C | PyPy 3-64 | TESTS | 24 | 124 | 1,536,000 | 140694341 | def process(A, B):
n = len(A)
m = len(B)
d = {}
for i in range(n):
for j in range(m):
x = A[i]+B[j]
if x not in d:
d[x] = [set([]), set([])]
d[x][0].add(i)
d[x][1].add(j)
d2 = sorted(d, key=lambda a:len(d[a][0])+len(d[a][1]), re... | 88 | 857 | 56,012,800 | 39336329 | from collections import Counter
MV = 400020
a = [0] * MV
for i in range(MV):
a[i] = set()
n ,m = list(map(int , input().split()))
first = list(map(int , input().split()))
second = list(map(int , input().split()))
for fid, f in enumerate(first):
for sid, s in enumerate(second):
a[f+s].add(fid + MV)
... | 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 |
660/A | 660 | A | Python 3 | TESTS | 6 | 31 | 0 | 150950277 | m=10**9+7
import math
n=int(input())
z=list(map(int,input().split()))
ans=[z[0]]
k=0
for i in range(1,n):
p=math.gcd(z[i-1],z[i])
# q=math.gcd(z[i],z[i+1])
if(p!=1):
ans.append(((z[i]*z[i-1])//(math.gcd(z[i],z[i-1]))+1)%m)
ans.append(z[i])
k+=1
else:
ans.append(z[i])
print(k)
print(*ans) | 93 | 46 | 0 | 179478285 | n = int(input())
a = [int(s) for s in input().split()]
def evklid(a, b):
while a!=0 and b!=0:
if a > b:
a = a % b
else:
b = b % a
return a + b
s = ''
k = 0
s += str(a[0])
for i in range(1, n):
if evklid(a[i], a[i-1]) != 1:
k += 1
s += ' 1 ' + str... | Educational Codeforces Round 11 | ICPC | 2,016 | 1 | 256 | Co-prime Array | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integer... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. | Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Als... | null | null | [{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}] | 1,200 | ["greedy", "implementation", "math", "number theory"] | 93 | [{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"inp... | false | stdio | import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
# Read submission output
with open(submission_path) a... | true |
818/E | 818 | E | Python 3 | TESTS | 2 | 77 | 7,065,600 | 36927052 | count=0
def is_valid(l,k):
pro=1
for i in l:
pro=pro*i
if(pro%k==0):
return 1
else:
return 0
def e_card(l,k):
global count
if(is_valid(l,k)):
count+=1
if(len(l)==1):
return
else:
m=l[len(l)-1]
l.pop()
e_card(l,k)
l.append(m)
m=l[0]
l.pop(0)
e_card(l,k)
... | 135 | 77 | 13,414,400 | 170114604 | R,G=lambda:map(int,input().split()),range
n,k=R();a=[0]+[*R()];z,l,p=0,1,1
for r in G(1,n+1):
p=p*a[r]%k
if p==0:
p=1;i=r
while p*a[i]%k:p=p*a[i]%k;i-=1
z+=(n-r+1)*(i-l+1);l=i+1
print(z) | Educational Codeforces Round 24 | ICPC | 2,017 | 2 | 256 | Card Game Again | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck.
After receiving th... | The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards. | Print the number of ways to choose x and y so the resulting deck is valid. | null | In the first example the possible values of x and y are:
1. x = 0, y = 0;
2. x = 1, y = 0;
3. x = 2, y = 0;
4. x = 0, y = 1. | [{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}] | 1,900 | ["binary search", "data structures", "number theory", "two pointers"] | 135 | [{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | false | stdio | null | true |
868/C | 868 | C | Python 3 | TESTS | 56 | 233 | 0 | 31025372 | def main():
m,k = map(int, input().split())
all = set()
zeros = ''
for _ in range(k):
zeros += '0'
for _ in range(m):
line = input().replace(' ', '')
if line == zeros:
print('YES')
return
all.add(line)
for s1 in all:
for s2 in all... | 143 | 202 | 0 | 31020373 | n, k = map(int, input().split())
a = set()
yes = False
for i in range(n):
a.add(input())
for w in a:
for w2 in a:
x = list(map(int, w.split()))
y = list(map(int, w2.split()))
count = 0
for i in range(k):
if x[i] + y[i] != 2:
count += 1
if count == k:
yes = True
if yes:
print("YES")
else:
print("... | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Qualification Rounds | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems... | The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | null | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | [{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}] | 1,500 | ["bitmasks", "brute force", "constructive algorithms", "dp"] | 143 | [{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\... | false | stdio | null | true |
868/C | 868 | C | Python 3 | TESTS | 37 | 218 | 307,200 | 31172359 | n,k = [int(i) for i in input().split()]
if k == 1:
alert = 0
for time in range(n):
term = str(input())
if term == "0":
alert = 1
break
print("NO") if alert == 0 else print("YES")
elif k == 2:
(s1,s2) = (0,0)
for time in range(n):
term = str(input())
... | 143 | 202 | 3,788,800 | 140599210 | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writabl... | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Qualification Rounds | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems... | The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | null | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | [{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}] | 1,500 | ["bitmasks", "brute force", "constructive algorithms", "dp"] | 143 | [{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\... | false | stdio | null | true |
868/C | 868 | C | PyPy 3 | TESTS | 56 | 935 | 14,540,800 | 52221630 | ##a = list(map(int, input().split()))
##print(' '.join(map(str, res)))
[n, k] = list(map(int, input().split()))
prob = list()
for _ in range(n):
prob.append(list(map(int, input().split())))
mask = list()
neg = list()
for p in prob:
x = 0
y = 0
for i in range(k):
if p[i] == 1:
x |= ... | 143 | 249 | 10,342,400 | 69655682 | '''input
2 3
0 0 1
1 0 0
'''
from sys import stdin
input = stdin.readline
import math
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 4)
def get_all(string, index, temp, aux):
if index == len(string):
return aux.append("".join(temp))
if string[index] == '1':
temp.append('1')
get_al... | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Qualification Rounds | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems... | The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | null | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | [{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}] | 1,500 | ["bitmasks", "brute force", "constructive algorithms", "dp"] | 143 | [{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\... | false | stdio | null | true |
868/C | 868 | C | PyPy 3 | TESTS | 56 | 826 | 6,246,400 | 64098804 | def flip(x):
return ''.join(['10'[int(i)] for i in x])
n, k = map(int, input().split())
s = set()
for _ in range(n):
x = input().replace(' ', '')
if flip(x) in s or x == '0' * k:
exit(print('YES'))
s.add(x)
print('NO') | 143 | 265 | 716,800 | 73197378 | from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
#sys.setrecursionlimit(100000)
n,k=mdata()
s=set()
for i in range(n):... | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Qualification Rounds | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems... | The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | null | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | [{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}] | 1,500 | ["bitmasks", "brute force", "constructive algorithms", "dp"] | 143 | [{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\... | false | stdio | null | true |
858/C | 858 | C | Python 3 | TESTS | 37 | 62 | 4,915,200 | 30463886 | a = input()
a += 'a'
g = {'a', 'e', 'i', 'o', 'u'}
b = ''
def seach(b):
b += 'a'
count = 0
i = -1
if len(set(b)) != 1:
while True:
i += 1
count += 1
if b[i] != b[i-1]:
if count > 2:
i1 = i - count
i2 = i
... | 108 | 62 | 0 | 30547555 | s = input()
gl = ['a', 'i', 'e', 'o', 'u']
t = []
i = 0
while i + 2 < len(s):
good = 0
if s[i] in gl or s[i + 1] in gl or s[i + 2] in gl or s[i] == s[i + 1] == s[i + 2]:
good = 1
t.append(s[i])
if not good:
t.append(s[i + 1])
t.append(' ')
i += 1
i += 1
while ... | Технокубок 2018 - Отборочный Раунд 1 | CF | 2,017 | 1 | 256 | Did you mean... | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | null | null | [{"input": "hellno", "output": "hell no"}, {"input": "abacaba", "output": "abacaba"}, {"input": "asdfasdf", "output": "asd fasd f"}] | 1,500 | ["dp", "greedy", "implementation"] | 108 | [{"input": "hellno\r\n", "output": "hell no \r\n"}, {"input": "abacaba\r\n", "output": "abacaba \r\n"}, {"input": "asdfasdf\r\n", "output": "asd fasd f \r\n"}, {"input": "ooo\r\n", "output": "ooo \r\n"}, {"input": "moyaoborona\r\n", "output": "moyaoborona \r\n"}, {"input": "jxegxxx\r\n", "output": "jxegx xx \r\n"}, {"i... | false | stdio | null | true |
127/B | 127 | B | PyPy 3-64 | TESTS | 14 | 46 | 0 | 204365712 | n = int(input())
data = input().split()
d = [int(x) for x in data]
ans = 0
kol = 0
while len(d) != 0:
kol += d.count(d[0]) // 2
now = d.count(d[0])
for j in range(now):
d.remove(d[0])
ans = kol // 2
print(ans) | 93 | 46 | 0 | 167795464 | n = input()
n = 0
sps = input().split()
slv = dict()
for i in sps:
if i not in slv:
slv[i] = 1
else:
slv[i] += 1
for j in slv.values():
n = n + (j // 2)
print (n // 2) | Codeforces Beta Round 93 (Div. 2 Only) | CF | 2,011 | 1 | 256 | Canvas Frames | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | null | null | [{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}] | 1,000 | ["implementation"] | 93 | [{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "... | false | stdio | null | true |
858/C | 858 | C | Python 3 | TESTS | 39 | 77 | 0 | 30484341 | string = input()
good = 'aeiou'
last = 0
a = ''
bad = ''
i = 0
while i <= len(string)-1:
if good.find(string[i]) >= 0:
a += bad
bad = ''
a += string[i]
i += 1
else:
bad += string[i]
if len(bad) >= 3:
if bad == bad[0] * 3:
a += bad
... | 108 | 62 | 0 | 30690983 | s = input()
vowels = ('a', 'e', 'u', 'o', 'i')
res = ''
i = 0
while i < len(s) - 2:
if s[i] not in vowels and s[i + 1] not in vowels and s[i + 2] not in vowels and s[i: i + 3] != s[i] * 3:
res += s[i: i + 2] + ' '
i += 2
else:
res += s[i]
i += 1
res += s[i:]
print(res) | Технокубок 2018 - Отборочный Раунд 1 | CF | 2,017 | 1 | 256 | Did you mean... | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | null | null | [{"input": "hellno", "output": "hell no"}, {"input": "abacaba", "output": "abacaba"}, {"input": "asdfasdf", "output": "asd fasd f"}] | 1,500 | ["dp", "greedy", "implementation"] | 108 | [{"input": "hellno\r\n", "output": "hell no \r\n"}, {"input": "abacaba\r\n", "output": "abacaba \r\n"}, {"input": "asdfasdf\r\n", "output": "asd fasd f \r\n"}, {"input": "ooo\r\n", "output": "ooo \r\n"}, {"input": "moyaoborona\r\n", "output": "moyaoborona \r\n"}, {"input": "jxegxxx\r\n", "output": "jxegx xx \r\n"}, {"i... | false | stdio | null | true |
660/A | 660 | A | Python 3 | TESTS | 6 | 61 | 4,608,000 | 25372542 | n = int(input())
num = list(map(int,input().split()))
x = 0
banyak = 0
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def coprime(a, b):
return gcd(a, b) == 1
while x<(len(num)-1):
if not coprime(num[x],num[x+1]):
p = max(num[x],num[x+1])-1
x+=1
banyak+=1
... | 93 | 46 | 0 | 182277449 | def gcd(a, b):
if (b == 0):
return a
return gcd(b, a%b)
n = int(input().strip())
arr = list(map(int, input().strip().split()))
i, count = 0, 0
for i in range(n-1):
if gcd(arr[i], arr[i+1]) != 1:
count += 1
print(count)
print(arr[0], end=" ")
for i in range(1, n):
if gcd(arr[i], arr[i-1]) != 1:
prin... | Educational Codeforces Round 11 | ICPC | 2,016 | 1 | 256 | Co-prime Array | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integer... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. | Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Als... | null | null | [{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}] | 1,200 | ["greedy", "implementation", "math", "number theory"] | 93 | [{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"inp... | false | stdio | import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
# Read submission output
with open(submission_path) a... | true |
724/B | 724 | B | PyPy 3 | TESTS | 63 | 155 | 23,142,400 | 21299288 | n, m = [int(x) for x in input().split()]
L = [[int(x) for x in input().split()] for i in range(n)]
def solve(L):
D = {i:set() for i in range(n)}
for i in range(n):
for j in range(m):
if L[i][j] != j+1:
D[i].add(j+1)
if len(D[i]) > 4 or len(D[i]) == 4 and L[i][... | 86 | 46 | 0 | 155465362 | n,m=map(int,input().split())
def test(b):
for r in range(n):
cnt = 0
for k in range(m):
cnt += b[r][k] != k+1
if cnt > 2:
return False
return True
a=[[*map(int,input().split())]for _ in range(n)]
if test(a): exit(print('YES'))
for j in range(m):
for i in ran... | 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 |
858/B | 858 | B | Python 3 | TESTS | 7 | 46 | 0 | 31321217 | import math
n,k=map(int,input().split(' '))
m=[]
d=0
for i in range(k):
m.append(list(map(int,input().split(' '))))
t=-1
for i in range(101):
p=0
for j in m:
if ((j[1]-1)*i<j[0]) and (j[0]<=i*j[1]):
p+=1
#print(i)
if (p==k) and (math.ceil(n/t)!= math.ceil(n/i)):
... | 101 | 46 | 0 | 204197100 | R=lambda:list(map(int,input().split()))
n,m=R()
c=[R()for i in range(m)]
a=list(set([(n-1)//i+1 for i in range(1,999)if all((k[0]-1)//i+1==k[1]for k in c)]))
print(a[0]if len(a)==1 else -1) | Технокубок 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 |
858/B | 858 | B | Python 3 | TESTS | 7 | 77 | 0 | 30460943 | n, m = map(int, input().split())
data = []
for i in range(0, m):
data.append(list(map(int, input().split())))
if m == 0:
print(-1)
else:
ans = []
for i in range(1, 102):
mark = 1
for j in range(0, m):
if (data[j][0] + i - 1) // i != data[j][1]:
mark = 0
... | 101 | 46 | 0 | 230752690 | p=lambda: map(int, input().split())
n,m=p()
a,b=1,n
for i in range(m):
k,f=p()
a=max(1+(k-1)//f,a)
if f>1:b=min((k-1)//(f-1),b)
x,y=(n-1)//a,(n-1)//b
print(-1 if x-y else (1+x)) | Технокубок 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 |
858/B | 858 | B | Python 3 | TESTS | 6 | 78 | 7,065,600 | 37639702 | n, m = map(int, input().split())
ans = set()
d = {}
for i in range(m):
k, f = map(int, input().split())
d[k] = f
for i in range(1, 100):
floor = 1
cur_floor = 0
ans_floor = 0
for j in range(1, 101):
if cur_floor == i:
floor += 1
cur_floor = 0
if d.get(j, f... | 101 | 62 | 0 | 30547080 | n, m = map(int, input().split())
a = [0] * m
for i in range(m):
a[i] = list(map(int, input().split()))
a[i][0] -= 1
a[i][1] -= 1
n -= 1
canbe = set()
last = 0
for i in range(1, 200):
good = 1
for j in range(m):
k = a[j][0]
f = a[j][1]
if not (i * f <= k <= i * (f + 1) - 1)... | Технокубок 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 |
858/B | 858 | B | Python 3 | TESTS | 6 | 93 | 0 | 55567888 | n, m = (int(s) for s in input().split())
g = set()
h = {}
ho = -1
for i in range(m):
k, f = (int(s) for s in input().split())
h[k] = f
for i in range(1, 100):
p = 0
for k in h:
if (k-1)//i!=h[k]-1:
p = -1
break
if p==0:
g.add(i)
for i in g:
if ... | 101 | 62 | 0 | 30622435 | import math
class TaskA:
def __init__(self):
s = input().split()
self.n, self.m = int(s[0]), int(s[1])
self.k = list()
self.f = list()
for i in range(self.m):
st = input().split()
self.k.append(int(st[0]))
self.f.append(int(st[1]))
def... | Технокубок 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 |
724/B | 724 | B | Python 3 | TESTS | 12 | 62 | 4,915,200 | 21284680 | __author__ = 'Think'
def parse(row):
count=0
problems=[]
for i in range(1, m+1):
if i!=row[i-1]:
count+=1
problems.append((i, row[i-1]))
if count==0:
return [0]
elif count==2:
return [2, problems[0][0], problems[0][1]]
elif count==3:
return [3, sorted((problems[0][0], problems[1][0])), sorted((probl... | 86 | 61 | 0 | 148662320 | n,m=map(int,input().split())
l=[]
for i in range(n):
l+=[list(map(int,input().split()))]
for i in range(m):
for j in range(i,m):
t=0
k=[_+1 for _ in range(m)]
k[i],k[j]=k[j],k[i]
for ii in range(n):
o=0
for jj in range(m):
if l[ii][jj]!=k[j... | 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 |
637/D | 637 | D | PyPy 3 | TESTS | 16 | 780 | 43,622,400 | 32695589 | f = lambda: map(int, input().split())
n, m, s, d = f()
a, b = [], []
x, z = -1, 1
for y in sorted(f()):
if y - x > s + 1:
a += [x - z + 2]
b += [y - x - 2]
z = y
x = y
a += [x - z + 2]
b += [m - x - 1]
if max(a) > d: print('IMPOSSIBLE')
else:
for u, v in zip(a, b):
if u: prin... | 98 | 670 | 35,328,000 | 20451694 | n, m, s, d=map(int, input().split())
x = sorted(map(int, input().split())) + [m + s + 1]
cur = l = 0
ans = []
while l < m:
r = min(x[cur] - 1, m)
ans += ['RUN ' + str(r - l)]
if r == m: break
if r - l < s: ans = ['IMPOSSIBLE']; break
t = x[cur] + 1
while x[cur + 1] - 1 - t < s: cur += 1; t = x[c... | VK Cup 2016 - Qualification Round 1 | CF | 2,016 | 2 | 256 | Running with Obstacles | A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a lengt... | The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a se... | If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
- print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run fo... | null | null | [{"input": "3 10 1 3\n3 4 7", "output": "RUN 2\nJUMP 3\nRUN 1\nJUMP 2\nRUN 2"}, {"input": "2 9 2 3\n6 4", "output": "IMPOSSIBLE"}] | 1,600 | ["*special", "data structures", "dp", "greedy"] | 98 | [{"input": "3 10 1 3\r\n3 4 7\r\n", "output": "RUN 2\r\nJUMP 3\r\nRUN 1\r\nJUMP 2\r\nRUN 2\r\n"}, {"input": "2 9 2 3\r\n6 4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 100 2 8\r\n93 35 24 87 39 46 86 37 73 33\r\n", "output": "RUN 23\r\nJUMP 2\r\nRUN 7\r\nJUMP 8\r\nRUN 5\r\nJUMP 2\r\nRUN 25\r\nJUMP 2\r\nRUN 11\r\nJ... | false | stdio | null | true |
979/B | 979 | B | PyPy 3 | TESTS | 86 | 217 | 3,174,400 | 91282490 | n=int(input())
se=[]
def fun(kuro):
global se
le=len(kuro)
dic={}
for i in kuro:
if( i in dic):
dic[i]+=1
else:
dic[i]=1
ma=max(list(dic.values()))
rest=le-ma
if(rest>=n):
a1=ma+n
else:
a1=ma+rest-(n%2)
se.append(a1)
for i in ra... | 184 | 108 | 7,680,000 | 38229042 | s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
n = int(input())
a = input()
b = input()
c = input()
m = len(a)
x = max(map(lambda r: a.count(r), s))
y = max(map(lambda r: b.count(r), s))
z = max(map(lambda r: c.count(r), s))
if n == 1:
if x == m: x -= 1
else: x += 1
if y == m: y -= 1
els... | 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 |
446/A | 446 | A | Python 3 | TESTS | 45 | 467 | 13,414,400 | 94972350 | n=int(input())
s=input()
s1=s.split()
l=[int(i) for i in s1]
dp1=[1 for i in range(len(l))]
for i in range(1,len(l)):
if l[i]>l[i-1]:
dp1[i]=dp1[i-1]+1
dp2=[1 for i in range(len(l))]
for i in range(len(l)-2,-1,-1):
if l[i]<l[i+1]:
dp2[i]=dp2[i+1]+1
maxlen=1
for i in range(0,len(l)):
... | 92 | 124 | 18,636,800 | 193129019 | n=int(input())
a=list(map(int,input().split()))
# a=[int(i/min(a)*10) for i in a]
# print(*a)
if n<=2:
print(n)
exit()
ends=[1]
for i in range(1,n):
if a[i]>a[i-1]:
ends.append(ends[i-1]+1)
else:
ends.append(1)
starts=[1]
for i in range(n-2,-1,-1):
if a[i]<a[i+1]:
starts.app... | Codeforces Round #FF (Div. 1) | CF | 2,014 | 1 | 256 | DZY Loves Sequences | DZY has a sequence a, consisting of n integers.
We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one numb... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | null | You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4. | [{"input": "6\n7 2 3 1 5 6", "output": "5"}] | 1,600 | ["dp", "implementation", "two pointers"] | 92 | [{"input": "6\r\n7 2 3 1 5 6\r\n", "output": "5\r\n"}, {"input": "10\r\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422\r\n", "output": "9\r\n"}, {"input": "50\r\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202... | false | stdio | null | true |
637/D | 637 | D | Python 3 | TESTS | 3 | 46 | 4,812,800 | 16941032 | def solve(a, s, d, m):
n = 0
l = []
r = []
i = 0
for j in a:
l += [i]
r += [j]
n += 1
i = j
l += [i]
r += [m + 1]
n += 1
u = []
for i in range(n):
x = r[i] - l[i] - 2
if (i == 0) or (i == n - 1):
x += 1
x = max(0, x)
u += [x]
if u[0] < s:
print("IMPOSSIBLE")
return
x = 0
z = 0
w = [... | 98 | 686 | 21,196,800 | 16705651 | import sys
def solve():
n, m, s, d = [int(x) for x in input().split()]
obstacles = [int(x) for x in input().split()]
obstacles.sort()
if obstacles[0] <= s: return False
pieces = [[obstacles[0], obstacles[0]]]
for x in obstacles:
if pieces[-1][1] + s + 2 > x:
pieces[-1][1] = ... | VK Cup 2016 - Qualification Round 1 | CF | 2,016 | 2 | 256 | Running with Obstacles | A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a lengt... | The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a se... | If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
- print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run fo... | null | null | [{"input": "3 10 1 3\n3 4 7", "output": "RUN 2\nJUMP 3\nRUN 1\nJUMP 2\nRUN 2"}, {"input": "2 9 2 3\n6 4", "output": "IMPOSSIBLE"}] | 1,600 | ["*special", "data structures", "dp", "greedy"] | 98 | [{"input": "3 10 1 3\r\n3 4 7\r\n", "output": "RUN 2\r\nJUMP 3\r\nRUN 1\r\nJUMP 2\r\nRUN 2\r\n"}, {"input": "2 9 2 3\r\n6 4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 100 2 8\r\n93 35 24 87 39 46 86 37 73 33\r\n", "output": "RUN 23\r\nJUMP 2\r\nRUN 7\r\nJUMP 8\r\nRUN 5\r\nJUMP 2\r\nRUN 25\r\nJUMP 2\r\nRUN 11\r\nJ... | false | stdio | null | true |
724/B | 724 | B | PyPy 3 | TESTS | 13 | 140 | 1,740,800 | 63931130 | n, m = map(int, input().split())
a = [input().split() for _ in range(n)]
for l in range(m - 1):
for r in range(l, m):
for s in a:
s1 = s.copy()
s1[l], s1[r] = s1[r], s1[l]
if sum(int(s1[i]) != i + 1 for i in range(m)) > 2:
break
else:
p... | 86 | 62 | 4,608,000 | 21282972 | import sys
n, m = map(int,input().split())
g = [list(map(int,input().split())) for _ in range(n)]
for c1 in range(m):
for c2 in range(c1, m):
ok = True
for row in g:
row[c1], row[c2] = row[c2], row[c1]
cnt = 0
for i in range(m):
if row[i] != 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 |
637/D | 637 | D | Python 3 | PRETESTS | 3 | 46 | 307,200 | 16700302 | import sys
# Ввод
n, m, s, d = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
# Максимальное рассятоние для разбега из позиции pos
# до препятсвия letIndex
def getRunLen(pos, letIndex):
if letIndex == len(a):
return m-pos
return a[letIndex] - pos - 1
# Получение длины препятсвия... | 98 | 732 | 39,424,000 | 16694961 | n, m, s, d = [int(x) for x in input().split()]
a_raw = sorted([int(x) for x in input().split()], reverse=True)
a = []
def process_obstacle(crd):
# print('processing %d'%crd)
if a:
segment = a.pop()
# distance you can actually run between obstacles:
# you start at position (segment[1]+1)
... | VK Cup 2016 - Qualification Round 1 | CF | 2,016 | 2 | 256 | Running with Obstacles | A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a lengt... | The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a se... | If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
- print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run fo... | null | null | [{"input": "3 10 1 3\n3 4 7", "output": "RUN 2\nJUMP 3\nRUN 1\nJUMP 2\nRUN 2"}, {"input": "2 9 2 3\n6 4", "output": "IMPOSSIBLE"}] | 1,600 | ["*special", "data structures", "dp", "greedy"] | 98 | [{"input": "3 10 1 3\r\n3 4 7\r\n", "output": "RUN 2\r\nJUMP 3\r\nRUN 1\r\nJUMP 2\r\nRUN 2\r\n"}, {"input": "2 9 2 3\r\n6 4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 100 2 8\r\n93 35 24 87 39 46 86 37 73 33\r\n", "output": "RUN 23\r\nJUMP 2\r\nRUN 7\r\nJUMP 8\r\nRUN 5\r\nJUMP 2\r\nRUN 25\r\nJUMP 2\r\nRUN 11\r\nJ... | false | stdio | null | true |
757/B | 757 | B | Python 3 | TESTS | 70 | 296 | 11,980,800 | 23902352 | def function1(n,s):
if n==1:
return 1
pokemonj=0
pokecage=[0 for i in range(100001)]
for i in range(n):
pokecage[s[i]]+=1
maxyincage=pokecage[1]
a = [i for i in range(100001)]
a[1] = 0
i = 2
while i <= 100000:
if a[i] != 0:
pokemonj=0
... | 134 | 93 | 13,516,800 | 176477161 | """ Prositka
16.10.2022"""
a=int(input())
s=list(map(int,input().split()))
q=[0]*100001
max=1
for i in s:
q[i] += 1
for i in range(2,100001):
res = 0
for j in range(i,100001,i):
res += q[j]
if res > max :
max = res
print (max) | 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 |
714/B | 714 | B | Python 3 | TESTS | 22 | 139 | 7,475,200 | 61342871 | input()
arr = input().split(" ")
count = 0
diff = 0
arr.sort()
for i in range(len(arr)-1):
if(arr[i]!=arr[i+1]):
count += 1
if (diff==0):
diff = int(arr[i+1]) - int(arr[i])
elif(diff != (int(arr[i+1]) - int(arr[i]))):
count = 3
break;
if(count>2):
print("NO")
else:
print("YES") | 79 | 62 | 8,192,000 | 186970801 | # for i in range(5005):
# count[i]=0
# for i in range(n):
# count[arr[i]]=count.get(arr[i], 0) + 1
n=int(input())
set1=set()
[set1.add(x) for x in input().split()]
# print(set1)
if len(set1)==1 or len(set1)==2:
print("YES")
exit()
arr=[]
if len(set1)==3:
for i in set1:
arr.append(int(i))
arr.sort()
# pri... | 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 | Python 3 | TESTS | 22 | 108 | 8,499,200 | 20682039 | def middle(list1):
for i in range(len(list1)):
if list1[i] != list1[0] and list1[i] != list1[len(list1)-1]:
return int(list1[i])
n=input()
list1 = (input().split())
list1.sort()
list2 = set(list1)
if len(list2) < 3:
print("YES")
elif len(list2) < 4:
if abs(int(list1[0])-middle(list1)... | 79 | 62 | 9,011,200 | 185453024 | n = int(input())
arr = set(map(int, input().split()))
n = len(arr)
if n > 3:
print('NO')
else:
if n == 3:
arr = sorted(arr)
if arr[1] - arr[0] == arr[-1]-arr[1]:
print('YES')
else:
print('NO')
else:
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 |
714/B | 714 | B | Python 3 | TESTS | 22 | 202 | 8,089,600 | 94259532 | n = int(input())
l = input().split()
s = set()
for i in l:
s.add(i)
l = list(s)
l.sort()
qtd = len(l)
s = []
for x in l:
s.append(int(x))
if(qtd == 3):
aux = (s[2] - s[0])//2
if(qtd==1 or qtd == 2 or qtd==3 and s[1] - s[0] == s[2] - s[1]):
print("YES")
else:
print("NO") | 79 | 62 | 9,113,600 | 197796499 | a=sorted({*map(int,[*open(0)][1].split())})
print('YNEOS'[len(a)==3 and a[1]-a[0]!=a[2]-a[1] or len(a)>3::2]) | 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 |
147/A | 147 | A | Python 3 | TESTS | 7 | 62 | 0 | 206085473 | a=[".",",","!","?"]
b=input().split()
for i in range(len(b)):
for j in range(len(b[i])):
if b[i][j] not in a:
print(b[i][j],end="")
else:
print(b[i][j],end=" ")
if i==len(b)-1:
print(end="")
break;
if b[i+1][0] in a:
print(end="")
else:
... | 85 | 92 | 0 | 145595112 | s = input()
res = []
punctuation = [',', '.', '!', '?']
for i in range(len(s)):
if i >= 1:
if s[i] == ' ':
if res[-1] != ' ':
res.append(s[i])
else:
continue
else:
if s[i] in punctuation:
if res[-1] == ' ':
... | 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 |
147/A | 147 | A | Python 3 | TESTS | 7 | 122 | 0 | 22708610 | string = input().split()
while '' in string:
string.remove('')
while ' ' in string:
string.remove(' ')
answer = ' '.join(string)
answer = answer.replace(',',', ')
answer = answer.replace('.','. ')
answer = answer.replace('!','! ')
answer = answer.replace('?','? ')
answer = answer.replace(' ,',',')
answer = answer.r... | 85 | 92 | 0 | 163464623 | def check_bit(number,bit_index):
return number | (1<<bit_index-1)==number
def update_bit(number,i,is_bit=True):
value = 1 if is_bit else 0
mask = ~(1<<i)
return (number & mask) | (value<<i)
def main():
str1 = input()
str2 = []
i = 0
pun = ['?',',','.','!']
while i<len(str1):
... | 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 |
757/B | 757 | B | PyPy 3 | TESTS | 70 | 405 | 10,137,600 | 59112936 | #391_B
n = int(input())
ln = sorted([int(i) for i in input().split(" ")])
dct = [0] * (10 ** 5 + 2)
for i in ln:
dct[i] += 1
for j in range(2, int(i ** 0.5) + 1):
if i % j == 0:
if j == i // j:
dct[j] += 1
else:
dct[j] += 1
dct[... | 134 | 124 | 12,185,600 | 24286726 | def function1(n,s):
if n==1:
return 1
sn=max(s)
pokecage=[0]*(sn+1)
for i in range(n):
pokecage[s[i]]+=1
maxyincage=min(pokecage[1],1)
a=[True]*100001
a[2*2::2]=[False]*len(a[2*2::2])
y=(3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, ... | 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 |
147/A | 147 | A | PyPy 3 | TESTS | 7 | 186 | 0 | 223649250 | s = input()
output = ""
num_spaces = 0
for char in s:
if(char in " "):
if(num_spaces == 0):
num_spaces = 1
output += char
else:
num_spaces = 0
output += char
if(char in ".,!?"):
if(output[-2] == ' '):
output = output[:-2] + output[-1]
output += " "
output = output.strip()
print(output)
# s_list = ... | 85 | 92 | 0 | 172440609 | s = input()
t = ',.?!'
for i in t : s = s.replace(i, i + ' ')
s = ' '.join(s.strip().split())
for i in t : s = s.replace(' ' + i, i)
print(s) | 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 |
147/A | 147 | A | Python 3 | TESTS | 7 | 154 | 5,632,000 | 35797370 | a=input()
for i in range(len(a)-1):
if a[i] in ('!','?',',','.') and not(a[i+1] in ('!','?',',','.')):
print(a[i],end=' ')
elif not(a[i]==' ' and (a[i+1] in ('!','?',',','.') or a[i+1]==' ')):
print(a[i],end='')
print(a[len(a)-1]) | 85 | 92 | 0 | 189665541 | s= input()#Abir . kumar . raj
a = ",.?!"
for i in a:
s = s.replace(i,i+" ")#Abir . kumar . raj
s = ' '.join(s.split()) #Abir . kumar . raj
for i in a:
s = s.replace(" "+i,i) #Abir. kumar. raj
print(s) | 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 |
147/A | 147 | A | Python 3 | TESTS | 7 | 154 | 6,963,200 | 129523765 | def rem_pon(init_str, pon):
layer = pon.join(init_str.split(' '+pon))
res = (pon+' ').join(layer.split(pon))
return res
one = ' '.join(input().split())
res = one
res = ' '.join(res.split())
for p in ('.', ',', '?' , '!'):
if p in res :
res = rem_pon(res, p)
print(res) | 85 | 122 | 819,200 | 138940004 | s=input()
r=''
com=False
for i in range(len(s)):
if (i==0) and (s[i]==',' or s[i]==' '):
continue
if s[i]==' 'and s[i+1]==' ':
continue
if s[i]==' 'and (s[i+1]==',' or s[i+1]=='.' or s[i+1]=='!' or s[i+1]=='?' or s[i+1]==';'):
continue
if s[i]==',' or s[i]=='.' or s[i]=='?' or s[i]=='!':
r=r+s[i... | 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 |
757/B | 757 | B | Python 3 | TESTS | 70 | 733 | 13,107,200 | 24018711 | from collections import Counter
n, ss = int(input()), map(int, input().split())
counts = Counter(ss)
sieve = [counts[i] for i in range(max(counts)+1)]
for i in range(2, len(sieve)):
for j in range(2*i, len(sieve), i):
sieve[i] += sieve[j]
print(max(sieve)) | 134 | 124 | 16,384,000 | 229098527 | # Version 21.0
import os, sys, math, itertools
from collections import deque, defaultdict, OrderedDict, Counter
from bisect import bisect, bisect_left, bisect_right, insort
from heapq import heapify, heappush, heappop, nsmallest, nlargest, heapreplace, heappushpop
offline = __debug__
if not offline:
import io
... | 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 |
757/B | 757 | B | Python 3 | TESTS | 70 | 483 | 6,860,800 | 39086225 | n = int(input())
arr = [int(x) for x in input().split()]
t = max(arr) +2
k = [0] * t
for x in arr: k[x]+=1
for j in range(2, t) :
for i in range(2*j, t, j):
k[j] += k[i]
print(max(k)) | 134 | 155 | 9,113,600 | 197497703 | n = int(input())
a = map(int, input().split())
ans = 1
c = [0] * 100100
for i in a:
c[i] += 1
for i in range(2, 100100):
ans = max(ans, sum(c[i::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 |
757/B | 757 | B | PyPy 3-64 | TESTS | 70 | 389 | 13,721,600 | 211025682 | import math
def gcd(a, b):
while b:
a, b = b, a % b
return a
def max_pokemon_count(n, strengths):
prime_factors = [0] * (max(strengths) + 1)
for strength in strengths:
factors = set()
for i in range(2, int(math.sqrt(strength)) + 1):
if strength % i == 0:
... | 134 | 156 | 12,902,400 | 208610990 | def solve(s):
valueToCount = {}
for value in s:
valueToCount[value] = valueToCount.get(value, 0) + 1
result = 1
max_value = max(s)
primes = [True] * (max_value + 1)
for i in range(2, len(primes)):
size = 0
if primes[i]:
for j in range(i, len(primes), i):
... | 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 |
637/D | 637 | D | Python 3 | PRETESTS | 3 | 46 | 307,200 | 16710537 | n,m,s,d=(int(z) for z in input().split())
x=[int(z) for z in input().split()]
x.sort()
x.append(m+1)
def g(n,s,m,d,x):
if x[0]<=s:
return[0,[]]
else:
hran=[0]
flag1=0
flag2=0
flag=x[flag1]
q=len(x)
while flag1<q-1:
while flag2<q-1 and x[flag2]... | 98 | 842 | 32,153,600 | 16718255 | n,m,s,d=map(int,input().split())
x=sorted(map(int,input().split()))+[m+s+1]
cur=l=0
ans=[]
while l<m:
r=min(x[cur]-1,m)
ans+=['RUN '+str(r-l)]
if r==m: break
if r-l<s: ans=['IMPOSSIBLE']; break
t=x[cur]+1
while x[cur+1]-1-t<s: cur+=1; t=x[cur]+1
if t-r>d: ans=['IMPOSSIBLE']; break
ans+=[... | VK Cup 2016 - Qualification Round 1 | CF | 2,016 | 2 | 256 | Running with Obstacles | A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a lengt... | The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a se... | If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
- print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run fo... | null | null | [{"input": "3 10 1 3\n3 4 7", "output": "RUN 2\nJUMP 3\nRUN 1\nJUMP 2\nRUN 2"}, {"input": "2 9 2 3\n6 4", "output": "IMPOSSIBLE"}] | 1,600 | ["*special", "data structures", "dp", "greedy"] | 98 | [{"input": "3 10 1 3\r\n3 4 7\r\n", "output": "RUN 2\r\nJUMP 3\r\nRUN 1\r\nJUMP 2\r\nRUN 2\r\n"}, {"input": "2 9 2 3\r\n6 4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 100 2 8\r\n93 35 24 87 39 46 86 37 73 33\r\n", "output": "RUN 23\r\nJUMP 2\r\nRUN 7\r\nJUMP 8\r\nRUN 5\r\nJUMP 2\r\nRUN 25\r\nJUMP 2\r\nRUN 11\r\nJ... | false | stdio | null | true |
757/B | 757 | B | PyPy 3-64 | TESTS | 70 | 748 | 12,800,000 | 214645520 | import math
n=int(input())
a=[]
c=[0]*100000
a=list(map(int,input().split()))
for i in range(n):
for j in range(2,int(math.sqrt(a[i]))+1):
if a[i]%j==0:
c[j]+=1
while a[i]%j==0:
a[i]//=j
c[a[i]]+=1
print(max(c)) | 134 | 171 | 14,438,400 | 177108381 | import math
N = 10**5+50
spf = [-1]*(N+1)
for i in range(N+1):
spf[i] = i
for i in range(2, int(math.sqrt(N))+1):
if spf[i] == i:
for j in range(i*2, N+1, i):
if spf[j] == j:
spf[j] = i
def factorize(n):
d = {}
while n != 1:
p = spf[n]
if p in 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 |
793/A | 793 | A | Python 3 | TESTS | 46 | 156 | 8,806,400 | 169220369 | n, m = map(int, input(). split())
a = list(map(int, input(). split()))
mn = min(a)
ans = 0
for i in range(n):
q = a[i] - mn
w = q // m
if w * m + mn == a[i]:
ans += w
else:
ans = -1
print(ans) | 88 | 77 | 13,414,400 | 228406107 | def solve():
n, k = map(int, input().split())
numbers = tuple(map(int, input().split()))
minimum = min(numbers)
result = 0
for number in numbers:
if not ((number - minimum) % k):
result += (number - minimum) // k
else:
print(-1)
r... | 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 |
147/A | 147 | A | Python 3 | TESTS | 24 | 218 | 307,200 | 91016425 | s = input()
res = []
res.append(s[0])
for i in range(1, len(s)-1):
if s[i] == ' ' and res[-1] == ' ':
continue
elif s[i] in ",.!?" and res[-1] == ' ':
res[-1] = s[i]
if s[i+1] != ' ':
res.append(' ')
elif s[i] in ",.!?" and s[i+1] != ' ':
res.append(s[i]+' ')
... | 85 | 124 | 0 | 164645771 | import sys
input = sys.stdin.readline
s = input()[:-1].replace(',',' , ').replace('.', ' . ').replace('!',' ! ').replace('?',' ? ')
w = ' '.join(s.split())
w = w.replace(' ,',',').replace(' .','.').replace(' !','!').replace(' ?','?')
print(w) | 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 |
724/B | 724 | B | Python 3 | TESTS | 55 | 77 | 4,915,200 | 21296088 | #!/usr/bin/env python3
from sys import stdin
def main():
n, m = stdin_get_ints_from_line()
x = []
y = [0] * m
max_changes = 0
for i in range(n):
line = stdin_get_ints_list_from_line()
changes = get_changes(list(line))
if changes > 2:
return 'NO'
if ... | 86 | 62 | 4,608,000 | 21319748 | n, m = map(int,input().split())
g = [list(map(int,input().split())) for _ in range(n)]
for c1 in range(m):
for c2 in range(c1, m):
ok = True
for row in g:
row[c1], row[c2] = row[c2], row[c1]
cnt = 0
for i in range(m):
if row[i] != 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 |
61/C | 61 | C | Python 3 | TESTS | 54 | 62 | 0 | 128176931 | def op2(num, bs):
di2 = {10: "A", 11: "B", 12: "C", 13: "D", 14: "E", 15: "F", 16: "G", 17: "H", 18: "I", 19: "J", 20: "K", 21: "L",
22: "M", 23: "N", 24: "O"}
arr = ""
while num > 0:
temp = num % bs
if temp > 9:
temp = di2[temp]
arr = arr + str(temp)
n... | 70 | 46 | 0 | 137851973 | a, b = input().strip().split(' ')
c = input()
a = int(a)
def conv(num,b):
convStr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if num < b:
return convStr[num]
else:
return conv(num//b,b) + convStr[num % b]
def write_roman(num):
val = [
1000, 900, 500, 400,
100, ... | Codeforces Beta Round 57 (Div. 2) | CF | 2,011 | 2 | 256 | Capture Valerian | It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.
Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captu... | The first line contains two integers a and b (2 ≤ a, b ≤ 25). Only b may be replaced by an R which indicates Roman numbering system.
The next line contains a single non-negative integer c in base a which may contain leading zeros but its length doesn't exceed 103.
It is guaranteed that if we have Roman numerals inclu... | Write a single line that contains integer c in base b. You must omit leading zeros. | null | You can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals | [{"input": "10 2\n1", "output": "1"}, {"input": "16 R\n5", "output": "V"}, {"input": "5 R\n4", "output": "IV"}, {"input": "2 2\n1111001", "output": "1111001"}, {"input": "12 13\nA", "output": "A"}] | 2,000 | ["math"] | 70 | [{"input": "10 2\r\n1\r\n", "output": "1\r\n"}, {"input": "16 R\r\n5\r\n", "output": "V\r\n"}, {"input": "5 R\r\n4\r\n", "output": "IV\r\n"}, {"input": "2 2\r\n1111001\r\n", "output": "1111001\r\n"}, {"input": "12 13\r\nA\r\n", "output": "A\r\n"}, {"input": "6 7\r\n12345\r\n", "output": "5303\r\n"}, {"input": "25 12\r\... | false | stdio | null | true |
757/B | 757 | B | Python 3 | TESTS | 53 | 1,544 | 11,878,400 | 23829097 | 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 | 217 | 12,185,600 | 23795793 | def main():
n = input()
L = [int(x) for x in input().split()]
print(solver(L))
def solver(L):
n = max(L)
nums = [0] * (n + 1)
for x in L:
nums[x] += 1
highestCount = 1
for i in range(2, n + 1):
count = sum(nums[i:n+1:i])
highestCount = max(highestCount, count)
return highestCount
#for j in range(i, n ... | 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 |
714/B | 714 | B | Python 3 | TESTS | 22 | 108 | 13,414,400 | 157342778 | n = int(input())
a = [int(i) for i in input().split(" ")]
a.sort()
average = sum(a) / n
median = []
median.append(a[len(a) // 2])
if len(a) % 2 == 0:
median.append(a[(len(a) // 2) - 1])
values = [average]
for value in median:
values.append(value)
equal_distance = True
for value in values:
equal_distance =... | 79 | 77 | 8,192,000 | 20680605 | n = int(input())
a = input().split()
b = list(set(a))
if len(b) > 3:
print("NO")
elif len(b) < 3:
print("YES")
else:
if (abs(int(b[0]) - int(b[1])) == abs(int(b[1]) - int(b[2]))) | (abs(int(b[2]) - int(b[1])) == abs(int(b[0]) - int(b[2]))) | (abs(int(b[0]) - int(b[1])) == abs(int(b[0]) - int(b[2]))):
... | 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 | Python 3 | TESTS | 22 | 155 | 9,830,400 | 94806997 | n = int(input())
li = list(map(int,input().split()))[:n]
if n<=2:
print("YES")
else:
li.sort()
half = len(li) // 2
mid = li[half]
flag1 = 0
flag2 = 0
choto = mid
for i in range(half, -1, -1):
if mid > li[i]:
choto = li[i]
break
diff = mid - choto
... | 79 | 77 | 8,806,400 | 189248642 | n=int(input())
arr=list(map(int,input().split()))
if len(set(arr)) in [1,2]:
print("YES")
elif len(set(arr))>3:
print("NO")
elif len(set(set(arr)))==3:
s=list(set(arr))
s=sorted(s)
if s[0]+s[2]==2*s[1]:
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 |
147/A | 147 | A | PyPy 3 | TESTS | 10 | 216 | 20,172,800 | 123746171 | #!/usr/bin/python3
input_text = input()
puncs = ['.','!',',', '?']
for punc in puncs:
input_text = input_text.replace(punc,f"{punc} ")
input_text = input_text.replace(" "," ")
input_text = input_text.replace(f" {punc}",punc)
print(input_text.replace(" "," ")) | 85 | 124 | 102,400 | 179138096 | # LUOGU_RID: 92736227
t = input().rstrip()
d, q = {}, []
for i in range(97, 123):
d[chr(i)] = 1
d['.'] = d[','] = d['!'] = d['?'] = 0
d[' '] = -1
tf = 1
for x in t:
f = d[x]
if tf == 1:
q.append(x)
tf = f
elif tf == 0:
q.append(' ')
if f == 1:
q.append(x)
... | 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 |
762/C | 762 | C | Python 3 | TESTS | 10 | 124 | 5,529,600 | 28194735 | a=input()
b=input()
pre=[len(a) for i in range(len(b))]
suf=[-1 for i in range(len(b))]
temp=0
for i in range(len(a)):
if b[temp]==a[i]:
pre[temp]=i
temp+=1
if temp==len(b):
break
temp=len(b)-1
for i in range(len(a)-1,-1,-1):
if b[temp]==a[i]:
suf[temp]=i
temp... | 99 | 93 | 8,089,600 | 230897513 | a, b = input(), input()
n = len(b)
def f(a, b):
i, t = 0, [0]
for q in a:
if i < n and q == b[i]: i += 1
t.append(i)
return t
u, v = f(a, b), f(a[::-1], b[::-1])[::-1]
t = [x + y for x, y in zip(u, v)]
i = t.index(max(t))
x, y = u[i], v[i]
s = b[:x] + b[max(x, n - y):]
print(s if s else '-') | 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 |
858/B | 858 | B | Python 3 | TESTS | 22 | 62 | 0 | 113672324 | I,l,r=lambda:map(int,input().split()),{},set(range(1,101))
n,m=I()
for i in range(m):q,w=I();l[q]=w
if l:
for j in l:
k=[]
for i in range(1,n+1):
if (j+i-1)//i==l[j]:k+=[(n+i-1)//i]
r&=set(k)
if n==1:print(1)
elif n in l:print(l[n])
else:print(-1if len(r)!=1else list(r)[0]) | 101 | 62 | 0 | 31213364 | n, m = map(int, input().split())
a = [tuple(map(int, input().split())) for i in range(m)]
ans = set()
for i in range(1, 101):
can = True
for k, f in a:
if (k + i - 1) // i != f:
can = False
break
if can:
ans.add((n + i - 1) // i)
if len(ans) == 1:
print(ans.pop())... | Технокубок 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 |
446/A | 446 | A | PyPy 3 | TESTS | 38 | 264 | 13,721,600 | 61094334 | n = int(input())
a = list(map(int, input().split()))
b = []
b.append(1)
for i in range(1, len(a)):
if a[i] > a[i - 1]:
b.append(b[i - 1] + 1)
else:
b.append(1)
for i in range(len(a) - 2, -1, -1):
if a[i] < a[i + 1]:
b[i] = b[i + 1]
ans = max(b) + 1
for i in range(len(a) - 2):
... | 92 | 139 | 18,022,400 | 211154193 | import sys,random,bisect
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush
import math
from types import GeneratorType
#from functools import cache 3.9
mod = int(1e9 + 7) #998244353
inf = int(1e20)
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().sp... | Codeforces Round #FF (Div. 1) | CF | 2,014 | 1 | 256 | DZY Loves Sequences | DZY has a sequence a, consisting of n integers.
We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one numb... | The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | null | You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4. | [{"input": "6\n7 2 3 1 5 6", "output": "5"}] | 1,600 | ["dp", "implementation", "two pointers"] | 92 | [{"input": "6\r\n7 2 3 1 5 6\r\n", "output": "5\r\n"}, {"input": "10\r\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422\r\n", "output": "9\r\n"}, {"input": "50\r\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202... | false | stdio | null | true |
724/B | 724 | B | Python 3 | TESTS | 28 | 46 | 102,400 | 174242001 | #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
def main():
n, m = map(int, input().split())
grid = []
for _ in range(n):
row = list(map(int, input().split()))
grid.append(row)
# two cycles of length 2
# one cycle of le... | 86 | 62 | 4,608,000 | 21341850 | import sys
n, m = map(int,input().split())
g = [list(map(int,input().split())) for _ in range(n)]
for c1 in range(m):
for c2 in range(c1, m):
ok = True
for row in g:
row[c1], row[c2] = row[c2], row[c1]
cnt = 0
for i in range(m):
if row[... | 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 |
629/D | 629 | D | PyPy 3 | TESTS | 5 | 795 | 25,088,000 | 32416743 | def add(i, q):
while i < len(d):
d[i] = max(d[i], q)
i += i & -i
def get(i):
q = 0
while i > 0:
q = max(d[i], q)
i -= i & -i
return q
from sys import *
t = list(map(int, stdin.read().split()))
p = [t[i] * t[i] * t[i + 1] for i in range(1, len(t), 2)]
k = {v: j for j, v in... | 111 | 1,185 | 31,948,800 | 18101531 | from math import *
from bisect import *
def update(bit, size, idx, amount):
while idx <= size:
if bit[idx] < amount:
bit[idx] = amount
idx += idx & -idx
def read(bit, idx):
rst = 0
while idx >= 1:
if bit[idx] > rst:
rst = bit[idx]
idx -= idx & -idx
... | Codeforces Round 343 (Div. 2) | CF | 2,016 | 2 | 256 | Babaei and Birthday Cake | As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special ca... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake. | Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac{|a-b|}{\max(1,b)} \l... | null | In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4. | [{"input": "2\n100 30\n40 10", "output": "942477.796077000"}, {"input": "4\n1 1\n9 7\n1 4\n10 7", "output": "3983.539484752"}] | 2,000 | ["data structures", "dp"] | 111 | [{"input": "2\r\n100 30\r\n40 10\r\n", "output": "942477.796077000\r\n"}, {"input": "4\r\n1 1\r\n9 7\r\n1 4\r\n10 7\r\n", "output": "3983.539484752\r\n"}, {"input": "3\r\n2 2\r\n1 1\r\n3 3\r\n", "output": "109.955742876\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "109.955742876\r\n"}, {"input": "3\r\n3 3\r... | false | stdio | import sys
from decimal import Decimal, getcontext
def main():
input_path, output_path, submission_output_path = sys.argv[1:4]
getcontext().prec = 20 # High precision to avoid parsing issues
# Read correct output
try:
with open(output_path, 'r') as f:
correct_line = f.readline().... | true |
489/B | 489 | B | Python 3 | TESTS | 36 | 61 | 0 | 200033159 | # ELO 1200
import sys
def check_skills(skill1, skill2, pairs, pair_index):
if pair_index not in pairs and skill1 in (skill2, skill2 - 1, skill2 + 1):
return True
return False
input_file = sys.stdin.read(-1).replace("\r\n", "\r")
input_file = input_file.split()
num_boys = int(input_file[0])
boy_skil... | 81 | 46 | 0 | 193504136 | def main():
num_boys = int(input())
boys_skill = list(map(int, input().split()))
num_girls = int(input())
girls_skill = list(map(int, input().split()))
boys_skill.sort()
girls_skill.sort()
boys_ptr = 0
girls_ptr = 0
num_pairs = 0
while boys_ptr < num_boys and ... | 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 |
147/A | 147 | A | PyPy 3 | TESTS | 15 | 248 | 0 | 41626817 | from sys import stdin
s = ' '.join(stdin.readline().split())
punc = ['.', ',', '!', '?']
ans = ''
for i in range(len(s)):
if s[i] not in punc:
continue
if s[i - 1] == ' ':
s = s[:i - 1] + s[i] + s[i - 1] + s[i + 1:]
elif s[i + 1] != ' ':
s = s[:i + 1] + ' ' + s[i + 1:]
s = ' '.join(s.split())
print(s, end = ''... | 85 | 124 | 409,600 | 143821252 | import re
def run():
out = input()
for i in ",.?!":
out = out.replace(i, f" {i} ")
out = re.sub(r"\s+", " ", out)
for i in ",.?!":
out = out.replace(f" {i} ", i + " ")
print(out)
run() | 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 |
979/B | 979 | B | PyPy 3 | TESTS | 85 | 187 | 3,276,800 | 78011677 | a=int(input())
a1=input()
a2=input()
a3=input()
ans1=[0 for i in range(52)]
ans2=[0 for i in range(52)]
ans3=[0 for i in range(52)]
for i in range(len(a1)):
if(a1[i].islower()):
ans1[ord(a1[i])-97]+=1
else:
ans1[ord(a1[i])-65+26]+=1
for i in range(len(a2)):
if(a2[i].islower()):
ans2... | 184 | 109 | 512,000 | 182416653 | num_inp=lambda: int(input())
arr_inp=lambda: list(map(int,input().split()))
sp_inp=lambda: map(int,input().split())
str_inp=lambda:input()
N = int(input())
n = [0,0,0]
for i in range(3):
z = [0 for i in range(128)]
x = input()
for j in x:
z[ord(j)]+=1
n[i]=min(N+max(z),len(x)-1 if (N==1 and len(x)==max(z)) else... | 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 |
714/B | 714 | B | PyPy 3-64 | TESTS | 18 | 77 | 16,793,600 | 210320795 | n = int(input())
arr = set(map(int, input().split()))
can = False
if len(arr) < 4:
if len(arr) == 3:
arr = list(arr)
d1 = abs(arr[0] - arr[1])
d2 = abs(arr[1] - arr[2])
if d1 == d2 or d1 == 2 * d2:
can = True
else:
can = True
print("YES") if can else print("... | 79 | 77 | 9,011,200 | 143479303 | I=input
I()
s=sorted(set(map(int,I().split())))
t=len(s)
print(['NO','YES'][t<3or(t==3and s[0]+s[2]==s[1]*2)]) | 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 |
724/B | 724 | B | Python 3 | TESTS | 12 | 62 | 4,608,000 | 21285877 | n, m = map(int, input().split())
number = []
ans = 1
commons = set()
for i in range(n):
number.append(list(map(int, input().split())))
s = set()
for j in range(m):
if number[i][j] != j + 1:
for z in range(j + 1, m):
if number[i][z] == j + 1:
s.ad... | 86 | 62 | 4,915,200 | 21286305 | n,m = map(int,input().split())
inp = [input() for _ in range(n) ]
mat = [[] for _ in range(m) ]
for row in inp:
r = row.split()
for idx,val in enumerate(r):
mat[idx].append(int(val))
def valid(row):
count = 0
for idx,col in enumerate(mat):
if (idx + 1) != col[row]:
count += 1
if count > 2:
return Fals... | 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 |
762/C | 762 | C | PyPy 3 | TESTS | 4 | 140 | 0 | 41498942 | a, b = input(), input()
def getprefix(b, a):
cur, i = 0, 0
pb = [10 ** 19] * len(b)
while i < len(b) and cur < len(a):
if b[i] == a[cur]:
pb[i] = cur
i += 1
cur += 1
else:
cur += 1
return pb
prb = getprefix(b, a)
sub = getprefix(b[::-... | 99 | 109 | 6,963,200 | 168750210 | def solve(s1,s2):
n=len(s1)
m=len(s2)
s1=' ' +s1 + ' '
s2=' ' +s2 + ' '
tmp=0
v1=[0]*100005
v2=[0]*100005
for i in range(1,n+1):
if s1[i]==s2[tmp+1]:
tmp+=1
v1[i]=tmp
tmp=m+1
v2[n+1]=tmp
for i in range(n,0,-1):
if s1[i]==s2[tmp-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 |
762/C | 762 | C | PyPy 3 | TESTS | 3 | 140 | 0 | 92900780 | import sys
s = list(map(lambda c: ord(c)-97, input()))
t = list(map(lambda c: ord(c)-97, input()))
n, m = len(s), len(t)
next_c = [[-1]*26 for _ in range(n+1)]
for i in range(n-1, -1, -1):
for j in range(26):
next_c[i][j] = next_c[i+1][j]
next_c[i][s[i]] = i+1
minf = -(10**9)
dp = [[minf, minf, minf... | 99 | 155 | 7,065,600 | 82784984 | from sys import stdin
def main():
t = stdin.readline()
s = stdin.readline()
n = len(s) - 1
m = len(t) - 1
post = [-1] * n
ss = n - 1
st = m - 1
while st >= 0 and ss >= 0:
if t[st] == s[ss]:
post[ss] = st
ss -= 1
st -= 1
pre = [-1] * n
ss ... | 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 |
979/B | 979 | B | Python 3 | TESTS | 85 | 187 | 1,024,000 | 77977543 | n=int(input())
a=input()
b=input()
c=input()
d={}
for i in a:
d[i]=0
for i in a:
d[i]+=1
e=min(len(a),n+max(d.values()))
if len(d)==1:
if n+max(d.values())>len(a):
if (n+max(d.values())-len(a))%2==1:
e=len(a)-1
d={}
for i in b:
d[i]=0
for i in b:
d[i]+=1
f=min(len(b),n+max(d.valu... | 184 | 109 | 4,608,000 | 149806807 | from collections import Counter
n = int(input())
kuro=input()
shir=input()
katie=input()
l=len(kuro)
m1 = list(Counter(kuro).most_common()[0])
if n > l-m1[1]:
if n==1:
m1[1] -=1
else:
m1[1]=l
else:
m1[1] = m1[1]+n
m2 = list(Counter(shir).most_common()[0])
if n > l-m2[1]:
if n==1:
m2[... | 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 |
984/B | 984 | B | Python 3 | TESTS | 30 | 77 | 0 | 146638989 | def vaild(x, y):
return 0 <= x and 0 <= y and x < n and y < m
D = [[0, 1], [1, 0], [-1, 0], [0, -1], [1, 1], [-1, -1], [1, -1], [-1, 1]]
def main():
global n, m
n, m = map(int, input().split())
g = []
ret = 0
cmp = 0
for i in range(n):
g.append(input())
for i in range(n):
... | 84 | 77 | 0 | 157885413 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
g = [list(map(lambda x:int(x) if x != '*' else str(x), input()[:-1].replace('.','0'))) for _ in range(n)]
d = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0), (1, 1)]
def f(a, b):
c = 0
for i, j in d:
if 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 |
147/A | 147 | A | PyPy 3 | TESTS | 58 | 468 | 3,174,400 | 69141200 | import string
lst = list(input().split())
punc = string.punctuation
for i in range(len(lst)):
for j in range(len(lst[i])):
if (j!=len(lst[i])-1):
if (lst[i][j] in punc and lst[i][j+1]!=' '):
lst[i] = lst[i][:j+1]+" "+lst[i][j+1:]
s = ""
for i in lst:
if (s==""):
s += i
elif (i[0] in punc):
s += i
els... | 85 | 124 | 2,252,800 | 167700757 | s = input()
curr = ''
words = []
for c in s:
if c == ' ':
if curr:
words.append(curr)
curr = ''
elif c in [',', '?', '.', '!']:
if curr:
curr += c
words.append(curr)
curr = ''
else:
words[-1]+=c
else:
cur... | 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 |
419/A | 420 | A | Python 3 | TESTS | 52 | 46 | 204,800 | 173254618 | word = input()
if('Q' in word or 'E' in word or ' R' in word or 'P' in word or 'S' in word or 'D' in word or 'F' in word or 'G' in word or 'J' in word or 'K' in word or 'L' in word or 'Z' in word or 'C' in word or 'B' in word or 'N' in word):
print("NO")
elif(word[::-1] == word):
print("YES")
else:
print("N... | 80 | 46 | 0 | 142124201 | s = input()
for q in s:
if q not in "AHIMOTUVWXY":
print("NO")
exit()
print("YES" if s==s[::-1] else "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 | 216661195 | n = int(input())
a = sorted(map(int,input().split()))
m = int(input())
b = sorted(map(int,input().split()))
la = len(a)
lb = len(b)
i=0
j=0
c=0
while i<la and j<lb:
d = a[i]-b[j]
if d>=-1 and d<=1:
c += 1
i += 1
j += 1
continue
pb = j+1
pa = i+1
if pa<la and pb<lb... | 81 | 46 | 0 | 193786862 | n = int(input())
b = sorted(list(map(int, input().split())))
m = int(input())
g = sorted(list(map(int, input().split())))
pair = 0
for boy in b:
for girl in g:
if boy == girl:
pair += 1
g.remove(boy)
break
elif (boy + 1) == girl:
pair += 1
... | 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 | PyPy 3-64 | TESTS | 36 | 62 | 0 | 204493778 | b = int(input())
boys = sorted([int(m) for m in input().split()])
g = int(input())
girls = sorted([int(m) for m in input().split()])
i = j = 0
count = 0
while i < b and j < g:
if abs(boys[i] - girls[j]) <= 1:
count += 1
i += 1
j += 1
continue
if i == b - 1:
j += 1
... | 81 | 46 | 0 | 194159148 | a, a1, b, b1, c, d, n= int(input()), sorted(list(map(int, input().split()))), int(input()), sorted(list(map(int, input().split()))), 0, 0, 0
while c < a and d < b:
if abs(a1[c]-b1[d]) <= 1: n += 1; c += 1; d += 1
else:
if a1[c] < b1[d]: c += 1
else:d += 1
print(n) | 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 |
95/B | 95 | B | PyPy 3 | TESTS | 51 | 374 | 6,144,000 | 58841482 | import math
from collections import defaultdict, Counter
R = lambda: map(int, input().split())
num = [x for x in input()]
n = len(num)
mi, mx = '4' * ((n + 1) // 2) + '7' * ((n + 1) // 2), '7' * ((n + 1) // 2) + '4' * ((n + 1) // 2)
if n % 2:
print(mi)
exit(0)
if ''.join(num) > mx:
print('4' + mi + '7')
... | 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 |
95/B | 95 | B | PyPy 3 | TESTS | 51 | 590 | 6,451,200 | 57351149 | import math
from collections import defaultdict
R = lambda: map(int, input().split())
num = input()
n = len(num)
if n & 1:
print('4' * ((n + 1) // 2) + '7' * ((n + 1) // 2))
exit(0)
else:
mx = '7' * (n // 2) + '4' * (n // 2)
if mx < num:
print('4' * (n // 2 + 1) + '7' * (n // 2 + 1))
ex... | 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 |
489/B | 489 | B | PyPy 3-64 | TESTS | 36 | 108 | 6,041,600 | 223829333 | from collections import deque
from sys import stdin, stdout
input = stdin.readline
INF = 10**18
class MaxFlow:
def __init__(self,N):
self.N = N
self.AL = [[] for i in range(N)]
self.EL = []
return
## Add edge to residual graph
def add_edge(self,u,v,c,directed = True):
... | 81 | 46 | 0 | 194370042 | n=int(input())
boys=list(map(int,input().split()))
m=int(input())
girls=list(map(int,input().split()))
boys.sort()
girls.sort()
i = 0
j = 0
count=0
while i<n and j<m:
if abs(boys[i]-girls[j])<=1:
count+=1
i+=1
j+=1
elif boys[i]<girls[j]:
i+=1
else:
j+=1
print(count) | 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 |
419/A | 420 | A | Python 3 | TESTS | 38 | 78 | 614,400 | 173250538 | name = input()
name = list(name)
# print(name)
can = True
not_mirror = "BCEFGJKLNPQRSZ"
for i in range(len(name)):
found = not_mirror.find(name[i])
if(found != -1):
can = False
print("NO")
break
if(can):
for i in range(len(name)//2):
# print(len(name)-i)
if(name[i] ... | 80 | 46 | 0 | 155530555 | def solve():
s = input()
good_chars = set("AHIMOTUVWXY")
for i in range(len(s) // 2 + 1):
if s[i] not in good_chars or s[i] != s[-1 - i]:
return "NO"
return "YES"
print(solve()) | 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 |
762/C | 762 | C | Python 3 | TESTS | 1 | 109 | 0 | 46240144 | #import sys
#sys.stdin = open('in', 'r')
#n = int(input())
#a = [int(x) for x in input().split()]
#n,m = map(int, input().split())
s1 = input()
s2 = input()
l1 = len(s1)
l2 = len(s2)
dl = {}
dr = {}
i1 = 0
i2 = 0
while i1 < l1 and i2 < l2:
while i1 < l1 and s1[i1] != s2[i2]:
i1 += 1
if i1 < l1:
... | 99 | 171 | 4,300,800 | 92954432 | import sys
s, t = input(), '*'+input()
n, m = len(s), len(t)-1
inf = 10**9
pre, suf = [-1] + [inf]*(m+1), [-1]*(m+1) + [n]
i = 0
for j in range(1, m+1):
while i < n and s[i] != t[j]:
i += 1
if i == n:
break
pre[j] = i
i += 1
i = n-1
for j in range(m, 0, -1):
while 0 <= i and s[i]... | 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 |
984/B | 984 | B | PyPy 3 | TESTS | 5 | 77 | 0 | 184552825 | n,m=map(int, input().split())
a=[]
for i in range(n):
l=input()
l=l.replace('.', '0', m)
a.append(l)
for i in range(n):
for j in range(m):
if a[i][j].isdigit():
ans=0
if j>0:
if a[i][j-1]=='*':
ans+=1
if j<m-1:
... | 84 | 77 | 0 | 185351378 | digits = '12345678'
n, m = map(int, input().split())
array = []
for _ in range(n):
x = list(input())
array.append(x)
flag = True
for i in range(n):
for j in range(m):
if array[i][j] in digits:
num = int(array[i][j])
c = 0
k = 1
if i+k < n:
... | 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 |
714/B | 714 | B | PyPy 3-64 | TESTS | 26 | 77 | 13,107,200 | 215356854 | n=int(input())
parsa=list(map(int,input().split()))
parsa.sort()
p=1
if parsa[0]==0 and parsa[n-1]%2!=0:
a=parsa[n-1]
elif parsa[0]==0 and parsa[n-1]%2==0:
a=int(parsa[n-1]/2)
elif (parsa[n-1]-parsa[0])%2==0:
a=int((parsa[n-1]-parsa[0])/2)
else:
a=int((parsa[n-1]+parsa[0])/2)
parsa[0]+=a
for i in range(... | 79 | 77 | 9,113,600 | 163441871 | n = int(input())
arr = set(map(int,input().split()))
if len(arr)<3:
print('YES')
elif len(arr)==3:
a,b,c = sorted(arr)
if b-a == c-b:
print('YES')
else:
print('NO')
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 |
489/B | 489 | B | Python 3 | TESTS | 26 | 46 | 0 | 205218969 | import sys
a = int(sys.stdin.readline())
t= (list(map(int,sys.stdin.readline().split())))
t.sort()
b = int(sys.stdin.readline())
dfex= (list(map(int, sys.stdin.readline().split())))
dfex.sort()
count = 0
ie = 0
while(len(t) != 0 and len(dfex) != 0):
if abs (t[0] - dfex[0])>1:
if t[0]> dfex[0]:
... | 81 | 46 | 0 | 194706784 | import heapq
n_boys = int(input())
boys = list(map(int, input().split()))
b_girls = int(input())
girls = list(map(int, input().split()))
boys = [-1*i for i in boys]
girls = [-1*i for i in girls]
heapq.heapify(boys)
heapq.heapify(girls)
ans = 0
while boys and girls:
diff = abs(boys[0] - girls[0])
if diff <... | 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 |
984/B | 984 | B | Python 3 | TESTS | 22 | 140 | 614,400 | 65319821 | # import sys
# sys.stdin = open("input.in","r")
# sys.stdout = open("output.out","w")
n,m = map(int,input().split())
s = []
for i in range(n):
s.append(input())
if m == 1 and n == 1:
if "1" <= s[0][0] <= "9":
print("NO")
exit()
else:
print("YES")
exit()
if m == 1:
for i in range(len(s)):
if s[i][0] == "."... | 84 | 77 | 204,800 | 114045799 | n, m = list(map(int, input().split()))
s = [['.' for _ in range(m+2)]]
valid = True
for _ in range(n):
k = list(str(input()))
k.insert(0, '.')
k.append('.')
s.append(k)
s.append(['.' for _ in range(m+2)])
for i in range(1, n+1):
for j in range(1, m+1):
if s[i][j] == '.':
s[i][j] ... | 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 |
670/F | 670 | F | PyPy 3 | TESTS | 3 | 77 | 1,331,200 | 198655452 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
a = list(input().rstrip())
b = list(input().rstrip())
a, b = [i - 48 for i in a], [i - 48 for i in b]
cnt = [0] * 10
for i in a:
cnt[i] += 1
n = len(a)
for i in range(1, 8):
if len(str(n - i)) == i:
u = n - i
break
... | 118 | 311 | 5,427,200 | 176663019 | def main():
s = input()
if s in ("01", "10"):
print(0)
return
cnt = [0] * 58
for j in map(ord, s):
cnt[j] += 1
n, s1 = sum(cnt), input()
for le in range(n - 1, 0, -1):
if len(str(le)) + le == n:
break
for s in s1, str(le):
for j in map(ord,... | 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 |
724/B | 724 | B | Python 3 | TESTS | 43 | 93 | 5,529,600 | 21290016 | import copy
def cal(l,n,m):
colswap=[0 for i in range(m)]
for j in range(m):
if(l[0][j]!=j+1):
colswap[j]=1
#print(colswap)
for i in range(m):
if(colswap[i]==1):
for j in range(i+1,m):
if(colswap[j]==1):
l1=copy.deepcopy(l[:])
flag1=0
for k1 in range(n):
l1[k1][i],l1[k1][j]=l1[k1]... | 86 | 62 | 4,915,200 | 21287978 | n, m = map(int, input().split())
def f(a):
global c, k
c = []
k = 0
for i in range(m):
if a[i] - 1 != i:
k += 1
c.append(i)
c = []
bb = []
cc = []
k = 0
flag1 = True
flag = True
for i in range(n):
b = list(map(int, input().split()))
f(b)
if... | 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 |
629/D | 629 | D | Python 3 | PRETESTS | 5 | 343 | 0 | 16243037 | import math
n = int(input())
res = 0
last = -1
for i in range(n):
r, h = [int(j) for j in input().split()]
v = r * r * h
if v > last:
res += v
last = v
print(res * math.pi) | 111 | 1,200 | 32,051,200 | 18118918 | from math import *
from bisect import *
def update(bit, size, idx, amount):
while idx <= size:
if bit[idx] < amount:
bit[idx] = amount
idx += idx & -idx
def read(bit, idx):
rst = 0
while idx >= 1:
if bit[idx] > rst:
rst = bit[idx]
idx -= idx & -idx
... | Codeforces Round 343 (Div. 2) | CF | 2,016 | 2 | 256 | Babaei and Birthday Cake | As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special ca... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake. | Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac{|a-b|}{\max(1,b)} \l... | null | In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4. | [{"input": "2\n100 30\n40 10", "output": "942477.796077000"}, {"input": "4\n1 1\n9 7\n1 4\n10 7", "output": "3983.539484752"}] | 2,000 | ["data structures", "dp"] | 111 | [{"input": "2\r\n100 30\r\n40 10\r\n", "output": "942477.796077000\r\n"}, {"input": "4\r\n1 1\r\n9 7\r\n1 4\r\n10 7\r\n", "output": "3983.539484752\r\n"}, {"input": "3\r\n2 2\r\n1 1\r\n3 3\r\n", "output": "109.955742876\r\n"}, {"input": "3\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "109.955742876\r\n"}, {"input": "3\r\n3 3\r... | false | stdio | import sys
from decimal import Decimal, getcontext
def main():
input_path, output_path, submission_output_path = sys.argv[1:4]
getcontext().prec = 20 # High precision to avoid parsing issues
# Read correct output
try:
with open(output_path, 'r') as f:
correct_line = f.readline().... | true |
419/A | 420 | A | Python 3 | TESTS | 35 | 93 | 307,200 | 6978153 | def test_achiral(ch, achiral):
for i in ch:
if i in achiral:
print("NO")
return()
ch1=""
j=-1
while j>=-len(ch):
ch1=ch1+ch[j]
j-=1
if ch1==ch:
print("YES")
return()
else:
print("NO")
return()
achiral="BCDEF... | 80 | 46 | 0 | 172376338 | sym={"A", "H", "I", "M", "O","T", "U", "V", "W", "X", "Y"}
s=input()
if s[::-1]==s:
for x in s:
if x not in sym:
print("NO")
break
else:
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 |
961/D | 961 | D | PyPy 3-64 | TESTS | 14 | 592 | 62,156,800 | 161724978 | import sys
from collections import defaultdict, deque, Counter
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
... | 121 | 140 | 13,209,600 | 185214075 | 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
class Point... | 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 | 49 | 902 | 409,600 | 190903015 | x=""
z=input()
l=a=b=-(-len(z)//2)
if len(z)%2==1:
x="4"*l+"7"*l
else:
m=("7"*l)+("4"*l)
if int(z)>int(m):
x="4"*(l+1)+"7"*(l+1)
elif z.count("4")==z.count("7")==l:
print(z)
else:
ca=0
for i in z:
if i <"4":
x+=a*"4"+"7"*b
break
elif "4"<i<"7":
x+="7"+a*"4"+"7"*... | 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 |
489/B | 489 | B | Python 3 | TESTS | 36 | 46 | 0 | 213730644 | n = int(input())
a = [int(i) for i in input().split()]
m = int(input())
b = [int(i) for i in input().split()]
bg = [-1 for i in range(n)]
gb = [-1 for i in range(m)]
vi = [-1 for i in range(m)]
def dfs(boy, cur):
for girl in range(m):
if abs(a[boy] - b[girl]) > 1:
continue
if vi[girl] == cur:
continue
else... | 81 | 46 | 0 | 194893214 | p=lambda:sorted(map(int,input().split()));n=p()[0];a=p();m=p()[0];b=p();
i,j,k=0,0,0
while i<n and j<m:
if abs(a[i]-b[j])<2:k+=1;i+=1;j+=1
elif a[i]<b[j]:i+=1
else:j+=1
print(k) | 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 |
61/C | 61 | C | PyPy 3 | TESTS | 50 | 140 | 0 | 40392286 | def main() :
def intToRoman(num) :
pattern = {'0':'', '1':'a', '2':'aa', '3':'aaa', '4':'ab',
'5':'b', '6':'ba', '7':'baa', '8':'baaa', '9':'ac'}
code = ['IVX', 'XLC', 'CDM', 'M__']
ret = []
for i,x in enumerate(reversed(str(num))) :
tmp = pattern[x]
for p,r in zip('abc', code[i]) :
tmp = tmp.repl... | 70 | 77 | 0 | 171482193 | num_one = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"]
num_two = ["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"]
num_three = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"]
num_four = ["", "M", "MM", "MMM", "MMMM"]
numbers = "0123456789ABCDEFGHIJKLMNOPQ"
def to_roman(x):
... | Codeforces Beta Round 57 (Div. 2) | CF | 2,011 | 2 | 256 | Capture Valerian | It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.
Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captu... | The first line contains two integers a and b (2 ≤ a, b ≤ 25). Only b may be replaced by an R which indicates Roman numbering system.
The next line contains a single non-negative integer c in base a which may contain leading zeros but its length doesn't exceed 103.
It is guaranteed that if we have Roman numerals inclu... | Write a single line that contains integer c in base b. You must omit leading zeros. | null | You can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals | [{"input": "10 2\n1", "output": "1"}, {"input": "16 R\n5", "output": "V"}, {"input": "5 R\n4", "output": "IV"}, {"input": "2 2\n1111001", "output": "1111001"}, {"input": "12 13\nA", "output": "A"}] | 2,000 | ["math"] | 70 | [{"input": "10 2\r\n1\r\n", "output": "1\r\n"}, {"input": "16 R\r\n5\r\n", "output": "V\r\n"}, {"input": "5 R\r\n4\r\n", "output": "IV\r\n"}, {"input": "2 2\r\n1111001\r\n", "output": "1111001\r\n"}, {"input": "12 13\r\nA\r\n", "output": "A\r\n"}, {"input": "6 7\r\n12345\r\n", "output": "5303\r\n"}, {"input": "25 12\r\... | false | stdio | null | true |
984/B | 984 | B | PyPy 3-64 | TESTS | 4 | 46 | 0 | 194604000 | n,m=map(int,input().split())
l=[]
for i in range(n):
a=[i for i in input()]
l.append(a)
flag=False
for i in range(n):
for j in range(m):
if l[i][j].isnumeric():
count_=0
if i+1!=n:
if l[i+1][j]=="*":
count_+=1
if i-1!=-1:
... | 84 | 77 | 4,096,000 | 148073239 | [n,m] = map(int,input().split())
grid = [input() for i in range(n)]
dx = [1,-1,0,0,-1,-1,1,1]
dy = [0,0,-1,1,1,-1,-1,1]
def check(r,c,x):
cnt = 0
for i in range(8):
nr = r + dx[i]
nc = c + dy[i]
if nr < 0 or nr >= n or nc < 0 or nc >= m:
continue
if grid[nr][nc] == ... | 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 |
961/D | 961 | D | PyPy 3 | TESTS | 48 | 935 | 15,155,200 | 119580152 | def gcd(a, b):
if a > b:
a, b = b, a
if b % a==0:
return a
return gcd(b % a, a)
def line(a, b):
x0, y0 = a
x1, y1 = b
if x0==x1:
return [True, x1, None]
else:
slope = (y1-y0)/(x1-x0)
inter = y0-slope*x0
return [False, slope, inter]
def on... | 121 | 171 | 20,480,000 | 191084748 | # Problem: D. Pair Of Lines
# Contest: Codeforces - Educational Codeforces Round 41 (Rated for Div. 2)
# URL: https://codeforces.com/contest/961/problem/D
# Memory Limit: 256 MB
# Time Limit: 2000 ms
import sys
import bisect
import random
import io, os
from bisect import *
from collections import *
from contextlib imp... | 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 | 48 | 1,388 | 23,552,000 | 82329037 | def slope(a,b):
if a[0]==b[0]:
return "x"
else:
return (b[1]-a[1])/(b[0]-a[0])
n=int(input())
a=[]
for i in range(n):
a.append(list(map(int,input().split())))
a.sort()
if n<5:
print("YES")
else:
b=a[0]
c=set([])
e=0
for i in range(1,n):
if slope(b,a[i]) in c:
... | 121 | 326 | 34,816,000 | 128474324 | import sys
input = sys.stdin.readline
def f(x1, y1, x2, y2, x3, y3):
if x1 == x2 == x3:
return True
if y1 == y2 == y3:
return True
if (x2 - x1) * (y3 - y2) == (x3 - x2) * (y2 - y1):
return True
else:
return False
n = int(input())
xy = [list(map(int, input().split())) fo... | 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 |
61/C | 61 | C | Python 3 | TESTS | 50 | 109 | 307,200 | 95843087 | import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
a, b = input().split()
a = int(a)
num = int(input().rstrip(), a)
if b != 'R':
b = int(b)
ans = []
while num:
rem = num % b
if rem >= 10:
ans.append(chr(65 + r... | 70 | 77 | 307,200 | 22208625 | system_1, system_2 = input().split()
integer = int(input(), base = int(system_1))
if system_2 == '10' or integer == 0:
print(integer)
exit(0)
digits = []
alphabet = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
if system_2 != 'R':
system_2 = int(sy... | Codeforces Beta Round 57 (Div. 2) | CF | 2,011 | 2 | 256 | Capture Valerian | It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.
Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captu... | The first line contains two integers a and b (2 ≤ a, b ≤ 25). Only b may be replaced by an R which indicates Roman numbering system.
The next line contains a single non-negative integer c in base a which may contain leading zeros but its length doesn't exceed 103.
It is guaranteed that if we have Roman numerals inclu... | Write a single line that contains integer c in base b. You must omit leading zeros. | null | You can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals | [{"input": "10 2\n1", "output": "1"}, {"input": "16 R\n5", "output": "V"}, {"input": "5 R\n4", "output": "IV"}, {"input": "2 2\n1111001", "output": "1111001"}, {"input": "12 13\nA", "output": "A"}] | 2,000 | ["math"] | 70 | [{"input": "10 2\r\n1\r\n", "output": "1\r\n"}, {"input": "16 R\r\n5\r\n", "output": "V\r\n"}, {"input": "5 R\r\n4\r\n", "output": "IV\r\n"}, {"input": "2 2\r\n1111001\r\n", "output": "1111001\r\n"}, {"input": "12 13\r\nA\r\n", "output": "A\r\n"}, {"input": "6 7\r\n12345\r\n", "output": "5303\r\n"}, {"input": "25 12\r\... | false | stdio | null | true |
457/A | 457 | A | Python 3 | TESTS | 86 | 202 | 10,240,000 | 213962189 | def normalize_backward(data, n):
if n < 3:
return
i = n - 1
while i >= 0:
if data[i] > 0 and data[i - 1] > 0:
data[i] -= 1
data[i - 1] -= 1
data[i - 2] += 1
i -= 1
else:
break
i -= 1
def normalize(data, n):
i =... | 177 | 202 | 32,358,400 | 84935682 | def clean(d):
ans = ['0']
for c in list(d):
ans.append(c)
i = len(ans) - 1 #find last index
while i > 1 and ans[i-2]== '0' and ans[i - 1] == '1' and ans[i] == '1':
ans[i - 2] = '1'
ans[i - 1] = '0'
ans[i] = '0'
i -= 2
return ''.join(ans... | MemSQL Start[c]UP 2.0 - Round 2 | CF | 2,014 | 1 | 256 | Golden System | Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number $$q = \frac{\sqrt{5}+1}{2}$$, in particular that q2 = q + 1, and she thinks it would make a good base for her new unique system. She called it "golden system". In golden syst... | Input consists of two lines — one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000. | Print ">" if the first number is larger, "<" if it is smaller and "=" if they are equal. | null | In the first example first number equals to $$( { \frac { \sqrt { 5 } + 1 } { 2 } } ) ^ { 3 } \approx 1. 6 1 8 0 3 3 9 8 8 ^ { 3 } \approx 4. 2 3 6$$, while second number is approximately 1.6180339882 + 1.618033988 + 1 ≈ 5.236, which is clearly a bigger number.
In the second example numbers are equal. Each of them is ... | [{"input": "1000\n111", "output": "<"}, {"input": "00100\n11", "output": "="}, {"input": "110\n101", "output": ">"}] | 1,700 | ["math", "meet-in-the-middle"] | 177 | [{"input": "1000\r\n111\r\n", "output": "<\r\n"}, {"input": "00100\r\n11\r\n", "output": "=\r\n"}, {"input": "110\r\n101\r\n", "output": ">\r\n"}, {"input": "0\r\n0\r\n", "output": "=\r\n"}, {"input": "1\r\n10\r\n", "output": "<\r\n"}, {"input": "11\r\n10\r\n", "output": ">\r\n"}, {"input": "00111\r\n10100\r\n", "outpu... | false | stdio | null | true |
985/E | 985 | E | PyPy 3 | TESTS | 12 | 748 | 46,796,800 | 94206692 | import sys
n, k, d = map(int, input().split())
a = sorted(map(int, input().split()))
g = [[r-k, r] for r in range(k, n+1, k)]
g[-1][1] = n
for i in range(len(g)-1, 0, -1):
while a[g[i][1]-1] - a[g[i][0]] > d:
g[i][0] += 1
if g[i][1] - g[i][0] < k:
print('NO')
exit()
g[i-1][1] = g... | 90 | 296 | 43,110,400 | 152785212 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, k, d = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dp = [0] * (n + 5)
dp[0] = 1
dp[1] = -1
r = 0
for i in range(n):
if not dp[i]:
dp[i + 1] += dp[i]
continue
ai = a[i]
while r < n a... | Educational Codeforces Round 44 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Pencils and Boxes | Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of n integer numbers — saturation of the color of each pencil. Now Mishka wants to ... | The first line contains three integer numbers n, k and d (1 ≤ k ≤ n ≤ 5·105, 0 ≤ d ≤ 109) — the number of pencils, minimal size of any non-empty box and maximal difference in saturation between any pair of pencils in the same box, respectively.
The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) ... | Print "YES" if it's possible to distribute all the pencils into boxes and satisfy all the conditions. Otherwise print "NO". | null | In the first example it is possible to distribute pencils into 2 boxes with 3 pencils in each with any distribution. And you also can put all the pencils into the same box, difference of any pair in it won't exceed 10.
In the second example you can split pencils of saturations [4, 5, 3, 4] into 2 boxes of size 2 and p... | [{"input": "6 3 10\n7 2 7 7 4 2", "output": "YES"}, {"input": "6 2 3\n4 5 3 13 4 10", "output": "YES"}, {"input": "3 2 5\n10 16 22", "output": "NO"}] | 2,100 | ["binary search", "data structures", "dp", "greedy", "two pointers"] | 90 | [{"input": "6 3 10\r\n7 2 7 7 4 2\r\n", "output": "YES\r\n"}, {"input": "6 2 3\r\n4 5 3 13 4 10\r\n", "output": "YES\r\n"}, {"input": "3 2 5\r\n10 16 22\r\n", "output": "NO\r\n"}, {"input": "8 7 13\r\n52 85 14 52 92 33 80 85\r\n", "output": "NO\r\n"}, {"input": "6 4 0\r\n1 3 2 4 2 1\r\n", "output": "NO\r\n"}, {"input":... | false | stdio | null | true |
660/A | 660 | A | Python 3 | TESTS | 6 | 62 | 0 | 202801404 | from math import gcd
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(n - 1):
ans.append(a[i])
if gcd(a[i], a[i + 1]) != 1:
ans.append(9)
ans.append(a[-1])
print(len(ans) - n)
print(*ans) | 93 | 46 | 0 | 191294126 | def prime(n):
if(n==1):
return False
else:
for i in range(2,int(n**0.5)+1):
if(n%i==0):
return False
return True
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b,a%b)
n = int(input())
#n,m = map(int,input().split())
l = list... | Educational Codeforces Round 11 | ICPC | 2,016 | 1 | 256 | Co-prime Array | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integer... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. | Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Als... | null | null | [{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}] | 1,200 | ["greedy", "implementation", "math", "number theory"] | 93 | [{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"inp... | false | stdio | import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
# Read submission output
with open(submission_path) a... | true |
711/B | 711 | B | Python 3 | TESTS | 6 | 62 | 6,963,200 | 128165635 | def main():
n = int(input())
matrix = []
x, y = -1, -1
maxi, mini =0,0
for i in range(n):
sum =0
flag = False
row = [int(j) for j in input().split()]
for k in range(len(row)):
sum+=row[k]
if(row[k]==0):
x,y=i,k
f... | 147 | 140 | 6,963,200 | 145694975 | from sys import stdin
input = lambda: stdin.buffer.readline().rstrip(b'\r\n').decode('ascii')
get_col = lambda arr, i: [row[i] for row in arr]
n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]
su, dis, ans = max([sum(x) for x in a]), set(), 0
for i in range(n):
for j 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 |
95/B | 95 | B | Python 3 | TESTS | 49 | 92 | 307,200 | 169630143 | def nr47(a):
n4 = a.count('4')
n7 = a.count('7')
if n4 < n7:
need = (n7 - n4) // 2
i = 1
k = 0
while k < need or (a[-i]) == '7':
k += a[-i] == '7'
i += 1
a = a[:-i] + '7' + '4' * (need + 1) + '7' * (i - need - 2)
elif n4 > n7:
need = (n4 - n7) // 2
i = 1
k = 0
while k < need:
k += a[-i] =... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.