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):
if a[i]==n:
print("NO")
exit()
m.sort(key=lambda x:x[k])
for i in range(n):
if m[i][k]==1:
for j in range(k):
if m[i][j]==1:
idx=j
for j in range(i+1,n):
if m[j][idx]!=1:
print("YES")
exit()
print("NO")
| 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. To make the contest interesting for them, each of the teams should know at most half of the selected problems.
Determine if Snark and Philip can make an interesting problemset!
|
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\n0 0 1\r\n1 0 1\r\n0 1 1\r\n1 0 0\r\n1 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 0 1\r\n1 1 0 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 1 0\r\n0 0 0 0\r\n0 0 1 0\r\n1 0 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n0 0\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 1\r\n1 0 0\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 0\r\n1 1 0 0\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 1\r\n1\r\n1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n0 1 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 0 1\r\n1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 1 1 0\r\n1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "6 3\r\n0 1 1\r\n1 0 1\r\n1 1 1\r\n0 1 0\r\n1 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n0 0 0 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 1 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "6 3\r\n1 0 0\r\n1 1 1\r\n1 1 1\r\n0 1 0\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 0 0\r\n1 1 1 1\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "1 3\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 1\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n1 1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n0 1 0 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n1 1 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 1 1\r\n1 0 1 0\r\n1 1 0 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 0 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 0\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 0 1\r\n0 0 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n1 1 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "8 4\r\n0 0 0 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 1\r\n1 1 1 0\r\n0 1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n0 0 0 1\r\n1 1 1 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n1 0 1\r\n0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 0 1\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 0 0\r\n1 0 1 0\r\n0 1 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 0 0 0\r\n1 0 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 0 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 0 1\r\n0 1 1 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 1 1\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 0\r\n", "output": "YES\r\n"}]
| 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 sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length.
Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.
|
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": "2"}, {"input": "33\r\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36\r\n", "output": "5"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n10\r\n", "output": "0"}, {"input": "2\r\n1 1\r\n", "output": "0"}, {"input": "3\r\n1 1 1\r\n", "output": "0"}, {"input": "3\r\n1 2 2\r\n", "output": "0"}, {"input": "3\r\n3 2 1\r\n", "output": "0"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1"}, {"input": "4\r\n1 2 1 2\r\n", "output": "1"}, {"input": "4\r\n1 100 1 100\r\n", "output": "1"}, {"input": "4\r\n10 100 100 10\r\n", "output": "1"}, {"input": "4\r\n1 2 3 3\r\n", "output": "0"}, {"input": "4\r\n8 5 9 13\r\n", "output": "0"}, {"input": "4\r\n100 100 100 100\r\n", "output": "1"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1"}, {"input": "5\r\n1 4 4 1 1\r\n", "output": "1"}, {"input": "5\r\n1 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 1 100 100 100\r\n", "output": "1"}, {"input": "5\r\n100 100 100 100 100\r\n", "output": "1"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "1"}, {"input": "6\r\n1 1 5 1 1 5\r\n", "output": "1"}, {"input": "6\r\n1 100 100 1 1 1\r\n", "output": "1"}, {"input": "6\r\n100 1 1 100 1 100\r\n", "output": "1"}, {"input": "6\r\n1 2 3 2 3 1\r\n", "output": "1"}, {"input": "6\r\n1 50 1 100 50 100\r\n", "output": "1"}, {"input": "6\r\n10 10 10 12 13 14\r\n", "output": "0"}, {"input": "7\r\n1 1 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 2 1 2 1 2\r\n", "output": "1"}, {"input": "7\r\n1 1 2 2 1 2 3\r\n", "output": "1"}, {"input": "7\r\n1 3 2 2 3 1 4\r\n", "output": "1"}, {"input": "7\r\n1 3 4 3 5 4 6\r\n", "output": "1"}, {"input": "7\r\n7 6 5 4 3 2 1\r\n", "output": "0"}, {"input": "8\r\n1 2 1 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 2 1 1 2 2 2\r\n", "output": "1"}, {"input": "8\r\n1 2 2 2 3 1 1 3\r\n", "output": "1"}, {"input": "8\r\n1 2 3 4 1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n1 1 1 1 2 3 2 3\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 5 5 5\r\n", "output": "1"}, {"input": "8\r\n1 2 1 3 4 1 5 6\r\n", "output": "0"}, {"input": "8\r\n1 2 3 4 5 6 1 7\r\n", "output": "0"}, {"input": "8\r\n8 6 3 4 5 2 1 7\r\n", "output": "0"}, {"input": "8\r\n100 100 100 100 100 100 100 100\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "10\r\n19 9 14 14 19 5 5 18 10 17\r\n", "output": "1"}, {"input": "10\r\n72 86 73 25 84 29 33 34 20 29\r\n", "output": "0"}, {"input": "10\r\n93 93 99 98 91 96 92 98 94 98\r\n", "output": "1"}, {"input": "13\r\n35 6 21 30 67 55 70 39 75 72 11 13 69\r\n", "output": "0"}, {"input": "17\r\n90 97 12 56 94 11 49 96 22 7 15 48 71 71 94 72 100\r\n", "output": "1"}, {"input": "18\r\n39 72 67 28 69 41 43 51 66 99 4 57 68 93 28 27 37 27\r\n", "output": "1"}, {"input": "23\r\n88 82 2 67 4 6 67 83 77 58 48 64 86 37 96 83 35 46 13 79 72 18 35\r\n", "output": "1"}, {"input": "30\r\n43 34 38 50 47 24 26 20 7 5 26 29 98 87 90 46 10 53 88 61 90 39 78 81 65 13 72 95 53 27\r\n", "output": "1"}, {"input": "33\r\n1 3 34 55 38 58 64 26 66 44 50 63 46 62 62 99 73 87 35 20 30 38 39 85 49 24 93 68 8 25 86 30 51\r\n", "output": "1"}, {"input": "38\r\n65 69 80 93 28 36 40 81 53 75 55 50 82 95 8 51 66 65 50 4 40 92 18 70 38 68 42 100 34 57 98 79 95 84 82 35 100 89\r\n", "output": "3"}, {"input": "40\r\n4 2 62 38 76 68 19 71 44 91 76 31 3 63 56 62 93 98 10 61 52 59 81 46 23 27 36 26 24 38 37 66 15 16 78 41 95 82 73 90\r\n", "output": "1"}, {"input": "43\r\n62 31 14 43 67 2 60 77 64 70 91 9 3 43 76 7 56 84 5 20 88 50 47 42 7 39 8 56 71 24 49 59 70 61 81 17 76 44 80 61 77 5 96\r\n", "output": "4"}, {"input": "49\r\n75 64 7 2 1 66 31 84 78 53 34 5 40 90 7 62 86 54 99 77 8 92 30 3 18 18 61 38 38 11 79 88 84 89 50 94 72 8 54 85 100 1 19 4 97 91 13 39 91\r\n", "output": "4"}, {"input": "57\r\n83 94 42 57 19 9 40 25 56 92 9 38 58 66 43 19 50 10 100 3 49 96 77 36 20 3 48 15 38 19 99 100 66 14 52 13 16 73 65 99 29 85 75 18 97 64 57 82 70 19 16 25 40 11 9 22 89\r\n", "output": "6"}, {"input": "67\r\n36 22 22 86 52 53 36 68 46 82 99 37 15 43 57 35 33 99 22 96 7 8 80 93 70 70 55 51 61 74 6 28 85 72 84 42 29 1 4 71 7 40 61 95 93 36 42 61 16 40 10 85 31 86 93 19 44 20 52 66 10 22 40 53 25 29 23\r\n", "output": "8"}, {"input": "74\r\n90 26 58 69 87 23 44 9 32 25 33 13 79 84 52 90 4 7 93 77 29 85 22 1 96 69 98 16 76 87 57 16 44 41 57 28 18 70 77 83 37 17 59 87 27 19 89 63 14 84 77 40 46 77 82 73 86 73 30 58 6 30 70 36 31 12 43 50 93 3 3 57 38 91\r\n", "output": "7"}, {"input": "100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "25"}, {"input": "100\r\n1 9 3 5 10 10 9 8 10 1 7 6 5 6 7 9 1 5 8 3 2 3 3 10 2 3 10 7 10 3 6 3 2 10 1 10 2 3 4 3 3 1 7 5 10 2 3 8 9 2 5 4 7 2 5 9 2 1 7 9 9 8 4 4 6 1 6 6 4 7 2 3 1 1 1 6 9 1 2 9 3 7 6 10 3 6 2 5 2 5 3 9 10 6 4 2 9 9 4 5\r\n", "output": "23"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "7\r\n13 13 13 13 6 2 3\r\n", "output": "1"}, {"input": "8\r\n1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n100 100 99 99 5\r\n", "output": "1"}, {"input": "8\r\n2 2 2 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 6 7 7\r\n", "output": "0"}, {"input": "8\r\n4 4 4 4 4 4 4 4\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 2 2\r\n", "output": "2"}, {"input": "4\r\n100 100 100 99\r\n", "output": "0"}, {"input": "4\r\n2 2 2 2\r\n", "output": "1"}, {"input": "5\r\n100 100 99 99 2\r\n", "output": "1"}, {"input": "9\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n2 2 3 4 4\r\n", "output": "1"}, {"input": "100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "25"}, {"input": "13\r\n1 2 3 4 5 6 7 8 9 10 11 12 13\r\n", "output": "0"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "4\r\n4 4 4 4\r\n", "output": "1"}, {"input": "5\r\n1 1 2 3 3\r\n", "output": "1"}, {"input": "5\r\n30 30 30 1 1\r\n", "output": "1"}]
| 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:
# Считаем время при использовании заклинаний первого типа
min_time = min(min_time, n * min(a[i], x))
for i in range(k):
if d[i] <= s:
# Считаем время при использовании заклинаний второго типа
remaining_potions = max(0, n - c[i])
min_time = min(min_time, remaining_potions * x)
print(min_time)
| 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, input().split()), 0] # num of instant
dd = [0, *map(int, input().split()), s + 1] # price of instant
res = []
for t, b in zip(aa, bb):
b = s - b
if b >= 0:
i = bisect(dd, b)
if b < dd[i]:
i -= 1
x = n - cc[i]
if x <= 0:
res = [0]
break
res.append(x * t)
print(min(res))
if __name__ == '__main__':
main()
|
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 this type speed up the preparation time of one potion. There are m spells of this type, the i-th of them costs bi manapoints and changes the preparation time of each potion to ai instead of x.
2. Spells of this type immediately prepare some number of potions. There are k such spells, the i-th of them costs di manapoints and instantly create ci potions.
Anton can use no more than one spell of the first type and no more than one spell of the second type, and the total number of manapoints spent should not exceed s. Consider that all spells are used instantly and right before Anton starts to prepare potions.
Anton wants to get to the next level as fast as possible, so he is interested in the minimum number of time he needs to spent in order to prepare at least n potions.
|
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 initial number of seconds required to prepare one potion and the number of manapoints Anton can use.
The third line contains m integers ai (1 ≤ ai < x) — the number of seconds it will take to prepare one potion if the i-th spell of the first type is used.
The fourth line contains m integers bi (1 ≤ bi ≤ 2·109) — the number of manapoints to use the i-th spell of the first type.
There are k integers ci (1 ≤ ci ≤ n) in the fifth line — the number of potions that will be immediately created if the i-th spell of the second type is used. It's guaranteed that ci are not decreasing, i.e. ci ≤ cj if i < j.
The sixth line contains k integers di (1 ≤ di ≤ 2·109) — the number of manapoints required to use the i-th spell of the second type. It's guaranteed that di are not decreasing, i.e. di ≤ dj if i < j.
|
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 used is 10 + 80 = 90, and the preparation time is 4·5 = 20 seconds (15 potions were prepared instantly, and the remaining 5 will take 4 seconds each).
In the second sample, Anton can't use any of the spells, so he just prepares 20 potions, spending 10 seconds on each of them and the answer is 20·10 = 200.
|
[{"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\n7\r\n236\r\n77\r\n5\r\n", "output": "119\r\n"}, {"input": "3 4 5\r\n5 9\r\n1 2 1 1\r\n3 5 4 1\r\n1 1 1 1 3\r\n1 2 3 4 5\r\n", "output": "0\r\n"}, {"input": "1 4 2\r\n3 10\r\n2 1 1 1\r\n1 5 3 5\r\n1 1\r\n1 5\r\n", "output": "0\r\n"}, {"input": "5 3 3\r\n4 4\r\n2 3 1\r\n1 3 1\r\n1 2 2\r\n2 2 5\r\n", "output": "3\r\n"}, {"input": "4 3 2\r\n2 7\r\n1 1 1\r\n2 4 1\r\n1 4\r\n1 5\r\n", "output": "0\r\n"}, {"input": "2000000000 1 1\r\n2000000000 1999999999\r\n1\r\n2000000000\r\n1\r\n2000000000\r\n", "output": "4000000000000000000\r\n"}, {"input": "3 1 1\r\n2 1\r\n1\r\n1\r\n1\r\n1\r\n", "output": "3\r\n"}, {"input": "379 5 8\r\n758 10000\r\n512 512 512 512 512\r\n500 500 500 500 500\r\n123 123 123 123 123 123 123 123\r\n500 500 500 500 500 500 500 500\r\n", "output": "131072\r\n"}, {"input": "256 22 22\r\n45 42\r\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\r\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\r\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\r\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\r\n", "output": "4935\r\n"}, {"input": "20 3 2\r\n1000 99\r\n1 2 3\r\n100 200 300\r\n1 2\r\n3 4\r\n", "output": "18000\r\n"}, {"input": "20 3 2\r\n10 99\r\n2 4 3\r\n200 100 400\r\n4 15\r\n10 80\r\n", "output": "50\r\n"}, {"input": "2000000000 1 1\r\n2000000000 1\r\n1\r\n100\r\n1\r\n100\r\n", "output": "4000000000000000000\r\n"}, {"input": "100 1 1\r\n100 1\r\n1\r\n1000\r\n100\r\n1\r\n", "output": "0\r\n"}, {"input": "100 1 1\r\n100 1\r\n1\r\n1000\r\n99\r\n1\r\n", "output": "100\r\n"}, {"input": "2 1 1\r\n10 10\r\n2\r\n11\r\n1\r\n2\r\n", "output": "10\r\n"}, {"input": "2000000000 3 2\r\n1000000000 99\r\n2 4 3\r\n100 100 100\r\n4 15\r\n100 100\r\n", "output": "2000000000000000000\r\n"}, {"input": "2000000000 1 1\r\n2000000000 1\r\n2\r\n2\r\n2\r\n2\r\n", "output": "4000000000000000000\r\n"}, {"input": "2000000000 2 2\r\n2000000000 1\r\n1 2\r\n100 100\r\n1 2\r\n100 100\r\n", "output": "4000000000000000000\r\n"}, {"input": "2000000000 1 1\r\n2000000000 1\r\n1\r\n2\r\n1\r\n2\r\n", "output": "4000000000000000000\r\n"}, {"input": "2000000000 3 2\r\n10 1\r\n2 4 3\r\n200 100 400\r\n4 15\r\n100 800\r\n", "output": "20000000000\r\n"}, {"input": "1000 1 1\r\n10 10\r\n1\r\n1000\r\n500\r\n10\r\n", "output": "5000\r\n"}, {"input": "4 2 2\r\n4 3\r\n1 1\r\n8 8\r\n1 1\r\n1 1\r\n", "output": "12\r\n"}, {"input": "20 3 2\r\n10 99\r\n2 4 3\r\n200 100 400\r\n20 20\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2000 1 1\r\n2000 1\r\n2\r\n2\r\n1\r\n1\r\n", "output": "3998000\r\n"}, {"input": "20 3 2\r\n10 99\r\n2 4 3\r\n20 20 40\r\n4 20\r\n10 80\r\n", "output": "0\r\n"}, {"input": "10 1 1\r\n10 50\r\n1\r\n50\r\n1\r\n50\r\n", "output": "10\r\n"}, {"input": "2000000000 3 2\r\n1000000000 99\r\n2 4 3\r\n200 100 400\r\n4 15\r\n100 100\r\n", "output": "2000000000000000000\r\n"}, {"input": "10 1 1\r\n10 10\r\n9\r\n100\r\n10\r\n10\r\n", "output": "0\r\n"}, {"input": "50 1 1\r\n3 10\r\n2\r\n100\r\n50\r\n10\r\n", "output": "0\r\n"}, {"input": "20 1 1\r\n10 99\r\n1\r\n100\r\n4\r\n10\r\n", "output": "160\r\n"}, {"input": "2000000000 3 2\r\n1000000000 99\r\n2 4 3\r\n200 100 400\r\n4 15\r\n100 800\r\n", "output": "2000000000000000000\r\n"}, {"input": "100 1 1\r\n100 2\r\n1\r\n2\r\n1\r\n2\r\n", "output": "100\r\n"}, {"input": "10 1 1\r\n10 50\r\n1\r\n51\r\n10\r\n50\r\n", "output": "0\r\n"}, {"input": "20 3 2\r\n10 10\r\n2 4 3\r\n10 90 90\r\n1 2\r\n999 1000\r\n", "output": "40\r\n"}, {"input": "5 1 1\r\n5 10\r\n3\r\n10\r\n5\r\n10\r\n", "output": "0\r\n"}, {"input": "20 1 1\r\n100 1\r\n2\r\n2\r\n20\r\n1\r\n", "output": "0\r\n"}, {"input": "100 1 1\r\n200 10\r\n10\r\n11\r\n100\r\n1\r\n", "output": "0\r\n"}, {"input": "20 3 2\r\n10 99\r\n2 4 3\r\n200 100 400\r\n4 15\r\n1 8\r\n", "output": "50\r\n"}, {"input": "20 3 1\r\n5 40\r\n2 3 4\r\n40 40 40\r\n20\r\n40\r\n", "output": "0\r\n"}, {"input": "10 1 1\r\n10 50\r\n1\r\n51\r\n9\r\n50\r\n", "output": "10\r\n"}, {"input": "2000000000 1 1\r\n2000000000 1\r\n1\r\n5\r\n1\r\n5\r\n", "output": "4000000000000000000\r\n"}, {"input": "100 1 1\r\n1000 5\r\n1\r\n6\r\n100\r\n4\r\n", "output": "0\r\n"}, {"input": "1000000000 1 1\r\n1000000000 1\r\n1\r\n10000\r\n1\r\n10000\r\n", "output": "1000000000000000000\r\n"}, {"input": "2000000000 1 1\r\n2000000000 1\r\n1\r\n10\r\n2\r\n10\r\n", "output": "4000000000000000000\r\n"}, {"input": "20 1 1\r\n10 100\r\n5\r\n200\r\n10\r\n1\r\n", "output": "100\r\n"}, {"input": "2000000000 1 1\r\n2000000000 1\r\n1999999999\r\n1\r\n1\r\n1\r\n", "output": "3999999998000000000\r\n"}, {"input": "20 3 2\r\n10 10\r\n2 4 3\r\n10 10 10\r\n20 20\r\n999 999\r\n", "output": "40\r\n"}, {"input": "20 2 2\r\n10 100\r\n1 1\r\n1000 2000\r\n4 15\r\n100 800\r\n", "output": "160\r\n"}, {"input": "2 1 1\r\n5 5\r\n2\r\n10\r\n2\r\n1\r\n", "output": "0\r\n"}, {"input": "20 3 2\r\n10 2\r\n1 1 1\r\n3 4 5\r\n1 2\r\n1 3\r\n", "output": "190\r\n"}, {"input": "20 3 1\r\n10 10\r\n9 9 9\r\n10 10 10\r\n20\r\n10\r\n", "output": "0\r\n"}, {"input": "1000000000 3 2\r\n1000000000 1\r\n2 4 3\r\n20 10 40\r\n4 15\r\n10 80\r\n", "output": "1000000000000000000\r\n"}, {"input": "10 1 1\r\n10 10\r\n1\r\n20\r\n5\r\n9\r\n", "output": "50\r\n"}, {"input": "1 1 1\r\n1000 1000\r\n1\r\n1000\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "1000000000 1 1\r\n1000000000 1\r\n1\r\n10000\r\n1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "20 1 1\r\n10 10\r\n4\r\n100\r\n20\r\n10\r\n", "output": "0\r\n"}, {"input": "100 1 1\r\n100 10000\r\n99\r\n10001\r\n100\r\n10000\r\n", "output": "0\r\n"}, {"input": "20 1 1\r\n10 100\r\n5\r\n200\r\n10\r\n100\r\n", "output": "100\r\n"}, {"input": "52 2 3\r\n50 101\r\n15 13\r\n10 20\r\n20 50 51\r\n20 100 200\r\n", "output": "100\r\n"}, {"input": "2000000000 1 1\r\n2000000000 10\r\n5\r\n15\r\n5\r\n15\r\n", "output": "4000000000000000000\r\n"}, {"input": "20 3 2\r\n10 99\r\n2 4 3\r\n99 100 400\r\n4 15\r\n100 800\r\n", "output": "40\r\n"}, {"input": "1 1 1\r\n1000 1\r\n1\r\n1000\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "100000000 1 1\r\n100000000 1\r\n10\r\n10\r\n10\r\n10\r\n", "output": "10000000000000000\r\n"}, {"input": "1000000000 3 2\r\n1000000000 99\r\n2 4 3\r\n20 10 40\r\n4 15\r\n10 80\r\n", "output": "1999999992\r\n"}, {"input": "100 1 1\r\n1000 5\r\n1\r\n6\r\n95\r\n4\r\n", "output": "5000\r\n"}, {"input": "1 1 1\r\n2 1\r\n1\r\n10\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "50 1 1\r\n10 10\r\n8\r\n11\r\n50\r\n10\r\n", "output": "0\r\n"}, {"input": "2000000000 1 1\r\n2000000000 1\r\n1\r\n10\r\n1\r\n10\r\n", "output": "4000000000000000000\r\n"}, {"input": "10 1 1\r\n10 10\r\n5\r\n5\r\n7\r\n10\r\n", "output": "30\r\n"}, {"input": "2000000000 1 1\r\n2000000000 1\r\n200000000\r\n2000000000\r\n2000000000\r\n2000000000\r\n", "output": "4000000000000000000\r\n"}, {"input": "2000000000 1 1\r\n2000000000 1\r\n4\r\n100\r\n20\r\n100\r\n", "output": "4000000000000000000\r\n"}, {"input": "100 1 1\r\n1000 5\r\n2\r\n6\r\n95\r\n4\r\n", "output": "5000\r\n"}, {"input": "10 1 2\r\n10 10\r\n5\r\n6\r\n5 7\r\n4 4\r\n", "output": "15\r\n"}, {"input": "1000000000 1 1\r\n1000000000 1\r\n1\r\n1000000\r\n1\r\n100000000\r\n", "output": "1000000000000000000\r\n"}, {"input": "2000000000 1 1\r\n2000000000 5\r\n2\r\n6\r\n2\r\n6\r\n", "output": "4000000000000000000\r\n"}, {"input": "2000000000 1 1\r\n2000000000 1\r\n100\r\n100\r\n100\r\n100\r\n", "output": "4000000000000000000\r\n"}, {"input": "20 3 2\r\n10 99\r\n2 4 3\r\n20 10 40\r\n20 20\r\n99 99\r\n", "output": "0\r\n"}, {"input": "10 2 2\r\n10 15\r\n5 7\r\n16 16\r\n5 10\r\n5 10\r\n", "output": "0\r\n"}, {"input": "1000000000 1 1\r\n1000000000 10\r\n999999991\r\n1\r\n1\r\n10000\r\n", "output": "999999991000000000\r\n"}, {"input": "1000000000 1 1\r\n1000000000 2\r\n999999999\r\n1\r\n1\r\n1\r\n", "output": "999999998000000001\r\n"}, {"input": "20 3 2\r\n2000000000 99\r\n2 4 3\r\n200 100 400\r\n4 15\r\n100 800\r\n", "output": "40000000000\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
dp[0][1][a[0]]=0
dp[0][1][1^a[0]]=1
dp[0][2][a[0]]=1
dp[0][2][1^a[0]]=1
for i in range(1,n):
dp[i][0][a[i]] = max(1+dp[i-1][0][1^a[i]],dp[i-1][0][a[i]])
dp[i][0][1 ^ a[i]] = dp[i-1][0][1^a[i]]
dp[i][1][a[i]] = max(dp[i-1][1][a[i]],dp[i-1][0][a[i]])
dp[i][1][1 ^ a[i]] = max(dp[i-1][1][a[i]]+1,dp[i-1][0][a[i]]+1)
dp[i][2][a[i]] = max(dp[i-1][2][1^a[i]]+1,dp[i-1][1][1^a[i]])
dp[i][2][1 ^ a[i]] = dp[i-1][1][a[i]]+1
ans=0
for i in range(3):
for j in range(2):
ans=max(ans,dp[n-1][i][j])
print(ans)
| 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 lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
|
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"}, {"input": "56\r\n10101011010101010101010101010101010101011010101010101010\r\n", "output": "56\r\n"}, {"input": "50\r\n01011010110101010101010101010101010101010101010100\r\n", "output": "49\r\n"}, {"input": "7\r\n0110100\r\n", "output": "7\r\n"}, {"input": "8\r\n11011111\r\n", "output": "5\r\n"}, {"input": "6\r\n000000\r\n", "output": "3\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "59\r\n10101010101010101010101010101010101010101010101010101010101\r\n", "output": "59\r\n"}, {"input": "88\r\n1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "88\r\n"}, {"input": "93\r\n010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "93\r\n"}, {"input": "70\r\n0101010101010101010101010101010101010101010101010101010101010101010101\r\n", "output": "70\r\n"}, {"input": "78\r\n010101010101010101010101010101101010101010101010101010101010101010101010101010\r\n", "output": "78\r\n"}, {"input": "83\r\n10101010101010101010101010101010101010101010101010110101010101010101010101010101010\r\n", "output": "83\r\n"}, {"input": "87\r\n101010101010101010101010101010101010101010101010101010101010101010101010101010010101010\r\n", "output": "87\r\n"}, {"input": "65\r\n01010101101010101010101010101010101010101010101010101010101010101\r\n", "output": "65\r\n"}, {"input": "69\r\n010101010101010101101010101010101010101010101010101010101010101010101\r\n", "output": "69\r\n"}, {"input": "74\r\n01010101010101010101010101010101010101010101010101010101010101000101010101\r\n", "output": "74\r\n"}, {"input": "77\r\n01010101010101001010101010101010100101010101010101010101010101010101010101010\r\n", "output": "77\r\n"}, {"input": "60\r\n101010110101010101010101010110101010101010101010101010101010\r\n", "output": "60\r\n"}, {"input": "89\r\n01010101010101010101010101010101010101010101010101010101101010101010101010100101010101010\r\n", "output": "89\r\n"}, {"input": "68\r\n01010101010101010101010101010101010100101010100101010101010100101010\r\n", "output": "67\r\n"}, {"input": "73\r\n0101010101010101010101010101010101010101010111011010101010101010101010101\r\n", "output": "72\r\n"}, {"input": "55\r\n1010101010101010010101010101101010101010101010100101010\r\n", "output": "54\r\n"}, {"input": "85\r\n1010101010101010101010101010010101010101010101101010101010101010101011010101010101010\r\n", "output": "84\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n1111111111\r\n", "output": "3\r\n"}, {"input": "2\r\n10\r\n", "output": "2\r\n"}, {"input": "2\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n00\r\n", "output": "2\r\n"}, {"input": "3\r\n000\r\n", "output": "3\r\n"}, {"input": "3\r\n001\r\n", "output": "3\r\n"}, {"input": "3\r\n010\r\n", "output": "3\r\n"}, {"input": "3\r\n011\r\n", "output": "3\r\n"}, {"input": "3\r\n100\r\n", "output": "3\r\n"}, {"input": "3\r\n101\r\n", "output": "3\r\n"}, {"input": "3\r\n110\r\n", "output": "3\r\n"}, {"input": "3\r\n111\r\n", "output": "3\r\n"}, {"input": "4\r\n0000\r\n", "output": "3\r\n"}, {"input": "4\r\n0001\r\n", "output": "4\r\n"}, {"input": "4\r\n0010\r\n", "output": "4\r\n"}, {"input": "4\r\n0011\r\n", "output": "4\r\n"}, {"input": "4\r\n0100\r\n", "output": "4\r\n"}, {"input": "4\r\n0101\r\n", "output": "4\r\n"}, {"input": "4\r\n0110\r\n", "output": "4\r\n"}, {"input": "4\r\n0111\r\n", "output": "4\r\n"}, {"input": "4\r\n1000\r\n", "output": "4\r\n"}, {"input": "4\r\n1001\r\n", "output": "4\r\n"}, {"input": "4\r\n1010\r\n", "output": "4\r\n"}, {"input": "4\r\n1011\r\n", "output": "4\r\n"}, {"input": "4\r\n1100\r\n", "output": "4\r\n"}, {"input": "4\r\n1101\r\n", "output": "4\r\n"}, {"input": "4\r\n1110\r\n", "output": "4\r\n"}, {"input": "4\r\n1111\r\n", "output": "3\r\n"}, {"input": "5\r\n00000\r\n", "output": "3\r\n"}, {"input": "5\r\n00001\r\n", "output": "4\r\n"}, {"input": "5\r\n00010\r\n", "output": "5\r\n"}, {"input": "5\r\n00011\r\n", "output": "4\r\n"}, {"input": "5\r\n00100\r\n", "output": "5\r\n"}, {"input": "5\r\n00101\r\n", "output": "5\r\n"}, {"input": "5\r\n00110\r\n", "output": "5\r\n"}, {"input": "5\r\n00111\r\n", "output": "4\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "5\r\n01001\r\n", "output": "5\r\n"}, {"input": "5\r\n01010\r\n", "output": "5\r\n"}, {"input": "5\r\n01011\r\n", "output": "5\r\n"}, {"input": "5\r\n01100\r\n", "output": "5\r\n"}, {"input": "5\r\n01101\r\n", "output": "5\r\n"}, {"input": "5\r\n01110\r\n", "output": "5\r\n"}, {"input": "5\r\n01111\r\n", "output": "4\r\n"}, {"input": "5\r\n10000\r\n", "output": "4\r\n"}, {"input": "5\r\n10001\r\n", "output": "5\r\n"}, {"input": "5\r\n10010\r\n", "output": "5\r\n"}, {"input": "5\r\n10100\r\n", "output": "5\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "5\r\n10110\r\n", "output": "5\r\n"}, {"input": "5\r\n10111\r\n", "output": "5\r\n"}, {"input": "5\r\n11000\r\n", "output": "4\r\n"}, {"input": "5\r\n11001\r\n", "output": "5\r\n"}, {"input": "5\r\n11010\r\n", "output": "5\r\n"}, {"input": "5\r\n11011\r\n", "output": "5\r\n"}, {"input": "5\r\n11100\r\n", "output": "4\r\n"}, {"input": "5\r\n11101\r\n", "output": "5\r\n"}, {"input": "5\r\n11110\r\n", "output": "4\r\n"}, {"input": "5\r\n11111\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
break
print(ans)
| 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 lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
|
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"}, {"input": "56\r\n10101011010101010101010101010101010101011010101010101010\r\n", "output": "56\r\n"}, {"input": "50\r\n01011010110101010101010101010101010101010101010100\r\n", "output": "49\r\n"}, {"input": "7\r\n0110100\r\n", "output": "7\r\n"}, {"input": "8\r\n11011111\r\n", "output": "5\r\n"}, {"input": "6\r\n000000\r\n", "output": "3\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "59\r\n10101010101010101010101010101010101010101010101010101010101\r\n", "output": "59\r\n"}, {"input": "88\r\n1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "88\r\n"}, {"input": "93\r\n010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "93\r\n"}, {"input": "70\r\n0101010101010101010101010101010101010101010101010101010101010101010101\r\n", "output": "70\r\n"}, {"input": "78\r\n010101010101010101010101010101101010101010101010101010101010101010101010101010\r\n", "output": "78\r\n"}, {"input": "83\r\n10101010101010101010101010101010101010101010101010110101010101010101010101010101010\r\n", "output": "83\r\n"}, {"input": "87\r\n101010101010101010101010101010101010101010101010101010101010101010101010101010010101010\r\n", "output": "87\r\n"}, {"input": "65\r\n01010101101010101010101010101010101010101010101010101010101010101\r\n", "output": "65\r\n"}, {"input": "69\r\n010101010101010101101010101010101010101010101010101010101010101010101\r\n", "output": "69\r\n"}, {"input": "74\r\n01010101010101010101010101010101010101010101010101010101010101000101010101\r\n", "output": "74\r\n"}, {"input": "77\r\n01010101010101001010101010101010100101010101010101010101010101010101010101010\r\n", "output": "77\r\n"}, {"input": "60\r\n101010110101010101010101010110101010101010101010101010101010\r\n", "output": "60\r\n"}, {"input": "89\r\n01010101010101010101010101010101010101010101010101010101101010101010101010100101010101010\r\n", "output": "89\r\n"}, {"input": "68\r\n01010101010101010101010101010101010100101010100101010101010100101010\r\n", "output": "67\r\n"}, {"input": "73\r\n0101010101010101010101010101010101010101010111011010101010101010101010101\r\n", "output": "72\r\n"}, {"input": "55\r\n1010101010101010010101010101101010101010101010100101010\r\n", "output": "54\r\n"}, {"input": "85\r\n1010101010101010101010101010010101010101010101101010101010101010101011010101010101010\r\n", "output": "84\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n1111111111\r\n", "output": "3\r\n"}, {"input": "2\r\n10\r\n", "output": "2\r\n"}, {"input": "2\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n00\r\n", "output": "2\r\n"}, {"input": "3\r\n000\r\n", "output": "3\r\n"}, {"input": "3\r\n001\r\n", "output": "3\r\n"}, {"input": "3\r\n010\r\n", "output": "3\r\n"}, {"input": "3\r\n011\r\n", "output": "3\r\n"}, {"input": "3\r\n100\r\n", "output": "3\r\n"}, {"input": "3\r\n101\r\n", "output": "3\r\n"}, {"input": "3\r\n110\r\n", "output": "3\r\n"}, {"input": "3\r\n111\r\n", "output": "3\r\n"}, {"input": "4\r\n0000\r\n", "output": "3\r\n"}, {"input": "4\r\n0001\r\n", "output": "4\r\n"}, {"input": "4\r\n0010\r\n", "output": "4\r\n"}, {"input": "4\r\n0011\r\n", "output": "4\r\n"}, {"input": "4\r\n0100\r\n", "output": "4\r\n"}, {"input": "4\r\n0101\r\n", "output": "4\r\n"}, {"input": "4\r\n0110\r\n", "output": "4\r\n"}, {"input": "4\r\n0111\r\n", "output": "4\r\n"}, {"input": "4\r\n1000\r\n", "output": "4\r\n"}, {"input": "4\r\n1001\r\n", "output": "4\r\n"}, {"input": "4\r\n1010\r\n", "output": "4\r\n"}, {"input": "4\r\n1011\r\n", "output": "4\r\n"}, {"input": "4\r\n1100\r\n", "output": "4\r\n"}, {"input": "4\r\n1101\r\n", "output": "4\r\n"}, {"input": "4\r\n1110\r\n", "output": "4\r\n"}, {"input": "4\r\n1111\r\n", "output": "3\r\n"}, {"input": "5\r\n00000\r\n", "output": "3\r\n"}, {"input": "5\r\n00001\r\n", "output": "4\r\n"}, {"input": "5\r\n00010\r\n", "output": "5\r\n"}, {"input": "5\r\n00011\r\n", "output": "4\r\n"}, {"input": "5\r\n00100\r\n", "output": "5\r\n"}, {"input": "5\r\n00101\r\n", "output": "5\r\n"}, {"input": "5\r\n00110\r\n", "output": "5\r\n"}, {"input": "5\r\n00111\r\n", "output": "4\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "5\r\n01001\r\n", "output": "5\r\n"}, {"input": "5\r\n01010\r\n", "output": "5\r\n"}, {"input": "5\r\n01011\r\n", "output": "5\r\n"}, {"input": "5\r\n01100\r\n", "output": "5\r\n"}, {"input": "5\r\n01101\r\n", "output": "5\r\n"}, {"input": "5\r\n01110\r\n", "output": "5\r\n"}, {"input": "5\r\n01111\r\n", "output": "4\r\n"}, {"input": "5\r\n10000\r\n", "output": "4\r\n"}, {"input": "5\r\n10001\r\n", "output": "5\r\n"}, {"input": "5\r\n10010\r\n", "output": "5\r\n"}, {"input": "5\r\n10100\r\n", "output": "5\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "5\r\n10110\r\n", "output": "5\r\n"}, {"input": "5\r\n10111\r\n", "output": "5\r\n"}, {"input": "5\r\n11000\r\n", "output": "4\r\n"}, {"input": "5\r\n11001\r\n", "output": "5\r\n"}, {"input": "5\r\n11010\r\n", "output": "5\r\n"}, {"input": "5\r\n11011\r\n", "output": "5\r\n"}, {"input": "5\r\n11100\r\n", "output": "4\r\n"}, {"input": "5\r\n11101\r\n", "output": "5\r\n"}, {"input": "5\r\n11110\r\n", "output": "4\r\n"}, {"input": "5\r\n11111\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:
inc[i] = inc[i - 1]
dec[i] = dec[i - 1]
subsec = max(max(inc), max(dec))
print(min(subsec + 2, n))
|
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 lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
|
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"}, {"input": "56\r\n10101011010101010101010101010101010101011010101010101010\r\n", "output": "56\r\n"}, {"input": "50\r\n01011010110101010101010101010101010101010101010100\r\n", "output": "49\r\n"}, {"input": "7\r\n0110100\r\n", "output": "7\r\n"}, {"input": "8\r\n11011111\r\n", "output": "5\r\n"}, {"input": "6\r\n000000\r\n", "output": "3\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "59\r\n10101010101010101010101010101010101010101010101010101010101\r\n", "output": "59\r\n"}, {"input": "88\r\n1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "88\r\n"}, {"input": "93\r\n010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "93\r\n"}, {"input": "70\r\n0101010101010101010101010101010101010101010101010101010101010101010101\r\n", "output": "70\r\n"}, {"input": "78\r\n010101010101010101010101010101101010101010101010101010101010101010101010101010\r\n", "output": "78\r\n"}, {"input": "83\r\n10101010101010101010101010101010101010101010101010110101010101010101010101010101010\r\n", "output": "83\r\n"}, {"input": "87\r\n101010101010101010101010101010101010101010101010101010101010101010101010101010010101010\r\n", "output": "87\r\n"}, {"input": "65\r\n01010101101010101010101010101010101010101010101010101010101010101\r\n", "output": "65\r\n"}, {"input": "69\r\n010101010101010101101010101010101010101010101010101010101010101010101\r\n", "output": "69\r\n"}, {"input": "74\r\n01010101010101010101010101010101010101010101010101010101010101000101010101\r\n", "output": "74\r\n"}, {"input": "77\r\n01010101010101001010101010101010100101010101010101010101010101010101010101010\r\n", "output": "77\r\n"}, {"input": "60\r\n101010110101010101010101010110101010101010101010101010101010\r\n", "output": "60\r\n"}, {"input": "89\r\n01010101010101010101010101010101010101010101010101010101101010101010101010100101010101010\r\n", "output": "89\r\n"}, {"input": "68\r\n01010101010101010101010101010101010100101010100101010101010100101010\r\n", "output": "67\r\n"}, {"input": "73\r\n0101010101010101010101010101010101010101010111011010101010101010101010101\r\n", "output": "72\r\n"}, {"input": "55\r\n1010101010101010010101010101101010101010101010100101010\r\n", "output": "54\r\n"}, {"input": "85\r\n1010101010101010101010101010010101010101010101101010101010101010101011010101010101010\r\n", "output": "84\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n1111111111\r\n", "output": "3\r\n"}, {"input": "2\r\n10\r\n", "output": "2\r\n"}, {"input": "2\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n00\r\n", "output": "2\r\n"}, {"input": "3\r\n000\r\n", "output": "3\r\n"}, {"input": "3\r\n001\r\n", "output": "3\r\n"}, {"input": "3\r\n010\r\n", "output": "3\r\n"}, {"input": "3\r\n011\r\n", "output": "3\r\n"}, {"input": "3\r\n100\r\n", "output": "3\r\n"}, {"input": "3\r\n101\r\n", "output": "3\r\n"}, {"input": "3\r\n110\r\n", "output": "3\r\n"}, {"input": "3\r\n111\r\n", "output": "3\r\n"}, {"input": "4\r\n0000\r\n", "output": "3\r\n"}, {"input": "4\r\n0001\r\n", "output": "4\r\n"}, {"input": "4\r\n0010\r\n", "output": "4\r\n"}, {"input": "4\r\n0011\r\n", "output": "4\r\n"}, {"input": "4\r\n0100\r\n", "output": "4\r\n"}, {"input": "4\r\n0101\r\n", "output": "4\r\n"}, {"input": "4\r\n0110\r\n", "output": "4\r\n"}, {"input": "4\r\n0111\r\n", "output": "4\r\n"}, {"input": "4\r\n1000\r\n", "output": "4\r\n"}, {"input": "4\r\n1001\r\n", "output": "4\r\n"}, {"input": "4\r\n1010\r\n", "output": "4\r\n"}, {"input": "4\r\n1011\r\n", "output": "4\r\n"}, {"input": "4\r\n1100\r\n", "output": "4\r\n"}, {"input": "4\r\n1101\r\n", "output": "4\r\n"}, {"input": "4\r\n1110\r\n", "output": "4\r\n"}, {"input": "4\r\n1111\r\n", "output": "3\r\n"}, {"input": "5\r\n00000\r\n", "output": "3\r\n"}, {"input": "5\r\n00001\r\n", "output": "4\r\n"}, {"input": "5\r\n00010\r\n", "output": "5\r\n"}, {"input": "5\r\n00011\r\n", "output": "4\r\n"}, {"input": "5\r\n00100\r\n", "output": "5\r\n"}, {"input": "5\r\n00101\r\n", "output": "5\r\n"}, {"input": "5\r\n00110\r\n", "output": "5\r\n"}, {"input": "5\r\n00111\r\n", "output": "4\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "5\r\n01001\r\n", "output": "5\r\n"}, {"input": "5\r\n01010\r\n", "output": "5\r\n"}, {"input": "5\r\n01011\r\n", "output": "5\r\n"}, {"input": "5\r\n01100\r\n", "output": "5\r\n"}, {"input": "5\r\n01101\r\n", "output": "5\r\n"}, {"input": "5\r\n01110\r\n", "output": "5\r\n"}, {"input": "5\r\n01111\r\n", "output": "4\r\n"}, {"input": "5\r\n10000\r\n", "output": "4\r\n"}, {"input": "5\r\n10001\r\n", "output": "5\r\n"}, {"input": "5\r\n10010\r\n", "output": "5\r\n"}, {"input": "5\r\n10100\r\n", "output": "5\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "5\r\n10110\r\n", "output": "5\r\n"}, {"input": "5\r\n10111\r\n", "output": "5\r\n"}, {"input": "5\r\n11000\r\n", "output": "4\r\n"}, {"input": "5\r\n11001\r\n", "output": "5\r\n"}, {"input": "5\r\n11010\r\n", "output": "5\r\n"}, {"input": "5\r\n11011\r\n", "output": "5\r\n"}, {"input": "5\r\n11100\r\n", "output": "4\r\n"}, {"input": "5\r\n11101\r\n", "output": "5\r\n"}, {"input": "5\r\n11110\r\n", "output": "4\r\n"}, {"input": "5\r\n11111\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 = True
prev = x
if cons or oppo > 1:
changes += 2
elif oppo == 1:
changes += 1
print(changes+1)
| 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 lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
|
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"}, {"input": "56\r\n10101011010101010101010101010101010101011010101010101010\r\n", "output": "56\r\n"}, {"input": "50\r\n01011010110101010101010101010101010101010101010100\r\n", "output": "49\r\n"}, {"input": "7\r\n0110100\r\n", "output": "7\r\n"}, {"input": "8\r\n11011111\r\n", "output": "5\r\n"}, {"input": "6\r\n000000\r\n", "output": "3\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "59\r\n10101010101010101010101010101010101010101010101010101010101\r\n", "output": "59\r\n"}, {"input": "88\r\n1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "88\r\n"}, {"input": "93\r\n010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "93\r\n"}, {"input": "70\r\n0101010101010101010101010101010101010101010101010101010101010101010101\r\n", "output": "70\r\n"}, {"input": "78\r\n010101010101010101010101010101101010101010101010101010101010101010101010101010\r\n", "output": "78\r\n"}, {"input": "83\r\n10101010101010101010101010101010101010101010101010110101010101010101010101010101010\r\n", "output": "83\r\n"}, {"input": "87\r\n101010101010101010101010101010101010101010101010101010101010101010101010101010010101010\r\n", "output": "87\r\n"}, {"input": "65\r\n01010101101010101010101010101010101010101010101010101010101010101\r\n", "output": "65\r\n"}, {"input": "69\r\n010101010101010101101010101010101010101010101010101010101010101010101\r\n", "output": "69\r\n"}, {"input": "74\r\n01010101010101010101010101010101010101010101010101010101010101000101010101\r\n", "output": "74\r\n"}, {"input": "77\r\n01010101010101001010101010101010100101010101010101010101010101010101010101010\r\n", "output": "77\r\n"}, {"input": "60\r\n101010110101010101010101010110101010101010101010101010101010\r\n", "output": "60\r\n"}, {"input": "89\r\n01010101010101010101010101010101010101010101010101010101101010101010101010100101010101010\r\n", "output": "89\r\n"}, {"input": "68\r\n01010101010101010101010101010101010100101010100101010101010100101010\r\n", "output": "67\r\n"}, {"input": "73\r\n0101010101010101010101010101010101010101010111011010101010101010101010101\r\n", "output": "72\r\n"}, {"input": "55\r\n1010101010101010010101010101101010101010101010100101010\r\n", "output": "54\r\n"}, {"input": "85\r\n1010101010101010101010101010010101010101010101101010101010101010101011010101010101010\r\n", "output": "84\r\n"}, {"input": "1\r\n0\r\n", "output": "1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n1111111111\r\n", "output": "3\r\n"}, {"input": "2\r\n10\r\n", "output": "2\r\n"}, {"input": "2\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n00\r\n", "output": "2\r\n"}, {"input": "3\r\n000\r\n", "output": "3\r\n"}, {"input": "3\r\n001\r\n", "output": "3\r\n"}, {"input": "3\r\n010\r\n", "output": "3\r\n"}, {"input": "3\r\n011\r\n", "output": "3\r\n"}, {"input": "3\r\n100\r\n", "output": "3\r\n"}, {"input": "3\r\n101\r\n", "output": "3\r\n"}, {"input": "3\r\n110\r\n", "output": "3\r\n"}, {"input": "3\r\n111\r\n", "output": "3\r\n"}, {"input": "4\r\n0000\r\n", "output": "3\r\n"}, {"input": "4\r\n0001\r\n", "output": "4\r\n"}, {"input": "4\r\n0010\r\n", "output": "4\r\n"}, {"input": "4\r\n0011\r\n", "output": "4\r\n"}, {"input": "4\r\n0100\r\n", "output": "4\r\n"}, {"input": "4\r\n0101\r\n", "output": "4\r\n"}, {"input": "4\r\n0110\r\n", "output": "4\r\n"}, {"input": "4\r\n0111\r\n", "output": "4\r\n"}, {"input": "4\r\n1000\r\n", "output": "4\r\n"}, {"input": "4\r\n1001\r\n", "output": "4\r\n"}, {"input": "4\r\n1010\r\n", "output": "4\r\n"}, {"input": "4\r\n1011\r\n", "output": "4\r\n"}, {"input": "4\r\n1100\r\n", "output": "4\r\n"}, {"input": "4\r\n1101\r\n", "output": "4\r\n"}, {"input": "4\r\n1110\r\n", "output": "4\r\n"}, {"input": "4\r\n1111\r\n", "output": "3\r\n"}, {"input": "5\r\n00000\r\n", "output": "3\r\n"}, {"input": "5\r\n00001\r\n", "output": "4\r\n"}, {"input": "5\r\n00010\r\n", "output": "5\r\n"}, {"input": "5\r\n00011\r\n", "output": "4\r\n"}, {"input": "5\r\n00100\r\n", "output": "5\r\n"}, {"input": "5\r\n00101\r\n", "output": "5\r\n"}, {"input": "5\r\n00110\r\n", "output": "5\r\n"}, {"input": "5\r\n00111\r\n", "output": "4\r\n"}, {"input": "5\r\n01000\r\n", "output": "5\r\n"}, {"input": "5\r\n01001\r\n", "output": "5\r\n"}, {"input": "5\r\n01010\r\n", "output": "5\r\n"}, {"input": "5\r\n01011\r\n", "output": "5\r\n"}, {"input": "5\r\n01100\r\n", "output": "5\r\n"}, {"input": "5\r\n01101\r\n", "output": "5\r\n"}, {"input": "5\r\n01110\r\n", "output": "5\r\n"}, {"input": "5\r\n01111\r\n", "output": "4\r\n"}, {"input": "5\r\n10000\r\n", "output": "4\r\n"}, {"input": "5\r\n10001\r\n", "output": "5\r\n"}, {"input": "5\r\n10010\r\n", "output": "5\r\n"}, {"input": "5\r\n10100\r\n", "output": "5\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "5\r\n10110\r\n", "output": "5\r\n"}, {"input": "5\r\n10111\r\n", "output": "5\r\n"}, {"input": "5\r\n11000\r\n", "output": "4\r\n"}, {"input": "5\r\n11001\r\n", "output": "5\r\n"}, {"input": "5\r\n11010\r\n", "output": "5\r\n"}, {"input": "5\r\n11011\r\n", "output": "5\r\n"}, {"input": "5\r\n11100\r\n", "output": "4\r\n"}, {"input": "5\r\n11101\r\n", "output": "5\r\n"}, {"input": "5\r\n11110\r\n", "output": "4\r\n"}, {"input": "5\r\n11111\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('')
ans[-1]+=c
cnt=1
seen.add(c)
else:
ans[-1]+=c
print(' '.join(ans))
| 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
for i in range(len(s)):
if ind < len(spaces) and spaces[ind] == i:
sys.stdout.write(' ')
ind += 1
sys.stdout.write(s[i])
|
Технокубок 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 three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
- the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
|
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"}, {"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz\r\n", "output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz \r\n"}, {"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte\r\n", "output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te \r\n"}, {"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz\r\n", "output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz \r\n"}, {"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf\r\n", "output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf \r\n"}, {"input": "mvjajoyeg\r\n", "output": "mv jajoyeg \r\n"}, {"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq\r\n", "output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q \r\n"}, {"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef\r\n", "output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef \r\n"}, {"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj\r\n", "output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j \r\n"}, {"input": "hzxkuwqxonsulnndlhygvmallghjerwp\r\n", "output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p \r\n"}, {"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd\r\n", "output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d \r\n"}, {"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr\r\n", "output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r \r\n"}, {"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu\r\n", "output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu \r\n"}, {"input": "a\r\n", "output": "a \r\n"}, {"input": "b\r\n", "output": "b \r\n"}, {"input": "aa\r\n", "output": "aa \r\n"}, {"input": "ab\r\n", "output": "ab \r\n"}, {"input": "ba\r\n", "output": "ba \r\n"}, {"input": "bb\r\n", "output": "bb \r\n"}, {"input": "aaa\r\n", "output": "aaa \r\n"}, {"input": "aab\r\n", "output": "aab \r\n"}, {"input": "aba\r\n", "output": "aba \r\n"}, {"input": "abb\r\n", "output": "abb \r\n"}, {"input": "baa\r\n", "output": "baa \r\n"}, {"input": "bab\r\n", "output": "bab \r\n"}, {"input": "bba\r\n", "output": "bba \r\n"}, {"input": "bbb\r\n", "output": "bbb \r\n"}, {"input": "bbc\r\n", "output": "bb c \r\n"}, {"input": "bcb\r\n", "output": "bc b \r\n"}, {"input": "cbb\r\n", "output": "cb b \r\n"}, {"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc\r\n", "output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc \r\n"}, {"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb\r\n", "output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b \r\n"}, {"input": "helllllooooo\r\n", "output": "helllllooooo \r\n"}, {"input": "bbbzxxx\r\n", "output": "bbb zx xx \r\n"}, {"input": "ffff\r\n", "output": "ffff \r\n"}, {"input": "cdddddddddddddddddd\r\n", "output": "cd ddddddddddddddddd \r\n"}, {"input": "bbbc\r\n", "output": "bbb c \r\n"}, {"input": "lll\r\n", "output": "lll \r\n"}, {"input": "bbbbb\r\n", "output": "bbbbb \r\n"}, {"input": "llll\r\n", "output": "llll \r\n"}, {"input": "bbbbbbccc\r\n", "output": "bbbbbb ccc \r\n"}, {"input": "lllllb\r\n", "output": "lllll b \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "lllll\r\n", "output": "lllll \r\n"}, {"input": "bbbbbbbbbc\r\n", "output": "bbbbbbbbb c \r\n"}, {"input": "helllllno\r\n", "output": "helllll no \r\n"}, {"input": "nnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnn \r\n"}, {"input": "bbbbbccc\r\n", "output": "bbbbb ccc \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "nnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "hhhh\r\n", "output": "hhhh \r\n"}, {"input": "nnnnnnnnnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzz\r\n", "output": "zzzzzzzzzz \r\n"}, {"input": "dddd\r\n", "output": "dddd \r\n"}, {"input": "heffffffgggggghhhhhh\r\n", "output": "heffffff gggggg hhhhhh \r\n"}, {"input": "bcddd\r\n", "output": "bc ddd \r\n"}, {"input": "x\r\n", "output": "x \r\n"}, {"input": "nnn\r\n", "output": "nnn \r\n"}, {"input": "xxxxxxxx\r\n", "output": "xxxxxxxx \r\n"}, {"input": "cclcc\r\n", "output": "cc lc c \r\n"}, {"input": "tttttttttttttt\r\n", "output": "tttttttttttttt \r\n"}, {"input": "xxxxxxx\r\n", "output": "xxxxxxx \r\n"}, {"input": "ccccb\r\n", "output": "cccc b \r\n"}, {"input": "bcecccc\r\n", "output": "bcecccc \r\n"}, {"input": "jjja\r\n", "output": "jjja \r\n"}, {"input": "zzz\r\n", "output": "zzz \r\n"}, {"input": "xxxxxxxxxzzzzzzzzzzzz\r\n", "output": "xxxxxxxxx zzzzzzzzzzzz \r\n"}, {"input": "alllewww\r\n", "output": "alllewww \r\n"}, {"input": "bbbbbbbbb\r\n", "output": "bbbbbbbbb \r\n"}, {"input": "jjj\r\n", "output": "jjj \r\n"}, {"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\r\n", "output": "bbbbbbbbbbbbbbbbbbbbbbbbb \r\n"}, {"input": "kkkkkkkkkklllllllllllllll\r\n", "output": "kkkkkkkkkk lllllllllllllll \r\n"}, {"input": "helllllllllllo\r\n", "output": "helllllllllllo \r\n"}, {"input": "ttttsttttt\r\n", "output": "tttt st tttt \r\n"}, {"input": "tttttttsssssss\r\n", "output": "ttttttt sssssss \r\n"}, {"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss\r\n", "output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss \r\n"}, {"input": "xxxxx\r\n", "output": "xxxxx \r\n"}, {"input": "bbbhbbb\r\n", "output": "bbb hb bb \r\n"}, {"input": "bbbbbbbb\r\n", "output": "bbbbbbbb \r\n"}]
| 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()
seen.add(ch)
p=1
else :
ans+=ch
seen=set()
seen.add(ch)
p=1
else :
ans+=ch
seen.add(ch)
p+=1
print(ans)
| 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 three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
- the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
|
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"}, {"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz\r\n", "output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz \r\n"}, {"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte\r\n", "output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te \r\n"}, {"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz\r\n", "output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz \r\n"}, {"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf\r\n", "output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf \r\n"}, {"input": "mvjajoyeg\r\n", "output": "mv jajoyeg \r\n"}, {"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq\r\n", "output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q \r\n"}, {"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef\r\n", "output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef \r\n"}, {"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj\r\n", "output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j \r\n"}, {"input": "hzxkuwqxonsulnndlhygvmallghjerwp\r\n", "output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p \r\n"}, {"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd\r\n", "output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d \r\n"}, {"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr\r\n", "output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r \r\n"}, {"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu\r\n", "output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu \r\n"}, {"input": "a\r\n", "output": "a \r\n"}, {"input": "b\r\n", "output": "b \r\n"}, {"input": "aa\r\n", "output": "aa \r\n"}, {"input": "ab\r\n", "output": "ab \r\n"}, {"input": "ba\r\n", "output": "ba \r\n"}, {"input": "bb\r\n", "output": "bb \r\n"}, {"input": "aaa\r\n", "output": "aaa \r\n"}, {"input": "aab\r\n", "output": "aab \r\n"}, {"input": "aba\r\n", "output": "aba \r\n"}, {"input": "abb\r\n", "output": "abb \r\n"}, {"input": "baa\r\n", "output": "baa \r\n"}, {"input": "bab\r\n", "output": "bab \r\n"}, {"input": "bba\r\n", "output": "bba \r\n"}, {"input": "bbb\r\n", "output": "bbb \r\n"}, {"input": "bbc\r\n", "output": "bb c \r\n"}, {"input": "bcb\r\n", "output": "bc b \r\n"}, {"input": "cbb\r\n", "output": "cb b \r\n"}, {"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc\r\n", "output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc \r\n"}, {"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb\r\n", "output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b \r\n"}, {"input": "helllllooooo\r\n", "output": "helllllooooo \r\n"}, {"input": "bbbzxxx\r\n", "output": "bbb zx xx \r\n"}, {"input": "ffff\r\n", "output": "ffff \r\n"}, {"input": "cdddddddddddddddddd\r\n", "output": "cd ddddddddddddddddd \r\n"}, {"input": "bbbc\r\n", "output": "bbb c \r\n"}, {"input": "lll\r\n", "output": "lll \r\n"}, {"input": "bbbbb\r\n", "output": "bbbbb \r\n"}, {"input": "llll\r\n", "output": "llll \r\n"}, {"input": "bbbbbbccc\r\n", "output": "bbbbbb ccc \r\n"}, {"input": "lllllb\r\n", "output": "lllll b \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "lllll\r\n", "output": "lllll \r\n"}, {"input": "bbbbbbbbbc\r\n", "output": "bbbbbbbbb c \r\n"}, {"input": "helllllno\r\n", "output": "helllll no \r\n"}, {"input": "nnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnn \r\n"}, {"input": "bbbbbccc\r\n", "output": "bbbbb ccc \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "nnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "hhhh\r\n", "output": "hhhh \r\n"}, {"input": "nnnnnnnnnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzz\r\n", "output": "zzzzzzzzzz \r\n"}, {"input": "dddd\r\n", "output": "dddd \r\n"}, {"input": "heffffffgggggghhhhhh\r\n", "output": "heffffff gggggg hhhhhh \r\n"}, {"input": "bcddd\r\n", "output": "bc ddd \r\n"}, {"input": "x\r\n", "output": "x \r\n"}, {"input": "nnn\r\n", "output": "nnn \r\n"}, {"input": "xxxxxxxx\r\n", "output": "xxxxxxxx \r\n"}, {"input": "cclcc\r\n", "output": "cc lc c \r\n"}, {"input": "tttttttttttttt\r\n", "output": "tttttttttttttt \r\n"}, {"input": "xxxxxxx\r\n", "output": "xxxxxxx \r\n"}, {"input": "ccccb\r\n", "output": "cccc b \r\n"}, {"input": "bcecccc\r\n", "output": "bcecccc \r\n"}, {"input": "jjja\r\n", "output": "jjja \r\n"}, {"input": "zzz\r\n", "output": "zzz \r\n"}, {"input": "xxxxxxxxxzzzzzzzzzzzz\r\n", "output": "xxxxxxxxx zzzzzzzzzzzz \r\n"}, {"input": "alllewww\r\n", "output": "alllewww \r\n"}, {"input": "bbbbbbbbb\r\n", "output": "bbbbbbbbb \r\n"}, {"input": "jjj\r\n", "output": "jjj \r\n"}, {"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\r\n", "output": "bbbbbbbbbbbbbbbbbbbbbbbbb \r\n"}, {"input": "kkkkkkkkkklllllllllllllll\r\n", "output": "kkkkkkkkkk lllllllllllllll \r\n"}, {"input": "helllllllllllo\r\n", "output": "helllllllllllo \r\n"}, {"input": "ttttsttttt\r\n", "output": "tttt st tttt \r\n"}, {"input": "tttttttsssssss\r\n", "output": "ttttttt sssssss \r\n"}, {"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss\r\n", "output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss \r\n"}, {"input": "xxxxx\r\n", "output": "xxxxx \r\n"}, {"input": "bbbhbbb\r\n", "output": "bbb hb bb \r\n"}, {"input": "bbbbbbbb\r\n", "output": "bbbbbbbb \r\n"}]
| 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(word)):
letter = word[i]
if (isVowel(letter)):
conCount = 0
block.clear()
else:
conCount += 1
block.add(letter)
if (len(block) > 1 and conCount >= 3):
isTypo = True
newWord = insert(newWord, " ", i + cutCount)
cutCount += 1
conCount = 1
block.clear()
block.add(letter)
if (isTypo):
print(newWord)
else:
print(word)
|
Технокубок 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 three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
- the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
|
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"}, {"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz\r\n", "output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz \r\n"}, {"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte\r\n", "output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te \r\n"}, {"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz\r\n", "output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz \r\n"}, {"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf\r\n", "output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf \r\n"}, {"input": "mvjajoyeg\r\n", "output": "mv jajoyeg \r\n"}, {"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq\r\n", "output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q \r\n"}, {"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef\r\n", "output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef \r\n"}, {"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj\r\n", "output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j \r\n"}, {"input": "hzxkuwqxonsulnndlhygvmallghjerwp\r\n", "output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p \r\n"}, {"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd\r\n", "output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d \r\n"}, {"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr\r\n", "output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r \r\n"}, {"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu\r\n", "output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu \r\n"}, {"input": "a\r\n", "output": "a \r\n"}, {"input": "b\r\n", "output": "b \r\n"}, {"input": "aa\r\n", "output": "aa \r\n"}, {"input": "ab\r\n", "output": "ab \r\n"}, {"input": "ba\r\n", "output": "ba \r\n"}, {"input": "bb\r\n", "output": "bb \r\n"}, {"input": "aaa\r\n", "output": "aaa \r\n"}, {"input": "aab\r\n", "output": "aab \r\n"}, {"input": "aba\r\n", "output": "aba \r\n"}, {"input": "abb\r\n", "output": "abb \r\n"}, {"input": "baa\r\n", "output": "baa \r\n"}, {"input": "bab\r\n", "output": "bab \r\n"}, {"input": "bba\r\n", "output": "bba \r\n"}, {"input": "bbb\r\n", "output": "bbb \r\n"}, {"input": "bbc\r\n", "output": "bb c \r\n"}, {"input": "bcb\r\n", "output": "bc b \r\n"}, {"input": "cbb\r\n", "output": "cb b \r\n"}, {"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc\r\n", "output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc \r\n"}, {"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb\r\n", "output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b \r\n"}, {"input": "helllllooooo\r\n", "output": "helllllooooo \r\n"}, {"input": "bbbzxxx\r\n", "output": "bbb zx xx \r\n"}, {"input": "ffff\r\n", "output": "ffff \r\n"}, {"input": "cdddddddddddddddddd\r\n", "output": "cd ddddddddddddddddd \r\n"}, {"input": "bbbc\r\n", "output": "bbb c \r\n"}, {"input": "lll\r\n", "output": "lll \r\n"}, {"input": "bbbbb\r\n", "output": "bbbbb \r\n"}, {"input": "llll\r\n", "output": "llll \r\n"}, {"input": "bbbbbbccc\r\n", "output": "bbbbbb ccc \r\n"}, {"input": "lllllb\r\n", "output": "lllll b \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "lllll\r\n", "output": "lllll \r\n"}, {"input": "bbbbbbbbbc\r\n", "output": "bbbbbbbbb c \r\n"}, {"input": "helllllno\r\n", "output": "helllll no \r\n"}, {"input": "nnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnn \r\n"}, {"input": "bbbbbccc\r\n", "output": "bbbbb ccc \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "nnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "hhhh\r\n", "output": "hhhh \r\n"}, {"input": "nnnnnnnnnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzz\r\n", "output": "zzzzzzzzzz \r\n"}, {"input": "dddd\r\n", "output": "dddd \r\n"}, {"input": "heffffffgggggghhhhhh\r\n", "output": "heffffff gggggg hhhhhh \r\n"}, {"input": "bcddd\r\n", "output": "bc ddd \r\n"}, {"input": "x\r\n", "output": "x \r\n"}, {"input": "nnn\r\n", "output": "nnn \r\n"}, {"input": "xxxxxxxx\r\n", "output": "xxxxxxxx \r\n"}, {"input": "cclcc\r\n", "output": "cc lc c \r\n"}, {"input": "tttttttttttttt\r\n", "output": "tttttttttttttt \r\n"}, {"input": "xxxxxxx\r\n", "output": "xxxxxxx \r\n"}, {"input": "ccccb\r\n", "output": "cccc b \r\n"}, {"input": "bcecccc\r\n", "output": "bcecccc \r\n"}, {"input": "jjja\r\n", "output": "jjja \r\n"}, {"input": "zzz\r\n", "output": "zzz \r\n"}, {"input": "xxxxxxxxxzzzzzzzzzzzz\r\n", "output": "xxxxxxxxx zzzzzzzzzzzz \r\n"}, {"input": "alllewww\r\n", "output": "alllewww \r\n"}, {"input": "bbbbbbbbb\r\n", "output": "bbbbbbbbb \r\n"}, {"input": "jjj\r\n", "output": "jjj \r\n"}, {"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\r\n", "output": "bbbbbbbbbbbbbbbbbbbbbbbbb \r\n"}, {"input": "kkkkkkkkkklllllllllllllll\r\n", "output": "kkkkkkkkkk lllllllllllllll \r\n"}, {"input": "helllllllllllo\r\n", "output": "helllllllllllo \r\n"}, {"input": "ttttsttttt\r\n", "output": "tttt st tttt \r\n"}, {"input": "tttttttsssssss\r\n", "output": "ttttttt sssssss \r\n"}, {"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss\r\n", "output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss \r\n"}, {"input": "xxxxx\r\n", "output": "xxxxx \r\n"}, {"input": "bbbhbbb\r\n", "output": "bbb hb bb \r\n"}, {"input": "bbbbbbbb\r\n", "output": "bbbbbbbb \r\n"}]
| 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]), reverse=True)
a = d2[0]
my_max = len(d[a][0])+len(d[a][1])
for i in range(len(d2)):
a1 = d2[i]
S1 = len(d[a1][0])+len(d[a1][1])
if 2*S1 < my_max:
break
for j in range(i+1):
a2 = d2[j]
S2 = len(d[a2][0])+len(d[a2][1])
if S1+S2 < my_max:
break
R1 = len(d[a1][0].union(d[a2][0]))
R2 = len(d[a1][1].union(d[a2][1]))
my_max = max(my_max, R1+R2)
return my_max
n, m = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
print(process(A, B))
| 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)
a[f+s].add(sid)
a.sort(key = lambda x: -len(x))
b = [len(k) for k in a]
# for k in range(MV):
# if b[k]>0:
# print(k, b[k], a[k])
best_res = b[0]
for pos in range(MV):
for pos2 in range(MV):
if b[pos] + b [pos2] <= best_res:
break
cur = len(a[pos].union(a[pos2]))
if cur > best_res :
best_res = cur
print(best_res)
|
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 positioned in such a way that they all have integer $$$y$$$-coordinates, and their $$$x$$$-coordinate is equal to $$$100$$$.
Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with $$$x=0$$$ (with not necessarily integer $$$y$$$-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots.
|
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$$$) — the $$$y$$$-coordinates of the spaceships in the first group.
The third line contains $$$m$$$ integers $$$y_{2,1}, y_{2,2}, \ldots, y_{2,m}$$$ ($$$|y_{2,i}| \le 10\,000$$$) — the $$$y$$$-coordinates of the spaceships in the second group.
The $$$y$$$ coordinates are not guaranteed to be unique, even within a group.
|
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)$$$, and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
|
[{"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 414 434 146 602 235 86 240 756 161 675\r\n222 371 393 634 76 268 348 294 227 429 835 534 756 67 174 704 685 462 829 561 249 148 868 512 118 232 33 450 445 420 397 129 122 74 426 441 989 892 662 727 492 702 352 818 399 968 894 297 342 405\r\n", "output": "29\r\n"}, {"input": "60 60\r\n842 229 415 973 606 880 422 808 121 317 41 358 725 32 395 286 819 550 410 516 81 599 623 275 568 102 778 234 385 445 194 89 105 643 220 165 872 858 420 653 843 465 696 723 594 8 127 273 289 345 260 553 231 940 912 687 205 272 14 706\r\n855 361 529 341 602 225 922 807 775 149 212 789 547 766 813 624 236 583 207 586 516 21 621 839 259 774 419 286 537 284 685 944 223 189 358 232 495 688 877 920 400 105 968 919 543 700 538 466 739 33 729 292 891 797 707 174 799 427 321 953\r\n", "output": "40\r\n"}, {"input": "1 5\r\n1\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "5 1\r\n1 2 3 4 5\r\n1\r\n", "output": "3\r\n"}, {"input": "2 2\r\n-10000 10000\r\n-10000 10000\r\n", "output": "4\r\n"}, {"input": "8 57\r\n-107 1000 -238 -917 -918 668 -769 360\r\n124 250 601 242 189 155 688 -886 -504 39 -924 -266 -122 109 232 216 567 576 269 -349 257 589 -462 939 977 0 -808 118 -423 -856 769 954 889 21 996 -714 198 -854 981 -99 554 302 -27 454 -557 -585 465 -513 -113 714 -82 -906 522 75 -866 -942 -293\r\n", "output": "8\r\n"}, {"input": "43 48\r\n-10 -4 -4 3 -4 3 -1 9 10 4 -2 -8 -9 -6 4 0 4 3 -1 -3 -1 7 10 -2 6 6 -4 -7 7 10 -5 -2 9 -4 -3 -1 -3 -9 0 -5 -6 -7 2\r\n-8 10 8 4 -3 7 2 -6 10 -1 4 -8 1 3 -8 5 2 4 8 7 -4 -7 8 -8 2 4 -2 4 2 1 -4 9 -3 -9 -1 6 -9 1 -6 -4 6 -2 3 5 5 6 -3 -3\r\n", "output": "91\r\n"}, {"input": "8 9\r\n782 -300 482 -158 -755 809 -125 27\r\n0 251 593 796 371 839 -892 -954 236\r\n", "output": "4\r\n"}, {"input": "54 41\r\n-5 9 -4 -7 8 -2 -5 -3 -10 -10 -9 2 9 1 -8 -5 -5 -3 1 -7 -2 -8 -5 -1 2 6 -2 -10 -7 5 2 -4 -9 -2 4 -6 5 5 -3 7 -5 2 7 0 -3 8 -10 5 6 -4 -7 3 -9 6\r\n-5 -5 10 3 2 5 -3 4 -5 -6 2 9 -7 3 0 -3 -10 -6 -5 -5 9 0 1 -6 1 0 -9 8 -10 -3 -2 -10 4 -1 -3 -10 -6 -7 -6 -3 2\r\n", "output": "95\r\n"}, {"input": "46 52\r\n-31 11 38 -71 38 39 57 -31 -2 85 25 -85 17 -8 93 -1 75 -89 22 -61 -66 63 -91 80 -66 19 57 86 42 36 16 -65 -76 53 -21 85 -66 -96 85 45 35 29 54 18 -94 78\r\n-14 65 94 33 42 23 94 98 -44 -68 5 -27 -5 50 30 -56 49 -31 -61 34 9 -63 -92 48 17 99 -98 54 -13 34 46 13 -38 81 6 -58 68 -97 21 97 84 -10 5 11 99 -65 36 99 23 -20 -81 50\r\n", "output": "53\r\n"}, {"input": "51 49\r\n-6 6 -4 -9 10 -5 1 -7 10 -7 -9 7 -6 5 -7 -5 5 6 -1 9 -10 6 -9 -7 1 7 6 -2 -6 0 -9 5 3 -9 0 8 -8 -5 -6 3 0 2 -1 -8 -3 -4 -8 0 1 -7 10\r\n-9 -4 10 -1 4 7 -2 5 -4 -8 0 -2 -10 10 9 9 10 -6 -8 -3 -6 -7 2 1 -4 -4 5 -5 5 2 8 -3 -7 5 10 7 2 -2 6 7 6 -3 -4 -8 -7 -3 5 -7 4\r\n", "output": "100\r\n"}, {"input": "49 45\r\n293 126 883 638 33 -235 -591 -317 -532 -850 367 249 -470 373 -438 866 271 357 423 -972 -358 -418 531 -255 524 831 -200 -677 -424 -486 513 84 -598 86 525 -612 749 -525 -904 -773 599 170 -385 -44 40 979 -963 320 -875\r\n-197 47 -399 -7 605 -94 371 -752 370 459 297 775 -144 91 895 871 774 997 71 -23 301 138 241 891 -806 -990 111 -120 -233 552 557 633 -221 -804 713 -384 404 13 345 4 -759 -826 148 889 -270\r\n", "output": "20\r\n"}, {"input": "59 50\r\n-85 -30 33 10 94 91 -53 58 -21 68 5 76 -61 -35 9 -19 -32 8 57 -75 -49 57 92 8 92 -39 98 -81 -55 -79 -9 36 19 57 -32 11 -68 60 -20 25 -65 1 -25 -59 -65 -30 93 -60 59 10 -92 -76 -83 71 -89 33 1 60 -65\r\n39 -57 -21 -13 9 34 -93 -11 56 0 -40 -85 18 -96 66 -29 -64 52 -61 -20 67 54 -20 83 -8 -20 75 37 75 -81 37 -67 -89 -91 -30 86 93 58 33 62 -68 -48 87 -7 72 -62 59 81 -6 30\r\n", "output": "68\r\n"}, {"input": "57 57\r\n77 62 -5 -19 75 31 -71 29 -73 68 -4 42 -73 72 29 20 50 45 -4 28 73 -1 -25 69 -55 27 5 88 81 52 84 45 -11 -93 -4 23 -33 11 65 47 45 -83 -89 -11 -100 -26 89 41 35 -91 11 4 -23 57 38 17 -67\r\n68 75 5 10 -98 -17 73 68 -56 -82 69 55 62 -73 -75 -6 46 87 14 -81 -50 -69 -73 42 0 14 -82 -19 -5 40 -60 12 52 -46 97 70 45 -93 29 36 -41 61 -75 -84 -50 20 85 -33 10 80 33 50 44 -67 91 63 6\r\n", "output": "64\r\n"}, {"input": "52 16\r\n-4770 -9663 -5578 4931 6841 2993 -9006 -1526 -7843 -6401 -3082 -1988 -790 -2443 135 3540 6817 1432 -5237 -588 2459 4466 -4806 -3125 -8135 2879 -7059 8579 5834 9838 4467 -8424 -115 -6929 3050 -9010 9686 -9669 -3200 8478 -605 4845 1800 3070 2025 3063 -3787 -2948 3255 1614 7372 1484\r\n8068 -5083 -2302 8047 8609 -1144 -2610 -7251 820 -9517 -7419 -1291 1444 4232 -5153 5539\r\n", "output": "8\r\n"}, {"input": "8 7\r\n1787 -3614 8770 -5002 -7234 -8845 -585 -908\r\n1132 -7180 -5499 3850 352 2707 -8875\r\n", "output": "4\r\n"}, {"input": "50 46\r\n17 29 -14 -16 -17 -54 74 -70 -43 5 80 15 82 -10 -21 -98 -98 -52 50 90 -2 97 -93 8 83 89 -31 44 -96 32 100 -4 77 36 71 28 -79 72 -18 89 -80 -3 -73 66 12 70 -78 -59 55 -44\r\n-10 -58 -14 -60 -6 -100 -41 -52 -67 -75 -33 -80 -98 -51 -76 92 -43 -4 -70 83 -70 28 -95 8 83 0 -54 -78 75 61 21 38 -53 -61 -95 4 -42 -43 14 60 -15 45 -73 -23 76 -73\r\n", "output": "56\r\n"}, {"input": "6 8\r\n9115 641 -7434 1037 -612 -6061\r\n-8444 4031 7752 -7787 -1387 -9687 -1176 8891\r\n", "output": "4\r\n"}, {"input": "60 13\r\n999 863 66 -380 488 494 -351 -911 -690 -341 -729 -215 -427 -286 -189 657 44 -577 655 646 731 -673 -49 -836 -768 -84 -833 -539 345 -244 562 -748 260 -765 569 -264 43 -853 -568 134 -574 -874 -64 -946 941 408 393 -741 155 -492 -994 -2 107 508 -560 15 -278 264 -875 -817\r\n-138 422 -958 95 245 820 -805 -27 376 121 -508 -951 977\r\n", "output": "12\r\n"}, {"input": "50 58\r\n-7 7 10 1 4 1 10 -10 -8 2 1 5 -9 10 2 -3 -6 -7 -8 2 7 0 8 -2 -7 9 -4 8 -6 10 -9 -9 2 -8 8 0 -2 8 -10 -10 -10 2 8 -3 5 1 0 4 -9 -2\r\n6 6 -9 10 -2 -2 7 -5 9 -5 -7 -8 -8 5 -9 -3 -3 7 9 0 9 -1 1 5 1 0 -8 -9 -4 4 -4 5 -2 2 -7 -6 10 -1 -8 -3 6 -1 -10 -5 -10 3 9 7 5 -3 8 -7 6 9 1 10 -9 3\r\n", "output": "108\r\n"}, {"input": "17 49\r\n17 55 -3 72 43 -91 1 -51 -5 -58 -30 -3 71 -39 44 9 7\r\n-38 -9 -74 -77 -14 14 78 13 -96 85 54 -83 -90 18 22 4 -61 23 -13 -38 -87 -79 -25 31 -64 47 -92 91 55 -8 -38 -34 -46 6 31 15 -72 80 -46 58 -1 90 -47 -28 53 31 -61 89 61\r\n", "output": "27\r\n"}, {"input": "22 54\r\n484 -77 -421 -590 633 -472 -983 -396 756 -21 -320 -96 -590 -677 758 -556 -672 -798 430 -449 -213 -944\r\n309 -468 -484 973 -992 -385 -210 205 -318 350 468 196 802 461 286 -431 -81 984 286 -462 47 -647 -760 629 314 -388 986 507 898 287 -434 -390 95 -163 584 -67 655 -19 -756 50 215 833 -753 485 -127 62 -897 -898 1 -924 -224 30 -373 975\r\n", "output": "17\r\n"}, {"input": "33 30\r\n-55 26 -48 -87 -87 -73 13 87 -79 -88 91 38 80 86 55 -66 72 -72 -77 -41 95 11 13 -99 -23 -66 -20 35 90 -40 59 -2 43\r\n-56 -23 16 51 78 -58 -61 -18 -7 -57 -8 86 -44 -47 -70 -31 -34 -80 -85 -21 53 93 -93 88 -54 -83 97 57 47 80\r\n", "output": "28\r\n"}, {"input": "10 8\r\n8780 -6753 -8212 -1027 1193 -6328 -4260 -8031 4114 -135\r\n-6545 1378 6091 -4158 3612 1509 -8731 1391\r\n", "output": "4\r\n"}, {"input": "10 5\r\n-7722 3155 -4851 -5222 -2712 4693 -3099 222 -4282 -4848\r\n3839 3098 -8804 4627 -7437\r\n", "output": "4\r\n"}, {"input": "4 10\r\n1796 5110 -8430 -617\r\n9903 -5666 -2809 -4878 -284 -1123 5202 -3694 -789 5483\r\n", "output": "4\r\n"}, {"input": "46 60\r\n-119 682 371 355 -473 978 -474 311 379 -311 601 -287 683 625 982 -772 -706 -995 451 -877 452 -823 -51 826 -771 -419 -215 -502 -110 -454 844 -433 942 250 155 -787 628 282 -818 -784 282 -888 200 628 -320 62\r\n-389 -518 341 98 -138 -816 -628 81 567 112 -220 -122 -307 -891 -85 253 -352 -244 194 779 -884 866 -23 298 -191 -497 106 -553 -612 -48 -279 847 -721 195 -397 -455 486 -572 -489 -183 -582 354 -542 -371 -330 -105 -110 -536 -559 -487 -297 -533 813 281 847 -786 8 -179 394 -734\r\n", "output": "19\r\n"}, {"input": "39 31\r\n268 -441 -422 252 377 420 749 748 660 893 -309 722 -612 -667 363 79 650 884 -672 -880 518 -936 806 376 359 -965 -964 138 851 717 -131 316 603 -375 114 421 976 688 -527\r\n-989 -76 -404 971 -572 771 149 674 -471 218 -317 -225 994 10 509 719 915 -811 -57 -995 865 -486 7 -766 143 -53 699 -466 -165 -486 602\r\n", "output": "15\r\n"}, {"input": "5 3\r\n-8452 -1472 4013 -5048 -6706\r\n-8387 -7493 -7090\r\n", "output": "4\r\n"}, {"input": "58 58\r\n-2 79 3 14 40 -23 87 -86 80 -23 77 12 55 -81 59 -84 -66 89 92 -85 14 -44 -28 -75 77 -36 97 69 21 -31 -26 -13 9 83 -70 38 58 79 -34 68 -52 -50 -68 41 86 -9 -87 64 90 -88 -55 -32 35 100 76 -85 63 -29\r\n68 3 -18 -13 -98 -52 -90 -21 43 -63 -97 49 40 65 -96 83 15 2 76 54 50 49 4 -71 -62 53 26 -90 -38 -24 71 -69 -58 -86 66 5 31 -23 -76 -34 -79 72 7 45 -86 -97 -43 85 -51 -76 26 98 58 -28 58 44 82 -70\r\n", "output": "79\r\n"}, {"input": "9 10\r\n-393 439 961 649 441 -536 -453 989 733\r\n-952 -776 674 696 -452 -700 58 -430 540 271\r\n", "output": "8\r\n"}, {"input": "8 6\r\n-90 817 655 798 -547 -390 -828 -50\r\n-626 -365 426 139 513 -607\r\n", "output": "6\r\n"}, {"input": "54 11\r\n-10 5 -4 -7 -2 10 -10 -4 6 4 9 -7 -10 8 8 6 0 -6 8 4 -6 -1 6 4 -6 1 -2 8 -5 -2 -9 -8 9 6 1 2 10 3 1 3 -3 -10 8 -2 3 9 8 3 -9 -5 -6 -2 -5 -6\r\n10 1 0 -9 -5 -6 8 0 -3 5 -5\r\n", "output": "55\r\n"}, {"input": "6 7\r\n3403 -4195 5813 -1096 -9300 -959\r\n-4820 9153 2254 6322 -5071 6383 -687\r\n", "output": "4\r\n"}, {"input": "41 56\r\n6 2 0 -3 3 6 0 10 -7 -5 -5 7 -5 -9 -3 -5 -2 9 5 -1 1 8 -2 1 -10 10 -4 -9 10 -8 8 7 7 7 4 4 -2 2 4 -6 -7\r\n9 6 -5 6 -7 2 -6 -3 -6 -1 10 -5 -5 3 10 10 4 3 0 2 8 4 -3 3 9 4 -6 0 2 6 6 -2 0 -3 -5 3 4 -2 -3 10 -10 1 3 -3 -7 2 -2 2 0 4 -6 8 -4 -1 1 -6\r\n", "output": "97\r\n"}, {"input": "45 57\r\n-5 -3 -10 2 -3 1 10 -3 -3 -7 -9 6 6 1 8 2 -4 3 -6 9 8 10 -1 8 -2 -8 -9 -7 -8 4 -1 -10 0 -4 8 -7 3 -1 0 3 -8 -10 -6 -8 -5\r\n1 3 -1 7 1 10 3 -2 8 6 0 2 -3 -3 10 -10 -6 -7 10 5 9 10 3 -2 4 10 -10 0 -2 4 -6 -1 -1 -5 7 -3 -2 -7 7 -2 2 2 1 -10 -7 -8 -3 4 0 8 -5 -7 -7 9 -3 8 -5\r\n", "output": "102\r\n"}, {"input": "51 39\r\n-10 6 -8 2 6 6 0 2 4 -3 8 10 7 1 9 -8 4 -2 3 5 8 -2 1 3 1 3 -5 0 2 2 7 -3 -10 4 9 -3 -7 5 5 10 -5 -5 9 -3 9 -1 -4 9 -7 -8 5\r\n-5 10 -2 -8 -10 5 -7 1 7 6 -3 -5 0 -4 0 -9 2 -9 -10 2 -6 10 0 4 -4 -8 -3 1 10 7 5 7 0 -7 1 0 9 0 -5\r\n", "output": "90\r\n"}, {"input": "4 10\r\n3 -7 -4 -8\r\n7 3 -1 -8 2 -1 -5 8 -8 9\r\n", "output": "12\r\n"}, {"input": "44 41\r\n-6 0 -2 5 5 -9 -4 -5 -2 -6 -7 -10 5 2 -6 -3 1 4 8 2 -7 6 5 0 10 -2 -9 3 -6 -3 7 5 -3 7 -10 -1 6 0 10 -6 -5 -6 -6 6\r\n6 -3 1 -1 8 9 6 7 -6 -4 -2 -4 -3 3 2 -1 3 1 10 -2 2 -10 -9 -3 8 -3 -1 -4 0 0 -4 7 -10 6 10 -8 5 6 2 -9 -4\r\n", "output": "85\r\n"}, {"input": "52 43\r\n-514 -667 -511 516 -332 73 -233 -594 125 -847 -584 432 631 -673 -380 835 69 523 -568 -110 -752 -731 864 250 550 -249 525 357 8 43 -395 -328 61 -84 -151 165 -896 955 -660 -195 375 806 -160 870 143 -725 -814 494 -953 -463 704 -415\r\n608 -584 673 -920 -227 -442 242 815 533 -184 -502 -594 -381 -960 786 -627 -531 -579 583 -252 -445 728 902 934 -311 971 119 -391 710 -794 738 -82 774 580 -142 208 704 -745 -509 979 -236 -276 -800\r\n", "output": "18\r\n"}, {"input": "51 48\r\n642 261 822 -266 700 18 -62 -915 39 997 564 -130 605 -141 58 426 -514 425 -310 -56 -524 860 -793 57 511 -563 -529 -140 -679 -489 -841 -326 -108 -785 599 3 -90 -52 769 -513 -328 -709 -887 736 729 -148 232 680 -589 77 531\r\n689 765 386 700 612 -936 -258 966 873 130 230 -78 -835 739 -755 127 -963 -282 -728 -833 345 -817 -61 680 944 -475 -46 -915 777 -789 -742 -755 325 -474 -220 544 19 828 -483 -388 -330 -150 -912 -219 185 -541 237 724\r\n", "output": "20\r\n"}, {"input": "35 32\r\n8 3 9 -6 -6 -3 -6 2 2 3 0 -4 8 9 -10 -7 7 -6 -4 1 -9 3 -2 3 -4 -8 -8 5 -10 2 6 4 -7 -6 -1\r\n7 -2 1 -9 1 8 4 -4 -4 -7 5 4 0 3 5 8 9 -7 -1 -8 -1 7 2 5 6 -2 -8 -2 9 -6 8 -6\r\n", "output": "67\r\n"}, {"input": "54 55\r\n-95 -3 -18 81 -85 -78 -76 95 -4 -91 88 98 35 88 -30 -82 -1 23 -98 82 -83 100 -47 -7 93 -87 -57 -5 -57 -46 30 -16 -27 -46 78 -58 4 87 86 -58 22 19 -40 8 -6 92 -65 10 -51 -34 -70 -69 -70 -51\r\n-42 75 48 -79 58 23 -8 47 48 33 -2 97 -30 -8 -87 56 22 -91 25 27 -91 -75 -10 45 -27 54 -94 60 -49 22 18 2 35 -81 8 -61 91 12 78 6 -83 76 -81 -27 -65 56 -99 -69 3 91 81 -34 9 -29 61\r\n", "output": "63\r\n"}, {"input": "18 4\r\n81 -30 22 81 -9 -66 -39 -11 16 9 91 74 -36 40 -26 -11 -13 -22\r\n21 67 96 96\r\n", "output": "8\r\n"}, {"input": "5 5\r\n9 9 -7 -4 6\r\n2 3 -3 -8 -1\r\n", "output": "7\r\n"}, {"input": "44 49\r\n28 76 41 66 49 31 3 4 41 89 44 41 33 73 5 -85 57 -55 86 43 25 0 -26 -36 81 -80 -71 77 96 85 -8 -96 -91 28 3 -98 -82 -87 -50 70 -39 -99 -70 66\r\n-12 28 11 -25 -34 70 -4 69 9 -31 -23 -8 19 -54 -5 -24 -7 -45 -70 -71 -64 77 39 60 -63 10 -7 -92 22 4 45 75 100 49 95 -66 -96 -85 -35 92 -9 -37 -38 62 -62 24 -35 40 3\r\n", "output": "52\r\n"}, {"input": "57 41\r\n-10 9 2 7 -1 1 -10 9 7 -9 -4 8 4 -8 -6 8 1 5 -7 9 8 -4 1 -2 -7 6 -9 -10 3 0 8 7 1 -4 -6 9 -10 8 3 -9 4 -9 6 -7 10 -4 3 -4 10 -1 -7 -7 -10 -10 0 3 -10\r\n-2 1 -5 6 0 -2 -4 8 2 -9 -6 7 2 6 -9 -1 -1 3 -4 -8 -4 -10 7 -1 -6 -5 -7 5 10 -5 -4 4 -7 6 -2 -9 -10 3 -7 -5 -9\r\n", "output": "98\r\n"}, {"input": "9 5\r\n7 -5 -2 -3 -10 -3 5 4 10\r\n-1 6 -4 3 2\r\n", "output": "11\r\n"}, {"input": "31 55\r\n68 -31 19 47 95 -44 67 45 32 -17 31 -14 52 -19 -75 97 88 9 -11 77 -23 74 -29 31 -42 -15 -77 30 -17 75 -9\r\n-63 94 98 45 -57 -41 4 34 38 67 68 69 -36 47 91 -55 58 73 77 -71 4 -89 -6 49 71 70 -64 -24 -87 -3 -96 62 -31 -56 -2 88 -80 95 -97 -91 25 -2 1 -80 -45 -96 -62 12 12 -61 -13 23 -32 6 29\r\n", "output": "43\r\n"}, {"input": "50 59\r\n-6 -5 8 -6 7 9 2 -7 0 -9 -7 1 -5 10 -6 -2 -10 6 -6 -2 -7 -10 1 4 -4 9 2 -8 -3 -1 5 -4 2 8 -10 7 -10 4 8 7 -4 9 1 5 -10 -7 -2 3 -9 5\r\n-10 -1 3 9 0 8 5 10 -6 -2 -2 4 4 -1 -3 -9 4 -6 9 -5 -5 -4 -7 -2 9 6 -3 -6 -1 -9 1 9 2 -9 2 -5 3 7 -10 7 -3 -1 -10 -3 2 6 -2 -5 10 5 8 7 4 6 -7 -5 2 -2 -10\r\n", "output": "109\r\n"}, {"input": "53 51\r\n678 -657 703 569 -524 -801 -221 -600 -95 11 -660 866 506 683 649 -842 604 -33 -929 541 379 939 -512 -347 763 697 653 844 927 488 -233 -313 357 -717 119 885 -864 738 -20 -350 -724 906 -41 324 -713 424 -432 154 173 406 29 -420 62\r\n-834 648 564 735 206 490 297 -968 -482 -914 -149 -312 506 56 -773 527 816 137 879 552 -224 811 -786 739 -828 -203 -873 148 -290 395 832 -845 302 -324 32 299 746 638 -684 216 392 -137 496 57 -187 477 -16 395 -325 -186 -801\r\n", "output": "24\r\n"}, {"input": "51 7\r\n323 236 120 48 521 587 327 613 -470 -474 522 -705 320 -51 1 288 -430 -954 732 -805 -562 300 -710 190 515 280 -101 -927 77 282 198 -51 -350 -990 -435 -765 178 -934 -955 704 -565 -640 853 -27 950 170 -712 -780 620 -572 -409\r\n244 671 425 977 773 -294 268\r\n", "output": "9\r\n"}, {"input": "9 9\r\n-9 -1 2 8 10 2 9 7 3\r\n5 8 -5 4 -4 -8 2 8 -8\r\n", "output": "16\r\n"}, {"input": "50 60\r\n445 303 -861 -583 436 -125 312 -700 -829 -865 -276 -25 -725 -286 528 -221 757 720 -572 514 -514 359 294 -992 -838 103 611 776 830 143 -247 182 -241 -627 299 -824 635 -571 -660 924 511 -876 160 569 -570 827 75 558 708 46\r\n899 974 750 -138 -439 -904 -113 -761 -150 -92 -279 489 323 -649 -759 667 -600 -76 -991 140 701 -654 -276 -563 108 -301 161 -989 -852 -97 316 31 -724 848 979 -501 -883 569 925 -532 86 456 302 -985 826 79 -911 660 752 941 -464 -157 -110 433 829 -872 172 496 528 -576\r\n", "output": "24\r\n"}, {"input": "7 3\r\n90 67 1 68 40 -100 -26\r\n-96 70 -74\r\n", "output": "6\r\n"}, {"input": "7 4\r\n-8 -2 -5 -3 -8 -9 8\r\n-8 4 -1 10\r\n", "output": "8\r\n"}, {"input": "52 48\r\n-552 43 -670 -163 -765 -603 -768 673 -248 337 -89 941 -676 -406 280 409 -630 -577 324 115 927 477 -242 108 -337 591 -158 -524 928 859 825 935 818 638 -51 988 -568 871 -842 889 -737 -272 234 -643 766 -422 473 -570 -1000 -735 -279 845\r\n963 -436 738 113 273 -374 -568 64 276 -698 -135 -748 909 -250 -740 -344 -436 414 719 119 973 -881 -576 868 -45 909 630 286 -845 458 684 -64 579 965 598 205 -318 -974 228 -596 596 -946 -198 923 571 -907 -911 -341\r\n", "output": "21\r\n"}, {"input": "40 54\r\n-26 -98 27 -64 0 33 62 -12 -8 -10 -62 28 28 75 -5 -89 -75 -100 -63 9 -97 -20 -81 62 56 -39 87 -33 13 61 19 -97 -23 95 18 -4 -48 55 -40 -81\r\n-69 -71 1 -46 -58 0 -100 -82 31 43 -59 -43 77 -8 -61 -2 -36 -55 -35 -44 -59 -13 -16 14 60 -95 -61 25 76 -1 -3 9 -92 48 -92 -54 2 -7 73 -16 42 -40 36 -58 97 81 13 -64 -12 -28 65 85 -61 8\r\n", "output": "54\r\n"}, {"input": "22 34\r\n-73 45 -81 -67 9 61 -97 0 -64 86 -9 47 -28 100 79 -53 25 -59 -80 -86 -47 24\r\n57 69 8 -34 -37 12 -32 -81 27 -65 87 -64 62 -44 97 34 44 -93 44 25 -72 93 14 95 -60 -65 96 -95 23 -69 28 -20 -95 74\r\n", "output": "27\r\n"}, {"input": "46 48\r\n-710 947 515 217 26 -548 -416 494 431 -872 -616 848 -950 -138 -104 560 241 -462 -265 90 66 -331 934 -788 -815 -558 86 39 784 86 -856 879 -733 -653 104 -673 -588 -568 78 368 -226 850 195 982 140 370\r\n470 -337 283 460 -710 -434 739 459 -567 173 217 511 -830 644 -734 764 -211 -106 423 -356 -126 677 -454 42 680 557 -636 9 -552 877 -246 -352 -44 442 -505 -811 -100 -768 -130 588 -428 755 -904 -138 14 -253 -40 265\r\n", "output": "20\r\n"}, {"input": "58 40\r\n120 571 -472 -980 993 -885 -546 -220 617 -697 -182 -42 128 -29 567 -615 -260 -876 -507 -642 -715 -283 495 -584 97 4 376 -131 186 -301 729 -545 8 -610 -643 233 -123 -769 -173 119 993 825 614 -503 891 426 -850 -992 -406 784 634 -294 997 127 697 -509 934 316\r\n630 -601 937 -544 -50 -176 -885 530 -828 556 -784 460 -422 647 347 -862 131 -76 490 -576 5 -761 922 -426 -7 -401 989 -554 688 -531 -303 -415 -507 -752 -581 -589 513 -151 -279 317\r\n", "output": "18\r\n"}, {"input": "8 6\r\n23 -18 -94 -80 74 89 -48 61\r\n-84 45 -12 -9 -74 63\r\n", "output": "7\r\n"}, {"input": "57 55\r\n-34 744 877 -4 -902 398 -404 225 -560 -600 634 180 -198 703 910 681 -864 388 394 -317 839 -95 -706 -474 -340 262 228 -196 -35 221 -689 -960 -430 946 -231 -146 741 -754 330 217 33 276 381 -734 780 -522 528 -425 -202 -19 -302 -743 53 -247 69 -314 -845\r\n-158 24 461 -274 -30 -58 223 -806 747 568 -59 126 56 661 8 419 -422 320 340 480 -185 905 -459 -530 -50 -484 303 366 889 404 915 -361 -985 -642 -690 -577 -80 -250 173 -740 385 908 -4 593 -559 731 326 -209 -697 490 265 -548 716 320 23\r\n", "output": "24\r\n"}, {"input": "59 56\r\n-8 -8 -4 5 -4 4 4 -5 -10 -2 0 6 -9 -2 10 1 -8 -2 9 5 2 -1 -5 7 -7 7 2 -7 -5 2 -2 -8 4 10 5 -9 5 9 6 10 7 6 -6 -4 -8 5 9 6 1 -7 5 -9 8 10 -7 1 3 -6 8\r\n6 -2 -7 4 -2 -5 -9 -5 0 8 5 5 -4 -6 -5 -10 4 3 -4 -4 -8 2 -6 -10 -10 4 -3 8 -1 8 -8 -5 -2 3 7 3 -8 10 6 0 -8 0 9 -3 9 0 9 0 -3 4 -3 10 10 5 -6 4\r\n", "output": "115\r\n"}, {"input": "53 30\r\n-4206 -1169 3492 6759 5051 -3338 4024 8267 -4651 -7685 -3346 -4958 2648 9321 6062 -3566 8118 9067 -1331 5064 148 6375 6193 -2024 -9376 -663 3837 3989 6583 6971 -146 2515 -4222 8159 -94 -4937 -8364 -6025 3566 556 -5229 3138 -9504 1383 1171 -3918 -1587 -6532 -2299 -6648 -5861 4864 9220\r\n-2359 7436 1682 1775 3850 2691 -4326 6670 3245 -3821 5932 -1159 6162 -2818 -5255 -7439 -6688 1778 -5132 8085 -3576 9153 -5260 -1438 9941 -4729 532 -5206 2133 -2252\r\n", "output": "10\r\n"}, {"input": "4 9\r\n-2 3 -5 -10\r\n7 -7 5 5 2 4 9 -4 5\r\n", "output": "11\r\n"}, {"input": "44 50\r\n23 -401 692 -570 264 -885 417 -355 560 -254 -468 -849 900 997 559 12 853 424 -579 485 711 67 638 771 -750 -583 294 -410 -225 -117 -262 148 385 627 610 983 -345 -236 -62 635 -421 363 88 682\r\n-204 -429 -74 855 533 -817 -613 205 972 941 -566 -813 79 -660 -604 661 273 -70 -70 921 -240 148 314 328 -155 -56 -793 259 -630 92 -975 -361 671 963 430 315 -94 957 465 548 -796 626 -58 -595 315 -455 -918 398 279 99\r\n", "output": "22\r\n"}, {"input": "53 30\r\n5 10 -1 -9 7 -7 1 6 0 7 2 -2 -2 1 -9 -9 2 -7 9 10 -9 1 -1 -9 -9 -5 -8 -3 2 4 -3 -6 6 4 -2 -3 -3 -9 2 -4 9 5 6 -5 -5 6 -2 -1 10 7 4 -4 -2\r\n-1 10 3 -1 7 10 -2 -1 -2 0 3 -10 -6 1 -9 2 -10 9 6 -7 -9 3 -7 1 0 9 -8 2 9 7\r\n", "output": "82\r\n"}, {"input": "9 9\r\n1 10 0 -2 9 -7 1 -4 3\r\n-7 -1 6 -4 8 2 6 6 -3\r\n", "output": "15\r\n"}, {"input": "9 9\r\n5181 -7243 3653 3587 -5051 -4899 -4110 7981 -6429\r\n-7365 -2247 7942 9486 -7160 -1020 -8934 7733 -3010\r\n", "output": "4\r\n"}, {"input": "55 43\r\n9 1 0 -7 4 3 4 4 -8 3 0 -7 0 -9 3 -6 0 4 7 1 -1 -10 -7 -6 -8 -8 2 -5 5 -4 -9 -7 5 -3 -7 -10 -4 -2 -7 -3 2 4 9 8 -8 9 -10 0 0 3 -6 -5 -2 9 -6\r\n-4 -6 9 -4 -2 5 9 6 -8 -2 -3 -7 -8 8 -8 5 1 7 9 7 -5 10 -10 -8 -3 10 0 8 8 4 8 3 10 -8 -4 -6 1 9 0 -3 -4 8 -10\r\n", "output": "98\r\n"}, {"input": "53 12\r\n63 88 91 -69 -15 20 98 40 -70 -49 -51 -74 -34 -52 1 21 83 -14 57 40 -57 33 94 2 -74 22 86 79 9 -18 67 -31 72 31 -64 -83 83 29 50 -29 -27 97 -40 -8 -57 69 -93 18 42 68 -71 -86 22\r\n51 19 33 12 98 91 -83 65 -6 16 81 86\r\n", "output": "27\r\n"}, {"input": "1 1\r\n0\r\n0\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 1 1\r\n1 2 2\r\n", "output": "6\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "2\r\n"}, {"input": "1 1\r\n0\r\n1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 0 0\r\n", "output": "6\r\n"}, {"input": "5 5\r\n5 5 5 5 5\r\n5 5 5 5 5\r\n", "output": "10\r\n"}, {"input": "60 60\r\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59\r\n0 60 120 180 240 300 360 420 480 540 600 660 720 780 840 900 960 1020 1080 1140 1200 1260 1320 1380 1440 1500 1560 1620 1680 1740 1800 1860 1920 1980 2040 2100 2160 2220 2280 2340 2400 2460 2520 2580 2640 2700 2760 2820 2880 2940 3000 3060 3120 3180 3240 3300 3360 3420 3480 3540\r\n", "output": "4\r\n"}, {"input": "2 2\r\n0 2\r\n0 1\r\n", "output": "4\r\n"}, {"input": "1 1\r\n5\r\n5\r\n", "output": "2\r\n"}, {"input": "10 10\r\n1 1 1 1 1 1 1 1 1 1\r\n-30 -30 -30 -30 40 40 40 40 40 40\r\n", "output": "20\r\n"}]
| 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(a[i])
else:
s += ' ' + str(a[i])
print(k)
print(s)
|
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 integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
|
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. Also the new array should be got from the original array a by adding k elements to it.
If there are multiple answers you can print any one of them.
| 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"}, {"input": "10\r\n26 723 970 13 422 968 875 329 234 983\r\n", "output": "2\r\n26 723 970 13 422 1 968 875 1 329 234 983\r\n"}, {"input": "10\r\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\r\n", "output": "7\r\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396\r\n"}, {"input": "100\r\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1\r\n", "output": "19\r\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1\r\n"}, {"input": "100\r\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917\r\n", "output": "38\r\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917\r\n"}, {"input": "5\r\n472882027 472882027 472882027 472882027 472882027\r\n", "output": "4\r\n472882027 1 472882027 1 472882027 1 472882027 1 472882027\r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "1\r\n1000000000 1 1000000000\r\n"}, {"input": "2\r\n8 6\r\n", "output": "1\r\n8 1 6\r\n"}, {"input": "3\r\n100000000 1000000000 1000000000\r\n", "output": "2\r\n100000000 1 1000000000 1 1000000000\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n1 2 3 4 5\r\n"}, {"input": "20\r\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000\r\n", "output": "19\r\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000\r\n"}, {"input": "2\r\n223092870 23\r\n", "output": "1\r\n223092870 1 23\r\n"}, {"input": "2\r\n100000003 100000003\r\n", "output": "1\r\n100000003 1 100000003\r\n"}, {"input": "2\r\n999999937 999999937\r\n", "output": "1\r\n999999937 1 999999937\r\n"}, {"input": "4\r\n999 999999937 999999937 999\r\n", "output": "1\r\n999 999999937 1 999999937 999\r\n"}, {"input": "2\r\n999999929 999999929\r\n", "output": "1\r\n999999929 1 999999929\r\n"}, {"input": "2\r\n1049459 2098918\r\n", "output": "1\r\n1049459 1 2098918\r\n"}, {"input": "2\r\n352229 704458\r\n", "output": "1\r\n352229 1 704458\r\n"}, {"input": "2\r\n7293 4011\r\n", "output": "1\r\n7293 1 4011\r\n"}, {"input": "2\r\n5565651 3999930\r\n", "output": "1\r\n5565651 1 3999930\r\n"}, {"input": "2\r\n997 997\r\n", "output": "1\r\n997 1 997\r\n"}, {"input": "3\r\n9994223 9994223 9994223\r\n", "output": "2\r\n9994223 1 9994223 1 9994223\r\n"}, {"input": "2\r\n99999998 1000000000\r\n", "output": "1\r\n99999998 1 1000000000\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "2\r\n1000000000 1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n130471 130471\r\n", "output": "1\r\n130471 1 130471\r\n"}, {"input": "3\r\n1000000000 2 2\r\n", "output": "2\r\n1000000000 1 2 1 2\r\n"}, {"input": "2\r\n223092870 66526\r\n", "output": "1\r\n223092870 1 66526\r\n"}, {"input": "14\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449\r\n", "output": "10\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449\r\n"}, {"input": "2\r\n3996017 3996017\r\n", "output": "1\r\n3996017 1 3996017\r\n"}, {"input": "2\r\n999983 999983\r\n", "output": "1\r\n999983 1 999983\r\n"}, {"input": "2\r\n618575685 773990454\r\n", "output": "1\r\n618575685 1 773990454\r\n"}, {"input": "3\r\n9699690 3 7\r\n", "output": "1\r\n9699690 1 3 7\r\n"}, {"input": "2\r\n999999999 999999996\r\n", "output": "1\r\n999999999 1 999999996\r\n"}, {"input": "2\r\n99999910 99999910\r\n", "output": "1\r\n99999910 1 99999910\r\n"}, {"input": "12\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491\r\n", "output": "9\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491\r\n"}, {"input": "3\r\n999999937 999999937 999999937\r\n", "output": "2\r\n999999937 1 999999937 1 999999937\r\n"}, {"input": "2\r\n99839 99839\r\n", "output": "1\r\n99839 1 99839\r\n"}, {"input": "3\r\n19999909 19999909 19999909\r\n", "output": "2\r\n19999909 1 19999909 1 19999909\r\n"}, {"input": "4\r\n1 1000000000 1 1000000000\r\n", "output": "0\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n64006 64006\r\n", "output": "1\r\n64006 1 64006\r\n"}, {"input": "2\r\n1956955 1956955\r\n", "output": "1\r\n1956955 1 1956955\r\n"}, {"input": "3\r\n1 1000000000 1000000000\r\n", "output": "1\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n982451707 982451707\r\n", "output": "1\r\n982451707 1 982451707\r\n"}, {"input": "2\r\n999999733 999999733\r\n", "output": "1\r\n999999733 1 999999733\r\n"}, {"input": "3\r\n999999733 999999733 999999733\r\n", "output": "2\r\n999999733 1 999999733 1 999999733\r\n"}, {"input": "2\r\n3257 3257\r\n", "output": "1\r\n3257 1 3257\r\n"}, {"input": "2\r\n223092870 181598\r\n", "output": "1\r\n223092870 1 181598\r\n"}, {"input": "3\r\n959919409 105935 105935\r\n", "output": "2\r\n959919409 1 105935 1 105935\r\n"}, {"input": "2\r\n510510 510510\r\n", "output": "1\r\n510510 1 510510\r\n"}, {"input": "3\r\n223092870 1000000000 1000000000\r\n", "output": "2\r\n223092870 1 1000000000 1 1000000000\r\n"}, {"input": "14\r\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000\r\n", "output": "11\r\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000\r\n"}, {"input": "7\r\n1 982451653 982451653 1 982451653 982451653 982451653\r\n", "output": "3\r\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653\r\n"}, {"input": "2\r\n100000007 100000007\r\n", "output": "1\r\n100000007 1 100000007\r\n"}, {"input": "3\r\n999999757 999999757 999999757\r\n", "output": "2\r\n999999757 1 999999757 1 999999757\r\n"}, {"input": "3\r\n99999989 99999989 99999989\r\n", "output": "2\r\n99999989 1 99999989 1 99999989\r\n"}, {"input": "5\r\n2 4 982451707 982451707 3\r\n", "output": "2\r\n2 1 4 982451707 1 982451707 3\r\n"}, {"input": "2\r\n20000014 20000014\r\n", "output": "1\r\n20000014 1 20000014\r\n"}, {"input": "2\r\n99999989 99999989\r\n", "output": "1\r\n99999989 1 99999989\r\n"}, {"input": "2\r\n111546435 111546435\r\n", "output": "1\r\n111546435 1 111546435\r\n"}, {"input": "2\r\n55288874 33538046\r\n", "output": "1\r\n55288874 1 33538046\r\n"}, {"input": "5\r\n179424673 179424673 179424673 179424673 179424673\r\n", "output": "4\r\n179424673 1 179424673 1 179424673 1 179424673 1 179424673\r\n"}, {"input": "2\r\n199999978 199999978\r\n", "output": "1\r\n199999978 1 199999978\r\n"}, {"input": "2\r\n1000000000 2\r\n", "output": "1\r\n1000000000 1 2\r\n"}, {"input": "3\r\n19999897 19999897 19999897\r\n", "output": "2\r\n19999897 1 19999897 1 19999897\r\n"}, {"input": "2\r\n19999982 19999982\r\n", "output": "1\r\n19999982 1 19999982\r\n"}, {"input": "2\r\n10000007 10000007\r\n", "output": "1\r\n10000007 1 10000007\r\n"}, {"input": "3\r\n999999937 999999937 2\r\n", "output": "1\r\n999999937 1 999999937 2\r\n"}, {"input": "5\r\n2017 2017 2017 2017 2017\r\n", "output": "4\r\n2017 1 2017 1 2017 1 2017 1 2017\r\n"}, {"input": "2\r\n19999909 39999818\r\n", "output": "1\r\n19999909 1 39999818\r\n"}, {"input": "2\r\n62615533 7919\r\n", "output": "1\r\n62615533 1 7919\r\n"}, {"input": "5\r\n39989 39989 33 31 29\r\n", "output": "1\r\n39989 1 39989 33 31 29\r\n"}, {"input": "2\r\n1000000000 100000\r\n", "output": "1\r\n1000000000 1 100000\r\n"}, {"input": "2\r\n1938 10010\r\n", "output": "1\r\n1938 1 10010\r\n"}, {"input": "2\r\n199999 199999\r\n", "output": "1\r\n199999 1 199999\r\n"}, {"input": "2\r\n107273 107273\r\n", "output": "1\r\n107273 1 107273\r\n"}, {"input": "3\r\n49999 49999 49999\r\n", "output": "2\r\n49999 1 49999 1 49999\r\n"}, {"input": "2\r\n1999966 1999958\r\n", "output": "1\r\n1999966 1 1999958\r\n"}, {"input": "2\r\n86020 300846\r\n", "output": "1\r\n86020 1 300846\r\n"}, {"input": "2\r\n999999997 213\r\n", "output": "1\r\n999999997 1 213\r\n"}, {"input": "2\r\n200000014 200000434\r\n", "output": "1\r\n200000014 1 200000434\r\n"}]
| false
|
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# 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) as f:
lines = f.readlines()
if len(lines) < 2:
print(0)
return
try:
k_sub = int(lines[0].strip())
array_sub = list(map(int, lines[1].strip().split()))
except:
print(0)
return
# Check array_sub length
if len(array_sub) != n + k_sub:
print(0)
return
# Read reference output's k_ref
with open(output_path) as f:
k_ref = int(f.readline().strip())
# Check k_sub equals k_ref
if k_sub != k_ref:
print(0)
return
# Check original array is a subsequence of array_sub
i = 0
for num in array_sub:
if i < len(a) and num == a[i]:
i += 1
if i != len(a):
print(0)
return
# Check all adjacent pairs are coprime
for j in range(len(array_sub)-1):
x = array_sub[j]
y = array_sub[j+1]
if math.gcd(x, y) != 1:
print(0)
return
# All checks passed
print(1)
if __name__ == "__main__":
main()
| 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)
l.insert(0,m)
n,k=[int(x) for x in input().strip().split()]
e_card([int(x) for x in input().strip().split()],k)
print(count)
| 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 the deck and the magic number, Vova removes x (possibly x = 0) cards from the top of the deck, y (possibly y = 0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards x + 1, x + 2, ... n - y - 1, n - y from the original deck.
Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by k. So Vova received a deck (possibly not a valid one) and a number k, and now he wonders, how many ways are there to choose x and y so the deck he will get after removing x cards from the top and y cards from the bottom is valid?
|
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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "5050\r\n"}, {"input": "100 1\r\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2 3 4 2 1 3 4 4 5 5 1 5 2 5 3 3 1 1 1 3 2 2 3 4 4 4 4 3 1 3 5 3 3 3 3 2 3 2 2 3 3 1 2 4 3 2 2 5 3 1 5 2 2 5 1 2 1 1 5 1 5 2 4 5 3 4 2 5 4 2 2 5 5 5 3 3 5 3 4 3 3 1\r\n", "output": "5050\r\n"}, {"input": "100 5\r\n4 4 3 2 4 4 1 2 2 1 5 3 2 5 5 3 2 3 4 5 2 2 3 4 2 4 3 1 2 3 5 5 1 3 3 5 2 3 3 4 1 3 1 5 4 4 2 1 5 1 4 4 1 5 1 1 5 5 5 4 1 3 1 2 3 2 4 5 5 1 3 4 3 3 1 2 2 4 1 5 1 1 2 4 4 4 5 5 5 3 4 3 3 3 3 2 1 1 5 5\r\n", "output": "4713\r\n"}, {"input": "100 6\r\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3\r\n", "output": "4580\r\n"}, {"input": "100 72\r\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5\r\n", "output": "4549\r\n"}, {"input": "100 72\r\n3 2 1 3 3 3 4 3 5 5 2 5 1 2 2 2 1 4 1 5 1 4 5 4 3 1 4 3 4 4 1 4 4 3 4 1 4 4 5 2 2 3 3 5 4 5 4 2 4 3 1 1 1 4 5 5 3 1 5 3 4 4 5 3 5 1 4 3 2 2 1 4 2 1 3 2 4 2 1 4 4 1 3 4 4 4 1 5 5 2 5 2 3 1 5 1 1 1 2 3\r\n", "output": "4123\r\n"}, {"input": "2 999634589\r\n31607 31627\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1\r\n", "output": "0\r\n"}, {"input": "1 3\r\n1\r\n", "output": "0\r\n"}, {"input": "1 4\r\n1\r\n", "output": "0\r\n"}, {"input": "1 5\r\n3\r\n", "output": "0\r\n"}, {"input": "1 6\r\n4\r\n", "output": "0\r\n"}, {"input": "1 7\r\n2\r\n", "output": "0\r\n"}, {"input": "1 8\r\n3\r\n", "output": "0\r\n"}, {"input": "1 9\r\n5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n3\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n", "output": "3\r\n"}, {"input": "2 2\r\n2 2\r\n", "output": "3\r\n"}, {"input": "2 3\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 4\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2 5\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 6\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2 7\r\n1 4\r\n", "output": "0\r\n"}, {"input": "2 8\r\n5 3\r\n", "output": "0\r\n"}, {"input": "2 9\r\n2 2\r\n", "output": "0\r\n"}, {"input": "2 10\r\n6 1\r\n", "output": "0\r\n"}, {"input": "3 1\r\n1 1 1\r\n", "output": "6\r\n"}, {"input": "3 2\r\n2 2 1\r\n", "output": "5\r\n"}, {"input": "3 3\r\n2 1 2\r\n", "output": "0\r\n"}, {"input": "3 4\r\n2 2 2\r\n", "output": "3\r\n"}, {"input": "3 5\r\n1 1 2\r\n", "output": "0\r\n"}, {"input": "3 6\r\n4 3 2\r\n", "output": "3\r\n"}, {"input": "3 7\r\n3 4 1\r\n", "output": "0\r\n"}, {"input": "3 8\r\n5 1 4\r\n", "output": "0\r\n"}, {"input": "3 9\r\n3 2 1\r\n", "output": "0\r\n"}, {"input": "3 10\r\n6 5 5\r\n", "output": "2\r\n"}, {"input": "4 1\r\n1 1 1 1\r\n", "output": "10\r\n"}, {"input": "4 2\r\n2 2 1 2\r\n", "output": "9\r\n"}, {"input": "4 3\r\n2 1 1 1\r\n", "output": "0\r\n"}, {"input": "4 4\r\n2 2 1 1\r\n", "output": "3\r\n"}, {"input": "4 5\r\n2 3 2 1\r\n", "output": "0\r\n"}, {"input": "4 6\r\n1 1 3 3\r\n", "output": "0\r\n"}, {"input": "4 7\r\n1 1 2 2\r\n", "output": "0\r\n"}, {"input": "4 8\r\n5 4 5 5\r\n", "output": "0\r\n"}, {"input": "4 9\r\n1 1 4 2\r\n", "output": "0\r\n"}, {"input": "4 10\r\n2 6 2 1\r\n", "output": "0\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "5 2\r\n2 2 1 2 1\r\n", "output": "13\r\n"}, {"input": "5 3\r\n2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "5 4\r\n2 2 1 3 1\r\n", "output": "4\r\n"}, {"input": "5 5\r\n2 3 1 1 3\r\n", "output": "0\r\n"}, {"input": "5 6\r\n3 4 3 4 3\r\n", "output": "10\r\n"}, {"input": "5 7\r\n3 1 3 2 4\r\n", "output": "0\r\n"}, {"input": "5 8\r\n2 2 3 3 1\r\n", "output": "0\r\n"}, {"input": "5 9\r\n3 1 3 3 4\r\n", "output": "7\r\n"}, {"input": "5 10\r\n3 6 6 1 5\r\n", "output": "3\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "21\r\n"}, {"input": "6 2\r\n1 2 2 1 1 1\r\n", "output": "14\r\n"}, {"input": "6 3\r\n2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 4\r\n1 3 3 3 3 2\r\n", "output": "0\r\n"}, {"input": "6 5\r\n2 3 3 2 1 2\r\n", "output": "0\r\n"}, {"input": "6 6\r\n1 2 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "6 7\r\n2 2 4 3 2 1\r\n", "output": "0\r\n"}, {"input": "6 8\r\n3 2 3 5 5 3\r\n", "output": "0\r\n"}, {"input": "6 9\r\n1 4 1 2 1 1\r\n", "output": "0\r\n"}, {"input": "6 10\r\n1 2 5 6 6 6\r\n", "output": "11\r\n"}, {"input": "7 1\r\n1 1 1 1 1 1 1\r\n", "output": "28\r\n"}, {"input": "7 2\r\n1 1 2 2 2 2 1\r\n", "output": "24\r\n"}, {"input": "7 3\r\n2 2 1 1 2 2 2\r\n", "output": "0\r\n"}, {"input": "7 4\r\n3 2 1 2 1 1 1\r\n", "output": "8\r\n"}, {"input": "7 5\r\n2 3 3 3 2 3 2\r\n", "output": "0\r\n"}, {"input": "7 6\r\n3 4 4 1 4 3 2\r\n", "output": "15\r\n"}, {"input": "7 7\r\n4 2 4 4 1 4 4\r\n", "output": "0\r\n"}, {"input": "7 8\r\n4 4 2 4 2 5 3\r\n", "output": "18\r\n"}, {"input": "7 9\r\n2 1 3 4 4 5 4\r\n", "output": "0\r\n"}, {"input": "7 10\r\n6 3 3 5 3 6 1\r\n", "output": "10\r\n"}, {"input": "8 1\r\n1 1 1 1 1 1 1 1\r\n", "output": "36\r\n"}, {"input": "8 2\r\n1 1 1 1 1 1 1 2\r\n", "output": "8\r\n"}, {"input": "8 3\r\n1 1 2 2 1 1 2 2\r\n", "output": "0\r\n"}, {"input": "8 4\r\n2 3 2 3 3 3 2 3\r\n", "output": "10\r\n"}, {"input": "8 5\r\n1 3 1 2 2 2 1 3\r\n", "output": "0\r\n"}, {"input": "8 6\r\n4 2 4 2 1 2 1 4\r\n", "output": "0\r\n"}, {"input": "8 7\r\n2 2 1 4 4 4 2 2\r\n", "output": "0\r\n"}, {"input": "8 8\r\n5 2 1 2 4 2 2 4\r\n", "output": "21\r\n"}, {"input": "8 9\r\n4 4 2 2 5 5 4 1\r\n", "output": "0\r\n"}, {"input": "8 10\r\n2 1 4 4 3 4 4 6\r\n", "output": "0\r\n"}, {"input": "9 1\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "45\r\n"}, {"input": "9 2\r\n1 1 1 2 1 1 2 2 2\r\n", "output": "36\r\n"}, {"input": "9 3\r\n1 1 1 2 2 1 1 2 1\r\n", "output": "0\r\n"}, {"input": "9 4\r\n1 1 2 1 2 1 1 1 1\r\n", "output": "15\r\n"}, {"input": "9 5\r\n3 2 3 2 3 1 1 3 2\r\n", "output": "0\r\n"}, {"input": "9 6\r\n2 1 1 3 2 4 1 2 2\r\n", "output": "21\r\n"}, {"input": "9 7\r\n4 3 2 1 2 3 3 4 4\r\n", "output": "0\r\n"}, {"input": "9 8\r\n5 5 2 1 3 1 3 1 3\r\n", "output": "0\r\n"}, {"input": "9 9\r\n2 4 1 4 4 3 3 4 1\r\n", "output": "18\r\n"}, {"input": "9 10\r\n4 3 2 5 2 2 2 2 6\r\n", "output": "23\r\n"}, {"input": "10 1\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "55\r\n"}, {"input": "10 2\r\n2 2 2 2 2 2 2 1 2 1\r\n", "output": "53\r\n"}, {"input": "10 3\r\n2 2 1 1 2 2 2 2 1 2\r\n", "output": "0\r\n"}, {"input": "10 4\r\n1 1 2 3 3 1 2 2 2 3\r\n", "output": "26\r\n"}, {"input": "10 5\r\n3 3 2 2 3 1 1 1 3 1\r\n", "output": "0\r\n"}, {"input": "10 6\r\n4 4 4 3 2 1 1 1 2 4\r\n", "output": "27\r\n"}, {"input": "10 7\r\n4 2 2 2 3 3 2 4 4 3\r\n", "output": "0\r\n"}, {"input": "10 8\r\n5 4 1 4 3 2 1 2 3 3\r\n", "output": "24\r\n"}, {"input": "10 9\r\n1 2 3 4 5 2 3 5 5 4\r\n", "output": "12\r\n"}, {"input": "10 10\r\n5 3 2 5 1 2 5 1 5 1\r\n", "output": "35\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 100000000\r\n1000000000\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "1\r\n"}]
| 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:
if s1 == s2:
continue
bad = False
for i in range(0, len(s1)):
if s1[i] == s2[i]:
bad = True
if not bad:
print('YES')
return
print('NO')
if __name__ == '__main__':
main()
| 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("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. To make the contest interesting for them, each of the teams should know at most half of the selected problems.
Determine if Snark and Philip can make an interesting problemset!
|
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\n0 0 1\r\n1 0 1\r\n0 1 1\r\n1 0 0\r\n1 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 0 1\r\n1 1 0 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 1 0\r\n0 0 0 0\r\n0 0 1 0\r\n1 0 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n0 0\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 1\r\n1 0 0\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 0\r\n1 1 0 0\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 1\r\n1\r\n1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n0 1 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 0 1\r\n1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 1 1 0\r\n1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "6 3\r\n0 1 1\r\n1 0 1\r\n1 1 1\r\n0 1 0\r\n1 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n0 0 0 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 1 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "6 3\r\n1 0 0\r\n1 1 1\r\n1 1 1\r\n0 1 0\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 0 0\r\n1 1 1 1\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "1 3\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 1\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n1 1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n0 1 0 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n1 1 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 1 1\r\n1 0 1 0\r\n1 1 0 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 0 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 0\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 0 1\r\n0 0 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n1 1 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "8 4\r\n0 0 0 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 1\r\n1 1 1 0\r\n0 1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n0 0 0 1\r\n1 1 1 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n1 0 1\r\n0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 0 1\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 0 0\r\n1 0 1 0\r\n0 1 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 0 0 0\r\n1 0 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 0 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 0 1\r\n0 1 1 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 1 1\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 0\r\n", "output": "YES\r\n"}]
| 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())
if term == "0 0":
(s1,s2) = (1,1)
break
else:
if term == "0 1":
s1 = 1
elif term == "1 0":
s2 = 1
if (s1,s2) == (1,1):
break
print("YES") if (s1,s2) == (1,1) else print("NO")
elif k == 3:
alert = 0
s = {str(input()) for i in range(n)}
if "0 0 0" in s:
alert = 1
elif "0 0 1" in s:
if "1 1 0" in s or "1 0 0" in s or "0 1 0" in s:
alert = 1
elif "0 1 0" in s:
if "1 0 1" in s or "1 0 0" in s or "0 0 1" in s:
alert = 1
elif "1 0 0" in s:
if "0 0 1" in s or "0 1 0" in s or "0 1 1" in s:
alert = 1
print("YES") if alert == 1 else print("NO")
elif k == 4:
alert = 0
s = {str(input()) for i in range(n)}
s = list(s)
if "0 0 0 0" in s:
alert = 1
elif "1 1 0 0" in s:
for i in range(len(s)):
if (s[i])[0] == '0' and (s[i])[2] == '0':
alert = 1
elif "1 0 1 0" in s:
for i in range(len(s)):
if (s[i])[0] == '0' and (s[i])[4] == '0':
alert = 1
elif "1 0 0 1" in s:
for i in range(len(s)):
if (s[i])[0] == '0' and (s[i])[6] == '0':
alert = 1
elif "0 1 1 0" in s:
for i in range(len(s)):
if (s[i])[2] == '0' and (s[i])[4] == '0':
alert = 1
elif "0 1 0 1" in s:
for i in range(len(s)):
if (s[i])[2] == '0' and (s[i])[6] == '0':
alert = 1
elif "0 0 1 1" in s:
for i in range(len(s)):
if (s[i])[4] == '0' and (s[i])[6] == '0':
alert = 1
print("YES") if alert == 1 else print("NO")
| 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.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def is_valid(curr,tmp):
curr=curr[::-1]
tmp=tmp[::-1]
pos=0
while True:
if pos==len(curr) or pos==len(tmp):
break
if curr[pos]=='1':
if tmp[pos]=='1':
return False
pos+=1
return True
n,k=map(int,input().split())
a=[]
ver=False
dict={}
for i in range(n):
tmp=list(map(int,input().split()))
zero=tmp.count(0)
s=""
for j in range(len(tmp)):
s+=str(tmp[j])
val=int(s,2)
if val in dict:
dict[val]+=1
else:
dict[val]=1
if zero==len(tmp):
ver=True
if ver:
print("YES")
else:
ver=False
for i in dict:
b=bin(i)[2:]
for j in range(int(2**k)):
d=[0]*k
c=bin(j)[2:]
x=-1
y=len(c)-1
for ll in range(len(c)):
if c[y]=='1':
d[x]=1
y-=1
x-=1
tmp=""
for binary in d:
tmp+=str(binary)
val=int(tmp,2)
if is_valid(bin(i)[2:],tmp):
if val==i:
if dict[val]>1:
ver=True
break
else:
if val in dict:
ver=True
break
if ver:
break
if ver:
print("YES")
else:
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. To make the contest interesting for them, each of the teams should know at most half of the selected problems.
Determine if Snark and Philip can make an interesting problemset!
|
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\n0 0 1\r\n1 0 1\r\n0 1 1\r\n1 0 0\r\n1 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 0 1\r\n1 1 0 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 1 0\r\n0 0 0 0\r\n0 0 1 0\r\n1 0 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n0 0\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 1\r\n1 0 0\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 0\r\n1 1 0 0\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 1\r\n1\r\n1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n0 1 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 0 1\r\n1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 1 1 0\r\n1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "6 3\r\n0 1 1\r\n1 0 1\r\n1 1 1\r\n0 1 0\r\n1 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n0 0 0 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 1 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "6 3\r\n1 0 0\r\n1 1 1\r\n1 1 1\r\n0 1 0\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 0 0\r\n1 1 1 1\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "1 3\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 1\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n1 1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n0 1 0 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n1 1 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 1 1\r\n1 0 1 0\r\n1 1 0 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 0 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 0\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 0 1\r\n0 0 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n1 1 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "8 4\r\n0 0 0 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 1\r\n1 1 1 0\r\n0 1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n0 0 0 1\r\n1 1 1 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n1 0 1\r\n0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 0 1\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 0 0\r\n1 0 1 0\r\n0 1 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 0 0 0\r\n1 0 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 0 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 0 1\r\n0 1 1 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 1 1\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 0\r\n", "output": "YES\r\n"}]
| 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 |= 1<<i
if p[i] == 0:
y |= 1<<i
mask.append(x)
neg.append(y)
mask.sort()
for x in mask:
if x == 0:
print('YES')
exit(0)
import bisect
for x in neg:
idx = bisect.bisect_left(mask, x)
if idx < n and mask[idx] == x:
print('YES')
exit(0)
print('NO')
| 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_all(string, index + 1, temp, aux)
temp.pop()
temp.append('0')
get_all(string, index + 1, temp, aux)
temp.pop()
else:
temp.append('0')
get_all(string, index + 1, temp, aux)
temp.pop()
def counter(string):
temp = []
for i in string:
if i == '0':
temp.append('1')
else:
temp.append('0')
aux = []
get_all(temp, 0, [], aux)
return aux
# main starts
n, k = list(map(int, input().split()))
num = set()
for _ in range(n):
temp = list(input().split())
num.add("".join(temp))
if '0'*k in num:
print("YES")
exit()
# print(num)
for i in num:
a = counter(i)
for j in a:
if j in num:
print("YES")
exit()
else:
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. To make the contest interesting for them, each of the teams should know at most half of the selected problems.
Determine if Snark and Philip can make an interesting problemset!
|
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\n0 0 1\r\n1 0 1\r\n0 1 1\r\n1 0 0\r\n1 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 0 1\r\n1 1 0 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 1 0\r\n0 0 0 0\r\n0 0 1 0\r\n1 0 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n0 0\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 1\r\n1 0 0\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 0\r\n1 1 0 0\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 1\r\n1\r\n1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n0 1 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 0 1\r\n1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 1 1 0\r\n1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "6 3\r\n0 1 1\r\n1 0 1\r\n1 1 1\r\n0 1 0\r\n1 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n0 0 0 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 1 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "6 3\r\n1 0 0\r\n1 1 1\r\n1 1 1\r\n0 1 0\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 0 0\r\n1 1 1 1\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "1 3\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 1\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n1 1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n0 1 0 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n1 1 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 1 1\r\n1 0 1 0\r\n1 1 0 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 0 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 0\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 0 1\r\n0 0 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n1 1 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "8 4\r\n0 0 0 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 1\r\n1 1 1 0\r\n0 1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n0 0 0 1\r\n1 1 1 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n1 0 1\r\n0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 0 1\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 0 0\r\n1 0 1 0\r\n0 1 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 0 0 0\r\n1 0 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 0 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 0 1\r\n0 1 1 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 1 1\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 0\r\n", "output": "YES\r\n"}]
| 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):
s.add(int(''.join(input().split()),2))
for i in s:
for j in s:
if i&j==0:
print("YES")
exit()
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. To make the contest interesting for them, each of the teams should know at most half of the selected problems.
Determine if Snark and Philip can make an interesting problemset!
|
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\n0 0 1\r\n1 0 1\r\n0 1 1\r\n1 0 0\r\n1 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 0 1\r\n1 1 0 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 1 0\r\n0 0 0 0\r\n0 0 1 0\r\n1 0 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n0 0\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 1\r\n1 0 0\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 0\r\n1 1 0 0\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 1\r\n1\r\n1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n0 1 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 0 1\r\n1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 1 1 0\r\n1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 0\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "6 3\r\n0 1 1\r\n1 0 1\r\n1 1 1\r\n0 1 0\r\n1 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 0\r\n0 0\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n0 0 0 1\r\n1 0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 1 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "6 3\r\n1 0 0\r\n1 1 1\r\n1 1 1\r\n0 1 0\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 0 0\r\n1 1 1 1\r\n1 1 1 1\r\n1 0 1 1\r\n", "output": "YES\r\n"}, {"input": "1 3\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 1 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1 4\r\n0 0 0 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n0 1\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 1 0\r\n1 1 1\r\n0 0 1\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n0\r\n0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 1 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n1 1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n0 1 0 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 0 0 0\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 1 0\r\n0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n0 0 1\r\n1 1 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 1 1 1\r\n1 0 1 0\r\n1 1 0 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 0 0\r\n0 0 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 0\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "3 2\r\n1 0\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 0 1\r\n0 0 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n1 1 0 1\r\n0 0 1 0\r\n", "output": "YES\r\n"}, {"input": "8 4\r\n0 0 0 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n1 0 1 1\r\n1 1 1 0\r\n0 1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 1 0 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n1 0 1 0\r\n1 0 1 0\r\n0 1 1 1\r\n1 0 1 1\r\n1 1 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n0 0 0 1\r\n1 1 1 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n1 0 1\r\n0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 0 1\r\n1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 1 0 0\r\n1 0 1 0\r\n0 1 1 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n1 0 0 0\r\n1 0 0 1\r\n1 0 0 1\r\n0 1 1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 1 0\r\n0 1 0 0\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n0 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 1 1 0\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n0 1 0 1\r\n1 0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n1 0 1\r\n0 1 0\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n0 0 0 0\r\n0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 0 1\r\n0 1 1 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 1 1 0\r\n1 1 0 0\r\n0 0 1 1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 0 1 0\r\n0 0 0 1\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n0 1 0\r\n1 0 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 1 1\r\n0 1 1 0\r\n1 1 0 0\r\n1 0 0 1\r\n", "output": "YES\r\n"}, {"input": "10 4\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n0 0 1 1\r\n1 1 0 0\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 1 0\r\n0 1 1\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "2 3\r\n0 0 1\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "4 4\r\n0 0 0 1\r\n0 0 1 1\r\n1 1 0 1\r\n1 1 1 0\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n0 0 1 1\r\n1 0 1 0\r\n0 1 0 1\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n1 1 1 0\r\n1 1 0 1\r\n1 0 1 1\r\n0 1 1 1\r\n0 0 1 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n1 0 0 0\r\n1 1 0 0\r\n0 1 1 0\r\n", "output": "YES\r\n"}]
| 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
if i1 == 0:
b = b[:i2] + '|' + b[i2:]
elif i2 + 1 == len(b):
b = b[:i1] + '|' + b[i1:]
else:
b = b[:i1] + '|' + b[i1:i2] + '|' + b[i2:]
count = 0
if b[i] == 'a':
break
b = b[:len(b)-1]
b = b.replace('||', '|')
b = b + '|'
i1 = 0
for i in range(len(b)):
if b[i] == '|':
if len(set(b[i1:i])) != 1 and i - i1 > 1:
l = 2
for z in range(2,len(b[i1:i]),2):
b = b[:i1+l] + '|' + b[l+i1:]
l += 3
i1 = i + 1
b = b[:len(b)-1]
return b
ans = ''
for i in range(len(a)):
if a[i] in g:
if len(b) > 2:
ans += seach(b)
else:
ans += b
b = ''
ans += a[i]
else:
b += a[i]
ans = ans[:len(ans)-1]
ans = ans.replace('||', ' ')
ans = ans.replace('|', ' ')
print(ans)
| 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 i < len(s):
t.append(s[i])
i += 1
print(''.join(t))
|
Технокубок 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 three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
- the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
|
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"}, {"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz\r\n", "output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz \r\n"}, {"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte\r\n", "output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te \r\n"}, {"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz\r\n", "output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz \r\n"}, {"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf\r\n", "output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf \r\n"}, {"input": "mvjajoyeg\r\n", "output": "mv jajoyeg \r\n"}, {"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq\r\n", "output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q \r\n"}, {"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef\r\n", "output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef \r\n"}, {"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj\r\n", "output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j \r\n"}, {"input": "hzxkuwqxonsulnndlhygvmallghjerwp\r\n", "output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p \r\n"}, {"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd\r\n", "output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d \r\n"}, {"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr\r\n", "output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r \r\n"}, {"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu\r\n", "output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu \r\n"}, {"input": "a\r\n", "output": "a \r\n"}, {"input": "b\r\n", "output": "b \r\n"}, {"input": "aa\r\n", "output": "aa \r\n"}, {"input": "ab\r\n", "output": "ab \r\n"}, {"input": "ba\r\n", "output": "ba \r\n"}, {"input": "bb\r\n", "output": "bb \r\n"}, {"input": "aaa\r\n", "output": "aaa \r\n"}, {"input": "aab\r\n", "output": "aab \r\n"}, {"input": "aba\r\n", "output": "aba \r\n"}, {"input": "abb\r\n", "output": "abb \r\n"}, {"input": "baa\r\n", "output": "baa \r\n"}, {"input": "bab\r\n", "output": "bab \r\n"}, {"input": "bba\r\n", "output": "bba \r\n"}, {"input": "bbb\r\n", "output": "bbb \r\n"}, {"input": "bbc\r\n", "output": "bb c \r\n"}, {"input": "bcb\r\n", "output": "bc b \r\n"}, {"input": "cbb\r\n", "output": "cb b \r\n"}, {"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc\r\n", "output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc \r\n"}, {"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb\r\n", "output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b \r\n"}, {"input": "helllllooooo\r\n", "output": "helllllooooo \r\n"}, {"input": "bbbzxxx\r\n", "output": "bbb zx xx \r\n"}, {"input": "ffff\r\n", "output": "ffff \r\n"}, {"input": "cdddddddddddddddddd\r\n", "output": "cd ddddddddddddddddd \r\n"}, {"input": "bbbc\r\n", "output": "bbb c \r\n"}, {"input": "lll\r\n", "output": "lll \r\n"}, {"input": "bbbbb\r\n", "output": "bbbbb \r\n"}, {"input": "llll\r\n", "output": "llll \r\n"}, {"input": "bbbbbbccc\r\n", "output": "bbbbbb ccc \r\n"}, {"input": "lllllb\r\n", "output": "lllll b \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "lllll\r\n", "output": "lllll \r\n"}, {"input": "bbbbbbbbbc\r\n", "output": "bbbbbbbbb c \r\n"}, {"input": "helllllno\r\n", "output": "helllll no \r\n"}, {"input": "nnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnn \r\n"}, {"input": "bbbbbccc\r\n", "output": "bbbbb ccc \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "nnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "hhhh\r\n", "output": "hhhh \r\n"}, {"input": "nnnnnnnnnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzz\r\n", "output": "zzzzzzzzzz \r\n"}, {"input": "dddd\r\n", "output": "dddd \r\n"}, {"input": "heffffffgggggghhhhhh\r\n", "output": "heffffff gggggg hhhhhh \r\n"}, {"input": "bcddd\r\n", "output": "bc ddd \r\n"}, {"input": "x\r\n", "output": "x \r\n"}, {"input": "nnn\r\n", "output": "nnn \r\n"}, {"input": "xxxxxxxx\r\n", "output": "xxxxxxxx \r\n"}, {"input": "cclcc\r\n", "output": "cc lc c \r\n"}, {"input": "tttttttttttttt\r\n", "output": "tttttttttttttt \r\n"}, {"input": "xxxxxxx\r\n", "output": "xxxxxxx \r\n"}, {"input": "ccccb\r\n", "output": "cccc b \r\n"}, {"input": "bcecccc\r\n", "output": "bcecccc \r\n"}, {"input": "jjja\r\n", "output": "jjja \r\n"}, {"input": "zzz\r\n", "output": "zzz \r\n"}, {"input": "xxxxxxxxxzzzzzzzzzzzz\r\n", "output": "xxxxxxxxx zzzzzzzzzzzz \r\n"}, {"input": "alllewww\r\n", "output": "alllewww \r\n"}, {"input": "bbbbbbbbb\r\n", "output": "bbbbbbbbb \r\n"}, {"input": "jjj\r\n", "output": "jjj \r\n"}, {"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\r\n", "output": "bbbbbbbbbbbbbbbbbbbbbbbbb \r\n"}, {"input": "kkkkkkkkkklllllllllllllll\r\n", "output": "kkkkkkkkkk lllllllllllllll \r\n"}, {"input": "helllllllllllo\r\n", "output": "helllllllllllo \r\n"}, {"input": "ttttsttttt\r\n", "output": "tttt st tttt \r\n"}, {"input": "tttttttsssssss\r\n", "output": "ttttttt sssssss \r\n"}, {"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss\r\n", "output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss \r\n"}, {"input": "xxxxx\r\n", "output": "xxxxx \r\n"}, {"input": "bbbhbbb\r\n", "output": "bbb hb bb \r\n"}, {"input": "bbbbbbbb\r\n", "output": "bbbbbbbb \r\n"}]
| 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 sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length.
Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.
|
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": "2"}, {"input": "33\r\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36\r\n", "output": "5"}, {"input": "1\r\n1\r\n", "output": "0"}, {"input": "1\r\n10\r\n", "output": "0"}, {"input": "2\r\n1 1\r\n", "output": "0"}, {"input": "3\r\n1 1 1\r\n", "output": "0"}, {"input": "3\r\n1 2 2\r\n", "output": "0"}, {"input": "3\r\n3 2 1\r\n", "output": "0"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1"}, {"input": "4\r\n1 2 1 2\r\n", "output": "1"}, {"input": "4\r\n1 100 1 100\r\n", "output": "1"}, {"input": "4\r\n10 100 100 10\r\n", "output": "1"}, {"input": "4\r\n1 2 3 3\r\n", "output": "0"}, {"input": "4\r\n8 5 9 13\r\n", "output": "0"}, {"input": "4\r\n100 100 100 100\r\n", "output": "1"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1"}, {"input": "5\r\n1 4 4 1 1\r\n", "output": "1"}, {"input": "5\r\n1 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 100 1 1 100\r\n", "output": "1"}, {"input": "5\r\n100 1 100 100 100\r\n", "output": "1"}, {"input": "5\r\n100 100 100 100 100\r\n", "output": "1"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "1"}, {"input": "6\r\n1 1 5 1 1 5\r\n", "output": "1"}, {"input": "6\r\n1 100 100 1 1 1\r\n", "output": "1"}, {"input": "6\r\n100 1 1 100 1 100\r\n", "output": "1"}, {"input": "6\r\n1 2 3 2 3 1\r\n", "output": "1"}, {"input": "6\r\n1 50 1 100 50 100\r\n", "output": "1"}, {"input": "6\r\n10 10 10 12 13 14\r\n", "output": "0"}, {"input": "7\r\n1 1 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 1 1 1 1 1\r\n", "output": "1"}, {"input": "7\r\n1 2 2 1 2 1 2\r\n", "output": "1"}, {"input": "7\r\n1 1 2 2 1 2 3\r\n", "output": "1"}, {"input": "7\r\n1 3 2 2 3 1 4\r\n", "output": "1"}, {"input": "7\r\n1 3 4 3 5 4 6\r\n", "output": "1"}, {"input": "7\r\n7 6 5 4 3 2 1\r\n", "output": "0"}, {"input": "8\r\n1 2 1 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 2 1 1 2 2 2\r\n", "output": "1"}, {"input": "8\r\n1 2 2 2 3 1 1 3\r\n", "output": "1"}, {"input": "8\r\n1 2 3 4 1 2 3 4\r\n", "output": "2"}, {"input": "8\r\n1 1 1 1 2 3 2 3\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 5 5 5\r\n", "output": "1"}, {"input": "8\r\n1 2 1 3 4 1 5 6\r\n", "output": "0"}, {"input": "8\r\n1 2 3 4 5 6 1 7\r\n", "output": "0"}, {"input": "8\r\n8 6 3 4 5 2 1 7\r\n", "output": "0"}, {"input": "8\r\n100 100 100 100 100 100 100 100\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "10\r\n19 9 14 14 19 5 5 18 10 17\r\n", "output": "1"}, {"input": "10\r\n72 86 73 25 84 29 33 34 20 29\r\n", "output": "0"}, {"input": "10\r\n93 93 99 98 91 96 92 98 94 98\r\n", "output": "1"}, {"input": "13\r\n35 6 21 30 67 55 70 39 75 72 11 13 69\r\n", "output": "0"}, {"input": "17\r\n90 97 12 56 94 11 49 96 22 7 15 48 71 71 94 72 100\r\n", "output": "1"}, {"input": "18\r\n39 72 67 28 69 41 43 51 66 99 4 57 68 93 28 27 37 27\r\n", "output": "1"}, {"input": "23\r\n88 82 2 67 4 6 67 83 77 58 48 64 86 37 96 83 35 46 13 79 72 18 35\r\n", "output": "1"}, {"input": "30\r\n43 34 38 50 47 24 26 20 7 5 26 29 98 87 90 46 10 53 88 61 90 39 78 81 65 13 72 95 53 27\r\n", "output": "1"}, {"input": "33\r\n1 3 34 55 38 58 64 26 66 44 50 63 46 62 62 99 73 87 35 20 30 38 39 85 49 24 93 68 8 25 86 30 51\r\n", "output": "1"}, {"input": "38\r\n65 69 80 93 28 36 40 81 53 75 55 50 82 95 8 51 66 65 50 4 40 92 18 70 38 68 42 100 34 57 98 79 95 84 82 35 100 89\r\n", "output": "3"}, {"input": "40\r\n4 2 62 38 76 68 19 71 44 91 76 31 3 63 56 62 93 98 10 61 52 59 81 46 23 27 36 26 24 38 37 66 15 16 78 41 95 82 73 90\r\n", "output": "1"}, {"input": "43\r\n62 31 14 43 67 2 60 77 64 70 91 9 3 43 76 7 56 84 5 20 88 50 47 42 7 39 8 56 71 24 49 59 70 61 81 17 76 44 80 61 77 5 96\r\n", "output": "4"}, {"input": "49\r\n75 64 7 2 1 66 31 84 78 53 34 5 40 90 7 62 86 54 99 77 8 92 30 3 18 18 61 38 38 11 79 88 84 89 50 94 72 8 54 85 100 1 19 4 97 91 13 39 91\r\n", "output": "4"}, {"input": "57\r\n83 94 42 57 19 9 40 25 56 92 9 38 58 66 43 19 50 10 100 3 49 96 77 36 20 3 48 15 38 19 99 100 66 14 52 13 16 73 65 99 29 85 75 18 97 64 57 82 70 19 16 25 40 11 9 22 89\r\n", "output": "6"}, {"input": "67\r\n36 22 22 86 52 53 36 68 46 82 99 37 15 43 57 35 33 99 22 96 7 8 80 93 70 70 55 51 61 74 6 28 85 72 84 42 29 1 4 71 7 40 61 95 93 36 42 61 16 40 10 85 31 86 93 19 44 20 52 66 10 22 40 53 25 29 23\r\n", "output": "8"}, {"input": "74\r\n90 26 58 69 87 23 44 9 32 25 33 13 79 84 52 90 4 7 93 77 29 85 22 1 96 69 98 16 76 87 57 16 44 41 57 28 18 70 77 83 37 17 59 87 27 19 89 63 14 84 77 40 46 77 82 73 86 73 30 58 6 30 70 36 31 12 43 50 93 3 3 57 38 91\r\n", "output": "7"}, {"input": "100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "25"}, {"input": "100\r\n1 9 3 5 10 10 9 8 10 1 7 6 5 6 7 9 1 5 8 3 2 3 3 10 2 3 10 7 10 3 6 3 2 10 1 10 2 3 4 3 3 1 7 5 10 2 3 8 9 2 5 4 7 2 5 9 2 1 7 9 9 8 4 4 6 1 6 6 4 7 2 3 1 1 1 6 9 1 2 9 3 7 6 10 3 6 2 5 2 5 3 9 10 6 4 2 9 9 4 5\r\n", "output": "23"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "7\r\n13 13 13 13 6 2 3\r\n", "output": "1"}, {"input": "8\r\n1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n100 100 99 99 5\r\n", "output": "1"}, {"input": "8\r\n2 2 2 2 2 2 2 2\r\n", "output": "2"}, {"input": "8\r\n1 2 3 4 5 6 7 7\r\n", "output": "0"}, {"input": "8\r\n4 4 4 4 4 4 4 4\r\n", "output": "2"}, {"input": "10\r\n1 1 1 1 1 1 1 1 2 2\r\n", "output": "2"}, {"input": "4\r\n100 100 100 99\r\n", "output": "0"}, {"input": "4\r\n2 2 2 2\r\n", "output": "1"}, {"input": "5\r\n100 100 99 99 2\r\n", "output": "1"}, {"input": "9\r\n1 1 1 1 1 1 1 1 1\r\n", "output": "2"}, {"input": "5\r\n2 2 3 4 4\r\n", "output": "1"}, {"input": "100\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "25"}, {"input": "13\r\n1 2 3 4 5 6 7 8 9 10 11 12 13\r\n", "output": "0"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "4\r\n4 4 4 4\r\n", "output": "1"}, {"input": "5\r\n1 1 2 3 3\r\n", "output": "1"}, {"input": "5\r\n30 30 30 1 1\r\n", "output": "1"}]
| 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
bad = ''
i += 1
else:
a += bad[0:2] + ' '
bad = ''
else:
i+=1
a += bad
print(a)
| 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 three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
- the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
|
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"}, {"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz\r\n", "output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz \r\n"}, {"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte\r\n", "output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te \r\n"}, {"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz\r\n", "output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz \r\n"}, {"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf\r\n", "output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf \r\n"}, {"input": "mvjajoyeg\r\n", "output": "mv jajoyeg \r\n"}, {"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq\r\n", "output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q \r\n"}, {"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef\r\n", "output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef \r\n"}, {"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj\r\n", "output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j \r\n"}, {"input": "hzxkuwqxonsulnndlhygvmallghjerwp\r\n", "output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p \r\n"}, {"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd\r\n", "output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d \r\n"}, {"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr\r\n", "output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r \r\n"}, {"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu\r\n", "output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu \r\n"}, {"input": "a\r\n", "output": "a \r\n"}, {"input": "b\r\n", "output": "b \r\n"}, {"input": "aa\r\n", "output": "aa \r\n"}, {"input": "ab\r\n", "output": "ab \r\n"}, {"input": "ba\r\n", "output": "ba \r\n"}, {"input": "bb\r\n", "output": "bb \r\n"}, {"input": "aaa\r\n", "output": "aaa \r\n"}, {"input": "aab\r\n", "output": "aab \r\n"}, {"input": "aba\r\n", "output": "aba \r\n"}, {"input": "abb\r\n", "output": "abb \r\n"}, {"input": "baa\r\n", "output": "baa \r\n"}, {"input": "bab\r\n", "output": "bab \r\n"}, {"input": "bba\r\n", "output": "bba \r\n"}, {"input": "bbb\r\n", "output": "bbb \r\n"}, {"input": "bbc\r\n", "output": "bb c \r\n"}, {"input": "bcb\r\n", "output": "bc b \r\n"}, {"input": "cbb\r\n", "output": "cb b \r\n"}, {"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc\r\n", "output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc \r\n"}, {"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb\r\n", "output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b \r\n"}, {"input": "helllllooooo\r\n", "output": "helllllooooo \r\n"}, {"input": "bbbzxxx\r\n", "output": "bbb zx xx \r\n"}, {"input": "ffff\r\n", "output": "ffff \r\n"}, {"input": "cdddddddddddddddddd\r\n", "output": "cd ddddddddddddddddd \r\n"}, {"input": "bbbc\r\n", "output": "bbb c \r\n"}, {"input": "lll\r\n", "output": "lll \r\n"}, {"input": "bbbbb\r\n", "output": "bbbbb \r\n"}, {"input": "llll\r\n", "output": "llll \r\n"}, {"input": "bbbbbbccc\r\n", "output": "bbbbbb ccc \r\n"}, {"input": "lllllb\r\n", "output": "lllll b \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "lllll\r\n", "output": "lllll \r\n"}, {"input": "bbbbbbbbbc\r\n", "output": "bbbbbbbbb c \r\n"}, {"input": "helllllno\r\n", "output": "helllll no \r\n"}, {"input": "nnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnn \r\n"}, {"input": "bbbbbccc\r\n", "output": "bbbbb ccc \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "nnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzz \r\n"}, {"input": "hhhh\r\n", "output": "hhhh \r\n"}, {"input": "nnnnnnnnnnnnnnnnnnnnnnnnn\r\n", "output": "nnnnnnnnnnnnnnnnnnnnnnnnn \r\n"}, {"input": "zzzzzzzzzz\r\n", "output": "zzzzzzzzzz \r\n"}, {"input": "dddd\r\n", "output": "dddd \r\n"}, {"input": "heffffffgggggghhhhhh\r\n", "output": "heffffff gggggg hhhhhh \r\n"}, {"input": "bcddd\r\n", "output": "bc ddd \r\n"}, {"input": "x\r\n", "output": "x \r\n"}, {"input": "nnn\r\n", "output": "nnn \r\n"}, {"input": "xxxxxxxx\r\n", "output": "xxxxxxxx \r\n"}, {"input": "cclcc\r\n", "output": "cc lc c \r\n"}, {"input": "tttttttttttttt\r\n", "output": "tttttttttttttt \r\n"}, {"input": "xxxxxxx\r\n", "output": "xxxxxxx \r\n"}, {"input": "ccccb\r\n", "output": "cccc b \r\n"}, {"input": "bcecccc\r\n", "output": "bcecccc \r\n"}, {"input": "jjja\r\n", "output": "jjja \r\n"}, {"input": "zzz\r\n", "output": "zzz \r\n"}, {"input": "xxxxxxxxxzzzzzzzzzzzz\r\n", "output": "xxxxxxxxx zzzzzzzzzzzz \r\n"}, {"input": "alllewww\r\n", "output": "alllewww \r\n"}, {"input": "bbbbbbbbb\r\n", "output": "bbbbbbbbb \r\n"}, {"input": "jjj\r\n", "output": "jjj \r\n"}, {"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\r\n", "output": "bbbbbbbbbbbbbbbbbbbbbbbbb \r\n"}, {"input": "kkkkkkkkkklllllllllllllll\r\n", "output": "kkkkkkkkkk lllllllllllllll \r\n"}, {"input": "helllllllllllo\r\n", "output": "helllllllllllo \r\n"}, {"input": "ttttsttttt\r\n", "output": "tttt st tttt \r\n"}, {"input": "tttttttsssssss\r\n", "output": "ttttttt sssssss \r\n"}, {"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss\r\n", "output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss \r\n"}, {"input": "xxxxx\r\n", "output": "xxxxx \r\n"}, {"input": "bbbhbbb\r\n", "output": "bbb hb bb \r\n"}, {"input": "bbbbbbbb\r\n", "output": "bbbbbbbb \r\n"}]
| 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
num.insert(x,p)
x+=1
print(banyak)
print(' '.join(list(map(str,num))))
| 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:
print(1, end=" ")
print(arr[i], end=" ")
|
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 integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
|
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. Also the new array should be got from the original array a by adding k elements to it.
If there are multiple answers you can print any one of them.
| 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"}, {"input": "10\r\n26 723 970 13 422 968 875 329 234 983\r\n", "output": "2\r\n26 723 970 13 422 1 968 875 1 329 234 983\r\n"}, {"input": "10\r\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\r\n", "output": "7\r\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396\r\n"}, {"input": "100\r\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1\r\n", "output": "19\r\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1\r\n"}, {"input": "100\r\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917\r\n", "output": "38\r\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917\r\n"}, {"input": "5\r\n472882027 472882027 472882027 472882027 472882027\r\n", "output": "4\r\n472882027 1 472882027 1 472882027 1 472882027 1 472882027\r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "1\r\n1000000000 1 1000000000\r\n"}, {"input": "2\r\n8 6\r\n", "output": "1\r\n8 1 6\r\n"}, {"input": "3\r\n100000000 1000000000 1000000000\r\n", "output": "2\r\n100000000 1 1000000000 1 1000000000\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n1 2 3 4 5\r\n"}, {"input": "20\r\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000\r\n", "output": "19\r\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000\r\n"}, {"input": "2\r\n223092870 23\r\n", "output": "1\r\n223092870 1 23\r\n"}, {"input": "2\r\n100000003 100000003\r\n", "output": "1\r\n100000003 1 100000003\r\n"}, {"input": "2\r\n999999937 999999937\r\n", "output": "1\r\n999999937 1 999999937\r\n"}, {"input": "4\r\n999 999999937 999999937 999\r\n", "output": "1\r\n999 999999937 1 999999937 999\r\n"}, {"input": "2\r\n999999929 999999929\r\n", "output": "1\r\n999999929 1 999999929\r\n"}, {"input": "2\r\n1049459 2098918\r\n", "output": "1\r\n1049459 1 2098918\r\n"}, {"input": "2\r\n352229 704458\r\n", "output": "1\r\n352229 1 704458\r\n"}, {"input": "2\r\n7293 4011\r\n", "output": "1\r\n7293 1 4011\r\n"}, {"input": "2\r\n5565651 3999930\r\n", "output": "1\r\n5565651 1 3999930\r\n"}, {"input": "2\r\n997 997\r\n", "output": "1\r\n997 1 997\r\n"}, {"input": "3\r\n9994223 9994223 9994223\r\n", "output": "2\r\n9994223 1 9994223 1 9994223\r\n"}, {"input": "2\r\n99999998 1000000000\r\n", "output": "1\r\n99999998 1 1000000000\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "2\r\n1000000000 1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n130471 130471\r\n", "output": "1\r\n130471 1 130471\r\n"}, {"input": "3\r\n1000000000 2 2\r\n", "output": "2\r\n1000000000 1 2 1 2\r\n"}, {"input": "2\r\n223092870 66526\r\n", "output": "1\r\n223092870 1 66526\r\n"}, {"input": "14\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449\r\n", "output": "10\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449\r\n"}, {"input": "2\r\n3996017 3996017\r\n", "output": "1\r\n3996017 1 3996017\r\n"}, {"input": "2\r\n999983 999983\r\n", "output": "1\r\n999983 1 999983\r\n"}, {"input": "2\r\n618575685 773990454\r\n", "output": "1\r\n618575685 1 773990454\r\n"}, {"input": "3\r\n9699690 3 7\r\n", "output": "1\r\n9699690 1 3 7\r\n"}, {"input": "2\r\n999999999 999999996\r\n", "output": "1\r\n999999999 1 999999996\r\n"}, {"input": "2\r\n99999910 99999910\r\n", "output": "1\r\n99999910 1 99999910\r\n"}, {"input": "12\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491\r\n", "output": "9\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491\r\n"}, {"input": "3\r\n999999937 999999937 999999937\r\n", "output": "2\r\n999999937 1 999999937 1 999999937\r\n"}, {"input": "2\r\n99839 99839\r\n", "output": "1\r\n99839 1 99839\r\n"}, {"input": "3\r\n19999909 19999909 19999909\r\n", "output": "2\r\n19999909 1 19999909 1 19999909\r\n"}, {"input": "4\r\n1 1000000000 1 1000000000\r\n", "output": "0\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n64006 64006\r\n", "output": "1\r\n64006 1 64006\r\n"}, {"input": "2\r\n1956955 1956955\r\n", "output": "1\r\n1956955 1 1956955\r\n"}, {"input": "3\r\n1 1000000000 1000000000\r\n", "output": "1\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n982451707 982451707\r\n", "output": "1\r\n982451707 1 982451707\r\n"}, {"input": "2\r\n999999733 999999733\r\n", "output": "1\r\n999999733 1 999999733\r\n"}, {"input": "3\r\n999999733 999999733 999999733\r\n", "output": "2\r\n999999733 1 999999733 1 999999733\r\n"}, {"input": "2\r\n3257 3257\r\n", "output": "1\r\n3257 1 3257\r\n"}, {"input": "2\r\n223092870 181598\r\n", "output": "1\r\n223092870 1 181598\r\n"}, {"input": "3\r\n959919409 105935 105935\r\n", "output": "2\r\n959919409 1 105935 1 105935\r\n"}, {"input": "2\r\n510510 510510\r\n", "output": "1\r\n510510 1 510510\r\n"}, {"input": "3\r\n223092870 1000000000 1000000000\r\n", "output": "2\r\n223092870 1 1000000000 1 1000000000\r\n"}, {"input": "14\r\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000\r\n", "output": "11\r\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000\r\n"}, {"input": "7\r\n1 982451653 982451653 1 982451653 982451653 982451653\r\n", "output": "3\r\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653\r\n"}, {"input": "2\r\n100000007 100000007\r\n", "output": "1\r\n100000007 1 100000007\r\n"}, {"input": "3\r\n999999757 999999757 999999757\r\n", "output": "2\r\n999999757 1 999999757 1 999999757\r\n"}, {"input": "3\r\n99999989 99999989 99999989\r\n", "output": "2\r\n99999989 1 99999989 1 99999989\r\n"}, {"input": "5\r\n2 4 982451707 982451707 3\r\n", "output": "2\r\n2 1 4 982451707 1 982451707 3\r\n"}, {"input": "2\r\n20000014 20000014\r\n", "output": "1\r\n20000014 1 20000014\r\n"}, {"input": "2\r\n99999989 99999989\r\n", "output": "1\r\n99999989 1 99999989\r\n"}, {"input": "2\r\n111546435 111546435\r\n", "output": "1\r\n111546435 1 111546435\r\n"}, {"input": "2\r\n55288874 33538046\r\n", "output": "1\r\n55288874 1 33538046\r\n"}, {"input": "5\r\n179424673 179424673 179424673 179424673 179424673\r\n", "output": "4\r\n179424673 1 179424673 1 179424673 1 179424673 1 179424673\r\n"}, {"input": "2\r\n199999978 199999978\r\n", "output": "1\r\n199999978 1 199999978\r\n"}, {"input": "2\r\n1000000000 2\r\n", "output": "1\r\n1000000000 1 2\r\n"}, {"input": "3\r\n19999897 19999897 19999897\r\n", "output": "2\r\n19999897 1 19999897 1 19999897\r\n"}, {"input": "2\r\n19999982 19999982\r\n", "output": "1\r\n19999982 1 19999982\r\n"}, {"input": "2\r\n10000007 10000007\r\n", "output": "1\r\n10000007 1 10000007\r\n"}, {"input": "3\r\n999999937 999999937 2\r\n", "output": "1\r\n999999937 1 999999937 2\r\n"}, {"input": "5\r\n2017 2017 2017 2017 2017\r\n", "output": "4\r\n2017 1 2017 1 2017 1 2017 1 2017\r\n"}, {"input": "2\r\n19999909 39999818\r\n", "output": "1\r\n19999909 1 39999818\r\n"}, {"input": "2\r\n62615533 7919\r\n", "output": "1\r\n62615533 1 7919\r\n"}, {"input": "5\r\n39989 39989 33 31 29\r\n", "output": "1\r\n39989 1 39989 33 31 29\r\n"}, {"input": "2\r\n1000000000 100000\r\n", "output": "1\r\n1000000000 1 100000\r\n"}, {"input": "2\r\n1938 10010\r\n", "output": "1\r\n1938 1 10010\r\n"}, {"input": "2\r\n199999 199999\r\n", "output": "1\r\n199999 1 199999\r\n"}, {"input": "2\r\n107273 107273\r\n", "output": "1\r\n107273 1 107273\r\n"}, {"input": "3\r\n49999 49999 49999\r\n", "output": "2\r\n49999 1 49999 1 49999\r\n"}, {"input": "2\r\n1999966 1999958\r\n", "output": "1\r\n1999966 1 1999958\r\n"}, {"input": "2\r\n86020 300846\r\n", "output": "1\r\n86020 1 300846\r\n"}, {"input": "2\r\n999999997 213\r\n", "output": "1\r\n999999997 1 213\r\n"}, {"input": "2\r\n200000014 200000434\r\n", "output": "1\r\n200000014 1 200000434\r\n"}]
| false
|
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# 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) as f:
lines = f.readlines()
if len(lines) < 2:
print(0)
return
try:
k_sub = int(lines[0].strip())
array_sub = list(map(int, lines[1].strip().split()))
except:
print(0)
return
# Check array_sub length
if len(array_sub) != n + k_sub:
print(0)
return
# Read reference output's k_ref
with open(output_path) as f:
k_ref = int(f.readline().strip())
# Check k_sub equals k_ref
if k_sub != k_ref:
print(0)
return
# Check original array is a subsequence of array_sub
i = 0
for num in array_sub:
if i < len(a) and num == a[i]:
i += 1
if i != len(a):
print(0)
return
# Check all adjacent pairs are coprime
for j in range(len(array_sub)-1):
x = array_sub[j]
y = array_sub[j+1]
if math.gcd(x, y) != 1:
print(0)
return
# All checks passed
print(1)
if __name__ == "__main__":
main()
| 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][L[i][j]-1] != j+1:
return False
if all((len(D[i]) < 3) for i in range(n)):
return True
for x in range(m):
for y in range(x,m):
for i in range(n):
if not (x+1 in D[i] and y+1 in D[i] or len(D[i]) == 0):
break
else:
return True
return False
print('YES') if solve(L) else print('NO')
| 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 range(j):
b = [r[:]for r in a]
for k in range(n):
b[k][i], b[k][j] = b[k][j], b[k][i]
if test(b):
exit(print('YES'))
print('NO')
|
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 to perform from 0 to n + 1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
|
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 8 9 10\r\n", "output": "YES\r\n"}, {"input": "5 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 8 5 6 7 10 9 4 11 12\r\n1 5 3 4 2 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n", "output": "YES\r\n"}, {"input": "4 10\r\n3 2 8 10 5 6 7 1 9 4\r\n1 2 9 4 5 3 7 8 10 6\r\n7 5 3 4 8 6 1 2 9 10\r\n4 2 3 9 8 6 7 5 1 10\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n9 2 3 4 5 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 10 7 8 1 6\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n9 10 4 2 3 5 7 1 8 6\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n6 4 7 3 5 8 1 9 10 2\r\n1 5 10 6 3 4 9 7 2 8\r\n3 2 1 7 8 6 5 4 10 9\r\n7 9 1 6 8 2 4 5 3 10\r\n3 4 6 9 8 7 1 2 10 5\r\n", "output": "NO\r\n"}, {"input": "20 2\r\n1 2\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "20 3\r\n3 2 1\r\n2 3 1\r\n2 3 1\r\n2 1 3\r\n1 3 2\r\n2 1 3\r\n1 2 3\r\n3 2 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n2 1 3\r\n2 3 1\r\n2 3 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n3 1 2\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 2 3 4 5 6 7 10 9 8\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n6 9 3 4 5 1 8 7 2 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 19 14 15 16 17 18 13 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 20\r\n1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 17 18 19 20\r\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 12 18 7 8 9 10 11 5 13 14 15 16 17 6 19 20\r\n6 2 3 4 5 1 7 8 9 10 11 12 13 20 15 16 17 18 19 14\r\n4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 19 8 9 10 11 12 13 14 15 20 17 18 7 16\r\n1 2 9 4 5 6 7 8 18 10 11 12 13 14 15 16 17 3 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n4 2 3 8 5 6 7 1 9 10\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n3 2 1 4 5 6 7 8 10 9\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 18 14 15 16 17 13 11 20\r\n1 2 11 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 3 20\r\n13 2 3 4 5 6 7 8 9 10 19 12 1 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 16 8 9 10 11 12 13 14 15 7 17 18 19 20\r\n1 2 3 14 5 6 16 8 9 10 11 12 13 4 15 7 17 18 19 20\r\n1 2 3 4 5 6 16 8 18 10 11 12 13 14 15 7 17 9 19 20\r\n1 2 3 4 5 6 16 8 9 15 11 12 13 14 10 7 17 18 19 20\r\n1 2 18 4 5 6 16 8 9 10 11 12 13 14 15 7 17 3 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 18 4 5 6 7 8 9 10 11 12 13 14 15 16 19 3 17 20\r\n8 2 3 9 5 6 7 1 4 10 11 12 13 14 15 16 17 18 19 20\r\n7 2 3 4 5 6 1 8 9 10 11 12 13 14 15 16 17 20 19 18\r\n1 2 3 12 5 6 7 8 9 17 11 4 13 14 15 16 10 18 19 20\r\n1 11 3 4 9 6 7 8 5 10 2 12 13 14 15 16 17 18 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n10 2 3 4 5 9 7 8 6 1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 9 2 4 6 5 8 3 7 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 3 2 19 5 6 7 8 9 17 11 12 13 14 15 16 10 18 4 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 20 6 7 8 9 17 11 12 13 14 15 16 10 18 19 5\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 6 17 4 5 2 7 14 9 10 11 12 13 8 15 16 3 18 19 20\r\n5 6 17 4 1 2 7 8 9 10 11 12 13 14 15 16 3 18 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 18 3 16 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 16 3 18 20 19\r\n1 6 17 8 5 2 7 4 9 10 11 12 13 14 15 16 3 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n10 2 9 4 5 6 7 8 15 1 11 16 13 14 3 12 17 18 19 20\r\n10 2 3 4 5 6 7 1 9 8 11 16 13 14 15 12 17 18 19 20\r\n9 2 3 4 5 6 7 8 10 1 11 16 13 14 15 12 20 18 19 17\r\n10 2 3 4 7 6 5 8 9 1 11 16 18 14 15 12 17 13 19 20\r\n10 2 3 4 5 6 7 8 9 20 11 16 14 13 15 12 17 18 19 1\r\n", "output": "NO\r\n"}, {"input": "1 4\r\n2 3 4 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 1 3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "15 6\r\n2 1 4 3 6 5\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n4 3 1 2\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "4 8\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n", "output": "YES\r\n"}, {"input": "4 6\r\n1 2 3 5 6 4\r\n3 2 1 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n3 1 2\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 1 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "20 8\r\n4 3 2 1 5 6 7 8\r\n1 2 3 4 8 7 6 5\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n8 7 6 5 4 3 2 1\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n", "output": "YES\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 11 12 9\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n3 2 1 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n2 3 1 4 5 6\r\n1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n2 3 1\r\n2 3 1\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "5 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n3 8 1 4 5 6 7 2\r\n1 8 3 6 5 4 7 2\r\n1 8 3 5 4 6 7 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 4 3 1\r\n2 1 5 4 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 3 1 4\r\n1 2 3 4\r\n2 3 1 4\r\n2 1 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 4 3 5\r\n2 1 4 3 5\r\n1 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "3 10\r\n2 1 3 4 5 6 8 7 10 9\r\n1 2 3 4 5 6 8 7 10 9\r\n1 2 3 4 6 5 8 7 10 9\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n3 1 2 4\r\n3 2 4 1\r\n3 1 2 4\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n1 4 2 3 5\r\n1 2 4 5 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 3 4\r\n2 1 5 3 4\r\n", "output": "NO\r\n"}, {"input": "3 6\r\n2 3 1 4 5 6\r\n2 1 4 3 5 6\r\n1 2 3 4 5 6\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "4 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 3 4 5\r\n1 3 4 2 5\r\n1 4 2 3 5\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 2 3\r\n1 2 3\r\n1 2 3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n3 1 2\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "7 4\r\n1 2 3 4\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 2 3\r\n1 3 2\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}]
| 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)):
t=i
d+=1
#print(i)
if d==1:
print(math.ceil(n/t))
else:
print(-1)
| 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 on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
|
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 ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
|
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-th flat.
|
[{"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\n"}, {"input": "16 6\r\n3 1\r\n16 4\r\n10 3\r\n9 3\r\n19 5\r\n8 2\r\n", "output": "4\r\n"}, {"input": "1 0\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1 1\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n3 3\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 1\r\n3 3\r\n", "output": "3\r\n"}, {"input": "3 3\r\n1 1\r\n3 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 3\r\n3 2\r\n1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "3 1\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n1 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "1 3\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "81 0\r\n", "output": "-1\r\n"}, {"input": "22 1\r\n73 73\r\n", "output": "22\r\n"}, {"input": "63 2\r\n10 10\r\n64 64\r\n", "output": "63\r\n"}, {"input": "88 3\r\n37 37\r\n15 15\r\n12 12\r\n", "output": "88\r\n"}, {"input": "29 4\r\n66 66\r\n47 47\r\n62 62\r\n2 2\r\n", "output": "29\r\n"}, {"input": "9 40\r\n72 72\r\n47 47\r\n63 63\r\n66 66\r\n21 21\r\n94 94\r\n28 28\r\n45 45\r\n93 93\r\n25 25\r\n100 100\r\n43 43\r\n49 49\r\n9 9\r\n74 74\r\n26 26\r\n42 42\r\n50 50\r\n2 2\r\n92 92\r\n76 76\r\n3 3\r\n78 78\r\n44 44\r\n69 69\r\n36 36\r\n65 65\r\n81 81\r\n13 13\r\n46 46\r\n24 24\r\n96 96\r\n73 73\r\n82 82\r\n68 68\r\n64 64\r\n41 41\r\n31 31\r\n29 29\r\n10 10\r\n", "output": "9\r\n"}, {"input": "50 70\r\n3 3\r\n80 80\r\n23 23\r\n11 11\r\n87 87\r\n7 7\r\n63 63\r\n61 61\r\n67 67\r\n53 53\r\n9 9\r\n43 43\r\n55 55\r\n27 27\r\n5 5\r\n1 1\r\n99 99\r\n65 65\r\n37 37\r\n60 60\r\n32 32\r\n38 38\r\n81 81\r\n2 2\r\n34 34\r\n17 17\r\n82 82\r\n26 26\r\n71 71\r\n4 4\r\n16 16\r\n19 19\r\n39 39\r\n51 51\r\n6 6\r\n49 49\r\n64 64\r\n83 83\r\n10 10\r\n56 56\r\n30 30\r\n76 76\r\n90 90\r\n42 42\r\n47 47\r\n91 91\r\n21 21\r\n52 52\r\n40 40\r\n77 77\r\n35 35\r\n88 88\r\n75 75\r\n95 95\r\n28 28\r\n15 15\r\n69 69\r\n22 22\r\n48 48\r\n66 66\r\n31 31\r\n98 98\r\n73 73\r\n25 25\r\n97 97\r\n18 18\r\n13 13\r\n54 54\r\n72 72\r\n29 29\r\n", "output": "50\r\n"}, {"input": "6 0\r\n", "output": "-1\r\n"}, {"input": "32 1\r\n9 5\r\n", "output": "16\r\n"}, {"input": "73 2\r\n17 9\r\n21 11\r\n", "output": "37\r\n"}, {"input": "6 3\r\n48 24\r\n51 26\r\n62 31\r\n", "output": "3\r\n"}, {"input": "43 4\r\n82 41\r\n52 26\r\n88 44\r\n41 21\r\n", "output": "22\r\n"}, {"input": "28 40\r\n85 43\r\n19 10\r\n71 36\r\n39 20\r\n57 29\r\n6 3\r\n15 8\r\n11 6\r\n99 50\r\n77 39\r\n79 40\r\n31 16\r\n35 18\r\n24 12\r\n54 27\r\n93 47\r\n90 45\r\n72 36\r\n63 32\r\n22 11\r\n83 42\r\n5 3\r\n12 6\r\n56 28\r\n94 47\r\n25 13\r\n41 21\r\n29 15\r\n36 18\r\n23 12\r\n1 1\r\n84 42\r\n55 28\r\n58 29\r\n9 5\r\n68 34\r\n86 43\r\n3 2\r\n48 24\r\n98 49\r\n", "output": "14\r\n"}, {"input": "81 70\r\n55 28\r\n85 43\r\n58 29\r\n20 10\r\n4 2\r\n47 24\r\n42 21\r\n28 14\r\n26 13\r\n38 19\r\n9 5\r\n83 42\r\n7 4\r\n72 36\r\n18 9\r\n61 31\r\n41 21\r\n64 32\r\n90 45\r\n46 23\r\n67 34\r\n2 1\r\n6 3\r\n27 14\r\n87 44\r\n39 20\r\n11 6\r\n21 11\r\n35 18\r\n48 24\r\n44 22\r\n3 2\r\n71 36\r\n62 31\r\n34 17\r\n16 8\r\n99 50\r\n57 29\r\n13 7\r\n79 40\r\n100 50\r\n53 27\r\n89 45\r\n36 18\r\n43 22\r\n92 46\r\n98 49\r\n75 38\r\n40 20\r\n97 49\r\n37 19\r\n68 34\r\n30 15\r\n96 48\r\n17 9\r\n12 6\r\n45 23\r\n65 33\r\n76 38\r\n84 42\r\n23 12\r\n91 46\r\n52 26\r\n8 4\r\n32 16\r\n77 39\r\n88 44\r\n86 43\r\n70 35\r\n51 26\r\n", "output": "41\r\n"}, {"input": "34 0\r\n", "output": "-1\r\n"}, {"input": "63 1\r\n94 24\r\n", "output": "16\r\n"}, {"input": "4 2\r\n38 10\r\n48 12\r\n", "output": "1\r\n"}, {"input": "37 3\r\n66 17\r\n89 23\r\n60 15\r\n", "output": "10\r\n"}, {"input": "71 4\r\n15 4\r\n13 4\r\n4 1\r\n70 18\r\n", "output": "18\r\n"}, {"input": "77 40\r\n49 13\r\n66 17\r\n73 19\r\n15 4\r\n36 9\r\n1 1\r\n41 11\r\n91 23\r\n51 13\r\n46 12\r\n39 10\r\n42 11\r\n56 14\r\n61 16\r\n70 18\r\n92 23\r\n65 17\r\n54 14\r\n97 25\r\n8 2\r\n87 22\r\n33 9\r\n28 7\r\n38 10\r\n50 13\r\n26 7\r\n7 2\r\n31 8\r\n84 21\r\n47 12\r\n27 7\r\n53 14\r\n19 5\r\n93 24\r\n29 8\r\n3 1\r\n77 20\r\n62 16\r\n9 3\r\n44 11\r\n", "output": "20\r\n"}, {"input": "18 70\r\n51 13\r\n55 14\r\n12 3\r\n43 11\r\n42 11\r\n95 24\r\n96 24\r\n29 8\r\n65 17\r\n71 18\r\n18 5\r\n62 16\r\n31 8\r\n100 25\r\n4 1\r\n77 20\r\n56 14\r\n24 6\r\n93 24\r\n97 25\r\n79 20\r\n40 10\r\n49 13\r\n86 22\r\n21 6\r\n46 12\r\n6 2\r\n14 4\r\n23 6\r\n20 5\r\n52 13\r\n88 22\r\n39 10\r\n70 18\r\n94 24\r\n13 4\r\n37 10\r\n41 11\r\n91 23\r\n85 22\r\n83 21\r\n89 23\r\n33 9\r\n64 16\r\n67 17\r\n57 15\r\n47 12\r\n36 9\r\n72 18\r\n81 21\r\n76 19\r\n35 9\r\n80 20\r\n34 9\r\n5 2\r\n22 6\r\n84 21\r\n63 16\r\n74 19\r\n90 23\r\n68 17\r\n98 25\r\n87 22\r\n2 1\r\n92 23\r\n50 13\r\n38 10\r\n28 7\r\n8 2\r\n60 15\r\n", "output": "5\r\n"}, {"input": "89 0\r\n", "output": "-1\r\n"}, {"input": "30 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "63 2\r\n48 6\r\n17 3\r\n", "output": "8\r\n"}, {"input": "96 3\r\n45 6\r\n25 4\r\n35 5\r\n", "output": "12\r\n"}, {"input": "37 4\r\n2 1\r\n29 4\r\n27 4\r\n47 6\r\n", "output": "5\r\n"}, {"input": "64 40\r\n40 5\r\n92 12\r\n23 3\r\n75 10\r\n71 9\r\n2 1\r\n54 7\r\n18 3\r\n9 2\r\n74 10\r\n87 11\r\n11 2\r\n90 12\r\n30 4\r\n48 6\r\n12 2\r\n91 12\r\n60 8\r\n35 5\r\n13 2\r\n53 7\r\n46 6\r\n38 5\r\n59 8\r\n97 13\r\n32 4\r\n6 1\r\n36 5\r\n43 6\r\n83 11\r\n81 11\r\n99 13\r\n69 9\r\n10 2\r\n21 3\r\n78 10\r\n31 4\r\n27 4\r\n57 8\r\n1 1\r\n", "output": "8\r\n"}, {"input": "17 70\r\n63 8\r\n26 4\r\n68 9\r\n30 4\r\n61 8\r\n84 11\r\n39 5\r\n53 7\r\n4 1\r\n81 11\r\n50 7\r\n91 12\r\n59 8\r\n90 12\r\n20 3\r\n21 3\r\n83 11\r\n94 12\r\n37 5\r\n8 1\r\n49 7\r\n34 5\r\n19 3\r\n44 6\r\n74 10\r\n2 1\r\n73 10\r\n88 11\r\n43 6\r\n36 5\r\n57 8\r\n64 8\r\n76 10\r\n40 5\r\n71 9\r\n95 12\r\n15 2\r\n41 6\r\n89 12\r\n42 6\r\n96 12\r\n1 1\r\n52 7\r\n38 5\r\n45 6\r\n78 10\r\n82 11\r\n16 2\r\n48 6\r\n51 7\r\n56 7\r\n28 4\r\n87 11\r\n93 12\r\n46 6\r\n29 4\r\n97 13\r\n54 7\r\n35 5\r\n3 1\r\n79 10\r\n99 13\r\n13 2\r\n55 7\r\n100 13\r\n11 2\r\n75 10\r\n24 3\r\n33 5\r\n22 3\r\n", "output": "3\r\n"}, {"input": "9 0\r\n", "output": "-1\r\n"}, {"input": "50 1\r\n31 2\r\n", "output": "-1\r\n"}, {"input": "79 2\r\n11 1\r\n22 2\r\n", "output": "-1\r\n"}, {"input": "16 3\r\n100 7\r\n94 6\r\n3 1\r\n", "output": "1\r\n"}, {"input": "58 4\r\n73 5\r\n52 4\r\n69 5\r\n3 1\r\n", "output": "4\r\n"}, {"input": "25 40\r\n70 5\r\n28 2\r\n60 4\r\n54 4\r\n33 3\r\n21 2\r\n51 4\r\n20 2\r\n44 3\r\n79 5\r\n65 5\r\n1 1\r\n52 4\r\n23 2\r\n38 3\r\n92 6\r\n63 4\r\n3 1\r\n91 6\r\n5 1\r\n64 4\r\n34 3\r\n25 2\r\n97 7\r\n89 6\r\n61 4\r\n71 5\r\n88 6\r\n29 2\r\n56 4\r\n45 3\r\n6 1\r\n53 4\r\n57 4\r\n90 6\r\n76 5\r\n8 1\r\n46 3\r\n73 5\r\n87 6\r\n", "output": "2\r\n"}, {"input": "78 70\r\n89 6\r\n52 4\r\n87 6\r\n99 7\r\n3 1\r\n25 2\r\n46 3\r\n78 5\r\n35 3\r\n68 5\r\n85 6\r\n23 2\r\n60 4\r\n88 6\r\n17 2\r\n8 1\r\n15 1\r\n67 5\r\n95 6\r\n59 4\r\n94 6\r\n31 2\r\n4 1\r\n16 1\r\n10 1\r\n97 7\r\n42 3\r\n2 1\r\n24 2\r\n34 3\r\n37 3\r\n70 5\r\n18 2\r\n41 3\r\n48 3\r\n58 4\r\n20 2\r\n38 3\r\n72 5\r\n50 4\r\n49 4\r\n40 3\r\n61 4\r\n6 1\r\n45 3\r\n28 2\r\n13 1\r\n27 2\r\n96 6\r\n56 4\r\n91 6\r\n77 5\r\n12 1\r\n11 1\r\n53 4\r\n76 5\r\n74 5\r\n82 6\r\n55 4\r\n80 5\r\n14 1\r\n44 3\r\n7 1\r\n83 6\r\n79 5\r\n92 6\r\n66 5\r\n36 3\r\n73 5\r\n100 7\r\n", "output": "5\r\n"}, {"input": "95 0\r\n", "output": "-1\r\n"}, {"input": "33 1\r\n30 1\r\n", "output": "-1\r\n"}, {"input": "62 2\r\n14 1\r\n15 1\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n6 1\r\n25 1\r\n38 2\r\n", "output": "1\r\n"}, {"input": "44 4\r\n72 3\r\n80 3\r\n15 1\r\n36 2\r\n", "output": "2\r\n"}, {"input": "34 40\r\n25 1\r\n28 1\r\n78 3\r\n5 1\r\n13 1\r\n75 3\r\n15 1\r\n67 3\r\n57 2\r\n23 1\r\n26 1\r\n61 2\r\n22 1\r\n48 2\r\n85 3\r\n24 1\r\n82 3\r\n83 3\r\n53 2\r\n38 2\r\n19 1\r\n33 2\r\n69 3\r\n17 1\r\n79 3\r\n54 2\r\n77 3\r\n97 4\r\n20 1\r\n35 2\r\n14 1\r\n18 1\r\n71 3\r\n21 1\r\n36 2\r\n56 2\r\n44 2\r\n63 2\r\n72 3\r\n32 1\r\n", "output": "2\r\n"}, {"input": "83 70\r\n79 3\r\n49 2\r\n2 1\r\n44 2\r\n38 2\r\n77 3\r\n86 3\r\n31 1\r\n83 3\r\n82 3\r\n35 2\r\n7 1\r\n78 3\r\n23 1\r\n39 2\r\n58 2\r\n1 1\r\n87 3\r\n72 3\r\n20 1\r\n48 2\r\n14 1\r\n13 1\r\n6 1\r\n70 3\r\n55 2\r\n52 2\r\n25 1\r\n11 1\r\n61 2\r\n76 3\r\n95 3\r\n32 1\r\n66 3\r\n29 1\r\n9 1\r\n5 1\r\n3 1\r\n88 3\r\n59 2\r\n96 3\r\n10 1\r\n63 2\r\n40 2\r\n42 2\r\n34 2\r\n43 2\r\n19 1\r\n89 3\r\n94 3\r\n24 1\r\n98 4\r\n12 1\r\n30 1\r\n69 3\r\n17 1\r\n50 2\r\n8 1\r\n93 3\r\n16 1\r\n97 4\r\n54 2\r\n71 3\r\n18 1\r\n33 2\r\n80 3\r\n15 1\r\n99 4\r\n75 3\r\n4 1\r\n", "output": "3\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "36 1\r\n96 1\r\n", "output": "1\r\n"}, {"input": "73 2\r\n34 1\r\n4 1\r\n", "output": "-1\r\n"}, {"input": "6 3\r\n37 1\r\n22 1\r\n70 1\r\n", "output": "1\r\n"}, {"input": "47 4\r\n66 1\r\n57 1\r\n85 1\r\n47 1\r\n", "output": "1\r\n"}, {"input": "9 40\r\n73 1\r\n21 1\r\n37 1\r\n87 1\r\n33 1\r\n69 1\r\n49 1\r\n19 1\r\n35 1\r\n93 1\r\n71 1\r\n43 1\r\n79 1\r\n85 1\r\n29 1\r\n72 1\r\n76 1\r\n47 1\r\n17 1\r\n67 1\r\n95 1\r\n41 1\r\n54 1\r\n88 1\r\n42 1\r\n80 1\r\n98 1\r\n96 1\r\n10 1\r\n24 1\r\n78 1\r\n18 1\r\n3 1\r\n91 1\r\n2 1\r\n15 1\r\n5 1\r\n60 1\r\n36 1\r\n46 1\r\n", "output": "1\r\n"}, {"input": "63 70\r\n82 1\r\n53 1\r\n57 1\r\n46 1\r\n97 1\r\n19 1\r\n36 1\r\n90 1\r\n23 1\r\n88 1\r\n68 1\r\n45 1\r\n2 1\r\n70 1\r\n86 1\r\n8 1\r\n83 1\r\n40 1\r\n99 1\r\n42 1\r\n32 1\r\n52 1\r\n81 1\r\n50 1\r\n77 1\r\n37 1\r\n54 1\r\n75 1\r\n4 1\r\n49 1\r\n73 1\r\n22 1\r\n21 1\r\n98 1\r\n18 1\r\n51 1\r\n14 1\r\n76 1\r\n92 1\r\n80 1\r\n78 1\r\n33 1\r\n79 1\r\n89 1\r\n67 1\r\n9 1\r\n44 1\r\n60 1\r\n64 1\r\n55 1\r\n29 1\r\n100 1\r\n16 1\r\n87 1\r\n10 1\r\n12 1\r\n25 1\r\n85 1\r\n30 1\r\n63 1\r\n39 1\r\n38 1\r\n31 1\r\n5 1\r\n26 1\r\n91 1\r\n43 1\r\n72 1\r\n48 1\r\n94 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}]
| 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
break
if mark:
ans.append(i)
for_print = (n + ans[0] - 1) // ans[0]
mark = 1
for i in range(1, len(ans)):
if ((n + ans[i] - 1) // ans[i] != for_print):
mark = 0
break
if mark:
print(for_print)
else:
print(-1)
| 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 on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
|
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 ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
|
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-th flat.
|
[{"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\n"}, {"input": "16 6\r\n3 1\r\n16 4\r\n10 3\r\n9 3\r\n19 5\r\n8 2\r\n", "output": "4\r\n"}, {"input": "1 0\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1 1\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n3 3\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 1\r\n3 3\r\n", "output": "3\r\n"}, {"input": "3 3\r\n1 1\r\n3 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 3\r\n3 2\r\n1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "3 1\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n1 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "1 3\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "81 0\r\n", "output": "-1\r\n"}, {"input": "22 1\r\n73 73\r\n", "output": "22\r\n"}, {"input": "63 2\r\n10 10\r\n64 64\r\n", "output": "63\r\n"}, {"input": "88 3\r\n37 37\r\n15 15\r\n12 12\r\n", "output": "88\r\n"}, {"input": "29 4\r\n66 66\r\n47 47\r\n62 62\r\n2 2\r\n", "output": "29\r\n"}, {"input": "9 40\r\n72 72\r\n47 47\r\n63 63\r\n66 66\r\n21 21\r\n94 94\r\n28 28\r\n45 45\r\n93 93\r\n25 25\r\n100 100\r\n43 43\r\n49 49\r\n9 9\r\n74 74\r\n26 26\r\n42 42\r\n50 50\r\n2 2\r\n92 92\r\n76 76\r\n3 3\r\n78 78\r\n44 44\r\n69 69\r\n36 36\r\n65 65\r\n81 81\r\n13 13\r\n46 46\r\n24 24\r\n96 96\r\n73 73\r\n82 82\r\n68 68\r\n64 64\r\n41 41\r\n31 31\r\n29 29\r\n10 10\r\n", "output": "9\r\n"}, {"input": "50 70\r\n3 3\r\n80 80\r\n23 23\r\n11 11\r\n87 87\r\n7 7\r\n63 63\r\n61 61\r\n67 67\r\n53 53\r\n9 9\r\n43 43\r\n55 55\r\n27 27\r\n5 5\r\n1 1\r\n99 99\r\n65 65\r\n37 37\r\n60 60\r\n32 32\r\n38 38\r\n81 81\r\n2 2\r\n34 34\r\n17 17\r\n82 82\r\n26 26\r\n71 71\r\n4 4\r\n16 16\r\n19 19\r\n39 39\r\n51 51\r\n6 6\r\n49 49\r\n64 64\r\n83 83\r\n10 10\r\n56 56\r\n30 30\r\n76 76\r\n90 90\r\n42 42\r\n47 47\r\n91 91\r\n21 21\r\n52 52\r\n40 40\r\n77 77\r\n35 35\r\n88 88\r\n75 75\r\n95 95\r\n28 28\r\n15 15\r\n69 69\r\n22 22\r\n48 48\r\n66 66\r\n31 31\r\n98 98\r\n73 73\r\n25 25\r\n97 97\r\n18 18\r\n13 13\r\n54 54\r\n72 72\r\n29 29\r\n", "output": "50\r\n"}, {"input": "6 0\r\n", "output": "-1\r\n"}, {"input": "32 1\r\n9 5\r\n", "output": "16\r\n"}, {"input": "73 2\r\n17 9\r\n21 11\r\n", "output": "37\r\n"}, {"input": "6 3\r\n48 24\r\n51 26\r\n62 31\r\n", "output": "3\r\n"}, {"input": "43 4\r\n82 41\r\n52 26\r\n88 44\r\n41 21\r\n", "output": "22\r\n"}, {"input": "28 40\r\n85 43\r\n19 10\r\n71 36\r\n39 20\r\n57 29\r\n6 3\r\n15 8\r\n11 6\r\n99 50\r\n77 39\r\n79 40\r\n31 16\r\n35 18\r\n24 12\r\n54 27\r\n93 47\r\n90 45\r\n72 36\r\n63 32\r\n22 11\r\n83 42\r\n5 3\r\n12 6\r\n56 28\r\n94 47\r\n25 13\r\n41 21\r\n29 15\r\n36 18\r\n23 12\r\n1 1\r\n84 42\r\n55 28\r\n58 29\r\n9 5\r\n68 34\r\n86 43\r\n3 2\r\n48 24\r\n98 49\r\n", "output": "14\r\n"}, {"input": "81 70\r\n55 28\r\n85 43\r\n58 29\r\n20 10\r\n4 2\r\n47 24\r\n42 21\r\n28 14\r\n26 13\r\n38 19\r\n9 5\r\n83 42\r\n7 4\r\n72 36\r\n18 9\r\n61 31\r\n41 21\r\n64 32\r\n90 45\r\n46 23\r\n67 34\r\n2 1\r\n6 3\r\n27 14\r\n87 44\r\n39 20\r\n11 6\r\n21 11\r\n35 18\r\n48 24\r\n44 22\r\n3 2\r\n71 36\r\n62 31\r\n34 17\r\n16 8\r\n99 50\r\n57 29\r\n13 7\r\n79 40\r\n100 50\r\n53 27\r\n89 45\r\n36 18\r\n43 22\r\n92 46\r\n98 49\r\n75 38\r\n40 20\r\n97 49\r\n37 19\r\n68 34\r\n30 15\r\n96 48\r\n17 9\r\n12 6\r\n45 23\r\n65 33\r\n76 38\r\n84 42\r\n23 12\r\n91 46\r\n52 26\r\n8 4\r\n32 16\r\n77 39\r\n88 44\r\n86 43\r\n70 35\r\n51 26\r\n", "output": "41\r\n"}, {"input": "34 0\r\n", "output": "-1\r\n"}, {"input": "63 1\r\n94 24\r\n", "output": "16\r\n"}, {"input": "4 2\r\n38 10\r\n48 12\r\n", "output": "1\r\n"}, {"input": "37 3\r\n66 17\r\n89 23\r\n60 15\r\n", "output": "10\r\n"}, {"input": "71 4\r\n15 4\r\n13 4\r\n4 1\r\n70 18\r\n", "output": "18\r\n"}, {"input": "77 40\r\n49 13\r\n66 17\r\n73 19\r\n15 4\r\n36 9\r\n1 1\r\n41 11\r\n91 23\r\n51 13\r\n46 12\r\n39 10\r\n42 11\r\n56 14\r\n61 16\r\n70 18\r\n92 23\r\n65 17\r\n54 14\r\n97 25\r\n8 2\r\n87 22\r\n33 9\r\n28 7\r\n38 10\r\n50 13\r\n26 7\r\n7 2\r\n31 8\r\n84 21\r\n47 12\r\n27 7\r\n53 14\r\n19 5\r\n93 24\r\n29 8\r\n3 1\r\n77 20\r\n62 16\r\n9 3\r\n44 11\r\n", "output": "20\r\n"}, {"input": "18 70\r\n51 13\r\n55 14\r\n12 3\r\n43 11\r\n42 11\r\n95 24\r\n96 24\r\n29 8\r\n65 17\r\n71 18\r\n18 5\r\n62 16\r\n31 8\r\n100 25\r\n4 1\r\n77 20\r\n56 14\r\n24 6\r\n93 24\r\n97 25\r\n79 20\r\n40 10\r\n49 13\r\n86 22\r\n21 6\r\n46 12\r\n6 2\r\n14 4\r\n23 6\r\n20 5\r\n52 13\r\n88 22\r\n39 10\r\n70 18\r\n94 24\r\n13 4\r\n37 10\r\n41 11\r\n91 23\r\n85 22\r\n83 21\r\n89 23\r\n33 9\r\n64 16\r\n67 17\r\n57 15\r\n47 12\r\n36 9\r\n72 18\r\n81 21\r\n76 19\r\n35 9\r\n80 20\r\n34 9\r\n5 2\r\n22 6\r\n84 21\r\n63 16\r\n74 19\r\n90 23\r\n68 17\r\n98 25\r\n87 22\r\n2 1\r\n92 23\r\n50 13\r\n38 10\r\n28 7\r\n8 2\r\n60 15\r\n", "output": "5\r\n"}, {"input": "89 0\r\n", "output": "-1\r\n"}, {"input": "30 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "63 2\r\n48 6\r\n17 3\r\n", "output": "8\r\n"}, {"input": "96 3\r\n45 6\r\n25 4\r\n35 5\r\n", "output": "12\r\n"}, {"input": "37 4\r\n2 1\r\n29 4\r\n27 4\r\n47 6\r\n", "output": "5\r\n"}, {"input": "64 40\r\n40 5\r\n92 12\r\n23 3\r\n75 10\r\n71 9\r\n2 1\r\n54 7\r\n18 3\r\n9 2\r\n74 10\r\n87 11\r\n11 2\r\n90 12\r\n30 4\r\n48 6\r\n12 2\r\n91 12\r\n60 8\r\n35 5\r\n13 2\r\n53 7\r\n46 6\r\n38 5\r\n59 8\r\n97 13\r\n32 4\r\n6 1\r\n36 5\r\n43 6\r\n83 11\r\n81 11\r\n99 13\r\n69 9\r\n10 2\r\n21 3\r\n78 10\r\n31 4\r\n27 4\r\n57 8\r\n1 1\r\n", "output": "8\r\n"}, {"input": "17 70\r\n63 8\r\n26 4\r\n68 9\r\n30 4\r\n61 8\r\n84 11\r\n39 5\r\n53 7\r\n4 1\r\n81 11\r\n50 7\r\n91 12\r\n59 8\r\n90 12\r\n20 3\r\n21 3\r\n83 11\r\n94 12\r\n37 5\r\n8 1\r\n49 7\r\n34 5\r\n19 3\r\n44 6\r\n74 10\r\n2 1\r\n73 10\r\n88 11\r\n43 6\r\n36 5\r\n57 8\r\n64 8\r\n76 10\r\n40 5\r\n71 9\r\n95 12\r\n15 2\r\n41 6\r\n89 12\r\n42 6\r\n96 12\r\n1 1\r\n52 7\r\n38 5\r\n45 6\r\n78 10\r\n82 11\r\n16 2\r\n48 6\r\n51 7\r\n56 7\r\n28 4\r\n87 11\r\n93 12\r\n46 6\r\n29 4\r\n97 13\r\n54 7\r\n35 5\r\n3 1\r\n79 10\r\n99 13\r\n13 2\r\n55 7\r\n100 13\r\n11 2\r\n75 10\r\n24 3\r\n33 5\r\n22 3\r\n", "output": "3\r\n"}, {"input": "9 0\r\n", "output": "-1\r\n"}, {"input": "50 1\r\n31 2\r\n", "output": "-1\r\n"}, {"input": "79 2\r\n11 1\r\n22 2\r\n", "output": "-1\r\n"}, {"input": "16 3\r\n100 7\r\n94 6\r\n3 1\r\n", "output": "1\r\n"}, {"input": "58 4\r\n73 5\r\n52 4\r\n69 5\r\n3 1\r\n", "output": "4\r\n"}, {"input": "25 40\r\n70 5\r\n28 2\r\n60 4\r\n54 4\r\n33 3\r\n21 2\r\n51 4\r\n20 2\r\n44 3\r\n79 5\r\n65 5\r\n1 1\r\n52 4\r\n23 2\r\n38 3\r\n92 6\r\n63 4\r\n3 1\r\n91 6\r\n5 1\r\n64 4\r\n34 3\r\n25 2\r\n97 7\r\n89 6\r\n61 4\r\n71 5\r\n88 6\r\n29 2\r\n56 4\r\n45 3\r\n6 1\r\n53 4\r\n57 4\r\n90 6\r\n76 5\r\n8 1\r\n46 3\r\n73 5\r\n87 6\r\n", "output": "2\r\n"}, {"input": "78 70\r\n89 6\r\n52 4\r\n87 6\r\n99 7\r\n3 1\r\n25 2\r\n46 3\r\n78 5\r\n35 3\r\n68 5\r\n85 6\r\n23 2\r\n60 4\r\n88 6\r\n17 2\r\n8 1\r\n15 1\r\n67 5\r\n95 6\r\n59 4\r\n94 6\r\n31 2\r\n4 1\r\n16 1\r\n10 1\r\n97 7\r\n42 3\r\n2 1\r\n24 2\r\n34 3\r\n37 3\r\n70 5\r\n18 2\r\n41 3\r\n48 3\r\n58 4\r\n20 2\r\n38 3\r\n72 5\r\n50 4\r\n49 4\r\n40 3\r\n61 4\r\n6 1\r\n45 3\r\n28 2\r\n13 1\r\n27 2\r\n96 6\r\n56 4\r\n91 6\r\n77 5\r\n12 1\r\n11 1\r\n53 4\r\n76 5\r\n74 5\r\n82 6\r\n55 4\r\n80 5\r\n14 1\r\n44 3\r\n7 1\r\n83 6\r\n79 5\r\n92 6\r\n66 5\r\n36 3\r\n73 5\r\n100 7\r\n", "output": "5\r\n"}, {"input": "95 0\r\n", "output": "-1\r\n"}, {"input": "33 1\r\n30 1\r\n", "output": "-1\r\n"}, {"input": "62 2\r\n14 1\r\n15 1\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n6 1\r\n25 1\r\n38 2\r\n", "output": "1\r\n"}, {"input": "44 4\r\n72 3\r\n80 3\r\n15 1\r\n36 2\r\n", "output": "2\r\n"}, {"input": "34 40\r\n25 1\r\n28 1\r\n78 3\r\n5 1\r\n13 1\r\n75 3\r\n15 1\r\n67 3\r\n57 2\r\n23 1\r\n26 1\r\n61 2\r\n22 1\r\n48 2\r\n85 3\r\n24 1\r\n82 3\r\n83 3\r\n53 2\r\n38 2\r\n19 1\r\n33 2\r\n69 3\r\n17 1\r\n79 3\r\n54 2\r\n77 3\r\n97 4\r\n20 1\r\n35 2\r\n14 1\r\n18 1\r\n71 3\r\n21 1\r\n36 2\r\n56 2\r\n44 2\r\n63 2\r\n72 3\r\n32 1\r\n", "output": "2\r\n"}, {"input": "83 70\r\n79 3\r\n49 2\r\n2 1\r\n44 2\r\n38 2\r\n77 3\r\n86 3\r\n31 1\r\n83 3\r\n82 3\r\n35 2\r\n7 1\r\n78 3\r\n23 1\r\n39 2\r\n58 2\r\n1 1\r\n87 3\r\n72 3\r\n20 1\r\n48 2\r\n14 1\r\n13 1\r\n6 1\r\n70 3\r\n55 2\r\n52 2\r\n25 1\r\n11 1\r\n61 2\r\n76 3\r\n95 3\r\n32 1\r\n66 3\r\n29 1\r\n9 1\r\n5 1\r\n3 1\r\n88 3\r\n59 2\r\n96 3\r\n10 1\r\n63 2\r\n40 2\r\n42 2\r\n34 2\r\n43 2\r\n19 1\r\n89 3\r\n94 3\r\n24 1\r\n98 4\r\n12 1\r\n30 1\r\n69 3\r\n17 1\r\n50 2\r\n8 1\r\n93 3\r\n16 1\r\n97 4\r\n54 2\r\n71 3\r\n18 1\r\n33 2\r\n80 3\r\n15 1\r\n99 4\r\n75 3\r\n4 1\r\n", "output": "3\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "36 1\r\n96 1\r\n", "output": "1\r\n"}, {"input": "73 2\r\n34 1\r\n4 1\r\n", "output": "-1\r\n"}, {"input": "6 3\r\n37 1\r\n22 1\r\n70 1\r\n", "output": "1\r\n"}, {"input": "47 4\r\n66 1\r\n57 1\r\n85 1\r\n47 1\r\n", "output": "1\r\n"}, {"input": "9 40\r\n73 1\r\n21 1\r\n37 1\r\n87 1\r\n33 1\r\n69 1\r\n49 1\r\n19 1\r\n35 1\r\n93 1\r\n71 1\r\n43 1\r\n79 1\r\n85 1\r\n29 1\r\n72 1\r\n76 1\r\n47 1\r\n17 1\r\n67 1\r\n95 1\r\n41 1\r\n54 1\r\n88 1\r\n42 1\r\n80 1\r\n98 1\r\n96 1\r\n10 1\r\n24 1\r\n78 1\r\n18 1\r\n3 1\r\n91 1\r\n2 1\r\n15 1\r\n5 1\r\n60 1\r\n36 1\r\n46 1\r\n", "output": "1\r\n"}, {"input": "63 70\r\n82 1\r\n53 1\r\n57 1\r\n46 1\r\n97 1\r\n19 1\r\n36 1\r\n90 1\r\n23 1\r\n88 1\r\n68 1\r\n45 1\r\n2 1\r\n70 1\r\n86 1\r\n8 1\r\n83 1\r\n40 1\r\n99 1\r\n42 1\r\n32 1\r\n52 1\r\n81 1\r\n50 1\r\n77 1\r\n37 1\r\n54 1\r\n75 1\r\n4 1\r\n49 1\r\n73 1\r\n22 1\r\n21 1\r\n98 1\r\n18 1\r\n51 1\r\n14 1\r\n76 1\r\n92 1\r\n80 1\r\n78 1\r\n33 1\r\n79 1\r\n89 1\r\n67 1\r\n9 1\r\n44 1\r\n60 1\r\n64 1\r\n55 1\r\n29 1\r\n100 1\r\n16 1\r\n87 1\r\n10 1\r\n12 1\r\n25 1\r\n85 1\r\n30 1\r\n63 1\r\n39 1\r\n38 1\r\n31 1\r\n5 1\r\n26 1\r\n91 1\r\n43 1\r\n72 1\r\n48 1\r\n94 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}]
| 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, floor) != floor:
break
if j == n:
ans_floor = floor
cur_floor += 1
else:
ans.add(ans_floor)
if len(ans) > 1:
print(-1)
else:
print(*ans)
| 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):
good = 0
if good:
canbe.add(n // i)
last = n // i + 1
if len(canbe) == 1:
print(last)
else:
print(-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 on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
|
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 ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
|
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-th flat.
|
[{"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\n"}, {"input": "16 6\r\n3 1\r\n16 4\r\n10 3\r\n9 3\r\n19 5\r\n8 2\r\n", "output": "4\r\n"}, {"input": "1 0\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1 1\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n3 3\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 1\r\n3 3\r\n", "output": "3\r\n"}, {"input": "3 3\r\n1 1\r\n3 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 3\r\n3 2\r\n1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "3 1\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n1 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "1 3\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "81 0\r\n", "output": "-1\r\n"}, {"input": "22 1\r\n73 73\r\n", "output": "22\r\n"}, {"input": "63 2\r\n10 10\r\n64 64\r\n", "output": "63\r\n"}, {"input": "88 3\r\n37 37\r\n15 15\r\n12 12\r\n", "output": "88\r\n"}, {"input": "29 4\r\n66 66\r\n47 47\r\n62 62\r\n2 2\r\n", "output": "29\r\n"}, {"input": "9 40\r\n72 72\r\n47 47\r\n63 63\r\n66 66\r\n21 21\r\n94 94\r\n28 28\r\n45 45\r\n93 93\r\n25 25\r\n100 100\r\n43 43\r\n49 49\r\n9 9\r\n74 74\r\n26 26\r\n42 42\r\n50 50\r\n2 2\r\n92 92\r\n76 76\r\n3 3\r\n78 78\r\n44 44\r\n69 69\r\n36 36\r\n65 65\r\n81 81\r\n13 13\r\n46 46\r\n24 24\r\n96 96\r\n73 73\r\n82 82\r\n68 68\r\n64 64\r\n41 41\r\n31 31\r\n29 29\r\n10 10\r\n", "output": "9\r\n"}, {"input": "50 70\r\n3 3\r\n80 80\r\n23 23\r\n11 11\r\n87 87\r\n7 7\r\n63 63\r\n61 61\r\n67 67\r\n53 53\r\n9 9\r\n43 43\r\n55 55\r\n27 27\r\n5 5\r\n1 1\r\n99 99\r\n65 65\r\n37 37\r\n60 60\r\n32 32\r\n38 38\r\n81 81\r\n2 2\r\n34 34\r\n17 17\r\n82 82\r\n26 26\r\n71 71\r\n4 4\r\n16 16\r\n19 19\r\n39 39\r\n51 51\r\n6 6\r\n49 49\r\n64 64\r\n83 83\r\n10 10\r\n56 56\r\n30 30\r\n76 76\r\n90 90\r\n42 42\r\n47 47\r\n91 91\r\n21 21\r\n52 52\r\n40 40\r\n77 77\r\n35 35\r\n88 88\r\n75 75\r\n95 95\r\n28 28\r\n15 15\r\n69 69\r\n22 22\r\n48 48\r\n66 66\r\n31 31\r\n98 98\r\n73 73\r\n25 25\r\n97 97\r\n18 18\r\n13 13\r\n54 54\r\n72 72\r\n29 29\r\n", "output": "50\r\n"}, {"input": "6 0\r\n", "output": "-1\r\n"}, {"input": "32 1\r\n9 5\r\n", "output": "16\r\n"}, {"input": "73 2\r\n17 9\r\n21 11\r\n", "output": "37\r\n"}, {"input": "6 3\r\n48 24\r\n51 26\r\n62 31\r\n", "output": "3\r\n"}, {"input": "43 4\r\n82 41\r\n52 26\r\n88 44\r\n41 21\r\n", "output": "22\r\n"}, {"input": "28 40\r\n85 43\r\n19 10\r\n71 36\r\n39 20\r\n57 29\r\n6 3\r\n15 8\r\n11 6\r\n99 50\r\n77 39\r\n79 40\r\n31 16\r\n35 18\r\n24 12\r\n54 27\r\n93 47\r\n90 45\r\n72 36\r\n63 32\r\n22 11\r\n83 42\r\n5 3\r\n12 6\r\n56 28\r\n94 47\r\n25 13\r\n41 21\r\n29 15\r\n36 18\r\n23 12\r\n1 1\r\n84 42\r\n55 28\r\n58 29\r\n9 5\r\n68 34\r\n86 43\r\n3 2\r\n48 24\r\n98 49\r\n", "output": "14\r\n"}, {"input": "81 70\r\n55 28\r\n85 43\r\n58 29\r\n20 10\r\n4 2\r\n47 24\r\n42 21\r\n28 14\r\n26 13\r\n38 19\r\n9 5\r\n83 42\r\n7 4\r\n72 36\r\n18 9\r\n61 31\r\n41 21\r\n64 32\r\n90 45\r\n46 23\r\n67 34\r\n2 1\r\n6 3\r\n27 14\r\n87 44\r\n39 20\r\n11 6\r\n21 11\r\n35 18\r\n48 24\r\n44 22\r\n3 2\r\n71 36\r\n62 31\r\n34 17\r\n16 8\r\n99 50\r\n57 29\r\n13 7\r\n79 40\r\n100 50\r\n53 27\r\n89 45\r\n36 18\r\n43 22\r\n92 46\r\n98 49\r\n75 38\r\n40 20\r\n97 49\r\n37 19\r\n68 34\r\n30 15\r\n96 48\r\n17 9\r\n12 6\r\n45 23\r\n65 33\r\n76 38\r\n84 42\r\n23 12\r\n91 46\r\n52 26\r\n8 4\r\n32 16\r\n77 39\r\n88 44\r\n86 43\r\n70 35\r\n51 26\r\n", "output": "41\r\n"}, {"input": "34 0\r\n", "output": "-1\r\n"}, {"input": "63 1\r\n94 24\r\n", "output": "16\r\n"}, {"input": "4 2\r\n38 10\r\n48 12\r\n", "output": "1\r\n"}, {"input": "37 3\r\n66 17\r\n89 23\r\n60 15\r\n", "output": "10\r\n"}, {"input": "71 4\r\n15 4\r\n13 4\r\n4 1\r\n70 18\r\n", "output": "18\r\n"}, {"input": "77 40\r\n49 13\r\n66 17\r\n73 19\r\n15 4\r\n36 9\r\n1 1\r\n41 11\r\n91 23\r\n51 13\r\n46 12\r\n39 10\r\n42 11\r\n56 14\r\n61 16\r\n70 18\r\n92 23\r\n65 17\r\n54 14\r\n97 25\r\n8 2\r\n87 22\r\n33 9\r\n28 7\r\n38 10\r\n50 13\r\n26 7\r\n7 2\r\n31 8\r\n84 21\r\n47 12\r\n27 7\r\n53 14\r\n19 5\r\n93 24\r\n29 8\r\n3 1\r\n77 20\r\n62 16\r\n9 3\r\n44 11\r\n", "output": "20\r\n"}, {"input": "18 70\r\n51 13\r\n55 14\r\n12 3\r\n43 11\r\n42 11\r\n95 24\r\n96 24\r\n29 8\r\n65 17\r\n71 18\r\n18 5\r\n62 16\r\n31 8\r\n100 25\r\n4 1\r\n77 20\r\n56 14\r\n24 6\r\n93 24\r\n97 25\r\n79 20\r\n40 10\r\n49 13\r\n86 22\r\n21 6\r\n46 12\r\n6 2\r\n14 4\r\n23 6\r\n20 5\r\n52 13\r\n88 22\r\n39 10\r\n70 18\r\n94 24\r\n13 4\r\n37 10\r\n41 11\r\n91 23\r\n85 22\r\n83 21\r\n89 23\r\n33 9\r\n64 16\r\n67 17\r\n57 15\r\n47 12\r\n36 9\r\n72 18\r\n81 21\r\n76 19\r\n35 9\r\n80 20\r\n34 9\r\n5 2\r\n22 6\r\n84 21\r\n63 16\r\n74 19\r\n90 23\r\n68 17\r\n98 25\r\n87 22\r\n2 1\r\n92 23\r\n50 13\r\n38 10\r\n28 7\r\n8 2\r\n60 15\r\n", "output": "5\r\n"}, {"input": "89 0\r\n", "output": "-1\r\n"}, {"input": "30 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "63 2\r\n48 6\r\n17 3\r\n", "output": "8\r\n"}, {"input": "96 3\r\n45 6\r\n25 4\r\n35 5\r\n", "output": "12\r\n"}, {"input": "37 4\r\n2 1\r\n29 4\r\n27 4\r\n47 6\r\n", "output": "5\r\n"}, {"input": "64 40\r\n40 5\r\n92 12\r\n23 3\r\n75 10\r\n71 9\r\n2 1\r\n54 7\r\n18 3\r\n9 2\r\n74 10\r\n87 11\r\n11 2\r\n90 12\r\n30 4\r\n48 6\r\n12 2\r\n91 12\r\n60 8\r\n35 5\r\n13 2\r\n53 7\r\n46 6\r\n38 5\r\n59 8\r\n97 13\r\n32 4\r\n6 1\r\n36 5\r\n43 6\r\n83 11\r\n81 11\r\n99 13\r\n69 9\r\n10 2\r\n21 3\r\n78 10\r\n31 4\r\n27 4\r\n57 8\r\n1 1\r\n", "output": "8\r\n"}, {"input": "17 70\r\n63 8\r\n26 4\r\n68 9\r\n30 4\r\n61 8\r\n84 11\r\n39 5\r\n53 7\r\n4 1\r\n81 11\r\n50 7\r\n91 12\r\n59 8\r\n90 12\r\n20 3\r\n21 3\r\n83 11\r\n94 12\r\n37 5\r\n8 1\r\n49 7\r\n34 5\r\n19 3\r\n44 6\r\n74 10\r\n2 1\r\n73 10\r\n88 11\r\n43 6\r\n36 5\r\n57 8\r\n64 8\r\n76 10\r\n40 5\r\n71 9\r\n95 12\r\n15 2\r\n41 6\r\n89 12\r\n42 6\r\n96 12\r\n1 1\r\n52 7\r\n38 5\r\n45 6\r\n78 10\r\n82 11\r\n16 2\r\n48 6\r\n51 7\r\n56 7\r\n28 4\r\n87 11\r\n93 12\r\n46 6\r\n29 4\r\n97 13\r\n54 7\r\n35 5\r\n3 1\r\n79 10\r\n99 13\r\n13 2\r\n55 7\r\n100 13\r\n11 2\r\n75 10\r\n24 3\r\n33 5\r\n22 3\r\n", "output": "3\r\n"}, {"input": "9 0\r\n", "output": "-1\r\n"}, {"input": "50 1\r\n31 2\r\n", "output": "-1\r\n"}, {"input": "79 2\r\n11 1\r\n22 2\r\n", "output": "-1\r\n"}, {"input": "16 3\r\n100 7\r\n94 6\r\n3 1\r\n", "output": "1\r\n"}, {"input": "58 4\r\n73 5\r\n52 4\r\n69 5\r\n3 1\r\n", "output": "4\r\n"}, {"input": "25 40\r\n70 5\r\n28 2\r\n60 4\r\n54 4\r\n33 3\r\n21 2\r\n51 4\r\n20 2\r\n44 3\r\n79 5\r\n65 5\r\n1 1\r\n52 4\r\n23 2\r\n38 3\r\n92 6\r\n63 4\r\n3 1\r\n91 6\r\n5 1\r\n64 4\r\n34 3\r\n25 2\r\n97 7\r\n89 6\r\n61 4\r\n71 5\r\n88 6\r\n29 2\r\n56 4\r\n45 3\r\n6 1\r\n53 4\r\n57 4\r\n90 6\r\n76 5\r\n8 1\r\n46 3\r\n73 5\r\n87 6\r\n", "output": "2\r\n"}, {"input": "78 70\r\n89 6\r\n52 4\r\n87 6\r\n99 7\r\n3 1\r\n25 2\r\n46 3\r\n78 5\r\n35 3\r\n68 5\r\n85 6\r\n23 2\r\n60 4\r\n88 6\r\n17 2\r\n8 1\r\n15 1\r\n67 5\r\n95 6\r\n59 4\r\n94 6\r\n31 2\r\n4 1\r\n16 1\r\n10 1\r\n97 7\r\n42 3\r\n2 1\r\n24 2\r\n34 3\r\n37 3\r\n70 5\r\n18 2\r\n41 3\r\n48 3\r\n58 4\r\n20 2\r\n38 3\r\n72 5\r\n50 4\r\n49 4\r\n40 3\r\n61 4\r\n6 1\r\n45 3\r\n28 2\r\n13 1\r\n27 2\r\n96 6\r\n56 4\r\n91 6\r\n77 5\r\n12 1\r\n11 1\r\n53 4\r\n76 5\r\n74 5\r\n82 6\r\n55 4\r\n80 5\r\n14 1\r\n44 3\r\n7 1\r\n83 6\r\n79 5\r\n92 6\r\n66 5\r\n36 3\r\n73 5\r\n100 7\r\n", "output": "5\r\n"}, {"input": "95 0\r\n", "output": "-1\r\n"}, {"input": "33 1\r\n30 1\r\n", "output": "-1\r\n"}, {"input": "62 2\r\n14 1\r\n15 1\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n6 1\r\n25 1\r\n38 2\r\n", "output": "1\r\n"}, {"input": "44 4\r\n72 3\r\n80 3\r\n15 1\r\n36 2\r\n", "output": "2\r\n"}, {"input": "34 40\r\n25 1\r\n28 1\r\n78 3\r\n5 1\r\n13 1\r\n75 3\r\n15 1\r\n67 3\r\n57 2\r\n23 1\r\n26 1\r\n61 2\r\n22 1\r\n48 2\r\n85 3\r\n24 1\r\n82 3\r\n83 3\r\n53 2\r\n38 2\r\n19 1\r\n33 2\r\n69 3\r\n17 1\r\n79 3\r\n54 2\r\n77 3\r\n97 4\r\n20 1\r\n35 2\r\n14 1\r\n18 1\r\n71 3\r\n21 1\r\n36 2\r\n56 2\r\n44 2\r\n63 2\r\n72 3\r\n32 1\r\n", "output": "2\r\n"}, {"input": "83 70\r\n79 3\r\n49 2\r\n2 1\r\n44 2\r\n38 2\r\n77 3\r\n86 3\r\n31 1\r\n83 3\r\n82 3\r\n35 2\r\n7 1\r\n78 3\r\n23 1\r\n39 2\r\n58 2\r\n1 1\r\n87 3\r\n72 3\r\n20 1\r\n48 2\r\n14 1\r\n13 1\r\n6 1\r\n70 3\r\n55 2\r\n52 2\r\n25 1\r\n11 1\r\n61 2\r\n76 3\r\n95 3\r\n32 1\r\n66 3\r\n29 1\r\n9 1\r\n5 1\r\n3 1\r\n88 3\r\n59 2\r\n96 3\r\n10 1\r\n63 2\r\n40 2\r\n42 2\r\n34 2\r\n43 2\r\n19 1\r\n89 3\r\n94 3\r\n24 1\r\n98 4\r\n12 1\r\n30 1\r\n69 3\r\n17 1\r\n50 2\r\n8 1\r\n93 3\r\n16 1\r\n97 4\r\n54 2\r\n71 3\r\n18 1\r\n33 2\r\n80 3\r\n15 1\r\n99 4\r\n75 3\r\n4 1\r\n", "output": "3\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "36 1\r\n96 1\r\n", "output": "1\r\n"}, {"input": "73 2\r\n34 1\r\n4 1\r\n", "output": "-1\r\n"}, {"input": "6 3\r\n37 1\r\n22 1\r\n70 1\r\n", "output": "1\r\n"}, {"input": "47 4\r\n66 1\r\n57 1\r\n85 1\r\n47 1\r\n", "output": "1\r\n"}, {"input": "9 40\r\n73 1\r\n21 1\r\n37 1\r\n87 1\r\n33 1\r\n69 1\r\n49 1\r\n19 1\r\n35 1\r\n93 1\r\n71 1\r\n43 1\r\n79 1\r\n85 1\r\n29 1\r\n72 1\r\n76 1\r\n47 1\r\n17 1\r\n67 1\r\n95 1\r\n41 1\r\n54 1\r\n88 1\r\n42 1\r\n80 1\r\n98 1\r\n96 1\r\n10 1\r\n24 1\r\n78 1\r\n18 1\r\n3 1\r\n91 1\r\n2 1\r\n15 1\r\n5 1\r\n60 1\r\n36 1\r\n46 1\r\n", "output": "1\r\n"}, {"input": "63 70\r\n82 1\r\n53 1\r\n57 1\r\n46 1\r\n97 1\r\n19 1\r\n36 1\r\n90 1\r\n23 1\r\n88 1\r\n68 1\r\n45 1\r\n2 1\r\n70 1\r\n86 1\r\n8 1\r\n83 1\r\n40 1\r\n99 1\r\n42 1\r\n32 1\r\n52 1\r\n81 1\r\n50 1\r\n77 1\r\n37 1\r\n54 1\r\n75 1\r\n4 1\r\n49 1\r\n73 1\r\n22 1\r\n21 1\r\n98 1\r\n18 1\r\n51 1\r\n14 1\r\n76 1\r\n92 1\r\n80 1\r\n78 1\r\n33 1\r\n79 1\r\n89 1\r\n67 1\r\n9 1\r\n44 1\r\n60 1\r\n64 1\r\n55 1\r\n29 1\r\n100 1\r\n16 1\r\n87 1\r\n10 1\r\n12 1\r\n25 1\r\n85 1\r\n30 1\r\n63 1\r\n39 1\r\n38 1\r\n31 1\r\n5 1\r\n26 1\r\n91 1\r\n43 1\r\n72 1\r\n48 1\r\n94 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}]
| 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 ho==-1:
ho = (n-1)//i+1
elif ho!=((n-1)//i+1):
ho = -1
break
print(ho)
| 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 Check(self, floor):
for i in range(self.m):
fl = int(math.ceil(self.k[i] / floor))
if fl != self.f[i]:
return False
return True
def Solve(self):
ans = -1
fl = -1
was = False
for i in range(1, 101):
if self.Check(i):
if not (was):
ans = int(math.ceil(self.n / i))
was = True
else:
t = int(math.ceil(self.n / i))
if (t != ans):
print(-1)
return
print(ans)
Solver = TaskA()
Solver.Solve()
|
Технокубок 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 on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
|
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 ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
|
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-th flat.
|
[{"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\n"}, {"input": "16 6\r\n3 1\r\n16 4\r\n10 3\r\n9 3\r\n19 5\r\n8 2\r\n", "output": "4\r\n"}, {"input": "1 0\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1 1\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n3 3\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 1\r\n3 3\r\n", "output": "3\r\n"}, {"input": "3 3\r\n1 1\r\n3 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 3\r\n3 2\r\n1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "3 1\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n1 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "1 3\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "81 0\r\n", "output": "-1\r\n"}, {"input": "22 1\r\n73 73\r\n", "output": "22\r\n"}, {"input": "63 2\r\n10 10\r\n64 64\r\n", "output": "63\r\n"}, {"input": "88 3\r\n37 37\r\n15 15\r\n12 12\r\n", "output": "88\r\n"}, {"input": "29 4\r\n66 66\r\n47 47\r\n62 62\r\n2 2\r\n", "output": "29\r\n"}, {"input": "9 40\r\n72 72\r\n47 47\r\n63 63\r\n66 66\r\n21 21\r\n94 94\r\n28 28\r\n45 45\r\n93 93\r\n25 25\r\n100 100\r\n43 43\r\n49 49\r\n9 9\r\n74 74\r\n26 26\r\n42 42\r\n50 50\r\n2 2\r\n92 92\r\n76 76\r\n3 3\r\n78 78\r\n44 44\r\n69 69\r\n36 36\r\n65 65\r\n81 81\r\n13 13\r\n46 46\r\n24 24\r\n96 96\r\n73 73\r\n82 82\r\n68 68\r\n64 64\r\n41 41\r\n31 31\r\n29 29\r\n10 10\r\n", "output": "9\r\n"}, {"input": "50 70\r\n3 3\r\n80 80\r\n23 23\r\n11 11\r\n87 87\r\n7 7\r\n63 63\r\n61 61\r\n67 67\r\n53 53\r\n9 9\r\n43 43\r\n55 55\r\n27 27\r\n5 5\r\n1 1\r\n99 99\r\n65 65\r\n37 37\r\n60 60\r\n32 32\r\n38 38\r\n81 81\r\n2 2\r\n34 34\r\n17 17\r\n82 82\r\n26 26\r\n71 71\r\n4 4\r\n16 16\r\n19 19\r\n39 39\r\n51 51\r\n6 6\r\n49 49\r\n64 64\r\n83 83\r\n10 10\r\n56 56\r\n30 30\r\n76 76\r\n90 90\r\n42 42\r\n47 47\r\n91 91\r\n21 21\r\n52 52\r\n40 40\r\n77 77\r\n35 35\r\n88 88\r\n75 75\r\n95 95\r\n28 28\r\n15 15\r\n69 69\r\n22 22\r\n48 48\r\n66 66\r\n31 31\r\n98 98\r\n73 73\r\n25 25\r\n97 97\r\n18 18\r\n13 13\r\n54 54\r\n72 72\r\n29 29\r\n", "output": "50\r\n"}, {"input": "6 0\r\n", "output": "-1\r\n"}, {"input": "32 1\r\n9 5\r\n", "output": "16\r\n"}, {"input": "73 2\r\n17 9\r\n21 11\r\n", "output": "37\r\n"}, {"input": "6 3\r\n48 24\r\n51 26\r\n62 31\r\n", "output": "3\r\n"}, {"input": "43 4\r\n82 41\r\n52 26\r\n88 44\r\n41 21\r\n", "output": "22\r\n"}, {"input": "28 40\r\n85 43\r\n19 10\r\n71 36\r\n39 20\r\n57 29\r\n6 3\r\n15 8\r\n11 6\r\n99 50\r\n77 39\r\n79 40\r\n31 16\r\n35 18\r\n24 12\r\n54 27\r\n93 47\r\n90 45\r\n72 36\r\n63 32\r\n22 11\r\n83 42\r\n5 3\r\n12 6\r\n56 28\r\n94 47\r\n25 13\r\n41 21\r\n29 15\r\n36 18\r\n23 12\r\n1 1\r\n84 42\r\n55 28\r\n58 29\r\n9 5\r\n68 34\r\n86 43\r\n3 2\r\n48 24\r\n98 49\r\n", "output": "14\r\n"}, {"input": "81 70\r\n55 28\r\n85 43\r\n58 29\r\n20 10\r\n4 2\r\n47 24\r\n42 21\r\n28 14\r\n26 13\r\n38 19\r\n9 5\r\n83 42\r\n7 4\r\n72 36\r\n18 9\r\n61 31\r\n41 21\r\n64 32\r\n90 45\r\n46 23\r\n67 34\r\n2 1\r\n6 3\r\n27 14\r\n87 44\r\n39 20\r\n11 6\r\n21 11\r\n35 18\r\n48 24\r\n44 22\r\n3 2\r\n71 36\r\n62 31\r\n34 17\r\n16 8\r\n99 50\r\n57 29\r\n13 7\r\n79 40\r\n100 50\r\n53 27\r\n89 45\r\n36 18\r\n43 22\r\n92 46\r\n98 49\r\n75 38\r\n40 20\r\n97 49\r\n37 19\r\n68 34\r\n30 15\r\n96 48\r\n17 9\r\n12 6\r\n45 23\r\n65 33\r\n76 38\r\n84 42\r\n23 12\r\n91 46\r\n52 26\r\n8 4\r\n32 16\r\n77 39\r\n88 44\r\n86 43\r\n70 35\r\n51 26\r\n", "output": "41\r\n"}, {"input": "34 0\r\n", "output": "-1\r\n"}, {"input": "63 1\r\n94 24\r\n", "output": "16\r\n"}, {"input": "4 2\r\n38 10\r\n48 12\r\n", "output": "1\r\n"}, {"input": "37 3\r\n66 17\r\n89 23\r\n60 15\r\n", "output": "10\r\n"}, {"input": "71 4\r\n15 4\r\n13 4\r\n4 1\r\n70 18\r\n", "output": "18\r\n"}, {"input": "77 40\r\n49 13\r\n66 17\r\n73 19\r\n15 4\r\n36 9\r\n1 1\r\n41 11\r\n91 23\r\n51 13\r\n46 12\r\n39 10\r\n42 11\r\n56 14\r\n61 16\r\n70 18\r\n92 23\r\n65 17\r\n54 14\r\n97 25\r\n8 2\r\n87 22\r\n33 9\r\n28 7\r\n38 10\r\n50 13\r\n26 7\r\n7 2\r\n31 8\r\n84 21\r\n47 12\r\n27 7\r\n53 14\r\n19 5\r\n93 24\r\n29 8\r\n3 1\r\n77 20\r\n62 16\r\n9 3\r\n44 11\r\n", "output": "20\r\n"}, {"input": "18 70\r\n51 13\r\n55 14\r\n12 3\r\n43 11\r\n42 11\r\n95 24\r\n96 24\r\n29 8\r\n65 17\r\n71 18\r\n18 5\r\n62 16\r\n31 8\r\n100 25\r\n4 1\r\n77 20\r\n56 14\r\n24 6\r\n93 24\r\n97 25\r\n79 20\r\n40 10\r\n49 13\r\n86 22\r\n21 6\r\n46 12\r\n6 2\r\n14 4\r\n23 6\r\n20 5\r\n52 13\r\n88 22\r\n39 10\r\n70 18\r\n94 24\r\n13 4\r\n37 10\r\n41 11\r\n91 23\r\n85 22\r\n83 21\r\n89 23\r\n33 9\r\n64 16\r\n67 17\r\n57 15\r\n47 12\r\n36 9\r\n72 18\r\n81 21\r\n76 19\r\n35 9\r\n80 20\r\n34 9\r\n5 2\r\n22 6\r\n84 21\r\n63 16\r\n74 19\r\n90 23\r\n68 17\r\n98 25\r\n87 22\r\n2 1\r\n92 23\r\n50 13\r\n38 10\r\n28 7\r\n8 2\r\n60 15\r\n", "output": "5\r\n"}, {"input": "89 0\r\n", "output": "-1\r\n"}, {"input": "30 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "63 2\r\n48 6\r\n17 3\r\n", "output": "8\r\n"}, {"input": "96 3\r\n45 6\r\n25 4\r\n35 5\r\n", "output": "12\r\n"}, {"input": "37 4\r\n2 1\r\n29 4\r\n27 4\r\n47 6\r\n", "output": "5\r\n"}, {"input": "64 40\r\n40 5\r\n92 12\r\n23 3\r\n75 10\r\n71 9\r\n2 1\r\n54 7\r\n18 3\r\n9 2\r\n74 10\r\n87 11\r\n11 2\r\n90 12\r\n30 4\r\n48 6\r\n12 2\r\n91 12\r\n60 8\r\n35 5\r\n13 2\r\n53 7\r\n46 6\r\n38 5\r\n59 8\r\n97 13\r\n32 4\r\n6 1\r\n36 5\r\n43 6\r\n83 11\r\n81 11\r\n99 13\r\n69 9\r\n10 2\r\n21 3\r\n78 10\r\n31 4\r\n27 4\r\n57 8\r\n1 1\r\n", "output": "8\r\n"}, {"input": "17 70\r\n63 8\r\n26 4\r\n68 9\r\n30 4\r\n61 8\r\n84 11\r\n39 5\r\n53 7\r\n4 1\r\n81 11\r\n50 7\r\n91 12\r\n59 8\r\n90 12\r\n20 3\r\n21 3\r\n83 11\r\n94 12\r\n37 5\r\n8 1\r\n49 7\r\n34 5\r\n19 3\r\n44 6\r\n74 10\r\n2 1\r\n73 10\r\n88 11\r\n43 6\r\n36 5\r\n57 8\r\n64 8\r\n76 10\r\n40 5\r\n71 9\r\n95 12\r\n15 2\r\n41 6\r\n89 12\r\n42 6\r\n96 12\r\n1 1\r\n52 7\r\n38 5\r\n45 6\r\n78 10\r\n82 11\r\n16 2\r\n48 6\r\n51 7\r\n56 7\r\n28 4\r\n87 11\r\n93 12\r\n46 6\r\n29 4\r\n97 13\r\n54 7\r\n35 5\r\n3 1\r\n79 10\r\n99 13\r\n13 2\r\n55 7\r\n100 13\r\n11 2\r\n75 10\r\n24 3\r\n33 5\r\n22 3\r\n", "output": "3\r\n"}, {"input": "9 0\r\n", "output": "-1\r\n"}, {"input": "50 1\r\n31 2\r\n", "output": "-1\r\n"}, {"input": "79 2\r\n11 1\r\n22 2\r\n", "output": "-1\r\n"}, {"input": "16 3\r\n100 7\r\n94 6\r\n3 1\r\n", "output": "1\r\n"}, {"input": "58 4\r\n73 5\r\n52 4\r\n69 5\r\n3 1\r\n", "output": "4\r\n"}, {"input": "25 40\r\n70 5\r\n28 2\r\n60 4\r\n54 4\r\n33 3\r\n21 2\r\n51 4\r\n20 2\r\n44 3\r\n79 5\r\n65 5\r\n1 1\r\n52 4\r\n23 2\r\n38 3\r\n92 6\r\n63 4\r\n3 1\r\n91 6\r\n5 1\r\n64 4\r\n34 3\r\n25 2\r\n97 7\r\n89 6\r\n61 4\r\n71 5\r\n88 6\r\n29 2\r\n56 4\r\n45 3\r\n6 1\r\n53 4\r\n57 4\r\n90 6\r\n76 5\r\n8 1\r\n46 3\r\n73 5\r\n87 6\r\n", "output": "2\r\n"}, {"input": "78 70\r\n89 6\r\n52 4\r\n87 6\r\n99 7\r\n3 1\r\n25 2\r\n46 3\r\n78 5\r\n35 3\r\n68 5\r\n85 6\r\n23 2\r\n60 4\r\n88 6\r\n17 2\r\n8 1\r\n15 1\r\n67 5\r\n95 6\r\n59 4\r\n94 6\r\n31 2\r\n4 1\r\n16 1\r\n10 1\r\n97 7\r\n42 3\r\n2 1\r\n24 2\r\n34 3\r\n37 3\r\n70 5\r\n18 2\r\n41 3\r\n48 3\r\n58 4\r\n20 2\r\n38 3\r\n72 5\r\n50 4\r\n49 4\r\n40 3\r\n61 4\r\n6 1\r\n45 3\r\n28 2\r\n13 1\r\n27 2\r\n96 6\r\n56 4\r\n91 6\r\n77 5\r\n12 1\r\n11 1\r\n53 4\r\n76 5\r\n74 5\r\n82 6\r\n55 4\r\n80 5\r\n14 1\r\n44 3\r\n7 1\r\n83 6\r\n79 5\r\n92 6\r\n66 5\r\n36 3\r\n73 5\r\n100 7\r\n", "output": "5\r\n"}, {"input": "95 0\r\n", "output": "-1\r\n"}, {"input": "33 1\r\n30 1\r\n", "output": "-1\r\n"}, {"input": "62 2\r\n14 1\r\n15 1\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n6 1\r\n25 1\r\n38 2\r\n", "output": "1\r\n"}, {"input": "44 4\r\n72 3\r\n80 3\r\n15 1\r\n36 2\r\n", "output": "2\r\n"}, {"input": "34 40\r\n25 1\r\n28 1\r\n78 3\r\n5 1\r\n13 1\r\n75 3\r\n15 1\r\n67 3\r\n57 2\r\n23 1\r\n26 1\r\n61 2\r\n22 1\r\n48 2\r\n85 3\r\n24 1\r\n82 3\r\n83 3\r\n53 2\r\n38 2\r\n19 1\r\n33 2\r\n69 3\r\n17 1\r\n79 3\r\n54 2\r\n77 3\r\n97 4\r\n20 1\r\n35 2\r\n14 1\r\n18 1\r\n71 3\r\n21 1\r\n36 2\r\n56 2\r\n44 2\r\n63 2\r\n72 3\r\n32 1\r\n", "output": "2\r\n"}, {"input": "83 70\r\n79 3\r\n49 2\r\n2 1\r\n44 2\r\n38 2\r\n77 3\r\n86 3\r\n31 1\r\n83 3\r\n82 3\r\n35 2\r\n7 1\r\n78 3\r\n23 1\r\n39 2\r\n58 2\r\n1 1\r\n87 3\r\n72 3\r\n20 1\r\n48 2\r\n14 1\r\n13 1\r\n6 1\r\n70 3\r\n55 2\r\n52 2\r\n25 1\r\n11 1\r\n61 2\r\n76 3\r\n95 3\r\n32 1\r\n66 3\r\n29 1\r\n9 1\r\n5 1\r\n3 1\r\n88 3\r\n59 2\r\n96 3\r\n10 1\r\n63 2\r\n40 2\r\n42 2\r\n34 2\r\n43 2\r\n19 1\r\n89 3\r\n94 3\r\n24 1\r\n98 4\r\n12 1\r\n30 1\r\n69 3\r\n17 1\r\n50 2\r\n8 1\r\n93 3\r\n16 1\r\n97 4\r\n54 2\r\n71 3\r\n18 1\r\n33 2\r\n80 3\r\n15 1\r\n99 4\r\n75 3\r\n4 1\r\n", "output": "3\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "36 1\r\n96 1\r\n", "output": "1\r\n"}, {"input": "73 2\r\n34 1\r\n4 1\r\n", "output": "-1\r\n"}, {"input": "6 3\r\n37 1\r\n22 1\r\n70 1\r\n", "output": "1\r\n"}, {"input": "47 4\r\n66 1\r\n57 1\r\n85 1\r\n47 1\r\n", "output": "1\r\n"}, {"input": "9 40\r\n73 1\r\n21 1\r\n37 1\r\n87 1\r\n33 1\r\n69 1\r\n49 1\r\n19 1\r\n35 1\r\n93 1\r\n71 1\r\n43 1\r\n79 1\r\n85 1\r\n29 1\r\n72 1\r\n76 1\r\n47 1\r\n17 1\r\n67 1\r\n95 1\r\n41 1\r\n54 1\r\n88 1\r\n42 1\r\n80 1\r\n98 1\r\n96 1\r\n10 1\r\n24 1\r\n78 1\r\n18 1\r\n3 1\r\n91 1\r\n2 1\r\n15 1\r\n5 1\r\n60 1\r\n36 1\r\n46 1\r\n", "output": "1\r\n"}, {"input": "63 70\r\n82 1\r\n53 1\r\n57 1\r\n46 1\r\n97 1\r\n19 1\r\n36 1\r\n90 1\r\n23 1\r\n88 1\r\n68 1\r\n45 1\r\n2 1\r\n70 1\r\n86 1\r\n8 1\r\n83 1\r\n40 1\r\n99 1\r\n42 1\r\n32 1\r\n52 1\r\n81 1\r\n50 1\r\n77 1\r\n37 1\r\n54 1\r\n75 1\r\n4 1\r\n49 1\r\n73 1\r\n22 1\r\n21 1\r\n98 1\r\n18 1\r\n51 1\r\n14 1\r\n76 1\r\n92 1\r\n80 1\r\n78 1\r\n33 1\r\n79 1\r\n89 1\r\n67 1\r\n9 1\r\n44 1\r\n60 1\r\n64 1\r\n55 1\r\n29 1\r\n100 1\r\n16 1\r\n87 1\r\n10 1\r\n12 1\r\n25 1\r\n85 1\r\n30 1\r\n63 1\r\n39 1\r\n38 1\r\n31 1\r\n5 1\r\n26 1\r\n91 1\r\n43 1\r\n72 1\r\n48 1\r\n94 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}]
| 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((problems[2][0], problems[1][0])), sorted((problems[0][0], problems[2][0]))]
elif count==4 and row[problems[0][1]-1]==problems[0][0]:
if problems[0][1]!=problems[1][0]:
return [3, sorted((problems[0][0], problems[0][1])), sorted((problems[1][0], problems[1][1]))]
else:
return [3, sorted((problems[0][0], problems[0][1])), sorted((problems[2][0], problems[2][1]))]
else:
return [4]
def merge(l1, l2):
if l1[0]==4 or l2==[4]:
return "Fail"
elif l1[0]==0:
return l2
elif l2[0]==0:
return l1
elif l1[0]==3 and l2[0]==3:
new=[3]
for i in l1[1:]:
if i in l2[1:]:
new.append(i)
if len(new)>1:
return new
else:
return "Fail"
elif (l1[0]==2) != (l2[0]==2):
new=[3]
if l1[0]==2:
newl2=l1
newl3=l2
else:
newl2=l2
newl3=l1
for i in newl3[1:]:
if i[0] in newl2[1:] or i[1] in newl2[1:]:
new.append(i)
if len(new)>1:
return new
else:
return "Fail"
elif l1[0]==2 and l2[0]==2:
new=[2]
for i in l1[1:]:
if i in l2[1:]:
new.append(i)
return new
print("Missed a case!", l1, l2)
current=[0]
broken=False
n, m=[int(i) for i in input().split()]
for j in range(n):
newrow=[int(i) for i in input().split()]
new=parse(newrow)
current=merge(new, current)
if current=="Fail":
print("NO")
broken=True
break
if not broken:
print("YES")
| 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[jj]:
o+=1
if o>2:
t+=1
if t==0:
exit(print("YES"))
else:
print("NO")
|
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 to perform from 0 to n + 1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
|
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 8 9 10\r\n", "output": "YES\r\n"}, {"input": "5 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 8 5 6 7 10 9 4 11 12\r\n1 5 3 4 2 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n", "output": "YES\r\n"}, {"input": "4 10\r\n3 2 8 10 5 6 7 1 9 4\r\n1 2 9 4 5 3 7 8 10 6\r\n7 5 3 4 8 6 1 2 9 10\r\n4 2 3 9 8 6 7 5 1 10\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n9 2 3 4 5 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 10 7 8 1 6\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n9 10 4 2 3 5 7 1 8 6\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n6 4 7 3 5 8 1 9 10 2\r\n1 5 10 6 3 4 9 7 2 8\r\n3 2 1 7 8 6 5 4 10 9\r\n7 9 1 6 8 2 4 5 3 10\r\n3 4 6 9 8 7 1 2 10 5\r\n", "output": "NO\r\n"}, {"input": "20 2\r\n1 2\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "20 3\r\n3 2 1\r\n2 3 1\r\n2 3 1\r\n2 1 3\r\n1 3 2\r\n2 1 3\r\n1 2 3\r\n3 2 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n2 1 3\r\n2 3 1\r\n2 3 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n3 1 2\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 2 3 4 5 6 7 10 9 8\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n6 9 3 4 5 1 8 7 2 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 19 14 15 16 17 18 13 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 20\r\n1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 17 18 19 20\r\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 12 18 7 8 9 10 11 5 13 14 15 16 17 6 19 20\r\n6 2 3 4 5 1 7 8 9 10 11 12 13 20 15 16 17 18 19 14\r\n4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 19 8 9 10 11 12 13 14 15 20 17 18 7 16\r\n1 2 9 4 5 6 7 8 18 10 11 12 13 14 15 16 17 3 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n4 2 3 8 5 6 7 1 9 10\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n3 2 1 4 5 6 7 8 10 9\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 18 14 15 16 17 13 11 20\r\n1 2 11 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 3 20\r\n13 2 3 4 5 6 7 8 9 10 19 12 1 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 16 8 9 10 11 12 13 14 15 7 17 18 19 20\r\n1 2 3 14 5 6 16 8 9 10 11 12 13 4 15 7 17 18 19 20\r\n1 2 3 4 5 6 16 8 18 10 11 12 13 14 15 7 17 9 19 20\r\n1 2 3 4 5 6 16 8 9 15 11 12 13 14 10 7 17 18 19 20\r\n1 2 18 4 5 6 16 8 9 10 11 12 13 14 15 7 17 3 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 18 4 5 6 7 8 9 10 11 12 13 14 15 16 19 3 17 20\r\n8 2 3 9 5 6 7 1 4 10 11 12 13 14 15 16 17 18 19 20\r\n7 2 3 4 5 6 1 8 9 10 11 12 13 14 15 16 17 20 19 18\r\n1 2 3 12 5 6 7 8 9 17 11 4 13 14 15 16 10 18 19 20\r\n1 11 3 4 9 6 7 8 5 10 2 12 13 14 15 16 17 18 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n10 2 3 4 5 9 7 8 6 1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 9 2 4 6 5 8 3 7 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 3 2 19 5 6 7 8 9 17 11 12 13 14 15 16 10 18 4 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 20 6 7 8 9 17 11 12 13 14 15 16 10 18 19 5\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 6 17 4 5 2 7 14 9 10 11 12 13 8 15 16 3 18 19 20\r\n5 6 17 4 1 2 7 8 9 10 11 12 13 14 15 16 3 18 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 18 3 16 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 16 3 18 20 19\r\n1 6 17 8 5 2 7 4 9 10 11 12 13 14 15 16 3 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n10 2 9 4 5 6 7 8 15 1 11 16 13 14 3 12 17 18 19 20\r\n10 2 3 4 5 6 7 1 9 8 11 16 13 14 15 12 17 18 19 20\r\n9 2 3 4 5 6 7 8 10 1 11 16 13 14 15 12 20 18 19 17\r\n10 2 3 4 7 6 5 8 9 1 11 16 18 14 15 12 17 13 19 20\r\n10 2 3 4 5 6 7 8 9 20 11 16 14 13 15 12 17 18 19 1\r\n", "output": "NO\r\n"}, {"input": "1 4\r\n2 3 4 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 1 3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "15 6\r\n2 1 4 3 6 5\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n4 3 1 2\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "4 8\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n", "output": "YES\r\n"}, {"input": "4 6\r\n1 2 3 5 6 4\r\n3 2 1 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n3 1 2\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 1 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "20 8\r\n4 3 2 1 5 6 7 8\r\n1 2 3 4 8 7 6 5\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n8 7 6 5 4 3 2 1\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n", "output": "YES\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 11 12 9\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n3 2 1 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n2 3 1 4 5 6\r\n1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n2 3 1\r\n2 3 1\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "5 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n3 8 1 4 5 6 7 2\r\n1 8 3 6 5 4 7 2\r\n1 8 3 5 4 6 7 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 4 3 1\r\n2 1 5 4 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 3 1 4\r\n1 2 3 4\r\n2 3 1 4\r\n2 1 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 4 3 5\r\n2 1 4 3 5\r\n1 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "3 10\r\n2 1 3 4 5 6 8 7 10 9\r\n1 2 3 4 5 6 8 7 10 9\r\n1 2 3 4 6 5 8 7 10 9\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n3 1 2 4\r\n3 2 4 1\r\n3 1 2 4\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n1 4 2 3 5\r\n1 2 4 5 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 3 4\r\n2 1 5 3 4\r\n", "output": "NO\r\n"}, {"input": "3 6\r\n2 3 1 4 5 6\r\n2 1 4 3 5 6\r\n1 2 3 4 5 6\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "4 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 3 4 5\r\n1 3 4 2 5\r\n1 4 2 3 5\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 2 3\r\n1 2 3\r\n1 2 3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n3 1 2\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "7 4\r\n1 2 3 4\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 2 3\r\n1 3 2\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}]
| 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: print('JUMP ' + str(u))
if v: print('RUN ' + str(v))
| 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[cur] + 1
if t - r > d: ans = ['IMPOSSIBLE']; break
ans += ['JUMP ' + str(t - r)]
l = t;cur += 1
print('\n'.join(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 length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
|
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 sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
|
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 for "X" more meters;
- print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
| 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\nJUMP 3\r\nRUN 4\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "10 1000000000 8905990 20319560\r\n233244997 997992814 242452779 497363176 572234096 126615858 886769539 662035052 989086824 716655858\r\n", "output": "RUN 126615857\r\nJUMP 2\r\nRUN 106629137\r\nJUMP 2\r\nRUN 9207780\r\nJUMP 2\r\nRUN 254910395\r\nJUMP 2\r\nRUN 74870918\r\nJUMP 2\r\nRUN 89800954\r\nJUMP 2\r\nRUN 54620804\r\nJUMP 2\r\nRUN 170113679\r\nJUMP 2\r\nRUN 102317283\r\nJUMP 8905992\r\nRUN 2007185\r\n"}, {"input": "100 1000 1 4\r\n228 420 360 642 442 551 940 343 24 83 928 110 663 548 704 461 942 799 283 746 371 204 435 209 986 489 918 526 496 321 233 643 208 717 806 18 291 431 521 631 3 450 711 602 401 60 680 930 625 891 161 279 510 529 546 338 473 925 446 786 384 952 260 649 865 916 789 71 103 997 484 89 408 129 953 670 568 55 287 511 369 225 950 539 652 567 730 499 687 90 779 848 801 606 82 853 967 776 951 329\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "100 600 1 4\r\n9 536 518 59 229 377 72 203 81 309 304 321 55 439 287 505 3 410 582 351 440 568 584 259 22 415 348 147 404 277 477 323 537 75 548 324 338 198 145 182 271 496 256 329 592 132 291 222 115 587 54 158 154 103 356 15 36 76 402 27 223 551 267 527 51 34 417 573 479 398 425 71 485 20 262 566 467 131 524 352 330 541 146 53 322 436 366 86 88 272 96 456 388 319 149 470 129 162 353 346\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 2 1 5\r\n1\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 3 1 2\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\n"}, {"input": "1 5 1 2\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\nRUN 2\r\n"}, {"input": "100 1000 1 5\r\n204 233 384 776 450 649 473 717 55 90 208 951 499 551 916 18 539 103 420 521 730 779 360 546 746 953 484 82 110 789 161 950 71 806 928 652 510 287 997 967 329 786 643 431 321 663 279 291 799 986 848 680 89 225 918 801 567 369 687 209 602 401 952 930 442 853 606 338 129 631 228 24 3 925 940 711 496 625 548 446 891 283 60 83 529 511 568 704 371 343 670 435 461 865 408 642 260 526 489 942\r\n", "output": "RUN 2\nJUMP 2\nRUN 13\nJUMP 2\nRUN 4\nJUMP 2\nRUN 29\nJUMP 2\nRUN 3\nJUMP 2\nRUN 9\nJUMP 2\nRUN 9\nJUMP 3\nRUN 4\nJUMP 3\nRUN 11\nJUMP 2\nRUN 5\nJUMP 2\nRUN 17\nJUMP 2\nRUN 30\nJUMP 2\nRUN 41\nJUMP 2\nRUN 2\nJUMP 3\nRUN 14\nJUMP 2\nRUN 1\nJUMP 2\nRUN 3\nJUMP 2\nRUN 25\nJUMP 2\nRUN 17\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 28\nJUMP 2\nRUN 6\nJUMP 2\nRUN 7\nJUMP 2\nRUN 3\nJUMP 2\nRUN 15\nJUMP 2\nRUN 7\nJUMP 4\nRUN 11\nJUMP 2\nRUN 15\nJUMP 2\nRUN 5\nJUMP 2\nRUN 10\nJUMP 2\nRUN 9\nJUMP 2\nRUN 2\nJUMP 2\nRUN 5\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 9\nJUMP 2\nRUN 10\nJUMP 2\nRUN 9\nJUMP 2\nRUN 3\nJUMP 2\nRUN 5\nJUMP 2\nRUN 1\nJUMP 2\nRUN 9\nJUMP 3\nRUN 8\nJUMP 2\nRUN 3\nJUMP 2\nRUN 1\nJUMP 2\nRUN 8\nJUMP 2\nRUN 5\nJUMP 4\nRUN 1\nJUMP 2\nRUN 14\nJUMP 3\nRUN 32\nJUMP 2\nRUN 2\nJUMP 2\nRUN 17\nJUMP 2\nRUN 4\nJUMP 2\nRUN 9\nJUMP 3\nRUN 4\nJUMP 2\nRUN 1\nJUMP 2\nRUN 9\nJUMP 2\nRUN 5\nJUMP 2\nRUN 8\nJUMP 2\nRUN 5\nJUMP 2\nRUN 15\nJUMP 2\nRUN 5\nJUMP 2\nRUN 4\nJUMP 2\nRUN 11\nJUMP 2\nRUN 14\nJUMP 2\nRUN 28\nJUMP 2\nRUN 1\nJUMP 2\nRUN 5\nJUMP 2\nRUN 1\nJUMP 2\nRUN 8\nJUMP 4\nRUN 3\nJUMP 2\nRUN 40\nJUMP 2\nRUN 3\nJUMP 2\nRUN 10\nJUMP 2\nRUN 24\nJUMP 2\nRUN 23\nJUMP 4\nRUN 5\nJUMP 2\nRUN 1\nJUMP 4\nRUN 8\nJUMP 4\nRUN 6\nJUMP 5\nRUN 12\nJUMP 2\nRUN 17\nJUMP 2\nRUN 9\nJUMP 2\nRUN 2\n"}, {"input": "1 1000000000 1000000000 2\r\n999999999\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 100 1 1\r\n4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 1000000000 1 1000000000\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\nRUN 999999997\r\n"}, {"input": "3 12000 2000 3000\r\n3000 9002 7001\r\n", "output": "RUN 2999\r\nJUMP 2\r\nRUN 3999\r\nJUMP 2003\r\nRUN 2997\r\n"}, {"input": "4 30000 5000 6000\r\n6000 16000 15000 21001\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 12000 2000 245\r\n3000 9003 7001\r\n", "output": "RUN 2999\r\nJUMP 2\r\nRUN 3999\r\nJUMP 2\r\nRUN 2000\r\nJUMP 2\r\nRUN 2996\r\n"}, {"input": "4 30000 5000 1654\r\n6000 16000 14999 21002\r\n", "output": "RUN 5999\r\nJUMP 2\r\nRUN 8997\r\nJUMP 1003\r\nRUN 5000\r\nJUMP 2\r\nRUN 8997\r\n"}, {"input": "4 10000 500 500\r\n700 600 1099 2000\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 20000 4000 3502\r\n5000 8500 15000\r\n", "output": "RUN 4999\r\nJUMP 3502\r\nRUN 6498\r\nJUMP 2\r\nRUN 4999\r\n"}, {"input": "4 10000 500 500\r\n700 601 1099 2000\r\n", "output": "RUN 600\r\nJUMP 500\r\nRUN 899\r\nJUMP 2\r\nRUN 7999\r\n"}, {"input": "3 20000 4000 3502\r\n5000 8501 15000\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 10 1 2\r\n9\r\n", "output": "RUN 8\r\nJUMP 2\r\n"}, {"input": "1 10 2 9\r\n5\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 4\r\n"}, {"input": "1 9 6 4\r\n4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 10 7 4\r\n5\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 14 8 8\r\n5 9\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 23 12 8\r\n8 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 14 4 2\r\n2 7\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 21 6 2\r\n7 11 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 29 3 4\r\n7 16 19\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 24 2 6\r\n6 12 17\r\n", "output": "RUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "4 31 12 9\r\n7 13 21 28\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "4 10 1 7\r\n2 4 6 8\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "4 36 8 4\r\n4 13 19 27\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 25 10 2\r\n6 12 13 15 22\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 19 7 10\r\n3 7 9 12 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 28 6 8\r\n3 9 15 21 25\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 35 12 4\r\n7 12 17 21 24 28\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 22 5 7\r\n4 6 10 13 15 18\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 55 3 5\r\n10 18 24 34 39 45\r\n", "output": "RUN 9\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 9\r\n"}, {"input": "7 51 6 1\r\n8 17 18 23 27 33 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "7 36 11 4\r\n6 11 17 19 22 24 30\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "7 28 10 2\r\n5 10 14 19 21 23 27\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 46 4 5\r\n3 6 15 21 24 26 36 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 51 2 1\r\n6 14 20 26 29 35 40 48\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 56 2 9\r\n7 11 20 28 34 39 40 48\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 7\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 3\r\nRUN 6\r\nJUMP 2\r\nRUN 7\r\n"}, {"input": "9 57 2 2\r\n5 11 15 21 24 30 36 43 50\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "9 82 14 4\r\n10 18 28 38 46 55 64 74 79\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "9 40 6 3\r\n5 10 14 18 22 27 30 31 36\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 44 6 2\r\n4 8 13 19 23 29 32 33 37 41\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 42 1 3\r\n1 6 10 15 17 22 24 29 33 38\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 82 2 5\r\n9 17 27 37 44 51 57 62 67 72\r\n", "output": "RUN 8\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 9\r\n"}, {"input": "11 69 4 9\r\n7 14 20 26 29 35 40 46 52 58 64\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 5\r\nRUN 4\r\nJUMP 7\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\n"}, {"input": "11 65 1 7\r\n7 11 14 21 24 30 37 44 50 56 59\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 5\r\n"}, {"input": "11 77 10 10\r\n7 14 17 24 29 34 38 47 56 64 69\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 78 3 1\r\n4 11 19 22 30 38 43 51 56 59 67 73\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 89 14 9\r\n6 11 18 24 33 37 45 51 60 69 71 80\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 13 6 7\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "13 91 1 3\r\n5 12 17 22 29 36 43 49 57 64 70 74 84\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "13 87 5 6\r\n7 10 18 24 31 40 41 48 54 63 69 78 81\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "13 46 2 4\r\n1 4 9 13 15 19 21 23 25 30 35 37 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 93 1 1\r\n8 15 19 21 28 36 44 51 56 63 67 74 79 85\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 62 11 4\r\n5 10 15 18 22 26 31 34 39 42 44 47 52 57\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 109 10 1\r\n8 15 25 29 38 48 57 65 70 79 81 89 94 100\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 97 4 4\r\n3 7 13 23 29 35 39 45 49 50 60 68 72 81 87\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 77 4 8\r\n7 14 16 20 26 33 36 43 44 48 52 59 61 66 70\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 56 1 5\r\n5 10 15 20 21 25 29 31 34 37 38 41 43 47 52\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 3\r\nRUN 2\r\nJUMP 2\r\nRUN 2\r\nJUMP 4\r\nRUN 1\r\nJUMP 2\r\nRUN 1\r\nJUMP 3\r\nRUN 1\r\nJUMP 4\r\nRUN 2\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\n"}, {"input": "2 1000000000 1 3\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 1 2\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 1 4\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 2 4\r\n5 8\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 1000000000 2 5\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 5\r\nRUN 999999991\r\n"}]
| 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 range(3):
fun(input())
ma=max(se)
if(se.count(ma)!=1):
print('Draw')
else:
if(se[0]==ma):
print('Kuro')
elif(se[1]==ma):
print('Shiro')
else:
print('Katie')
| 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
else: y += 1
if z == m: z -= 1
else: z += 1
else:
x = min(m, x+n)
y = min(m, y+n)
z = min(m, z+n)
mx = max(x, y, z)
if x == mx and y < mx and z < mx:
print ('Kuro')
elif x < mx and y == mx and z < mx:
print ('Shiro')
elif x < mx and y < mx and z == mx:
print ('Katie')
else:
print ('Draw')
|
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. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $$$7$$$ because its subribbon a appears $$$7$$$ times, and the ribbon abcdabc has the beauty of $$$2$$$ because its subribbon abc appears twice.
The rules are simple. The game will have $$$n$$$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $$$n$$$ turns wins the treasure.
Could you find out who is going to be the winner if they all play optimally?
|
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 that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
|
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 into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is $$$9$$$ and the number of turn is $$$15$$$, everyone can change their ribbons in some way to reach the maximal beauty of $$$9$$$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.
|
[{"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"}, {"input": "1\r\naaaaaaaaaa\r\nAAAAAAcAAA\r\nbbbbbbzzbb\r\n", "output": "Shiro\r\n"}, {"input": "60\r\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\r\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\r\nXaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ\r\n", "output": "Draw\r\n"}, {"input": "9174\r\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzcccbccczzbbcbbzbzzzcbczbzbzzbbbczbbcbzzzbcbzczbcczb\r\ndbzzzccdcdczzzzzcdczbbzcdzbcdbzzdczbzddcddbdbzzzczcczzbdcbbzccbzzzdzbzddcbzbdzdcczccbdb\r\nzdczddzcdddddczdczdczdcdzczddzczdzddczdcdcdzczczzdzccdccczczdzczczdzcdddzddzccddcczczzd\r\n", "output": "Draw\r\n"}, {"input": "727\r\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\r\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\r\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffeeeeeefeffef\r\n", "output": "Draw\r\n"}, {"input": "61\r\nbzqiqprzfwddqwctcrhnkqcsnbmcmfmrgaljwieajfouvuiunmfbrehxchupmsdpwilwu\r\njyxxujvxkwilikqeegzxlyiugflxqqbwbujzedqnlzucdnuipacatdhcozuvgktwvirhs\r\ntqiahohijwfcetyyjlkfhfvkhdgllxmhyyhhtlhltcdspusyhwpwqzyagtsbaswaobwub\r\n", "output": "Katie\r\n"}, {"input": "30\r\njAjcdwkvcTYSYBBLniJIIIiubKWnqeDtUiaXSIPfhDTOrCWBQetm\r\nPQPOTgqfBWzQvPNeEaUaPQGdUgldmOZsBtsIqZGGyXozntMpOsyY\r\nNPfvGxMqIULNWOmUrHJfsqORUHkzKQfecXsTzgFCmUtFmIBudCJr\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcabcabcabcdddabc\r\nzxytzytxxtytxyzxyt\r\nfgffghfghffgghghhh\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabcd\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nbbb\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nlkjhg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nbbbbb\r\naabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\nfghij\r\nkkkkk\r\n", "output": "Katie\r\n"}, {"input": "4\r\naaaabcd\r\naaaabcd\r\naaaaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naabcde\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaaa\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "1\r\nAAAAA\r\nBBBBB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "1\r\nabcde\r\naaaaa\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabfcde\r\nabfcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\naaa\r\naab\r\nccd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naabbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\nxxxxxx\r\nxxxooo\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\noooo\r\naaac\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\naaabb\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nqwery\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaa\r\nbbbbbb\r\naaaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabb\r\naabb\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naab\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nbbbbcc\r\nbbbbbb\r\nsadfgh\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaacc\r\nxxxxkkkk\r\nxxxxkkkk\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaac\r\nbbbbc\r\nccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaabbbbbb\r\nabcdewert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabc\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaa\r\naaaaaaab\r\naaaabbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcdefg\r\nabccccc\r\nacccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabcdef\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaabbb\r\naabdef\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabba\r\nbbbb\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbbaaa\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naaa\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcda\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabbc\r\nqwert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabbcc\r\naabbcc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nAAAAAA\r\nAAAAAB\r\nABCDEF\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabc\r\naac\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naabbc\r\naabbc\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaab\r\naaaaabb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaaaa\r\nbbbbbbbbaaa\r\nqwertyuiasd\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\naabb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabcd\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nabc\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "1\r\naa\r\nab\r\nbb\r\n", "output": "Shiro\r\n"}, {"input": "1\r\naacb\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcd\r\nabcd\r\naaad\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaab\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaab\r\nabcd\r\nabcd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\nabcd\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "2\r\nxxxx\r\nyyyx\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nAAAAA\r\nAAAAB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaacdc\r\naaaaabc\r\naaaaabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabcde\r\naabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naaabb\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\nabbbbb\r\ncbbbbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaaaabbbb\r\naaaaabbbb\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaaaaab\r\naaabbbb\r\naaabbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaaabb\r\naaabbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaabb\r\naaaaab\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaa\r\naaaae\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\nbbbcde\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaaabbb\r\naabcdef\r\naabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaa\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabbbbb\r\naaabbbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\naabcd\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\naaabbcc\r\nabcdefg\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naabbb\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\nbbb\r\nabb\r\nqer\r\n", "output": "Kuro\r\n"}, {"input": "5\r\naabbbbb\r\naaaaaaa\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naaaab\r\naaabb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaaab\r\naaaabbb\r\naaaaccc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaaaaaaa\r\naaaaaaaaaaab\r\naaaaaabbbbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabb\r\nabcde\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaac\r\naaaaebc\r\naaaaaac\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaabbb\r\nqwerty\r\n", "output": "Draw\r\n"}, {"input": "3\r\ncccca\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "100005\r\nAA\r\nBC\r\nCC\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\nccca\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbcdef\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\naabb\r\nqwer\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\nbbaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaa\r\naaaa\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\naaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaa\r\nabcd\r\naaab\r\n", "output": "Katie\r\n"}]
| 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)):
if i+1<len(l) and i-1>=0 and l[i+1]>l[i-1]+1:
maxlen=max(dp1[i-1]+dp2[i+1]+1,maxlen)
if i-1>=0 and l[i]<=l[i-1]:
maxlen=max(maxlen,dp1[i-1]+1)
if i+1<len(l) and l[i]>=l[i+1]:
maxlen=max(maxlen,dp2[i+1]+1)
print(maxlen)
| 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.append(starts[-1]+1)
else:
starts.append(1)
starts.reverse()
ans=0
for i in range(1,n-1):
if a[i-1]<a[i+1]-1:
ans=max(ans,ends[i-1]+starts[i+1]+1)
else:
ans=max(ans,ends[i-1]+1,starts[i+1]+1)
ans=max(ans,starts[1]+1)
ans=max(ans,ends[n-2]+1)
print(ans)
|
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 number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find.
|
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 25202363 350490028 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737 35005212 521595369 294702568 726956430 336465783 861021531 59961394 89018457 101513930 125898168 131176230 145174068 233665124 278722863 315634023 369133070 468703136 628175012 635723059 653377374 656478043 801979803 859484422 914544920 608413785 756898538 734575199 973594325 149798316 38664371\r\n", "output": "19\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 3 4 1\r\n", "output": "5\r\n"}, {"input": "10\r\n1 2 3 4 5 5 6 7 8 9\r\n", "output": "6\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 2 3 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 2 3 1 6\r\n", "output": "5\r\n"}, {"input": "1\r\n42\r\n", "output": "1\r\n"}, {"input": "5\r\n1 2 42 3 4\r\n", "output": "4\r\n"}, {"input": "5\r\n1 5 9 6 10\r\n", "output": "4\r\n"}, {"input": "5\r\n5 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 3 3 4\r\n", "output": "4\r\n"}, {"input": "8\r\n1 2 3 4 1 5 6 7\r\n", "output": "5\r\n"}, {"input": "1\r\n3\r\n", "output": "1\r\n"}, {"input": "3\r\n5 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 3 4\r\n", "output": "4\r\n"}, {"input": "6\r\n7 2 12 4 5 6\r\n", "output": "5\r\n"}, {"input": "6\r\n7 2 3 1 4 5\r\n", "output": "4\r\n"}, {"input": "6\r\n2 3 5 5 6 7\r\n", "output": "6\r\n"}, {"input": "5\r\n2 4 7 6 8\r\n", "output": "5\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "3\r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n4 1 2 3 4\r\n", "output": "5\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6\r\n", "output": "7\r\n"}, {"input": "4\r\n1 2 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n4 3 1 2\r\n", "output": "3\r\n"}, {"input": "6\r\n1 2 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n5 1 2 3\r\n", "output": "4\r\n"}, {"input": "5\r\n9 1 2 3 4\r\n", "output": "5\r\n"}, {"input": "2\r\n1 1\r\n", "output": "2\r\n"}, {"input": "5\r\n1 3 2 4 5\r\n", "output": "4\r\n"}, {"input": "6\r\n1 2 1 2 4 5\r\n", "output": "5\r\n"}, {"input": "10\r\n1 1 5 3 2 9 9 7 7 6\r\n", "output": "3\r\n"}, {"input": "6\r\n1 2 3 100000 100 101\r\n", "output": "6\r\n"}, {"input": "4\r\n3 3 3 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 5\r\n", "output": "3\r\n"}, {"input": "5\r\n1 3 2 3 4\r\n", "output": "4\r\n"}, {"input": "10\r\n1 2 3 4 5 10 10 11 12 13\r\n", "output": "10\r\n"}, {"input": "7\r\n11 2 1 2 13 4 14\r\n", "output": "5\r\n"}, {"input": "3\r\n5 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 5 3 4\r\n", "output": "4\r\n"}, {"input": "10\r\n1 2 3 4 100 6 7 8 9 10\r\n", "output": "10\r\n"}, {"input": "3\r\n5 3 5\r\n", "output": "3\r\n"}, {"input": "5\r\n100 100 7 8 9\r\n", "output": "4\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5\r\n1 2 4 4 5\r\n", "output": "5\r\n"}, {"input": "6\r\n7 4 5 6 7 8\r\n", "output": "6\r\n"}, {"input": "9\r\n3 4 1 6 3 4 5 6 7\r\n", "output": "7\r\n"}, {"input": "3\r\n1000 1 2\r\n", "output": "3\r\n"}, {"input": "3\r\n20 1 9\r\n", "output": "3\r\n"}, {"input": "6\r\n7 2 3 1 4 6\r\n", "output": "4\r\n"}, {"input": "3\r\n100 5 10\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 2 3\r\n", "output": "3\r\n"}, {"input": "6\r\n4 2 8 1 2 5\r\n", "output": "4\r\n"}, {"input": "3\r\n25 1 6\r\n", "output": "3\r\n"}, {"input": "10\r\n17 99 23 72 78 36 5 43 95 9\r\n", "output": "5\r\n"}, {"input": "7\r\n21 16 22 21 11 13 19\r\n", "output": "4\r\n"}, {"input": "5\r\n1 2 5 3 4\r\n", "output": "4\r\n"}, {"input": "6\r\n2 2 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 1 2 3\r\n", "output": "4\r\n"}, {"input": "3\r\n81 33 64\r\n", "output": "3\r\n"}, {"input": "7\r\n14 3 3 19 13 19 15\r\n", "output": "4\r\n"}, {"input": "9\r\n1 2 3 4 5 42 7 8 9\r\n", "output": "9\r\n"}, {"input": "5\r\n2 3 7 5 6\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 3 4 5\r\n", "output": "5\r\n"}, {"input": "6\r\n1 5 4 3 4 5\r\n", "output": "4\r\n"}]
| 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 = []
while x < m:
if z >= n - 1:
w += [m - x]
break
w += [r[z] - x - 1]
x = r[z] - 1
f = False
for i in range(z + 1, n):
if (u[i] >= s) and (l[i] + 1 - x <= d):
w += [l[i] + 1 - x]
x = l[i] + 1
z = i
f = True
break
if not f:
print("IMPOSSIBLE")
return
for i in range(len(w)):
if i % 2 == 0:
print("RUN", w[i])
else:
print("JUMP", w[i])
n, m, s, d = map(int, input().split())
a = [int(v) for v in input().split()]
a.sort()
solve(a, s, d, m)
| 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] = x
else:
if pieces[-1][1] - pieces[-1][0] + 2 > d: return False
pieces.append([x, x])
if pieces[-1][1] - pieces[-1][0] + 2 > d: return False
pos = 0
for piece in pieces:
sys.stdout.write('RUN ' + str(piece[0] - pos - 1) + '\n')
sys.stdout.write('JUMP ' + str(piece[1] - piece[0] + 2) + '\n')
pos = piece[1] + 1
if pos < m:
sys.stdout.write('RUN ' + str(m - pos) + '\n')
return True
if not solve():
print('IMPOSSIBLE')
|
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 length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
|
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 sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
|
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 for "X" more meters;
- print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
| 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\nJUMP 3\r\nRUN 4\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "10 1000000000 8905990 20319560\r\n233244997 997992814 242452779 497363176 572234096 126615858 886769539 662035052 989086824 716655858\r\n", "output": "RUN 126615857\r\nJUMP 2\r\nRUN 106629137\r\nJUMP 2\r\nRUN 9207780\r\nJUMP 2\r\nRUN 254910395\r\nJUMP 2\r\nRUN 74870918\r\nJUMP 2\r\nRUN 89800954\r\nJUMP 2\r\nRUN 54620804\r\nJUMP 2\r\nRUN 170113679\r\nJUMP 2\r\nRUN 102317283\r\nJUMP 8905992\r\nRUN 2007185\r\n"}, {"input": "100 1000 1 4\r\n228 420 360 642 442 551 940 343 24 83 928 110 663 548 704 461 942 799 283 746 371 204 435 209 986 489 918 526 496 321 233 643 208 717 806 18 291 431 521 631 3 450 711 602 401 60 680 930 625 891 161 279 510 529 546 338 473 925 446 786 384 952 260 649 865 916 789 71 103 997 484 89 408 129 953 670 568 55 287 511 369 225 950 539 652 567 730 499 687 90 779 848 801 606 82 853 967 776 951 329\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "100 600 1 4\r\n9 536 518 59 229 377 72 203 81 309 304 321 55 439 287 505 3 410 582 351 440 568 584 259 22 415 348 147 404 277 477 323 537 75 548 324 338 198 145 182 271 496 256 329 592 132 291 222 115 587 54 158 154 103 356 15 36 76 402 27 223 551 267 527 51 34 417 573 479 398 425 71 485 20 262 566 467 131 524 352 330 541 146 53 322 436 366 86 88 272 96 456 388 319 149 470 129 162 353 346\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 2 1 5\r\n1\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 3 1 2\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\n"}, {"input": "1 5 1 2\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\nRUN 2\r\n"}, {"input": "100 1000 1 5\r\n204 233 384 776 450 649 473 717 55 90 208 951 499 551 916 18 539 103 420 521 730 779 360 546 746 953 484 82 110 789 161 950 71 806 928 652 510 287 997 967 329 786 643 431 321 663 279 291 799 986 848 680 89 225 918 801 567 369 687 209 602 401 952 930 442 853 606 338 129 631 228 24 3 925 940 711 496 625 548 446 891 283 60 83 529 511 568 704 371 343 670 435 461 865 408 642 260 526 489 942\r\n", "output": "RUN 2\nJUMP 2\nRUN 13\nJUMP 2\nRUN 4\nJUMP 2\nRUN 29\nJUMP 2\nRUN 3\nJUMP 2\nRUN 9\nJUMP 2\nRUN 9\nJUMP 3\nRUN 4\nJUMP 3\nRUN 11\nJUMP 2\nRUN 5\nJUMP 2\nRUN 17\nJUMP 2\nRUN 30\nJUMP 2\nRUN 41\nJUMP 2\nRUN 2\nJUMP 3\nRUN 14\nJUMP 2\nRUN 1\nJUMP 2\nRUN 3\nJUMP 2\nRUN 25\nJUMP 2\nRUN 17\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 28\nJUMP 2\nRUN 6\nJUMP 2\nRUN 7\nJUMP 2\nRUN 3\nJUMP 2\nRUN 15\nJUMP 2\nRUN 7\nJUMP 4\nRUN 11\nJUMP 2\nRUN 15\nJUMP 2\nRUN 5\nJUMP 2\nRUN 10\nJUMP 2\nRUN 9\nJUMP 2\nRUN 2\nJUMP 2\nRUN 5\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 9\nJUMP 2\nRUN 10\nJUMP 2\nRUN 9\nJUMP 2\nRUN 3\nJUMP 2\nRUN 5\nJUMP 2\nRUN 1\nJUMP 2\nRUN 9\nJUMP 3\nRUN 8\nJUMP 2\nRUN 3\nJUMP 2\nRUN 1\nJUMP 2\nRUN 8\nJUMP 2\nRUN 5\nJUMP 4\nRUN 1\nJUMP 2\nRUN 14\nJUMP 3\nRUN 32\nJUMP 2\nRUN 2\nJUMP 2\nRUN 17\nJUMP 2\nRUN 4\nJUMP 2\nRUN 9\nJUMP 3\nRUN 4\nJUMP 2\nRUN 1\nJUMP 2\nRUN 9\nJUMP 2\nRUN 5\nJUMP 2\nRUN 8\nJUMP 2\nRUN 5\nJUMP 2\nRUN 15\nJUMP 2\nRUN 5\nJUMP 2\nRUN 4\nJUMP 2\nRUN 11\nJUMP 2\nRUN 14\nJUMP 2\nRUN 28\nJUMP 2\nRUN 1\nJUMP 2\nRUN 5\nJUMP 2\nRUN 1\nJUMP 2\nRUN 8\nJUMP 4\nRUN 3\nJUMP 2\nRUN 40\nJUMP 2\nRUN 3\nJUMP 2\nRUN 10\nJUMP 2\nRUN 24\nJUMP 2\nRUN 23\nJUMP 4\nRUN 5\nJUMP 2\nRUN 1\nJUMP 4\nRUN 8\nJUMP 4\nRUN 6\nJUMP 5\nRUN 12\nJUMP 2\nRUN 17\nJUMP 2\nRUN 9\nJUMP 2\nRUN 2\n"}, {"input": "1 1000000000 1000000000 2\r\n999999999\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 100 1 1\r\n4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 1000000000 1 1000000000\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\nRUN 999999997\r\n"}, {"input": "3 12000 2000 3000\r\n3000 9002 7001\r\n", "output": "RUN 2999\r\nJUMP 2\r\nRUN 3999\r\nJUMP 2003\r\nRUN 2997\r\n"}, {"input": "4 30000 5000 6000\r\n6000 16000 15000 21001\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 12000 2000 245\r\n3000 9003 7001\r\n", "output": "RUN 2999\r\nJUMP 2\r\nRUN 3999\r\nJUMP 2\r\nRUN 2000\r\nJUMP 2\r\nRUN 2996\r\n"}, {"input": "4 30000 5000 1654\r\n6000 16000 14999 21002\r\n", "output": "RUN 5999\r\nJUMP 2\r\nRUN 8997\r\nJUMP 1003\r\nRUN 5000\r\nJUMP 2\r\nRUN 8997\r\n"}, {"input": "4 10000 500 500\r\n700 600 1099 2000\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 20000 4000 3502\r\n5000 8500 15000\r\n", "output": "RUN 4999\r\nJUMP 3502\r\nRUN 6498\r\nJUMP 2\r\nRUN 4999\r\n"}, {"input": "4 10000 500 500\r\n700 601 1099 2000\r\n", "output": "RUN 600\r\nJUMP 500\r\nRUN 899\r\nJUMP 2\r\nRUN 7999\r\n"}, {"input": "3 20000 4000 3502\r\n5000 8501 15000\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 10 1 2\r\n9\r\n", "output": "RUN 8\r\nJUMP 2\r\n"}, {"input": "1 10 2 9\r\n5\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 4\r\n"}, {"input": "1 9 6 4\r\n4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 10 7 4\r\n5\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 14 8 8\r\n5 9\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 23 12 8\r\n8 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 14 4 2\r\n2 7\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 21 6 2\r\n7 11 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 29 3 4\r\n7 16 19\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 24 2 6\r\n6 12 17\r\n", "output": "RUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "4 31 12 9\r\n7 13 21 28\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "4 10 1 7\r\n2 4 6 8\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "4 36 8 4\r\n4 13 19 27\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 25 10 2\r\n6 12 13 15 22\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 19 7 10\r\n3 7 9 12 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 28 6 8\r\n3 9 15 21 25\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 35 12 4\r\n7 12 17 21 24 28\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 22 5 7\r\n4 6 10 13 15 18\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 55 3 5\r\n10 18 24 34 39 45\r\n", "output": "RUN 9\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 9\r\n"}, {"input": "7 51 6 1\r\n8 17 18 23 27 33 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "7 36 11 4\r\n6 11 17 19 22 24 30\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "7 28 10 2\r\n5 10 14 19 21 23 27\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 46 4 5\r\n3 6 15 21 24 26 36 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 51 2 1\r\n6 14 20 26 29 35 40 48\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 56 2 9\r\n7 11 20 28 34 39 40 48\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 7\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 3\r\nRUN 6\r\nJUMP 2\r\nRUN 7\r\n"}, {"input": "9 57 2 2\r\n5 11 15 21 24 30 36 43 50\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "9 82 14 4\r\n10 18 28 38 46 55 64 74 79\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "9 40 6 3\r\n5 10 14 18 22 27 30 31 36\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 44 6 2\r\n4 8 13 19 23 29 32 33 37 41\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 42 1 3\r\n1 6 10 15 17 22 24 29 33 38\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 82 2 5\r\n9 17 27 37 44 51 57 62 67 72\r\n", "output": "RUN 8\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 9\r\n"}, {"input": "11 69 4 9\r\n7 14 20 26 29 35 40 46 52 58 64\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 5\r\nRUN 4\r\nJUMP 7\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\n"}, {"input": "11 65 1 7\r\n7 11 14 21 24 30 37 44 50 56 59\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 5\r\n"}, {"input": "11 77 10 10\r\n7 14 17 24 29 34 38 47 56 64 69\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 78 3 1\r\n4 11 19 22 30 38 43 51 56 59 67 73\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 89 14 9\r\n6 11 18 24 33 37 45 51 60 69 71 80\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 13 6 7\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "13 91 1 3\r\n5 12 17 22 29 36 43 49 57 64 70 74 84\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "13 87 5 6\r\n7 10 18 24 31 40 41 48 54 63 69 78 81\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "13 46 2 4\r\n1 4 9 13 15 19 21 23 25 30 35 37 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 93 1 1\r\n8 15 19 21 28 36 44 51 56 63 67 74 79 85\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 62 11 4\r\n5 10 15 18 22 26 31 34 39 42 44 47 52 57\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 109 10 1\r\n8 15 25 29 38 48 57 65 70 79 81 89 94 100\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 97 4 4\r\n3 7 13 23 29 35 39 45 49 50 60 68 72 81 87\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 77 4 8\r\n7 14 16 20 26 33 36 43 44 48 52 59 61 66 70\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 56 1 5\r\n5 10 15 20 21 25 29 31 34 37 38 41 43 47 52\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 3\r\nRUN 2\r\nJUMP 2\r\nRUN 2\r\nJUMP 4\r\nRUN 1\r\nJUMP 2\r\nRUN 1\r\nJUMP 3\r\nRUN 1\r\nJUMP 4\r\nRUN 2\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\n"}, {"input": "2 1000000000 1 3\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 1 2\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 1 4\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 2 4\r\n5 8\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 1000000000 2 5\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 5\r\nRUN 999999991\r\n"}]
| 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:
print('YES')
exit()
print('NO')
| 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:
cnt += 1
if cnt > 2:
break
row[c1], row[c2] = row[c2], row[c1]
if cnt > 2:
ok = False
break
if ok:
print('YES')
sys.exit(0)
print('NO')
|
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 to perform from 0 to n + 1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
|
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 8 9 10\r\n", "output": "YES\r\n"}, {"input": "5 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 8 5 6 7 10 9 4 11 12\r\n1 5 3 4 2 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n", "output": "YES\r\n"}, {"input": "4 10\r\n3 2 8 10 5 6 7 1 9 4\r\n1 2 9 4 5 3 7 8 10 6\r\n7 5 3 4 8 6 1 2 9 10\r\n4 2 3 9 8 6 7 5 1 10\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n9 2 3 4 5 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 10 7 8 1 6\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n9 10 4 2 3 5 7 1 8 6\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n6 4 7 3 5 8 1 9 10 2\r\n1 5 10 6 3 4 9 7 2 8\r\n3 2 1 7 8 6 5 4 10 9\r\n7 9 1 6 8 2 4 5 3 10\r\n3 4 6 9 8 7 1 2 10 5\r\n", "output": "NO\r\n"}, {"input": "20 2\r\n1 2\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "20 3\r\n3 2 1\r\n2 3 1\r\n2 3 1\r\n2 1 3\r\n1 3 2\r\n2 1 3\r\n1 2 3\r\n3 2 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n2 1 3\r\n2 3 1\r\n2 3 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n3 1 2\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 2 3 4 5 6 7 10 9 8\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n6 9 3 4 5 1 8 7 2 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 19 14 15 16 17 18 13 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 20\r\n1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 17 18 19 20\r\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 12 18 7 8 9 10 11 5 13 14 15 16 17 6 19 20\r\n6 2 3 4 5 1 7 8 9 10 11 12 13 20 15 16 17 18 19 14\r\n4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 19 8 9 10 11 12 13 14 15 20 17 18 7 16\r\n1 2 9 4 5 6 7 8 18 10 11 12 13 14 15 16 17 3 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n4 2 3 8 5 6 7 1 9 10\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n3 2 1 4 5 6 7 8 10 9\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 18 14 15 16 17 13 11 20\r\n1 2 11 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 3 20\r\n13 2 3 4 5 6 7 8 9 10 19 12 1 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 16 8 9 10 11 12 13 14 15 7 17 18 19 20\r\n1 2 3 14 5 6 16 8 9 10 11 12 13 4 15 7 17 18 19 20\r\n1 2 3 4 5 6 16 8 18 10 11 12 13 14 15 7 17 9 19 20\r\n1 2 3 4 5 6 16 8 9 15 11 12 13 14 10 7 17 18 19 20\r\n1 2 18 4 5 6 16 8 9 10 11 12 13 14 15 7 17 3 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 18 4 5 6 7 8 9 10 11 12 13 14 15 16 19 3 17 20\r\n8 2 3 9 5 6 7 1 4 10 11 12 13 14 15 16 17 18 19 20\r\n7 2 3 4 5 6 1 8 9 10 11 12 13 14 15 16 17 20 19 18\r\n1 2 3 12 5 6 7 8 9 17 11 4 13 14 15 16 10 18 19 20\r\n1 11 3 4 9 6 7 8 5 10 2 12 13 14 15 16 17 18 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n10 2 3 4 5 9 7 8 6 1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 9 2 4 6 5 8 3 7 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 3 2 19 5 6 7 8 9 17 11 12 13 14 15 16 10 18 4 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 20 6 7 8 9 17 11 12 13 14 15 16 10 18 19 5\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 6 17 4 5 2 7 14 9 10 11 12 13 8 15 16 3 18 19 20\r\n5 6 17 4 1 2 7 8 9 10 11 12 13 14 15 16 3 18 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 18 3 16 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 16 3 18 20 19\r\n1 6 17 8 5 2 7 4 9 10 11 12 13 14 15 16 3 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n10 2 9 4 5 6 7 8 15 1 11 16 13 14 3 12 17 18 19 20\r\n10 2 3 4 5 6 7 1 9 8 11 16 13 14 15 12 17 18 19 20\r\n9 2 3 4 5 6 7 8 10 1 11 16 13 14 15 12 20 18 19 17\r\n10 2 3 4 7 6 5 8 9 1 11 16 18 14 15 12 17 13 19 20\r\n10 2 3 4 5 6 7 8 9 20 11 16 14 13 15 12 17 18 19 1\r\n", "output": "NO\r\n"}, {"input": "1 4\r\n2 3 4 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 1 3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "15 6\r\n2 1 4 3 6 5\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n4 3 1 2\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "4 8\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n", "output": "YES\r\n"}, {"input": "4 6\r\n1 2 3 5 6 4\r\n3 2 1 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n3 1 2\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 1 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "20 8\r\n4 3 2 1 5 6 7 8\r\n1 2 3 4 8 7 6 5\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n8 7 6 5 4 3 2 1\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n", "output": "YES\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 11 12 9\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n3 2 1 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n2 3 1 4 5 6\r\n1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n2 3 1\r\n2 3 1\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "5 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n3 8 1 4 5 6 7 2\r\n1 8 3 6 5 4 7 2\r\n1 8 3 5 4 6 7 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 4 3 1\r\n2 1 5 4 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 3 1 4\r\n1 2 3 4\r\n2 3 1 4\r\n2 1 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 4 3 5\r\n2 1 4 3 5\r\n1 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "3 10\r\n2 1 3 4 5 6 8 7 10 9\r\n1 2 3 4 5 6 8 7 10 9\r\n1 2 3 4 6 5 8 7 10 9\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n3 1 2 4\r\n3 2 4 1\r\n3 1 2 4\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n1 4 2 3 5\r\n1 2 4 5 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 3 4\r\n2 1 5 3 4\r\n", "output": "NO\r\n"}, {"input": "3 6\r\n2 3 1 4 5 6\r\n2 1 4 3 5 6\r\n1 2 3 4 5 6\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "4 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 3 4 5\r\n1 3 4 2 5\r\n1 4 2 3 5\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 2 3\r\n1 2 3\r\n1 2 3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n3 1 2\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "7 4\r\n1 2 3 4\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 2 3\r\n1 3 2\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}]
| 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
# Получение длины препятсвия
def getLetLen(letIndex) -> "(newIndex, letLen)":
if letIndex == len(a): return (letIndex, 0)
letPosition, res = a[letIndex], 1
while True:
letIndex += 1
if letIndex == len(a): break
nextLetPosition = a[letIndex]
if letPosition == nextLetPosition - 1:
letPosition, res = nextLetPosition, res + 1
else:
break
return (letIndex, res + 1)
# Получение полной длины препятсвия
def getFullLetLen(position, runLen, letIndex) -> "(newIndex, letLen)":
nextIndex, letLen = getLetLen(letIndex)
res = letLen
newPosition = position + runLen + letLen
while True:
# Расматриваем следующий этап. Бегун находиться в позиции newPosition
# Текущий индекс препятсвия nextIndex
if nextIndex == len(a): return (nextIndex, res)
nextRunLen = getRunLen(newPosition, nextIndex)
if nextRunLen < s:
nextIndex, letLen = getLetLen(nextIndex)
newPosition += nextRunLen + letLen
res += nextRunLen + letLen
else:
break
return (nextIndex, res)
# Текущее состояние
currentPosition = 0 # Положение на прямой и
currentLetIndex = 0 # текущее препятствие
res = []
while True:
if currentPosition == m: break
runLen = getRunLen(currentPosition, currentLetIndex)
currentLetIndex, letLen = getFullLetLen(currentPosition, runLen, currentLetIndex)
if runLen < s or letLen > d:
print("IMPOSSIBLE")
sys.exit(0)
if runLen > 0:
currentPosition += runLen
tstr = "RUN " + str(runLen)
res.append(tstr)
if letLen > 0:
currentPosition += letLen
tstr = "JUMP " + str(letLen)
res.append(tstr)
print("\n".join(list(map(str, res))))
| 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)
# and end up at (crd-1)
dist = crd-segment[1] - 2
if dist < s or crd==segment[1]+1:
a.append((segment[0], crd))
return
else: a.append(segment)
a.append((crd, crd))
while a_raw: process_obstacle(a_raw.pop())
a_raw = None
a = a[::-1]
def freakout():
print('IMPOSSIBLE')
exit(0)
x = 0
steps = []
while x != m:
if a:
l, r = a.pop()
if l < x: continue
if l > m:
a.clear()
continue
dist, length = l-x-1, r-l+2
# print('x=%d l=%d r=%d dist=%d len=%d'%(x, l, r, dist, length))
if dist < s: freakout()
if length > d: freakout()
steps.append('RUN %d'%dist)
steps.append('JUMP %d'%length)
# x = r+1
x += dist + length
else:
steps.append('RUN %d'%(m-x))
x = m
print('\n'.join(steps))
|
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 length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
|
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 sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
|
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 for "X" more meters;
- print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
| 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\nJUMP 3\r\nRUN 4\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "10 1000000000 8905990 20319560\r\n233244997 997992814 242452779 497363176 572234096 126615858 886769539 662035052 989086824 716655858\r\n", "output": "RUN 126615857\r\nJUMP 2\r\nRUN 106629137\r\nJUMP 2\r\nRUN 9207780\r\nJUMP 2\r\nRUN 254910395\r\nJUMP 2\r\nRUN 74870918\r\nJUMP 2\r\nRUN 89800954\r\nJUMP 2\r\nRUN 54620804\r\nJUMP 2\r\nRUN 170113679\r\nJUMP 2\r\nRUN 102317283\r\nJUMP 8905992\r\nRUN 2007185\r\n"}, {"input": "100 1000 1 4\r\n228 420 360 642 442 551 940 343 24 83 928 110 663 548 704 461 942 799 283 746 371 204 435 209 986 489 918 526 496 321 233 643 208 717 806 18 291 431 521 631 3 450 711 602 401 60 680 930 625 891 161 279 510 529 546 338 473 925 446 786 384 952 260 649 865 916 789 71 103 997 484 89 408 129 953 670 568 55 287 511 369 225 950 539 652 567 730 499 687 90 779 848 801 606 82 853 967 776 951 329\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "100 600 1 4\r\n9 536 518 59 229 377 72 203 81 309 304 321 55 439 287 505 3 410 582 351 440 568 584 259 22 415 348 147 404 277 477 323 537 75 548 324 338 198 145 182 271 496 256 329 592 132 291 222 115 587 54 158 154 103 356 15 36 76 402 27 223 551 267 527 51 34 417 573 479 398 425 71 485 20 262 566 467 131 524 352 330 541 146 53 322 436 366 86 88 272 96 456 388 319 149 470 129 162 353 346\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 2 1 5\r\n1\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 3 1 2\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\n"}, {"input": "1 5 1 2\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\nRUN 2\r\n"}, {"input": "100 1000 1 5\r\n204 233 384 776 450 649 473 717 55 90 208 951 499 551 916 18 539 103 420 521 730 779 360 546 746 953 484 82 110 789 161 950 71 806 928 652 510 287 997 967 329 786 643 431 321 663 279 291 799 986 848 680 89 225 918 801 567 369 687 209 602 401 952 930 442 853 606 338 129 631 228 24 3 925 940 711 496 625 548 446 891 283 60 83 529 511 568 704 371 343 670 435 461 865 408 642 260 526 489 942\r\n", "output": "RUN 2\nJUMP 2\nRUN 13\nJUMP 2\nRUN 4\nJUMP 2\nRUN 29\nJUMP 2\nRUN 3\nJUMP 2\nRUN 9\nJUMP 2\nRUN 9\nJUMP 3\nRUN 4\nJUMP 3\nRUN 11\nJUMP 2\nRUN 5\nJUMP 2\nRUN 17\nJUMP 2\nRUN 30\nJUMP 2\nRUN 41\nJUMP 2\nRUN 2\nJUMP 3\nRUN 14\nJUMP 2\nRUN 1\nJUMP 2\nRUN 3\nJUMP 2\nRUN 25\nJUMP 2\nRUN 17\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 28\nJUMP 2\nRUN 6\nJUMP 2\nRUN 7\nJUMP 2\nRUN 3\nJUMP 2\nRUN 15\nJUMP 2\nRUN 7\nJUMP 4\nRUN 11\nJUMP 2\nRUN 15\nJUMP 2\nRUN 5\nJUMP 2\nRUN 10\nJUMP 2\nRUN 9\nJUMP 2\nRUN 2\nJUMP 2\nRUN 5\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 9\nJUMP 2\nRUN 10\nJUMP 2\nRUN 9\nJUMP 2\nRUN 3\nJUMP 2\nRUN 5\nJUMP 2\nRUN 1\nJUMP 2\nRUN 9\nJUMP 3\nRUN 8\nJUMP 2\nRUN 3\nJUMP 2\nRUN 1\nJUMP 2\nRUN 8\nJUMP 2\nRUN 5\nJUMP 4\nRUN 1\nJUMP 2\nRUN 14\nJUMP 3\nRUN 32\nJUMP 2\nRUN 2\nJUMP 2\nRUN 17\nJUMP 2\nRUN 4\nJUMP 2\nRUN 9\nJUMP 3\nRUN 4\nJUMP 2\nRUN 1\nJUMP 2\nRUN 9\nJUMP 2\nRUN 5\nJUMP 2\nRUN 8\nJUMP 2\nRUN 5\nJUMP 2\nRUN 15\nJUMP 2\nRUN 5\nJUMP 2\nRUN 4\nJUMP 2\nRUN 11\nJUMP 2\nRUN 14\nJUMP 2\nRUN 28\nJUMP 2\nRUN 1\nJUMP 2\nRUN 5\nJUMP 2\nRUN 1\nJUMP 2\nRUN 8\nJUMP 4\nRUN 3\nJUMP 2\nRUN 40\nJUMP 2\nRUN 3\nJUMP 2\nRUN 10\nJUMP 2\nRUN 24\nJUMP 2\nRUN 23\nJUMP 4\nRUN 5\nJUMP 2\nRUN 1\nJUMP 4\nRUN 8\nJUMP 4\nRUN 6\nJUMP 5\nRUN 12\nJUMP 2\nRUN 17\nJUMP 2\nRUN 9\nJUMP 2\nRUN 2\n"}, {"input": "1 1000000000 1000000000 2\r\n999999999\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 100 1 1\r\n4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 1000000000 1 1000000000\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\nRUN 999999997\r\n"}, {"input": "3 12000 2000 3000\r\n3000 9002 7001\r\n", "output": "RUN 2999\r\nJUMP 2\r\nRUN 3999\r\nJUMP 2003\r\nRUN 2997\r\n"}, {"input": "4 30000 5000 6000\r\n6000 16000 15000 21001\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 12000 2000 245\r\n3000 9003 7001\r\n", "output": "RUN 2999\r\nJUMP 2\r\nRUN 3999\r\nJUMP 2\r\nRUN 2000\r\nJUMP 2\r\nRUN 2996\r\n"}, {"input": "4 30000 5000 1654\r\n6000 16000 14999 21002\r\n", "output": "RUN 5999\r\nJUMP 2\r\nRUN 8997\r\nJUMP 1003\r\nRUN 5000\r\nJUMP 2\r\nRUN 8997\r\n"}, {"input": "4 10000 500 500\r\n700 600 1099 2000\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 20000 4000 3502\r\n5000 8500 15000\r\n", "output": "RUN 4999\r\nJUMP 3502\r\nRUN 6498\r\nJUMP 2\r\nRUN 4999\r\n"}, {"input": "4 10000 500 500\r\n700 601 1099 2000\r\n", "output": "RUN 600\r\nJUMP 500\r\nRUN 899\r\nJUMP 2\r\nRUN 7999\r\n"}, {"input": "3 20000 4000 3502\r\n5000 8501 15000\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 10 1 2\r\n9\r\n", "output": "RUN 8\r\nJUMP 2\r\n"}, {"input": "1 10 2 9\r\n5\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 4\r\n"}, {"input": "1 9 6 4\r\n4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 10 7 4\r\n5\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 14 8 8\r\n5 9\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 23 12 8\r\n8 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 14 4 2\r\n2 7\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 21 6 2\r\n7 11 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 29 3 4\r\n7 16 19\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 24 2 6\r\n6 12 17\r\n", "output": "RUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "4 31 12 9\r\n7 13 21 28\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "4 10 1 7\r\n2 4 6 8\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "4 36 8 4\r\n4 13 19 27\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 25 10 2\r\n6 12 13 15 22\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 19 7 10\r\n3 7 9 12 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 28 6 8\r\n3 9 15 21 25\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 35 12 4\r\n7 12 17 21 24 28\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 22 5 7\r\n4 6 10 13 15 18\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 55 3 5\r\n10 18 24 34 39 45\r\n", "output": "RUN 9\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 9\r\n"}, {"input": "7 51 6 1\r\n8 17 18 23 27 33 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "7 36 11 4\r\n6 11 17 19 22 24 30\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "7 28 10 2\r\n5 10 14 19 21 23 27\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 46 4 5\r\n3 6 15 21 24 26 36 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 51 2 1\r\n6 14 20 26 29 35 40 48\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 56 2 9\r\n7 11 20 28 34 39 40 48\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 7\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 3\r\nRUN 6\r\nJUMP 2\r\nRUN 7\r\n"}, {"input": "9 57 2 2\r\n5 11 15 21 24 30 36 43 50\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "9 82 14 4\r\n10 18 28 38 46 55 64 74 79\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "9 40 6 3\r\n5 10 14 18 22 27 30 31 36\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 44 6 2\r\n4 8 13 19 23 29 32 33 37 41\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 42 1 3\r\n1 6 10 15 17 22 24 29 33 38\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 82 2 5\r\n9 17 27 37 44 51 57 62 67 72\r\n", "output": "RUN 8\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 9\r\n"}, {"input": "11 69 4 9\r\n7 14 20 26 29 35 40 46 52 58 64\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 5\r\nRUN 4\r\nJUMP 7\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\n"}, {"input": "11 65 1 7\r\n7 11 14 21 24 30 37 44 50 56 59\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 5\r\n"}, {"input": "11 77 10 10\r\n7 14 17 24 29 34 38 47 56 64 69\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 78 3 1\r\n4 11 19 22 30 38 43 51 56 59 67 73\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 89 14 9\r\n6 11 18 24 33 37 45 51 60 69 71 80\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 13 6 7\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "13 91 1 3\r\n5 12 17 22 29 36 43 49 57 64 70 74 84\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "13 87 5 6\r\n7 10 18 24 31 40 41 48 54 63 69 78 81\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "13 46 2 4\r\n1 4 9 13 15 19 21 23 25 30 35 37 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 93 1 1\r\n8 15 19 21 28 36 44 51 56 63 67 74 79 85\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 62 11 4\r\n5 10 15 18 22 26 31 34 39 42 44 47 52 57\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 109 10 1\r\n8 15 25 29 38 48 57 65 70 79 81 89 94 100\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 97 4 4\r\n3 7 13 23 29 35 39 45 49 50 60 68 72 81 87\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 77 4 8\r\n7 14 16 20 26 33 36 43 44 48 52 59 61 66 70\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 56 1 5\r\n5 10 15 20 21 25 29 31 34 37 38 41 43 47 52\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 3\r\nRUN 2\r\nJUMP 2\r\nRUN 2\r\nJUMP 4\r\nRUN 1\r\nJUMP 2\r\nRUN 1\r\nJUMP 3\r\nRUN 1\r\nJUMP 4\r\nRUN 2\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\n"}, {"input": "2 1000000000 1 3\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 1 2\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 1 4\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 2 4\r\n5 8\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 1000000000 2 5\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 5\r\nRUN 999999991\r\n"}]
| 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
for j in range(i, 100001, i):
a[j] = 0
pokemonj+=pokecage[j]
if pokemonj>maxyincage:
maxyincage=pokemonj
i += 1
return(maxyincage)
def main():
n=int(input())
s=list(map(int,input().split()))
print(function1(n,s))
if __name__=='__main__':
main()
| 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, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
|
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 is no larger group with gcd ≠ 1.
|
[{"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 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10\r\n", "output": "38\r\n"}, {"input": "95\r\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50\r\n", "output": "48\r\n"}, {"input": "44\r\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684\r\n", "output": "19\r\n"}, {"input": "35\r\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557\r\n", "output": "20\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n10 7 9 8 3 3 10 7 3 3\r\n", "output": "5\r\n"}, {"input": "9\r\n10 10 6 10 9 1 8 3 5\r\n", "output": "5\r\n"}, {"input": "7\r\n9 4 2 3 3 9 8\r\n", "output": "4\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "6\r\n1623 45906 37856 34727 27156 12598\r\n", "output": "4\r\n"}, {"input": "30\r\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566\r\n", "output": "15\r\n"}, {"input": "23\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16\r\n", "output": "22\r\n"}, {"input": "46\r\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33\r\n", "output": "27\r\n"}, {"input": "43\r\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34\r\n", "output": "21\r\n"}, {"input": "25\r\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 6\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n3 3 3 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n541 541\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n99989 99989\r\n", "output": "2\r\n"}, {"input": "3\r\n3 9 27\r\n", "output": "3\r\n"}, {"input": "2\r\n1009 1009\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "6\r\n2 10 20 5 15 25\r\n", "output": "5\r\n"}, {"input": "3\r\n3 3 6\r\n", "output": "3\r\n"}, {"input": "3\r\n457 457 457\r\n", "output": "3\r\n"}, {"input": "2\r\n34 17\r\n", "output": "2\r\n"}, {"input": "3\r\n12 24 3\r\n", "output": "3\r\n"}, {"input": "10\r\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991\r\n", "output": "10\r\n"}, {"input": "2\r\n1009 2018\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "3\r\n"}, {"input": "7\r\n6 9 12 15 21 27 33\r\n", "output": "7\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n557 557\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 101 101 101\r\n", "output": "3\r\n"}, {"input": "2\r\n122 3721\r\n", "output": "2\r\n"}, {"input": "2\r\n49201 98402\r\n", "output": "2\r\n"}, {"input": "2\r\n88258 44129\r\n", "output": "2\r\n"}, {"input": "2\r\n7919 47514\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n10007 20014 30021\r\n", "output": "3\r\n"}, {"input": "4\r\n10 10 5 5\r\n", "output": "4\r\n"}, {"input": "2\r\n6 9\r\n", "output": "2\r\n"}, {"input": "3\r\n6 12 9\r\n", "output": "3\r\n"}, {"input": "2\r\n14 7\r\n", "output": "2\r\n"}, {"input": "2\r\n199 199\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 49999 99998\r\n", "output": "3\r\n"}, {"input": "5\r\n1009 1009 1009 1009 1009\r\n", "output": "5\r\n"}, {"input": "3\r\n17 17 17\r\n", "output": "3\r\n"}, {"input": "2\r\n503 1509\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 99998 99998\r\n", "output": "3\r\n"}, {"input": "2\r\n28657 28657\r\n", "output": "2\r\n"}, {"input": "3\r\n121 22 33\r\n", "output": "3\r\n"}, {"input": "2\r\n10079 20158\r\n", "output": "2\r\n"}, {"input": "2\r\n6 15\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 3\r\n", "output": "4\r\n"}, {"input": "2\r\n991 1982\r\n", "output": "2\r\n"}, {"input": "3\r\n20362 30543 50905\r\n", "output": "3\r\n"}, {"input": "2\r\n443 886\r\n", "output": "2\r\n"}, {"input": "4\r\n3 7 7 21\r\n", "output": "3\r\n"}, {"input": "3\r\n3 6 9\r\n", "output": "3\r\n"}, {"input": "2\r\n217 31\r\n", "output": "2\r\n"}, {"input": "6\r\n10 10 10 5 5 5\r\n", "output": "6\r\n"}, {"input": "4\r\n49441 25225 9081 4036\r\n", "output": "4\r\n"}, {"input": "2\r\n4 9\r\n", "output": "1\r\n"}, {"input": "2\r\n18 27\r\n", "output": "2\r\n"}, {"input": "2\r\n13 26\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 15\r\n", "output": "4\r\n"}]
| 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()
# print(arr)
# x=arr[2]+arr[0]-(2*arr[1])
if arr[1]-arr[0]==arr[2]-arr[1]:
print("YES")
exit()
print("NO")
# print(arr)
|
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 from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
|
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": "4\r\n1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 4 7\r\n", "output": "YES\r\n"}, {"input": "3\r\n99999999 1 50000000\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 2 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 5 11\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n100000001 100000003\r\n", "output": "YES\r\n"}, {"input": "3\r\n7 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 100 29\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 5 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 6 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 1 1 1 1 2 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 4 4 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 2 4 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 9 10\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 1 1 1 1 1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 15 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 6 7 8 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 6 8\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 6 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n10 20 21 30\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 2 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 6 12\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0 1 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 5 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 4 5 6\r\n", "output": "NO\r\n"}]
| 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)) == abs(int(list1[len(list1)-1])-middle(list1)):
print("YES")
else:
print("NO")
else:
print("NO")
| 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 from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
|
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": "4\r\n1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 4 7\r\n", "output": "YES\r\n"}, {"input": "3\r\n99999999 1 50000000\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 2 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 5 11\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n100000001 100000003\r\n", "output": "YES\r\n"}, {"input": "3\r\n7 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 100 29\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 5 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 6 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 1 1 1 1 2 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 4 4 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 2 4 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 9 10\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 1 1 1 1 1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 15 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 6 7 8 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 6 8\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 6 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n10 20 21 30\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 2 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 6 12\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0 1 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 5 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 4 5 6\r\n", "output": "NO\r\n"}]
| 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 from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
|
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": "4\r\n1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 4 7\r\n", "output": "YES\r\n"}, {"input": "3\r\n99999999 1 50000000\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 2 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 5 11\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n100000001 100000003\r\n", "output": "YES\r\n"}, {"input": "3\r\n7 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 100 29\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 5 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 6 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 1 1 1 1 2 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 4 4 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 2 4 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 9 10\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 1 1 1 1 1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 15 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 6 7 8 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 6 8\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 6 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n10 20 21 30\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 2 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 6 12\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0 1 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 5 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 4 5 6\r\n", "output": "NO\r\n"}]
| 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:
print(end=" ")
| 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] == ' ':
res.pop()
res.append(s[i])
res.append(' ')
else:
res.append(s[i])
else:
if s[i] == ' ':
continue
if s[i] in punctuation:
continue
else:
res.append(s[i])
print(''.join(res))
|
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, then they should be separated by exactly one space
- there should be no spaces before each punctuation mark
- there should be exactly one space after each punctuation mark
It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.
|
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\n"}, {"input": "a a a a a\r\n", "output": "a a a a a\r\n"}, {"input": "ksdfk sdlfsdf sdf sdf sdf\r\n", "output": "ksdfk sdlfsdf sdf sdf sdf\r\n"}, {"input": "gdv\r\n", "output": "gdv\r\n"}, {"input": "incen q\r\n", "output": "incen q\r\n"}, {"input": "k ? gq dad\r\n", "output": "k? gq dad\r\n"}, {"input": "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb\r\n", "output": "ntomzzut! pousysvfg, rnl mcyytihe hplnqnb\r\n"}, {"input": "mck . gq dauqminf wee bazyzy humnv d pgtvx , vxntxgrkrc rg rwr, uuyweyz l\r\n", "output": "mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l\r\n"}, {"input": "jjcmhwnon taetfgdvc, ysrajurstj ! fryavybwpg hnxbnsron ,txplbmm atw?wkfhn ez mcdn tujsy wrdhw . k i lzwtxcyam fi . nyeu j\r\n", "output": "jjcmhwnon taetfgdvc, ysrajurstj! fryavybwpg hnxbnsron, txplbmm atw? wkfhn ez mcdn tujsy wrdhw. k i lzwtxcyam fi. nyeu j\r\n"}, {"input": "chcf htb flfwkosmda a qygyompixkgz ?rg? hdw f dsvqzs kxvjt ? zj zghgarwihw zgrhr xlwmhv . lycpsmdm iotv . d jhsxoogbr ! ppgrpwcrcl inw usegrtd ?fexma ? mhszrvdoa ,audsrhina epoleuq oaz hqapedl lm\r\n", "output": "chcf htb flfwkosmda a qygyompixkgz? rg? hdw f dsvqzs kxvjt? zj zghgarwihw zgrhr xlwmhv. lycpsmdm iotv. d jhsxoogbr! ppgrpwcrcl inw usegrtd? fexma? mhszrvdoa, audsrhina epoleuq oaz hqapedl lm\r\n"}, {"input": "x\r\n", "output": "x\r\n"}, {"input": "xx\r\n", "output": "xx\r\n"}, {"input": "x x\r\n", "output": "x x\r\n"}, {"input": "x,x\r\n", "output": "x, x\r\n"}, {"input": "x.x\r\n", "output": "x. x\r\n"}, {"input": "x!x\r\n", "output": "x! x\r\n"}, {"input": "x?x\r\n", "output": "x? x\r\n"}, {"input": "a!b\r\n", "output": "a! b\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "physicist ?mathematician.astronomer\r\n", "output": "physicist? mathematician. astronomer\r\n"}, {"input": "dfgdfg ? ddfgdsfg ? dsfgdsfgsdfgdsf ! dsfg . sd dsg sdg ! sdfg\r\n", "output": "dfgdfg? ddfgdsfg? dsfgdsfgsdfgdsf! dsfg. sd dsg sdg! sdfg\r\n"}, {"input": "jojo ! majo , hehehehe? jo . kok\r\n", "output": "jojo! majo, hehehehe? jo. kok\r\n"}, {"input": "adskfj,kjdf?kjadf kj!kajs f\r\n", "output": "adskfj, kjdf? kjadf kj! kajs f\r\n"}, {"input": "a , b\r\n", "output": "a, b\r\n"}, {"input": "ahmed? ahmed ? ahmed ?ahmed\r\n", "output": "ahmed? ahmed? ahmed? ahmed\r\n"}, {"input": "kjdsf, kdjf?kjdf!kj kdjf\r\n", "output": "kjdsf, kdjf? kjdf! kj kdjf\r\n"}, {"input": "italian physicist .mathematician?astronomer\r\n", "output": "italian physicist. mathematician? astronomer\r\n"}, {"input": "galileo galilei was an italian physicist , mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "z zz zz z z! z z aksz zkjsdfz kajfz z !akj , zz a z\r\n", "output": "z zz zz z z! z z aksz zkjsdfz kajfz z! akj, zz a z\r\n"}, {"input": "jojo ! maja . jaooo\r\n", "output": "jojo! maja. jaooo\r\n"}, {"input": "a ! b\r\n", "output": "a! b\r\n"}, {"input": "fff , fff\r\n", "output": "fff, fff\r\n"}, {"input": "a!a?a ! a ? a\r\n", "output": "a! a? a! a? a\r\n"}, {"input": "a!a\r\n", "output": "a! a\r\n"}, {"input": "a!a a ! a ? a ! a , a . a\r\n", "output": "a! a a! a? a! a, a. a\r\n"}, {"input": "casa?mesa, y unos de , los sapotes?l\r\n", "output": "casa? mesa, y unos de, los sapotes? l\r\n"}, {"input": "ff ! ff\r\n", "output": "ff! ff\r\n"}, {"input": "i love evgenia ! x\r\n", "output": "i love evgenia! x\r\n"}, {"input": "galileo galilei was an italian physicist ,mathematician,astronomer?asdf ?asdfff?asdf. asdf.dfd .dfdf ? df d! sdf dsfsa sdf ! asdf ? sdfsdf, dfg a ! b ?a\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer? asdf? asdfff? asdf. asdf. dfd. dfdf? df d! sdf dsfsa sdf! asdf? sdfsdf, dfg a! b? a\r\n"}, {"input": "a , a\r\n", "output": "a, a\r\n"}, {"input": "x, werwr, werwerwr we,rwer ,wer\r\n", "output": "x, werwr, werwerwr we, rwer, wer\r\n"}, {"input": "abcabc, abcabc\r\n", "output": "abcabc, abcabc\r\n"}, {"input": "i love evgenia x! x\r\n", "output": "i love evgenia x! x\r\n"}, {"input": "gg gg,h,h,j,i,jh , jjj , jj ,aadd , jjj jjj\r\n", "output": "gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj\r\n"}, {"input": "mt test ! case\r\n", "output": "mt test! case\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "asdasdasd.asdasdasdasd?asdasdasd!asdasdasd,asdasdasdasd\r\n", "output": "asdasdasd. asdasdasdasd? asdasdasd! asdasdasd, asdasdasdasd\r\n"}, {"input": "x, x, ds ,ertert, ert, et et\r\n", "output": "x, x, ds, ertert, ert, et et\r\n"}, {"input": "anton!love ?yourself\r\n", "output": "anton! love? yourself\r\n"}, {"input": "facepalm ? yes , lol ! yeah\r\n", "output": "facepalm? yes, lol! yeah\r\n"}, {"input": "a ! a\r\n", "output": "a! a\r\n"}, {"input": "adf!kadjf?kajdf,lkdas. kd ! akdjf\r\n", "output": "adf! kadjf? kajdf, lkdas. kd! akdjf\r\n"}, {"input": "a? x\r\n", "output": "a? x\r\n"}, {"input": "read problem carefully ! heh\r\n", "output": "read problem carefully! heh\r\n"}, {"input": "a?a?a?a.a\r\n", "output": "a? a? a? a. a\r\n"}, {"input": "a. v\r\n", "output": "a. v\r\n"}, {"input": "a!a a ! a ? a ! a , a . a aaaaaa ! a ! a. a a .a a.a aa.aa aa . aa aa .aa aa. aa\r\n", "output": "a! a a! a? a! a, a. a aaaaaa! a! a. a a. a a. a aa. aa aa. aa aa. aa aa. aa\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "a!a!a\r\n", "output": "a! a! a\r\n"}, {"input": "a.a.a.a\r\n", "output": "a. a. a. a\r\n"}, {"input": "a, b\r\n", "output": "a, b\r\n"}, {"input": "galileo galilei was an italian physicist, mathematician, astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "a!a!a!a\r\n", "output": "a! a! a! a\r\n"}, {"input": "af ! kadjf ? kjdfkj!kjadkfjz z z a a! ka,kjf\r\n", "output": "af! kadjf? kjdfkj! kjadkfjz z z a a! ka, kjf\r\n"}, {"input": "ab cd,k\r\n", "output": "ab cd, k\r\n"}, {"input": "a!n , to\r\n", "output": "a! n, to\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "u, sux\r\n", "output": "u, sux\r\n"}]
| 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.replace(' .','.')
answer = answer.replace(' !','!')
answer = answer.replace(' ?','?')
print(answer)
| 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):
if str1[i]==' ' and len(str2)>0 and str2[len(str2)-1]==' ':
pass
elif str1[i] in pun and len(str2)>0 and str2[len(str2)-1]==' ':
str2[len(str2)-1] = str1[i]
str2.append(' ')
elif str1[i] in pun:
str2.append(str1[i])
str2.append(' ')
else:
str2.append(str1[i])
i+=1
print(''.join(str2))
if __name__=="__main__":
main()
|
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, then they should be separated by exactly one space
- there should be no spaces before each punctuation mark
- there should be exactly one space after each punctuation mark
It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.
|
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\n"}, {"input": "a a a a a\r\n", "output": "a a a a a\r\n"}, {"input": "ksdfk sdlfsdf sdf sdf sdf\r\n", "output": "ksdfk sdlfsdf sdf sdf sdf\r\n"}, {"input": "gdv\r\n", "output": "gdv\r\n"}, {"input": "incen q\r\n", "output": "incen q\r\n"}, {"input": "k ? gq dad\r\n", "output": "k? gq dad\r\n"}, {"input": "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb\r\n", "output": "ntomzzut! pousysvfg, rnl mcyytihe hplnqnb\r\n"}, {"input": "mck . gq dauqminf wee bazyzy humnv d pgtvx , vxntxgrkrc rg rwr, uuyweyz l\r\n", "output": "mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l\r\n"}, {"input": "jjcmhwnon taetfgdvc, ysrajurstj ! fryavybwpg hnxbnsron ,txplbmm atw?wkfhn ez mcdn tujsy wrdhw . k i lzwtxcyam fi . nyeu j\r\n", "output": "jjcmhwnon taetfgdvc, ysrajurstj! fryavybwpg hnxbnsron, txplbmm atw? wkfhn ez mcdn tujsy wrdhw. k i lzwtxcyam fi. nyeu j\r\n"}, {"input": "chcf htb flfwkosmda a qygyompixkgz ?rg? hdw f dsvqzs kxvjt ? zj zghgarwihw zgrhr xlwmhv . lycpsmdm iotv . d jhsxoogbr ! ppgrpwcrcl inw usegrtd ?fexma ? mhszrvdoa ,audsrhina epoleuq oaz hqapedl lm\r\n", "output": "chcf htb flfwkosmda a qygyompixkgz? rg? hdw f dsvqzs kxvjt? zj zghgarwihw zgrhr xlwmhv. lycpsmdm iotv. d jhsxoogbr! ppgrpwcrcl inw usegrtd? fexma? mhszrvdoa, audsrhina epoleuq oaz hqapedl lm\r\n"}, {"input": "x\r\n", "output": "x\r\n"}, {"input": "xx\r\n", "output": "xx\r\n"}, {"input": "x x\r\n", "output": "x x\r\n"}, {"input": "x,x\r\n", "output": "x, x\r\n"}, {"input": "x.x\r\n", "output": "x. x\r\n"}, {"input": "x!x\r\n", "output": "x! x\r\n"}, {"input": "x?x\r\n", "output": "x? x\r\n"}, {"input": "a!b\r\n", "output": "a! b\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "physicist ?mathematician.astronomer\r\n", "output": "physicist? mathematician. astronomer\r\n"}, {"input": "dfgdfg ? ddfgdsfg ? dsfgdsfgsdfgdsf ! dsfg . sd dsg sdg ! sdfg\r\n", "output": "dfgdfg? ddfgdsfg? dsfgdsfgsdfgdsf! dsfg. sd dsg sdg! sdfg\r\n"}, {"input": "jojo ! majo , hehehehe? jo . kok\r\n", "output": "jojo! majo, hehehehe? jo. kok\r\n"}, {"input": "adskfj,kjdf?kjadf kj!kajs f\r\n", "output": "adskfj, kjdf? kjadf kj! kajs f\r\n"}, {"input": "a , b\r\n", "output": "a, b\r\n"}, {"input": "ahmed? ahmed ? ahmed ?ahmed\r\n", "output": "ahmed? ahmed? ahmed? ahmed\r\n"}, {"input": "kjdsf, kdjf?kjdf!kj kdjf\r\n", "output": "kjdsf, kdjf? kjdf! kj kdjf\r\n"}, {"input": "italian physicist .mathematician?astronomer\r\n", "output": "italian physicist. mathematician? astronomer\r\n"}, {"input": "galileo galilei was an italian physicist , mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "z zz zz z z! z z aksz zkjsdfz kajfz z !akj , zz a z\r\n", "output": "z zz zz z z! z z aksz zkjsdfz kajfz z! akj, zz a z\r\n"}, {"input": "jojo ! maja . jaooo\r\n", "output": "jojo! maja. jaooo\r\n"}, {"input": "a ! b\r\n", "output": "a! b\r\n"}, {"input": "fff , fff\r\n", "output": "fff, fff\r\n"}, {"input": "a!a?a ! a ? a\r\n", "output": "a! a? a! a? a\r\n"}, {"input": "a!a\r\n", "output": "a! a\r\n"}, {"input": "a!a a ! a ? a ! a , a . a\r\n", "output": "a! a a! a? a! a, a. a\r\n"}, {"input": "casa?mesa, y unos de , los sapotes?l\r\n", "output": "casa? mesa, y unos de, los sapotes? l\r\n"}, {"input": "ff ! ff\r\n", "output": "ff! ff\r\n"}, {"input": "i love evgenia ! x\r\n", "output": "i love evgenia! x\r\n"}, {"input": "galileo galilei was an italian physicist ,mathematician,astronomer?asdf ?asdfff?asdf. asdf.dfd .dfdf ? df d! sdf dsfsa sdf ! asdf ? sdfsdf, dfg a ! b ?a\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer? asdf? asdfff? asdf. asdf. dfd. dfdf? df d! sdf dsfsa sdf! asdf? sdfsdf, dfg a! b? a\r\n"}, {"input": "a , a\r\n", "output": "a, a\r\n"}, {"input": "x, werwr, werwerwr we,rwer ,wer\r\n", "output": "x, werwr, werwerwr we, rwer, wer\r\n"}, {"input": "abcabc, abcabc\r\n", "output": "abcabc, abcabc\r\n"}, {"input": "i love evgenia x! x\r\n", "output": "i love evgenia x! x\r\n"}, {"input": "gg gg,h,h,j,i,jh , jjj , jj ,aadd , jjj jjj\r\n", "output": "gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj\r\n"}, {"input": "mt test ! case\r\n", "output": "mt test! case\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "asdasdasd.asdasdasdasd?asdasdasd!asdasdasd,asdasdasdasd\r\n", "output": "asdasdasd. asdasdasdasd? asdasdasd! asdasdasd, asdasdasdasd\r\n"}, {"input": "x, x, ds ,ertert, ert, et et\r\n", "output": "x, x, ds, ertert, ert, et et\r\n"}, {"input": "anton!love ?yourself\r\n", "output": "anton! love? yourself\r\n"}, {"input": "facepalm ? yes , lol ! yeah\r\n", "output": "facepalm? yes, lol! yeah\r\n"}, {"input": "a ! a\r\n", "output": "a! a\r\n"}, {"input": "adf!kadjf?kajdf,lkdas. kd ! akdjf\r\n", "output": "adf! kadjf? kajdf, lkdas. kd! akdjf\r\n"}, {"input": "a? x\r\n", "output": "a? x\r\n"}, {"input": "read problem carefully ! heh\r\n", "output": "read problem carefully! heh\r\n"}, {"input": "a?a?a?a.a\r\n", "output": "a? a? a? a. a\r\n"}, {"input": "a. v\r\n", "output": "a. v\r\n"}, {"input": "a!a a ! a ? a ! a , a . a aaaaaa ! a ! a. a a .a a.a aa.aa aa . aa aa .aa aa. aa\r\n", "output": "a! a a! a? a! a, a. a aaaaaa! a! a. a a. a a. a aa. aa aa. aa aa. aa aa. aa\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "a!a!a\r\n", "output": "a! a! a\r\n"}, {"input": "a.a.a.a\r\n", "output": "a. a. a. a\r\n"}, {"input": "a, b\r\n", "output": "a, b\r\n"}, {"input": "galileo galilei was an italian physicist, mathematician, astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "a!a!a!a\r\n", "output": "a! a! a! a\r\n"}, {"input": "af ! kadjf ? kjdfkj!kjadkfjz z z a a! ka,kjf\r\n", "output": "af! kadjf? kjdfkj! kjadkfjz z z a a! ka, kjf\r\n"}, {"input": "ab cd,k\r\n", "output": "ab cd, k\r\n"}, {"input": "a!n , to\r\n", "output": "a! n, to\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "u, sux\r\n", "output": "u, sux\r\n"}]
| 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[i // j] += 1
print(max(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, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317)
if sn>2:
for y in y:
a[y*y::y+y]=[False]*len(a[y*y::y+y])
for i in range(2,sn+1):
if a[i]:
maxyincage=max(sum(pokecage[i:sn+1:i]),maxyincage)
return(maxyincage)
def main():
n=int(input())
s=list(map(int,input().split()))
print(function1(n,s))
if __name__=='__main__':
main()
|
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, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
|
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 is no larger group with gcd ≠ 1.
|
[{"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 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10\r\n", "output": "38\r\n"}, {"input": "95\r\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50\r\n", "output": "48\r\n"}, {"input": "44\r\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684\r\n", "output": "19\r\n"}, {"input": "35\r\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557\r\n", "output": "20\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n10 7 9 8 3 3 10 7 3 3\r\n", "output": "5\r\n"}, {"input": "9\r\n10 10 6 10 9 1 8 3 5\r\n", "output": "5\r\n"}, {"input": "7\r\n9 4 2 3 3 9 8\r\n", "output": "4\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "6\r\n1623 45906 37856 34727 27156 12598\r\n", "output": "4\r\n"}, {"input": "30\r\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566\r\n", "output": "15\r\n"}, {"input": "23\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16\r\n", "output": "22\r\n"}, {"input": "46\r\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33\r\n", "output": "27\r\n"}, {"input": "43\r\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34\r\n", "output": "21\r\n"}, {"input": "25\r\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 6\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n3 3 3 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n541 541\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n99989 99989\r\n", "output": "2\r\n"}, {"input": "3\r\n3 9 27\r\n", "output": "3\r\n"}, {"input": "2\r\n1009 1009\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "6\r\n2 10 20 5 15 25\r\n", "output": "5\r\n"}, {"input": "3\r\n3 3 6\r\n", "output": "3\r\n"}, {"input": "3\r\n457 457 457\r\n", "output": "3\r\n"}, {"input": "2\r\n34 17\r\n", "output": "2\r\n"}, {"input": "3\r\n12 24 3\r\n", "output": "3\r\n"}, {"input": "10\r\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991\r\n", "output": "10\r\n"}, {"input": "2\r\n1009 2018\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "3\r\n"}, {"input": "7\r\n6 9 12 15 21 27 33\r\n", "output": "7\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n557 557\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 101 101 101\r\n", "output": "3\r\n"}, {"input": "2\r\n122 3721\r\n", "output": "2\r\n"}, {"input": "2\r\n49201 98402\r\n", "output": "2\r\n"}, {"input": "2\r\n88258 44129\r\n", "output": "2\r\n"}, {"input": "2\r\n7919 47514\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n10007 20014 30021\r\n", "output": "3\r\n"}, {"input": "4\r\n10 10 5 5\r\n", "output": "4\r\n"}, {"input": "2\r\n6 9\r\n", "output": "2\r\n"}, {"input": "3\r\n6 12 9\r\n", "output": "3\r\n"}, {"input": "2\r\n14 7\r\n", "output": "2\r\n"}, {"input": "2\r\n199 199\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 49999 99998\r\n", "output": "3\r\n"}, {"input": "5\r\n1009 1009 1009 1009 1009\r\n", "output": "5\r\n"}, {"input": "3\r\n17 17 17\r\n", "output": "3\r\n"}, {"input": "2\r\n503 1509\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 99998 99998\r\n", "output": "3\r\n"}, {"input": "2\r\n28657 28657\r\n", "output": "2\r\n"}, {"input": "3\r\n121 22 33\r\n", "output": "3\r\n"}, {"input": "2\r\n10079 20158\r\n", "output": "2\r\n"}, {"input": "2\r\n6 15\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 3\r\n", "output": "4\r\n"}, {"input": "2\r\n991 1982\r\n", "output": "2\r\n"}, {"input": "3\r\n20362 30543 50905\r\n", "output": "3\r\n"}, {"input": "2\r\n443 886\r\n", "output": "2\r\n"}, {"input": "4\r\n3 7 7 21\r\n", "output": "3\r\n"}, {"input": "3\r\n3 6 9\r\n", "output": "3\r\n"}, {"input": "2\r\n217 31\r\n", "output": "2\r\n"}, {"input": "6\r\n10 10 10 5 5 5\r\n", "output": "6\r\n"}, {"input": "4\r\n49441 25225 9081 4036\r\n", "output": "4\r\n"}, {"input": "2\r\n4 9\r\n", "output": "1\r\n"}, {"input": "2\r\n18 27\r\n", "output": "2\r\n"}, {"input": "2\r\n13 26\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 15\r\n", "output": "4\r\n"}]
| 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 = s.split()
# output_str = ""
# for s in s_list:
# print("s:", s)
# if(s[0] in ".,!?"):
# output_str += s[0]
# output_str += " "
# s = s[1:]
# output_str += s
# output_str += " "
# print(output_str)
| 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, then they should be separated by exactly one space
- there should be no spaces before each punctuation mark
- there should be exactly one space after each punctuation mark
It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.
|
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\n"}, {"input": "a a a a a\r\n", "output": "a a a a a\r\n"}, {"input": "ksdfk sdlfsdf sdf sdf sdf\r\n", "output": "ksdfk sdlfsdf sdf sdf sdf\r\n"}, {"input": "gdv\r\n", "output": "gdv\r\n"}, {"input": "incen q\r\n", "output": "incen q\r\n"}, {"input": "k ? gq dad\r\n", "output": "k? gq dad\r\n"}, {"input": "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb\r\n", "output": "ntomzzut! pousysvfg, rnl mcyytihe hplnqnb\r\n"}, {"input": "mck . gq dauqminf wee bazyzy humnv d pgtvx , vxntxgrkrc rg rwr, uuyweyz l\r\n", "output": "mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l\r\n"}, {"input": "jjcmhwnon taetfgdvc, ysrajurstj ! fryavybwpg hnxbnsron ,txplbmm atw?wkfhn ez mcdn tujsy wrdhw . k i lzwtxcyam fi . nyeu j\r\n", "output": "jjcmhwnon taetfgdvc, ysrajurstj! fryavybwpg hnxbnsron, txplbmm atw? wkfhn ez mcdn tujsy wrdhw. k i lzwtxcyam fi. nyeu j\r\n"}, {"input": "chcf htb flfwkosmda a qygyompixkgz ?rg? hdw f dsvqzs kxvjt ? zj zghgarwihw zgrhr xlwmhv . lycpsmdm iotv . d jhsxoogbr ! ppgrpwcrcl inw usegrtd ?fexma ? mhszrvdoa ,audsrhina epoleuq oaz hqapedl lm\r\n", "output": "chcf htb flfwkosmda a qygyompixkgz? rg? hdw f dsvqzs kxvjt? zj zghgarwihw zgrhr xlwmhv. lycpsmdm iotv. d jhsxoogbr! ppgrpwcrcl inw usegrtd? fexma? mhszrvdoa, audsrhina epoleuq oaz hqapedl lm\r\n"}, {"input": "x\r\n", "output": "x\r\n"}, {"input": "xx\r\n", "output": "xx\r\n"}, {"input": "x x\r\n", "output": "x x\r\n"}, {"input": "x,x\r\n", "output": "x, x\r\n"}, {"input": "x.x\r\n", "output": "x. x\r\n"}, {"input": "x!x\r\n", "output": "x! x\r\n"}, {"input": "x?x\r\n", "output": "x? x\r\n"}, {"input": "a!b\r\n", "output": "a! b\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "physicist ?mathematician.astronomer\r\n", "output": "physicist? mathematician. astronomer\r\n"}, {"input": "dfgdfg ? ddfgdsfg ? dsfgdsfgsdfgdsf ! dsfg . sd dsg sdg ! sdfg\r\n", "output": "dfgdfg? ddfgdsfg? dsfgdsfgsdfgdsf! dsfg. sd dsg sdg! sdfg\r\n"}, {"input": "jojo ! majo , hehehehe? jo . kok\r\n", "output": "jojo! majo, hehehehe? jo. kok\r\n"}, {"input": "adskfj,kjdf?kjadf kj!kajs f\r\n", "output": "adskfj, kjdf? kjadf kj! kajs f\r\n"}, {"input": "a , b\r\n", "output": "a, b\r\n"}, {"input": "ahmed? ahmed ? ahmed ?ahmed\r\n", "output": "ahmed? ahmed? ahmed? ahmed\r\n"}, {"input": "kjdsf, kdjf?kjdf!kj kdjf\r\n", "output": "kjdsf, kdjf? kjdf! kj kdjf\r\n"}, {"input": "italian physicist .mathematician?astronomer\r\n", "output": "italian physicist. mathematician? astronomer\r\n"}, {"input": "galileo galilei was an italian physicist , mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "z zz zz z z! z z aksz zkjsdfz kajfz z !akj , zz a z\r\n", "output": "z zz zz z z! z z aksz zkjsdfz kajfz z! akj, zz a z\r\n"}, {"input": "jojo ! maja . jaooo\r\n", "output": "jojo! maja. jaooo\r\n"}, {"input": "a ! b\r\n", "output": "a! b\r\n"}, {"input": "fff , fff\r\n", "output": "fff, fff\r\n"}, {"input": "a!a?a ! a ? a\r\n", "output": "a! a? a! a? a\r\n"}, {"input": "a!a\r\n", "output": "a! a\r\n"}, {"input": "a!a a ! a ? a ! a , a . a\r\n", "output": "a! a a! a? a! a, a. a\r\n"}, {"input": "casa?mesa, y unos de , los sapotes?l\r\n", "output": "casa? mesa, y unos de, los sapotes? l\r\n"}, {"input": "ff ! ff\r\n", "output": "ff! ff\r\n"}, {"input": "i love evgenia ! x\r\n", "output": "i love evgenia! x\r\n"}, {"input": "galileo galilei was an italian physicist ,mathematician,astronomer?asdf ?asdfff?asdf. asdf.dfd .dfdf ? df d! sdf dsfsa sdf ! asdf ? sdfsdf, dfg a ! b ?a\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer? asdf? asdfff? asdf. asdf. dfd. dfdf? df d! sdf dsfsa sdf! asdf? sdfsdf, dfg a! b? a\r\n"}, {"input": "a , a\r\n", "output": "a, a\r\n"}, {"input": "x, werwr, werwerwr we,rwer ,wer\r\n", "output": "x, werwr, werwerwr we, rwer, wer\r\n"}, {"input": "abcabc, abcabc\r\n", "output": "abcabc, abcabc\r\n"}, {"input": "i love evgenia x! x\r\n", "output": "i love evgenia x! x\r\n"}, {"input": "gg gg,h,h,j,i,jh , jjj , jj ,aadd , jjj jjj\r\n", "output": "gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj\r\n"}, {"input": "mt test ! case\r\n", "output": "mt test! case\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "asdasdasd.asdasdasdasd?asdasdasd!asdasdasd,asdasdasdasd\r\n", "output": "asdasdasd. asdasdasdasd? asdasdasd! asdasdasd, asdasdasdasd\r\n"}, {"input": "x, x, ds ,ertert, ert, et et\r\n", "output": "x, x, ds, ertert, ert, et et\r\n"}, {"input": "anton!love ?yourself\r\n", "output": "anton! love? yourself\r\n"}, {"input": "facepalm ? yes , lol ! yeah\r\n", "output": "facepalm? yes, lol! yeah\r\n"}, {"input": "a ! a\r\n", "output": "a! a\r\n"}, {"input": "adf!kadjf?kajdf,lkdas. kd ! akdjf\r\n", "output": "adf! kadjf? kajdf, lkdas. kd! akdjf\r\n"}, {"input": "a? x\r\n", "output": "a? x\r\n"}, {"input": "read problem carefully ! heh\r\n", "output": "read problem carefully! heh\r\n"}, {"input": "a?a?a?a.a\r\n", "output": "a? a? a? a. a\r\n"}, {"input": "a. v\r\n", "output": "a. v\r\n"}, {"input": "a!a a ! a ? a ! a , a . a aaaaaa ! a ! a. a a .a a.a aa.aa aa . aa aa .aa aa. aa\r\n", "output": "a! a a! a? a! a, a. a aaaaaa! a! a. a a. a a. a aa. aa aa. aa aa. aa aa. aa\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "a!a!a\r\n", "output": "a! a! a\r\n"}, {"input": "a.a.a.a\r\n", "output": "a. a. a. a\r\n"}, {"input": "a, b\r\n", "output": "a, b\r\n"}, {"input": "galileo galilei was an italian physicist, mathematician, astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "a!a!a!a\r\n", "output": "a! a! a! a\r\n"}, {"input": "af ! kadjf ? kjdfkj!kjadkfjz z z a a! ka,kjf\r\n", "output": "af! kadjf? kjdfkj! kjadkfjz z z a a! ka, kjf\r\n"}, {"input": "ab cd,k\r\n", "output": "ab cd, k\r\n"}, {"input": "a!n , to\r\n", "output": "a! n, to\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "u, sux\r\n", "output": "u, sux\r\n"}]
| 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, then they should be separated by exactly one space
- there should be no spaces before each punctuation mark
- there should be exactly one space after each punctuation mark
It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.
|
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\n"}, {"input": "a a a a a\r\n", "output": "a a a a a\r\n"}, {"input": "ksdfk sdlfsdf sdf sdf sdf\r\n", "output": "ksdfk sdlfsdf sdf sdf sdf\r\n"}, {"input": "gdv\r\n", "output": "gdv\r\n"}, {"input": "incen q\r\n", "output": "incen q\r\n"}, {"input": "k ? gq dad\r\n", "output": "k? gq dad\r\n"}, {"input": "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb\r\n", "output": "ntomzzut! pousysvfg, rnl mcyytihe hplnqnb\r\n"}, {"input": "mck . gq dauqminf wee bazyzy humnv d pgtvx , vxntxgrkrc rg rwr, uuyweyz l\r\n", "output": "mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l\r\n"}, {"input": "jjcmhwnon taetfgdvc, ysrajurstj ! fryavybwpg hnxbnsron ,txplbmm atw?wkfhn ez mcdn tujsy wrdhw . k i lzwtxcyam fi . nyeu j\r\n", "output": "jjcmhwnon taetfgdvc, ysrajurstj! fryavybwpg hnxbnsron, txplbmm atw? wkfhn ez mcdn tujsy wrdhw. k i lzwtxcyam fi. nyeu j\r\n"}, {"input": "chcf htb flfwkosmda a qygyompixkgz ?rg? hdw f dsvqzs kxvjt ? zj zghgarwihw zgrhr xlwmhv . lycpsmdm iotv . d jhsxoogbr ! ppgrpwcrcl inw usegrtd ?fexma ? mhszrvdoa ,audsrhina epoleuq oaz hqapedl lm\r\n", "output": "chcf htb flfwkosmda a qygyompixkgz? rg? hdw f dsvqzs kxvjt? zj zghgarwihw zgrhr xlwmhv. lycpsmdm iotv. d jhsxoogbr! ppgrpwcrcl inw usegrtd? fexma? mhszrvdoa, audsrhina epoleuq oaz hqapedl lm\r\n"}, {"input": "x\r\n", "output": "x\r\n"}, {"input": "xx\r\n", "output": "xx\r\n"}, {"input": "x x\r\n", "output": "x x\r\n"}, {"input": "x,x\r\n", "output": "x, x\r\n"}, {"input": "x.x\r\n", "output": "x. x\r\n"}, {"input": "x!x\r\n", "output": "x! x\r\n"}, {"input": "x?x\r\n", "output": "x? x\r\n"}, {"input": "a!b\r\n", "output": "a! b\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "physicist ?mathematician.astronomer\r\n", "output": "physicist? mathematician. astronomer\r\n"}, {"input": "dfgdfg ? ddfgdsfg ? dsfgdsfgsdfgdsf ! dsfg . sd dsg sdg ! sdfg\r\n", "output": "dfgdfg? ddfgdsfg? dsfgdsfgsdfgdsf! dsfg. sd dsg sdg! sdfg\r\n"}, {"input": "jojo ! majo , hehehehe? jo . kok\r\n", "output": "jojo! majo, hehehehe? jo. kok\r\n"}, {"input": "adskfj,kjdf?kjadf kj!kajs f\r\n", "output": "adskfj, kjdf? kjadf kj! kajs f\r\n"}, {"input": "a , b\r\n", "output": "a, b\r\n"}, {"input": "ahmed? ahmed ? ahmed ?ahmed\r\n", "output": "ahmed? ahmed? ahmed? ahmed\r\n"}, {"input": "kjdsf, kdjf?kjdf!kj kdjf\r\n", "output": "kjdsf, kdjf? kjdf! kj kdjf\r\n"}, {"input": "italian physicist .mathematician?astronomer\r\n", "output": "italian physicist. mathematician? astronomer\r\n"}, {"input": "galileo galilei was an italian physicist , mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "z zz zz z z! z z aksz zkjsdfz kajfz z !akj , zz a z\r\n", "output": "z zz zz z z! z z aksz zkjsdfz kajfz z! akj, zz a z\r\n"}, {"input": "jojo ! maja . jaooo\r\n", "output": "jojo! maja. jaooo\r\n"}, {"input": "a ! b\r\n", "output": "a! b\r\n"}, {"input": "fff , fff\r\n", "output": "fff, fff\r\n"}, {"input": "a!a?a ! a ? a\r\n", "output": "a! a? a! a? a\r\n"}, {"input": "a!a\r\n", "output": "a! a\r\n"}, {"input": "a!a a ! a ? a ! a , a . a\r\n", "output": "a! a a! a? a! a, a. a\r\n"}, {"input": "casa?mesa, y unos de , los sapotes?l\r\n", "output": "casa? mesa, y unos de, los sapotes? l\r\n"}, {"input": "ff ! ff\r\n", "output": "ff! ff\r\n"}, {"input": "i love evgenia ! x\r\n", "output": "i love evgenia! x\r\n"}, {"input": "galileo galilei was an italian physicist ,mathematician,astronomer?asdf ?asdfff?asdf. asdf.dfd .dfdf ? df d! sdf dsfsa sdf ! asdf ? sdfsdf, dfg a ! b ?a\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer? asdf? asdfff? asdf. asdf. dfd. dfdf? df d! sdf dsfsa sdf! asdf? sdfsdf, dfg a! b? a\r\n"}, {"input": "a , a\r\n", "output": "a, a\r\n"}, {"input": "x, werwr, werwerwr we,rwer ,wer\r\n", "output": "x, werwr, werwerwr we, rwer, wer\r\n"}, {"input": "abcabc, abcabc\r\n", "output": "abcabc, abcabc\r\n"}, {"input": "i love evgenia x! x\r\n", "output": "i love evgenia x! x\r\n"}, {"input": "gg gg,h,h,j,i,jh , jjj , jj ,aadd , jjj jjj\r\n", "output": "gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj\r\n"}, {"input": "mt test ! case\r\n", "output": "mt test! case\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "asdasdasd.asdasdasdasd?asdasdasd!asdasdasd,asdasdasdasd\r\n", "output": "asdasdasd. asdasdasdasd? asdasdasd! asdasdasd, asdasdasdasd\r\n"}, {"input": "x, x, ds ,ertert, ert, et et\r\n", "output": "x, x, ds, ertert, ert, et et\r\n"}, {"input": "anton!love ?yourself\r\n", "output": "anton! love? yourself\r\n"}, {"input": "facepalm ? yes , lol ! yeah\r\n", "output": "facepalm? yes, lol! yeah\r\n"}, {"input": "a ! a\r\n", "output": "a! a\r\n"}, {"input": "adf!kadjf?kajdf,lkdas. kd ! akdjf\r\n", "output": "adf! kadjf? kajdf, lkdas. kd! akdjf\r\n"}, {"input": "a? x\r\n", "output": "a? x\r\n"}, {"input": "read problem carefully ! heh\r\n", "output": "read problem carefully! heh\r\n"}, {"input": "a?a?a?a.a\r\n", "output": "a? a? a? a. a\r\n"}, {"input": "a. v\r\n", "output": "a. v\r\n"}, {"input": "a!a a ! a ? a ! a , a . a aaaaaa ! a ! a. a a .a a.a aa.aa aa . aa aa .aa aa. aa\r\n", "output": "a! a a! a? a! a, a. a aaaaaa! a! a. a a. a a. a aa. aa aa. aa aa. aa aa. aa\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "a!a!a\r\n", "output": "a! a! a\r\n"}, {"input": "a.a.a.a\r\n", "output": "a. a. a. a\r\n"}, {"input": "a, b\r\n", "output": "a, b\r\n"}, {"input": "galileo galilei was an italian physicist, mathematician, astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "a!a!a!a\r\n", "output": "a! a! a! a\r\n"}, {"input": "af ! kadjf ? kjdfkj!kjadkfjz z z a a! ka,kjf\r\n", "output": "af! kadjf? kjdfkj! kjadkfjz z z a a! ka, kjf\r\n"}, {"input": "ab cd,k\r\n", "output": "ab cd, k\r\n"}, {"input": "a!n , to\r\n", "output": "a! n, to\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "u, sux\r\n", "output": "u, sux\r\n"}]
| 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]+' '
com=True
continue
if com and s[i]==' ':
continue
else :
com=False
r=r+s[i]
print(r)
|
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, then they should be separated by exactly one space
- there should be no spaces before each punctuation mark
- there should be exactly one space after each punctuation mark
It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.
|
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\n"}, {"input": "a a a a a\r\n", "output": "a a a a a\r\n"}, {"input": "ksdfk sdlfsdf sdf sdf sdf\r\n", "output": "ksdfk sdlfsdf sdf sdf sdf\r\n"}, {"input": "gdv\r\n", "output": "gdv\r\n"}, {"input": "incen q\r\n", "output": "incen q\r\n"}, {"input": "k ? gq dad\r\n", "output": "k? gq dad\r\n"}, {"input": "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb\r\n", "output": "ntomzzut! pousysvfg, rnl mcyytihe hplnqnb\r\n"}, {"input": "mck . gq dauqminf wee bazyzy humnv d pgtvx , vxntxgrkrc rg rwr, uuyweyz l\r\n", "output": "mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l\r\n"}, {"input": "jjcmhwnon taetfgdvc, ysrajurstj ! fryavybwpg hnxbnsron ,txplbmm atw?wkfhn ez mcdn tujsy wrdhw . k i lzwtxcyam fi . nyeu j\r\n", "output": "jjcmhwnon taetfgdvc, ysrajurstj! fryavybwpg hnxbnsron, txplbmm atw? wkfhn ez mcdn tujsy wrdhw. k i lzwtxcyam fi. nyeu j\r\n"}, {"input": "chcf htb flfwkosmda a qygyompixkgz ?rg? hdw f dsvqzs kxvjt ? zj zghgarwihw zgrhr xlwmhv . lycpsmdm iotv . d jhsxoogbr ! ppgrpwcrcl inw usegrtd ?fexma ? mhszrvdoa ,audsrhina epoleuq oaz hqapedl lm\r\n", "output": "chcf htb flfwkosmda a qygyompixkgz? rg? hdw f dsvqzs kxvjt? zj zghgarwihw zgrhr xlwmhv. lycpsmdm iotv. d jhsxoogbr! ppgrpwcrcl inw usegrtd? fexma? mhszrvdoa, audsrhina epoleuq oaz hqapedl lm\r\n"}, {"input": "x\r\n", "output": "x\r\n"}, {"input": "xx\r\n", "output": "xx\r\n"}, {"input": "x x\r\n", "output": "x x\r\n"}, {"input": "x,x\r\n", "output": "x, x\r\n"}, {"input": "x.x\r\n", "output": "x. x\r\n"}, {"input": "x!x\r\n", "output": "x! x\r\n"}, {"input": "x?x\r\n", "output": "x? x\r\n"}, {"input": "a!b\r\n", "output": "a! b\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "physicist ?mathematician.astronomer\r\n", "output": "physicist? mathematician. astronomer\r\n"}, {"input": "dfgdfg ? ddfgdsfg ? dsfgdsfgsdfgdsf ! dsfg . sd dsg sdg ! sdfg\r\n", "output": "dfgdfg? ddfgdsfg? dsfgdsfgsdfgdsf! dsfg. sd dsg sdg! sdfg\r\n"}, {"input": "jojo ! majo , hehehehe? jo . kok\r\n", "output": "jojo! majo, hehehehe? jo. kok\r\n"}, {"input": "adskfj,kjdf?kjadf kj!kajs f\r\n", "output": "adskfj, kjdf? kjadf kj! kajs f\r\n"}, {"input": "a , b\r\n", "output": "a, b\r\n"}, {"input": "ahmed? ahmed ? ahmed ?ahmed\r\n", "output": "ahmed? ahmed? ahmed? ahmed\r\n"}, {"input": "kjdsf, kdjf?kjdf!kj kdjf\r\n", "output": "kjdsf, kdjf? kjdf! kj kdjf\r\n"}, {"input": "italian physicist .mathematician?astronomer\r\n", "output": "italian physicist. mathematician? astronomer\r\n"}, {"input": "galileo galilei was an italian physicist , mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "z zz zz z z! z z aksz zkjsdfz kajfz z !akj , zz a z\r\n", "output": "z zz zz z z! z z aksz zkjsdfz kajfz z! akj, zz a z\r\n"}, {"input": "jojo ! maja . jaooo\r\n", "output": "jojo! maja. jaooo\r\n"}, {"input": "a ! b\r\n", "output": "a! b\r\n"}, {"input": "fff , fff\r\n", "output": "fff, fff\r\n"}, {"input": "a!a?a ! a ? a\r\n", "output": "a! a? a! a? a\r\n"}, {"input": "a!a\r\n", "output": "a! a\r\n"}, {"input": "a!a a ! a ? a ! a , a . a\r\n", "output": "a! a a! a? a! a, a. a\r\n"}, {"input": "casa?mesa, y unos de , los sapotes?l\r\n", "output": "casa? mesa, y unos de, los sapotes? l\r\n"}, {"input": "ff ! ff\r\n", "output": "ff! ff\r\n"}, {"input": "i love evgenia ! x\r\n", "output": "i love evgenia! x\r\n"}, {"input": "galileo galilei was an italian physicist ,mathematician,astronomer?asdf ?asdfff?asdf. asdf.dfd .dfdf ? df d! sdf dsfsa sdf ! asdf ? sdfsdf, dfg a ! b ?a\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer? asdf? asdfff? asdf. asdf. dfd. dfdf? df d! sdf dsfsa sdf! asdf? sdfsdf, dfg a! b? a\r\n"}, {"input": "a , a\r\n", "output": "a, a\r\n"}, {"input": "x, werwr, werwerwr we,rwer ,wer\r\n", "output": "x, werwr, werwerwr we, rwer, wer\r\n"}, {"input": "abcabc, abcabc\r\n", "output": "abcabc, abcabc\r\n"}, {"input": "i love evgenia x! x\r\n", "output": "i love evgenia x! x\r\n"}, {"input": "gg gg,h,h,j,i,jh , jjj , jj ,aadd , jjj jjj\r\n", "output": "gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj\r\n"}, {"input": "mt test ! case\r\n", "output": "mt test! case\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "asdasdasd.asdasdasdasd?asdasdasd!asdasdasd,asdasdasdasd\r\n", "output": "asdasdasd. asdasdasdasd? asdasdasd! asdasdasd, asdasdasdasd\r\n"}, {"input": "x, x, ds ,ertert, ert, et et\r\n", "output": "x, x, ds, ertert, ert, et et\r\n"}, {"input": "anton!love ?yourself\r\n", "output": "anton! love? yourself\r\n"}, {"input": "facepalm ? yes , lol ! yeah\r\n", "output": "facepalm? yes, lol! yeah\r\n"}, {"input": "a ! a\r\n", "output": "a! a\r\n"}, {"input": "adf!kadjf?kajdf,lkdas. kd ! akdjf\r\n", "output": "adf! kadjf? kajdf, lkdas. kd! akdjf\r\n"}, {"input": "a? x\r\n", "output": "a? x\r\n"}, {"input": "read problem carefully ! heh\r\n", "output": "read problem carefully! heh\r\n"}, {"input": "a?a?a?a.a\r\n", "output": "a? a? a? a. a\r\n"}, {"input": "a. v\r\n", "output": "a. v\r\n"}, {"input": "a!a a ! a ? a ! a , a . a aaaaaa ! a ! a. a a .a a.a aa.aa aa . aa aa .aa aa. aa\r\n", "output": "a! a a! a? a! a, a. a aaaaaa! a! a. a a. a a. a aa. aa aa. aa aa. aa aa. aa\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "a!a!a\r\n", "output": "a! a! a\r\n"}, {"input": "a.a.a.a\r\n", "output": "a. a. a. a\r\n"}, {"input": "a, b\r\n", "output": "a, b\r\n"}, {"input": "galileo galilei was an italian physicist, mathematician, astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "a!a!a!a\r\n", "output": "a! a! a! a\r\n"}, {"input": "af ! kadjf ? kjdfkj!kjadkfjz z z a a! ka,kjf\r\n", "output": "af! kadjf? kjdfkj! kjadkfjz z z a a! ka, kjf\r\n"}, {"input": "ab cd,k\r\n", "output": "ab cd, k\r\n"}, {"input": "a!n , to\r\n", "output": "a! n, to\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "u, sux\r\n", "output": "u, sux\r\n"}]
| 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
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
ii = lambda : int(input())
si = lambda : input()
mi = lambda : map(int,input().strip().split(" "))
msi = lambda : map(str,input().strip().split(" "))
li = lambda : list(mi())
lsi = lambda : list(msi())
out = []
export = lambda : sys.stdout.write('\n'.join(map(str, out)))
p = lambda x : out.append(x)
pp = lambda array : p(' '.join(map(str,array)))
def main() -> None:
# 2023-10-21 22:55:36
n = ii()
l = li()
th = int(1e5) + 1
arr = [0] * th
store = []
for i in l: arr[i]+=1
for i in range(2,th):
s = 0
for j in range(i,th,i):
s += arr[j]
store.append(s)
p(max(max(store),1))
try: exec('from hq import *\nexec(cc)')
except (FileNotFoundError, ModuleNotFoundError): main(); export()
|
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, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
|
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 is no larger group with gcd ≠ 1.
|
[{"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 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10\r\n", "output": "38\r\n"}, {"input": "95\r\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50\r\n", "output": "48\r\n"}, {"input": "44\r\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684\r\n", "output": "19\r\n"}, {"input": "35\r\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557\r\n", "output": "20\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n10 7 9 8 3 3 10 7 3 3\r\n", "output": "5\r\n"}, {"input": "9\r\n10 10 6 10 9 1 8 3 5\r\n", "output": "5\r\n"}, {"input": "7\r\n9 4 2 3 3 9 8\r\n", "output": "4\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "6\r\n1623 45906 37856 34727 27156 12598\r\n", "output": "4\r\n"}, {"input": "30\r\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566\r\n", "output": "15\r\n"}, {"input": "23\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16\r\n", "output": "22\r\n"}, {"input": "46\r\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33\r\n", "output": "27\r\n"}, {"input": "43\r\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34\r\n", "output": "21\r\n"}, {"input": "25\r\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 6\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n3 3 3 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n541 541\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n99989 99989\r\n", "output": "2\r\n"}, {"input": "3\r\n3 9 27\r\n", "output": "3\r\n"}, {"input": "2\r\n1009 1009\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "6\r\n2 10 20 5 15 25\r\n", "output": "5\r\n"}, {"input": "3\r\n3 3 6\r\n", "output": "3\r\n"}, {"input": "3\r\n457 457 457\r\n", "output": "3\r\n"}, {"input": "2\r\n34 17\r\n", "output": "2\r\n"}, {"input": "3\r\n12 24 3\r\n", "output": "3\r\n"}, {"input": "10\r\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991\r\n", "output": "10\r\n"}, {"input": "2\r\n1009 2018\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "3\r\n"}, {"input": "7\r\n6 9 12 15 21 27 33\r\n", "output": "7\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n557 557\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 101 101 101\r\n", "output": "3\r\n"}, {"input": "2\r\n122 3721\r\n", "output": "2\r\n"}, {"input": "2\r\n49201 98402\r\n", "output": "2\r\n"}, {"input": "2\r\n88258 44129\r\n", "output": "2\r\n"}, {"input": "2\r\n7919 47514\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n10007 20014 30021\r\n", "output": "3\r\n"}, {"input": "4\r\n10 10 5 5\r\n", "output": "4\r\n"}, {"input": "2\r\n6 9\r\n", "output": "2\r\n"}, {"input": "3\r\n6 12 9\r\n", "output": "3\r\n"}, {"input": "2\r\n14 7\r\n", "output": "2\r\n"}, {"input": "2\r\n199 199\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 49999 99998\r\n", "output": "3\r\n"}, {"input": "5\r\n1009 1009 1009 1009 1009\r\n", "output": "5\r\n"}, {"input": "3\r\n17 17 17\r\n", "output": "3\r\n"}, {"input": "2\r\n503 1509\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 99998 99998\r\n", "output": "3\r\n"}, {"input": "2\r\n28657 28657\r\n", "output": "2\r\n"}, {"input": "3\r\n121 22 33\r\n", "output": "3\r\n"}, {"input": "2\r\n10079 20158\r\n", "output": "2\r\n"}, {"input": "2\r\n6 15\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 3\r\n", "output": "4\r\n"}, {"input": "2\r\n991 1982\r\n", "output": "2\r\n"}, {"input": "3\r\n20362 30543 50905\r\n", "output": "3\r\n"}, {"input": "2\r\n443 886\r\n", "output": "2\r\n"}, {"input": "4\r\n3 7 7 21\r\n", "output": "3\r\n"}, {"input": "3\r\n3 6 9\r\n", "output": "3\r\n"}, {"input": "2\r\n217 31\r\n", "output": "2\r\n"}, {"input": "6\r\n10 10 10 5 5 5\r\n", "output": "6\r\n"}, {"input": "4\r\n49441 25225 9081 4036\r\n", "output": "4\r\n"}, {"input": "2\r\n4 9\r\n", "output": "1\r\n"}, {"input": "2\r\n18 27\r\n", "output": "2\r\n"}, {"input": "2\r\n13 26\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 15\r\n", "output": "4\r\n"}]
| 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, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
|
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 is no larger group with gcd ≠ 1.
|
[{"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 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10\r\n", "output": "38\r\n"}, {"input": "95\r\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50\r\n", "output": "48\r\n"}, {"input": "44\r\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684\r\n", "output": "19\r\n"}, {"input": "35\r\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557\r\n", "output": "20\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n10 7 9 8 3 3 10 7 3 3\r\n", "output": "5\r\n"}, {"input": "9\r\n10 10 6 10 9 1 8 3 5\r\n", "output": "5\r\n"}, {"input": "7\r\n9 4 2 3 3 9 8\r\n", "output": "4\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "6\r\n1623 45906 37856 34727 27156 12598\r\n", "output": "4\r\n"}, {"input": "30\r\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566\r\n", "output": "15\r\n"}, {"input": "23\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16\r\n", "output": "22\r\n"}, {"input": "46\r\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33\r\n", "output": "27\r\n"}, {"input": "43\r\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34\r\n", "output": "21\r\n"}, {"input": "25\r\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 6\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n3 3 3 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n541 541\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n99989 99989\r\n", "output": "2\r\n"}, {"input": "3\r\n3 9 27\r\n", "output": "3\r\n"}, {"input": "2\r\n1009 1009\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "6\r\n2 10 20 5 15 25\r\n", "output": "5\r\n"}, {"input": "3\r\n3 3 6\r\n", "output": "3\r\n"}, {"input": "3\r\n457 457 457\r\n", "output": "3\r\n"}, {"input": "2\r\n34 17\r\n", "output": "2\r\n"}, {"input": "3\r\n12 24 3\r\n", "output": "3\r\n"}, {"input": "10\r\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991\r\n", "output": "10\r\n"}, {"input": "2\r\n1009 2018\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "3\r\n"}, {"input": "7\r\n6 9 12 15 21 27 33\r\n", "output": "7\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n557 557\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 101 101 101\r\n", "output": "3\r\n"}, {"input": "2\r\n122 3721\r\n", "output": "2\r\n"}, {"input": "2\r\n49201 98402\r\n", "output": "2\r\n"}, {"input": "2\r\n88258 44129\r\n", "output": "2\r\n"}, {"input": "2\r\n7919 47514\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n10007 20014 30021\r\n", "output": "3\r\n"}, {"input": "4\r\n10 10 5 5\r\n", "output": "4\r\n"}, {"input": "2\r\n6 9\r\n", "output": "2\r\n"}, {"input": "3\r\n6 12 9\r\n", "output": "3\r\n"}, {"input": "2\r\n14 7\r\n", "output": "2\r\n"}, {"input": "2\r\n199 199\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 49999 99998\r\n", "output": "3\r\n"}, {"input": "5\r\n1009 1009 1009 1009 1009\r\n", "output": "5\r\n"}, {"input": "3\r\n17 17 17\r\n", "output": "3\r\n"}, {"input": "2\r\n503 1509\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 99998 99998\r\n", "output": "3\r\n"}, {"input": "2\r\n28657 28657\r\n", "output": "2\r\n"}, {"input": "3\r\n121 22 33\r\n", "output": "3\r\n"}, {"input": "2\r\n10079 20158\r\n", "output": "2\r\n"}, {"input": "2\r\n6 15\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 3\r\n", "output": "4\r\n"}, {"input": "2\r\n991 1982\r\n", "output": "2\r\n"}, {"input": "3\r\n20362 30543 50905\r\n", "output": "3\r\n"}, {"input": "2\r\n443 886\r\n", "output": "2\r\n"}, {"input": "4\r\n3 7 7 21\r\n", "output": "3\r\n"}, {"input": "3\r\n3 6 9\r\n", "output": "3\r\n"}, {"input": "2\r\n217 31\r\n", "output": "2\r\n"}, {"input": "6\r\n10 10 10 5 5 5\r\n", "output": "6\r\n"}, {"input": "4\r\n49441 25225 9081 4036\r\n", "output": "4\r\n"}, {"input": "2\r\n4 9\r\n", "output": "1\r\n"}, {"input": "2\r\n18 27\r\n", "output": "2\r\n"}, {"input": "2\r\n13 26\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 15\r\n", "output": "4\r\n"}]
| 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:
factors.add(i)
factors.add(strength // i)
factors.add(strength)
for factor in factors:
prime_factors[factor] += 1
max_count = max(prime_factors)
return max_count if max_count > 1 else 1
n = int(input())
strengths = list(map(int, input().split()))
print(max_pokemon_count(n, strengths))
| 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):
primes[j] = False
size += valueToCount.get(j, 0)
result = max(result, size)
return result
if __name__ == "__main__":
n = int(input())
s = list(map(int, input().split()))
print(solve(s))
|
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, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
|
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 is no larger group with gcd ≠ 1.
|
[{"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 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10\r\n", "output": "38\r\n"}, {"input": "95\r\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50\r\n", "output": "48\r\n"}, {"input": "44\r\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684\r\n", "output": "19\r\n"}, {"input": "35\r\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557\r\n", "output": "20\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n10 7 9 8 3 3 10 7 3 3\r\n", "output": "5\r\n"}, {"input": "9\r\n10 10 6 10 9 1 8 3 5\r\n", "output": "5\r\n"}, {"input": "7\r\n9 4 2 3 3 9 8\r\n", "output": "4\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "6\r\n1623 45906 37856 34727 27156 12598\r\n", "output": "4\r\n"}, {"input": "30\r\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566\r\n", "output": "15\r\n"}, {"input": "23\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16\r\n", "output": "22\r\n"}, {"input": "46\r\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33\r\n", "output": "27\r\n"}, {"input": "43\r\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34\r\n", "output": "21\r\n"}, {"input": "25\r\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 6\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n3 3 3 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n541 541\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n99989 99989\r\n", "output": "2\r\n"}, {"input": "3\r\n3 9 27\r\n", "output": "3\r\n"}, {"input": "2\r\n1009 1009\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "6\r\n2 10 20 5 15 25\r\n", "output": "5\r\n"}, {"input": "3\r\n3 3 6\r\n", "output": "3\r\n"}, {"input": "3\r\n457 457 457\r\n", "output": "3\r\n"}, {"input": "2\r\n34 17\r\n", "output": "2\r\n"}, {"input": "3\r\n12 24 3\r\n", "output": "3\r\n"}, {"input": "10\r\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991\r\n", "output": "10\r\n"}, {"input": "2\r\n1009 2018\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "3\r\n"}, {"input": "7\r\n6 9 12 15 21 27 33\r\n", "output": "7\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n557 557\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 101 101 101\r\n", "output": "3\r\n"}, {"input": "2\r\n122 3721\r\n", "output": "2\r\n"}, {"input": "2\r\n49201 98402\r\n", "output": "2\r\n"}, {"input": "2\r\n88258 44129\r\n", "output": "2\r\n"}, {"input": "2\r\n7919 47514\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n10007 20014 30021\r\n", "output": "3\r\n"}, {"input": "4\r\n10 10 5 5\r\n", "output": "4\r\n"}, {"input": "2\r\n6 9\r\n", "output": "2\r\n"}, {"input": "3\r\n6 12 9\r\n", "output": "3\r\n"}, {"input": "2\r\n14 7\r\n", "output": "2\r\n"}, {"input": "2\r\n199 199\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 49999 99998\r\n", "output": "3\r\n"}, {"input": "5\r\n1009 1009 1009 1009 1009\r\n", "output": "5\r\n"}, {"input": "3\r\n17 17 17\r\n", "output": "3\r\n"}, {"input": "2\r\n503 1509\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 99998 99998\r\n", "output": "3\r\n"}, {"input": "2\r\n28657 28657\r\n", "output": "2\r\n"}, {"input": "3\r\n121 22 33\r\n", "output": "3\r\n"}, {"input": "2\r\n10079 20158\r\n", "output": "2\r\n"}, {"input": "2\r\n6 15\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 3\r\n", "output": "4\r\n"}, {"input": "2\r\n991 1982\r\n", "output": "2\r\n"}, {"input": "3\r\n20362 30543 50905\r\n", "output": "3\r\n"}, {"input": "2\r\n443 886\r\n", "output": "2\r\n"}, {"input": "4\r\n3 7 7 21\r\n", "output": "3\r\n"}, {"input": "3\r\n3 6 9\r\n", "output": "3\r\n"}, {"input": "2\r\n217 31\r\n", "output": "2\r\n"}, {"input": "6\r\n10 10 10 5 5 5\r\n", "output": "6\r\n"}, {"input": "4\r\n49441 25225 9081 4036\r\n", "output": "4\r\n"}, {"input": "2\r\n4 9\r\n", "output": "1\r\n"}, {"input": "2\r\n18 27\r\n", "output": "2\r\n"}, {"input": "2\r\n13 26\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 15\r\n", "output": "4\r\n"}]
| 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]-flag<=d-2 and x[flag2+1]-x[flag2]<s+2:
flag2+=1
if flag2>=q-1:
return [0,[]]
if x[flag2]-flag>d-2 or x[flag2+1]-x[flag2]<s+2:
return [0,[]]
flag1=flag2+1
flag2=flag1
flag=x[flag1]
hran+=[flag1]
return [1,hran]
a=g(n,s,m,d,x)
if a[0]==0:
print("IMPOSSIBLE")
else:
e=a[1]
print("RUN",x[e[0]]-1)
i=1
le=len(e)
while i<le:
print("JUMP",x[e[i]-1]-x[e[i-1]]+2)
if x[e[i]]-x[e[i]-1]-2!=0:
print("RUN",x[e[i]]-x[e[i]-1]-2)
i+=1
| 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+=['JUMP '+str(t-r)]
l=t;cur+=1
print('\n'.join(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 length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x1, x2, ..., xn. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
|
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 sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
|
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 for "X" more meters;
- print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
| 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\nJUMP 3\r\nRUN 4\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "10 1000000000 8905990 20319560\r\n233244997 997992814 242452779 497363176 572234096 126615858 886769539 662035052 989086824 716655858\r\n", "output": "RUN 126615857\r\nJUMP 2\r\nRUN 106629137\r\nJUMP 2\r\nRUN 9207780\r\nJUMP 2\r\nRUN 254910395\r\nJUMP 2\r\nRUN 74870918\r\nJUMP 2\r\nRUN 89800954\r\nJUMP 2\r\nRUN 54620804\r\nJUMP 2\r\nRUN 170113679\r\nJUMP 2\r\nRUN 102317283\r\nJUMP 8905992\r\nRUN 2007185\r\n"}, {"input": "100 1000 1 4\r\n228 420 360 642 442 551 940 343 24 83 928 110 663 548 704 461 942 799 283 746 371 204 435 209 986 489 918 526 496 321 233 643 208 717 806 18 291 431 521 631 3 450 711 602 401 60 680 930 625 891 161 279 510 529 546 338 473 925 446 786 384 952 260 649 865 916 789 71 103 997 484 89 408 129 953 670 568 55 287 511 369 225 950 539 652 567 730 499 687 90 779 848 801 606 82 853 967 776 951 329\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "100 600 1 4\r\n9 536 518 59 229 377 72 203 81 309 304 321 55 439 287 505 3 410 582 351 440 568 584 259 22 415 348 147 404 277 477 323 537 75 548 324 338 198 145 182 271 496 256 329 592 132 291 222 115 587 54 158 154 103 356 15 36 76 402 27 223 551 267 527 51 34 417 573 479 398 425 71 485 20 262 566 467 131 524 352 330 541 146 53 322 436 366 86 88 272 96 456 388 319 149 470 129 162 353 346\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 2 1 5\r\n1\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 3 1 2\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\n"}, {"input": "1 5 1 2\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\nRUN 2\r\n"}, {"input": "100 1000 1 5\r\n204 233 384 776 450 649 473 717 55 90 208 951 499 551 916 18 539 103 420 521 730 779 360 546 746 953 484 82 110 789 161 950 71 806 928 652 510 287 997 967 329 786 643 431 321 663 279 291 799 986 848 680 89 225 918 801 567 369 687 209 602 401 952 930 442 853 606 338 129 631 228 24 3 925 940 711 496 625 548 446 891 283 60 83 529 511 568 704 371 343 670 435 461 865 408 642 260 526 489 942\r\n", "output": "RUN 2\nJUMP 2\nRUN 13\nJUMP 2\nRUN 4\nJUMP 2\nRUN 29\nJUMP 2\nRUN 3\nJUMP 2\nRUN 9\nJUMP 2\nRUN 9\nJUMP 3\nRUN 4\nJUMP 3\nRUN 11\nJUMP 2\nRUN 5\nJUMP 2\nRUN 17\nJUMP 2\nRUN 30\nJUMP 2\nRUN 41\nJUMP 2\nRUN 2\nJUMP 3\nRUN 14\nJUMP 2\nRUN 1\nJUMP 2\nRUN 3\nJUMP 2\nRUN 25\nJUMP 2\nRUN 17\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 28\nJUMP 2\nRUN 6\nJUMP 2\nRUN 7\nJUMP 2\nRUN 3\nJUMP 2\nRUN 15\nJUMP 2\nRUN 7\nJUMP 4\nRUN 11\nJUMP 2\nRUN 15\nJUMP 2\nRUN 5\nJUMP 2\nRUN 10\nJUMP 2\nRUN 9\nJUMP 2\nRUN 2\nJUMP 2\nRUN 5\nJUMP 2\nRUN 2\nJUMP 2\nRUN 2\nJUMP 2\nRUN 9\nJUMP 2\nRUN 10\nJUMP 2\nRUN 9\nJUMP 2\nRUN 3\nJUMP 2\nRUN 5\nJUMP 2\nRUN 1\nJUMP 2\nRUN 9\nJUMP 3\nRUN 8\nJUMP 2\nRUN 3\nJUMP 2\nRUN 1\nJUMP 2\nRUN 8\nJUMP 2\nRUN 5\nJUMP 4\nRUN 1\nJUMP 2\nRUN 14\nJUMP 3\nRUN 32\nJUMP 2\nRUN 2\nJUMP 2\nRUN 17\nJUMP 2\nRUN 4\nJUMP 2\nRUN 9\nJUMP 3\nRUN 4\nJUMP 2\nRUN 1\nJUMP 2\nRUN 9\nJUMP 2\nRUN 5\nJUMP 2\nRUN 8\nJUMP 2\nRUN 5\nJUMP 2\nRUN 15\nJUMP 2\nRUN 5\nJUMP 2\nRUN 4\nJUMP 2\nRUN 11\nJUMP 2\nRUN 14\nJUMP 2\nRUN 28\nJUMP 2\nRUN 1\nJUMP 2\nRUN 5\nJUMP 2\nRUN 1\nJUMP 2\nRUN 8\nJUMP 4\nRUN 3\nJUMP 2\nRUN 40\nJUMP 2\nRUN 3\nJUMP 2\nRUN 10\nJUMP 2\nRUN 24\nJUMP 2\nRUN 23\nJUMP 4\nRUN 5\nJUMP 2\nRUN 1\nJUMP 4\nRUN 8\nJUMP 4\nRUN 6\nJUMP 5\nRUN 12\nJUMP 2\nRUN 17\nJUMP 2\nRUN 9\nJUMP 2\nRUN 2\n"}, {"input": "1 1000000000 1000000000 2\r\n999999999\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 100 1 1\r\n4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 1000000000 1 1000000000\r\n2\r\n", "output": "RUN 1\r\nJUMP 2\r\nRUN 999999997\r\n"}, {"input": "3 12000 2000 3000\r\n3000 9002 7001\r\n", "output": "RUN 2999\r\nJUMP 2\r\nRUN 3999\r\nJUMP 2003\r\nRUN 2997\r\n"}, {"input": "4 30000 5000 6000\r\n6000 16000 15000 21001\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 12000 2000 245\r\n3000 9003 7001\r\n", "output": "RUN 2999\r\nJUMP 2\r\nRUN 3999\r\nJUMP 2\r\nRUN 2000\r\nJUMP 2\r\nRUN 2996\r\n"}, {"input": "4 30000 5000 1654\r\n6000 16000 14999 21002\r\n", "output": "RUN 5999\r\nJUMP 2\r\nRUN 8997\r\nJUMP 1003\r\nRUN 5000\r\nJUMP 2\r\nRUN 8997\r\n"}, {"input": "4 10000 500 500\r\n700 600 1099 2000\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 20000 4000 3502\r\n5000 8500 15000\r\n", "output": "RUN 4999\r\nJUMP 3502\r\nRUN 6498\r\nJUMP 2\r\nRUN 4999\r\n"}, {"input": "4 10000 500 500\r\n700 601 1099 2000\r\n", "output": "RUN 600\r\nJUMP 500\r\nRUN 899\r\nJUMP 2\r\nRUN 7999\r\n"}, {"input": "3 20000 4000 3502\r\n5000 8501 15000\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 10 1 2\r\n9\r\n", "output": "RUN 8\r\nJUMP 2\r\n"}, {"input": "1 10 2 9\r\n5\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 4\r\n"}, {"input": "1 9 6 4\r\n4\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 10 7 4\r\n5\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 14 8 8\r\n5 9\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 23 12 8\r\n8 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 14 4 2\r\n2 7\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 21 6 2\r\n7 11 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 29 3 4\r\n7 16 19\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "3 24 2 6\r\n6 12 17\r\n", "output": "RUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "4 31 12 9\r\n7 13 21 28\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "4 10 1 7\r\n2 4 6 8\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "4 36 8 4\r\n4 13 19 27\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 25 10 2\r\n6 12 13 15 22\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 19 7 10\r\n3 7 9 12 16\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "5 28 6 8\r\n3 9 15 21 25\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 35 12 4\r\n7 12 17 21 24 28\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 22 5 7\r\n4 6 10 13 15 18\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "6 55 3 5\r\n10 18 24 34 39 45\r\n", "output": "RUN 9\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 9\r\n"}, {"input": "7 51 6 1\r\n8 17 18 23 27 33 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "7 36 11 4\r\n6 11 17 19 22 24 30\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "7 28 10 2\r\n5 10 14 19 21 23 27\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 46 4 5\r\n3 6 15 21 24 26 36 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 51 2 1\r\n6 14 20 26 29 35 40 48\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "8 56 2 9\r\n7 11 20 28 34 39 40 48\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 7\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 3\r\nRUN 6\r\nJUMP 2\r\nRUN 7\r\n"}, {"input": "9 57 2 2\r\n5 11 15 21 24 30 36 43 50\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "9 82 14 4\r\n10 18 28 38 46 55 64 74 79\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "9 40 6 3\r\n5 10 14 18 22 27 30 31 36\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 44 6 2\r\n4 8 13 19 23 29 32 33 37 41\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 42 1 3\r\n1 6 10 15 17 22 24 29 33 38\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "10 82 2 5\r\n9 17 27 37 44 51 57 62 67 72\r\n", "output": "RUN 8\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 9\r\n"}, {"input": "11 69 4 9\r\n7 14 20 26 29 35 40 46 52 58 64\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 5\r\nRUN 4\r\nJUMP 7\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\n"}, {"input": "11 65 1 7\r\n7 11 14 21 24 30 37 44 50 56 59\r\n", "output": "RUN 6\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 5\r\n"}, {"input": "11 77 10 10\r\n7 14 17 24 29 34 38 47 56 64 69\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 78 3 1\r\n4 11 19 22 30 38 43 51 56 59 67 73\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 89 14 9\r\n6 11 18 24 33 37 45 51 60 69 71 80\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "12 13 6 7\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "13 91 1 3\r\n5 12 17 22 29 36 43 49 57 64 70 74 84\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 6\r\nJUMP 2\r\nRUN 5\r\nJUMP 2\r\nRUN 4\r\nJUMP 2\r\nRUN 2\r\nJUMP 2\r\nRUN 8\r\nJUMP 2\r\nRUN 6\r\n"}, {"input": "13 87 5 6\r\n7 10 18 24 31 40 41 48 54 63 69 78 81\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "13 46 2 4\r\n1 4 9 13 15 19 21 23 25 30 35 37 42\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 93 1 1\r\n8 15 19 21 28 36 44 51 56 63 67 74 79 85\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 62 11 4\r\n5 10 15 18 22 26 31 34 39 42 44 47 52 57\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "14 109 10 1\r\n8 15 25 29 38 48 57 65 70 79 81 89 94 100\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 97 4 4\r\n3 7 13 23 29 35 39 45 49 50 60 68 72 81 87\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 77 4 8\r\n7 14 16 20 26 33 36 43 44 48 52 59 61 66 70\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "15 56 1 5\r\n5 10 15 20 21 25 29 31 34 37 38 41 43 47 52\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\nJUMP 3\r\nRUN 2\r\nJUMP 2\r\nRUN 2\r\nJUMP 4\r\nRUN 1\r\nJUMP 2\r\nRUN 1\r\nJUMP 3\r\nRUN 1\r\nJUMP 4\r\nRUN 2\r\nJUMP 2\r\nRUN 3\r\nJUMP 2\r\nRUN 3\r\n"}, {"input": "2 1000000000 1 3\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 1 2\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 1 4\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 2\r\nRUN 1\r\nJUMP 2\r\nRUN 999999991\r\n"}, {"input": "2 1000000000 2 4\r\n5 8\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "2 1000000000 2 5\r\n5 8\r\n", "output": "RUN 4\r\nJUMP 5\r\nRUN 999999991\r\n"}]
| 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:
d[p] += 1
else:
d[p] = 1
n //= p
return d
from collections import Counter
n = int(input())
S = list(map(int, input().split()))
C = Counter()
for s in S:
d = factorize(s)
for p in d.keys():
C[p] += 1
ans = 1
for k, v in C.items():
ans = max(ans, v)
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, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
|
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 is no larger group with gcd ≠ 1.
|
[{"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 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10\r\n", "output": "38\r\n"}, {"input": "95\r\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50\r\n", "output": "48\r\n"}, {"input": "44\r\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684\r\n", "output": "19\r\n"}, {"input": "35\r\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557\r\n", "output": "20\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n10 7 9 8 3 3 10 7 3 3\r\n", "output": "5\r\n"}, {"input": "9\r\n10 10 6 10 9 1 8 3 5\r\n", "output": "5\r\n"}, {"input": "7\r\n9 4 2 3 3 9 8\r\n", "output": "4\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "6\r\n1623 45906 37856 34727 27156 12598\r\n", "output": "4\r\n"}, {"input": "30\r\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566\r\n", "output": "15\r\n"}, {"input": "23\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16\r\n", "output": "22\r\n"}, {"input": "46\r\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33\r\n", "output": "27\r\n"}, {"input": "43\r\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34\r\n", "output": "21\r\n"}, {"input": "25\r\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 6\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n3 3 3 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n541 541\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n99989 99989\r\n", "output": "2\r\n"}, {"input": "3\r\n3 9 27\r\n", "output": "3\r\n"}, {"input": "2\r\n1009 1009\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "6\r\n2 10 20 5 15 25\r\n", "output": "5\r\n"}, {"input": "3\r\n3 3 6\r\n", "output": "3\r\n"}, {"input": "3\r\n457 457 457\r\n", "output": "3\r\n"}, {"input": "2\r\n34 17\r\n", "output": "2\r\n"}, {"input": "3\r\n12 24 3\r\n", "output": "3\r\n"}, {"input": "10\r\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991\r\n", "output": "10\r\n"}, {"input": "2\r\n1009 2018\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "3\r\n"}, {"input": "7\r\n6 9 12 15 21 27 33\r\n", "output": "7\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n557 557\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 101 101 101\r\n", "output": "3\r\n"}, {"input": "2\r\n122 3721\r\n", "output": "2\r\n"}, {"input": "2\r\n49201 98402\r\n", "output": "2\r\n"}, {"input": "2\r\n88258 44129\r\n", "output": "2\r\n"}, {"input": "2\r\n7919 47514\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n10007 20014 30021\r\n", "output": "3\r\n"}, {"input": "4\r\n10 10 5 5\r\n", "output": "4\r\n"}, {"input": "2\r\n6 9\r\n", "output": "2\r\n"}, {"input": "3\r\n6 12 9\r\n", "output": "3\r\n"}, {"input": "2\r\n14 7\r\n", "output": "2\r\n"}, {"input": "2\r\n199 199\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 49999 99998\r\n", "output": "3\r\n"}, {"input": "5\r\n1009 1009 1009 1009 1009\r\n", "output": "5\r\n"}, {"input": "3\r\n17 17 17\r\n", "output": "3\r\n"}, {"input": "2\r\n503 1509\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 99998 99998\r\n", "output": "3\r\n"}, {"input": "2\r\n28657 28657\r\n", "output": "2\r\n"}, {"input": "3\r\n121 22 33\r\n", "output": "3\r\n"}, {"input": "2\r\n10079 20158\r\n", "output": "2\r\n"}, {"input": "2\r\n6 15\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 3\r\n", "output": "4\r\n"}, {"input": "2\r\n991 1982\r\n", "output": "2\r\n"}, {"input": "3\r\n20362 30543 50905\r\n", "output": "3\r\n"}, {"input": "2\r\n443 886\r\n", "output": "2\r\n"}, {"input": "4\r\n3 7 7 21\r\n", "output": "3\r\n"}, {"input": "3\r\n3 6 9\r\n", "output": "3\r\n"}, {"input": "2\r\n217 31\r\n", "output": "2\r\n"}, {"input": "6\r\n10 10 10 5 5 5\r\n", "output": "6\r\n"}, {"input": "4\r\n49441 25225 9081 4036\r\n", "output": "4\r\n"}, {"input": "2\r\n4 9\r\n", "output": "1\r\n"}, {"input": "2\r\n18 27\r\n", "output": "2\r\n"}, {"input": "2\r\n13 26\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 15\r\n", "output": "4\r\n"}]
| 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)
return
print(result)
if __name__ == "__main__":
solve()
|
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 found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?
|
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 could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3.
In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal.
In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
|
[{"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"}, {"input": "20 5\r\n59 54 19 88 55 100 54 3 6 13 99 38 36 71 59 6 64 85 45 54\r\n", "output": "-1"}, {"input": "100 10\r\n340 70 440 330 130 120 340 210 440 110 410 120 180 40 50 230 70 110 310 360 480 70 230 120 230 310 470 60 210 60 210 480 290 250 450 440 150 40 500 230 280 250 30 50 310 50 230 360 420 260 330 80 50 160 70 470 140 180 380 190 250 30 220 410 80 310 280 50 20 430 440 180 310 190 190 330 90 190 320 390 170 460 230 30 80 500 470 370 80 500 400 120 220 150 70 120 70 320 260 260\r\n", "output": "2157"}, {"input": "100 18\r\n489 42 300 366 473 105 220 448 70 488 201 396 168 281 67 235 324 291 313 387 407 223 39 144 224 233 72 318 229 377 62 171 448 119 354 282 147 447 260 384 172 199 67 326 311 431 337 142 281 202 404 468 38 120 90 437 33 420 249 372 367 253 255 411 309 333 103 176 162 120 203 41 352 478 216 498 224 31 261 493 277 99 375 370 394 229 71 488 246 194 233 13 66 111 366 456 277 360 116 354\r\n", "output": "-1"}, {"input": "4 2\r\n1 2 3 4\r\n", "output": "-1"}, {"input": "3 4\r\n3 5 5\r\n", "output": "-1"}, {"input": "3 2\r\n88888884 88888886 88888888\r\n", "output": "3"}, {"input": "2 1\r\n1000000000 1000000000\r\n", "output": "0"}, {"input": "4 2\r\n1000000000 100000000 100000000 100000000\r\n", "output": "450000000"}, {"input": "2 2\r\n1000000000 1000000000\r\n", "output": "0"}, {"input": "3 3\r\n3 2 1\r\n", "output": "-1"}, {"input": "3 4\r\n3 5 3\r\n", "output": "-1"}, {"input": "3 2\r\n1 2 2\r\n", "output": "-1"}, {"input": "4 2\r\n2 3 3 2\r\n", "output": "-1"}, {"input": "3 2\r\n1 2 4\r\n", "output": "-1"}, {"input": "3 2\r\n3 4 4\r\n", "output": "-1"}, {"input": "3 3\r\n4 7 10\r\n", "output": "3"}, {"input": "4 3\r\n2 2 5 1\r\n", "output": "-1"}, {"input": "3 3\r\n1 3 5\r\n", "output": "-1"}, {"input": "2 5\r\n5 9\r\n", "output": "-1"}, {"input": "2 3\r\n5 7\r\n", "output": "-1"}, {"input": "3 137\r\n1000000000 1000000000 1000000000\r\n", "output": "0"}, {"input": "5 1000000000\r\n1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0"}, {"input": "3 5\r\n1 2 5\r\n", "output": "-1"}, {"input": "3 3\r\n1000000000 1000000000 999999997\r\n", "output": "2"}, {"input": "2 4\r\n5 6\r\n", "output": "-1"}, {"input": "4 1\r\n1000000000 1000000000 1000000000 1000000000\r\n", "output": "0"}, {"input": "2 3\r\n5 8\r\n", "output": "1"}, {"input": "2 6\r\n8 16\r\n", "output": "-1"}, {"input": "5 3\r\n15 14 9 12 18\r\n", "output": "-1"}, {"input": "3 3\r\n1 2 3\r\n", "output": "-1"}, {"input": "3 3\r\n3 4 5\r\n", "output": "-1"}, {"input": "2 5\r\n8 17\r\n", "output": "-1"}, {"input": "2 1\r\n1 2\r\n", "output": "1"}, {"input": "1 1\r\n1000000000\r\n", "output": "0"}, {"input": "3 3\r\n5 3 4\r\n", "output": "-1"}, {"input": "3 6\r\n10 14 12\r\n", "output": "-1"}, {"input": "2 2\r\n3 5\r\n", "output": "1"}, {"input": "3 5\r\n1 3 4\r\n", "output": "-1"}, {"input": "4 3\r\n1 6 6 6\r\n", "output": "-1"}, {"input": "2 3\r\n1 8\r\n", "output": "-1"}, {"input": "3 5\r\n6 11 17\r\n", "output": "-1"}, {"input": "2 2\r\n1 4\r\n", "output": "-1"}, {"input": "2 4\r\n6 8\r\n", "output": "-1"}, {"input": "2 1\r\n2 3\r\n", "output": "1"}, {"input": "4 4\r\n1 5 8 14\r\n", "output": "-1"}, {"input": "3 3\r\n1 5 3\r\n", "output": "-1"}, {"input": "4 3\r\n1 2 2 5\r\n", "output": "-1"}, {"input": "3 2\r\n1 4 6\r\n", "output": "-1"}, {"input": "2 3\r\n6 9\r\n", "output": "1"}, {"input": "3 3\r\n2 3 4\r\n", "output": "-1"}, {"input": "3 2\r\n9 10 10\r\n", "output": "-1"}, {"input": "2 2\r\n9 12\r\n", "output": "-1"}, {"input": "2 2\r\n100000003 100000005\r\n", "output": "1"}, {"input": "2 3\r\n2 4\r\n", "output": "-1"}, {"input": "3 2\r\n2 3 5\r\n", "output": "-1"}, {"input": "3 3\r\n1 3 4\r\n", "output": "-1"}, {"input": "10 2\r\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "4499999991"}, {"input": "3 5\r\n2 4 5\r\n", "output": "-1"}, {"input": "2 3\r\n7 10\r\n", "output": "1"}, {"input": "3 10\r\n10 13 17\r\n", "output": "-1"}, {"input": "2 3\r\n1 6\r\n", "output": "-1"}, {"input": "1 7\r\n1000000000\r\n", "output": "0"}, {"input": "2 4\r\n3 7\r\n", "output": "1"}, {"input": "2 3\r\n2 5\r\n", "output": "1"}, {"input": "20 1\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n", "output": "0"}, {"input": "3 3\r\n7 8 8\r\n", "output": "-1"}, {"input": "4 10\r\n1 11 100 11\r\n", "output": "-1"}]
| 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]+' ')
else:
res.append(s[i])
res.append(s[-1])
print("".join(res))
| 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, then they should be separated by exactly one space
- there should be no spaces before each punctuation mark
- there should be exactly one space after each punctuation mark
It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.
|
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\n"}, {"input": "a a a a a\r\n", "output": "a a a a a\r\n"}, {"input": "ksdfk sdlfsdf sdf sdf sdf\r\n", "output": "ksdfk sdlfsdf sdf sdf sdf\r\n"}, {"input": "gdv\r\n", "output": "gdv\r\n"}, {"input": "incen q\r\n", "output": "incen q\r\n"}, {"input": "k ? gq dad\r\n", "output": "k? gq dad\r\n"}, {"input": "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb\r\n", "output": "ntomzzut! pousysvfg, rnl mcyytihe hplnqnb\r\n"}, {"input": "mck . gq dauqminf wee bazyzy humnv d pgtvx , vxntxgrkrc rg rwr, uuyweyz l\r\n", "output": "mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l\r\n"}, {"input": "jjcmhwnon taetfgdvc, ysrajurstj ! fryavybwpg hnxbnsron ,txplbmm atw?wkfhn ez mcdn tujsy wrdhw . k i lzwtxcyam fi . nyeu j\r\n", "output": "jjcmhwnon taetfgdvc, ysrajurstj! fryavybwpg hnxbnsron, txplbmm atw? wkfhn ez mcdn tujsy wrdhw. k i lzwtxcyam fi. nyeu j\r\n"}, {"input": "chcf htb flfwkosmda a qygyompixkgz ?rg? hdw f dsvqzs kxvjt ? zj zghgarwihw zgrhr xlwmhv . lycpsmdm iotv . d jhsxoogbr ! ppgrpwcrcl inw usegrtd ?fexma ? mhszrvdoa ,audsrhina epoleuq oaz hqapedl lm\r\n", "output": "chcf htb flfwkosmda a qygyompixkgz? rg? hdw f dsvqzs kxvjt? zj zghgarwihw zgrhr xlwmhv. lycpsmdm iotv. d jhsxoogbr! ppgrpwcrcl inw usegrtd? fexma? mhszrvdoa, audsrhina epoleuq oaz hqapedl lm\r\n"}, {"input": "x\r\n", "output": "x\r\n"}, {"input": "xx\r\n", "output": "xx\r\n"}, {"input": "x x\r\n", "output": "x x\r\n"}, {"input": "x,x\r\n", "output": "x, x\r\n"}, {"input": "x.x\r\n", "output": "x. x\r\n"}, {"input": "x!x\r\n", "output": "x! x\r\n"}, {"input": "x?x\r\n", "output": "x? x\r\n"}, {"input": "a!b\r\n", "output": "a! b\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "physicist ?mathematician.astronomer\r\n", "output": "physicist? mathematician. astronomer\r\n"}, {"input": "dfgdfg ? ddfgdsfg ? dsfgdsfgsdfgdsf ! dsfg . sd dsg sdg ! sdfg\r\n", "output": "dfgdfg? ddfgdsfg? dsfgdsfgsdfgdsf! dsfg. sd dsg sdg! sdfg\r\n"}, {"input": "jojo ! majo , hehehehe? jo . kok\r\n", "output": "jojo! majo, hehehehe? jo. kok\r\n"}, {"input": "adskfj,kjdf?kjadf kj!kajs f\r\n", "output": "adskfj, kjdf? kjadf kj! kajs f\r\n"}, {"input": "a , b\r\n", "output": "a, b\r\n"}, {"input": "ahmed? ahmed ? ahmed ?ahmed\r\n", "output": "ahmed? ahmed? ahmed? ahmed\r\n"}, {"input": "kjdsf, kdjf?kjdf!kj kdjf\r\n", "output": "kjdsf, kdjf? kjdf! kj kdjf\r\n"}, {"input": "italian physicist .mathematician?astronomer\r\n", "output": "italian physicist. mathematician? astronomer\r\n"}, {"input": "galileo galilei was an italian physicist , mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "z zz zz z z! z z aksz zkjsdfz kajfz z !akj , zz a z\r\n", "output": "z zz zz z z! z z aksz zkjsdfz kajfz z! akj, zz a z\r\n"}, {"input": "jojo ! maja . jaooo\r\n", "output": "jojo! maja. jaooo\r\n"}, {"input": "a ! b\r\n", "output": "a! b\r\n"}, {"input": "fff , fff\r\n", "output": "fff, fff\r\n"}, {"input": "a!a?a ! a ? a\r\n", "output": "a! a? a! a? a\r\n"}, {"input": "a!a\r\n", "output": "a! a\r\n"}, {"input": "a!a a ! a ? a ! a , a . a\r\n", "output": "a! a a! a? a! a, a. a\r\n"}, {"input": "casa?mesa, y unos de , los sapotes?l\r\n", "output": "casa? mesa, y unos de, los sapotes? l\r\n"}, {"input": "ff ! ff\r\n", "output": "ff! ff\r\n"}, {"input": "i love evgenia ! x\r\n", "output": "i love evgenia! x\r\n"}, {"input": "galileo galilei was an italian physicist ,mathematician,astronomer?asdf ?asdfff?asdf. asdf.dfd .dfdf ? df d! sdf dsfsa sdf ! asdf ? sdfsdf, dfg a ! b ?a\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer? asdf? asdfff? asdf. asdf. dfd. dfdf? df d! sdf dsfsa sdf! asdf? sdfsdf, dfg a! b? a\r\n"}, {"input": "a , a\r\n", "output": "a, a\r\n"}, {"input": "x, werwr, werwerwr we,rwer ,wer\r\n", "output": "x, werwr, werwerwr we, rwer, wer\r\n"}, {"input": "abcabc, abcabc\r\n", "output": "abcabc, abcabc\r\n"}, {"input": "i love evgenia x! x\r\n", "output": "i love evgenia x! x\r\n"}, {"input": "gg gg,h,h,j,i,jh , jjj , jj ,aadd , jjj jjj\r\n", "output": "gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj\r\n"}, {"input": "mt test ! case\r\n", "output": "mt test! case\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "asdasdasd.asdasdasdasd?asdasdasd!asdasdasd,asdasdasdasd\r\n", "output": "asdasdasd. asdasdasdasd? asdasdasd! asdasdasd, asdasdasdasd\r\n"}, {"input": "x, x, ds ,ertert, ert, et et\r\n", "output": "x, x, ds, ertert, ert, et et\r\n"}, {"input": "anton!love ?yourself\r\n", "output": "anton! love? yourself\r\n"}, {"input": "facepalm ? yes , lol ! yeah\r\n", "output": "facepalm? yes, lol! yeah\r\n"}, {"input": "a ! a\r\n", "output": "a! a\r\n"}, {"input": "adf!kadjf?kajdf,lkdas. kd ! akdjf\r\n", "output": "adf! kadjf? kajdf, lkdas. kd! akdjf\r\n"}, {"input": "a? x\r\n", "output": "a? x\r\n"}, {"input": "read problem carefully ! heh\r\n", "output": "read problem carefully! heh\r\n"}, {"input": "a?a?a?a.a\r\n", "output": "a? a? a? a. a\r\n"}, {"input": "a. v\r\n", "output": "a. v\r\n"}, {"input": "a!a a ! a ? a ! a , a . a aaaaaa ! a ! a. a a .a a.a aa.aa aa . aa aa .aa aa. aa\r\n", "output": "a! a a! a? a! a, a. a aaaaaa! a! a. a a. a a. a aa. aa aa. aa aa. aa aa. aa\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "a!a!a\r\n", "output": "a! a! a\r\n"}, {"input": "a.a.a.a\r\n", "output": "a. a. a. a\r\n"}, {"input": "a, b\r\n", "output": "a, b\r\n"}, {"input": "galileo galilei was an italian physicist, mathematician, astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "a!a!a!a\r\n", "output": "a! a! a! a\r\n"}, {"input": "af ! kadjf ? kjdfkj!kjadkfjz z z a a! ka,kjf\r\n", "output": "af! kadjf? kjdfkj! kjadkfjz z z a a! ka, kjf\r\n"}, {"input": "ab cd,k\r\n", "output": "ab cd, k\r\n"}, {"input": "a!n , to\r\n", "output": "a! n, to\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "u, sux\r\n", "output": "u, sux\r\n"}]
| 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 max_changes < changes:
max_changes = changes
for j in range(m):
if line[j] != j + 1:
y[j] += 1
x.append(line)
if max_changes <= 1:
return 'YES'
if n == 1 and max_changes == 2:
return 'YES'
max1, max2 = get_max_idxs(y)
#print(x)
#print(max2, max2)
for line in x:
line[max1], line[max2] = line[max2], line[max1]
if get_changes(list(line)) > 1:
return 'NO'
return 'YES'
def get_max_idxs(y):
max_val1 = 0
max_idx1 = 0
max_val2 = 0
max_idx2 = 0
for idx, val in enumerate(y):
if val >= max_val1:
max_val2 = max_val1
max_idx2 = max_idx1
max_val1 = val
max_idx1 = idx
elif val >= max_val2:
max_val2 = val
max_idx2 = idx
return max_idx1, max_idx2
def get_changes(x):
changes = 0
for idx in range(len(x)):
val = x[idx]
while val != idx + 1:
x[val - 1], x[idx] = x[idx], x[val - 1]
val = x[idx]
changes += 1
return changes
def stdin_get_ints_from_line():
return (int(x) for x in stdin.readline().strip().split(' '))
def stdin_get_ints_list_from_line():
return list(int(x) for x in stdin.readline().strip().split(' '))
def stdin_get_string_from_line():
return stdin.readline().strip()
if __name__ == '__main__':
print(main())
| 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:
cnt += 1
if cnt > 2:
break
row[c1], row[c2] = row[c2], row[c1]
if cnt > 2:
ok = False
break
if ok:
print('YES')
exit(0)
print('NO')
|
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 to perform from 0 to n + 1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
|
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 8 9 10\r\n", "output": "YES\r\n"}, {"input": "5 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 8 5 6 7 10 9 4 11 12\r\n1 5 3 4 2 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n", "output": "YES\r\n"}, {"input": "4 10\r\n3 2 8 10 5 6 7 1 9 4\r\n1 2 9 4 5 3 7 8 10 6\r\n7 5 3 4 8 6 1 2 9 10\r\n4 2 3 9 8 6 7 5 1 10\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n9 2 3 4 5 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 10 7 8 1 6\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n9 10 4 2 3 5 7 1 8 6\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n6 4 7 3 5 8 1 9 10 2\r\n1 5 10 6 3 4 9 7 2 8\r\n3 2 1 7 8 6 5 4 10 9\r\n7 9 1 6 8 2 4 5 3 10\r\n3 4 6 9 8 7 1 2 10 5\r\n", "output": "NO\r\n"}, {"input": "20 2\r\n1 2\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "20 3\r\n3 2 1\r\n2 3 1\r\n2 3 1\r\n2 1 3\r\n1 3 2\r\n2 1 3\r\n1 2 3\r\n3 2 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n2 1 3\r\n2 3 1\r\n2 3 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n3 1 2\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 2 3 4 5 6 7 10 9 8\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n6 9 3 4 5 1 8 7 2 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 19 14 15 16 17 18 13 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 20\r\n1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 17 18 19 20\r\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 12 18 7 8 9 10 11 5 13 14 15 16 17 6 19 20\r\n6 2 3 4 5 1 7 8 9 10 11 12 13 20 15 16 17 18 19 14\r\n4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 19 8 9 10 11 12 13 14 15 20 17 18 7 16\r\n1 2 9 4 5 6 7 8 18 10 11 12 13 14 15 16 17 3 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n4 2 3 8 5 6 7 1 9 10\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n3 2 1 4 5 6 7 8 10 9\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 18 14 15 16 17 13 11 20\r\n1 2 11 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 3 20\r\n13 2 3 4 5 6 7 8 9 10 19 12 1 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 16 8 9 10 11 12 13 14 15 7 17 18 19 20\r\n1 2 3 14 5 6 16 8 9 10 11 12 13 4 15 7 17 18 19 20\r\n1 2 3 4 5 6 16 8 18 10 11 12 13 14 15 7 17 9 19 20\r\n1 2 3 4 5 6 16 8 9 15 11 12 13 14 10 7 17 18 19 20\r\n1 2 18 4 5 6 16 8 9 10 11 12 13 14 15 7 17 3 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 18 4 5 6 7 8 9 10 11 12 13 14 15 16 19 3 17 20\r\n8 2 3 9 5 6 7 1 4 10 11 12 13 14 15 16 17 18 19 20\r\n7 2 3 4 5 6 1 8 9 10 11 12 13 14 15 16 17 20 19 18\r\n1 2 3 12 5 6 7 8 9 17 11 4 13 14 15 16 10 18 19 20\r\n1 11 3 4 9 6 7 8 5 10 2 12 13 14 15 16 17 18 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n10 2 3 4 5 9 7 8 6 1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 9 2 4 6 5 8 3 7 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 3 2 19 5 6 7 8 9 17 11 12 13 14 15 16 10 18 4 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 20 6 7 8 9 17 11 12 13 14 15 16 10 18 19 5\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 6 17 4 5 2 7 14 9 10 11 12 13 8 15 16 3 18 19 20\r\n5 6 17 4 1 2 7 8 9 10 11 12 13 14 15 16 3 18 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 18 3 16 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 16 3 18 20 19\r\n1 6 17 8 5 2 7 4 9 10 11 12 13 14 15 16 3 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n10 2 9 4 5 6 7 8 15 1 11 16 13 14 3 12 17 18 19 20\r\n10 2 3 4 5 6 7 1 9 8 11 16 13 14 15 12 17 18 19 20\r\n9 2 3 4 5 6 7 8 10 1 11 16 13 14 15 12 20 18 19 17\r\n10 2 3 4 7 6 5 8 9 1 11 16 18 14 15 12 17 13 19 20\r\n10 2 3 4 5 6 7 8 9 20 11 16 14 13 15 12 17 18 19 1\r\n", "output": "NO\r\n"}, {"input": "1 4\r\n2 3 4 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 1 3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "15 6\r\n2 1 4 3 6 5\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n4 3 1 2\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "4 8\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n", "output": "YES\r\n"}, {"input": "4 6\r\n1 2 3 5 6 4\r\n3 2 1 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n3 1 2\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 1 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "20 8\r\n4 3 2 1 5 6 7 8\r\n1 2 3 4 8 7 6 5\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n8 7 6 5 4 3 2 1\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n", "output": "YES\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 11 12 9\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n3 2 1 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n2 3 1 4 5 6\r\n1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n2 3 1\r\n2 3 1\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "5 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n3 8 1 4 5 6 7 2\r\n1 8 3 6 5 4 7 2\r\n1 8 3 5 4 6 7 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 4 3 1\r\n2 1 5 4 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 3 1 4\r\n1 2 3 4\r\n2 3 1 4\r\n2 1 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 4 3 5\r\n2 1 4 3 5\r\n1 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "3 10\r\n2 1 3 4 5 6 8 7 10 9\r\n1 2 3 4 5 6 8 7 10 9\r\n1 2 3 4 6 5 8 7 10 9\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n3 1 2 4\r\n3 2 4 1\r\n3 1 2 4\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n1 4 2 3 5\r\n1 2 4 5 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 3 4\r\n2 1 5 3 4\r\n", "output": "NO\r\n"}, {"input": "3 6\r\n2 3 1 4 5 6\r\n2 1 4 3 5 6\r\n1 2 3 4 5 6\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "4 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 3 4 5\r\n1 3 4 2 5\r\n1 4 2 3 5\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 2 3\r\n1 2 3\r\n1 2 3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n3 1 2\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "7 4\r\n1 2 3 4\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 2 3\r\n1 3 2\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}]
| 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)
num = int(num / bs)
arr = arr[::-1]
if len(arr) == 0:
arr = "0"
return arr
def roman(nm):
tot = 12
roma = ""
num = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]
rom = ["I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"]
while nm > 0:
q = int(nm / num[tot])
roma = roma + rom[tot] * q
nm = nm % num[tot]
tot -= 1
return roma
def op1(txt, bs):
di = {"A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15, "G": 16, "H": 17, "I": 18, "J": 19, "K": 20,
"L": 21, "M": 22, "N": 23, "O": 24}
num = 0
if bs != 10:
for i, j in zip(reversed(range(len(txt))), txt):
if j.isalpha():
j = di[j.upper()]
num = num + int(j) * pow(bs, i)
if bs == 10:
num = int(txt)
return num
waste, base = input().split()
number = input()
if base == "R":
number = op1(number, int(waste))
print(roman(int(number)))
elif base == waste:
print(number)
else:
number = op1(number, int(waste))
print(op2(number, int(base)))
| 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, 90, 50, 40,
10, 9, 5, 4,
1
]
syb = [
"M", "CM", "D", "CD",
"C", "XC", "L", "XL",
"X", "IX", "V", "IV",
"I"
]
roman_num = ''
i = 0
while num > 0:
for _ in range(num // val[i]):
roman_num += syb[i]
num -= val[i]
i += 1
return roman_num
t = int(c.lower(),a)
if b != 'R':
print(conv(t,int(b)))
else:
print(write_roman(t))
|
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 captured by Shapur and Shapur is now going to capture Valerian, the Roman emperor.
Being defeated, the cowardly Valerian hid in a room at the top of one of his castles. To capture him, Shapur has to open many doors. Fortunately Valerian was too scared to make impenetrable locks for the doors.
Each door has 4 parts. The first part is an integer number a. The second part is either an integer number b or some really odd sign which looks like R. The third one is an integer c and the fourth part is empty! As if it was laid for writing something. Being extremely gifted, after opening the first few doors, Shapur found out the secret behind the locks.
c is an integer written in base a, to open the door we should write it in base b. The only bad news is that this R is some sort of special numbering system that is used only in Roman empire, so opening the doors is not just a piece of cake!
Here's an explanation of this really weird number system that even doesn't have zero:
Roman numerals are based on seven symbols: a stroke (identified with the letter I) for a unit, a chevron (identified with the letter V) for a five, a cross-stroke (identified with the letter X) for a ten, a C (identified as an abbreviation of Centum) for a hundred, etc.:
- I=1
- V=5
- X=10
- L=50
- C=100
- D=500
- M=1000
Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1, 000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I 1, II 2, III 3, V 5, VI 6, VII 7, etc., and the same for other bases: X 10, XX 20, XXX 30, L 50, LXXX 80; CC 200, DCC 700, etc. At the fourth and ninth iteration, a subtractive principle must be employed, with the base placed before the higher base: IV 4, IX 9, XL 40, XC 90, CD 400, CM 900.
Also in bases greater than 10 we use A for 10, B for 11, etc.
Help Shapur capture Valerian and bring peace back to Persia, especially Armenia.
|
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 included the number would be less than or equal to 300010 and it won't be 0. In any other case the number won't be greater than 101510.
|
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\nABG\r\n", "output": "3951\r\n"}, {"input": "17 10\r\nABACG\r\n", "output": "892363\r\n"}, {"input": "18 R\r\nGH\r\n", "output": "CCCV\r\n"}, {"input": "20 25\r\n4E32BB21D812\r\n", "output": "A2II7CL2HDM\r\n"}, {"input": "15 11\r\n760595A635B24\r\n", "output": "258AA2604713696\r\n"}, {"input": "10 22\r\n956512026633000\r\n", "output": "1E06A57IC4H2\r\n"}, {"input": "5 9\r\n1102101401441324123301\r\n", "output": "2733824152181178\r\n"}, {"input": "23 4\r\nDL5K6H78CAH\r\n", "output": "2003021332111213003322000\r\n"}, {"input": "18 R\r\n36E\r\n", "output": "MXCIV\r\n"}, {"input": "13 2\r\n1B579528314B30\r\n", "output": "10000001011010101001110000001110001011010111010010\r\n"}, {"input": "8 13\r\n20043013541570572\r\n", "output": "1B35CBA6B32102\r\n"}, {"input": "19 24\r\n1BH47I158EII\r\n", "output": "2NHBDL4ECN2\r\n"}, {"input": "14 19\r\n33BC51B817C55\r\n", "output": "1B573FFHHH12\r\n"}, {"input": "24 10\r\nE2E3EA6MJ05\r\n", "output": "894488519782085\r\n"}, {"input": "25 2\r\nIBGNAB3C0H\r\n", "output": "10000000001001000010100000111011000110101000001\r\n"}, {"input": "3 R\r\n2\r\n", "output": "II\r\n"}, {"input": "20 20\r\n3HBAH9JA9EDE\r\n", "output": "3HBAH9JA9EDE\r\n"}, {"input": "21 21\r\n2G3DK3F23905\r\n", "output": "2G3DK3F23905\r\n"}, {"input": "23 R\r\n57F\r\n", "output": "MMDCCCXXI\r\n"}, {"input": "16 6\r\n27774848D1D9F\r\n", "output": "10500345245142230115\r\n"}, {"input": "18 7\r\nD9D42E745C5A\r\n", "output": "351206225505021115\r\n"}, {"input": "11 R\r\n1A8A\r\n", "output": "MMDCXXXIX\r\n"}, {"input": "12 17\r\n567872838B15A5\r\n", "output": "105CA323BC110\r\n"}, {"input": "12 19\r\n78613621478844\r\n", "output": "71A1E1HB01EB\r\n"}, {"input": "12 25\r\n51B878A1B3A7B8\r\n", "output": "5JLBAF5JBEA\r\n"}, {"input": "12 R\r\n17BB\r\n", "output": "MMDCCCLXXIX\r\n"}, {"input": "20 R\r\nFI\r\n", "output": "CCCXVIII\r\n"}, {"input": "20 5\r\n1FAD98HHG13G\r\n", "output": "340143030243121422401\r\n"}, {"input": "19 12\r\nEHIAG4GG072\r\n", "output": "A33B813901970\r\n"}, {"input": "3 R\r\n2201120\r\n", "output": "MCMLXXXVI\r\n"}, {"input": "3 R\r\n10210211\r\n", "output": "MMDCCLXXVI\r\n"}, {"input": "3 R\r\n21222\r\n", "output": "CCXV\r\n"}, {"input": "11 22\r\n172A57412774400\r\n", "output": "11G8KLBCI95B\r\n"}, {"input": "17 4\r\n1509D9E003C5C\r\n", "output": "2223230302121200303102203\r\n"}, {"input": "2 R\r\n101110110111\r\n", "output": "MMCMXCIX\r\n"}, {"input": "25 R\r\n2JA\r\n", "output": "MDCCXXXV\r\n"}, {"input": "23 R\r\n3HK\r\n", "output": "MCMXCVIII\r\n"}, {"input": "10 22\r\n1000000000000000\r\n", "output": "1FE6KH3A0F7A\r\n"}, {"input": "10 2\r\n999999999999993\r\n", "output": "11100011010111111010100100110001100111111111111001\r\n"}, {"input": "4 21\r\n112233030100132210003330\r\n", "output": "5KIIKBEFE1G\r\n"}, {"input": "4 10\r\n112233030100132210003330\r\n", "output": "100000000000252\r\n"}, {"input": "4 5\r\n112233030100132210003330\r\n", "output": "101101400000000002002\r\n"}, {"input": "2 R\r\n1\r\n", "output": "I\r\n"}, {"input": "13 15\r\n33BCA79805767B\r\n", "output": "7A924652EB469\r\n"}, {"input": "2 10\r\n0\r\n", "output": "0\r\n"}, {"input": "25 2\r\n0\r\n", "output": "0\r\n"}, {"input": "25 10\r\n001\r\n", "output": "1\r\n"}, {"input": "17 17\r\n00000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": "0\r\n"}, {"input": "10 R\r\n999\r\n", "output": "CMXCIX\r\n"}, {"input": "2 2\r\n0\r\n", "output": "0\r\n"}, {"input": "10 10\r\n100000000000\r\n", "output": "100000000000\r\n"}, {"input": "10 10\r\n0\r\n", "output": "0\r\n"}, {"input": "10 R\r\n900\r\n", "output": "CM\r\n"}, {"input": "10 11\r\n12345678912345\r\n", "output": "3A2A855993029\r\n"}, {"input": "10 2\r\n100000000000000\r\n", "output": "10110101111001100010000011110100100000000000000\r\n"}, {"input": "10 R\r\n1983\r\n", "output": "MCMLXXXIII\r\n"}, {"input": "2 R\r\n101110111000\r\n", "output": "MMM\r\n"}, {"input": "2 R\r\n101110111000\r\n", "output": "MMM\r\n"}, {"input": "10 11\r\n1000000000000000\r\n", "output": "26A6A368906563A\r\n"}, {"input": "10 R\r\n1137\r\n", "output": "MCXXXVII\r\n"}, {"input": "10 R\r\n100\r\n", "output": "C\r\n"}, {"input": "10 25\r\n12343456543435\r\n", "output": "35M8JNIJCA\r\n"}, {"input": "16 10\r\n0523456789ABC\r\n", "output": "90384742521532\r\n"}]
| 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, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317]
if n == 1:
print(1)
else:
prime = [True for i in range(n)]
best = 0
for pr in primes:
count = 0
for i in range(n):
if pkmns[i] % pr == 0:
count += 1
prime[i] = False
if count > best:
best = count
pkmn_big_primes = set()
for i in prime:
if i and pkmns[i] > 317:
pkmn_big_primes.add(pkmns[i])
if len(pkmn_big_primes) > 0:
for p in pkmn_big_primes:
count = 0
for q in pkmns:
if q % p == 0:
count += 1
if count > best:
best = count
if best > 0:
print(best)
else:
print(1)
| 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 + 1, i):
# count +=
# n = max(L)
# primes = makePrimes(n)
# highestCount = maxCount(L)
# for prime in primes:
# if prime > n**0.5:
# break
# count = len([x for x in L if x % prime == 0])
# if count > highestCount:
# highestCount = count
# return highestCount
def maxCount(L):
d = dict()
for x in L:
if x in d:
d[x] += 1
else:
d[x] = 1
d[1] = 1
return max([d[x] for x in d])
# print(solver([2, 3, 4]))
# print(solver([3, 9]))
# print(solver([2, 3, 4, 6, 7]))
# print(solver([12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 12553, 15, 1, 18, 28, 20, 6, 31, 16, 5, 23, 21, 38, 3, 11, 18, 11, 3, 25, 33]))
# print(solver([1, 1, 1]))
# print(solver([1, 3, 6]))
main()
|
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, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
|
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 is no larger group with gcd ≠ 1.
|
[{"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 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10\r\n", "output": "38\r\n"}, {"input": "95\r\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50\r\n", "output": "48\r\n"}, {"input": "44\r\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684\r\n", "output": "19\r\n"}, {"input": "35\r\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557\r\n", "output": "20\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n10 7 9 8 3 3 10 7 3 3\r\n", "output": "5\r\n"}, {"input": "9\r\n10 10 6 10 9 1 8 3 5\r\n", "output": "5\r\n"}, {"input": "7\r\n9 4 2 3 3 9 8\r\n", "output": "4\r\n"}, {"input": "1\r\n4\r\n", "output": "1\r\n"}, {"input": "6\r\n1623 45906 37856 34727 27156 12598\r\n", "output": "4\r\n"}, {"input": "30\r\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566\r\n", "output": "15\r\n"}, {"input": "23\r\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16\r\n", "output": "22\r\n"}, {"input": "46\r\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33\r\n", "output": "27\r\n"}, {"input": "43\r\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34\r\n", "output": "21\r\n"}, {"input": "25\r\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n3 6\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n3 3 3 3 3\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n541 541\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n99989 99989\r\n", "output": "2\r\n"}, {"input": "3\r\n3 9 27\r\n", "output": "3\r\n"}, {"input": "2\r\n1009 1009\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "6\r\n2 10 20 5 15 25\r\n", "output": "5\r\n"}, {"input": "3\r\n3 3 6\r\n", "output": "3\r\n"}, {"input": "3\r\n457 457 457\r\n", "output": "3\r\n"}, {"input": "2\r\n34 17\r\n", "output": "2\r\n"}, {"input": "3\r\n12 24 3\r\n", "output": "3\r\n"}, {"input": "10\r\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991\r\n", "output": "10\r\n"}, {"input": "2\r\n1009 2018\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n", "output": "3\r\n"}, {"input": "7\r\n6 9 12 15 21 27 33\r\n", "output": "7\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n557 557\r\n", "output": "2\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 101 101 101\r\n", "output": "3\r\n"}, {"input": "2\r\n122 3721\r\n", "output": "2\r\n"}, {"input": "2\r\n49201 98402\r\n", "output": "2\r\n"}, {"input": "2\r\n88258 44129\r\n", "output": "2\r\n"}, {"input": "2\r\n7919 47514\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n10007 20014 30021\r\n", "output": "3\r\n"}, {"input": "4\r\n10 10 5 5\r\n", "output": "4\r\n"}, {"input": "2\r\n6 9\r\n", "output": "2\r\n"}, {"input": "3\r\n6 12 9\r\n", "output": "3\r\n"}, {"input": "2\r\n14 7\r\n", "output": "2\r\n"}, {"input": "2\r\n199 199\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 49999 99998\r\n", "output": "3\r\n"}, {"input": "5\r\n1009 1009 1009 1009 1009\r\n", "output": "5\r\n"}, {"input": "3\r\n17 17 17\r\n", "output": "3\r\n"}, {"input": "2\r\n503 1509\r\n", "output": "2\r\n"}, {"input": "3\r\n49999 99998 99998\r\n", "output": "3\r\n"}, {"input": "2\r\n28657 28657\r\n", "output": "2\r\n"}, {"input": "3\r\n121 22 33\r\n", "output": "3\r\n"}, {"input": "2\r\n10079 20158\r\n", "output": "2\r\n"}, {"input": "2\r\n6 15\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 3\r\n", "output": "4\r\n"}, {"input": "2\r\n991 1982\r\n", "output": "2\r\n"}, {"input": "3\r\n20362 30543 50905\r\n", "output": "3\r\n"}, {"input": "2\r\n443 886\r\n", "output": "2\r\n"}, {"input": "4\r\n3 7 7 21\r\n", "output": "3\r\n"}, {"input": "3\r\n3 6 9\r\n", "output": "3\r\n"}, {"input": "2\r\n217 31\r\n", "output": "2\r\n"}, {"input": "6\r\n10 10 10 5 5 5\r\n", "output": "6\r\n"}, {"input": "4\r\n49441 25225 9081 4036\r\n", "output": "4\r\n"}, {"input": "2\r\n4 9\r\n", "output": "1\r\n"}, {"input": "2\r\n18 27\r\n", "output": "2\r\n"}, {"input": "2\r\n13 26\r\n", "output": "2\r\n"}, {"input": "4\r\n6 6 6 15\r\n", "output": "4\r\n"}]
| 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 = True
distance = {0, abs(a[0]-value)}
for i in a:
if abs(i - value) not in distance:
equal_distance = False
break
if equal_distance:
break
if equal_distance:
print("YES")
else:
print("NO")
| 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]))):
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 from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
|
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": "4\r\n1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 4 7\r\n", "output": "YES\r\n"}, {"input": "3\r\n99999999 1 50000000\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 2 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 5 11\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n100000001 100000003\r\n", "output": "YES\r\n"}, {"input": "3\r\n7 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 100 29\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 5 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 6 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 1 1 1 1 2 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 4 4 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 2 4 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 9 10\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 1 1 1 1 1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 15 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 6 7 8 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 6 8\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 6 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n10 20 21 30\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 2 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 6 12\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0 1 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 5 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 4 5 6\r\n", "output": "NO\r\n"}]
| 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
for i in range(half,-1,-1):
if mid - li[i] == 0 or mid - li[i]== diff:
flag1 = 1
else:
flag1 = 0
break
for j in range(half+1,len(li),1):
if li[j]-mid == 0 or li[j] - mid == diff:
flag2 = 1
else:
flag2 = 0
break
if flag1==1 and flag2 ==1:
print("YES")
elif flag1==0 or flag2 ==0:
print("NO")
| 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 from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
|
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": "4\r\n1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 4 7\r\n", "output": "YES\r\n"}, {"input": "3\r\n99999999 1 50000000\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 2 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 5 11\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n100000001 100000003\r\n", "output": "YES\r\n"}, {"input": "3\r\n7 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 100 29\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 5 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 6 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 1 1 1 1 2 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 4 4 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 2 4 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 9 10\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 1 1 1 1 1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 15 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 6 7 8 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 6 8\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 6 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n10 20 21 30\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 2 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 6 12\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0 1 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 5 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 4 5 6\r\n", "output": "NO\r\n"}]
| 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)
tf = 1
else: tf = -1
else:
if f == 1:
q.append(x)
tf = 1
elif f == 0:
q[-1] = x
tf = 0
for x in q:
print(x, end = '')
|
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, then they should be separated by exactly one space
- there should be no spaces before each punctuation mark
- there should be exactly one space after each punctuation mark
It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.
|
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\n"}, {"input": "a a a a a\r\n", "output": "a a a a a\r\n"}, {"input": "ksdfk sdlfsdf sdf sdf sdf\r\n", "output": "ksdfk sdlfsdf sdf sdf sdf\r\n"}, {"input": "gdv\r\n", "output": "gdv\r\n"}, {"input": "incen q\r\n", "output": "incen q\r\n"}, {"input": "k ? gq dad\r\n", "output": "k? gq dad\r\n"}, {"input": "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb\r\n", "output": "ntomzzut! pousysvfg, rnl mcyytihe hplnqnb\r\n"}, {"input": "mck . gq dauqminf wee bazyzy humnv d pgtvx , vxntxgrkrc rg rwr, uuyweyz l\r\n", "output": "mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l\r\n"}, {"input": "jjcmhwnon taetfgdvc, ysrajurstj ! fryavybwpg hnxbnsron ,txplbmm atw?wkfhn ez mcdn tujsy wrdhw . k i lzwtxcyam fi . nyeu j\r\n", "output": "jjcmhwnon taetfgdvc, ysrajurstj! fryavybwpg hnxbnsron, txplbmm atw? wkfhn ez mcdn tujsy wrdhw. k i lzwtxcyam fi. nyeu j\r\n"}, {"input": "chcf htb flfwkosmda a qygyompixkgz ?rg? hdw f dsvqzs kxvjt ? zj zghgarwihw zgrhr xlwmhv . lycpsmdm iotv . d jhsxoogbr ! ppgrpwcrcl inw usegrtd ?fexma ? mhszrvdoa ,audsrhina epoleuq oaz hqapedl lm\r\n", "output": "chcf htb flfwkosmda a qygyompixkgz? rg? hdw f dsvqzs kxvjt? zj zghgarwihw zgrhr xlwmhv. lycpsmdm iotv. d jhsxoogbr! ppgrpwcrcl inw usegrtd? fexma? mhszrvdoa, audsrhina epoleuq oaz hqapedl lm\r\n"}, {"input": "x\r\n", "output": "x\r\n"}, {"input": "xx\r\n", "output": "xx\r\n"}, {"input": "x x\r\n", "output": "x x\r\n"}, {"input": "x,x\r\n", "output": "x, x\r\n"}, {"input": "x.x\r\n", "output": "x. x\r\n"}, {"input": "x!x\r\n", "output": "x! x\r\n"}, {"input": "x?x\r\n", "output": "x? x\r\n"}, {"input": "a!b\r\n", "output": "a! b\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "physicist ?mathematician.astronomer\r\n", "output": "physicist? mathematician. astronomer\r\n"}, {"input": "dfgdfg ? ddfgdsfg ? dsfgdsfgsdfgdsf ! dsfg . sd dsg sdg ! sdfg\r\n", "output": "dfgdfg? ddfgdsfg? dsfgdsfgsdfgdsf! dsfg. sd dsg sdg! sdfg\r\n"}, {"input": "jojo ! majo , hehehehe? jo . kok\r\n", "output": "jojo! majo, hehehehe? jo. kok\r\n"}, {"input": "adskfj,kjdf?kjadf kj!kajs f\r\n", "output": "adskfj, kjdf? kjadf kj! kajs f\r\n"}, {"input": "a , b\r\n", "output": "a, b\r\n"}, {"input": "ahmed? ahmed ? ahmed ?ahmed\r\n", "output": "ahmed? ahmed? ahmed? ahmed\r\n"}, {"input": "kjdsf, kdjf?kjdf!kj kdjf\r\n", "output": "kjdsf, kdjf? kjdf! kj kdjf\r\n"}, {"input": "italian physicist .mathematician?astronomer\r\n", "output": "italian physicist. mathematician? astronomer\r\n"}, {"input": "galileo galilei was an italian physicist , mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "z zz zz z z! z z aksz zkjsdfz kajfz z !akj , zz a z\r\n", "output": "z zz zz z z! z z aksz zkjsdfz kajfz z! akj, zz a z\r\n"}, {"input": "jojo ! maja . jaooo\r\n", "output": "jojo! maja. jaooo\r\n"}, {"input": "a ! b\r\n", "output": "a! b\r\n"}, {"input": "fff , fff\r\n", "output": "fff, fff\r\n"}, {"input": "a!a?a ! a ? a\r\n", "output": "a! a? a! a? a\r\n"}, {"input": "a!a\r\n", "output": "a! a\r\n"}, {"input": "a!a a ! a ? a ! a , a . a\r\n", "output": "a! a a! a? a! a, a. a\r\n"}, {"input": "casa?mesa, y unos de , los sapotes?l\r\n", "output": "casa? mesa, y unos de, los sapotes? l\r\n"}, {"input": "ff ! ff\r\n", "output": "ff! ff\r\n"}, {"input": "i love evgenia ! x\r\n", "output": "i love evgenia! x\r\n"}, {"input": "galileo galilei was an italian physicist ,mathematician,astronomer?asdf ?asdfff?asdf. asdf.dfd .dfdf ? df d! sdf dsfsa sdf ! asdf ? sdfsdf, dfg a ! b ?a\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer? asdf? asdfff? asdf. asdf. dfd. dfdf? df d! sdf dsfsa sdf! asdf? sdfsdf, dfg a! b? a\r\n"}, {"input": "a , a\r\n", "output": "a, a\r\n"}, {"input": "x, werwr, werwerwr we,rwer ,wer\r\n", "output": "x, werwr, werwerwr we, rwer, wer\r\n"}, {"input": "abcabc, abcabc\r\n", "output": "abcabc, abcabc\r\n"}, {"input": "i love evgenia x! x\r\n", "output": "i love evgenia x! x\r\n"}, {"input": "gg gg,h,h,j,i,jh , jjj , jj ,aadd , jjj jjj\r\n", "output": "gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj\r\n"}, {"input": "mt test ! case\r\n", "output": "mt test! case\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "asdasdasd.asdasdasdasd?asdasdasd!asdasdasd,asdasdasdasd\r\n", "output": "asdasdasd. asdasdasdasd? asdasdasd! asdasdasd, asdasdasdasd\r\n"}, {"input": "x, x, ds ,ertert, ert, et et\r\n", "output": "x, x, ds, ertert, ert, et et\r\n"}, {"input": "anton!love ?yourself\r\n", "output": "anton! love? yourself\r\n"}, {"input": "facepalm ? yes , lol ! yeah\r\n", "output": "facepalm? yes, lol! yeah\r\n"}, {"input": "a ! a\r\n", "output": "a! a\r\n"}, {"input": "adf!kadjf?kajdf,lkdas. kd ! akdjf\r\n", "output": "adf! kadjf? kajdf, lkdas. kd! akdjf\r\n"}, {"input": "a? x\r\n", "output": "a? x\r\n"}, {"input": "read problem carefully ! heh\r\n", "output": "read problem carefully! heh\r\n"}, {"input": "a?a?a?a.a\r\n", "output": "a? a? a? a. a\r\n"}, {"input": "a. v\r\n", "output": "a. v\r\n"}, {"input": "a!a a ! a ? a ! a , a . a aaaaaa ! a ! a. a a .a a.a aa.aa aa . aa aa .aa aa. aa\r\n", "output": "a! a a! a? a! a, a. a aaaaaa! a! a. a a. a a. a aa. aa aa. aa aa. aa aa. aa\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "a!a!a\r\n", "output": "a! a! a\r\n"}, {"input": "a.a.a.a\r\n", "output": "a. a. a. a\r\n"}, {"input": "a, b\r\n", "output": "a, b\r\n"}, {"input": "galileo galilei was an italian physicist, mathematician, astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "a!a!a!a\r\n", "output": "a! a! a! a\r\n"}, {"input": "af ! kadjf ? kjdfkj!kjadkfjz z z a a! ka,kjf\r\n", "output": "af! kadjf? kjdfkj! kjadkfjz z z a a! ka, kjf\r\n"}, {"input": "ab cd,k\r\n", "output": "ab cd, k\r\n"}, {"input": "a!n , to\r\n", "output": "a! n, to\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "u, sux\r\n", "output": "u, sux\r\n"}]
| 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-=1
if temp==-1:
break
ans=[]
index=0
for i in range(len(b)):
temp=pre[i]
index=max(i+1,index)
start=index
for j in range(start,len(b)):
if suf[j]>pre[i]:
index=j
break
else:
index=len(a)
if index!=len(a) and pre[i]!=len(a):
ans+=[len(b)+1+i-index]
elif pre[i]==len(a):
ans+=[0]
elif index==len(a) and pre[i]!=len(a):
ans+=[i+1]
else:
ans+=[0]
MAXsufANS=0
MAXsufindex=len(b)
for i in range(len(b)-1,-1,-1):
if suf[i]!=-1:
MAXsufANS=len(b)-i
MAXsufindex=i
MAX=0
MAXindex=-1
for i in range(len(b)):
if ans[i]>MAX:
MAXindex=i
MAX=ans[i]
usesuf=0
if MAXsufANS>MAX:
usesuf=1
if MAXindex==-1:
print('-')
else:
if usesuf==1:
anss=b[MAXsufindex:]
print(anss)
else:
m=MAXindex
L=MAX
anss=b[:m+1]+b[len(b)-(MAX-(m+1)):]
print(anss)
| 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 the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
|
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\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk\r\n", "output": "ouypvk\r\n"}, {"input": "npnkmawey\r\nareakefvowledfriyjejqnnaeqheoh\r\n", "output": "a\r\n"}, {"input": "fdtffutxkujflswyddvhusfcook\r\nkavkhnhphcvckogqqqqhdmgwjdfenzizrebefsbuhzzwhzvc\r\n", "output": "kvc\r\n"}, {"input": "abacaba\r\naa\r\n", "output": "aa\r\n"}, {"input": "edbcd\r\nd\r\n", "output": "d\r\n"}, {"input": "abc\r\nksdksdsdsnabc\r\n", "output": "abc\r\n"}, {"input": "abxzxzxzzaba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abcd\r\nzzhabcd\r\n", "output": "abcd\r\n"}, {"input": "aa\r\naa\r\n", "output": "aa\r\n"}, {"input": "test\r\nt\r\n", "output": "t\r\n"}, {"input": "aa\r\na\r\n", "output": "a\r\n"}, {"input": "aaaabbbbaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "aa\r\nzzaa\r\n", "output": "aa\r\n"}, {"input": "zhbt\r\nztjihmhebkrztefpwty\r\n", "output": "zt\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaa\r\naaaaaaaa\r\n", "output": "aaaaaaaa\r\n"}, {"input": "abba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abbba\r\naba\r\n", "output": "aba\r\n"}, {"input": "aaaaaaaaaaaa\r\naaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaa\r\n"}, {"input": "aaa\r\naa\r\n", "output": "aa\r\n"}, {"input": "aaaaaaaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "aaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "ashfaniosafapisfasipfaspfaspfaspfapsfjpasfshvcmvncxmvnxcvnmcxvnmxcnvmcvxvnxmcvxcmvh\r\nashish\r\n", "output": "ashish\r\n"}, {"input": "a\r\na\r\n", "output": "a\r\n"}, {"input": "aaaab\r\naab\r\n", "output": "aab\r\n"}, {"input": "aaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "a\r\naaa\r\n", "output": "a\r\n"}, {"input": "aaaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "def\r\nabcdef\r\n", "output": "def\r\n"}, {"input": "aaaaaaaaa\r\na\r\n", "output": "a\r\n"}, {"input": "bababsbs\r\nabs\r\n", "output": "abs\r\n"}, {"input": "hddddddack\r\nhackyz\r\n", "output": "hack\r\n"}, {"input": "aba\r\na\r\n", "output": "a\r\n"}, {"input": "ofih\r\nihfsdf\r\n", "output": "ih\r\n"}, {"input": "b\r\nabb\r\n", "output": "b\r\n"}, {"input": "lctsczqr\r\nqvkp\r\n", "output": "q\r\n"}, {"input": "dedcbaa\r\ndca\r\n", "output": "dca\r\n"}, {"input": "haddack\r\nhack\r\n", "output": "hack\r\n"}, {"input": "abcabc\r\nabc\r\n", "output": "abc\r\n"}, {"input": "asdf\r\ngasdf\r\n", "output": "asdf\r\n"}, {"input": "abab\r\nab\r\n", "output": "ab\r\n"}, {"input": "aaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "asdf\r\nfasdf\r\n", "output": "asdf\r\n"}, {"input": "bbaabb\r\nab\r\n", "output": "ab\r\n"}, {"input": "accac\r\nbaacccbcccabaabbcacbbcccacbaabaaac\r\n", "output": "aac\r\n"}, {"input": "az\r\naaazazaa\r\n", "output": "a\r\n"}, {"input": "bbacaabbaaa\r\nacaabcaa\r\n", "output": "acaabaa\r\n"}, {"input": "c\r\ncbcbcbbacacacbccaaccbcabaaabbaaa\r\n", "output": "c\r\n"}, {"input": "bacb\r\nccacacbacbccbbccccaccccccbcbabbbaababa\r\n", "output": "ba\r\n"}, {"input": "ac\r\naacacaacbaaacbbbabacaca\r\n", "output": "a\r\n"}, {"input": "a\r\nzazaa\r\n", "output": "a\r\n"}, {"input": "abcd\r\nfaaaabbbbccccdddeda\r\n", "output": "a\r\n"}, {"input": "abcde\r\nfabcde\r\n", "output": "abcde\r\n"}, {"input": "a\r\nab\r\n", "output": "a\r\n"}, {"input": "ababbbbbbbbbbbb\r\nabbbbb\r\n", "output": "abbbbb\r\n"}, {"input": "bbbbaabbababbaaaaababbaaabbbbaaabbbababbbbabaabababaabaaabbbabababbbabababaababaaaaa\r\nbbabaaaabaaaabbaaabbbabaaabaabbbababbbbbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n", "output": "bbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n"}, {"input": "ab\r\naba\r\n", "output": "ab\r\n"}, {"input": "aa\r\naaaa\r\n", "output": "aa\r\n"}, {"input": "aaaaabbbaaaaa\r\naabbaa\r\n", "output": "aabbaa\r\n"}, {"input": "aaaaaaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "abbcc\r\naca\r\n", "output": "ac\r\n"}, {"input": "b\r\ncb\r\n", "output": "b\r\n"}, {"input": "aac\r\naaa\r\n", "output": "aa\r\n"}, {"input": "ba\r\nbb\r\n", "output": "b\r\n"}, {"input": "a\r\nb\r\n", "output": "-\r\n"}, {"input": "gkvubrvpbhsfiuyha\r\nihotmn\r\n", "output": "ih\r\n"}, {"input": "ccccabccbb\r\ncbbabcc\r\n", "output": "cabcc\r\n"}, {"input": "babababbaaabb\r\nabbab\r\n", "output": "abbab\r\n"}, {"input": "njtdhyqundyedsjyvy\r\nypjrs\r\n", "output": "ys\r\n"}, {"input": "uglyqhkpruxoakm\r\ncixxkpaaoodpuuh\r\n", "output": "uh\r\n"}, {"input": "a\r\naaaaaaaaa\r\n", "output": "a\r\n"}, {"input": "aaa\r\naaaaa\r\n", "output": "aaa\r\n"}, {"input": "abcabbcbcccbccbbcc\r\nacbcaabbbbcabbbaca\r\n", "output": "acbc\r\n"}, {"input": "caacacaacbaa\r\nacbbbabacacac\r\n", "output": "aacacac\r\n"}, {"input": "aa\r\naaab\r\n", "output": "aa\r\n"}, {"input": "acbc\r\ncacacbac\r\n", "output": "ac\r\n"}, {"input": "bacbcaacabbaacb\r\ncbbaaccccbcaacacaabb\r\n", "output": "cbcaabb\r\n"}, {"input": "baababaaaab\r\nbaababbbbbbb\r\n", "output": "baababb\r\n"}, {"input": "aaxyaba\r\naaba\r\n", "output": "aaba\r\n"}]
| 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())
else:
print('-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 on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
|
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 ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
|
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-th flat.
|
[{"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\n"}, {"input": "16 6\r\n3 1\r\n16 4\r\n10 3\r\n9 3\r\n19 5\r\n8 2\r\n", "output": "4\r\n"}, {"input": "1 0\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 2\r\n1 1\r\n2 2\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n3 3\r\n", "output": "2\r\n"}, {"input": "3 2\r\n1 1\r\n3 3\r\n", "output": "3\r\n"}, {"input": "3 3\r\n1 1\r\n3 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "2 3\r\n3 2\r\n1 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3 0\r\n", "output": "-1\r\n"}, {"input": "3 1\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n1 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "1 3\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "1\r\n"}, {"input": "81 0\r\n", "output": "-1\r\n"}, {"input": "22 1\r\n73 73\r\n", "output": "22\r\n"}, {"input": "63 2\r\n10 10\r\n64 64\r\n", "output": "63\r\n"}, {"input": "88 3\r\n37 37\r\n15 15\r\n12 12\r\n", "output": "88\r\n"}, {"input": "29 4\r\n66 66\r\n47 47\r\n62 62\r\n2 2\r\n", "output": "29\r\n"}, {"input": "9 40\r\n72 72\r\n47 47\r\n63 63\r\n66 66\r\n21 21\r\n94 94\r\n28 28\r\n45 45\r\n93 93\r\n25 25\r\n100 100\r\n43 43\r\n49 49\r\n9 9\r\n74 74\r\n26 26\r\n42 42\r\n50 50\r\n2 2\r\n92 92\r\n76 76\r\n3 3\r\n78 78\r\n44 44\r\n69 69\r\n36 36\r\n65 65\r\n81 81\r\n13 13\r\n46 46\r\n24 24\r\n96 96\r\n73 73\r\n82 82\r\n68 68\r\n64 64\r\n41 41\r\n31 31\r\n29 29\r\n10 10\r\n", "output": "9\r\n"}, {"input": "50 70\r\n3 3\r\n80 80\r\n23 23\r\n11 11\r\n87 87\r\n7 7\r\n63 63\r\n61 61\r\n67 67\r\n53 53\r\n9 9\r\n43 43\r\n55 55\r\n27 27\r\n5 5\r\n1 1\r\n99 99\r\n65 65\r\n37 37\r\n60 60\r\n32 32\r\n38 38\r\n81 81\r\n2 2\r\n34 34\r\n17 17\r\n82 82\r\n26 26\r\n71 71\r\n4 4\r\n16 16\r\n19 19\r\n39 39\r\n51 51\r\n6 6\r\n49 49\r\n64 64\r\n83 83\r\n10 10\r\n56 56\r\n30 30\r\n76 76\r\n90 90\r\n42 42\r\n47 47\r\n91 91\r\n21 21\r\n52 52\r\n40 40\r\n77 77\r\n35 35\r\n88 88\r\n75 75\r\n95 95\r\n28 28\r\n15 15\r\n69 69\r\n22 22\r\n48 48\r\n66 66\r\n31 31\r\n98 98\r\n73 73\r\n25 25\r\n97 97\r\n18 18\r\n13 13\r\n54 54\r\n72 72\r\n29 29\r\n", "output": "50\r\n"}, {"input": "6 0\r\n", "output": "-1\r\n"}, {"input": "32 1\r\n9 5\r\n", "output": "16\r\n"}, {"input": "73 2\r\n17 9\r\n21 11\r\n", "output": "37\r\n"}, {"input": "6 3\r\n48 24\r\n51 26\r\n62 31\r\n", "output": "3\r\n"}, {"input": "43 4\r\n82 41\r\n52 26\r\n88 44\r\n41 21\r\n", "output": "22\r\n"}, {"input": "28 40\r\n85 43\r\n19 10\r\n71 36\r\n39 20\r\n57 29\r\n6 3\r\n15 8\r\n11 6\r\n99 50\r\n77 39\r\n79 40\r\n31 16\r\n35 18\r\n24 12\r\n54 27\r\n93 47\r\n90 45\r\n72 36\r\n63 32\r\n22 11\r\n83 42\r\n5 3\r\n12 6\r\n56 28\r\n94 47\r\n25 13\r\n41 21\r\n29 15\r\n36 18\r\n23 12\r\n1 1\r\n84 42\r\n55 28\r\n58 29\r\n9 5\r\n68 34\r\n86 43\r\n3 2\r\n48 24\r\n98 49\r\n", "output": "14\r\n"}, {"input": "81 70\r\n55 28\r\n85 43\r\n58 29\r\n20 10\r\n4 2\r\n47 24\r\n42 21\r\n28 14\r\n26 13\r\n38 19\r\n9 5\r\n83 42\r\n7 4\r\n72 36\r\n18 9\r\n61 31\r\n41 21\r\n64 32\r\n90 45\r\n46 23\r\n67 34\r\n2 1\r\n6 3\r\n27 14\r\n87 44\r\n39 20\r\n11 6\r\n21 11\r\n35 18\r\n48 24\r\n44 22\r\n3 2\r\n71 36\r\n62 31\r\n34 17\r\n16 8\r\n99 50\r\n57 29\r\n13 7\r\n79 40\r\n100 50\r\n53 27\r\n89 45\r\n36 18\r\n43 22\r\n92 46\r\n98 49\r\n75 38\r\n40 20\r\n97 49\r\n37 19\r\n68 34\r\n30 15\r\n96 48\r\n17 9\r\n12 6\r\n45 23\r\n65 33\r\n76 38\r\n84 42\r\n23 12\r\n91 46\r\n52 26\r\n8 4\r\n32 16\r\n77 39\r\n88 44\r\n86 43\r\n70 35\r\n51 26\r\n", "output": "41\r\n"}, {"input": "34 0\r\n", "output": "-1\r\n"}, {"input": "63 1\r\n94 24\r\n", "output": "16\r\n"}, {"input": "4 2\r\n38 10\r\n48 12\r\n", "output": "1\r\n"}, {"input": "37 3\r\n66 17\r\n89 23\r\n60 15\r\n", "output": "10\r\n"}, {"input": "71 4\r\n15 4\r\n13 4\r\n4 1\r\n70 18\r\n", "output": "18\r\n"}, {"input": "77 40\r\n49 13\r\n66 17\r\n73 19\r\n15 4\r\n36 9\r\n1 1\r\n41 11\r\n91 23\r\n51 13\r\n46 12\r\n39 10\r\n42 11\r\n56 14\r\n61 16\r\n70 18\r\n92 23\r\n65 17\r\n54 14\r\n97 25\r\n8 2\r\n87 22\r\n33 9\r\n28 7\r\n38 10\r\n50 13\r\n26 7\r\n7 2\r\n31 8\r\n84 21\r\n47 12\r\n27 7\r\n53 14\r\n19 5\r\n93 24\r\n29 8\r\n3 1\r\n77 20\r\n62 16\r\n9 3\r\n44 11\r\n", "output": "20\r\n"}, {"input": "18 70\r\n51 13\r\n55 14\r\n12 3\r\n43 11\r\n42 11\r\n95 24\r\n96 24\r\n29 8\r\n65 17\r\n71 18\r\n18 5\r\n62 16\r\n31 8\r\n100 25\r\n4 1\r\n77 20\r\n56 14\r\n24 6\r\n93 24\r\n97 25\r\n79 20\r\n40 10\r\n49 13\r\n86 22\r\n21 6\r\n46 12\r\n6 2\r\n14 4\r\n23 6\r\n20 5\r\n52 13\r\n88 22\r\n39 10\r\n70 18\r\n94 24\r\n13 4\r\n37 10\r\n41 11\r\n91 23\r\n85 22\r\n83 21\r\n89 23\r\n33 9\r\n64 16\r\n67 17\r\n57 15\r\n47 12\r\n36 9\r\n72 18\r\n81 21\r\n76 19\r\n35 9\r\n80 20\r\n34 9\r\n5 2\r\n22 6\r\n84 21\r\n63 16\r\n74 19\r\n90 23\r\n68 17\r\n98 25\r\n87 22\r\n2 1\r\n92 23\r\n50 13\r\n38 10\r\n28 7\r\n8 2\r\n60 15\r\n", "output": "5\r\n"}, {"input": "89 0\r\n", "output": "-1\r\n"}, {"input": "30 1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "63 2\r\n48 6\r\n17 3\r\n", "output": "8\r\n"}, {"input": "96 3\r\n45 6\r\n25 4\r\n35 5\r\n", "output": "12\r\n"}, {"input": "37 4\r\n2 1\r\n29 4\r\n27 4\r\n47 6\r\n", "output": "5\r\n"}, {"input": "64 40\r\n40 5\r\n92 12\r\n23 3\r\n75 10\r\n71 9\r\n2 1\r\n54 7\r\n18 3\r\n9 2\r\n74 10\r\n87 11\r\n11 2\r\n90 12\r\n30 4\r\n48 6\r\n12 2\r\n91 12\r\n60 8\r\n35 5\r\n13 2\r\n53 7\r\n46 6\r\n38 5\r\n59 8\r\n97 13\r\n32 4\r\n6 1\r\n36 5\r\n43 6\r\n83 11\r\n81 11\r\n99 13\r\n69 9\r\n10 2\r\n21 3\r\n78 10\r\n31 4\r\n27 4\r\n57 8\r\n1 1\r\n", "output": "8\r\n"}, {"input": "17 70\r\n63 8\r\n26 4\r\n68 9\r\n30 4\r\n61 8\r\n84 11\r\n39 5\r\n53 7\r\n4 1\r\n81 11\r\n50 7\r\n91 12\r\n59 8\r\n90 12\r\n20 3\r\n21 3\r\n83 11\r\n94 12\r\n37 5\r\n8 1\r\n49 7\r\n34 5\r\n19 3\r\n44 6\r\n74 10\r\n2 1\r\n73 10\r\n88 11\r\n43 6\r\n36 5\r\n57 8\r\n64 8\r\n76 10\r\n40 5\r\n71 9\r\n95 12\r\n15 2\r\n41 6\r\n89 12\r\n42 6\r\n96 12\r\n1 1\r\n52 7\r\n38 5\r\n45 6\r\n78 10\r\n82 11\r\n16 2\r\n48 6\r\n51 7\r\n56 7\r\n28 4\r\n87 11\r\n93 12\r\n46 6\r\n29 4\r\n97 13\r\n54 7\r\n35 5\r\n3 1\r\n79 10\r\n99 13\r\n13 2\r\n55 7\r\n100 13\r\n11 2\r\n75 10\r\n24 3\r\n33 5\r\n22 3\r\n", "output": "3\r\n"}, {"input": "9 0\r\n", "output": "-1\r\n"}, {"input": "50 1\r\n31 2\r\n", "output": "-1\r\n"}, {"input": "79 2\r\n11 1\r\n22 2\r\n", "output": "-1\r\n"}, {"input": "16 3\r\n100 7\r\n94 6\r\n3 1\r\n", "output": "1\r\n"}, {"input": "58 4\r\n73 5\r\n52 4\r\n69 5\r\n3 1\r\n", "output": "4\r\n"}, {"input": "25 40\r\n70 5\r\n28 2\r\n60 4\r\n54 4\r\n33 3\r\n21 2\r\n51 4\r\n20 2\r\n44 3\r\n79 5\r\n65 5\r\n1 1\r\n52 4\r\n23 2\r\n38 3\r\n92 6\r\n63 4\r\n3 1\r\n91 6\r\n5 1\r\n64 4\r\n34 3\r\n25 2\r\n97 7\r\n89 6\r\n61 4\r\n71 5\r\n88 6\r\n29 2\r\n56 4\r\n45 3\r\n6 1\r\n53 4\r\n57 4\r\n90 6\r\n76 5\r\n8 1\r\n46 3\r\n73 5\r\n87 6\r\n", "output": "2\r\n"}, {"input": "78 70\r\n89 6\r\n52 4\r\n87 6\r\n99 7\r\n3 1\r\n25 2\r\n46 3\r\n78 5\r\n35 3\r\n68 5\r\n85 6\r\n23 2\r\n60 4\r\n88 6\r\n17 2\r\n8 1\r\n15 1\r\n67 5\r\n95 6\r\n59 4\r\n94 6\r\n31 2\r\n4 1\r\n16 1\r\n10 1\r\n97 7\r\n42 3\r\n2 1\r\n24 2\r\n34 3\r\n37 3\r\n70 5\r\n18 2\r\n41 3\r\n48 3\r\n58 4\r\n20 2\r\n38 3\r\n72 5\r\n50 4\r\n49 4\r\n40 3\r\n61 4\r\n6 1\r\n45 3\r\n28 2\r\n13 1\r\n27 2\r\n96 6\r\n56 4\r\n91 6\r\n77 5\r\n12 1\r\n11 1\r\n53 4\r\n76 5\r\n74 5\r\n82 6\r\n55 4\r\n80 5\r\n14 1\r\n44 3\r\n7 1\r\n83 6\r\n79 5\r\n92 6\r\n66 5\r\n36 3\r\n73 5\r\n100 7\r\n", "output": "5\r\n"}, {"input": "95 0\r\n", "output": "-1\r\n"}, {"input": "33 1\r\n30 1\r\n", "output": "-1\r\n"}, {"input": "62 2\r\n14 1\r\n15 1\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n6 1\r\n25 1\r\n38 2\r\n", "output": "1\r\n"}, {"input": "44 4\r\n72 3\r\n80 3\r\n15 1\r\n36 2\r\n", "output": "2\r\n"}, {"input": "34 40\r\n25 1\r\n28 1\r\n78 3\r\n5 1\r\n13 1\r\n75 3\r\n15 1\r\n67 3\r\n57 2\r\n23 1\r\n26 1\r\n61 2\r\n22 1\r\n48 2\r\n85 3\r\n24 1\r\n82 3\r\n83 3\r\n53 2\r\n38 2\r\n19 1\r\n33 2\r\n69 3\r\n17 1\r\n79 3\r\n54 2\r\n77 3\r\n97 4\r\n20 1\r\n35 2\r\n14 1\r\n18 1\r\n71 3\r\n21 1\r\n36 2\r\n56 2\r\n44 2\r\n63 2\r\n72 3\r\n32 1\r\n", "output": "2\r\n"}, {"input": "83 70\r\n79 3\r\n49 2\r\n2 1\r\n44 2\r\n38 2\r\n77 3\r\n86 3\r\n31 1\r\n83 3\r\n82 3\r\n35 2\r\n7 1\r\n78 3\r\n23 1\r\n39 2\r\n58 2\r\n1 1\r\n87 3\r\n72 3\r\n20 1\r\n48 2\r\n14 1\r\n13 1\r\n6 1\r\n70 3\r\n55 2\r\n52 2\r\n25 1\r\n11 1\r\n61 2\r\n76 3\r\n95 3\r\n32 1\r\n66 3\r\n29 1\r\n9 1\r\n5 1\r\n3 1\r\n88 3\r\n59 2\r\n96 3\r\n10 1\r\n63 2\r\n40 2\r\n42 2\r\n34 2\r\n43 2\r\n19 1\r\n89 3\r\n94 3\r\n24 1\r\n98 4\r\n12 1\r\n30 1\r\n69 3\r\n17 1\r\n50 2\r\n8 1\r\n93 3\r\n16 1\r\n97 4\r\n54 2\r\n71 3\r\n18 1\r\n33 2\r\n80 3\r\n15 1\r\n99 4\r\n75 3\r\n4 1\r\n", "output": "3\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}, {"input": "36 1\r\n96 1\r\n", "output": "1\r\n"}, {"input": "73 2\r\n34 1\r\n4 1\r\n", "output": "-1\r\n"}, {"input": "6 3\r\n37 1\r\n22 1\r\n70 1\r\n", "output": "1\r\n"}, {"input": "47 4\r\n66 1\r\n57 1\r\n85 1\r\n47 1\r\n", "output": "1\r\n"}, {"input": "9 40\r\n73 1\r\n21 1\r\n37 1\r\n87 1\r\n33 1\r\n69 1\r\n49 1\r\n19 1\r\n35 1\r\n93 1\r\n71 1\r\n43 1\r\n79 1\r\n85 1\r\n29 1\r\n72 1\r\n76 1\r\n47 1\r\n17 1\r\n67 1\r\n95 1\r\n41 1\r\n54 1\r\n88 1\r\n42 1\r\n80 1\r\n98 1\r\n96 1\r\n10 1\r\n24 1\r\n78 1\r\n18 1\r\n3 1\r\n91 1\r\n2 1\r\n15 1\r\n5 1\r\n60 1\r\n36 1\r\n46 1\r\n", "output": "1\r\n"}, {"input": "63 70\r\n82 1\r\n53 1\r\n57 1\r\n46 1\r\n97 1\r\n19 1\r\n36 1\r\n90 1\r\n23 1\r\n88 1\r\n68 1\r\n45 1\r\n2 1\r\n70 1\r\n86 1\r\n8 1\r\n83 1\r\n40 1\r\n99 1\r\n42 1\r\n32 1\r\n52 1\r\n81 1\r\n50 1\r\n77 1\r\n37 1\r\n54 1\r\n75 1\r\n4 1\r\n49 1\r\n73 1\r\n22 1\r\n21 1\r\n98 1\r\n18 1\r\n51 1\r\n14 1\r\n76 1\r\n92 1\r\n80 1\r\n78 1\r\n33 1\r\n79 1\r\n89 1\r\n67 1\r\n9 1\r\n44 1\r\n60 1\r\n64 1\r\n55 1\r\n29 1\r\n100 1\r\n16 1\r\n87 1\r\n10 1\r\n12 1\r\n25 1\r\n85 1\r\n30 1\r\n63 1\r\n39 1\r\n38 1\r\n31 1\r\n5 1\r\n26 1\r\n91 1\r\n43 1\r\n72 1\r\n48 1\r\n94 1\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "-1\r\n"}]
| 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):
if b[i] != b[i + 1]:
if a[i + 2] - a[i] > 1 or a[i + 1] - a[i - 1] > 1:
ans = max(ans, b[i] + b[i + 1])
print(min(ans, len(a)))
| 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().split())
li = lambda :list(mi())
ii = lambda :int(input())
py = lambda :print("YES")
pn = lambda :print("NO")
n=ii()
a=li()
l=[0]*n
r=[0]*n
for i in range(1,n):
if i==1:
l[i]=1
elif a[i-1]>a[i-2]:
l[i]=l[i-1]+1
else:
l[i]=1
for i in range(n-2,-1,-1):
if i==n-2:
r[i]=1
elif a[i+1]<a[i+2]:
r[i]=r[i+1]+1
else:
r[i]=1
res=0
for i in range(n):
if i==0 or i==n-1 or a[i+1]-a[i-1]>1:
res=max(res,l[i]+r[i]+1)
res=max(res,l[i]+1,r[i]+1)
print(res)
|
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 number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find.
|
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 25202363 350490028 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737 35005212 521595369 294702568 726956430 336465783 861021531 59961394 89018457 101513930 125898168 131176230 145174068 233665124 278722863 315634023 369133070 468703136 628175012 635723059 653377374 656478043 801979803 859484422 914544920 608413785 756898538 734575199 973594325 149798316 38664371\r\n", "output": "19\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 3 4 1\r\n", "output": "5\r\n"}, {"input": "10\r\n1 2 3 4 5 5 6 7 8 9\r\n", "output": "6\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "5\r\n1 1 2 3 4\r\n", "output": "5\r\n"}, {"input": "5\r\n1 2 3 1 6\r\n", "output": "5\r\n"}, {"input": "1\r\n42\r\n", "output": "1\r\n"}, {"input": "5\r\n1 2 42 3 4\r\n", "output": "4\r\n"}, {"input": "5\r\n1 5 9 6 10\r\n", "output": "4\r\n"}, {"input": "5\r\n5 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 3 3 4\r\n", "output": "4\r\n"}, {"input": "8\r\n1 2 3 4 1 5 6 7\r\n", "output": "5\r\n"}, {"input": "1\r\n3\r\n", "output": "1\r\n"}, {"input": "3\r\n5 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 3 4\r\n", "output": "4\r\n"}, {"input": "6\r\n7 2 12 4 5 6\r\n", "output": "5\r\n"}, {"input": "6\r\n7 2 3 1 4 5\r\n", "output": "4\r\n"}, {"input": "6\r\n2 3 5 5 6 7\r\n", "output": "6\r\n"}, {"input": "5\r\n2 4 7 6 8\r\n", "output": "5\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "3\r\n"}, {"input": "2\r\n1 2\r\n", "output": "2\r\n"}, {"input": "5\r\n4 1 2 3 4\r\n", "output": "5\r\n"}, {"input": "20\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6\r\n", "output": "7\r\n"}, {"input": "4\r\n1 2 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n4 3 1 2\r\n", "output": "3\r\n"}, {"input": "6\r\n1 2 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n5 1 2 3\r\n", "output": "4\r\n"}, {"input": "5\r\n9 1 2 3 4\r\n", "output": "5\r\n"}, {"input": "2\r\n1 1\r\n", "output": "2\r\n"}, {"input": "5\r\n1 3 2 4 5\r\n", "output": "4\r\n"}, {"input": "6\r\n1 2 1 2 4 5\r\n", "output": "5\r\n"}, {"input": "10\r\n1 1 5 3 2 9 9 7 7 6\r\n", "output": "3\r\n"}, {"input": "6\r\n1 2 3 100000 100 101\r\n", "output": "6\r\n"}, {"input": "4\r\n3 3 3 4\r\n", "output": "3\r\n"}, {"input": "3\r\n4 3 5\r\n", "output": "3\r\n"}, {"input": "5\r\n1 3 2 3 4\r\n", "output": "4\r\n"}, {"input": "10\r\n1 2 3 4 5 10 10 11 12 13\r\n", "output": "10\r\n"}, {"input": "7\r\n11 2 1 2 13 4 14\r\n", "output": "5\r\n"}, {"input": "3\r\n5 1 3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 5 3 4\r\n", "output": "4\r\n"}, {"input": "10\r\n1 2 3 4 100 6 7 8 9 10\r\n", "output": "10\r\n"}, {"input": "3\r\n5 3 5\r\n", "output": "3\r\n"}, {"input": "5\r\n100 100 7 8 9\r\n", "output": "4\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5\r\n1 2 4 4 5\r\n", "output": "5\r\n"}, {"input": "6\r\n7 4 5 6 7 8\r\n", "output": "6\r\n"}, {"input": "9\r\n3 4 1 6 3 4 5 6 7\r\n", "output": "7\r\n"}, {"input": "3\r\n1000 1 2\r\n", "output": "3\r\n"}, {"input": "3\r\n20 1 9\r\n", "output": "3\r\n"}, {"input": "6\r\n7 2 3 1 4 6\r\n", "output": "4\r\n"}, {"input": "3\r\n100 5 10\r\n", "output": "3\r\n"}, {"input": "4\r\n2 2 2 3\r\n", "output": "3\r\n"}, {"input": "6\r\n4 2 8 1 2 5\r\n", "output": "4\r\n"}, {"input": "3\r\n25 1 6\r\n", "output": "3\r\n"}, {"input": "10\r\n17 99 23 72 78 36 5 43 95 9\r\n", "output": "5\r\n"}, {"input": "7\r\n21 16 22 21 11 13 19\r\n", "output": "4\r\n"}, {"input": "5\r\n1 2 5 3 4\r\n", "output": "4\r\n"}, {"input": "6\r\n2 2 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 1 2 3\r\n", "output": "4\r\n"}, {"input": "3\r\n81 33 64\r\n", "output": "3\r\n"}, {"input": "7\r\n14 3 3 19 13 19 15\r\n", "output": "4\r\n"}, {"input": "9\r\n1 2 3 4 5 42 7 8 9\r\n", "output": "9\r\n"}, {"input": "5\r\n2 3 7 5 6\r\n", "output": "5\r\n"}, {"input": "5\r\n1 3 3 4 5\r\n", "output": "5\r\n"}, {"input": "6\r\n1 5 4 3 4 5\r\n", "output": "4\r\n"}]
| 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 lenght 3
inv = defaultdict(list)
ii = [-1, -1, -1]
for i in range(n):
# inv[i] is a list of sets
a = grid[i]
swaps = 0
seen = [False for _ in range(m)]
# iterate and generate cycles
for j in range(m-1):
if seen[j] or a[j] == j+1:
continue
cycle = 0
k = j
inv[i].append(set())
while not seen[k]:
seen[k] = True
if not seen[a[k] - 1]:
inv[i][-1].add((k, a[k] - 1))
k = a[k] - 1
cycle += 1
swaps += cycle - 1
if swaps > 2:
print("NO")
return 0
ii[swaps] = i
# no 2s -> YES
if ii[2] == -1:
print("YES")
return 0
for a in range(m):
for b in range(a + 1, m):
# (a, b) is the candidate to swap for all
ans = True
for i in range(n):
if len(inv[i]) == 0:
continue
cur = False
for cycle in inv[i]:
if (a, b) in cycle:
cur = True
break
ans &= cur
if ans:
print("YES")
return 0
print("NO")
return 0
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._file = 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.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
| 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[i] != i + 1:
cnt += 1
if cnt > 2:
break
row[c1], row[c2] = row[c2], row[c1]
if cnt > 2:
ok = False
break
if ok:
print('YES')
sys.exit(0)
print('NO')
|
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 to perform from 0 to n + 1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
|
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 8 9 10\r\n", "output": "YES\r\n"}, {"input": "5 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 8 5 6 7 10 9 4 11 12\r\n1 5 3 4 2 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n", "output": "YES\r\n"}, {"input": "4 10\r\n3 2 8 10 5 6 7 1 9 4\r\n1 2 9 4 5 3 7 8 10 6\r\n7 5 3 4 8 6 1 2 9 10\r\n4 2 3 9 8 6 7 5 1 10\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n9 2 3 4 5 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 10 7 8 1 6\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n9 10 4 2 3 5 7 1 8 6\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n6 4 7 3 5 8 1 9 10 2\r\n1 5 10 6 3 4 9 7 2 8\r\n3 2 1 7 8 6 5 4 10 9\r\n7 9 1 6 8 2 4 5 3 10\r\n3 4 6 9 8 7 1 2 10 5\r\n", "output": "NO\r\n"}, {"input": "20 2\r\n1 2\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "20 3\r\n3 2 1\r\n2 3 1\r\n2 3 1\r\n2 1 3\r\n1 3 2\r\n2 1 3\r\n1 2 3\r\n3 2 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n2 1 3\r\n2 3 1\r\n2 3 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n3 1 2\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 2 3 4 5 6 7 10 9 8\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n6 9 3 4 5 1 8 7 2 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 19 14 15 16 17 18 13 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 20\r\n1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 17 18 19 20\r\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 12 18 7 8 9 10 11 5 13 14 15 16 17 6 19 20\r\n6 2 3 4 5 1 7 8 9 10 11 12 13 20 15 16 17 18 19 14\r\n4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 19 8 9 10 11 12 13 14 15 20 17 18 7 16\r\n1 2 9 4 5 6 7 8 18 10 11 12 13 14 15 16 17 3 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n4 2 3 8 5 6 7 1 9 10\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n3 2 1 4 5 6 7 8 10 9\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 18 14 15 16 17 13 11 20\r\n1 2 11 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 3 20\r\n13 2 3 4 5 6 7 8 9 10 19 12 1 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 16 8 9 10 11 12 13 14 15 7 17 18 19 20\r\n1 2 3 14 5 6 16 8 9 10 11 12 13 4 15 7 17 18 19 20\r\n1 2 3 4 5 6 16 8 18 10 11 12 13 14 15 7 17 9 19 20\r\n1 2 3 4 5 6 16 8 9 15 11 12 13 14 10 7 17 18 19 20\r\n1 2 18 4 5 6 16 8 9 10 11 12 13 14 15 7 17 3 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 18 4 5 6 7 8 9 10 11 12 13 14 15 16 19 3 17 20\r\n8 2 3 9 5 6 7 1 4 10 11 12 13 14 15 16 17 18 19 20\r\n7 2 3 4 5 6 1 8 9 10 11 12 13 14 15 16 17 20 19 18\r\n1 2 3 12 5 6 7 8 9 17 11 4 13 14 15 16 10 18 19 20\r\n1 11 3 4 9 6 7 8 5 10 2 12 13 14 15 16 17 18 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n10 2 3 4 5 9 7 8 6 1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 9 2 4 6 5 8 3 7 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 3 2 19 5 6 7 8 9 17 11 12 13 14 15 16 10 18 4 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 20 6 7 8 9 17 11 12 13 14 15 16 10 18 19 5\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 6 17 4 5 2 7 14 9 10 11 12 13 8 15 16 3 18 19 20\r\n5 6 17 4 1 2 7 8 9 10 11 12 13 14 15 16 3 18 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 18 3 16 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 16 3 18 20 19\r\n1 6 17 8 5 2 7 4 9 10 11 12 13 14 15 16 3 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n10 2 9 4 5 6 7 8 15 1 11 16 13 14 3 12 17 18 19 20\r\n10 2 3 4 5 6 7 1 9 8 11 16 13 14 15 12 17 18 19 20\r\n9 2 3 4 5 6 7 8 10 1 11 16 13 14 15 12 20 18 19 17\r\n10 2 3 4 7 6 5 8 9 1 11 16 18 14 15 12 17 13 19 20\r\n10 2 3 4 5 6 7 8 9 20 11 16 14 13 15 12 17 18 19 1\r\n", "output": "NO\r\n"}, {"input": "1 4\r\n2 3 4 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 1 3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "15 6\r\n2 1 4 3 6 5\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n4 3 1 2\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "4 8\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n", "output": "YES\r\n"}, {"input": "4 6\r\n1 2 3 5 6 4\r\n3 2 1 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n3 1 2\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 1 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "20 8\r\n4 3 2 1 5 6 7 8\r\n1 2 3 4 8 7 6 5\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n8 7 6 5 4 3 2 1\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n", "output": "YES\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 11 12 9\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n3 2 1 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n2 3 1 4 5 6\r\n1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n2 3 1\r\n2 3 1\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "5 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n3 8 1 4 5 6 7 2\r\n1 8 3 6 5 4 7 2\r\n1 8 3 5 4 6 7 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 4 3 1\r\n2 1 5 4 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 3 1 4\r\n1 2 3 4\r\n2 3 1 4\r\n2 1 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 4 3 5\r\n2 1 4 3 5\r\n1 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "3 10\r\n2 1 3 4 5 6 8 7 10 9\r\n1 2 3 4 5 6 8 7 10 9\r\n1 2 3 4 6 5 8 7 10 9\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n3 1 2 4\r\n3 2 4 1\r\n3 1 2 4\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n1 4 2 3 5\r\n1 2 4 5 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 3 4\r\n2 1 5 3 4\r\n", "output": "NO\r\n"}, {"input": "3 6\r\n2 3 1 4 5 6\r\n2 1 4 3 5 6\r\n1 2 3 4 5 6\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "4 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 3 4 5\r\n1 3 4 2 5\r\n1 4 2 3 5\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 2 3\r\n1 2 3\r\n1 2 3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n3 1 2\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "7 4\r\n1 2 3 4\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 2 3\r\n1 3 2\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}]
| 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 enumerate(sorted(set(p)))}
d = [0] * (len(k) + 1)
for v in p:
j = k[v]
add(j + 1, get(j) + v)
print(d[-1] * 3.14159265)
| 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
return rst
n = int(input())
arr = [map(int, input().split()) for _ in range(n)]
arr = [r*r*h for r, h in arr]
arr2 = sorted(list(set(arr)))
n2 = len(arr2)
bit = [0] * (n2 + 1)
for v in arr:
idx = bisect(arr2, v)
update(bit, n2, idx, read(bit, idx-1) + v)
print(pi*max(bit))
|
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 cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
|
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)} \leq 10^{-6}$$.
| 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\n1 1\r\n2 2\r\n", "output": "84.823001647\r\n"}, {"input": "3\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "113.097335529\r\n"}, {"input": "3\r\n1 1\r\n3 3\r\n2 2\r\n", "output": "87.964594301\r\n"}, {"input": "3\r\n3 3\r\n2 2\r\n1 1\r\n", "output": "84.823001647\r\n"}, {"input": "1\r\n1 1\r\n", "output": "3.141592654\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "28.274333882\r\n"}, {"input": "2\r\n2 2\r\n1 1\r\n", "output": "25.132741229\r\n"}, {"input": "4\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n", "output": "314.159265359\r\n"}, {"input": "4\r\n1 1\r\n2 2\r\n4 4\r\n3 3\r\n", "output": "229.336263712\r\n"}, {"input": "4\r\n1 1\r\n3 3\r\n2 2\r\n4 4\r\n", "output": "289.026524130\r\n"}, {"input": "4\r\n1 1\r\n3 3\r\n4 4\r\n2 2\r\n", "output": "289.026524130\r\n"}, {"input": "4\r\n1 1\r\n4 4\r\n2 2\r\n3 3\r\n", "output": "204.203522483\r\n"}, {"input": "4\r\n1 1\r\n4 4\r\n3 3\r\n2 2\r\n", "output": "204.203522483\r\n"}, {"input": "4\r\n2 2\r\n1 1\r\n3 3\r\n4 4\r\n", "output": "311.017672705\r\n"}, {"input": "4\r\n2 2\r\n1 1\r\n4 4\r\n3 3\r\n", "output": "226.194671058\r\n"}, {"input": "4\r\n2 2\r\n3 3\r\n1 1\r\n4 4\r\n", "output": "311.017672705\r\n"}, {"input": "4\r\n2 2\r\n3 3\r\n4 4\r\n1 1\r\n", "output": "311.017672705\r\n"}, {"input": "4\r\n2 2\r\n4 4\r\n1 1\r\n3 3\r\n", "output": "226.194671058\r\n"}, {"input": "4\r\n2 2\r\n4 4\r\n3 3\r\n1 1\r\n", "output": "226.194671058\r\n"}, {"input": "4\r\n3 3\r\n1 1\r\n2 2\r\n4 4\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n3 3\r\n1 1\r\n4 4\r\n2 2\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n3 3\r\n2 2\r\n1 1\r\n4 4\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n3 3\r\n2 2\r\n4 4\r\n1 1\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n3 3\r\n4 4\r\n1 1\r\n2 2\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n3 3\r\n4 4\r\n2 2\r\n1 1\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n4 4\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "201.061929830\r\n"}, {"input": "4\r\n4 4\r\n1 1\r\n3 3\r\n2 2\r\n", "output": "201.061929830\r\n"}, {"input": "4\r\n4 4\r\n2 2\r\n1 1\r\n3 3\r\n", "output": "201.061929830\r\n"}, {"input": "4\r\n4 4\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "201.061929830\r\n"}, {"input": "4\r\n4 4\r\n3 3\r\n1 1\r\n2 2\r\n", "output": "201.061929830\r\n"}, {"input": "4\r\n4 4\r\n3 3\r\n2 2\r\n1 1\r\n", "output": "201.061929830\r\n"}, {"input": "24\r\n14 3600\r\n105 64\r\n40 441\r\n15 3136\r\n24 1225\r\n42 400\r\n84 100\r\n12 4900\r\n120 49\r\n56 225\r\n140 36\r\n70 144\r\n168 25\r\n60 196\r\n30 784\r\n280 9\r\n10 7056\r\n21 1600\r\n28 900\r\n210 16\r\n420 4\r\n840 1\r\n35 576\r\n20 1764\r\n", "output": "2216707.776373104\r\n"}, {"input": "15\r\n40 9\r\n12 100\r\n60 4\r\n20 36\r\n24 25\r\n15 64\r\n120 1\r\n4 900\r\n6 400\r\n5 576\r\n10 144\r\n30 16\r\n3 1600\r\n2 3600\r\n8 225\r\n", "output": "45238.934211696\r\n"}, {"input": "14\r\n8 324\r\n12 144\r\n72 4\r\n144 1\r\n48 9\r\n3 2304\r\n24 36\r\n2 5184\r\n9 256\r\n36 16\r\n6 576\r\n4 1296\r\n18 64\r\n16 81\r\n", "output": "65144.065264842\r\n"}, {"input": "15\r\n4 1764\r\n24 49\r\n84 4\r\n21 64\r\n28 36\r\n6 784\r\n7 576\r\n2 7056\r\n168 1\r\n56 9\r\n3 3136\r\n8 441\r\n14 144\r\n42 16\r\n12 196\r\n", "output": "88668.311054924\r\n"}, {"input": "15\r\n3 3200\r\n2 7200\r\n20 72\r\n8 450\r\n60 8\r\n15 128\r\n4 1800\r\n5 1152\r\n24 50\r\n40 18\r\n120 2\r\n6 800\r\n30 32\r\n12 200\r\n10 288\r\n", "output": "90477.868423392\r\n"}, {"input": "17\r\n6 900\r\n20 81\r\n45 16\r\n4 2025\r\n15 144\r\n9 400\r\n2 8100\r\n3 3600\r\n10 324\r\n30 36\r\n5 1296\r\n12 225\r\n36 25\r\n18 100\r\n90 4\r\n60 9\r\n180 1\r\n", "output": "101787.601976316\r\n"}, {"input": "13\r\n24 72\r\n3 4608\r\n18 128\r\n72 8\r\n48 18\r\n144 2\r\n4 2592\r\n16 162\r\n9 512\r\n6 1152\r\n12 288\r\n36 32\r\n8 648\r\n", "output": "130288.130529684\r\n"}, {"input": "14\r\n60 12\r\n20 108\r\n24 75\r\n120 3\r\n3 4800\r\n5 1728\r\n6 1200\r\n8 675\r\n12 300\r\n4 2700\r\n30 48\r\n15 192\r\n40 27\r\n10 432\r\n", "output": "135716.802635088\r\n"}, {"input": "14\r\n105 4\r\n14 225\r\n6 1225\r\n7 900\r\n35 36\r\n10 441\r\n30 49\r\n5 1764\r\n21 100\r\n70 9\r\n42 25\r\n3 4900\r\n210 1\r\n15 196\r\n", "output": "138544.236023319\r\n"}, {"input": "14\r\n6 1296\r\n216 1\r\n18 144\r\n3 5184\r\n8 729\r\n4 2916\r\n72 9\r\n12 324\r\n9 576\r\n54 16\r\n36 36\r\n27 64\r\n108 4\r\n24 81\r\n", "output": "146574.146845895\r\n"}, {"input": "14\r\n4 3528\r\n12 392\r\n24 98\r\n84 8\r\n14 288\r\n42 32\r\n168 2\r\n56 18\r\n6 1568\r\n8 882\r\n3 6272\r\n21 128\r\n28 72\r\n7 1152\r\n", "output": "177336.622109848\r\n"}, {"input": "18\r\n3 6400\r\n4 3600\r\n20 144\r\n8 900\r\n24 100\r\n15 256\r\n30 64\r\n16 225\r\n10 576\r\n48 25\r\n5 2304\r\n80 9\r\n60 16\r\n240 1\r\n6 1600\r\n40 36\r\n12 400\r\n120 4\r\n", "output": "180955.736846784\r\n"}, {"input": "13\r\n3 6912\r\n144 3\r\n24 108\r\n18 192\r\n16 243\r\n36 48\r\n9 768\r\n12 432\r\n4 3888\r\n48 27\r\n72 12\r\n8 972\r\n6 1728\r\n", "output": "195432.195794527\r\n"}, {"input": "16\r\n126 4\r\n21 144\r\n3 7056\r\n14 324\r\n42 36\r\n63 16\r\n28 81\r\n36 49\r\n7 1296\r\n84 9\r\n252 1\r\n4 3969\r\n6 1764\r\n9 784\r\n12 441\r\n18 196\r\n", "output": "199503.699873579\r\n"}, {"input": "16\r\n45 32\r\n12 450\r\n60 18\r\n9 800\r\n180 2\r\n6 1800\r\n4 4050\r\n36 50\r\n3 7200\r\n18 200\r\n15 288\r\n30 72\r\n20 162\r\n90 8\r\n10 648\r\n5 2592\r\n", "output": "203575.203952632\r\n"}, {"input": "14\r\n22 144\r\n24 121\r\n264 1\r\n6 1936\r\n132 4\r\n33 64\r\n4 4356\r\n12 484\r\n66 16\r\n3 7744\r\n44 36\r\n11 576\r\n88 9\r\n8 1089\r\n", "output": "218956.441584609\r\n"}, {"input": "14\r\n30 80\r\n5 2880\r\n4 4500\r\n3 8000\r\n10 720\r\n12 500\r\n8 1125\r\n6 2000\r\n60 20\r\n120 5\r\n24 125\r\n15 320\r\n40 45\r\n20 180\r\n", "output": "226194.671058480\r\n"}, {"input": "14\r\n27 100\r\n135 4\r\n3 8100\r\n45 36\r\n90 9\r\n30 81\r\n6 2025\r\n270 1\r\n54 25\r\n18 225\r\n10 729\r\n15 324\r\n5 2916\r\n9 900\r\n", "output": "229022.104446711\r\n"}, {"input": "14\r\n28 100\r\n140 4\r\n20 196\r\n5 3136\r\n56 25\r\n4 4900\r\n40 49\r\n7 1600\r\n35 64\r\n70 16\r\n10 784\r\n280 1\r\n14 400\r\n8 1225\r\n", "output": "246300.864041456\r\n"}, {"input": "16\r\n32 81\r\n96 9\r\n12 576\r\n3 9216\r\n18 256\r\n144 4\r\n36 64\r\n16 324\r\n72 16\r\n4 5184\r\n48 36\r\n288 1\r\n8 1296\r\n6 2304\r\n24 144\r\n9 1024\r\n", "output": "260576.261059369\r\n"}, {"input": "14\r\n3 9408\r\n12 588\r\n4 5292\r\n24 147\r\n42 48\r\n7 1728\r\n168 3\r\n84 12\r\n6 2352\r\n28 108\r\n56 27\r\n8 1323\r\n21 192\r\n14 432\r\n", "output": "266004.933164772\r\n"}, {"input": "14\r\n20 216\r\n12 600\r\n5 3456\r\n10 864\r\n15 384\r\n3 9600\r\n4 5400\r\n30 96\r\n8 1350\r\n6 2400\r\n24 150\r\n60 24\r\n120 6\r\n40 54\r\n", "output": "271433.605270176\r\n"}, {"input": "14\r\n35 72\r\n21 200\r\n6 2450\r\n5 3528\r\n70 18\r\n30 98\r\n10 882\r\n15 392\r\n105 8\r\n210 2\r\n42 50\r\n3 9800\r\n14 450\r\n7 1800\r\n", "output": "277088.472046638\r\n"}, {"input": "16\r\n100 9\r\n3 10000\r\n60 25\r\n15 400\r\n75 16\r\n10 900\r\n50 36\r\n150 4\r\n25 144\r\n6 2500\r\n12 625\r\n5 3600\r\n20 225\r\n30 100\r\n4 5625\r\n300 1\r\n", "output": "282743.338823100\r\n"}, {"input": "13\r\n72 18\r\n24 162\r\n36 72\r\n4 5832\r\n18 288\r\n54 32\r\n12 648\r\n9 1152\r\n108 8\r\n216 2\r\n8 1458\r\n27 128\r\n6 2592\r\n", "output": "293148.293691790\r\n"}, {"input": "15\r\n36 75\r\n45 48\r\n6 2700\r\n9 1200\r\n30 108\r\n18 300\r\n12 675\r\n20 243\r\n5 3888\r\n4 6075\r\n60 27\r\n90 12\r\n10 972\r\n180 3\r\n15 432\r\n", "output": "305362.805928948\r\n"}, {"input": "13\r\n12 676\r\n39 64\r\n6 2704\r\n8 1521\r\n52 36\r\n312 1\r\n13 576\r\n104 9\r\n4 6084\r\n156 4\r\n24 169\r\n78 16\r\n26 144\r\n", "output": "305815.195271065\r\n"}, {"input": "9\r\n4 2\r\n2 2\r\n4 1\r\n3 1\r\n1 1\r\n4 3\r\n5 1\r\n4 3\r\n4 1\r\n", "output": "304.734487398\r\n"}, {"input": "5\r\n8 3\r\n6 3\r\n4 2\r\n7 3\r\n6 3\r\n", "output": "801.106126665\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "3.141592654\r\n"}, {"input": "3\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "3141.592653590\r\n"}, {"input": "2\r\n100 30\r\n100 30\r\n", "output": "942477.796077000\r\n"}]
| 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().strip()
b = Decimal(correct_line)
except:
print(0)
return
# Read submission output
try:
with open(submission_output_path, 'r') as f:
sub_line = f.readline().strip()
a = Decimal(sub_line)
except:
print(0)
return
absolute_diff = abs(a - b)
denominator = max(Decimal(1), b)
if absolute_diff <= Decimal('1e-6') * denominator:
print(1)
else:
print(0)
if __name__ == "__main__":
main()
| 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_skills = []
del input_file[0]
for i in range(num_boys):
boy_skills.append(int(input_file[i]))
del input_file[0:num_boys]
num_girls = int(input_file[0])
girl_skills = []
del input_file[0]
for i in range(num_girls):
girl_skills.append(int(input_file[i]))
del input_file[0:num_girls]
boy_skills.sort()
girl_skills.sort()
in_pair = set()
if num_boys > num_girls:
for i in range(num_girls):
current_girl = girl_skills[i]
if check_skills(boy_skills[i], current_girl, in_pair, i):
in_pair.add(i)
continue
index = i - 1
# CHECK LOWER RANKED
while index > 0:
current_boy = boy_skills[index]
if current_boy < current_girl - 1:
break
if check_skills(current_boy, current_girl, in_pair, index):
in_pair.add(index)
break
index -= 1
index = i + 1
# CHECK HIGHER RANKED
while index < num_boys:
current_boy = boy_skills[index]
if current_boy > current_girl + 1:
break
if check_skills(current_boy, current_girl, in_pair, index):
in_pair.add(index)
break
index += 1
else:
for i in range(num_boys):
current_boy = boy_skills[i]
# print(f"BOY: {current_boy}")
if check_skills(girl_skills[i], current_boy, in_pair, i):
in_pair.add(i)
continue
index = i - 1
# CHECK LOWER RANKED
while index > 0:
current_girl = girl_skills[index]
if current_girl < current_boy - 1:
break
if check_skills(current_girl, current_boy, in_pair, index):
in_pair.add(index)
break
index -= 1
index = i + 1
# CHECK HIGHER RANKED
while index < num_girls:
current_girl = girl_skills[index]
if current_girl > current_boy + 1:
break
if check_skills(current_girl, current_boy, in_pair, index):
in_pair.add(index)
break
index += 1
print(len(in_pair))
| 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 girls_ptr < num_girls:
cur_boy_skill = boys_skill[boys_ptr]
cur_girl_skill = girls_skill[girls_ptr]
if abs(cur_boy_skill - cur_girl_skill) <= 1:
num_pairs += 1
boys_ptr += 1
girls_ptr += 1
elif cur_boy_skill < cur_girl_skill:
boys_ptr += 1
else:
girls_ptr += 1
print(num_pairs)
main()
|
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 must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
|
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 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.
|
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"}, {"input": "4\r\n4 5 4 4\r\n5\r\n5 3 4 2 4\r\n", "output": "4\r\n"}, {"input": "1\r\n2\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n2\r\n3 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n3\r\n4 4 4\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n4\r\n3 1 4 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n5\r\n2 5 5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "2\r\n4 2\r\n2\r\n4 4\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n3\r\n2 3 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n4\r\n5 5 5 6\r\n", "output": "1\r\n"}, {"input": "2\r\n5 7\r\n5\r\n4 6 7 2 5\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "3\r\n5 4 5\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n6 3 4\r\n3\r\n4 5 2\r\n", "output": "3\r\n"}, {"input": "3\r\n7 7 7\r\n4\r\n2 7 2 4\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 3\r\n5\r\n1 3 4 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 3\r\n1\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n4 4 6 6\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "4\r\n3 1 1 1\r\n3\r\n1 6 7\r\n", "output": "1\r\n"}, {"input": "4\r\n2 5 1 2\r\n4\r\n2 3 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n9 1 7 1\r\n5\r\n9 9 9 8 4\r\n", "output": "2\r\n"}, {"input": "5\r\n1 6 5 5 6\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 4 5 6\r\n2\r\n7 4\r\n", "output": "2\r\n"}, {"input": "5\r\n4 1 3 1 4\r\n3\r\n6 3 6\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 3 1 4\r\n4\r\n1 3 1 7\r\n", "output": "3\r\n"}, {"input": "5\r\n9 8 10 9 10\r\n5\r\n2 1 5 4 6\r\n", "output": "0\r\n"}, {"input": "1\r\n48\r\n100\r\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6\r\n", "output": "1\r\n"}, {"input": "100\r\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\r\n1\r\n58\r\n", "output": "0\r\n"}, {"input": "10\r\n20 87 3 39 20 20 8 40 70 51\r\n100\r\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96\r\n", "output": "6\r\n"}, {"input": "100\r\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\r\n10\r\n66 74 40 67 28 82 99 57 93 64\r\n", "output": "9\r\n"}, {"input": "100\r\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\r\n100\r\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1\r\n", "output": "76\r\n"}, {"input": "4\r\n1 6 9 15\r\n2\r\n5 8\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 5\r\n3\r\n3 4 6\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 4\r\n3\r\n2 1 5\r\n", "output": "3\r\n"}, {"input": "2\r\n5 5\r\n4\r\n1 1 1 5\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "2\r\n3 1\r\n2\r\n2 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n10 12\r\n2\r\n11 9\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n3\r\n3 2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n1 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n4 5\r\n2\r\n5 3\r\n", "output": "2\r\n"}, {"input": "2\r\n7 5\r\n2\r\n6 8\r\n", "output": "2\r\n"}, {"input": "4\r\n4 3 2 1\r\n4\r\n1 2 3 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 3\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n3\r\n3 1 8\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 1\r\n3\r\n2 4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 3\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 3 3\r\n4\r\n2 2 1 1\r\n", "output": "4\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n2 4 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n5\r\n2 3 4 5 1\r\n", "output": "5\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n5 4\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 5 5\r\n4\r\n4 4 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n2 7 5\r\n3\r\n2 4 8\r\n", "output": "3\r\n"}, {"input": "100\r\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\r\n100\r\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5\r\n", "output": "100\r\n"}, {"input": "1\r\n3\r\n2\r\n2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n5 6\r\n3\r\n1 5 100\r\n", "output": "1\r\n"}, {"input": "2\r\n2 7\r\n2\r\n6 8\r\n", "output": "1\r\n"}, {"input": "4\r\n4 10 15 17\r\n4\r\n3 12 16 16\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n2\r\n1 2\r\n", "output": "2\r\n"}]
| 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, then they should be separated by exactly one space
- there should be no spaces before each punctuation mark
- there should be exactly one space after each punctuation mark
It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.
|
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\n"}, {"input": "a a a a a\r\n", "output": "a a a a a\r\n"}, {"input": "ksdfk sdlfsdf sdf sdf sdf\r\n", "output": "ksdfk sdlfsdf sdf sdf sdf\r\n"}, {"input": "gdv\r\n", "output": "gdv\r\n"}, {"input": "incen q\r\n", "output": "incen q\r\n"}, {"input": "k ? gq dad\r\n", "output": "k? gq dad\r\n"}, {"input": "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb\r\n", "output": "ntomzzut! pousysvfg, rnl mcyytihe hplnqnb\r\n"}, {"input": "mck . gq dauqminf wee bazyzy humnv d pgtvx , vxntxgrkrc rg rwr, uuyweyz l\r\n", "output": "mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l\r\n"}, {"input": "jjcmhwnon taetfgdvc, ysrajurstj ! fryavybwpg hnxbnsron ,txplbmm atw?wkfhn ez mcdn tujsy wrdhw . k i lzwtxcyam fi . nyeu j\r\n", "output": "jjcmhwnon taetfgdvc, ysrajurstj! fryavybwpg hnxbnsron, txplbmm atw? wkfhn ez mcdn tujsy wrdhw. k i lzwtxcyam fi. nyeu j\r\n"}, {"input": "chcf htb flfwkosmda a qygyompixkgz ?rg? hdw f dsvqzs kxvjt ? zj zghgarwihw zgrhr xlwmhv . lycpsmdm iotv . d jhsxoogbr ! ppgrpwcrcl inw usegrtd ?fexma ? mhszrvdoa ,audsrhina epoleuq oaz hqapedl lm\r\n", "output": "chcf htb flfwkosmda a qygyompixkgz? rg? hdw f dsvqzs kxvjt? zj zghgarwihw zgrhr xlwmhv. lycpsmdm iotv. d jhsxoogbr! ppgrpwcrcl inw usegrtd? fexma? mhszrvdoa, audsrhina epoleuq oaz hqapedl lm\r\n"}, {"input": "x\r\n", "output": "x\r\n"}, {"input": "xx\r\n", "output": "xx\r\n"}, {"input": "x x\r\n", "output": "x x\r\n"}, {"input": "x,x\r\n", "output": "x, x\r\n"}, {"input": "x.x\r\n", "output": "x. x\r\n"}, {"input": "x!x\r\n", "output": "x! x\r\n"}, {"input": "x?x\r\n", "output": "x? x\r\n"}, {"input": "a!b\r\n", "output": "a! b\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "physicist ?mathematician.astronomer\r\n", "output": "physicist? mathematician. astronomer\r\n"}, {"input": "dfgdfg ? ddfgdsfg ? dsfgdsfgsdfgdsf ! dsfg . sd dsg sdg ! sdfg\r\n", "output": "dfgdfg? ddfgdsfg? dsfgdsfgsdfgdsf! dsfg. sd dsg sdg! sdfg\r\n"}, {"input": "jojo ! majo , hehehehe? jo . kok\r\n", "output": "jojo! majo, hehehehe? jo. kok\r\n"}, {"input": "adskfj,kjdf?kjadf kj!kajs f\r\n", "output": "adskfj, kjdf? kjadf kj! kajs f\r\n"}, {"input": "a , b\r\n", "output": "a, b\r\n"}, {"input": "ahmed? ahmed ? ahmed ?ahmed\r\n", "output": "ahmed? ahmed? ahmed? ahmed\r\n"}, {"input": "kjdsf, kdjf?kjdf!kj kdjf\r\n", "output": "kjdsf, kdjf? kjdf! kj kdjf\r\n"}, {"input": "italian physicist .mathematician?astronomer\r\n", "output": "italian physicist. mathematician? astronomer\r\n"}, {"input": "galileo galilei was an italian physicist , mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "z zz zz z z! z z aksz zkjsdfz kajfz z !akj , zz a z\r\n", "output": "z zz zz z z! z z aksz zkjsdfz kajfz z! akj, zz a z\r\n"}, {"input": "jojo ! maja . jaooo\r\n", "output": "jojo! maja. jaooo\r\n"}, {"input": "a ! b\r\n", "output": "a! b\r\n"}, {"input": "fff , fff\r\n", "output": "fff, fff\r\n"}, {"input": "a!a?a ! a ? a\r\n", "output": "a! a? a! a? a\r\n"}, {"input": "a!a\r\n", "output": "a! a\r\n"}, {"input": "a!a a ! a ? a ! a , a . a\r\n", "output": "a! a a! a? a! a, a. a\r\n"}, {"input": "casa?mesa, y unos de , los sapotes?l\r\n", "output": "casa? mesa, y unos de, los sapotes? l\r\n"}, {"input": "ff ! ff\r\n", "output": "ff! ff\r\n"}, {"input": "i love evgenia ! x\r\n", "output": "i love evgenia! x\r\n"}, {"input": "galileo galilei was an italian physicist ,mathematician,astronomer?asdf ?asdfff?asdf. asdf.dfd .dfdf ? df d! sdf dsfsa sdf ! asdf ? sdfsdf, dfg a ! b ?a\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer? asdf? asdfff? asdf. asdf. dfd. dfdf? df d! sdf dsfsa sdf! asdf? sdfsdf, dfg a! b? a\r\n"}, {"input": "a , a\r\n", "output": "a, a\r\n"}, {"input": "x, werwr, werwerwr we,rwer ,wer\r\n", "output": "x, werwr, werwerwr we, rwer, wer\r\n"}, {"input": "abcabc, abcabc\r\n", "output": "abcabc, abcabc\r\n"}, {"input": "i love evgenia x! x\r\n", "output": "i love evgenia x! x\r\n"}, {"input": "gg gg,h,h,j,i,jh , jjj , jj ,aadd , jjj jjj\r\n", "output": "gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj\r\n"}, {"input": "mt test ! case\r\n", "output": "mt test! case\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "asdasdasd.asdasdasdasd?asdasdasd!asdasdasd,asdasdasdasd\r\n", "output": "asdasdasd. asdasdasdasd? asdasdasd! asdasdasd, asdasdasdasd\r\n"}, {"input": "x, x, ds ,ertert, ert, et et\r\n", "output": "x, x, ds, ertert, ert, et et\r\n"}, {"input": "anton!love ?yourself\r\n", "output": "anton! love? yourself\r\n"}, {"input": "facepalm ? yes , lol ! yeah\r\n", "output": "facepalm? yes, lol! yeah\r\n"}, {"input": "a ! a\r\n", "output": "a! a\r\n"}, {"input": "adf!kadjf?kajdf,lkdas. kd ! akdjf\r\n", "output": "adf! kadjf? kajdf, lkdas. kd! akdjf\r\n"}, {"input": "a? x\r\n", "output": "a? x\r\n"}, {"input": "read problem carefully ! heh\r\n", "output": "read problem carefully! heh\r\n"}, {"input": "a?a?a?a.a\r\n", "output": "a? a? a? a. a\r\n"}, {"input": "a. v\r\n", "output": "a. v\r\n"}, {"input": "a!a a ! a ? a ! a , a . a aaaaaa ! a ! a. a a .a a.a aa.aa aa . aa aa .aa aa. aa\r\n", "output": "a! a a! a? a! a, a. a aaaaaa! a! a. a a. a a. a aa. aa aa. aa aa. aa aa. aa\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "a!a!a\r\n", "output": "a! a! a\r\n"}, {"input": "a.a.a.a\r\n", "output": "a. a. a. a\r\n"}, {"input": "a, b\r\n", "output": "a, b\r\n"}, {"input": "galileo galilei was an italian physicist, mathematician, astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "a!a!a!a\r\n", "output": "a! a! a! a\r\n"}, {"input": "af ! kadjf ? kjdfkj!kjadkfjz z z a a! ka,kjf\r\n", "output": "af! kadjf? kjdfkj! kjadkfjz z z a a! ka, kjf\r\n"}, {"input": "ab cd,k\r\n", "output": "ab cd, k\r\n"}, {"input": "a!n , to\r\n", "output": "a! n, to\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "u, sux\r\n", "output": "u, sux\r\n"}]
| 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[ord(a2[i])-97]+=1
else:
ans2[ord(a2[i])-65+26]+=1
for i in range(len(a3)):
if(a3[i].islower()):
ans3[ord(a3[i])-97]+=1
else:
ans3[ord(a3[i])-65+26]+=1
k=max(ans1)
m=max(ans2)
p=max(ans3)
if(k+a>=len(a1)):
if(k==len(a1) and a%2==1):
k=k-1
else:
k=len(a1)
else:
k=k+a
if(m+a>=len(a1)):
if(m==len(a1) and a%2==1):
m=m-1
else:
m=len(a1)
else:
m=m+a
if(p+a>=len(a1)):
if(p==len(a1) and a%2==1):
p=p-1
else:
p=len(a1)
else:
p=p+a
flag=0
if(k>m and k>p):
print('Kuro')
flag=1
if(m>k and m>p):
print('Shiro')
flag=1
if(p>k and p>m):
print('Katie')
flag=1
if(flag==0):
print('Draw')
| 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 len(x))
r=max(n)
if n.count(r)==1:
if(n[0]==r):
print("Kuro")
elif(n[1]==r):
print("Shiro")
else:
print("Katie")
else:
print("Draw")
|
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. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $$$7$$$ because its subribbon a appears $$$7$$$ times, and the ribbon abcdabc has the beauty of $$$2$$$ because its subribbon abc appears twice.
The rules are simple. The game will have $$$n$$$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $$$n$$$ turns wins the treasure.
Could you find out who is going to be the winner if they all play optimally?
|
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 that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
|
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 into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is $$$9$$$ and the number of turn is $$$15$$$, everyone can change their ribbons in some way to reach the maximal beauty of $$$9$$$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.
|
[{"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"}, {"input": "1\r\naaaaaaaaaa\r\nAAAAAAcAAA\r\nbbbbbbzzbb\r\n", "output": "Shiro\r\n"}, {"input": "60\r\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\r\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\r\nXaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ\r\n", "output": "Draw\r\n"}, {"input": "9174\r\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzcccbccczzbbcbbzbzzzcbczbzbzzbbbczbbcbzzzbcbzczbcczb\r\ndbzzzccdcdczzzzzcdczbbzcdzbcdbzzdczbzddcddbdbzzzczcczzbdcbbzccbzzzdzbzddcbzbdzdcczccbdb\r\nzdczddzcdddddczdczdczdcdzczddzczdzddczdcdcdzczczzdzccdccczczdzczczdzcdddzddzccddcczczzd\r\n", "output": "Draw\r\n"}, {"input": "727\r\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\r\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\r\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffeeeeeefeffef\r\n", "output": "Draw\r\n"}, {"input": "61\r\nbzqiqprzfwddqwctcrhnkqcsnbmcmfmrgaljwieajfouvuiunmfbrehxchupmsdpwilwu\r\njyxxujvxkwilikqeegzxlyiugflxqqbwbujzedqnlzucdnuipacatdhcozuvgktwvirhs\r\ntqiahohijwfcetyyjlkfhfvkhdgllxmhyyhhtlhltcdspusyhwpwqzyagtsbaswaobwub\r\n", "output": "Katie\r\n"}, {"input": "30\r\njAjcdwkvcTYSYBBLniJIIIiubKWnqeDtUiaXSIPfhDTOrCWBQetm\r\nPQPOTgqfBWzQvPNeEaUaPQGdUgldmOZsBtsIqZGGyXozntMpOsyY\r\nNPfvGxMqIULNWOmUrHJfsqORUHkzKQfecXsTzgFCmUtFmIBudCJr\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcabcabcabcdddabc\r\nzxytzytxxtytxyzxyt\r\nfgffghfghffgghghhh\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabcd\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nbbb\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nlkjhg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nbbbbb\r\naabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\nfghij\r\nkkkkk\r\n", "output": "Katie\r\n"}, {"input": "4\r\naaaabcd\r\naaaabcd\r\naaaaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naabcde\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaaa\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "1\r\nAAAAA\r\nBBBBB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "1\r\nabcde\r\naaaaa\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabfcde\r\nabfcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\naaa\r\naab\r\nccd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naabbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\nxxxxxx\r\nxxxooo\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\noooo\r\naaac\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\naaabb\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nqwery\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaa\r\nbbbbbb\r\naaaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabb\r\naabb\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naab\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nbbbbcc\r\nbbbbbb\r\nsadfgh\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaacc\r\nxxxxkkkk\r\nxxxxkkkk\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaac\r\nbbbbc\r\nccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaabbbbbb\r\nabcdewert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabc\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaa\r\naaaaaaab\r\naaaabbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcdefg\r\nabccccc\r\nacccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabcdef\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaabbb\r\naabdef\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabba\r\nbbbb\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbbaaa\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naaa\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcda\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabbc\r\nqwert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabbcc\r\naabbcc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nAAAAAA\r\nAAAAAB\r\nABCDEF\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabc\r\naac\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naabbc\r\naabbc\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaab\r\naaaaabb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaaaa\r\nbbbbbbbbaaa\r\nqwertyuiasd\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\naabb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabcd\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nabc\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "1\r\naa\r\nab\r\nbb\r\n", "output": "Shiro\r\n"}, {"input": "1\r\naacb\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcd\r\nabcd\r\naaad\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaab\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaab\r\nabcd\r\nabcd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\nabcd\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "2\r\nxxxx\r\nyyyx\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nAAAAA\r\nAAAAB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaacdc\r\naaaaabc\r\naaaaabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabcde\r\naabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naaabb\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\nabbbbb\r\ncbbbbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaaaabbbb\r\naaaaabbbb\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaaaaab\r\naaabbbb\r\naaabbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaaabb\r\naaabbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaabb\r\naaaaab\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaa\r\naaaae\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\nbbbcde\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaaabbb\r\naabcdef\r\naabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaa\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabbbbb\r\naaabbbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\naabcd\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\naaabbcc\r\nabcdefg\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naabbb\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\nbbb\r\nabb\r\nqer\r\n", "output": "Kuro\r\n"}, {"input": "5\r\naabbbbb\r\naaaaaaa\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naaaab\r\naaabb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaaab\r\naaaabbb\r\naaaaccc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaaaaaaa\r\naaaaaaaaaaab\r\naaaaaabbbbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabb\r\nabcde\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaac\r\naaaaebc\r\naaaaaac\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaabbb\r\nqwerty\r\n", "output": "Draw\r\n"}, {"input": "3\r\ncccca\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "100005\r\nAA\r\nBC\r\nCC\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\nccca\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbcdef\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\naabb\r\nqwer\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\nbbaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaa\r\naaaa\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\naaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaa\r\nabcd\r\naaab\r\n", "output": "Katie\r\n"}]
| 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("NO")
| 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 from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
|
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": "4\r\n1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 4 7\r\n", "output": "YES\r\n"}, {"input": "3\r\n99999999 1 50000000\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 2 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 5 11\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n100000001 100000003\r\n", "output": "YES\r\n"}, {"input": "3\r\n7 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 100 29\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 5 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 6 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 1 1 1 1 2 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 4 4 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 2 4 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 9 10\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 1 1 1 1 1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 15 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 6 7 8 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 6 8\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 6 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n10 20 21 30\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 2 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 6 12\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0 1 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 5 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 4 5 6\r\n", "output": "NO\r\n"}]
| 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.add((j, z))
if len(s) > 2:
ans = 0
commons |= s
if len(commons) > n + 1:
ans = 0
if not ans:
print('NO')
else:
print('YES')
| 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 False
return count <= 2
def try_swap(col1,col2):
temp = mat[col1]
mat[col1] = mat[col2]
mat[col2] = temp
for row in range(n):
if not valid(row):
temp = mat[col2]
mat[col2] = mat[col1]
mat[col1] = temp
return False
temp = mat[col2]
mat[col2] = mat[col1]
mat[col1] = temp
return True
for col in range(m):
for col2 in range(col + 1,m):
if try_swap(col,col2):
print('YES')
import sys
sys.exit(0)
if try_swap(0,0):
print('YES')
else:
print('NO')
|
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 to perform from 0 to n + 1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
|
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 8 9 10\r\n", "output": "YES\r\n"}, {"input": "5 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 8 5 6 7 10 9 4 11 12\r\n1 5 3 4 2 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n", "output": "YES\r\n"}, {"input": "4 10\r\n3 2 8 10 5 6 7 1 9 4\r\n1 2 9 4 5 3 7 8 10 6\r\n7 5 3 4 8 6 1 2 9 10\r\n4 2 3 9 8 6 7 5 1 10\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n9 2 3 4 5 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 10 7 8 1 6\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n9 10 4 2 3 5 7 1 8 6\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n6 4 7 3 5 8 1 9 10 2\r\n1 5 10 6 3 4 9 7 2 8\r\n3 2 1 7 8 6 5 4 10 9\r\n7 9 1 6 8 2 4 5 3 10\r\n3 4 6 9 8 7 1 2 10 5\r\n", "output": "NO\r\n"}, {"input": "20 2\r\n1 2\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "20 3\r\n3 2 1\r\n2 3 1\r\n2 3 1\r\n2 1 3\r\n1 3 2\r\n2 1 3\r\n1 2 3\r\n3 2 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n2 1 3\r\n2 3 1\r\n2 3 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n3 1 2\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 2 3 4 5 6 7 10 9 8\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n6 9 3 4 5 1 8 7 2 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 19 14 15 16 17 18 13 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 20\r\n1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 17 18 19 20\r\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 12 18 7 8 9 10 11 5 13 14 15 16 17 6 19 20\r\n6 2 3 4 5 1 7 8 9 10 11 12 13 20 15 16 17 18 19 14\r\n4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 19 8 9 10 11 12 13 14 15 20 17 18 7 16\r\n1 2 9 4 5 6 7 8 18 10 11 12 13 14 15 16 17 3 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n4 2 3 8 5 6 7 1 9 10\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n3 2 1 4 5 6 7 8 10 9\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 18 14 15 16 17 13 11 20\r\n1 2 11 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 3 20\r\n13 2 3 4 5 6 7 8 9 10 19 12 1 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 16 8 9 10 11 12 13 14 15 7 17 18 19 20\r\n1 2 3 14 5 6 16 8 9 10 11 12 13 4 15 7 17 18 19 20\r\n1 2 3 4 5 6 16 8 18 10 11 12 13 14 15 7 17 9 19 20\r\n1 2 3 4 5 6 16 8 9 15 11 12 13 14 10 7 17 18 19 20\r\n1 2 18 4 5 6 16 8 9 10 11 12 13 14 15 7 17 3 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 18 4 5 6 7 8 9 10 11 12 13 14 15 16 19 3 17 20\r\n8 2 3 9 5 6 7 1 4 10 11 12 13 14 15 16 17 18 19 20\r\n7 2 3 4 5 6 1 8 9 10 11 12 13 14 15 16 17 20 19 18\r\n1 2 3 12 5 6 7 8 9 17 11 4 13 14 15 16 10 18 19 20\r\n1 11 3 4 9 6 7 8 5 10 2 12 13 14 15 16 17 18 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n10 2 3 4 5 9 7 8 6 1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 9 2 4 6 5 8 3 7 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 3 2 19 5 6 7 8 9 17 11 12 13 14 15 16 10 18 4 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 20 6 7 8 9 17 11 12 13 14 15 16 10 18 19 5\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 6 17 4 5 2 7 14 9 10 11 12 13 8 15 16 3 18 19 20\r\n5 6 17 4 1 2 7 8 9 10 11 12 13 14 15 16 3 18 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 18 3 16 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 16 3 18 20 19\r\n1 6 17 8 5 2 7 4 9 10 11 12 13 14 15 16 3 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n10 2 9 4 5 6 7 8 15 1 11 16 13 14 3 12 17 18 19 20\r\n10 2 3 4 5 6 7 1 9 8 11 16 13 14 15 12 17 18 19 20\r\n9 2 3 4 5 6 7 8 10 1 11 16 13 14 15 12 20 18 19 17\r\n10 2 3 4 7 6 5 8 9 1 11 16 18 14 15 12 17 13 19 20\r\n10 2 3 4 5 6 7 8 9 20 11 16 14 13 15 12 17 18 19 1\r\n", "output": "NO\r\n"}, {"input": "1 4\r\n2 3 4 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 1 3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "15 6\r\n2 1 4 3 6 5\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n4 3 1 2\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "4 8\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n", "output": "YES\r\n"}, {"input": "4 6\r\n1 2 3 5 6 4\r\n3 2 1 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n3 1 2\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 1 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "20 8\r\n4 3 2 1 5 6 7 8\r\n1 2 3 4 8 7 6 5\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n8 7 6 5 4 3 2 1\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n", "output": "YES\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 11 12 9\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n3 2 1 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n2 3 1 4 5 6\r\n1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n2 3 1\r\n2 3 1\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "5 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n3 8 1 4 5 6 7 2\r\n1 8 3 6 5 4 7 2\r\n1 8 3 5 4 6 7 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 4 3 1\r\n2 1 5 4 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 3 1 4\r\n1 2 3 4\r\n2 3 1 4\r\n2 1 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 4 3 5\r\n2 1 4 3 5\r\n1 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "3 10\r\n2 1 3 4 5 6 8 7 10 9\r\n1 2 3 4 5 6 8 7 10 9\r\n1 2 3 4 6 5 8 7 10 9\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n3 1 2 4\r\n3 2 4 1\r\n3 1 2 4\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n1 4 2 3 5\r\n1 2 4 5 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 3 4\r\n2 1 5 3 4\r\n", "output": "NO\r\n"}, {"input": "3 6\r\n2 3 1 4 5 6\r\n2 1 4 3 5 6\r\n1 2 3 4 5 6\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "4 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 3 4 5\r\n1 3 4 2 5\r\n1 4 2 3 5\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 2 3\r\n1 2 3\r\n1 2 3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n3 1 2\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "7 4\r\n1 2 3 4\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 2 3\r\n1 3 2\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}]
| 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[::-1], a[::-1])
s, f = -2, 0
for i in range(len(b)):
if sub[i] < 10 ** 19:
s = -1
f = i
import bisect
for i in range(len(b)):
if prb[i] >= 10 ** 19:
break
rem = len(a) - prb[i] - 2
j = bisect.bisect_right(sub, rem, 0, len(b) - i - 1)
if i + j > s + f:
s, f = i, j
if s == -2:
print('-')
else:
print(b[0:s + 1] + b[len(b) - f:])
| 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]:
tmp-=1
v2[i]=tmp
b=0
mx=0
for i in range(n+1):
c=v1[i]+m-v2[i+1]+1
if c>mx:
mx=c
b=i
ans=[]
if mx>=m:
for i in range(1,m+1):
ans.append(s2[i])
else:
for i in range(1,v1[b]+1):
ans.append(s2[i])
for i in range(v2[b+1],m+1):
ans.append(s2[i])
while len(ans)>0 and ans[-1]==' ':
ans.pop()
if len(ans)==0:
ans="-"
return ''.join(ans)
s1=input()
s2=input()
print(solve(s1,s2))
|
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 the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
|
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\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk\r\n", "output": "ouypvk\r\n"}, {"input": "npnkmawey\r\nareakefvowledfriyjejqnnaeqheoh\r\n", "output": "a\r\n"}, {"input": "fdtffutxkujflswyddvhusfcook\r\nkavkhnhphcvckogqqqqhdmgwjdfenzizrebefsbuhzzwhzvc\r\n", "output": "kvc\r\n"}, {"input": "abacaba\r\naa\r\n", "output": "aa\r\n"}, {"input": "edbcd\r\nd\r\n", "output": "d\r\n"}, {"input": "abc\r\nksdksdsdsnabc\r\n", "output": "abc\r\n"}, {"input": "abxzxzxzzaba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abcd\r\nzzhabcd\r\n", "output": "abcd\r\n"}, {"input": "aa\r\naa\r\n", "output": "aa\r\n"}, {"input": "test\r\nt\r\n", "output": "t\r\n"}, {"input": "aa\r\na\r\n", "output": "a\r\n"}, {"input": "aaaabbbbaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "aa\r\nzzaa\r\n", "output": "aa\r\n"}, {"input": "zhbt\r\nztjihmhebkrztefpwty\r\n", "output": "zt\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaa\r\naaaaaaaa\r\n", "output": "aaaaaaaa\r\n"}, {"input": "abba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abbba\r\naba\r\n", "output": "aba\r\n"}, {"input": "aaaaaaaaaaaa\r\naaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaa\r\n"}, {"input": "aaa\r\naa\r\n", "output": "aa\r\n"}, {"input": "aaaaaaaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "aaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "ashfaniosafapisfasipfaspfaspfaspfapsfjpasfshvcmvncxmvnxcvnmcxvnmxcnvmcvxvnxmcvxcmvh\r\nashish\r\n", "output": "ashish\r\n"}, {"input": "a\r\na\r\n", "output": "a\r\n"}, {"input": "aaaab\r\naab\r\n", "output": "aab\r\n"}, {"input": "aaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "a\r\naaa\r\n", "output": "a\r\n"}, {"input": "aaaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "def\r\nabcdef\r\n", "output": "def\r\n"}, {"input": "aaaaaaaaa\r\na\r\n", "output": "a\r\n"}, {"input": "bababsbs\r\nabs\r\n", "output": "abs\r\n"}, {"input": "hddddddack\r\nhackyz\r\n", "output": "hack\r\n"}, {"input": "aba\r\na\r\n", "output": "a\r\n"}, {"input": "ofih\r\nihfsdf\r\n", "output": "ih\r\n"}, {"input": "b\r\nabb\r\n", "output": "b\r\n"}, {"input": "lctsczqr\r\nqvkp\r\n", "output": "q\r\n"}, {"input": "dedcbaa\r\ndca\r\n", "output": "dca\r\n"}, {"input": "haddack\r\nhack\r\n", "output": "hack\r\n"}, {"input": "abcabc\r\nabc\r\n", "output": "abc\r\n"}, {"input": "asdf\r\ngasdf\r\n", "output": "asdf\r\n"}, {"input": "abab\r\nab\r\n", "output": "ab\r\n"}, {"input": "aaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "asdf\r\nfasdf\r\n", "output": "asdf\r\n"}, {"input": "bbaabb\r\nab\r\n", "output": "ab\r\n"}, {"input": "accac\r\nbaacccbcccabaabbcacbbcccacbaabaaac\r\n", "output": "aac\r\n"}, {"input": "az\r\naaazazaa\r\n", "output": "a\r\n"}, {"input": "bbacaabbaaa\r\nacaabcaa\r\n", "output": "acaabaa\r\n"}, {"input": "c\r\ncbcbcbbacacacbccaaccbcabaaabbaaa\r\n", "output": "c\r\n"}, {"input": "bacb\r\nccacacbacbccbbccccaccccccbcbabbbaababa\r\n", "output": "ba\r\n"}, {"input": "ac\r\naacacaacbaaacbbbabacaca\r\n", "output": "a\r\n"}, {"input": "a\r\nzazaa\r\n", "output": "a\r\n"}, {"input": "abcd\r\nfaaaabbbbccccdddeda\r\n", "output": "a\r\n"}, {"input": "abcde\r\nfabcde\r\n", "output": "abcde\r\n"}, {"input": "a\r\nab\r\n", "output": "a\r\n"}, {"input": "ababbbbbbbbbbbb\r\nabbbbb\r\n", "output": "abbbbb\r\n"}, {"input": "bbbbaabbababbaaaaababbaaabbbbaaabbbababbbbabaabababaabaaabbbabababbbabababaababaaaaa\r\nbbabaaaabaaaabbaaabbbabaaabaabbbababbbbbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n", "output": "bbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n"}, {"input": "ab\r\naba\r\n", "output": "ab\r\n"}, {"input": "aa\r\naaaa\r\n", "output": "aa\r\n"}, {"input": "aaaaabbbaaaaa\r\naabbaa\r\n", "output": "aabbaa\r\n"}, {"input": "aaaaaaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "abbcc\r\naca\r\n", "output": "ac\r\n"}, {"input": "b\r\ncb\r\n", "output": "b\r\n"}, {"input": "aac\r\naaa\r\n", "output": "aa\r\n"}, {"input": "ba\r\nbb\r\n", "output": "b\r\n"}, {"input": "a\r\nb\r\n", "output": "-\r\n"}, {"input": "gkvubrvpbhsfiuyha\r\nihotmn\r\n", "output": "ih\r\n"}, {"input": "ccccabccbb\r\ncbbabcc\r\n", "output": "cabcc\r\n"}, {"input": "babababbaaabb\r\nabbab\r\n", "output": "abbab\r\n"}, {"input": "njtdhyqundyedsjyvy\r\nypjrs\r\n", "output": "ys\r\n"}, {"input": "uglyqhkpruxoakm\r\ncixxkpaaoodpuuh\r\n", "output": "uh\r\n"}, {"input": "a\r\naaaaaaaaa\r\n", "output": "a\r\n"}, {"input": "aaa\r\naaaaa\r\n", "output": "aaa\r\n"}, {"input": "abcabbcbcccbccbbcc\r\nacbcaabbbbcabbbaca\r\n", "output": "acbc\r\n"}, {"input": "caacacaacbaa\r\nacbbbabacacac\r\n", "output": "aacacac\r\n"}, {"input": "aa\r\naaab\r\n", "output": "aa\r\n"}, {"input": "acbc\r\ncacacbac\r\n", "output": "ac\r\n"}, {"input": "bacbcaacabbaacb\r\ncbbaaccccbcaacacaabb\r\n", "output": "cbcaabb\r\n"}, {"input": "baababaaaab\r\nbaababbbbbbb\r\n", "output": "baababb\r\n"}, {"input": "aaxyaba\r\naaba\r\n", "output": "aaba\r\n"}]
| 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] for _ in range(m+1)]
dp_i = [[0, 0, 0] for _ in range(m+1)]
dp[0][0] = 0
def solve1(i1, j1, i2, j2, c):
next_i = next_c[dp_i[i2][j2]][c]
if next_i != -1 and (dp[i1][j1] < dp[i2][j2]+1 or dp[i1][j1] == dp[i2][j2]+1 and dp_i[i1][j1] > next_i):
dp[i1][j1] = dp[i2][j2]+1
dp_i[i1][j1] = next_i
def solve2(i1, j1, i2, j2):
if dp[i1][j1] < dp[i2][j2] or dp[i1][j1] == dp[i2][j2] and dp_i[i1][j1] > dp_i[i2][j2]:
dp[i1][j1] = dp[i2][j2]
dp_i[i1][j1] = dp_i[i2][j2]
for i in range(m):
solve1(i+1, 0, i, 0, t[i])
solve2(i+1, 1, i, 0)
solve2(i+1, 1, i, 1)
solve1(i+1, 2, i, 1, t[i])
solve1(i+1, 2, i, 2, t[i])
i, j, max_len = 0, 0, 0
for ii in range(m+1):
for jj in range(3):
if max_len < dp[ii][jj]:
i, j, max_len = ii, jj, dp[i][j]
ans = []
while i > 0:
if j == 1 and dp[i-1][j] == dp[i][j] and dp_i[i-1][j] == dp_i[i][j]:
i -= 1
continue
if j == 1 and dp[i-1][j-1] == dp[i][j] and dp_i[i-1][j-1] == dp_i[i][j]:
i -= 1
j -= 1
continue
if j != 1 and dp[i-1][j]+1 == dp[i][j] and dp_i[i-1][j] < dp_i[i][j]:
ans.append(chr(97 + t[i-1]))
i -= 1
continue
if j == 2 and dp[i-1][j-1]+1 == dp[i][j] and dp_i[i-1][j-1] < dp_i[i][j]:
ans.append(chr(97 + t[i-1]))
i -= 1
j -= 1
print(''.join(reversed(ans)) if ans else '-')
| 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 = 0
st = 0
while st < m and ss < n:
if t[st] == s[ss]:
pre[ss] = st
ss += 1
st += 1
low = 0
high = n
min_ans = n
start = -1
end = -1
while low < high:
mid = (low + high) >> 1
ok = False
if post[mid] != -1:
if mid < min_ans:
min_ans = mid
start = 0
end = mid - 1
ok = True
for i in range(1, n - mid):
if pre[i - 1] != -1 and post[i + mid] != -1 and post[i + mid] > pre[i - 1]:
if mid < min_ans:
min_ans = mid
start = i
end = i + mid - 1
ok = True
if pre[n - mid - 1] != -1:
if mid < min_ans:
min_ans = mid
start = n - mid
end = n - 1
ok = True
if not ok:
low = mid + 1
else:
high = mid
ans = []
for i in range(n):
if start <= i <= end:
continue
ans.append(s[i])
if min_ans == n:
print('-')
else:
print(''.join(ans))
if __name__ == '__main__':
main()
|
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 the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
|
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\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk\r\n", "output": "ouypvk\r\n"}, {"input": "npnkmawey\r\nareakefvowledfriyjejqnnaeqheoh\r\n", "output": "a\r\n"}, {"input": "fdtffutxkujflswyddvhusfcook\r\nkavkhnhphcvckogqqqqhdmgwjdfenzizrebefsbuhzzwhzvc\r\n", "output": "kvc\r\n"}, {"input": "abacaba\r\naa\r\n", "output": "aa\r\n"}, {"input": "edbcd\r\nd\r\n", "output": "d\r\n"}, {"input": "abc\r\nksdksdsdsnabc\r\n", "output": "abc\r\n"}, {"input": "abxzxzxzzaba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abcd\r\nzzhabcd\r\n", "output": "abcd\r\n"}, {"input": "aa\r\naa\r\n", "output": "aa\r\n"}, {"input": "test\r\nt\r\n", "output": "t\r\n"}, {"input": "aa\r\na\r\n", "output": "a\r\n"}, {"input": "aaaabbbbaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "aa\r\nzzaa\r\n", "output": "aa\r\n"}, {"input": "zhbt\r\nztjihmhebkrztefpwty\r\n", "output": "zt\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaa\r\naaaaaaaa\r\n", "output": "aaaaaaaa\r\n"}, {"input": "abba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abbba\r\naba\r\n", "output": "aba\r\n"}, {"input": "aaaaaaaaaaaa\r\naaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaa\r\n"}, {"input": "aaa\r\naa\r\n", "output": "aa\r\n"}, {"input": "aaaaaaaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "aaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "ashfaniosafapisfasipfaspfaspfaspfapsfjpasfshvcmvncxmvnxcvnmcxvnmxcnvmcvxvnxmcvxcmvh\r\nashish\r\n", "output": "ashish\r\n"}, {"input": "a\r\na\r\n", "output": "a\r\n"}, {"input": "aaaab\r\naab\r\n", "output": "aab\r\n"}, {"input": "aaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "a\r\naaa\r\n", "output": "a\r\n"}, {"input": "aaaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "def\r\nabcdef\r\n", "output": "def\r\n"}, {"input": "aaaaaaaaa\r\na\r\n", "output": "a\r\n"}, {"input": "bababsbs\r\nabs\r\n", "output": "abs\r\n"}, {"input": "hddddddack\r\nhackyz\r\n", "output": "hack\r\n"}, {"input": "aba\r\na\r\n", "output": "a\r\n"}, {"input": "ofih\r\nihfsdf\r\n", "output": "ih\r\n"}, {"input": "b\r\nabb\r\n", "output": "b\r\n"}, {"input": "lctsczqr\r\nqvkp\r\n", "output": "q\r\n"}, {"input": "dedcbaa\r\ndca\r\n", "output": "dca\r\n"}, {"input": "haddack\r\nhack\r\n", "output": "hack\r\n"}, {"input": "abcabc\r\nabc\r\n", "output": "abc\r\n"}, {"input": "asdf\r\ngasdf\r\n", "output": "asdf\r\n"}, {"input": "abab\r\nab\r\n", "output": "ab\r\n"}, {"input": "aaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "asdf\r\nfasdf\r\n", "output": "asdf\r\n"}, {"input": "bbaabb\r\nab\r\n", "output": "ab\r\n"}, {"input": "accac\r\nbaacccbcccabaabbcacbbcccacbaabaaac\r\n", "output": "aac\r\n"}, {"input": "az\r\naaazazaa\r\n", "output": "a\r\n"}, {"input": "bbacaabbaaa\r\nacaabcaa\r\n", "output": "acaabaa\r\n"}, {"input": "c\r\ncbcbcbbacacacbccaaccbcabaaabbaaa\r\n", "output": "c\r\n"}, {"input": "bacb\r\nccacacbacbccbbccccaccccccbcbabbbaababa\r\n", "output": "ba\r\n"}, {"input": "ac\r\naacacaacbaaacbbbabacaca\r\n", "output": "a\r\n"}, {"input": "a\r\nzazaa\r\n", "output": "a\r\n"}, {"input": "abcd\r\nfaaaabbbbccccdddeda\r\n", "output": "a\r\n"}, {"input": "abcde\r\nfabcde\r\n", "output": "abcde\r\n"}, {"input": "a\r\nab\r\n", "output": "a\r\n"}, {"input": "ababbbbbbbbbbbb\r\nabbbbb\r\n", "output": "abbbbb\r\n"}, {"input": "bbbbaabbababbaaaaababbaaabbbbaaabbbababbbbabaabababaabaaabbbabababbbabababaababaaaaa\r\nbbabaaaabaaaabbaaabbbabaaabaabbbababbbbbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n", "output": "bbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n"}, {"input": "ab\r\naba\r\n", "output": "ab\r\n"}, {"input": "aa\r\naaaa\r\n", "output": "aa\r\n"}, {"input": "aaaaabbbaaaaa\r\naabbaa\r\n", "output": "aabbaa\r\n"}, {"input": "aaaaaaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "abbcc\r\naca\r\n", "output": "ac\r\n"}, {"input": "b\r\ncb\r\n", "output": "b\r\n"}, {"input": "aac\r\naaa\r\n", "output": "aa\r\n"}, {"input": "ba\r\nbb\r\n", "output": "b\r\n"}, {"input": "a\r\nb\r\n", "output": "-\r\n"}, {"input": "gkvubrvpbhsfiuyha\r\nihotmn\r\n", "output": "ih\r\n"}, {"input": "ccccabccbb\r\ncbbabcc\r\n", "output": "cabcc\r\n"}, {"input": "babababbaaabb\r\nabbab\r\n", "output": "abbab\r\n"}, {"input": "njtdhyqundyedsjyvy\r\nypjrs\r\n", "output": "ys\r\n"}, {"input": "uglyqhkpruxoakm\r\ncixxkpaaoodpuuh\r\n", "output": "uh\r\n"}, {"input": "a\r\naaaaaaaaa\r\n", "output": "a\r\n"}, {"input": "aaa\r\naaaaa\r\n", "output": "aaa\r\n"}, {"input": "abcabbcbcccbccbbcc\r\nacbcaabbbbcabbbaca\r\n", "output": "acbc\r\n"}, {"input": "caacacaacbaa\r\nacbbbabacacac\r\n", "output": "aacacac\r\n"}, {"input": "aa\r\naaab\r\n", "output": "aa\r\n"}, {"input": "acbc\r\ncacacbac\r\n", "output": "ac\r\n"}, {"input": "bacbcaacabbaacb\r\ncbbaaccccbcaacacaabb\r\n", "output": "cbcaabb\r\n"}, {"input": "baababaaaab\r\nbaababbbbbbb\r\n", "output": "baababb\r\n"}, {"input": "aaxyaba\r\naaba\r\n", "output": "aaba\r\n"}]
| 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.values()))
if len(d)==1:
if n+max(d.values())>len(b):
if (n+max(d.values())-len(b))%2==1:
f=len(b)-1
d={}
for i in c:
d[i]=0
for i in c:
d[i]+=1
g=min(len(c),n+max(d.values()))
if len(d)==1:
if n+max(d.values())>len(c):
if (n+max(d.values())-len(c))%2==1:
g=len(c)-1
if e>f and e>g:
print("Kuro")
elif f>g and f>e:
print("Shiro")
elif g>f and g>e:
print("Katie")
else:
print("Draw")
| 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[1] -=1
else:
m2[1]=l
else:
m2[1] = m2[1]+n
m3 = list(Counter(katie).most_common()[0])
if n > l-m3[1]:
if n==1:
m3[1] -=1
else:
m3[1]=l
else:
m3[1] = m3[1]+n
M = max(m1[1],m2[1],m3[1])
if (m1[1],m2[1],m3[1]).count(M) > 1:
print("Draw")
elif M==m1[1]:
print("Kuro")
elif M==m2[1]:
print("Shiro")
else:
print("Katie")
|
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. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $$$7$$$ because its subribbon a appears $$$7$$$ times, and the ribbon abcdabc has the beauty of $$$2$$$ because its subribbon abc appears twice.
The rules are simple. The game will have $$$n$$$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $$$n$$$ turns wins the treasure.
Could you find out who is going to be the winner if they all play optimally?
|
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 that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
|
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 into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is $$$9$$$ and the number of turn is $$$15$$$, everyone can change their ribbons in some way to reach the maximal beauty of $$$9$$$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.
|
[{"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"}, {"input": "1\r\naaaaaaaaaa\r\nAAAAAAcAAA\r\nbbbbbbzzbb\r\n", "output": "Shiro\r\n"}, {"input": "60\r\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\r\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\r\nXaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ\r\n", "output": "Draw\r\n"}, {"input": "9174\r\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzcccbccczzbbcbbzbzzzcbczbzbzzbbbczbbcbzzzbcbzczbcczb\r\ndbzzzccdcdczzzzzcdczbbzcdzbcdbzzdczbzddcddbdbzzzczcczzbdcbbzccbzzzdzbzddcbzbdzdcczccbdb\r\nzdczddzcdddddczdczdczdcdzczddzczdzddczdcdcdzczczzdzccdccczczdzczczdzcdddzddzccddcczczzd\r\n", "output": "Draw\r\n"}, {"input": "727\r\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\r\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\r\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffeeeeeefeffef\r\n", "output": "Draw\r\n"}, {"input": "61\r\nbzqiqprzfwddqwctcrhnkqcsnbmcmfmrgaljwieajfouvuiunmfbrehxchupmsdpwilwu\r\njyxxujvxkwilikqeegzxlyiugflxqqbwbujzedqnlzucdnuipacatdhcozuvgktwvirhs\r\ntqiahohijwfcetyyjlkfhfvkhdgllxmhyyhhtlhltcdspusyhwpwqzyagtsbaswaobwub\r\n", "output": "Katie\r\n"}, {"input": "30\r\njAjcdwkvcTYSYBBLniJIIIiubKWnqeDtUiaXSIPfhDTOrCWBQetm\r\nPQPOTgqfBWzQvPNeEaUaPQGdUgldmOZsBtsIqZGGyXozntMpOsyY\r\nNPfvGxMqIULNWOmUrHJfsqORUHkzKQfecXsTzgFCmUtFmIBudCJr\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcabcabcabcdddabc\r\nzxytzytxxtytxyzxyt\r\nfgffghfghffgghghhh\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabcd\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaa\r\naaaabbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nbbb\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nlkjhg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\nbbbbb\r\naabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\nfghij\r\nkkkkk\r\n", "output": "Katie\r\n"}, {"input": "4\r\naaaabcd\r\naaaabcd\r\naaaaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naabcde\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaaa\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "1\r\nAAAAA\r\nBBBBB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "1\r\nabcde\r\naaaaa\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabfcde\r\nabfcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\naaa\r\naab\r\nccd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaa\r\naaaaa\r\naabbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\nxxxxxx\r\nxxxooo\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\noooo\r\naaac\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaaaaa\r\naaabcde\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\naaabb\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nqwert\r\nqwery\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaa\r\nbbbbbb\r\naaaaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabb\r\naabb\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naab\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nbbbbcc\r\nbbbbbb\r\nsadfgh\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaacc\r\nxxxxkkkk\r\nxxxxkkkk\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaac\r\nbbbbc\r\nccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaabbbbbb\r\nabcdewert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabc\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaa\r\naaaaaaab\r\naaaabbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcdefg\r\nabccccc\r\nacccccc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaabbb\r\nabcdef\r\nabcdef\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaabbb\r\naabdef\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabba\r\nbbbb\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbbaaa\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaa\r\naaa\r\nabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcda\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nabcde\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabbc\r\nqwert\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabbcc\r\naabbcc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nAAAAAA\r\nAAAAAB\r\nABCDEF\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabc\r\naac\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naabbc\r\naabbc\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaaab\r\naaaaabb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaaaa\r\nbbbbbbbbaaa\r\nqwertyuiasd\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\naabb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabcd\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaa\r\nabc\r\nbbb\r\n", "output": "Draw\r\n"}, {"input": "1\r\naa\r\nab\r\nbb\r\n", "output": "Shiro\r\n"}, {"input": "1\r\naacb\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaabbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "2\r\nabcd\r\nabcd\r\naaad\r\n", "output": "Katie\r\n"}, {"input": "3\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaaaab\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaab\r\nabcd\r\nabcd\r\n", "output": "Kuro\r\n"}, {"input": "3\r\nooooo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naabcd\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "4\r\nabcd\r\nabcd\r\naaaa\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaa\r\nbbb\r\naab\r\n", "output": "Draw\r\n"}, {"input": "2\r\nxxxx\r\nyyyx\r\nabcd\r\n", "output": "Draw\r\n"}, {"input": "3\r\nAAAAA\r\nAAAAB\r\nABCDE\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaacdc\r\naaaaabc\r\naaaaabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naabcde\r\naabcde\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaabb\r\naaabb\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\nabbbbb\r\ncbbbbb\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaaaaa\r\naaaaabbbb\r\naaaaabbbb\r\n", "output": "Kuro\r\n"}, {"input": "4\r\naaaaaab\r\naaabbbb\r\naaabbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaabb\r\naaaabb\r\naaabbb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaabb\r\naaaaab\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaa\r\naaaae\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\nbbbcde\r\nabcdef\r\n", "output": "Draw\r\n"}, {"input": "4\r\naaaabbb\r\naabcdef\r\naabcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaaaa\r\naaaab\r\nabcde\r\n", "output": "Draw\r\n"}, {"input": "3\r\naabbbbb\r\naaabbbb\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcde\r\naabcd\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "5\r\naaabbcc\r\nabcdefg\r\nabcdefg\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naabbb\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "0\r\nbbb\r\nabb\r\nqer\r\n", "output": "Kuro\r\n"}, {"input": "5\r\naabbbbb\r\naaaaaaa\r\nabcdefg\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaab\r\naaaab\r\naaabb\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaaaab\r\naaaabbb\r\naaaaccc\r\n", "output": "Kuro\r\n"}, {"input": "3\r\naaaaaaaaaaaa\r\naaaaaaaaaaab\r\naaaaaabbbbbb\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaabb\r\nabcde\r\naaaaa\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaac\r\naaaaebc\r\naaaaaac\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaaa\r\naaabbb\r\nqwerty\r\n", "output": "Draw\r\n"}, {"input": "3\r\ncccca\r\nabcde\r\nabcde\r\n", "output": "Kuro\r\n"}, {"input": "100005\r\nAA\r\nBC\r\nCC\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\nbbbb\r\nccca\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaaa\r\nbcdef\r\nbcdef\r\n", "output": "Kuro\r\n"}, {"input": "2\r\naaab\r\naabb\r\nqwer\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\nbbaaaa\r\n", "output": "Draw\r\n"}, {"input": "2\r\naaaa\r\naaaa\r\naabc\r\n", "output": "Draw\r\n"}, {"input": "3\r\naaaa\r\naaaa\r\naaab\r\n", "output": "Draw\r\n"}, {"input": "3\r\nabcddd\r\nabcdef\r\naaaaaa\r\n", "output": "Draw\r\n"}, {"input": "1\r\naaaa\r\nabcd\r\naaab\r\n", "output": "Katie\r\n"}]
| 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):
for j in range(m):
if g[i][j].isdigit():
cmp += int(g[i][j]) - 0
for i in range(n):
for j in range(m):
if g[i][j] == '*':
for [x, y] in D:
dx = i + x
dy = j + y
if vaild(dx, dy) and g[dx][dy] != '*':
ret += 1
if ret == cmp:
print("YES")
else:
print("NO")
main()
| 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 <= a+i <= n-1 and 0 <= b+j <= m-1:
if g[a+i][b+j] == '*':
c += 1
if g[a][b] == c:
return 1
return 0
ans = "YES"
for i in range(n):
for j in range(m):
if g[i][j] != '*':
if f(i,j) == 0:
ans = "NO"
break
if ans == "NO":
break
print(ans)
|
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 difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $$$n \times m$$$, where each cell is either empty, or contains a digit from $$$1$$$ to $$$8$$$, or a bomb. The field is valid if for each cell:
- if there is a digit $$$k$$$ in the cell, then exactly $$$k$$$ neighboring cells have bombs.
- if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $$$8$$$ neighboring cells).
|
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 $$$8$$$, inclusive.
|
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*31..11\r\n..111..111\r\n.......1*1\r\n.......111\r\n", "output": "YES"}, {"input": "10 17\r\n12*2*22123*31....\r\n2*333*3*4***3211.\r\n*22*213**4***3*1.\r\n11111.12224*6*21.\r\n221..111.14**4311\r\n**2233*212****2*1\r\n*55***4*13*544421\r\n2***54*322*21**31\r\n13*4*33*221114*4*\r\n.1122*22*1...2*31\r\n", "output": "YES"}, {"input": "10 10\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n******3***\r\n**********\r\n**********\r\n**********\r\n***3.5****\r\n", "output": "NO"}, {"input": "21 10\r\n62637783*1\r\n23*51**531\r\n35*7*6.**.\r\n.*3***581*\r\n2.32*745**\r\n83*7*6*6*5\r\n*74.**6**3\r\n323*6**7*6\r\n3454*67.*1\r\n**63265*6*\r\n3725*4553*\r\n24****5**4\r\n23.34****4\r\n55257*1*4*\r\n4*3253*456\r\n**.3*45488\r\n*7318**4*5\r\n234.*4557*\r\n12..21*.*3\r\n286.225*4*\r\n834*11*.3*\r\n", "output": "NO"}, {"input": "10 10\r\n**********\r\n*********6\r\n*********5\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n", "output": "NO"}, {"input": "100 1\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n1\r\n1\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n*\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n", "output": "YES"}, {"input": "1 100\r\n*************5****5****************************************************4****************************\r\n", "output": "NO"}, {"input": "1 100\r\n..1*1..........................1*1....1*1....1*1.1*1....1*1..1**1........................1**1.......\r\n", "output": "YES"}, {"input": "1 100\r\n.....1*1........1*1................................1*1...1**11*1.......1*1....1.....1*1.....1*1...1*\r\n", "output": "NO"}, {"input": "1 10\r\n881111882*\r\n", "output": "NO"}, {"input": "5 5\r\n*2221\r\n24**2\r\n*3*5*\r\n3425*\r\n**12*\r\n", "output": "NO"}, {"input": "5 5\r\n****2\r\n4***4\r\n3****\r\n3*563\r\n*22**\r\n", "output": "NO"}, {"input": "5 5\r\n***2.\r\n5**31\r\n**6**\r\n***43\r\n**31*\r\n", "output": "NO"}, {"input": "5 5\r\n*32**\r\n4*3*4\r\n**44*\r\n**45*\r\n*4***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n*2*\r\n***\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "1 2\r\n*1\r\n", "output": "YES"}, {"input": "1 2\r\n*2\r\n", "output": "NO"}, {"input": "2 2\r\n32\r\n**\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n232\r\n***\r\n", "output": "YES"}, {"input": "3 2\r\n..\r\n11\r\n.*\r\n", "output": "NO"}, {"input": "2 3\r\n1*2\r\n3*2\r\n", "output": "NO"}, {"input": "1 3\r\n.*.\r\n", "output": "NO"}, {"input": "3 1\r\n.\r\n*\r\n.\r\n", "output": "NO"}, {"input": "3 1\r\n1\r\n*\r\n1\r\n", "output": "YES"}, {"input": "3 1\r\n*\r\n1\r\n*\r\n", "output": "NO"}, {"input": "1 3\r\n1**\r\n", "output": "YES"}, {"input": "1 1\r\n8\r\n", "output": "NO"}, {"input": "1 1\r\n.\r\n", "output": "YES"}, {"input": "1 2\r\n2*\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n2\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n*\r\n", "output": "YES"}, {"input": "2 1\r\n.\r\n1\r\n", "output": "NO"}, {"input": "1 3\r\n..1\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n.*.\r\n...\r\n", "output": "NO"}, {"input": "3 3\r\n112\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n11.\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n151\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n1.1\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n611\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n.11\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n2*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n**1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n5*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n.*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n411\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n.11\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n121\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n1.1\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n115\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n11.\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*4\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*.\r\n111\r\n", "output": "NO"}, {"input": "1 4\r\n*222\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "2 2\r\n**\r\n**\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*.*\r\n***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n***\r\n***\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*4*\r\n***\r\n", "output": "NO"}, {"input": "2 6\r\n....1.\r\n.....*\r\n", "output": "NO"}, {"input": "5 5\r\n*****\r\n*****\r\n*****\r\n*****\r\n*****\r\n", "output": "YES"}, {"input": "4 1\r\n.\r\n*\r\n.\r\n.\r\n", "output": "NO"}, {"input": "2 2\r\n2*\r\n11\r\n", "output": "NO"}, {"input": "3 3\r\n888\r\n888\r\n888\r\n", "output": "NO"}, {"input": "1 4\r\n*22*\r\n", "output": "NO"}]
| 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
else:
s +=" "+i
print(s)
| 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:
curr+=c
if curr:
words.append(curr)
print(' '.join(words))
|
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, then they should be separated by exactly one space
- there should be no spaces before each punctuation mark
- there should be exactly one space after each punctuation mark
It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.
|
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\n"}, {"input": "a a a a a\r\n", "output": "a a a a a\r\n"}, {"input": "ksdfk sdlfsdf sdf sdf sdf\r\n", "output": "ksdfk sdlfsdf sdf sdf sdf\r\n"}, {"input": "gdv\r\n", "output": "gdv\r\n"}, {"input": "incen q\r\n", "output": "incen q\r\n"}, {"input": "k ? gq dad\r\n", "output": "k? gq dad\r\n"}, {"input": "ntomzzut !pousysvfg ,rnl mcyytihe hplnqnb\r\n", "output": "ntomzzut! pousysvfg, rnl mcyytihe hplnqnb\r\n"}, {"input": "mck . gq dauqminf wee bazyzy humnv d pgtvx , vxntxgrkrc rg rwr, uuyweyz l\r\n", "output": "mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l\r\n"}, {"input": "jjcmhwnon taetfgdvc, ysrajurstj ! fryavybwpg hnxbnsron ,txplbmm atw?wkfhn ez mcdn tujsy wrdhw . k i lzwtxcyam fi . nyeu j\r\n", "output": "jjcmhwnon taetfgdvc, ysrajurstj! fryavybwpg hnxbnsron, txplbmm atw? wkfhn ez mcdn tujsy wrdhw. k i lzwtxcyam fi. nyeu j\r\n"}, {"input": "chcf htb flfwkosmda a qygyompixkgz ?rg? hdw f dsvqzs kxvjt ? zj zghgarwihw zgrhr xlwmhv . lycpsmdm iotv . d jhsxoogbr ! ppgrpwcrcl inw usegrtd ?fexma ? mhszrvdoa ,audsrhina epoleuq oaz hqapedl lm\r\n", "output": "chcf htb flfwkosmda a qygyompixkgz? rg? hdw f dsvqzs kxvjt? zj zghgarwihw zgrhr xlwmhv. lycpsmdm iotv. d jhsxoogbr! ppgrpwcrcl inw usegrtd? fexma? mhszrvdoa, audsrhina epoleuq oaz hqapedl lm\r\n"}, {"input": "x\r\n", "output": "x\r\n"}, {"input": "xx\r\n", "output": "xx\r\n"}, {"input": "x x\r\n", "output": "x x\r\n"}, {"input": "x,x\r\n", "output": "x, x\r\n"}, {"input": "x.x\r\n", "output": "x. x\r\n"}, {"input": "x!x\r\n", "output": "x! x\r\n"}, {"input": "x?x\r\n", "output": "x? x\r\n"}, {"input": "a!b\r\n", "output": "a! b\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "physicist ?mathematician.astronomer\r\n", "output": "physicist? mathematician. astronomer\r\n"}, {"input": "dfgdfg ? ddfgdsfg ? dsfgdsfgsdfgdsf ! dsfg . sd dsg sdg ! sdfg\r\n", "output": "dfgdfg? ddfgdsfg? dsfgdsfgsdfgdsf! dsfg. sd dsg sdg! sdfg\r\n"}, {"input": "jojo ! majo , hehehehe? jo . kok\r\n", "output": "jojo! majo, hehehehe? jo. kok\r\n"}, {"input": "adskfj,kjdf?kjadf kj!kajs f\r\n", "output": "adskfj, kjdf? kjadf kj! kajs f\r\n"}, {"input": "a , b\r\n", "output": "a, b\r\n"}, {"input": "ahmed? ahmed ? ahmed ?ahmed\r\n", "output": "ahmed? ahmed? ahmed? ahmed\r\n"}, {"input": "kjdsf, kdjf?kjdf!kj kdjf\r\n", "output": "kjdsf, kdjf? kjdf! kj kdjf\r\n"}, {"input": "italian physicist .mathematician?astronomer\r\n", "output": "italian physicist. mathematician? astronomer\r\n"}, {"input": "galileo galilei was an italian physicist , mathematician,astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "z zz zz z z! z z aksz zkjsdfz kajfz z !akj , zz a z\r\n", "output": "z zz zz z z! z z aksz zkjsdfz kajfz z! akj, zz a z\r\n"}, {"input": "jojo ! maja . jaooo\r\n", "output": "jojo! maja. jaooo\r\n"}, {"input": "a ! b\r\n", "output": "a! b\r\n"}, {"input": "fff , fff\r\n", "output": "fff, fff\r\n"}, {"input": "a!a?a ! a ? a\r\n", "output": "a! a? a! a? a\r\n"}, {"input": "a!a\r\n", "output": "a! a\r\n"}, {"input": "a!a a ! a ? a ! a , a . a\r\n", "output": "a! a a! a? a! a, a. a\r\n"}, {"input": "casa?mesa, y unos de , los sapotes?l\r\n", "output": "casa? mesa, y unos de, los sapotes? l\r\n"}, {"input": "ff ! ff\r\n", "output": "ff! ff\r\n"}, {"input": "i love evgenia ! x\r\n", "output": "i love evgenia! x\r\n"}, {"input": "galileo galilei was an italian physicist ,mathematician,astronomer?asdf ?asdfff?asdf. asdf.dfd .dfdf ? df d! sdf dsfsa sdf ! asdf ? sdfsdf, dfg a ! b ?a\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer? asdf? asdfff? asdf. asdf. dfd. dfdf? df d! sdf dsfsa sdf! asdf? sdfsdf, dfg a! b? a\r\n"}, {"input": "a , a\r\n", "output": "a, a\r\n"}, {"input": "x, werwr, werwerwr we,rwer ,wer\r\n", "output": "x, werwr, werwerwr we, rwer, wer\r\n"}, {"input": "abcabc, abcabc\r\n", "output": "abcabc, abcabc\r\n"}, {"input": "i love evgenia x! x\r\n", "output": "i love evgenia x! x\r\n"}, {"input": "gg gg,h,h,j,i,jh , jjj , jj ,aadd , jjj jjj\r\n", "output": "gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj\r\n"}, {"input": "mt test ! case\r\n", "output": "mt test! case\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "asdasdasd.asdasdasdasd?asdasdasd!asdasdasd,asdasdasdasd\r\n", "output": "asdasdasd. asdasdasdasd? asdasdasd! asdasdasd, asdasdasdasd\r\n"}, {"input": "x, x, ds ,ertert, ert, et et\r\n", "output": "x, x, ds, ertert, ert, et et\r\n"}, {"input": "anton!love ?yourself\r\n", "output": "anton! love? yourself\r\n"}, {"input": "facepalm ? yes , lol ! yeah\r\n", "output": "facepalm? yes, lol! yeah\r\n"}, {"input": "a ! a\r\n", "output": "a! a\r\n"}, {"input": "adf!kadjf?kajdf,lkdas. kd ! akdjf\r\n", "output": "adf! kadjf? kajdf, lkdas. kd! akdjf\r\n"}, {"input": "a? x\r\n", "output": "a? x\r\n"}, {"input": "read problem carefully ! heh\r\n", "output": "read problem carefully! heh\r\n"}, {"input": "a?a?a?a.a\r\n", "output": "a? a? a? a. a\r\n"}, {"input": "a. v\r\n", "output": "a. v\r\n"}, {"input": "a!a a ! a ? a ! a , a . a aaaaaa ! a ! a. a a .a a.a aa.aa aa . aa aa .aa aa. aa\r\n", "output": "a! a a! a? a! a, a. a aaaaaa! a! a. a a. a a. a aa. aa aa. aa aa. aa aa. aa\r\n"}, {"input": "a, a\r\n", "output": "a, a\r\n"}, {"input": "a!a!a\r\n", "output": "a! a! a\r\n"}, {"input": "a.a.a.a\r\n", "output": "a. a. a. a\r\n"}, {"input": "a, b\r\n", "output": "a, b\r\n"}, {"input": "galileo galilei was an italian physicist, mathematician, astronomer\r\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\r\n"}, {"input": "a!a!a!a\r\n", "output": "a! a! a! a\r\n"}, {"input": "af ! kadjf ? kjdfkj!kjadkfjz z z a a! ka,kjf\r\n", "output": "af! kadjf? kjdfkj! kjadkfjz z z a a! ka, kjf\r\n"}, {"input": "ab cd,k\r\n", "output": "ab cd, k\r\n"}, {"input": "a!n , to\r\n", "output": "a! n, to\r\n"}, {"input": "dolphi ! nigle\r\n", "output": "dolphi! nigle\r\n"}, {"input": "u, sux\r\n", "output": "u, sux\r\n"}]
| 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("NO")
| 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 name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
|
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": "YYHUIUGYI\r\n", "output": "NO\r\n"}, {"input": "TT\r\n", "output": "YES\r\n"}, {"input": "UUU\r\n", "output": "YES\r\n"}, {"input": "WYYW\r\n", "output": "YES\r\n"}, {"input": "MITIM\r\n", "output": "YES\r\n"}, {"input": "VO\r\n", "output": "NO\r\n"}, {"input": "WWS\r\n", "output": "NO\r\n"}, {"input": "VIYMAXXAVM\r\n", "output": "NO\r\n"}, {"input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM\r\n", "output": "NO\r\n"}, {"input": "CC\r\n", "output": "NO\r\n"}, {"input": "QOQ\r\n", "output": "NO\r\n"}, {"input": "AEEA\r\n", "output": "NO\r\n"}, {"input": "OQQQO\r\n", "output": "NO\r\n"}, {"input": "HNCMEEMCNH\r\n", "output": "NO\r\n"}, {"input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ\r\n", "output": "NO\r\n"}, {"input": "A\r\n", "output": "YES\r\n"}, {"input": "B\r\n", "output": "NO\r\n"}, {"input": "C\r\n", "output": "NO\r\n"}, {"input": "D\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}, {"input": "F\r\n", "output": "NO\r\n"}, {"input": "G\r\n", "output": "NO\r\n"}, {"input": "H\r\n", "output": "YES\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "J\r\n", "output": "NO\r\n"}, {"input": "K\r\n", "output": "NO\r\n"}, {"input": "L\r\n", "output": "NO\r\n"}, {"input": "M\r\n", "output": "YES\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "O\r\n", "output": "YES\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "Q\r\n", "output": "NO\r\n"}, {"input": "R\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "T\r\n", "output": "YES\r\n"}, {"input": "U\r\n", "output": "YES\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "W\r\n", "output": "YES\r\n"}, {"input": "X\r\n", "output": "YES\r\n"}, {"input": "Y\r\n", "output": "YES\r\n"}, {"input": "JL\r\n", "output": "NO\r\n"}, {"input": "AAAKTAAA\r\n", "output": "NO\r\n"}, {"input": "AKA\r\n", "output": "NO\r\n"}, {"input": "AAJAA\r\n", "output": "NO\r\n"}, {"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "AAAAAABAAAAAA\r\n", "output": "NO\r\n"}, {"input": "ZZ\r\n", "output": "NO\r\n"}, {"input": "ADA\r\n", "output": "NO\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "LAL\r\n", "output": "NO\r\n"}, {"input": "AABAA\r\n", "output": "NO\r\n"}, {"input": "AZA\r\n", "output": "NO\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "SSS\r\n", "output": "NO\r\n"}, {"input": "NNN\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "SS\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}]
| 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:
da = a[pa] - b[j]
da = da if da>0 else -da
db = a[i] - b[pb]
db = db if db>0 else -db
if da < db:
i += 1
continue
else:
j+=1
continue
elif pa<la:
i += 1
continue
elif pb<lb:
j += 1
continue
else:
break
print(c)
| 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
g.remove(boy+1)
break
elif (boy - 1) == girl:
pair += 1
g.remove(boy-1)
break
print(pair)
|
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 must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
|
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 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.
|
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"}, {"input": "4\r\n4 5 4 4\r\n5\r\n5 3 4 2 4\r\n", "output": "4\r\n"}, {"input": "1\r\n2\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n2\r\n3 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n3\r\n4 4 4\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n4\r\n3 1 4 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n5\r\n2 5 5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "2\r\n4 2\r\n2\r\n4 4\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n3\r\n2 3 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n4\r\n5 5 5 6\r\n", "output": "1\r\n"}, {"input": "2\r\n5 7\r\n5\r\n4 6 7 2 5\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "3\r\n5 4 5\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n6 3 4\r\n3\r\n4 5 2\r\n", "output": "3\r\n"}, {"input": "3\r\n7 7 7\r\n4\r\n2 7 2 4\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 3\r\n5\r\n1 3 4 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 3\r\n1\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n4 4 6 6\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "4\r\n3 1 1 1\r\n3\r\n1 6 7\r\n", "output": "1\r\n"}, {"input": "4\r\n2 5 1 2\r\n4\r\n2 3 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n9 1 7 1\r\n5\r\n9 9 9 8 4\r\n", "output": "2\r\n"}, {"input": "5\r\n1 6 5 5 6\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 4 5 6\r\n2\r\n7 4\r\n", "output": "2\r\n"}, {"input": "5\r\n4 1 3 1 4\r\n3\r\n6 3 6\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 3 1 4\r\n4\r\n1 3 1 7\r\n", "output": "3\r\n"}, {"input": "5\r\n9 8 10 9 10\r\n5\r\n2 1 5 4 6\r\n", "output": "0\r\n"}, {"input": "1\r\n48\r\n100\r\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6\r\n", "output": "1\r\n"}, {"input": "100\r\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\r\n1\r\n58\r\n", "output": "0\r\n"}, {"input": "10\r\n20 87 3 39 20 20 8 40 70 51\r\n100\r\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96\r\n", "output": "6\r\n"}, {"input": "100\r\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\r\n10\r\n66 74 40 67 28 82 99 57 93 64\r\n", "output": "9\r\n"}, {"input": "100\r\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\r\n100\r\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1\r\n", "output": "76\r\n"}, {"input": "4\r\n1 6 9 15\r\n2\r\n5 8\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 5\r\n3\r\n3 4 6\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 4\r\n3\r\n2 1 5\r\n", "output": "3\r\n"}, {"input": "2\r\n5 5\r\n4\r\n1 1 1 5\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "2\r\n3 1\r\n2\r\n2 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n10 12\r\n2\r\n11 9\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n3\r\n3 2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n1 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n4 5\r\n2\r\n5 3\r\n", "output": "2\r\n"}, {"input": "2\r\n7 5\r\n2\r\n6 8\r\n", "output": "2\r\n"}, {"input": "4\r\n4 3 2 1\r\n4\r\n1 2 3 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 3\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n3\r\n3 1 8\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 1\r\n3\r\n2 4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 3\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 3 3\r\n4\r\n2 2 1 1\r\n", "output": "4\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n2 4 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n5\r\n2 3 4 5 1\r\n", "output": "5\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n5 4\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 5 5\r\n4\r\n4 4 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n2 7 5\r\n3\r\n2 4 8\r\n", "output": "3\r\n"}, {"input": "100\r\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\r\n100\r\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5\r\n", "output": "100\r\n"}, {"input": "1\r\n3\r\n2\r\n2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n5 6\r\n3\r\n1 5 100\r\n", "output": "1\r\n"}, {"input": "2\r\n2 7\r\n2\r\n6 8\r\n", "output": "1\r\n"}, {"input": "4\r\n4 10 15 17\r\n4\r\n3 12 16 16\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n2\r\n1 2\r\n", "output": "2\r\n"}]
| 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
elif j == g - 1:
i += 1
else:
if abs(boys[i+1] - girls[j]) < abs(boys[i] - girls[j+1]):
i += 1
else:
j += 1
print(count)
| 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 must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
|
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 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.
|
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"}, {"input": "4\r\n4 5 4 4\r\n5\r\n5 3 4 2 4\r\n", "output": "4\r\n"}, {"input": "1\r\n2\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n2\r\n3 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n3\r\n4 4 4\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n4\r\n3 1 4 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n5\r\n2 5 5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "2\r\n4 2\r\n2\r\n4 4\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n3\r\n2 3 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n4\r\n5 5 5 6\r\n", "output": "1\r\n"}, {"input": "2\r\n5 7\r\n5\r\n4 6 7 2 5\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "3\r\n5 4 5\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n6 3 4\r\n3\r\n4 5 2\r\n", "output": "3\r\n"}, {"input": "3\r\n7 7 7\r\n4\r\n2 7 2 4\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 3\r\n5\r\n1 3 4 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 3\r\n1\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n4 4 6 6\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "4\r\n3 1 1 1\r\n3\r\n1 6 7\r\n", "output": "1\r\n"}, {"input": "4\r\n2 5 1 2\r\n4\r\n2 3 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n9 1 7 1\r\n5\r\n9 9 9 8 4\r\n", "output": "2\r\n"}, {"input": "5\r\n1 6 5 5 6\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 4 5 6\r\n2\r\n7 4\r\n", "output": "2\r\n"}, {"input": "5\r\n4 1 3 1 4\r\n3\r\n6 3 6\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 3 1 4\r\n4\r\n1 3 1 7\r\n", "output": "3\r\n"}, {"input": "5\r\n9 8 10 9 10\r\n5\r\n2 1 5 4 6\r\n", "output": "0\r\n"}, {"input": "1\r\n48\r\n100\r\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6\r\n", "output": "1\r\n"}, {"input": "100\r\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\r\n1\r\n58\r\n", "output": "0\r\n"}, {"input": "10\r\n20 87 3 39 20 20 8 40 70 51\r\n100\r\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96\r\n", "output": "6\r\n"}, {"input": "100\r\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\r\n10\r\n66 74 40 67 28 82 99 57 93 64\r\n", "output": "9\r\n"}, {"input": "100\r\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\r\n100\r\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1\r\n", "output": "76\r\n"}, {"input": "4\r\n1 6 9 15\r\n2\r\n5 8\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 5\r\n3\r\n3 4 6\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 4\r\n3\r\n2 1 5\r\n", "output": "3\r\n"}, {"input": "2\r\n5 5\r\n4\r\n1 1 1 5\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "2\r\n3 1\r\n2\r\n2 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n10 12\r\n2\r\n11 9\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n3\r\n3 2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n1 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n4 5\r\n2\r\n5 3\r\n", "output": "2\r\n"}, {"input": "2\r\n7 5\r\n2\r\n6 8\r\n", "output": "2\r\n"}, {"input": "4\r\n4 3 2 1\r\n4\r\n1 2 3 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 3\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n3\r\n3 1 8\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 1\r\n3\r\n2 4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 3\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 3 3\r\n4\r\n2 2 1 1\r\n", "output": "4\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n2 4 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n5\r\n2 3 4 5 1\r\n", "output": "5\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n5 4\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 5 5\r\n4\r\n4 4 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n2 7 5\r\n3\r\n2 4 8\r\n", "output": "3\r\n"}, {"input": "100\r\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\r\n100\r\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5\r\n", "output": "100\r\n"}, {"input": "1\r\n3\r\n2\r\n2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n5 6\r\n3\r\n1 5 100\r\n", "output": "1\r\n"}, {"input": "2\r\n2 7\r\n2\r\n6 8\r\n", "output": "1\r\n"}, {"input": "4\r\n4 10 15 17\r\n4\r\n3 12 16 16\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n2\r\n1 2\r\n", "output": "2\r\n"}]
| 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')
exit(0)
b, sc, fc = -1, 0, 0
for i in range(n):
if num[i] != '4' and num[i] != '7':
b = i
break
sc += num[i] == '7'
fc += num[i] == '4'
if sc > n // 2 or fc > n // 2:
b = i
break
if b == -1:
print(''.join(num))
elif num[b] < '4':
print(''.join(num[:b]) + '4' * (n // 2 - fc) + '7' * (n // 2 - sc))
elif num[b] == '4':
print(''.join(num[:b]) + '7' * (n - b))
elif num[b] < '7':
print(''.join(num[:b]) + '7' + '4' * (n // 2 - fc) + '7' * (n // 2 - sc - 1))
else:
sc -= num[b] == '7'
while num[b - 1] != '4':
sc -= 1
b -= 1
b -= 1
fc -= 1
print(''.join(num[:b]) + '7' + '4' * (n // 2 - fc) + '7' * (n // 2 - sc - 1))
| 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
n4 -= 1;continue
if n4 > 0:z = (i, "4", n4 - 1, n7)
break
else:z=(n,'',0,0)
P(f(*z))
|
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. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
|
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", "output": "4444477777"}, {"input": "49102094540227023300\r\n", "output": "74444444444777777777\r\n"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "777777\r\n", "output": "44447777"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "474\r\n", "output": "4477"}, {"input": "85469\r\n", "output": "444777"}, {"input": "7474747\r\n", "output": "44447777"}, {"input": "2145226\r\n", "output": "44447777"}, {"input": "5556585\r\n", "output": "44447777"}, {"input": "87584777\r\n", "output": "4444477777"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "999999999\r\n", "output": "4444477777"}, {"input": "74477744\r\n", "output": "74477744\r\n"}, {"input": "444444444\r\n", "output": "4444477777"}, {"input": "467549754\r\n", "output": "4444477777"}, {"input": "147474747\r\n", "output": "4444477777"}, {"input": "555\r\n", "output": "4477"}, {"input": "100000\r\n", "output": "444777\r\n"}, {"input": "74777443\r\n", "output": "74777444\r\n"}, {"input": "4700007\r\n", "output": "44447777"}, {"input": "70070077\r\n", "output": "74444777\r\n"}, {"input": "123\r\n", "output": "4477"}, {"input": "7474\r\n", "output": "7474\r\n"}, {"input": "3696\r\n", "output": "4477\r\n"}, {"input": "5594108733309806863211189515406929423407691887690557101598403485\r\n", "output": "7444444444444444444444444444444447777777777777777777777777777777\r\n"}, {"input": "7004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224\r\n", "output": "7444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777\r\n"}, {"input": "795193728547733389463100378996233822835539327235483308682350676991954960294227364128385843182064933115\r\n", "output": "44444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777"}, {"input": "61136338618684683458627308377793588546921041456473994251912971721612136383004772112243903436104509483190819343988300672009142812305068378720235800534191119843225949741796417107434937387267716981006150\r\n", "output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777\r\n"}, {"input": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774744777447\r\n", "output": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774747444444\r\n"}, {"input": "474777447477447774447777477444444747747747447474\r\n", "output": "474777447477447774447777477444444747747747447474\r\n"}, {"input": "35881905331681060827588553219538774024143083787975\r\n", "output": "44444444444444444444444447777777777777777777777777\r\n"}, {"input": "221020945402270233\r\n", "output": "444444444777777777\r\n"}, {"input": "241925018843248944336317949908388280315030601139576419352009710\r\n", "output": "4444444444444444444444444444444477777777777777777777777777777777"}, {"input": "888999577\r\n", "output": "4444477777"}, {"input": "10\r\n", "output": "47\r\n"}, {"input": "7\r\n", "output": "47"}, {"input": "50\r\n", "output": "74\r\n"}, {"input": "70\r\n", "output": "74\r\n"}, {"input": "74700\r\n", "output": "444777"}, {"input": "1024\r\n", "output": "4477\r\n"}, {"input": "73\r\n", "output": "74\r\n"}, {"input": "74710000\r\n", "output": "74744477\r\n"}, {"input": "444000000\r\n", "output": "4444477777"}, {"input": "4\r\n", "output": "47"}, {"input": "1\r\n", "output": "47"}, {"input": "9\r\n", "output": "47"}, {"input": "99\r\n", "output": "4477"}, {"input": "48\r\n", "output": "74\r\n"}, {"input": "4747474749\r\n", "output": "4747474774\r\n"}, {"input": "4747474774\r\n", "output": "4747474774\r\n"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "4777\r\n", "output": "7447\r\n"}, {"input": "7748\r\n", "output": "444777"}, {"input": "7773\r\n", "output": "444777"}, {"input": "19\r\n", "output": "47\r\n"}, {"input": "447777\r\n", "output": "474477\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))
exit(0)
else:
w = [c for c in num]
sc, fc = n // 2, n // 2
res = ''
for i in range(n):
if w[i] == '4' and fc == 0:
print(''.join(w[:i]) + '7' * sc)
exit(0)
if w[i] > '7' or w[i] > '4' and sc == 0:
for j in range(i - 1, -1, -1):
if w[j] == '4':
sc, fc = w[:j].count('7') + 1, w[:j].count('4')
print(''.join(w[:j]) + '7' + '4' * (n // 2 - fc) + '7' * (n // 2 - sc))
exit(0)
if w[i] < '4':
print(''.join(w[:i]) + '4' * fc + '7' * sc)
exit(0)
if w[i] != '4' and w[i] < '7' and sc > 0:
print(''.join(w[:i]) + '7' + '4' * fc + '7' * (sc - 1))
exit(0)
sc -= (w[i] == '7')
fc -= (w[i] == '4')
print(num)
| 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 result
for i in range(n):
add4 = False
if remaining[0]:
if digits[i] < '4':
add4 = True
elif digits[i] == '4':
lastIdx = i + remaining[1] # last index that can be replaced with 7
for j in range(i + 1, n):
d = '7' if j <= lastIdx else '4'
if digits[j] < d:
add4 = True
break
elif digits[j] > d:
add4 = False
break
elif j == n - 1:
add4 = True
if add4:
result[i] = '4'
remaining[0] -= 1
else:
result[i] = '7'
remaining[1] -= 1
if result[i] > digits[i] or remaining[1] == 0:
# append remaining 4s and 7s
for k in range(i + 1, i + 1 + remaining[0]):
result[k] = '4'
for k in range(i + 1 + remaining[0], i + 1 + remaining[0] + remaining[1]):
result[k] = '7'
break
return ''.join(result)
if __name__ == "__main__":
print(nextLuckyNumber(input()))
|
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. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
|
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", "output": "4444477777"}, {"input": "49102094540227023300\r\n", "output": "74444444444777777777\r\n"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "777777\r\n", "output": "44447777"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "474\r\n", "output": "4477"}, {"input": "85469\r\n", "output": "444777"}, {"input": "7474747\r\n", "output": "44447777"}, {"input": "2145226\r\n", "output": "44447777"}, {"input": "5556585\r\n", "output": "44447777"}, {"input": "87584777\r\n", "output": "4444477777"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "999999999\r\n", "output": "4444477777"}, {"input": "74477744\r\n", "output": "74477744\r\n"}, {"input": "444444444\r\n", "output": "4444477777"}, {"input": "467549754\r\n", "output": "4444477777"}, {"input": "147474747\r\n", "output": "4444477777"}, {"input": "555\r\n", "output": "4477"}, {"input": "100000\r\n", "output": "444777\r\n"}, {"input": "74777443\r\n", "output": "74777444\r\n"}, {"input": "4700007\r\n", "output": "44447777"}, {"input": "70070077\r\n", "output": "74444777\r\n"}, {"input": "123\r\n", "output": "4477"}, {"input": "7474\r\n", "output": "7474\r\n"}, {"input": "3696\r\n", "output": "4477\r\n"}, {"input": "5594108733309806863211189515406929423407691887690557101598403485\r\n", "output": "7444444444444444444444444444444447777777777777777777777777777777\r\n"}, {"input": "7004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224\r\n", "output": "7444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777\r\n"}, {"input": "795193728547733389463100378996233822835539327235483308682350676991954960294227364128385843182064933115\r\n", "output": "44444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777"}, {"input": "61136338618684683458627308377793588546921041456473994251912971721612136383004772112243903436104509483190819343988300672009142812305068378720235800534191119843225949741796417107434937387267716981006150\r\n", "output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777\r\n"}, {"input": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774744777447\r\n", "output": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774747444444\r\n"}, {"input": "474777447477447774447777477444444747747747447474\r\n", "output": "474777447477447774447777477444444747747747447474\r\n"}, {"input": "35881905331681060827588553219538774024143083787975\r\n", "output": "44444444444444444444444447777777777777777777777777\r\n"}, {"input": "221020945402270233\r\n", "output": "444444444777777777\r\n"}, {"input": "241925018843248944336317949908388280315030601139576419352009710\r\n", "output": "4444444444444444444444444444444477777777777777777777777777777777"}, {"input": "888999577\r\n", "output": "4444477777"}, {"input": "10\r\n", "output": "47\r\n"}, {"input": "7\r\n", "output": "47"}, {"input": "50\r\n", "output": "74\r\n"}, {"input": "70\r\n", "output": "74\r\n"}, {"input": "74700\r\n", "output": "444777"}, {"input": "1024\r\n", "output": "4477\r\n"}, {"input": "73\r\n", "output": "74\r\n"}, {"input": "74710000\r\n", "output": "74744477\r\n"}, {"input": "444000000\r\n", "output": "4444477777"}, {"input": "4\r\n", "output": "47"}, {"input": "1\r\n", "output": "47"}, {"input": "9\r\n", "output": "47"}, {"input": "99\r\n", "output": "4477"}, {"input": "48\r\n", "output": "74\r\n"}, {"input": "4747474749\r\n", "output": "4747474774\r\n"}, {"input": "4747474774\r\n", "output": "4747474774\r\n"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "4777\r\n", "output": "7447\r\n"}, {"input": "7748\r\n", "output": "444777"}, {"input": "7773\r\n", "output": "444777"}, {"input": "19\r\n", "output": "47\r\n"}, {"input": "447777\r\n", "output": "474477\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):
self.EL.append((v,c,0))
self.AL[u].append(len(self.EL)-1)
self.EL.append((u,0 if directed else c,0))
self.AL[v].append(len(self.EL)-1)
return
## Find shortest path from s-t
def bfs(self,s,t):
d = [-1 for i in range(self.N)]
d[s] = 0
q = deque([s])
self.p = [(-1,-1) for i in range(self.N)]
while q:
vertex = q.popleft()
for idx in self.AL[vertex]:
child,cap,flow = self.EL[idx]
if d[child] == -1 and cap-flow > 0:
q.append(child)
d[child] = d[vertex] + 1
self.p[child] = (vertex,idx)
return d[t] != -1
## Find pmc: path min capcity - bottleneck capacity in path
## Update flows along shortest s-t path with pmc
def send_one_flow(self,s,t,f = INF):
if s==t:
return f
u,idx = self.p[t]
v,cap,flow = self.EL[idx]
pmc = self.send_one_flow(s,u,min(f,cap-flow))
self.EL[idx] = (v,cap,flow+pmc)
self.EL[idx^1] = (u,cap,flow-pmc)
return pmc
## While path exists from s-t,
## send one flow & update residual graph (forward and back edges)
def edmond_karps(self,s,t):
maxflow = 0
while self.bfs(s,t):
maxflow += self.send_one_flow(s,t)
return maxflow
## Main
n = int(input())
boys = list(map(int,input().split()))
m = int(input())
girls = list(map(int,input().split()))
maxf = MaxFlow(n+m+3)
for i in range(n):
maxf.add_edge(1,i+2,1)
for j in range(m):
if i==0:
maxf.add_edge(n+j+2,n+m+2,1)
if abs(boys[i]-girls[j]) <= 1:
maxf.add_edge(i+2,n+j+2,1)
print(maxf.edmond_karps(1,n+m+2))
| 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 must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
|
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 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.
|
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"}, {"input": "4\r\n4 5 4 4\r\n5\r\n5 3 4 2 4\r\n", "output": "4\r\n"}, {"input": "1\r\n2\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n2\r\n3 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n3\r\n4 4 4\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n4\r\n3 1 4 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n5\r\n2 5 5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "2\r\n4 2\r\n2\r\n4 4\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n3\r\n2 3 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n4\r\n5 5 5 6\r\n", "output": "1\r\n"}, {"input": "2\r\n5 7\r\n5\r\n4 6 7 2 5\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "3\r\n5 4 5\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n6 3 4\r\n3\r\n4 5 2\r\n", "output": "3\r\n"}, {"input": "3\r\n7 7 7\r\n4\r\n2 7 2 4\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 3\r\n5\r\n1 3 4 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 3\r\n1\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n4 4 6 6\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "4\r\n3 1 1 1\r\n3\r\n1 6 7\r\n", "output": "1\r\n"}, {"input": "4\r\n2 5 1 2\r\n4\r\n2 3 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n9 1 7 1\r\n5\r\n9 9 9 8 4\r\n", "output": "2\r\n"}, {"input": "5\r\n1 6 5 5 6\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 4 5 6\r\n2\r\n7 4\r\n", "output": "2\r\n"}, {"input": "5\r\n4 1 3 1 4\r\n3\r\n6 3 6\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 3 1 4\r\n4\r\n1 3 1 7\r\n", "output": "3\r\n"}, {"input": "5\r\n9 8 10 9 10\r\n5\r\n2 1 5 4 6\r\n", "output": "0\r\n"}, {"input": "1\r\n48\r\n100\r\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6\r\n", "output": "1\r\n"}, {"input": "100\r\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\r\n1\r\n58\r\n", "output": "0\r\n"}, {"input": "10\r\n20 87 3 39 20 20 8 40 70 51\r\n100\r\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96\r\n", "output": "6\r\n"}, {"input": "100\r\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\r\n10\r\n66 74 40 67 28 82 99 57 93 64\r\n", "output": "9\r\n"}, {"input": "100\r\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\r\n100\r\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1\r\n", "output": "76\r\n"}, {"input": "4\r\n1 6 9 15\r\n2\r\n5 8\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 5\r\n3\r\n3 4 6\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 4\r\n3\r\n2 1 5\r\n", "output": "3\r\n"}, {"input": "2\r\n5 5\r\n4\r\n1 1 1 5\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "2\r\n3 1\r\n2\r\n2 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n10 12\r\n2\r\n11 9\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n3\r\n3 2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n1 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n4 5\r\n2\r\n5 3\r\n", "output": "2\r\n"}, {"input": "2\r\n7 5\r\n2\r\n6 8\r\n", "output": "2\r\n"}, {"input": "4\r\n4 3 2 1\r\n4\r\n1 2 3 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 3\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n3\r\n3 1 8\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 1\r\n3\r\n2 4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 3\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 3 3\r\n4\r\n2 2 1 1\r\n", "output": "4\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n2 4 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n5\r\n2 3 4 5 1\r\n", "output": "5\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n5 4\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 5 5\r\n4\r\n4 4 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n2 7 5\r\n3\r\n2 4 8\r\n", "output": "3\r\n"}, {"input": "100\r\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\r\n100\r\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5\r\n", "output": "100\r\n"}, {"input": "1\r\n3\r\n2\r\n2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n5 6\r\n3\r\n1 5 100\r\n", "output": "1\r\n"}, {"input": "2\r\n2 7\r\n2\r\n6 8\r\n", "output": "1\r\n"}, {"input": "4\r\n4 10 15 17\r\n4\r\n3 12 16 16\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n2\r\n1 2\r\n", "output": "2\r\n"}]
| 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] != name[len(name)-1-i]):
print("NO")
can = False
break
if(can):
print("YES")
| 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 name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
|
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": "YYHUIUGYI\r\n", "output": "NO\r\n"}, {"input": "TT\r\n", "output": "YES\r\n"}, {"input": "UUU\r\n", "output": "YES\r\n"}, {"input": "WYYW\r\n", "output": "YES\r\n"}, {"input": "MITIM\r\n", "output": "YES\r\n"}, {"input": "VO\r\n", "output": "NO\r\n"}, {"input": "WWS\r\n", "output": "NO\r\n"}, {"input": "VIYMAXXAVM\r\n", "output": "NO\r\n"}, {"input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM\r\n", "output": "NO\r\n"}, {"input": "CC\r\n", "output": "NO\r\n"}, {"input": "QOQ\r\n", "output": "NO\r\n"}, {"input": "AEEA\r\n", "output": "NO\r\n"}, {"input": "OQQQO\r\n", "output": "NO\r\n"}, {"input": "HNCMEEMCNH\r\n", "output": "NO\r\n"}, {"input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ\r\n", "output": "NO\r\n"}, {"input": "A\r\n", "output": "YES\r\n"}, {"input": "B\r\n", "output": "NO\r\n"}, {"input": "C\r\n", "output": "NO\r\n"}, {"input": "D\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}, {"input": "F\r\n", "output": "NO\r\n"}, {"input": "G\r\n", "output": "NO\r\n"}, {"input": "H\r\n", "output": "YES\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "J\r\n", "output": "NO\r\n"}, {"input": "K\r\n", "output": "NO\r\n"}, {"input": "L\r\n", "output": "NO\r\n"}, {"input": "M\r\n", "output": "YES\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "O\r\n", "output": "YES\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "Q\r\n", "output": "NO\r\n"}, {"input": "R\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "T\r\n", "output": "YES\r\n"}, {"input": "U\r\n", "output": "YES\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "W\r\n", "output": "YES\r\n"}, {"input": "X\r\n", "output": "YES\r\n"}, {"input": "Y\r\n", "output": "YES\r\n"}, {"input": "JL\r\n", "output": "NO\r\n"}, {"input": "AAAKTAAA\r\n", "output": "NO\r\n"}, {"input": "AKA\r\n", "output": "NO\r\n"}, {"input": "AAJAA\r\n", "output": "NO\r\n"}, {"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "AAAAAABAAAAAA\r\n", "output": "NO\r\n"}, {"input": "ZZ\r\n", "output": "NO\r\n"}, {"input": "ADA\r\n", "output": "NO\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "LAL\r\n", "output": "NO\r\n"}, {"input": "AABAA\r\n", "output": "NO\r\n"}, {"input": "AZA\r\n", "output": "NO\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "SSS\r\n", "output": "NO\r\n"}, {"input": "NNN\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "SS\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}]
| 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:
dl[i2] = i1
i2 += 1
i1 += 1
lmax = i2
if lmax == l2:
print(s2)
else:
i1 = l1 - 1
i2 = l2 - 1
while i1 >= 0 and i2 >= 0:
while i1 >= 0 and s1[i1] != s2[i2]:
i1 -= 1
if i1 >= 0:
dr[i2] = i1
i2 -= 1
i1 -= 1
rmax = i2
le = -1
re = -1
if l2 - lmax < rmax + 1:
rcnt = l2 - lmax
ls = 0
rs = lmax
else:
rcnt = rmax + 1
ls = rmax + 1
rs = l2
rr = rmax + 1
for ll in range(lmax):
while rr < l2 and (rr <= ll or dl[ll] >= dr[rr]):
rr += 1
dif = rr - l2 - 1
if dif < rcnt:
rcnt = dif
ls = 0
rs = ll + 1
le = rr
re = l2
result = s2[ls:rs]
if le != -1:
result += s2[le:re]
print(result if len(result) > 0 else '-')
| 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] != t[j]:
i -= 1
if i == -1:
break
suf[j] = i
i -= 1
max_len, best_l, best_r = 0, 0, 0
j = 1
for i in range(m+1):
j = max(j, i+1)
while j <= m and pre[i] >= suf[j]:
j += 1
if pre[i] == inf:
break
if max_len < i + m + 1 - j:
max_len = i + m + 1 - j
best_l, best_r = i, j
pre_s = t[1:best_l+1]
suf_s = t[best_r:]
print(pre_s + suf_s if max_len 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 the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
|
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\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk\r\n", "output": "ouypvk\r\n"}, {"input": "npnkmawey\r\nareakefvowledfriyjejqnnaeqheoh\r\n", "output": "a\r\n"}, {"input": "fdtffutxkujflswyddvhusfcook\r\nkavkhnhphcvckogqqqqhdmgwjdfenzizrebefsbuhzzwhzvc\r\n", "output": "kvc\r\n"}, {"input": "abacaba\r\naa\r\n", "output": "aa\r\n"}, {"input": "edbcd\r\nd\r\n", "output": "d\r\n"}, {"input": "abc\r\nksdksdsdsnabc\r\n", "output": "abc\r\n"}, {"input": "abxzxzxzzaba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abcd\r\nzzhabcd\r\n", "output": "abcd\r\n"}, {"input": "aa\r\naa\r\n", "output": "aa\r\n"}, {"input": "test\r\nt\r\n", "output": "t\r\n"}, {"input": "aa\r\na\r\n", "output": "a\r\n"}, {"input": "aaaabbbbaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "aa\r\nzzaa\r\n", "output": "aa\r\n"}, {"input": "zhbt\r\nztjihmhebkrztefpwty\r\n", "output": "zt\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaa\r\naaaaaaaa\r\n", "output": "aaaaaaaa\r\n"}, {"input": "abba\r\naba\r\n", "output": "aba\r\n"}, {"input": "abbba\r\naba\r\n", "output": "aba\r\n"}, {"input": "aaaaaaaaaaaa\r\naaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaa\r\n"}, {"input": "aaa\r\naa\r\n", "output": "aa\r\n"}, {"input": "aaaaaaaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "aaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "ashfaniosafapisfasipfaspfaspfaspfapsfjpasfshvcmvncxmvnxcvnmcxvnmxcnvmcvxvnxmcvxcmvh\r\nashish\r\n", "output": "ashish\r\n"}, {"input": "a\r\na\r\n", "output": "a\r\n"}, {"input": "aaaab\r\naab\r\n", "output": "aab\r\n"}, {"input": "aaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "a\r\naaa\r\n", "output": "a\r\n"}, {"input": "aaaaaabbbbbbaaaaaa\r\naba\r\n", "output": "aba\r\n"}, {"input": "def\r\nabcdef\r\n", "output": "def\r\n"}, {"input": "aaaaaaaaa\r\na\r\n", "output": "a\r\n"}, {"input": "bababsbs\r\nabs\r\n", "output": "abs\r\n"}, {"input": "hddddddack\r\nhackyz\r\n", "output": "hack\r\n"}, {"input": "aba\r\na\r\n", "output": "a\r\n"}, {"input": "ofih\r\nihfsdf\r\n", "output": "ih\r\n"}, {"input": "b\r\nabb\r\n", "output": "b\r\n"}, {"input": "lctsczqr\r\nqvkp\r\n", "output": "q\r\n"}, {"input": "dedcbaa\r\ndca\r\n", "output": "dca\r\n"}, {"input": "haddack\r\nhack\r\n", "output": "hack\r\n"}, {"input": "abcabc\r\nabc\r\n", "output": "abc\r\n"}, {"input": "asdf\r\ngasdf\r\n", "output": "asdf\r\n"}, {"input": "abab\r\nab\r\n", "output": "ab\r\n"}, {"input": "aaaaaaa\r\naaa\r\n", "output": "aaa\r\n"}, {"input": "asdf\r\nfasdf\r\n", "output": "asdf\r\n"}, {"input": "bbaabb\r\nab\r\n", "output": "ab\r\n"}, {"input": "accac\r\nbaacccbcccabaabbcacbbcccacbaabaaac\r\n", "output": "aac\r\n"}, {"input": "az\r\naaazazaa\r\n", "output": "a\r\n"}, {"input": "bbacaabbaaa\r\nacaabcaa\r\n", "output": "acaabaa\r\n"}, {"input": "c\r\ncbcbcbbacacacbccaaccbcabaaabbaaa\r\n", "output": "c\r\n"}, {"input": "bacb\r\nccacacbacbccbbccccaccccccbcbabbbaababa\r\n", "output": "ba\r\n"}, {"input": "ac\r\naacacaacbaaacbbbabacaca\r\n", "output": "a\r\n"}, {"input": "a\r\nzazaa\r\n", "output": "a\r\n"}, {"input": "abcd\r\nfaaaabbbbccccdddeda\r\n", "output": "a\r\n"}, {"input": "abcde\r\nfabcde\r\n", "output": "abcde\r\n"}, {"input": "a\r\nab\r\n", "output": "a\r\n"}, {"input": "ababbbbbbbbbbbb\r\nabbbbb\r\n", "output": "abbbbb\r\n"}, {"input": "bbbbaabbababbaaaaababbaaabbbbaaabbbababbbbabaabababaabaaabbbabababbbabababaababaaaaa\r\nbbabaaaabaaaabbaaabbbabaaabaabbbababbbbbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n", "output": "bbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\r\n"}, {"input": "ab\r\naba\r\n", "output": "ab\r\n"}, {"input": "aa\r\naaaa\r\n", "output": "aa\r\n"}, {"input": "aaaaabbbaaaaa\r\naabbaa\r\n", "output": "aabbaa\r\n"}, {"input": "aaaaaaaaa\r\naaaa\r\n", "output": "aaaa\r\n"}, {"input": "abbcc\r\naca\r\n", "output": "ac\r\n"}, {"input": "b\r\ncb\r\n", "output": "b\r\n"}, {"input": "aac\r\naaa\r\n", "output": "aa\r\n"}, {"input": "ba\r\nbb\r\n", "output": "b\r\n"}, {"input": "a\r\nb\r\n", "output": "-\r\n"}, {"input": "gkvubrvpbhsfiuyha\r\nihotmn\r\n", "output": "ih\r\n"}, {"input": "ccccabccbb\r\ncbbabcc\r\n", "output": "cabcc\r\n"}, {"input": "babababbaaabb\r\nabbab\r\n", "output": "abbab\r\n"}, {"input": "njtdhyqundyedsjyvy\r\nypjrs\r\n", "output": "ys\r\n"}, {"input": "uglyqhkpruxoakm\r\ncixxkpaaoodpuuh\r\n", "output": "uh\r\n"}, {"input": "a\r\naaaaaaaaa\r\n", "output": "a\r\n"}, {"input": "aaa\r\naaaaa\r\n", "output": "aaa\r\n"}, {"input": "abcabbcbcccbccbbcc\r\nacbcaabbbbcabbbaca\r\n", "output": "acbc\r\n"}, {"input": "caacacaacbaa\r\nacbbbabacacac\r\n", "output": "aacacac\r\n"}, {"input": "aa\r\naaab\r\n", "output": "aa\r\n"}, {"input": "acbc\r\ncacacbac\r\n", "output": "ac\r\n"}, {"input": "bacbcaacabbaacb\r\ncbbaaccccbcaacacaabb\r\n", "output": "cbcaabb\r\n"}, {"input": "baababaaaab\r\nbaababbbbbbb\r\n", "output": "baababb\r\n"}, {"input": "aaxyaba\r\naaba\r\n", "output": "aaba\r\n"}]
| 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:
if a[i][j + 1] == '*':
ans += 1
if i>1:
if a[i-1][j] == '*':
ans += 1
if i<n-1:
if a[i+1][j] == '*':
ans += 1
if i>1 and j>1:
if a[i-1][j - 1] == '*':
ans += 1
if i<n-1 and j>1:
if a[i+1][j - 1] == '*':
ans += 1
if i<n-1 and j<m-1:
if a[i+1][j + 1] == '*':
ans += 1
if i>1 and j<m-1:
if a[i-1][j + 1] == '*':
ans += 1
if str(ans)!=a[i][j]:
print('NO')
exit()
print('YES')
| 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:
if array[i+k][j] == '*':
c += 1
if i-k >= 0:
if array[i-k][j] == '*':
c += 1
if j + k < m:
if array[i][j+k] == "*":
c += 1
if j-k >= 0:
if array[i][j-k] == "*":
c += 1
if i + k < n and j + k < m:
if array[i+k][j+k] == "*":
c += 1
if i - k >= 0 and j - k >= 0:
if array[i-k][j-k] == "*":
c += 1
if i + k < n and j - k >= 0:
if array[i+k][j-k] == "*":
c += 1
if i - k >= 0 and j + k < m:
if array[i-k][j+k] == "*":
c += 1
if c != num:
flag = False
break
elif array[i][j] == '.':
num = 1
c = 0
k = 1
if i+k < n:
if array[i+k][j] == '*':
c += 1
if i-k >= 0:
if array[i-k][j] == '*':
c += 1
if j + k < m:
if array[i][j+k] == "*":
c += 1
if j-k >= 0:
if array[i][j-k] == "*":
c += 1
if i + k < n and j + k < m:
if array[i+k][j+k] == "*":
c += 1
if i - k >= 0 and j - k >= 0:
if array[i-k][j-k] == "*":
c += 1
if i + k < n and j - k >= 0:
if array[i+k][j-k] == "*":
c += 1
if i - k >= 0 and j + k < m:
if array[i-k][j+k] == "*":
c += 1
if c > 0:
flag = False
break
if not flag:
break
if flag:
print("YES")
else:
print("NO")
|
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 difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $$$n \times m$$$, where each cell is either empty, or contains a digit from $$$1$$$ to $$$8$$$, or a bomb. The field is valid if for each cell:
- if there is a digit $$$k$$$ in the cell, then exactly $$$k$$$ neighboring cells have bombs.
- if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $$$8$$$ neighboring cells).
|
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 $$$8$$$, inclusive.
|
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*31..11\r\n..111..111\r\n.......1*1\r\n.......111\r\n", "output": "YES"}, {"input": "10 17\r\n12*2*22123*31....\r\n2*333*3*4***3211.\r\n*22*213**4***3*1.\r\n11111.12224*6*21.\r\n221..111.14**4311\r\n**2233*212****2*1\r\n*55***4*13*544421\r\n2***54*322*21**31\r\n13*4*33*221114*4*\r\n.1122*22*1...2*31\r\n", "output": "YES"}, {"input": "10 10\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n******3***\r\n**********\r\n**********\r\n**********\r\n***3.5****\r\n", "output": "NO"}, {"input": "21 10\r\n62637783*1\r\n23*51**531\r\n35*7*6.**.\r\n.*3***581*\r\n2.32*745**\r\n83*7*6*6*5\r\n*74.**6**3\r\n323*6**7*6\r\n3454*67.*1\r\n**63265*6*\r\n3725*4553*\r\n24****5**4\r\n23.34****4\r\n55257*1*4*\r\n4*3253*456\r\n**.3*45488\r\n*7318**4*5\r\n234.*4557*\r\n12..21*.*3\r\n286.225*4*\r\n834*11*.3*\r\n", "output": "NO"}, {"input": "10 10\r\n**********\r\n*********6\r\n*********5\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n", "output": "NO"}, {"input": "100 1\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n1\r\n1\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n*\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n", "output": "YES"}, {"input": "1 100\r\n*************5****5****************************************************4****************************\r\n", "output": "NO"}, {"input": "1 100\r\n..1*1..........................1*1....1*1....1*1.1*1....1*1..1**1........................1**1.......\r\n", "output": "YES"}, {"input": "1 100\r\n.....1*1........1*1................................1*1...1**11*1.......1*1....1.....1*1.....1*1...1*\r\n", "output": "NO"}, {"input": "1 10\r\n881111882*\r\n", "output": "NO"}, {"input": "5 5\r\n*2221\r\n24**2\r\n*3*5*\r\n3425*\r\n**12*\r\n", "output": "NO"}, {"input": "5 5\r\n****2\r\n4***4\r\n3****\r\n3*563\r\n*22**\r\n", "output": "NO"}, {"input": "5 5\r\n***2.\r\n5**31\r\n**6**\r\n***43\r\n**31*\r\n", "output": "NO"}, {"input": "5 5\r\n*32**\r\n4*3*4\r\n**44*\r\n**45*\r\n*4***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n*2*\r\n***\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "1 2\r\n*1\r\n", "output": "YES"}, {"input": "1 2\r\n*2\r\n", "output": "NO"}, {"input": "2 2\r\n32\r\n**\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n232\r\n***\r\n", "output": "YES"}, {"input": "3 2\r\n..\r\n11\r\n.*\r\n", "output": "NO"}, {"input": "2 3\r\n1*2\r\n3*2\r\n", "output": "NO"}, {"input": "1 3\r\n.*.\r\n", "output": "NO"}, {"input": "3 1\r\n.\r\n*\r\n.\r\n", "output": "NO"}, {"input": "3 1\r\n1\r\n*\r\n1\r\n", "output": "YES"}, {"input": "3 1\r\n*\r\n1\r\n*\r\n", "output": "NO"}, {"input": "1 3\r\n1**\r\n", "output": "YES"}, {"input": "1 1\r\n8\r\n", "output": "NO"}, {"input": "1 1\r\n.\r\n", "output": "YES"}, {"input": "1 2\r\n2*\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n2\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n*\r\n", "output": "YES"}, {"input": "2 1\r\n.\r\n1\r\n", "output": "NO"}, {"input": "1 3\r\n..1\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n.*.\r\n...\r\n", "output": "NO"}, {"input": "3 3\r\n112\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n11.\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n151\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n1.1\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n611\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n.11\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n2*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n**1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n5*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n.*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n411\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n.11\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n121\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n1.1\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n115\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n11.\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*4\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*.\r\n111\r\n", "output": "NO"}, {"input": "1 4\r\n*222\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "2 2\r\n**\r\n**\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*.*\r\n***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n***\r\n***\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*4*\r\n***\r\n", "output": "NO"}, {"input": "2 6\r\n....1.\r\n.....*\r\n", "output": "NO"}, {"input": "5 5\r\n*****\r\n*****\r\n*****\r\n*****\r\n*****\r\n", "output": "YES"}, {"input": "4 1\r\n.\r\n*\r\n.\r\n.\r\n", "output": "NO"}, {"input": "2 2\r\n2*\r\n11\r\n", "output": "NO"}, {"input": "3 3\r\n888\r\n888\r\n888\r\n", "output": "NO"}, {"input": "1 4\r\n*22*\r\n", "output": "NO"}]
| 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(1,n-1,1):
if parsa[i]+a==parsa[0] or parsa[i]-a==parsa[0] or parsa[i]==parsa[0]:
p=1
else:
p=0
break
if p==0:
print('NO')
else:
print('YES')
| 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 from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
|
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": "4\r\n1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n4 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 1 4 7\r\n", "output": "YES\r\n"}, {"input": "3\r\n99999999 1 50000000\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 2 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 5 11\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 7\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 4 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n100000001 100000003\r\n", "output": "YES\r\n"}, {"input": "3\r\n7 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 5\r\n", "output": "NO\r\n"}, {"input": "2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 100 29\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 6\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 5 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n5 4 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 6 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 5 10\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 7 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 1 1 1 1 2 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 4 4 6\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 2 4 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 9 10\r\n", "output": "NO\r\n"}, {"input": "8\r\n1 1 1 1 1 1 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 100\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 15 14\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 10\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n3 6 7 8 9\r\n", "output": "NO\r\n"}, {"input": "3\r\n7 6 8\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "3\r\n4 6 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n10 20 21 30\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 2 3 4\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 6 12\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0 1 3 5\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 5 8\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 4 4\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 4 5 6\r\n", "output": "NO\r\n"}]
| 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]:
dfex.pop(0)
if (len(t) == 0 or len(dfex) == 0):
break
if t[0]< dfex[0]:
t.pop(0)
if (len(t) == 0 or len(dfex) == 0):
break
else:
dfex.pop(0)
t.pop(0)
count+=1
print(count)
| 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 <= 1:
heapq.heappop(boys)
heapq.heappop(girls)
ans += 1
elif -1* boys[0] > -1* girls[0]:
heapq.heappop(boys)
else:
heapq.heappop(girls)
print(ans)
|
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 must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
|
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 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.
|
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"}, {"input": "4\r\n4 5 4 4\r\n5\r\n5 3 4 2 4\r\n", "output": "4\r\n"}, {"input": "1\r\n2\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n2\r\n3 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n3\r\n4 4 4\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n4\r\n3 1 4 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n5\r\n2 5 5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "2\r\n4 2\r\n2\r\n4 4\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n3\r\n2 3 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n4\r\n5 5 5 6\r\n", "output": "1\r\n"}, {"input": "2\r\n5 7\r\n5\r\n4 6 7 2 5\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "3\r\n5 4 5\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n6 3 4\r\n3\r\n4 5 2\r\n", "output": "3\r\n"}, {"input": "3\r\n7 7 7\r\n4\r\n2 7 2 4\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 3\r\n5\r\n1 3 4 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 3\r\n1\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n4 4 6 6\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "4\r\n3 1 1 1\r\n3\r\n1 6 7\r\n", "output": "1\r\n"}, {"input": "4\r\n2 5 1 2\r\n4\r\n2 3 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n9 1 7 1\r\n5\r\n9 9 9 8 4\r\n", "output": "2\r\n"}, {"input": "5\r\n1 6 5 5 6\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 4 5 6\r\n2\r\n7 4\r\n", "output": "2\r\n"}, {"input": "5\r\n4 1 3 1 4\r\n3\r\n6 3 6\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 3 1 4\r\n4\r\n1 3 1 7\r\n", "output": "3\r\n"}, {"input": "5\r\n9 8 10 9 10\r\n5\r\n2 1 5 4 6\r\n", "output": "0\r\n"}, {"input": "1\r\n48\r\n100\r\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6\r\n", "output": "1\r\n"}, {"input": "100\r\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\r\n1\r\n58\r\n", "output": "0\r\n"}, {"input": "10\r\n20 87 3 39 20 20 8 40 70 51\r\n100\r\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96\r\n", "output": "6\r\n"}, {"input": "100\r\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\r\n10\r\n66 74 40 67 28 82 99 57 93 64\r\n", "output": "9\r\n"}, {"input": "100\r\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\r\n100\r\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1\r\n", "output": "76\r\n"}, {"input": "4\r\n1 6 9 15\r\n2\r\n5 8\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 5\r\n3\r\n3 4 6\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 4\r\n3\r\n2 1 5\r\n", "output": "3\r\n"}, {"input": "2\r\n5 5\r\n4\r\n1 1 1 5\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "2\r\n3 1\r\n2\r\n2 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n10 12\r\n2\r\n11 9\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n3\r\n3 2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n1 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n4 5\r\n2\r\n5 3\r\n", "output": "2\r\n"}, {"input": "2\r\n7 5\r\n2\r\n6 8\r\n", "output": "2\r\n"}, {"input": "4\r\n4 3 2 1\r\n4\r\n1 2 3 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 3\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n3\r\n3 1 8\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 1\r\n3\r\n2 4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 3\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 3 3\r\n4\r\n2 2 1 1\r\n", "output": "4\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n2 4 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n5\r\n2 3 4 5 1\r\n", "output": "5\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n5 4\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 5 5\r\n4\r\n4 4 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n2 7 5\r\n3\r\n2 4 8\r\n", "output": "3\r\n"}, {"input": "100\r\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\r\n100\r\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5\r\n", "output": "100\r\n"}, {"input": "1\r\n3\r\n2\r\n2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n5 6\r\n3\r\n1 5 100\r\n", "output": "1\r\n"}, {"input": "2\r\n2 7\r\n2\r\n6 8\r\n", "output": "1\r\n"}, {"input": "4\r\n4 10 15 17\r\n4\r\n3 12 16 16\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n2\r\n1 2\r\n", "output": "2\r\n"}]
| 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] == ".":
if i > 0 and i < n-1 and s[i+1][0] == "*" or\
i > 0 and i < n-1 and s[i-1][0] == "*":
print("NO")
exit()
if i == 0 and s[i+1][0] == "*":
print("NO")
exit()
if i == n-1 and s[i-1][0] == "*":
print("NO")
exit()
if s[i][0] == "2":
if i == 0 or i == n-1:
print("NO")
exit()
if i > 0 and i < n-1 and s[i-1][0] != "*" and s[i+1][0] != "*" or\
i > 0 and i < n-1 and s[i-1][0] != "*" and s[i+1][0] == "*" or\
i > 0 and i < n-1 and s[i-1][0] == "*" and s[i+1][0] != "*":
# print(i)
print("NO")
exit()
if s[i][0] == "1":
if i == 0 and s[i+1][0] != "*":
print("NO")
exit()
if i == n-1 and s[i-1][0] != "*":
print("NO")
exit()
if i > 0 and i < n-1 and s[i+1][0] != "*" and s[i-1][0] != "*" or\
i > 0 and i < n-1 and s[i+1][0] == "*" and s[i-1][0] == "*":
print("NO")
exit()
if "2" < s[i][0] <= "9":
print("NO")
exit()
if n == 1:
for i in range(m):
if s[0][i] == ".":
if i < n-1 and s[0][i+1] == "*" or\
i > 0 and s[0][i-1] == "*":
print("NO")
exit()
if i == 0 and s[0][i+1] == "*":
print("NO")
exit()
if i == m-1 and s[0][i-1] == "*":
print("NO")
exit()
if s[0][i] == "2":
if i == 0 or i == m-1:
print("NO")
exit()
if i > 0 and i < m-1 and s[0][i-1] == "*" and s[0][i+1] == "*":
print("NO")
exit()
if s[0][1] == "1":
if i == 0 and s[0][i+1] == "*":
print("NO")
exit()
if i == m-1 and s[0][i-1] == "*":
print("NO")
exit()
if i > 0 and i < m-1 and s[0][i+1] == "*" and s[0][i-1] != "*" or\
i > 0 and i < m-1 and s[0][i+1] != "*" and s[0][i-1] == "*":
print("NO")
exit()
if "2" < s[0][i] <= "9":
print("NO")
exit()
if m > 1 and n > 1:
for i in range(n):
for j in range(m):
if "1" <= s[i][j] <= "9":
count = 0
if i == 0 and j == 0:
if s[i][j+1] == "*":
count = count + 1
if s[i+1][j] == "*":
count = count + 1
if s[i+1][j+1] == "*":
count = count + 1
if i == 0 and j == m-1:
if s[i][j-1] == "*":
count = count + 1
if s[i+1][j] == "*":
count = count + 1
if s[i+1][j-1] == "*":
count = count + 1
if i == n-1 and j == 0:
if s[i-1][j] == "*":
count = count + 1
if s[i][j+1] == "*":
count = count + 1
if s[i-1][j+1] == "*":
count = count + 1
if i == n-1 and j == m-1:
if s[i-1][j] == "*":
count = count + 1
if s[i][j-1] == "*":
count = count + 1
if s[i-1][j-1] == "*":
count = count + 1
if i == 0 and j > 0 and j < m-1:
if s[i+1][j] == "*":
count = count + 1
if s[i][j-1] == "*":
count = count + 1
if s[i][j+1] == "*":
count = count + 1
if s[i+1][j-1] == "*":
count = count + 1
if s[i+1][j+1] == "*":
count = count + 1
if i == n-1 and j > 0 and j < m-1:
if s[i][j-1] == "*":
count = count + 1
if s[i][j+1] == "*":
count = count + 1
if s[i-1][j-1] == "*":
count = count + 1
if s[i-1][j+1] == "*":
count = count + 1
if s[i-1][j] == "*":
count = count + 1
if j == 0 and i > 0 and i < n-1:
if s[i-1][j] == "*":
count = count + 1
if s[i+1][j] == "*":
count = count + 1
if s[i][j+1] == "*":
count = count + 1
if s[i-1][j+1] == "*":
count = count + 1
if s[i+1][j+1] == "*":
count = count + 1
if j == m-1 and i > 0 and i < n-1:
if s[i-1][j] == "*":
count = count + 1
if s[i+1][j] == "*":
count = count + 1
if s[i][j-1] == "*":
count = count + 1
if s[i-1][j-1] == "*":
count = count + 1
if s[i+1][j-1] == "*":
count = count + 1
if i > 0 and i < n-1 and j > 0 and j < m-1:
if s[i-1][j] == "*":
count = count + 1
if s[i+1][j] == "*":
count = count + 1
if s[i][j+1] == "*":
count = count + 1
if s[i][j-1] == "*":
count = count + 1
if s[i-1][j-1] == "*":
count = count + 1
if s[i-1][j+1] == "*":
count = count + 1
if s[i+1][j-1] == "*":
count = count + 1
if s[i+1][j+1] == "*":
count = count + 1
if count != int(s[i][j]):
print("NO")
exit()
if s[i][j] == ".":
if i == 0 and j == 0:
if s[i+1][j] == "*" or s[i][j+1] == "*" or\
s[i+1][j+1] == "*":
print("NO")
exit()
if i == 0 and j == m-1:
if s[i+1][j] == "*" or s[i][j-1] == "*" or s[i+1][j-1] == "*":
print("NO")
exit()
if i == n-1 and j == 0:
if s[i-1][j] == "*" or s[i][j+1] == "*" or s[i-1][j+1] == "*":
print("NO")
exit()
if i == n-1 and j == m-1:
if s[i-1][j] == "*" or s[i][j-1] == "*" or s[i-1][j-1] == "*":
print("NO")
exit()
if i == 0 and j > 0 and j < m-1:
if s[i][j+1] == "*" or s[i][j-1] == "*" or\
s[i+1][j] == "*" or s[i+1][j-1] == "*" or s[i+1][j+1] == "*":
print("NO")
exit()
if i == n-1 and j > 0 and j < m-1:
if s[i][j-1] == "*" or s[i][j+1] == "*" or\
s[i-1][j] == "*" or s[i-1][j-1] == "*" or\
s[i-1][j+1] == "*":
print("NO")
exit()
if j == 0 and i > 0 and i < n-1:
if s[i-1][j] == "*" or s[i+1][j] == "*" or\
s[i][j+1] == "*" or s[i-1][j+1] == "*" or\
s[i+1][j+1] == "*":
print("NO")
exit()
if j == m-1 and i > 0 and i < n-1:
if s[i-1][j] == "*" or s[i+1][j] == "*" or\
s[i][j-1] == "*" or s[i-1][j-1] == "*" or\
s[i+1][j-1] == "*":
print("NO")
exit()
if i > 0 and i < n-1 and j > 0 and j < m-1:
if s[i][j-1] == "*" or s[i][j+1] == "*" or s[i-1][j] == "*"\
or s[i+1][j] == "*" or s[i-1][j-1] == "*" or s[i-1][j+1] == "*"\
or s[i+1][j-1] == "*" or s[i+1][j+1] == "*":
print("NO")
exit()
print("YES")
| 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] = '0'
if s[i][j].isdigit():
if [s[i][j-1], s[i][j+1], s[i-1][j], s[i+1][j], s[i+1][j+1], s[i-1][j-1],
s[i+1][j-1], s[i-1][j+1]].count('*') != int(s[i][j]):
valid = False
break
if not valid:
break
print("YES" if valid else "NO")
|
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 difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $$$n \times m$$$, where each cell is either empty, or contains a digit from $$$1$$$ to $$$8$$$, or a bomb. The field is valid if for each cell:
- if there is a digit $$$k$$$ in the cell, then exactly $$$k$$$ neighboring cells have bombs.
- if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $$$8$$$ neighboring cells).
|
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 $$$8$$$, inclusive.
|
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*31..11\r\n..111..111\r\n.......1*1\r\n.......111\r\n", "output": "YES"}, {"input": "10 17\r\n12*2*22123*31....\r\n2*333*3*4***3211.\r\n*22*213**4***3*1.\r\n11111.12224*6*21.\r\n221..111.14**4311\r\n**2233*212****2*1\r\n*55***4*13*544421\r\n2***54*322*21**31\r\n13*4*33*221114*4*\r\n.1122*22*1...2*31\r\n", "output": "YES"}, {"input": "10 10\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n******3***\r\n**********\r\n**********\r\n**********\r\n***3.5****\r\n", "output": "NO"}, {"input": "21 10\r\n62637783*1\r\n23*51**531\r\n35*7*6.**.\r\n.*3***581*\r\n2.32*745**\r\n83*7*6*6*5\r\n*74.**6**3\r\n323*6**7*6\r\n3454*67.*1\r\n**63265*6*\r\n3725*4553*\r\n24****5**4\r\n23.34****4\r\n55257*1*4*\r\n4*3253*456\r\n**.3*45488\r\n*7318**4*5\r\n234.*4557*\r\n12..21*.*3\r\n286.225*4*\r\n834*11*.3*\r\n", "output": "NO"}, {"input": "10 10\r\n**********\r\n*********6\r\n*********5\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n", "output": "NO"}, {"input": "100 1\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n1\r\n1\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n*\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n", "output": "YES"}, {"input": "1 100\r\n*************5****5****************************************************4****************************\r\n", "output": "NO"}, {"input": "1 100\r\n..1*1..........................1*1....1*1....1*1.1*1....1*1..1**1........................1**1.......\r\n", "output": "YES"}, {"input": "1 100\r\n.....1*1........1*1................................1*1...1**11*1.......1*1....1.....1*1.....1*1...1*\r\n", "output": "NO"}, {"input": "1 10\r\n881111882*\r\n", "output": "NO"}, {"input": "5 5\r\n*2221\r\n24**2\r\n*3*5*\r\n3425*\r\n**12*\r\n", "output": "NO"}, {"input": "5 5\r\n****2\r\n4***4\r\n3****\r\n3*563\r\n*22**\r\n", "output": "NO"}, {"input": "5 5\r\n***2.\r\n5**31\r\n**6**\r\n***43\r\n**31*\r\n", "output": "NO"}, {"input": "5 5\r\n*32**\r\n4*3*4\r\n**44*\r\n**45*\r\n*4***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n*2*\r\n***\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "1 2\r\n*1\r\n", "output": "YES"}, {"input": "1 2\r\n*2\r\n", "output": "NO"}, {"input": "2 2\r\n32\r\n**\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n232\r\n***\r\n", "output": "YES"}, {"input": "3 2\r\n..\r\n11\r\n.*\r\n", "output": "NO"}, {"input": "2 3\r\n1*2\r\n3*2\r\n", "output": "NO"}, {"input": "1 3\r\n.*.\r\n", "output": "NO"}, {"input": "3 1\r\n.\r\n*\r\n.\r\n", "output": "NO"}, {"input": "3 1\r\n1\r\n*\r\n1\r\n", "output": "YES"}, {"input": "3 1\r\n*\r\n1\r\n*\r\n", "output": "NO"}, {"input": "1 3\r\n1**\r\n", "output": "YES"}, {"input": "1 1\r\n8\r\n", "output": "NO"}, {"input": "1 1\r\n.\r\n", "output": "YES"}, {"input": "1 2\r\n2*\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n2\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n*\r\n", "output": "YES"}, {"input": "2 1\r\n.\r\n1\r\n", "output": "NO"}, {"input": "1 3\r\n..1\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n.*.\r\n...\r\n", "output": "NO"}, {"input": "3 3\r\n112\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n11.\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n151\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n1.1\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n611\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n.11\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n2*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n**1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n5*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n.*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n411\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n.11\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n121\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n1.1\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n115\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n11.\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*4\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*.\r\n111\r\n", "output": "NO"}, {"input": "1 4\r\n*222\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "2 2\r\n**\r\n**\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*.*\r\n***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n***\r\n***\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*4*\r\n***\r\n", "output": "NO"}, {"input": "2 6\r\n....1.\r\n.....*\r\n", "output": "NO"}, {"input": "5 5\r\n*****\r\n*****\r\n*****\r\n*****\r\n*****\r\n", "output": "YES"}, {"input": "4 1\r\n.\r\n*\r\n.\r\n.\r\n", "output": "NO"}, {"input": "2 2\r\n2*\r\n11\r\n", "output": "NO"}, {"input": "3 3\r\n888\r\n888\r\n888\r\n", "output": "NO"}, {"input": "1 4\r\n*22*\r\n", "output": "NO"}]
| 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
for i in str(u):
cnt[int(i)] -= 1
for i in b:
cnt[i] -= 1
if not max(cnt[1:]):
ans = "".join(map(str, b)) + "0" * cnt[0]
elif not b[0]:
ans = []
for i in range(1, 10):
if cnt[i]:
ans.append(i)
cnt[i] -= 1
break
for _ in range(cnt[0]):
ans.append(0)
for i in b:
ans.append(i)
for i in range(1, 10):
for _ in range(cnt[i]):
ans.append(i)
ans = "".join(map(str, ans))
else:
x = list(b)
for i in range(10):
for _ in range(cnt[i]):
x.append(i)
y, z = [], []
for i in range(1, 10):
if b[0] ^ i:
if cnt[0] and cnt[i]:
y.append(i)
z.append(i)
cnt[i] -= 1
for _ in range(cnt[0]):
y.append(0)
z.append(0)
cnt[0] = 0
for _ in range(cnt[i]):
y.append(i)
z.append(i)
elif not cnt[i]:
for j in b:
y.append(j)
z.append(j)
else:
c = [i]
cnt[i] -= 1
for _ in range(cnt[0]):
c.append(0)
cnt[0] = 0
for _ in range(cnt[i]):
c.append(i)
for j in b + c:
y.append(j)
for j in c + b:
z.append(j)
ans = min("".join(map(str, x)), "".join(map(str, y)), "".join(map(str, z)))
print(ans)
| 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, s):
cnt[j] -= 1
res = [''.join([s1] + [chr(i) * a for i, a in enumerate(cnt) if a])] if s1[0] > '0' else []
for i in range(49, 58):
if cnt[i]:
cnt[i] -= 1
l = [chr(i) * a for i, a in enumerate(cnt) if a]
l.append(s1)
res.append(''.join([chr(i)] + sorted(l)))
break
print(min(res))
if __name__ == '__main__':
main()
|
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 substring of n (a substring of n is a sequence of consecutive digits of the number n).
Vasya knows that there may be more than one way to restore the number n. Your task is to find the smallest possible initial integer n. Note that decimal representation of number n contained no leading zeroes, except the case the integer n was equal to zero itself (in this case a single digit 0 was used).
|
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\r\n", "output": "100009213544\r\n"}, {"input": "11317110\r\n01\r\n", "output": "1011113\r\n"}, {"input": "1516532320120301262110112013012410838210025280432402042406224604110031740090203024020012\r\n0126064\r\n", "output": "10000000000000000000000012606411111111111111222222222222222222333333334444444455567889\r\n"}, {"input": "233121122272652143504001162131110307236110231414093112213120271312010423132181004\r\n0344011\r\n", "output": "1000000000003440111111111111111111111112222222222222222233333333333444455666778\r\n"}, {"input": "1626112553124100114021300410533124010061200562040601301\r\n00612141\r\n", "output": "10000000000000006121411111111111222222333344445556666\r\n"}, {"input": "040005088\r\n0\r\n", "output": "40000058\r\n"}, {"input": "420002200110100211206222101201021321440210\r\n00\r\n", "output": "1000000000000011111111112222222222223446\r\n"}, {"input": "801095116\r\n0\r\n", "output": "10011569\r\n"}, {"input": "070421120216020020\r\n000024\r\n", "output": "1000000024122227\r\n"}, {"input": "825083\r\n0\r\n", "output": "20388\r\n"}, {"input": "6201067\r\n0\r\n", "output": "100267\r\n"}, {"input": "34404430311310306128103301112523111011050561125004200941114005444000000040133002103062151514033103\r\n010215110013511400400140133404\r\n", "output": "100000000000000000000102151100135114004001401334041111111111111122222233333333333444444455555668\r\n"}, {"input": "14\r\n4\r\n", "output": "4\r\n"}, {"input": "21\r\n2\r\n", "output": "2\r\n"}, {"input": "204\r\n4\r\n", "output": "40\r\n"}, {"input": "12\r\n2\r\n", "output": "2\r\n"}, {"input": "05740110115001520111222011422101032503200010203300510014413\r\n000151\r\n", "output": "100000000000000000001511111111111111222222222333334444555\r\n"}, {"input": "116051111111001510011110101111111101001111111101111101101\r\n00111111111\r\n", "output": "1000000000000011111111111111111111111111111111111111116\r\n"}, {"input": "1161100\r\n01110\r\n", "output": "101110\r\n"}, {"input": "101313020013110703821620035452130200177115540090000\r\n002001320\r\n", "output": "1000000000000002001320111111111222333334555567778\r\n"}, {"input": "03111100110111111118\r\n01001111111101111\r\n", "output": "301001111111101111\r\n"}, {"input": "01170141\r\n01114\r\n", "output": "1001114\r\n"}, {"input": "0500014440100110264222000342611000102247070652310723\r\n0003217\r\n", "output": "10000000000000000032171111112222222233444444566677\r\n"}, {"input": "111011111101111131113111111111011\r\n0111111111111111010111111111\r\n", "output": "1011111111111111101011111111113\r\n"}, {"input": "11003040044200003323519101102070252000010622902208104150200400140042011224011154237302003323632011235\r\n0\r\n", "output": "100000000000000000000000000000000001111111111111111222222222222222222333333333334444444445555566778\r\n"}, {"input": "111111011110101141110110011010011114110111\r\n01010111111011111\r\n", "output": "1000000101011111101111111111111111111114\r\n"}, {"input": "011010171110\r\n010110117\r\n", "output": "1010110117\r\n"}, {"input": "510017\r\n0\r\n", "output": "10017\r\n"}, {"input": "00111111110114112110011105\r\n0\r\n", "output": "100000011111111111111115\r\n"}, {"input": "320403902031031110003113410860101243100423120201101124080311242010930103200001451200132304400000\r\n01\r\n", "output": "1000000000000000000000000000000000011111111111111111111122222222222233333333333334444444456889\r\n"}, {"input": "125\r\n15\r\n", "output": "15\r\n"}, {"input": "1160190\r\n110019\r\n", "output": "110019\r\n"}, {"input": "11111111111101101111110101011111010101001111001110010011810010110111101101112140110110\r\n110101100101111101011111111101111111111110111110011111011000111010100111011111000002\r\n", "output": "110101100101111101011111111101111111111110111110011111011000111010100111011111000002\r\n"}, {"input": "2206026141112316065224201412118064151200614042100160093001020024005013121010030020083221011\r\n280060226\r\n", "output": "10000000000000000000000000111111111111111111111222222222222228006022633333444444455566666\r\n"}, {"input": "63007511113226210230771304213600010311075400082011350143450007091200\r\n25\r\n", "output": "100000000000000000000011111111111112222222533333333444455567777789\r\n"}, {"input": "142245201505011321217122212\r\n12521721230\r\n", "output": "1001111125217212302222445\r\n"}, {"input": "712\r\n17\r\n", "output": "17\r\n"}, {"input": "11011111111003010101111111111103111\r\n101111111110110111111011001011111\r\n", "output": "101111111110110111111011001011111\r\n"}, {"input": "143213104201201003340424615500135122127119000020020017400111102423312241032010400\r\n235321200411204201121201304100003\r\n", "output": "1000000000000001111111111222222223532120041120420112120130410000333334444445567\r\n"}, {"input": "080001181\r\n18\r\n", "output": "10000118\r\n"}, {"input": "4141403055010511470013300502174230460332129228041229160601006121052601201100001153120100000\r\n49\r\n", "output": "10000000000000000000000000000011111111111111111112222222222223333333444444495555556666677\r\n"}, {"input": "2131\r\n112\r\n", "output": "112\r\n"}, {"input": "0111110011011110111012109101101111101111150011110111110111001\r\n10110010111111011111111011001101001111111111111110001011012\r\n", "output": "10110010111111011111111011001101001111111111111110001011012\r\n"}, {"input": "251137317010111402300506643001203241303324162124225270011006213015100\r\n3512\r\n", "output": "1000000000000000001111111111111122222222223333333335124444455566677\r\n"}, {"input": "12140051050330004342310455231200020252193200\r\n23012\r\n", "output": "100000000000001111222222301233333444555559\r\n"}, {"input": "291\r\n19\r\n", "output": "19\r\n"}, {"input": "11011011000111101111111111081101110001011111101111110111111111011111011011111100111\r\n1110111111111\r\n", "output": "100000000000000000011101111111111111111111111111111111111111111111111111111111111\r\n"}, {"input": "170422032160671323013220212523333410720410110020005012206133500200001015971250190240204004002041\r\n10010405153200037262043200214001340010615320\r\n", "output": "1000000000000000100104051532000372620432002140013400106153201111111122222222222233333445567779\r\n"}, {"input": "210042022032002310001424611003103312001401111120015141083050404330261401411234412400319100212120\r\n10014121114054\r\n", "output": "1000000000000000000000000010014121114054111111111111111111222222222222223333333333444444445668\r\n"}, {"input": "222122228\r\n2221\r\n", "output": "22212222\r\n"}, {"input": "10\r\n0\r\n", "output": "0\r\n"}, {"input": "11007000\r\n1000\r\n", "output": "1000001\r\n"}, {"input": "3323\r\n32\r\n", "output": "323\r\n"}, {"input": "1001016\r\n1001\r\n", "output": "100101\r\n"}, {"input": "50104\r\n10\r\n", "output": "1005\r\n"}, {"input": "2023\r\n20\r\n", "output": "202\r\n"}, {"input": "0001116\r\n1001\r\n", "output": "100101\r\n"}, {"input": "32334\r\n32\r\n", "output": "3233\r\n"}, {"input": "1103\r\n10\r\n", "output": "101\r\n"}, {"input": "023335\r\n23\r\n", "output": "23033\r\n"}, {"input": "111111111110\r\n1\r\n", "output": "1111111111\r\n"}, {"input": "501105\r\n110\r\n", "output": "11005\r\n"}, {"input": "1110006\r\n1001\r\n", "output": "100101\r\n"}]
| 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][j],l1[k1][i]
for k1 in range(n):
c1=0
for k2 in range(m):
if(l1[k1][k2]!=k2+1):
c1+=1
if(c1>2):
flag1=1
break
if(flag1==0):
return 1
return -1
n,m=map(int,input().split())
l=[]
for i in range(n):
l.append(list(map(int,input().split())))
flag=0
for i in range(n):
c1=0
for j in range(m):
if(l[i][j]!=j+1):
c1+=1
if(c1>4):
flag=2
if(c1>2):
flag+=1
break
#print(flag)
if(flag==0):
print("YES")
elif(flag==1):
t=cal(l,n,m)
# print(t)
if(t==1):
print("YES")
else:
print("NO")
else:
print("NO")
| 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 k > 2:
flag1 = False
if k > 2:
if k > 4:
print('NO')
flag = False
break
elif cc == []:
for j in range(len(c)):
cc.append(c[j])
elif k == 3:
cc = []
for j in range(len(c)):
cc.append(c[j])
bb.append(b)
if flag1:
print('YES')
else:
if flag:
for i in range(n):
bb[i][cc[0]], bb[i][cc[1]] = bb[i][cc[1]], bb[i][cc[0]]
f(bb[i])
if k > 2:
flag = False
bb[i][cc[0]], bb[i][cc[1]] = bb[i][cc[1]], bb[i][cc[0]]
if flag:
print('YES')
else:
flag = True
for i in range(n):
bb[i][cc[0]], bb[i][cc[2]] = bb[i][cc[2]], bb[i][cc[0]]
f(bb[i])
if k > 2:
flag = False
bb[i][cc[0]], bb[i][cc[2]] = bb[i][cc[2]], bb[i][cc[0]]
if flag:
print('YES')
else:
flag = True
for i in range(n):
bb[i][cc[1]], bb[i][cc[2]] = bb[i][cc[2]], bb[i][cc[1]]
f(bb[i])
if k > 2:
flag = False
bb[i][cc[1]], bb[i][cc[2]] = bb[i][cc[2]], bb[i][cc[1]]
if flag:
print('YES')
else:
if len(cc) == 3:
print('NO')
else:
flag = True
for i in range(n):
bb[i][cc[0]], bb[i][cc[3]] = bb[i][cc[3]], bb[i][cc[0]]
f(bb[i])
if k > 2:
flag = False
bb[i][cc[0]], bb[i][cc[3]] = bb[i][cc[3]], bb[i][cc[0]]
if flag:
print('YES')
else:
flag = True
for i in range(n):
bb[i][cc[1]], bb[i][cc[3]] = bb[i][cc[3]], bb[i][cc[1]]
f(bb[i])
if k > 2:
flag = False
bb[i][cc[1]], bb[i][cc[3]] = bb[i][cc[3]], bb[i][cc[1]]
if flag:
print('YES')
else:
flag = True
for i in range(n):
bb[i][cc[2]], bb[i][cc[3]] = bb[i][cc[3]], bb[i][cc[2]]
f(bb[i])
if k > 2:
flag = False
bb[i][cc[2]], bb[i][cc[3]] = bb[i][cc[3]], bb[i][cc[2]]
if flag:
print('YES')
else:
print('NO')
|
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 to perform from 0 to n + 1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
|
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 8 9 10\r\n", "output": "YES\r\n"}, {"input": "5 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n1 2 3 8 5 6 7 10 9 4 11 12\r\n1 5 3 4 2 6 7 10 9 8 11 12\r\n1 2 3 4 5 6 7 10 9 8 11 12\r\n", "output": "YES\r\n"}, {"input": "4 10\r\n3 2 8 10 5 6 7 1 9 4\r\n1 2 9 4 5 3 7 8 10 6\r\n7 5 3 4 8 6 1 2 9 10\r\n4 2 3 9 8 6 7 5 1 10\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n9 2 3 4 5 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 6 7 8 1 10\r\n9 5 3 4 2 10 7 8 1 6\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n9 10 4 2 3 5 7 1 8 6\r\n", "output": "NO\r\n"}, {"input": "5 10\r\n6 4 7 3 5 8 1 9 10 2\r\n1 5 10 6 3 4 9 7 2 8\r\n3 2 1 7 8 6 5 4 10 9\r\n7 9 1 6 8 2 4 5 3 10\r\n3 4 6 9 8 7 1 2 10 5\r\n", "output": "NO\r\n"}, {"input": "20 2\r\n1 2\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n1 2\r\n2 1\r\n2 1\r\n1 2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "20 3\r\n3 2 1\r\n2 3 1\r\n2 3 1\r\n2 1 3\r\n1 3 2\r\n2 1 3\r\n1 2 3\r\n3 2 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n2 1 3\r\n2 3 1\r\n2 3 1\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n1 3 2\r\n3 1 2\r\n3 1 2\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 2 3 4 5 6 7 10 9 8\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n6 9 3 4 5 1 8 7 2 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 19 14 15 16 17 18 13 20\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 20\r\n1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 17 18 19 20\r\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20\r\n1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 12 18 7 8 9 10 11 5 13 14 15 16 17 6 19 20\r\n6 2 3 4 5 1 7 8 9 10 11 12 13 20 15 16 17 18 19 14\r\n4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17 18 19 20\r\n1 2 3 4 5 6 19 8 9 10 11 12 13 14 15 20 17 18 7 16\r\n1 2 9 4 5 6 7 8 18 10 11 12 13 14 15 16 17 3 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n4 2 3 8 5 6 7 1 9 10\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n3 2 1 4 5 6 7 8 10 9\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 18 14 15 16 17 13 11 20\r\n1 2 11 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 3 20\r\n13 2 3 4 5 6 7 8 9 10 19 12 1 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 3 4 5 6 16 8 9 10 11 12 13 14 15 7 17 18 19 20\r\n1 2 3 14 5 6 16 8 9 10 11 12 13 4 15 7 17 18 19 20\r\n1 2 3 4 5 6 16 8 18 10 11 12 13 14 15 7 17 9 19 20\r\n1 2 3 4 5 6 16 8 9 15 11 12 13 14 10 7 17 18 19 20\r\n1 2 18 4 5 6 16 8 9 10 11 12 13 14 15 7 17 3 19 20\r\n", "output": "YES\r\n"}, {"input": "5 20\r\n1 2 18 4 5 6 7 8 9 10 11 12 13 14 15 16 19 3 17 20\r\n8 2 3 9 5 6 7 1 4 10 11 12 13 14 15 16 17 18 19 20\r\n7 2 3 4 5 6 1 8 9 10 11 12 13 14 15 16 17 20 19 18\r\n1 2 3 12 5 6 7 8 9 17 11 4 13 14 15 16 10 18 19 20\r\n1 11 3 4 9 6 7 8 5 10 2 12 13 14 15 16 17 18 19 20\r\n", "output": "NO\r\n"}, {"input": "1 10\r\n10 2 3 4 5 9 7 8 6 1\r\n", "output": "YES\r\n"}, {"input": "1 10\r\n1 9 2 4 6 5 8 3 7 10\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 3 2 19 5 6 7 8 9 17 11 12 13 14 15 16 10 18 4 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 20 6 7 8 9 17 11 12 13 14 15 16 10 18 19 5\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n1 6 17 4 5 2 7 14 9 10 11 12 13 8 15 16 3 18 19 20\r\n5 6 17 4 1 2 7 8 9 10 11 12 13 14 15 16 3 18 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 18 3 16 19 20\r\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 16 3 18 20 19\r\n1 6 17 8 5 2 7 4 9 10 11 12 13 14 15 16 3 18 19 20\r\n", "output": "NO\r\n"}, {"input": "5 20\r\n10 2 9 4 5 6 7 8 15 1 11 16 13 14 3 12 17 18 19 20\r\n10 2 3 4 5 6 7 1 9 8 11 16 13 14 15 12 17 18 19 20\r\n9 2 3 4 5 6 7 8 10 1 11 16 13 14 15 12 20 18 19 17\r\n10 2 3 4 7 6 5 8 9 1 11 16 18 14 15 12 17 13 19 20\r\n10 2 3 4 5 6 7 8 9 20 11 16 14 13 15 12 17 18 19 1\r\n", "output": "NO\r\n"}, {"input": "1 4\r\n2 3 4 1\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n2 1 3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "15 6\r\n2 1 4 3 6 5\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n4 3 1 2\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "4 8\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n1 2 3 4 6 5 8 7\r\n", "output": "YES\r\n"}, {"input": "4 6\r\n1 2 3 5 6 4\r\n3 2 1 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n1 2 3\r\n3 1 2\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 1 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "20 8\r\n4 3 2 1 5 6 7 8\r\n1 2 3 4 8 7 6 5\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n8 7 6 5 4 3 2 1\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n1 2 3 4 5 6 7 8\r\n", "output": "NO\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n1 2 3 4 5 6 7 8 10 9 12 11\r\n", "output": "YES\r\n"}, {"input": "6 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 9 10 11 12\r\n1 2 3 4 5 6 7 8 10 11 12 9\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n3 2 1 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n4 3 2 1\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 3 4\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n2 3 1 4 5 6\r\n1 2 3 5 6 4\r\n", "output": "NO\r\n"}, {"input": "3 3\r\n2 3 1\r\n2 3 1\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 6\r\n6 5 4 3 2 1\r\n6 5 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "5 4\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n3 1 4 2\r\n", "output": "NO\r\n"}, {"input": "6 8\r\n3 8 1 4 5 6 7 2\r\n1 8 3 6 5 4 7 2\r\n1 8 3 5 4 6 7 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n1 8 3 7 5 6 4 2\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 2 4 3 1\r\n2 1 5 4 3\r\n", "output": "NO\r\n"}, {"input": "4 4\r\n2 3 1 4\r\n1 2 3 4\r\n2 3 1 4\r\n2 1 3 4\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n1 2 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 4 3 5\r\n2 1 4 3 5\r\n1 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "3 10\r\n2 1 3 4 5 6 8 7 10 9\r\n1 2 3 4 5 6 8 7 10 9\r\n1 2 3 4 6 5 8 7 10 9\r\n", "output": "NO\r\n"}, {"input": "3 4\r\n3 1 2 4\r\n3 2 4 1\r\n3 1 2 4\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n1 4 2 3 5\r\n1 2 4 5 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 3 4\r\n2 1 5 3 4\r\n", "output": "NO\r\n"}, {"input": "3 6\r\n2 3 1 4 5 6\r\n2 1 4 3 5 6\r\n1 2 3 4 5 6\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}, {"input": "1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "2 4\r\n2 1 4 3\r\n2 1 4 3\r\n", "output": "YES\r\n"}, {"input": "6 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "4 6\r\n6 5 4 3 2 1\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n1 2 3 4 5 6\r\n", "output": "NO\r\n"}, {"input": "2 4\r\n2 3 1 4\r\n1 2 3 4\r\n", "output": "YES\r\n"}, {"input": "3 5\r\n1 2 3 4 5\r\n1 3 4 2 5\r\n1 4 2 3 5\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n1 2 3\r\n1 2 3\r\n1 2 3\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "2 3\r\n3 1 2\r\n1 2 3\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n2 1 5 4 3\r\n2 1 5 4 3\r\n", "output": "YES\r\n"}, {"input": "7 4\r\n1 2 3 4\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n4 3 2 1\r\n", "output": "YES\r\n"}, {"input": "3 3\r\n1 2 3\r\n1 3 2\r\n3 1 2\r\n", "output": "YES\r\n"}, {"input": "10 6\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n2 1 4 3 6 5\r\n", "output": "NO\r\n"}]
| 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
return rst
n = int(input())
arr = [map(int, input().split()) for _ in range(n)]
arr = [pi*(r*r*h) for r, h in arr]
arr2 = sorted(list(set(arr)))
n2 = len(arr2)
bit = [0.0] * (n2 + 1)
for v in arr:
idx = bisect(arr2, v)
update(bit, n2, idx, read(bit, idx-1) + v)
print(max(bit))
|
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 cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
|
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)} \leq 10^{-6}$$.
| 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\n1 1\r\n2 2\r\n", "output": "84.823001647\r\n"}, {"input": "3\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "113.097335529\r\n"}, {"input": "3\r\n1 1\r\n3 3\r\n2 2\r\n", "output": "87.964594301\r\n"}, {"input": "3\r\n3 3\r\n2 2\r\n1 1\r\n", "output": "84.823001647\r\n"}, {"input": "1\r\n1 1\r\n", "output": "3.141592654\r\n"}, {"input": "2\r\n1 1\r\n2 2\r\n", "output": "28.274333882\r\n"}, {"input": "2\r\n2 2\r\n1 1\r\n", "output": "25.132741229\r\n"}, {"input": "4\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n", "output": "314.159265359\r\n"}, {"input": "4\r\n1 1\r\n2 2\r\n4 4\r\n3 3\r\n", "output": "229.336263712\r\n"}, {"input": "4\r\n1 1\r\n3 3\r\n2 2\r\n4 4\r\n", "output": "289.026524130\r\n"}, {"input": "4\r\n1 1\r\n3 3\r\n4 4\r\n2 2\r\n", "output": "289.026524130\r\n"}, {"input": "4\r\n1 1\r\n4 4\r\n2 2\r\n3 3\r\n", "output": "204.203522483\r\n"}, {"input": "4\r\n1 1\r\n4 4\r\n3 3\r\n2 2\r\n", "output": "204.203522483\r\n"}, {"input": "4\r\n2 2\r\n1 1\r\n3 3\r\n4 4\r\n", "output": "311.017672705\r\n"}, {"input": "4\r\n2 2\r\n1 1\r\n4 4\r\n3 3\r\n", "output": "226.194671058\r\n"}, {"input": "4\r\n2 2\r\n3 3\r\n1 1\r\n4 4\r\n", "output": "311.017672705\r\n"}, {"input": "4\r\n2 2\r\n3 3\r\n4 4\r\n1 1\r\n", "output": "311.017672705\r\n"}, {"input": "4\r\n2 2\r\n4 4\r\n1 1\r\n3 3\r\n", "output": "226.194671058\r\n"}, {"input": "4\r\n2 2\r\n4 4\r\n3 3\r\n1 1\r\n", "output": "226.194671058\r\n"}, {"input": "4\r\n3 3\r\n1 1\r\n2 2\r\n4 4\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n3 3\r\n1 1\r\n4 4\r\n2 2\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n3 3\r\n2 2\r\n1 1\r\n4 4\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n3 3\r\n2 2\r\n4 4\r\n1 1\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n3 3\r\n4 4\r\n1 1\r\n2 2\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n3 3\r\n4 4\r\n2 2\r\n1 1\r\n", "output": "285.884931477\r\n"}, {"input": "4\r\n4 4\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "201.061929830\r\n"}, {"input": "4\r\n4 4\r\n1 1\r\n3 3\r\n2 2\r\n", "output": "201.061929830\r\n"}, {"input": "4\r\n4 4\r\n2 2\r\n1 1\r\n3 3\r\n", "output": "201.061929830\r\n"}, {"input": "4\r\n4 4\r\n2 2\r\n3 3\r\n1 1\r\n", "output": "201.061929830\r\n"}, {"input": "4\r\n4 4\r\n3 3\r\n1 1\r\n2 2\r\n", "output": "201.061929830\r\n"}, {"input": "4\r\n4 4\r\n3 3\r\n2 2\r\n1 1\r\n", "output": "201.061929830\r\n"}, {"input": "24\r\n14 3600\r\n105 64\r\n40 441\r\n15 3136\r\n24 1225\r\n42 400\r\n84 100\r\n12 4900\r\n120 49\r\n56 225\r\n140 36\r\n70 144\r\n168 25\r\n60 196\r\n30 784\r\n280 9\r\n10 7056\r\n21 1600\r\n28 900\r\n210 16\r\n420 4\r\n840 1\r\n35 576\r\n20 1764\r\n", "output": "2216707.776373104\r\n"}, {"input": "15\r\n40 9\r\n12 100\r\n60 4\r\n20 36\r\n24 25\r\n15 64\r\n120 1\r\n4 900\r\n6 400\r\n5 576\r\n10 144\r\n30 16\r\n3 1600\r\n2 3600\r\n8 225\r\n", "output": "45238.934211696\r\n"}, {"input": "14\r\n8 324\r\n12 144\r\n72 4\r\n144 1\r\n48 9\r\n3 2304\r\n24 36\r\n2 5184\r\n9 256\r\n36 16\r\n6 576\r\n4 1296\r\n18 64\r\n16 81\r\n", "output": "65144.065264842\r\n"}, {"input": "15\r\n4 1764\r\n24 49\r\n84 4\r\n21 64\r\n28 36\r\n6 784\r\n7 576\r\n2 7056\r\n168 1\r\n56 9\r\n3 3136\r\n8 441\r\n14 144\r\n42 16\r\n12 196\r\n", "output": "88668.311054924\r\n"}, {"input": "15\r\n3 3200\r\n2 7200\r\n20 72\r\n8 450\r\n60 8\r\n15 128\r\n4 1800\r\n5 1152\r\n24 50\r\n40 18\r\n120 2\r\n6 800\r\n30 32\r\n12 200\r\n10 288\r\n", "output": "90477.868423392\r\n"}, {"input": "17\r\n6 900\r\n20 81\r\n45 16\r\n4 2025\r\n15 144\r\n9 400\r\n2 8100\r\n3 3600\r\n10 324\r\n30 36\r\n5 1296\r\n12 225\r\n36 25\r\n18 100\r\n90 4\r\n60 9\r\n180 1\r\n", "output": "101787.601976316\r\n"}, {"input": "13\r\n24 72\r\n3 4608\r\n18 128\r\n72 8\r\n48 18\r\n144 2\r\n4 2592\r\n16 162\r\n9 512\r\n6 1152\r\n12 288\r\n36 32\r\n8 648\r\n", "output": "130288.130529684\r\n"}, {"input": "14\r\n60 12\r\n20 108\r\n24 75\r\n120 3\r\n3 4800\r\n5 1728\r\n6 1200\r\n8 675\r\n12 300\r\n4 2700\r\n30 48\r\n15 192\r\n40 27\r\n10 432\r\n", "output": "135716.802635088\r\n"}, {"input": "14\r\n105 4\r\n14 225\r\n6 1225\r\n7 900\r\n35 36\r\n10 441\r\n30 49\r\n5 1764\r\n21 100\r\n70 9\r\n42 25\r\n3 4900\r\n210 1\r\n15 196\r\n", "output": "138544.236023319\r\n"}, {"input": "14\r\n6 1296\r\n216 1\r\n18 144\r\n3 5184\r\n8 729\r\n4 2916\r\n72 9\r\n12 324\r\n9 576\r\n54 16\r\n36 36\r\n27 64\r\n108 4\r\n24 81\r\n", "output": "146574.146845895\r\n"}, {"input": "14\r\n4 3528\r\n12 392\r\n24 98\r\n84 8\r\n14 288\r\n42 32\r\n168 2\r\n56 18\r\n6 1568\r\n8 882\r\n3 6272\r\n21 128\r\n28 72\r\n7 1152\r\n", "output": "177336.622109848\r\n"}, {"input": "18\r\n3 6400\r\n4 3600\r\n20 144\r\n8 900\r\n24 100\r\n15 256\r\n30 64\r\n16 225\r\n10 576\r\n48 25\r\n5 2304\r\n80 9\r\n60 16\r\n240 1\r\n6 1600\r\n40 36\r\n12 400\r\n120 4\r\n", "output": "180955.736846784\r\n"}, {"input": "13\r\n3 6912\r\n144 3\r\n24 108\r\n18 192\r\n16 243\r\n36 48\r\n9 768\r\n12 432\r\n4 3888\r\n48 27\r\n72 12\r\n8 972\r\n6 1728\r\n", "output": "195432.195794527\r\n"}, {"input": "16\r\n126 4\r\n21 144\r\n3 7056\r\n14 324\r\n42 36\r\n63 16\r\n28 81\r\n36 49\r\n7 1296\r\n84 9\r\n252 1\r\n4 3969\r\n6 1764\r\n9 784\r\n12 441\r\n18 196\r\n", "output": "199503.699873579\r\n"}, {"input": "16\r\n45 32\r\n12 450\r\n60 18\r\n9 800\r\n180 2\r\n6 1800\r\n4 4050\r\n36 50\r\n3 7200\r\n18 200\r\n15 288\r\n30 72\r\n20 162\r\n90 8\r\n10 648\r\n5 2592\r\n", "output": "203575.203952632\r\n"}, {"input": "14\r\n22 144\r\n24 121\r\n264 1\r\n6 1936\r\n132 4\r\n33 64\r\n4 4356\r\n12 484\r\n66 16\r\n3 7744\r\n44 36\r\n11 576\r\n88 9\r\n8 1089\r\n", "output": "218956.441584609\r\n"}, {"input": "14\r\n30 80\r\n5 2880\r\n4 4500\r\n3 8000\r\n10 720\r\n12 500\r\n8 1125\r\n6 2000\r\n60 20\r\n120 5\r\n24 125\r\n15 320\r\n40 45\r\n20 180\r\n", "output": "226194.671058480\r\n"}, {"input": "14\r\n27 100\r\n135 4\r\n3 8100\r\n45 36\r\n90 9\r\n30 81\r\n6 2025\r\n270 1\r\n54 25\r\n18 225\r\n10 729\r\n15 324\r\n5 2916\r\n9 900\r\n", "output": "229022.104446711\r\n"}, {"input": "14\r\n28 100\r\n140 4\r\n20 196\r\n5 3136\r\n56 25\r\n4 4900\r\n40 49\r\n7 1600\r\n35 64\r\n70 16\r\n10 784\r\n280 1\r\n14 400\r\n8 1225\r\n", "output": "246300.864041456\r\n"}, {"input": "16\r\n32 81\r\n96 9\r\n12 576\r\n3 9216\r\n18 256\r\n144 4\r\n36 64\r\n16 324\r\n72 16\r\n4 5184\r\n48 36\r\n288 1\r\n8 1296\r\n6 2304\r\n24 144\r\n9 1024\r\n", "output": "260576.261059369\r\n"}, {"input": "14\r\n3 9408\r\n12 588\r\n4 5292\r\n24 147\r\n42 48\r\n7 1728\r\n168 3\r\n84 12\r\n6 2352\r\n28 108\r\n56 27\r\n8 1323\r\n21 192\r\n14 432\r\n", "output": "266004.933164772\r\n"}, {"input": "14\r\n20 216\r\n12 600\r\n5 3456\r\n10 864\r\n15 384\r\n3 9600\r\n4 5400\r\n30 96\r\n8 1350\r\n6 2400\r\n24 150\r\n60 24\r\n120 6\r\n40 54\r\n", "output": "271433.605270176\r\n"}, {"input": "14\r\n35 72\r\n21 200\r\n6 2450\r\n5 3528\r\n70 18\r\n30 98\r\n10 882\r\n15 392\r\n105 8\r\n210 2\r\n42 50\r\n3 9800\r\n14 450\r\n7 1800\r\n", "output": "277088.472046638\r\n"}, {"input": "16\r\n100 9\r\n3 10000\r\n60 25\r\n15 400\r\n75 16\r\n10 900\r\n50 36\r\n150 4\r\n25 144\r\n6 2500\r\n12 625\r\n5 3600\r\n20 225\r\n30 100\r\n4 5625\r\n300 1\r\n", "output": "282743.338823100\r\n"}, {"input": "13\r\n72 18\r\n24 162\r\n36 72\r\n4 5832\r\n18 288\r\n54 32\r\n12 648\r\n9 1152\r\n108 8\r\n216 2\r\n8 1458\r\n27 128\r\n6 2592\r\n", "output": "293148.293691790\r\n"}, {"input": "15\r\n36 75\r\n45 48\r\n6 2700\r\n9 1200\r\n30 108\r\n18 300\r\n12 675\r\n20 243\r\n5 3888\r\n4 6075\r\n60 27\r\n90 12\r\n10 972\r\n180 3\r\n15 432\r\n", "output": "305362.805928948\r\n"}, {"input": "13\r\n12 676\r\n39 64\r\n6 2704\r\n8 1521\r\n52 36\r\n312 1\r\n13 576\r\n104 9\r\n4 6084\r\n156 4\r\n24 169\r\n78 16\r\n26 144\r\n", "output": "305815.195271065\r\n"}, {"input": "9\r\n4 2\r\n2 2\r\n4 1\r\n3 1\r\n1 1\r\n4 3\r\n5 1\r\n4 3\r\n4 1\r\n", "output": "304.734487398\r\n"}, {"input": "5\r\n8 3\r\n6 3\r\n4 2\r\n7 3\r\n6 3\r\n", "output": "801.106126665\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "3.141592654\r\n"}, {"input": "3\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "3141.592653590\r\n"}, {"input": "2\r\n100 30\r\n100 30\r\n", "output": "942477.796077000\r\n"}]
| 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().strip()
b = Decimal(correct_line)
except:
print(0)
return
# Read submission output
try:
with open(submission_output_path, 'r') as f:
sub_line = f.readline().strip()
a = Decimal(sub_line)
except:
print(0)
return
absolute_diff = abs(a - b)
denominator = max(Decimal(1), b)
if absolute_diff <= Decimal('1e-6') * denominator:
print(1)
else:
print(0)
if __name__ == "__main__":
main()
| 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="BCDEFGJKLNPQRSZ"
ch=input()
if ch!="" and len(ch)<=10**5 and 'A'<ch<='Z':
test_achiral(ch,achiral)
| 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 name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
|
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": "YYHUIUGYI\r\n", "output": "NO\r\n"}, {"input": "TT\r\n", "output": "YES\r\n"}, {"input": "UUU\r\n", "output": "YES\r\n"}, {"input": "WYYW\r\n", "output": "YES\r\n"}, {"input": "MITIM\r\n", "output": "YES\r\n"}, {"input": "VO\r\n", "output": "NO\r\n"}, {"input": "WWS\r\n", "output": "NO\r\n"}, {"input": "VIYMAXXAVM\r\n", "output": "NO\r\n"}, {"input": "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM\r\n", "output": "NO\r\n"}, {"input": "CC\r\n", "output": "NO\r\n"}, {"input": "QOQ\r\n", "output": "NO\r\n"}, {"input": "AEEA\r\n", "output": "NO\r\n"}, {"input": "OQQQO\r\n", "output": "NO\r\n"}, {"input": "HNCMEEMCNH\r\n", "output": "NO\r\n"}, {"input": "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ\r\n", "output": "NO\r\n"}, {"input": "A\r\n", "output": "YES\r\n"}, {"input": "B\r\n", "output": "NO\r\n"}, {"input": "C\r\n", "output": "NO\r\n"}, {"input": "D\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}, {"input": "F\r\n", "output": "NO\r\n"}, {"input": "G\r\n", "output": "NO\r\n"}, {"input": "H\r\n", "output": "YES\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "J\r\n", "output": "NO\r\n"}, {"input": "K\r\n", "output": "NO\r\n"}, {"input": "L\r\n", "output": "NO\r\n"}, {"input": "M\r\n", "output": "YES\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "O\r\n", "output": "YES\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "Q\r\n", "output": "NO\r\n"}, {"input": "R\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "T\r\n", "output": "YES\r\n"}, {"input": "U\r\n", "output": "YES\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "W\r\n", "output": "YES\r\n"}, {"input": "X\r\n", "output": "YES\r\n"}, {"input": "Y\r\n", "output": "YES\r\n"}, {"input": "JL\r\n", "output": "NO\r\n"}, {"input": "AAAKTAAA\r\n", "output": "NO\r\n"}, {"input": "AKA\r\n", "output": "NO\r\n"}, {"input": "AAJAA\r\n", "output": "NO\r\n"}, {"input": "ABA\r\n", "output": "NO\r\n"}, {"input": "AAAAAABAAAAAA\r\n", "output": "NO\r\n"}, {"input": "ZZ\r\n", "output": "NO\r\n"}, {"input": "ADA\r\n", "output": "NO\r\n"}, {"input": "N\r\n", "output": "NO\r\n"}, {"input": "P\r\n", "output": "NO\r\n"}, {"input": "LAL\r\n", "output": "NO\r\n"}, {"input": "AABAA\r\n", "output": "NO\r\n"}, {"input": "AZA\r\n", "output": "NO\r\n"}, {"input": "V\r\n", "output": "YES\r\n"}, {"input": "SSS\r\n", "output": "NO\r\n"}, {"input": "NNN\r\n", "output": "NO\r\n"}, {"input": "S\r\n", "output": "NO\r\n"}, {"input": "I\r\n", "output": "YES\r\n"}, {"input": "SS\r\n", "output": "NO\r\n"}, {"input": "E\r\n", "output": "NO\r\n"}]
| 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
from bisect import bisect_left, bisect_right
def input():
return sys.stdin.readline().rstrip()
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getListGraph():
return list(map(lambda x:int(x) - 1, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
mod = 10 ** 9 + 7
MOD = 998244353
# sys.setrecursionlimit(10000000)
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
inf = float('inf')
eps = 10 ** (-12)
dy = [0, 1, 0, -1]
dx = [1, 0, -1, 0]
#############
# Main Code #
#############¥
def reduction(nume, deno):
g = math.gcd(nume, deno)
if g == 0:
g = 1
if deno < 0:
return (-(nume // g), -(deno // g))
elif deno > 0:
return (nume // g, deno // g)
# n / 0 inf
else:
return (1, 0)
def on_the_line(point, center):
res = []
for i in range(len(point)):
x, y = point[i][0] - center[0], point[i][1] - center[1]
g = max(math.gcd(x, y), 1)
if x < 0:
x *= -1
y *= -1
res.append((x // g, y // g))
return res
"""
点はN個ある
とりあえず点0と同一な線上に乗るものは? 残りのもののうち1つでまたやる
見るのは3点だけでいい
①頂点1と頂点2が同一線上 それ以外が同一線上か
②頂点1と頂点3が同一線上 同上
③頂点1とそれ以外が同一線上 頂点2と頂点3は同一線上である必要があるので
線2-3以外の頂点が同一線上か
"""
N = getN()
P = [getList() for i in range(N)]
if N <= 3:
print('YES')
exit()
ans = 'NO'
# 頂点1と頂点2
vec = on_the_line(P, P[0])
left = [P[i] for i in range(N) if vec[i] != vec[0] and vec[i] != vec[1]]
# 全て同一線上
if not left:
print('YES')
exit()
vec_left = on_the_line(left, left[0])
# 原点と何か1つだけならok
if len(set(vec_left)) <= 2:
ans = 'YES'
# 頂点1と頂点3
left = [P[i] for i in range(N) if vec[i] != vec[0] and vec[i] != vec[2]]
vec_left = on_the_line(left, left[0])
if len(set(vec_left)) <= 2:
ans = 'YES'
# 頂点2と頂点3
vec = on_the_line(P, P[1])
left = [P[i] for i in range(N) if vec[i] != vec[1] and vec[i] != vec[2]]
vec_left = on_the_line(left, left[0])
if len(set(vec_left)) <= 2:
ans = 'YES'
print(ans)
| 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:
def add(self, p1, p2, dist=1):
return [p1[0] + p2[0] * dist, p1[1] + p2[1] * dist]
def sub(self, p1, p2):
return [p2[0] - p1[0], p2[1] - p1[1]]
# dot==0 if v1 perpendicular
def dot_mul(self, p1, p2):
return p1[0] * p2[0] + p1[1] * p2[1]
def vecs_ang2(self, p1, p2):
'''measure angle in counter clockwise order'''
v1 = self.cross_mul(p1, p2)
v2 = (p1[0] ** 2 + p1[1] ** 2) ** .5 * (p2[0] ** 2 + p2[1] ** 2) ** .5
return degrees(asin(v1 / v2)) % 360
# cross==0 if <v1v2=0 elif cross<0 then right perpendicular else left perpendicular
def cross_mul(self, p1, p2):
return p1[0] * p2[1] - p2[0] * p1[1]
def unit(self, p1, p2, dist):
return [(p2[0] - p1[0]) / dist, (p2[1] - p1[1]) / dist]
def unit_gcd(self, p1, p2):
vec = [(p2[0] - p1[0]), (p2[1] - p1[1])]
g = abs(gcd(vec[0], vec[1]))
return [vec[0] // g, vec[1] // g]
def collinear(self, p1, p2, p3):
return abs(self.cross_mul(self.sub(p1, p2), self.sub(p1, p3)))
def in_ray(self, p1, p2, p3):
return self.collinear(p1, p2, p3) and self.dot_mul(self.sub(p1, p2), self.sub(p1, p3)) >= 0
def in_segment(self, p1, p2, p3):
return self.in_ray(p1, p2, p3) or self.in_ray(p2, p1, p3)
def dist_to_line(self, p1, p2, p3):
return abs(self.cross_mul(self.sub(p1, p2), self.sub(p1, p3)) / (dist2d([0, 0], self.sub(p1, p2))))
def vec_slop(self, p):
return (360 + degrees(atan2(p[1], p[0]))) % 360
def slop(self, p1, p2):
try:
return (p2[1] - p1[1]) / (p2[0] - p1[0])
except:
return float('inf')
def triangle_area(self, p1, p2, p3):
return abs((p1[0] * (p2[1] - p3[1]) + p2[0] * (p3[1] - p1[1]) + p3[0] * (p1[1] - p2[1])) / 2)
def solve():
if n < 3: return 'YES'
p = Point()
for i in range(3):
for j in range(i + 1, 3):
oth = []
for k in range(n):
if k != i and k != j:
if p.collinear([xs[i], ys[i]], [xs[j], ys[j]], [xs[k], ys[k]]):
oth.append(k)
if len(oth) < 3: return 'YES'
for k in range(2, len(oth)):
if p.collinear([xs[oth[0]], ys[oth[0]]], [xs[oth[1]], ys[oth[1]]], [xs[oth[k]], ys[oth[k]]]):
break
else:
return 'YES'
return 'NO'
for _ in range(tests):
n = int(input())
xs = array('i', [0] * n)
ys = array('i', [0] * n)
for i in range(n): xs[i], ys[i] = inp(int)
out.append(solve())
print('\n'.join(map(str, out)))
|
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\r\n10 5\r\n10 -2\r\n-2 -10\r\n-4 -9\r\n", "output": "YES\r\n"}, {"input": "5\r\n-10 3\r\n4 -5\r\n-9 5\r\n-5 -3\r\n-4 -6\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 9\r\n-1 -4\r\n-3 -8\r\n-4 8\r\n7 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n315 202\r\n315 203\r\n315 204\r\n-138 -298\r\n-136 -295\r\n-134 -292\r\n-132 -289\r\n-130 -286\r\n-128 -283\r\n-126 -280\r\n", "output": "YES\r\n"}, {"input": "10\r\n416 -473\r\n-162 491\r\n-164 488\r\n-170 479\r\n-166 485\r\n-172 476\r\n416 -475\r\n416 -474\r\n-168 482\r\n-160 494\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 1\r\n0 1\r\n1 0\r\n0 2\r\n2 0\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3\r\n6 3\r\n0 0\r\n10 0\r\n-10 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0\r\n1 0\r\n0 1\r\n0 2\r\n2 0\r\n3 0\r\n0 3\r\n0 4\r\n4 0\r\n0 -10000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 -1\r\n1 -1\r\n3 3\r\n2 0\r\n-2 -2\r\n1 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1000000000 1000000000\r\n999999999 999999999\r\n999999999 999999998\r\n-1000000000 1000000000\r\n-1000000000 999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n-1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 -1\r\n1 1\r\n1 -1\r\n2 -1\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n536870912 536870912\r\n268435456 368435456\r\n268435456 168435456\r\n1 3\r\n2 4\r\n3 5\r\n4 6\r\n5 7\r\n6 8\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n100 100\r\n100 99\r\n100 98\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n5 0\r\n7 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n1 1\r\n0 2\r\n5 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n0 0\r\n4 0\r\n1 1\r\n2 2\r\n3 1\r\n5 1\r\n6 2\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n2 2\r\n3 2\r\n4 1\r\n5 2\r\n6 1\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 0\r\n3 0\r\n0 1\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "12\r\n0 0\r\n1 1\r\n2 2\r\n3 3\r\n10 11\r\n20 11\r\n30 11\r\n40 11\r\n-1 1\r\n-2 2\r\n-3 3\r\n-4 4\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 0\r\n165580141 267914296\r\n331160282 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n433494437 701408733\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n229254610 -608716105\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-176884026 -737994048\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n5 0\r\n5 1\r\n5 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1 1\r\n1 0\r\n1 1\r\n1 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n0 0\r\n-1 -1\r\n1 0\r\n0 -1\r\n-1 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n8 8\r\n3303829 10\r\n10 1308\r\n4 2\r\n6 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n0 2\r\n0 3\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n165580142 267914296\r\n331160283 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n", "output": "YES\r\n"}, {"input": "59\r\n1 0\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n6 0\r\n7 0\r\n8 0\r\n9 0\r\n10 0\r\n0 11\r\n12 0\r\n13 0\r\n14 0\r\n15 0\r\n0 16\r\n0 17\r\n18 0\r\n19 0\r\n20 0\r\n21 0\r\n0 22\r\n23 0\r\n24 0\r\n0 25\r\n26 0\r\n27 0\r\n0 28\r\n0 29\r\n30 0\r\n31 0\r\n0 32\r\n33 0\r\n34 0\r\n0 35\r\n0 36\r\n37 0\r\n0 38\r\n39 0\r\n40 0\r\n0 41\r\n42 0\r\n0 43\r\n0 44\r\n0 45\r\n0 46\r\n47 0\r\n0 48\r\n0 49\r\n50 0\r\n0 51\r\n0 52\r\n53 0\r\n0 54\r\n55 0\r\n0 56\r\n57 0\r\n0 58\r\n59 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n10000000 40000100\r\n3 112\r\n2 400000100\r\n1 104\r\n1000000 701789036\r\n", "output": "YES\r\n"}, {"input": "5\r\n514 2131\r\n312 52362\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "YES\r\n"}, {"input": "9\r\n-65536 65536\r\n0 65536\r\n65536 65536\r\n-65536 0\r\n0 0\r\n65536 0\r\n-65536 -65536\r\n0 -65536\r\n65536 -65536\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 -7\r\n0 10000\r\n1 1000000000\r\n100 0\r\n200 0\r\n", "output": "NO\r\n"}, {"input": "7\r\n0 0\r\n2 2\r\n2 -2\r\n-2 2\r\n-2 -2\r\n0 1\r\n0 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 0\r\n4 1\r\n0 0\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-65536 -65536\r\n65536 0\r\n131072 0\r\n0 65536\r\n0 131072\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n2 0\r\n0 2\r\n0 -2\r\n-2 1\r\n-4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-133011126 -464171408\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n-1 0\r\n0 1\r\n-1 1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 -1\r\n0 -1\r\n-1 1\r\n-1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 1\r\n-1 0\r\n0 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n-1 1\r\n-1 0\r\n1 1\r\n-1 -1\r\n0 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 2\r\n-1 1\r\n2 1\r\n-2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n-1000000000 0\r\n999999999 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n0 0\r\n65536 65536\r\n65536 131072\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n999999999 1\r\n-1000000000 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n-1 1\r\n-1 -1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 -1\r\n3 -3\r\n1 2\r\n0 -2\r\n1 -3\r\n0 1\r\n0 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n-1 1\r\n-1 -1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n-1 1\r\n0 -1\r\n1 0\r\n-1 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n0 0\r\n-1 0\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "11\r\n-2 -2\r\n2 3\r\n3 -2\r\n1 -2\r\n2 -2\r\n2 0\r\n2 2\r\n-3 -2\r\n-1 -2\r\n2 -3\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 0\r\n-1 1\r\n1 0\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 -1\r\n0 0\r\n0 1\r\n-1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 1\r\n0 -2\r\n1 -1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-999999998 -999999998\r\n229254612 -608716103\r\n-588442011 -868997022\r\n-182303375 -739719079\r\n-176884024 -737994046\r\n", "output": "YES\r\n"}]
| 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"*(b-1)
break
elif i>"7" or a+b==1:
b+=ca
x=x[:-ca-1]+"7"
a+=1
b-=1
x+="4"*(a)+"7"*b
break
else:
x+=i
if i=="4":
a-=1
else:
b-=1
if i=="7":
ca+=1
else:
ca=0
print(x)
| 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 = []
for j in range(1, len(challenger) + 1):
if challenger[-j] == '4':
update += ['7'] + challenger[:-j][::-1]
break
else:
update.append('4')
else:
update.append('4')
challenger = update[::-1] + ['4' for j in range(len(s[i:]))]
break
elif s[i] < '4':
challenger += ['4' for j in range(len(s[i:]))]
break
else:
challenger += ['7'] + ['4' for j in range(len(s[i:]) - 1)]
break
while True:
if challenger.count('4') == challenger.count('7'):
break
if len(challenger) % 2:
challenger = ['4' for i in range((len(challenger) + 1) // 2)] + ['7' for i in range((len(challenger) + 1) // 2)]
elif challenger.count('4') > challenger.count('7'):
cnt = challenger.count('4') - challenger.count('7')
for i in range(len(challenger) - 1, -1, -1):
if challenger[i] == '4':#1
challenger[i] = '7'
cnt -= 2
if not cnt:
break
else:
cnt = [0 for i in range(len(challenger))]
cnt[-1] = challenger[-1] == '7'
for i in range(2, len(challenger) + 1):
cnt[-i] = cnt[-i + 1] + (challenger[-i] == '7')
if not challenger[:len(challenger) // 2].count('4'):
challenger = ['4' for i in range((len(challenger) + 2) // 2)] + ['7' for i in range((len(challenger) + 2) // 2)]
else:
first, second = challenger.count('4'), challenger.count('7')
for j in range(len(challenger) - 2, -1, -1):
if challenger[j] == '4' and cnt[j + 1] * 2 + first >= second:
challenger[j] = '7'
for z in range(j + 1, len(challenger)):
challenger[z] = '4'
break
stdout.write(''.join(challenger))
# Made By Mostafa_Khaled
|
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. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
|
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", "output": "4444477777"}, {"input": "49102094540227023300\r\n", "output": "74444444444777777777\r\n"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "777777\r\n", "output": "44447777"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "474\r\n", "output": "4477"}, {"input": "85469\r\n", "output": "444777"}, {"input": "7474747\r\n", "output": "44447777"}, {"input": "2145226\r\n", "output": "44447777"}, {"input": "5556585\r\n", "output": "44447777"}, {"input": "87584777\r\n", "output": "4444477777"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "999999999\r\n", "output": "4444477777"}, {"input": "74477744\r\n", "output": "74477744\r\n"}, {"input": "444444444\r\n", "output": "4444477777"}, {"input": "467549754\r\n", "output": "4444477777"}, {"input": "147474747\r\n", "output": "4444477777"}, {"input": "555\r\n", "output": "4477"}, {"input": "100000\r\n", "output": "444777\r\n"}, {"input": "74777443\r\n", "output": "74777444\r\n"}, {"input": "4700007\r\n", "output": "44447777"}, {"input": "70070077\r\n", "output": "74444777\r\n"}, {"input": "123\r\n", "output": "4477"}, {"input": "7474\r\n", "output": "7474\r\n"}, {"input": "3696\r\n", "output": "4477\r\n"}, {"input": "5594108733309806863211189515406929423407691887690557101598403485\r\n", "output": "7444444444444444444444444444444447777777777777777777777777777777\r\n"}, {"input": "7004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224\r\n", "output": "7444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777\r\n"}, {"input": "795193728547733389463100378996233822835539327235483308682350676991954960294227364128385843182064933115\r\n", "output": "44444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777"}, {"input": "61136338618684683458627308377793588546921041456473994251912971721612136383004772112243903436104509483190819343988300672009142812305068378720235800534191119843225949741796417107434937387267716981006150\r\n", "output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777\r\n"}, {"input": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774744777447\r\n", "output": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774747444444\r\n"}, {"input": "474777447477447774447777477444444747747747447474\r\n", "output": "474777447477447774447777477444444747747747447474\r\n"}, {"input": "35881905331681060827588553219538774024143083787975\r\n", "output": "44444444444444444444444447777777777777777777777777\r\n"}, {"input": "221020945402270233\r\n", "output": "444444444777777777\r\n"}, {"input": "241925018843248944336317949908388280315030601139576419352009710\r\n", "output": "4444444444444444444444444444444477777777777777777777777777777777"}, {"input": "888999577\r\n", "output": "4444477777"}, {"input": "10\r\n", "output": "47\r\n"}, {"input": "7\r\n", "output": "47"}, {"input": "50\r\n", "output": "74\r\n"}, {"input": "70\r\n", "output": "74\r\n"}, {"input": "74700\r\n", "output": "444777"}, {"input": "1024\r\n", "output": "4477\r\n"}, {"input": "73\r\n", "output": "74\r\n"}, {"input": "74710000\r\n", "output": "74744477\r\n"}, {"input": "444000000\r\n", "output": "4444477777"}, {"input": "4\r\n", "output": "47"}, {"input": "1\r\n", "output": "47"}, {"input": "9\r\n", "output": "47"}, {"input": "99\r\n", "output": "4477"}, {"input": "48\r\n", "output": "74\r\n"}, {"input": "4747474749\r\n", "output": "4747474774\r\n"}, {"input": "4747474774\r\n", "output": "4747474774\r\n"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "4777\r\n", "output": "7447\r\n"}, {"input": "7748\r\n", "output": "444777"}, {"input": "7773\r\n", "output": "444777"}, {"input": "19\r\n", "output": "47\r\n"}, {"input": "447777\r\n", "output": "474477\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:
vi[girl] = cur
if gb[girl] == -1:
bg[boy] = girl
gb[girl] = boy
return 1
if dfs(gb[girl], cur) > 0:
bg[boy] = girl
bg[girl] = boy
return 1
return 0
ans = 0
for cur in range(n):
ans += dfs(cur, cur)
print(ans)
| 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 must differ by at most one.
For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.
|
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 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.
|
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"}, {"input": "4\r\n4 5 4 4\r\n5\r\n5 3 4 2 4\r\n", "output": "4\r\n"}, {"input": "1\r\n2\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n3\r\n2\r\n3 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n3\r\n4 4 4\r\n", "output": "1\r\n"}, {"input": "1\r\n2\r\n4\r\n3 1 4 2\r\n", "output": "1\r\n"}, {"input": "1\r\n4\r\n5\r\n2 5 5 3 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "2\r\n4 2\r\n2\r\n4 4\r\n", "output": "1\r\n"}, {"input": "2\r\n4 1\r\n3\r\n2 3 2\r\n", "output": "2\r\n"}, {"input": "2\r\n4 3\r\n4\r\n5 5 5 6\r\n", "output": "1\r\n"}, {"input": "2\r\n5 7\r\n5\r\n4 6 7 2 5\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "3\r\n5 4 5\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n6 3 4\r\n3\r\n4 5 2\r\n", "output": "3\r\n"}, {"input": "3\r\n7 7 7\r\n4\r\n2 7 2 4\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 3\r\n5\r\n1 3 4 1 2\r\n", "output": "3\r\n"}, {"input": "4\r\n1 2 1 3\r\n1\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n4 4 6 6\r\n2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "4\r\n3 1 1 1\r\n3\r\n1 6 7\r\n", "output": "1\r\n"}, {"input": "4\r\n2 5 1 2\r\n4\r\n2 3 3 1\r\n", "output": "3\r\n"}, {"input": "4\r\n9 1 7 1\r\n5\r\n9 9 9 8 4\r\n", "output": "2\r\n"}, {"input": "5\r\n1 6 5 5 6\r\n1\r\n2\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 4 5 6\r\n2\r\n7 4\r\n", "output": "2\r\n"}, {"input": "5\r\n4 1 3 1 4\r\n3\r\n6 3 6\r\n", "output": "1\r\n"}, {"input": "5\r\n5 2 3 1 4\r\n4\r\n1 3 1 7\r\n", "output": "3\r\n"}, {"input": "5\r\n9 8 10 9 10\r\n5\r\n2 1 5 4 6\r\n", "output": "0\r\n"}, {"input": "1\r\n48\r\n100\r\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6\r\n", "output": "1\r\n"}, {"input": "100\r\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\r\n1\r\n58\r\n", "output": "0\r\n"}, {"input": "10\r\n20 87 3 39 20 20 8 40 70 51\r\n100\r\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96\r\n", "output": "6\r\n"}, {"input": "100\r\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\r\n10\r\n66 74 40 67 28 82 99 57 93 64\r\n", "output": "9\r\n"}, {"input": "100\r\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\r\n100\r\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1\r\n", "output": "76\r\n"}, {"input": "4\r\n1 6 9 15\r\n2\r\n5 8\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "3\r\n2 3 5\r\n3\r\n3 4 6\r\n", "output": "3\r\n"}, {"input": "3\r\n1 3 4\r\n3\r\n2 1 5\r\n", "output": "3\r\n"}, {"input": "2\r\n5 5\r\n4\r\n1 1 1 5\r\n", "output": "1\r\n"}, {"input": "2\r\n3 2\r\n2\r\n3 4\r\n", "output": "2\r\n"}, {"input": "2\r\n3 1\r\n2\r\n2 4\r\n", "output": "2\r\n"}, {"input": "2\r\n2 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n10 12\r\n2\r\n11 9\r\n", "output": "2\r\n"}, {"input": "3\r\n1 2 3\r\n3\r\n3 2 1\r\n", "output": "3\r\n"}, {"input": "2\r\n1 3\r\n2\r\n2 1\r\n", "output": "2\r\n"}, {"input": "2\r\n4 5\r\n2\r\n5 3\r\n", "output": "2\r\n"}, {"input": "2\r\n7 5\r\n2\r\n6 8\r\n", "output": "2\r\n"}, {"input": "4\r\n4 3 2 1\r\n4\r\n1 2 3 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 3\r\n2\r\n3 1\r\n", "output": "2\r\n"}, {"input": "2\r\n2 4\r\n3\r\n3 1 8\r\n", "output": "2\r\n"}, {"input": "3\r\n3 1 1\r\n3\r\n2 4 4\r\n", "output": "2\r\n"}, {"input": "2\r\n5 3\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n1 1 3 3\r\n4\r\n2 2 1 1\r\n", "output": "4\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n2 4 3\r\n", "output": "3\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n5\r\n2 3 4 5 1\r\n", "output": "5\r\n"}, {"input": "3\r\n3 2 1\r\n3\r\n1 2 3\r\n", "output": "3\r\n"}, {"input": "2\r\n5 4\r\n2\r\n4 6\r\n", "output": "2\r\n"}, {"input": "4\r\n3 3 5 5\r\n4\r\n4 4 2 2\r\n", "output": "4\r\n"}, {"input": "3\r\n2 7 5\r\n3\r\n2 4 8\r\n", "output": "3\r\n"}, {"input": "100\r\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\r\n100\r\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5\r\n", "output": "100\r\n"}, {"input": "1\r\n3\r\n2\r\n2 3\r\n", "output": "1\r\n"}, {"input": "2\r\n5 6\r\n3\r\n1 5 100\r\n", "output": "1\r\n"}, {"input": "2\r\n2 7\r\n2\r\n6 8\r\n", "output": "1\r\n"}, {"input": "4\r\n4 10 15 17\r\n4\r\n3 12 16 16\r\n", "output": "3\r\n"}, {"input": "2\r\n2 3\r\n2\r\n1 2\r\n", "output": "2\r\n"}]
| 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.replace(p, r)
ret.append(tmp)
return ''.join(reversed(ret))
encodeB = '0123456789ABCDEFGHIJKLMNO'
decodeA = {x:i for i,x in enumerate(encodeB)}
a,b = input().split()
a = int(a)
if b != 'R' : b = int(b)
c = sum(decodeA[x] * a**i
for i,x in enumerate(reversed(input().lstrip('0'))))
if b == 'R' :
print(intToRoman(c))
return
ans = []
while c :
ans.append(encodeB[c % b])
c //= b
print(''.join(reversed(ans)))
main()
| 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):
x = int(x)
ans = ""
ans += num_four[x // 1000]
x -= (x // 1000) * 1000
ans += num_three[x // 100]
x -= (x // 100) * 100
ans += num_two[x // 10]
x -= (x // 10) * 10
ans += num_one[x]
x -= x
return ans
def to_base(x, b):
x = int(x)
ans = ""
while x >= b:
ans += numbers[x % b]
x = x // b
if x > 0:
ans += numbers[x]
return ans[::-1]
def to_ten(x, b):
x = str(x)
x = x[::-1]
ans = 0
for i in range(len(x)):
ans += (b ** i) * numbers.index(x[i])
return ans
a, b = input().split()
a = int(a)
c = to_ten(input(), a)
if c == 0:
print(0)
elif b == "R":
print(to_roman(c))
else:
print(to_base(c, int(b)))
|
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 captured by Shapur and Shapur is now going to capture Valerian, the Roman emperor.
Being defeated, the cowardly Valerian hid in a room at the top of one of his castles. To capture him, Shapur has to open many doors. Fortunately Valerian was too scared to make impenetrable locks for the doors.
Each door has 4 parts. The first part is an integer number a. The second part is either an integer number b or some really odd sign which looks like R. The third one is an integer c and the fourth part is empty! As if it was laid for writing something. Being extremely gifted, after opening the first few doors, Shapur found out the secret behind the locks.
c is an integer written in base a, to open the door we should write it in base b. The only bad news is that this R is some sort of special numbering system that is used only in Roman empire, so opening the doors is not just a piece of cake!
Here's an explanation of this really weird number system that even doesn't have zero:
Roman numerals are based on seven symbols: a stroke (identified with the letter I) for a unit, a chevron (identified with the letter V) for a five, a cross-stroke (identified with the letter X) for a ten, a C (identified as an abbreviation of Centum) for a hundred, etc.:
- I=1
- V=5
- X=10
- L=50
- C=100
- D=500
- M=1000
Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1, 000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I 1, II 2, III 3, V 5, VI 6, VII 7, etc., and the same for other bases: X 10, XX 20, XXX 30, L 50, LXXX 80; CC 200, DCC 700, etc. At the fourth and ninth iteration, a subtractive principle must be employed, with the base placed before the higher base: IV 4, IX 9, XL 40, XC 90, CD 400, CM 900.
Also in bases greater than 10 we use A for 10, B for 11, etc.
Help Shapur capture Valerian and bring peace back to Persia, especially Armenia.
|
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 included the number would be less than or equal to 300010 and it won't be 0. In any other case the number won't be greater than 101510.
|
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\nABG\r\n", "output": "3951\r\n"}, {"input": "17 10\r\nABACG\r\n", "output": "892363\r\n"}, {"input": "18 R\r\nGH\r\n", "output": "CCCV\r\n"}, {"input": "20 25\r\n4E32BB21D812\r\n", "output": "A2II7CL2HDM\r\n"}, {"input": "15 11\r\n760595A635B24\r\n", "output": "258AA2604713696\r\n"}, {"input": "10 22\r\n956512026633000\r\n", "output": "1E06A57IC4H2\r\n"}, {"input": "5 9\r\n1102101401441324123301\r\n", "output": "2733824152181178\r\n"}, {"input": "23 4\r\nDL5K6H78CAH\r\n", "output": "2003021332111213003322000\r\n"}, {"input": "18 R\r\n36E\r\n", "output": "MXCIV\r\n"}, {"input": "13 2\r\n1B579528314B30\r\n", "output": "10000001011010101001110000001110001011010111010010\r\n"}, {"input": "8 13\r\n20043013541570572\r\n", "output": "1B35CBA6B32102\r\n"}, {"input": "19 24\r\n1BH47I158EII\r\n", "output": "2NHBDL4ECN2\r\n"}, {"input": "14 19\r\n33BC51B817C55\r\n", "output": "1B573FFHHH12\r\n"}, {"input": "24 10\r\nE2E3EA6MJ05\r\n", "output": "894488519782085\r\n"}, {"input": "25 2\r\nIBGNAB3C0H\r\n", "output": "10000000001001000010100000111011000110101000001\r\n"}, {"input": "3 R\r\n2\r\n", "output": "II\r\n"}, {"input": "20 20\r\n3HBAH9JA9EDE\r\n", "output": "3HBAH9JA9EDE\r\n"}, {"input": "21 21\r\n2G3DK3F23905\r\n", "output": "2G3DK3F23905\r\n"}, {"input": "23 R\r\n57F\r\n", "output": "MMDCCCXXI\r\n"}, {"input": "16 6\r\n27774848D1D9F\r\n", "output": "10500345245142230115\r\n"}, {"input": "18 7\r\nD9D42E745C5A\r\n", "output": "351206225505021115\r\n"}, {"input": "11 R\r\n1A8A\r\n", "output": "MMDCXXXIX\r\n"}, {"input": "12 17\r\n567872838B15A5\r\n", "output": "105CA323BC110\r\n"}, {"input": "12 19\r\n78613621478844\r\n", "output": "71A1E1HB01EB\r\n"}, {"input": "12 25\r\n51B878A1B3A7B8\r\n", "output": "5JLBAF5JBEA\r\n"}, {"input": "12 R\r\n17BB\r\n", "output": "MMDCCCLXXIX\r\n"}, {"input": "20 R\r\nFI\r\n", "output": "CCCXVIII\r\n"}, {"input": "20 5\r\n1FAD98HHG13G\r\n", "output": "340143030243121422401\r\n"}, {"input": "19 12\r\nEHIAG4GG072\r\n", "output": "A33B813901970\r\n"}, {"input": "3 R\r\n2201120\r\n", "output": "MCMLXXXVI\r\n"}, {"input": "3 R\r\n10210211\r\n", "output": "MMDCCLXXVI\r\n"}, {"input": "3 R\r\n21222\r\n", "output": "CCXV\r\n"}, {"input": "11 22\r\n172A57412774400\r\n", "output": "11G8KLBCI95B\r\n"}, {"input": "17 4\r\n1509D9E003C5C\r\n", "output": "2223230302121200303102203\r\n"}, {"input": "2 R\r\n101110110111\r\n", "output": "MMCMXCIX\r\n"}, {"input": "25 R\r\n2JA\r\n", "output": "MDCCXXXV\r\n"}, {"input": "23 R\r\n3HK\r\n", "output": "MCMXCVIII\r\n"}, {"input": "10 22\r\n1000000000000000\r\n", "output": "1FE6KH3A0F7A\r\n"}, {"input": "10 2\r\n999999999999993\r\n", "output": "11100011010111111010100100110001100111111111111001\r\n"}, {"input": "4 21\r\n112233030100132210003330\r\n", "output": "5KIIKBEFE1G\r\n"}, {"input": "4 10\r\n112233030100132210003330\r\n", "output": "100000000000252\r\n"}, {"input": "4 5\r\n112233030100132210003330\r\n", "output": "101101400000000002002\r\n"}, {"input": "2 R\r\n1\r\n", "output": "I\r\n"}, {"input": "13 15\r\n33BCA79805767B\r\n", "output": "7A924652EB469\r\n"}, {"input": "2 10\r\n0\r\n", "output": "0\r\n"}, {"input": "25 2\r\n0\r\n", "output": "0\r\n"}, {"input": "25 10\r\n001\r\n", "output": "1\r\n"}, {"input": "17 17\r\n00000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": "0\r\n"}, {"input": "10 R\r\n999\r\n", "output": "CMXCIX\r\n"}, {"input": "2 2\r\n0\r\n", "output": "0\r\n"}, {"input": "10 10\r\n100000000000\r\n", "output": "100000000000\r\n"}, {"input": "10 10\r\n0\r\n", "output": "0\r\n"}, {"input": "10 R\r\n900\r\n", "output": "CM\r\n"}, {"input": "10 11\r\n12345678912345\r\n", "output": "3A2A855993029\r\n"}, {"input": "10 2\r\n100000000000000\r\n", "output": "10110101111001100010000011110100100000000000000\r\n"}, {"input": "10 R\r\n1983\r\n", "output": "MCMLXXXIII\r\n"}, {"input": "2 R\r\n101110111000\r\n", "output": "MMM\r\n"}, {"input": "2 R\r\n101110111000\r\n", "output": "MMM\r\n"}, {"input": "10 11\r\n1000000000000000\r\n", "output": "26A6A368906563A\r\n"}, {"input": "10 R\r\n1137\r\n", "output": "MCXXXVII\r\n"}, {"input": "10 R\r\n100\r\n", "output": "C\r\n"}, {"input": "10 25\r\n12343456543435\r\n", "output": "35M8JNIJCA\r\n"}, {"input": "16 10\r\n0523456789ABC\r\n", "output": "90384742521532\r\n"}]
| 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:
if l[i-1][j]=="*":
count_+=1
if j-1!=-1:
if l[i][j-1]=="*":
count_+=1
if j+1!=m:
if l[i][j+1]=="*":
count_+=1
if i+1!=n and j-1!=-1:
if l[i+1][j-1]=="*":
count_+=1
if i+1!=n and j+1!=m:
if l[i+1][j+1]=="*":
count_+=1
if i-1!=-1 and j+1!=m:
if l[i-1][j+1]=="*":
count_+=1
if i-1!=-1 and j+1!=-1:
if l[i-1][j-1]=="*":
count_+=1
if count_!=int(l[i][j]):
flag=True
break
if l[i][j]==".":
count_=0
if i+1!=n:
if l[i+1][j]=="*":
count_+=1
if i-1!=-1:
if l[i-1][j]=="*":
count_+=1
if j-1!=-1:
if l[i][j-1]=="*":
count_+=1
if j+1!=m:
if l[i][j+1]=="*":
count_+=1
if i+1!=n and j-1!=-1:
if l[i+1][j-1]=="*":
count_+=1
if i+1!=n and j+1!=m:
if l[i+1][j+1]=="*":
count_+=1
if i-1!=-1 and j+1!=m:
if l[i-1][j+1]=="*":
count_+=1
if i-1!=-1 and j+1!=-1:
if l[i-1][j-1]=="*":
count_+=1
if count_!=0:
flag=True
break
if flag:
print("NO")
break
if flag==False:
print("YES")
| 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] == '*':
cnt += 1
if cnt != x:
print("NO")
exit(0)
for i in range(n):
for j in range(m):
if grid[i][j] == '.':
check(i,j,0)
elif grid[i][j].isdigit():
check(i,j,int(grid[i][j]))
print("YES")
|
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 difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle $$$n \times m$$$, where each cell is either empty, or contains a digit from $$$1$$$ to $$$8$$$, or a bomb. The field is valid if for each cell:
- if there is a digit $$$k$$$ in the cell, then exactly $$$k$$$ neighboring cells have bombs.
- if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most $$$8$$$ neighboring cells).
|
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 $$$8$$$, inclusive.
|
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*31..11\r\n..111..111\r\n.......1*1\r\n.......111\r\n", "output": "YES"}, {"input": "10 17\r\n12*2*22123*31....\r\n2*333*3*4***3211.\r\n*22*213**4***3*1.\r\n11111.12224*6*21.\r\n221..111.14**4311\r\n**2233*212****2*1\r\n*55***4*13*544421\r\n2***54*322*21**31\r\n13*4*33*221114*4*\r\n.1122*22*1...2*31\r\n", "output": "YES"}, {"input": "10 10\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n******3***\r\n**********\r\n**********\r\n**********\r\n***3.5****\r\n", "output": "NO"}, {"input": "21 10\r\n62637783*1\r\n23*51**531\r\n35*7*6.**.\r\n.*3***581*\r\n2.32*745**\r\n83*7*6*6*5\r\n*74.**6**3\r\n323*6**7*6\r\n3454*67.*1\r\n**63265*6*\r\n3725*4553*\r\n24****5**4\r\n23.34****4\r\n55257*1*4*\r\n4*3253*456\r\n**.3*45488\r\n*7318**4*5\r\n234.*4557*\r\n12..21*.*3\r\n286.225*4*\r\n834*11*.3*\r\n", "output": "NO"}, {"input": "10 10\r\n**********\r\n*********6\r\n*********5\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n**********\r\n", "output": "NO"}, {"input": "100 1\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n1\r\n1\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n*\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n1\r\n*\r\n2\r\n*\r\n1\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n.\r\n", "output": "YES"}, {"input": "1 100\r\n*************5****5****************************************************4****************************\r\n", "output": "NO"}, {"input": "1 100\r\n..1*1..........................1*1....1*1....1*1.1*1....1*1..1**1........................1**1.......\r\n", "output": "YES"}, {"input": "1 100\r\n.....1*1........1*1................................1*1...1**11*1.......1*1....1.....1*1.....1*1...1*\r\n", "output": "NO"}, {"input": "1 10\r\n881111882*\r\n", "output": "NO"}, {"input": "5 5\r\n*2221\r\n24**2\r\n*3*5*\r\n3425*\r\n**12*\r\n", "output": "NO"}, {"input": "5 5\r\n****2\r\n4***4\r\n3****\r\n3*563\r\n*22**\r\n", "output": "NO"}, {"input": "5 5\r\n***2.\r\n5**31\r\n**6**\r\n***43\r\n**31*\r\n", "output": "NO"}, {"input": "5 5\r\n*32**\r\n4*3*4\r\n**44*\r\n**45*\r\n*4***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n*2*\r\n***\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "1 2\r\n*1\r\n", "output": "YES"}, {"input": "1 2\r\n*2\r\n", "output": "NO"}, {"input": "2 2\r\n32\r\n**\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n232\r\n***\r\n", "output": "YES"}, {"input": "3 2\r\n..\r\n11\r\n.*\r\n", "output": "NO"}, {"input": "2 3\r\n1*2\r\n3*2\r\n", "output": "NO"}, {"input": "1 3\r\n.*.\r\n", "output": "NO"}, {"input": "3 1\r\n.\r\n*\r\n.\r\n", "output": "NO"}, {"input": "3 1\r\n1\r\n*\r\n1\r\n", "output": "YES"}, {"input": "3 1\r\n*\r\n1\r\n*\r\n", "output": "NO"}, {"input": "1 3\r\n1**\r\n", "output": "YES"}, {"input": "1 1\r\n8\r\n", "output": "NO"}, {"input": "1 1\r\n.\r\n", "output": "YES"}, {"input": "1 2\r\n2*\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n2\r\n", "output": "NO"}, {"input": "2 1\r\n*\r\n*\r\n", "output": "YES"}, {"input": "2 1\r\n.\r\n1\r\n", "output": "NO"}, {"input": "1 3\r\n..1\r\n", "output": "NO"}, {"input": "3 3\r\n...\r\n.*.\r\n...\r\n", "output": "NO"}, {"input": "3 3\r\n112\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n11.\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n151\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n1.1\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n611\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n.11\r\n1*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n2*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n**1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n5*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n.*1\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n411\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n.11\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n121\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n1.1\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n115\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*1\r\n11.\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*4\r\n111\r\n", "output": "NO"}, {"input": "3 3\r\n111\r\n1*.\r\n111\r\n", "output": "NO"}, {"input": "1 4\r\n*222\r\n", "output": "NO"}, {"input": "1 1\r\n*\r\n", "output": "YES"}, {"input": "2 2\r\n**\r\n**\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*.*\r\n***\r\n", "output": "NO"}, {"input": "3 3\r\n***\r\n***\r\n***\r\n", "output": "YES"}, {"input": "3 3\r\n***\r\n*4*\r\n***\r\n", "output": "NO"}, {"input": "2 6\r\n....1.\r\n.....*\r\n", "output": "NO"}, {"input": "5 5\r\n*****\r\n*****\r\n*****\r\n*****\r\n*****\r\n", "output": "YES"}, {"input": "4 1\r\n.\r\n*\r\n.\r\n.\r\n", "output": "NO"}, {"input": "2 2\r\n2*\r\n11\r\n", "output": "NO"}, {"input": "3 3\r\n888\r\n888\r\n888\r\n", "output": "NO"}, {"input": "1 4\r\n*22*\r\n", "output": "NO"}]
| 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 online(line, a):
x0, y0 = a
if line[0]:
return x0==line[1]
else:
C, slope, inter = line
return slope*x0+inter==y0
def process(A):
n = len(A)
if n <= 3:
return 'YES'
l1 = line(A[0], A[1])
l2 = line(A[1], A[2])
l3 = line(A[0], A[2])
for Line1 in [l1, l2, l3]:
other = []
for x in A:
if not online(Line1, x):
other.append(x)
if len(other) <= 2:
return 'YES'
a1 = other[0]
a2 = other[1]
Line2 = line(a1, a2)
works = True
for x in other:
if not online(Line2, x):
works = False
break
if works:
return 'YES'
return 'NO'
n = int(input())
A = []
for i in range(n):
x, y = [int(x) for x in input().split()]
A.append([x, y])
print(process(A))
| 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 import redirect_stdout
from itertools import *
from array import *
from functools import lru_cache
from types import GeneratorType
from heapq import *
from math import sqrt, gcd, inf
if sys.version >= '3.8': # ACW没有comb
from math import comb
RI = lambda: map(int, sys.stdin.buffer.readline().split())
RS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())
RILST = lambda: list(RI())
DEBUG = lambda *x: sys.stderr.write(f'{str(x)}\n')
MOD = 10 ** 9 + 7
PROBLEM = """https://codeforces.com/contest/961/problem/D
输入 n(≤1e5) 和 n 个点 (xi,yi),范围在 [-1e9,1e9],所有点都是不同的。
你能否画至多两条直线,覆盖所有点?输出 YES 或 NO。
输入
5
0 0
0 1
1 1
1 -1
2 2
输出 YES
输入
5
0 0
1 0
2 1
1 1
2 3
输出 NO
"""
"""
https://codeforces.com/contest/961/submission/190438603
提示 1:如果可以画,那么任意三点中必然有两个点在所画直线上。
提示 2:枚举前三个点中的两个点,确定一条直线,然后看其余点是否在一条直线上。
求导:
(y1-y2)/(x1-x2) == (y1-y3)/(x1-x3)
(y1-y2)(x1-x3) == (y1-y3)(x1-x2)
"""
# ms
def solve():
n, = RI()
ps = []
for _ in range(n):
ps.append(RILST())
if n <= 4:
return print('YES')
def f(ps):
(x1, y1), (x2, y2) = ps[:2]
other = []
for x3, y3 in ps[2:]:
if (y1 - y2) * (x1 - x3) != (y1 - y3) * (x1 - x2):
if len(other) < 2:
other.append((x3, y3))
else:
(a1, b1), (a2, b2) = other
if (b1 - b2) * (a1 - x3) != (b1 - y3) * (a1 - a2):
return False
return True
if f(ps):
return print('YES')
ps[:3] = ps[1:3] + ps[:1]
if f(ps):
return print('YES')
ps[:3] = ps[1:3] + ps[:1]
if f(ps):
return print('YES')
print('NO')
if __name__ == '__main__':
solve()
|
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\r\n10 5\r\n10 -2\r\n-2 -10\r\n-4 -9\r\n", "output": "YES\r\n"}, {"input": "5\r\n-10 3\r\n4 -5\r\n-9 5\r\n-5 -3\r\n-4 -6\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 9\r\n-1 -4\r\n-3 -8\r\n-4 8\r\n7 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n315 202\r\n315 203\r\n315 204\r\n-138 -298\r\n-136 -295\r\n-134 -292\r\n-132 -289\r\n-130 -286\r\n-128 -283\r\n-126 -280\r\n", "output": "YES\r\n"}, {"input": "10\r\n416 -473\r\n-162 491\r\n-164 488\r\n-170 479\r\n-166 485\r\n-172 476\r\n416 -475\r\n416 -474\r\n-168 482\r\n-160 494\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 1\r\n0 1\r\n1 0\r\n0 2\r\n2 0\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3\r\n6 3\r\n0 0\r\n10 0\r\n-10 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0\r\n1 0\r\n0 1\r\n0 2\r\n2 0\r\n3 0\r\n0 3\r\n0 4\r\n4 0\r\n0 -10000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 -1\r\n1 -1\r\n3 3\r\n2 0\r\n-2 -2\r\n1 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1000000000 1000000000\r\n999999999 999999999\r\n999999999 999999998\r\n-1000000000 1000000000\r\n-1000000000 999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n-1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 -1\r\n1 1\r\n1 -1\r\n2 -1\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n536870912 536870912\r\n268435456 368435456\r\n268435456 168435456\r\n1 3\r\n2 4\r\n3 5\r\n4 6\r\n5 7\r\n6 8\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n100 100\r\n100 99\r\n100 98\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n5 0\r\n7 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n1 1\r\n0 2\r\n5 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n0 0\r\n4 0\r\n1 1\r\n2 2\r\n3 1\r\n5 1\r\n6 2\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n2 2\r\n3 2\r\n4 1\r\n5 2\r\n6 1\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 0\r\n3 0\r\n0 1\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "12\r\n0 0\r\n1 1\r\n2 2\r\n3 3\r\n10 11\r\n20 11\r\n30 11\r\n40 11\r\n-1 1\r\n-2 2\r\n-3 3\r\n-4 4\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 0\r\n165580141 267914296\r\n331160282 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n433494437 701408733\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n229254610 -608716105\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-176884026 -737994048\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n5 0\r\n5 1\r\n5 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1 1\r\n1 0\r\n1 1\r\n1 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n0 0\r\n-1 -1\r\n1 0\r\n0 -1\r\n-1 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n8 8\r\n3303829 10\r\n10 1308\r\n4 2\r\n6 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n0 2\r\n0 3\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n165580142 267914296\r\n331160283 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n", "output": "YES\r\n"}, {"input": "59\r\n1 0\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n6 0\r\n7 0\r\n8 0\r\n9 0\r\n10 0\r\n0 11\r\n12 0\r\n13 0\r\n14 0\r\n15 0\r\n0 16\r\n0 17\r\n18 0\r\n19 0\r\n20 0\r\n21 0\r\n0 22\r\n23 0\r\n24 0\r\n0 25\r\n26 0\r\n27 0\r\n0 28\r\n0 29\r\n30 0\r\n31 0\r\n0 32\r\n33 0\r\n34 0\r\n0 35\r\n0 36\r\n37 0\r\n0 38\r\n39 0\r\n40 0\r\n0 41\r\n42 0\r\n0 43\r\n0 44\r\n0 45\r\n0 46\r\n47 0\r\n0 48\r\n0 49\r\n50 0\r\n0 51\r\n0 52\r\n53 0\r\n0 54\r\n55 0\r\n0 56\r\n57 0\r\n0 58\r\n59 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n10000000 40000100\r\n3 112\r\n2 400000100\r\n1 104\r\n1000000 701789036\r\n", "output": "YES\r\n"}, {"input": "5\r\n514 2131\r\n312 52362\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "YES\r\n"}, {"input": "9\r\n-65536 65536\r\n0 65536\r\n65536 65536\r\n-65536 0\r\n0 0\r\n65536 0\r\n-65536 -65536\r\n0 -65536\r\n65536 -65536\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 -7\r\n0 10000\r\n1 1000000000\r\n100 0\r\n200 0\r\n", "output": "NO\r\n"}, {"input": "7\r\n0 0\r\n2 2\r\n2 -2\r\n-2 2\r\n-2 -2\r\n0 1\r\n0 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 0\r\n4 1\r\n0 0\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-65536 -65536\r\n65536 0\r\n131072 0\r\n0 65536\r\n0 131072\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n2 0\r\n0 2\r\n0 -2\r\n-2 1\r\n-4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-133011126 -464171408\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n-1 0\r\n0 1\r\n-1 1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 -1\r\n0 -1\r\n-1 1\r\n-1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 1\r\n-1 0\r\n0 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n-1 1\r\n-1 0\r\n1 1\r\n-1 -1\r\n0 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 2\r\n-1 1\r\n2 1\r\n-2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n-1000000000 0\r\n999999999 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n0 0\r\n65536 65536\r\n65536 131072\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n999999999 1\r\n-1000000000 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n-1 1\r\n-1 -1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 -1\r\n3 -3\r\n1 2\r\n0 -2\r\n1 -3\r\n0 1\r\n0 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n-1 1\r\n-1 -1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n-1 1\r\n0 -1\r\n1 0\r\n-1 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n0 0\r\n-1 0\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "11\r\n-2 -2\r\n2 3\r\n3 -2\r\n1 -2\r\n2 -2\r\n2 0\r\n2 2\r\n-3 -2\r\n-1 -2\r\n2 -3\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 0\r\n-1 1\r\n1 0\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 -1\r\n0 0\r\n0 1\r\n-1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 1\r\n0 -2\r\n1 -1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-999999998 -999999998\r\n229254612 -608716103\r\n-588442011 -868997022\r\n-182303375 -739719079\r\n-176884024 -737994046\r\n", "output": "YES\r\n"}]
| 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:
e=1
f=slope(b,a[i])
g=0
break
else:
c.add(slope(b,a[i]))
if e!=1:
b=a[1]
c=set([])
e=0
for i in range(2,n):
if slope(b,a[i]) in c:
e=1
f=slope(b,a[i])
g=1
break
else:
c.add(slope(b,a[i]))
if e!=1:
b=a[2]
c=set([])
e=0
for i in range(3,n):
if slope(b,a[i]) in c:
e=1
f=slope(b,a[i])
g=2
break
else:
c.add(slope(b,a[i]))
if e!=1:
print("NO")
else:
vis=[0]*n
vis[g]=1
for i in range(n):
if vis[i]!=1:
if slope(a[i],a[g])==f:
vis[i]=1
if 0 in vis:
ind=vis.index(0)
c=set([])
for i in range(n):
if vis[i]==0 and i!=ind:
c.add(slope(a[i],a[ind]))
if len(c)<2:
print("YES")
else:
print("NO")
else:
print("YES")
| 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())) for _ in range(n)]
if n < 5:
ans = "YES"
else:
x1, y1 = xy[0]
x2, y2 = xy[1]
x3, y3 = xy[2]
if f(x1, y1, x2, y2, x3, y3):
c = []
for i in range(3, n):
xi, yi = xy[i]
if not f(x1, y1, x2, y2, xi, yi):
c.append((xi, yi))
if len(c) < 3:
ans = "YES"
else:
x1, y1 = c[0]
x2, y2 = c[1]
ans = "YES"
for i in range(2, len(c)):
xi, yi = c[i]
if not f(x1, y1, x2, y2, xi, yi):
ans = "NO"
break
else:
s = [0] * 3
c = []
for i in range(3, n):
xi, yi = xy[i]
if f(x1, y1, x2, y2, xi, yi):
s[0] = 1
elif f(x1, y1, x3, y3, xi, yi):
s[1] = 1
elif f(x2, y2, x3, y3, xi, yi):
s[2] = 1
else:
c.append((xi, yi))
if not c:
ans = "YES" if sum(s) < 3 else "NO"
else:
ans = "YES"
if sum(s) == 0:
x4, y4 = c[0]
x5, y5 = c[1]
if f(x1, y1, x4, y4, x5, y5):
x0, y0 = x1, y1
elif f(x2, y2, x4, y4, x5, y5):
x0, y0 = x2, y2
elif f(x3, y3, x4, y4, x5, y5):
x0, y0 = x3, y3
else:
ans = "NO"
if ans == "YES":
for i in range(2, len(c)):
xi, yi = c[i]
if not f(xi, yi, x4, y4, x5, y5):
ans = "NO"
break
elif sum(s) == 1:
ans = "YES"
if s[0] == 1:
x0, y0 = x3, y3
elif s[1] == 1:
x0, y0 = x2, y2
else:
x0, y0 = x1, y1
x4, y4 = c[0]
for i in range(1, len(c)):
xi, yi = c[i]
if not f(xi, yi, x4, y4, x0, y0):
ans = "NO"
break
else:
ans = "NO"
print(ans)
|
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\r\n10 5\r\n10 -2\r\n-2 -10\r\n-4 -9\r\n", "output": "YES\r\n"}, {"input": "5\r\n-10 3\r\n4 -5\r\n-9 5\r\n-5 -3\r\n-4 -6\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 9\r\n-1 -4\r\n-3 -8\r\n-4 8\r\n7 2\r\n", "output": "NO\r\n"}, {"input": "10\r\n315 202\r\n315 203\r\n315 204\r\n-138 -298\r\n-136 -295\r\n-134 -292\r\n-132 -289\r\n-130 -286\r\n-128 -283\r\n-126 -280\r\n", "output": "YES\r\n"}, {"input": "10\r\n416 -473\r\n-162 491\r\n-164 488\r\n-170 479\r\n-166 485\r\n-172 476\r\n416 -475\r\n416 -474\r\n-168 482\r\n-160 494\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 1\r\n0 1\r\n1 0\r\n0 2\r\n2 0\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3\r\n6 3\r\n0 0\r\n10 0\r\n-10 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0\r\n1 0\r\n0 1\r\n0 2\r\n2 0\r\n3 0\r\n0 3\r\n0 4\r\n4 0\r\n0 -10000000\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n1 1\r\n1 2\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 -1\r\n1 -1\r\n3 3\r\n2 0\r\n-2 -2\r\n1 -2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1000000000 1000000000\r\n999999999 999999999\r\n999999999 999999998\r\n-1000000000 1000000000\r\n-1000000000 999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n-1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 -1\r\n1 1\r\n1 -1\r\n2 -1\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n0 1\r\n1 0\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n536870912 536870912\r\n268435456 368435456\r\n268435456 168435456\r\n1 3\r\n2 4\r\n3 5\r\n4 6\r\n5 7\r\n6 8\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n100 100\r\n100 99\r\n100 98\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 1\r\n1 1\r\n0 1\r\n6 0\r\n5 0\r\n7 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n2 0\r\n1 1\r\n0 2\r\n5 1\r\n", "output": "YES\r\n"}, {"input": "7\r\n0 0\r\n4 0\r\n1 1\r\n2 2\r\n3 1\r\n5 1\r\n6 2\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n2 2\r\n3 2\r\n4 1\r\n5 2\r\n6 1\r\n", "output": "YES\r\n"}, {"input": "8\r\n0 0\r\n1 0\r\n2 0\r\n3 0\r\n0 1\r\n1 1\r\n2 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "12\r\n0 0\r\n1 1\r\n2 2\r\n3 3\r\n10 11\r\n20 11\r\n30 11\r\n40 11\r\n-1 1\r\n-2 2\r\n-3 3\r\n-4 4\r\n", "output": "NO\r\n"}, {"input": "6\r\n0 0\r\n165580141 267914296\r\n331160282 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n433494437 701408733\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n229254610 -608716105\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-176884026 -737994048\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n0 2\r\n5 0\r\n5 1\r\n5 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1 1\r\n1 0\r\n1 1\r\n1 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n229254610 -608716105\r\n-588442013 -868997024\r\n-182303377 -739719081\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 1\r\n0 0\r\n-1 -1\r\n1 0\r\n0 -1\r\n-1 -10\r\n", "output": "NO\r\n"}, {"input": "5\r\n8 8\r\n3303829 10\r\n10 1308\r\n4 2\r\n6 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 0\r\n0 1\r\n0 2\r\n0 3\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n165580142 267914296\r\n331160283 535828592\r\n267914296 433494437\r\n535828592 866988874\r\n", "output": "YES\r\n"}, {"input": "59\r\n1 0\r\n0 2\r\n0 3\r\n0 4\r\n0 5\r\n6 0\r\n7 0\r\n8 0\r\n9 0\r\n10 0\r\n0 11\r\n12 0\r\n13 0\r\n14 0\r\n15 0\r\n0 16\r\n0 17\r\n18 0\r\n19 0\r\n20 0\r\n21 0\r\n0 22\r\n23 0\r\n24 0\r\n0 25\r\n26 0\r\n27 0\r\n0 28\r\n0 29\r\n30 0\r\n31 0\r\n0 32\r\n33 0\r\n34 0\r\n0 35\r\n0 36\r\n37 0\r\n0 38\r\n39 0\r\n40 0\r\n0 41\r\n42 0\r\n0 43\r\n0 44\r\n0 45\r\n0 46\r\n47 0\r\n0 48\r\n0 49\r\n50 0\r\n0 51\r\n0 52\r\n53 0\r\n0 54\r\n55 0\r\n0 56\r\n57 0\r\n0 58\r\n59 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n10000000 40000100\r\n3 112\r\n2 400000100\r\n1 104\r\n1000000 701789036\r\n", "output": "YES\r\n"}, {"input": "5\r\n514 2131\r\n312 52362\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "YES\r\n"}, {"input": "9\r\n-65536 65536\r\n0 65536\r\n65536 65536\r\n-65536 0\r\n0 0\r\n65536 0\r\n-65536 -65536\r\n0 -65536\r\n65536 -65536\r\n", "output": "NO\r\n"}, {"input": "5\r\n0 -7\r\n0 10000\r\n1 1000000000\r\n100 0\r\n200 0\r\n", "output": "NO\r\n"}, {"input": "7\r\n0 0\r\n2 2\r\n2 -2\r\n-2 2\r\n-2 -2\r\n0 1\r\n0 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 0\r\n4 1\r\n0 0\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-65536 -65536\r\n65536 0\r\n131072 0\r\n0 65536\r\n0 131072\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n1 0\r\n0 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n2 0\r\n0 2\r\n0 -2\r\n-2 1\r\n-4 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-133011126 -464171408\r\n", "output": "YES\r\n"}, {"input": "5\r\n-1000000000 -1000000000\r\n134903170 -298591267\r\n-566505563 -732085704\r\n-298591267 -566505563\r\n-999999999 -999999999\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n-1 0\r\n0 1\r\n-1 1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 -1\r\n0 -1\r\n-1 1\r\n-1 0\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 1\r\n-1 0\r\n0 -1\r\n-1 -1\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n-1 1\r\n-1 0\r\n1 1\r\n-1 -1\r\n0 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n-1 2\r\n-1 1\r\n2 1\r\n-2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n-1000000000 0\r\n999999999 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n0 0\r\n65536 65536\r\n65536 131072\r\n", "output": "NO\r\n"}, {"input": "6\r\n-1 -1\r\n-1 -2\r\n-1 -3\r\n1000000000 1\r\n999999999 1\r\n-1000000000 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n-1 1\r\n-1 -1\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "7\r\n1 -1\r\n3 -3\r\n1 2\r\n0 -2\r\n1 -3\r\n0 1\r\n0 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n0 0\r\n-1 1\r\n-1 -1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "6\r\n0 0\r\n0 1\r\n-1 1\r\n0 -1\r\n1 0\r\n-1 -1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1\r\n0 0\r\n-1 0\r\n0 1\r\n1 0\r\n", "output": "YES\r\n"}, {"input": "11\r\n-2 -2\r\n2 3\r\n3 -2\r\n1 -2\r\n2 -2\r\n2 0\r\n2 2\r\n-3 -2\r\n-1 -2\r\n2 -3\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n-1 0\r\n-1 1\r\n1 0\r\n1 -1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 -1\r\n0 0\r\n0 1\r\n-1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n0 0\r\n1 1\r\n0 -2\r\n1 -1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n-999999998 -999999998\r\n229254612 -608716103\r\n-588442011 -868997022\r\n-182303375 -739719079\r\n-176884024 -737994046\r\n", "output": "YES\r\n"}]
| 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 + rem - 10))
else:
ans.append(str(rem))
num //= b
print(*ans[::-1], sep='')
else:
ans = []
ans.append('M' * (num // 1000))
num %= 1000
if num >= 500:
if num >= 900:
ans.append('CM')
num -= 900
else:
ans.append('D' + 'C' * ((num - 500) // 100))
num %= 100
if num >= 100:
if num >= 400:
ans.append('CD')
num -= 400
else:
ans.append('C' * (num // 100))
num %= 100
if num >= 50:
if num >= 90:
ans.append('XC')
num -= 90
else:
ans.append('L' + 'X' * ((num - 50) // 10))
num %= 10
if num >= 10:
if num >= 40:
ans.append('XL')
num -= 40
else:
ans.append('X' * (num // 10))
num %= 10
if num >= 5:
if num >= 9:
ans.append('IX')
num -= 9
else:
ans.append('V' + 'I' * (num - 5))
num = 0
if num > 0:
if num == 4:
ans.append('IV')
else:
ans.append('I' * num)
print(*ans, sep='')
| 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(system_2)
while integer != 0:
if system_2 < 10:
digits.append(str(integer%system_2))
else:
if integer%system_2 < 10: digits.append(str(integer%system_2))
else: digits.append(alphabet[integer%system_2 - 10])
integer = integer//system_2
print(''.join(digits[::-1]))
else:
roman = [1000,'M',900,'CM',500,'D',400,'CD',100,'C',90,'XC',50,'L',40,'XL',10,'X',9,'IX',5,'V',4,'IV',1,'I']
ans = ""
while integer != 0:
for i in range(len(roman)//2):
if integer>=roman[2*i]:
ans = ans + roman[2*i + 1]
integer = integer - roman[2*i]
break
print(ans)
|
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 captured by Shapur and Shapur is now going to capture Valerian, the Roman emperor.
Being defeated, the cowardly Valerian hid in a room at the top of one of his castles. To capture him, Shapur has to open many doors. Fortunately Valerian was too scared to make impenetrable locks for the doors.
Each door has 4 parts. The first part is an integer number a. The second part is either an integer number b or some really odd sign which looks like R. The third one is an integer c and the fourth part is empty! As if it was laid for writing something. Being extremely gifted, after opening the first few doors, Shapur found out the secret behind the locks.
c is an integer written in base a, to open the door we should write it in base b. The only bad news is that this R is some sort of special numbering system that is used only in Roman empire, so opening the doors is not just a piece of cake!
Here's an explanation of this really weird number system that even doesn't have zero:
Roman numerals are based on seven symbols: a stroke (identified with the letter I) for a unit, a chevron (identified with the letter V) for a five, a cross-stroke (identified with the letter X) for a ten, a C (identified as an abbreviation of Centum) for a hundred, etc.:
- I=1
- V=5
- X=10
- L=50
- C=100
- D=500
- M=1000
Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1, 000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I 1, II 2, III 3, V 5, VI 6, VII 7, etc., and the same for other bases: X 10, XX 20, XXX 30, L 50, LXXX 80; CC 200, DCC 700, etc. At the fourth and ninth iteration, a subtractive principle must be employed, with the base placed before the higher base: IV 4, IX 9, XL 40, XC 90, CD 400, CM 900.
Also in bases greater than 10 we use A for 10, B for 11, etc.
Help Shapur capture Valerian and bring peace back to Persia, especially Armenia.
|
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 included the number would be less than or equal to 300010 and it won't be 0. In any other case the number won't be greater than 101510.
|
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\nABG\r\n", "output": "3951\r\n"}, {"input": "17 10\r\nABACG\r\n", "output": "892363\r\n"}, {"input": "18 R\r\nGH\r\n", "output": "CCCV\r\n"}, {"input": "20 25\r\n4E32BB21D812\r\n", "output": "A2II7CL2HDM\r\n"}, {"input": "15 11\r\n760595A635B24\r\n", "output": "258AA2604713696\r\n"}, {"input": "10 22\r\n956512026633000\r\n", "output": "1E06A57IC4H2\r\n"}, {"input": "5 9\r\n1102101401441324123301\r\n", "output": "2733824152181178\r\n"}, {"input": "23 4\r\nDL5K6H78CAH\r\n", "output": "2003021332111213003322000\r\n"}, {"input": "18 R\r\n36E\r\n", "output": "MXCIV\r\n"}, {"input": "13 2\r\n1B579528314B30\r\n", "output": "10000001011010101001110000001110001011010111010010\r\n"}, {"input": "8 13\r\n20043013541570572\r\n", "output": "1B35CBA6B32102\r\n"}, {"input": "19 24\r\n1BH47I158EII\r\n", "output": "2NHBDL4ECN2\r\n"}, {"input": "14 19\r\n33BC51B817C55\r\n", "output": "1B573FFHHH12\r\n"}, {"input": "24 10\r\nE2E3EA6MJ05\r\n", "output": "894488519782085\r\n"}, {"input": "25 2\r\nIBGNAB3C0H\r\n", "output": "10000000001001000010100000111011000110101000001\r\n"}, {"input": "3 R\r\n2\r\n", "output": "II\r\n"}, {"input": "20 20\r\n3HBAH9JA9EDE\r\n", "output": "3HBAH9JA9EDE\r\n"}, {"input": "21 21\r\n2G3DK3F23905\r\n", "output": "2G3DK3F23905\r\n"}, {"input": "23 R\r\n57F\r\n", "output": "MMDCCCXXI\r\n"}, {"input": "16 6\r\n27774848D1D9F\r\n", "output": "10500345245142230115\r\n"}, {"input": "18 7\r\nD9D42E745C5A\r\n", "output": "351206225505021115\r\n"}, {"input": "11 R\r\n1A8A\r\n", "output": "MMDCXXXIX\r\n"}, {"input": "12 17\r\n567872838B15A5\r\n", "output": "105CA323BC110\r\n"}, {"input": "12 19\r\n78613621478844\r\n", "output": "71A1E1HB01EB\r\n"}, {"input": "12 25\r\n51B878A1B3A7B8\r\n", "output": "5JLBAF5JBEA\r\n"}, {"input": "12 R\r\n17BB\r\n", "output": "MMDCCCLXXIX\r\n"}, {"input": "20 R\r\nFI\r\n", "output": "CCCXVIII\r\n"}, {"input": "20 5\r\n1FAD98HHG13G\r\n", "output": "340143030243121422401\r\n"}, {"input": "19 12\r\nEHIAG4GG072\r\n", "output": "A33B813901970\r\n"}, {"input": "3 R\r\n2201120\r\n", "output": "MCMLXXXVI\r\n"}, {"input": "3 R\r\n10210211\r\n", "output": "MMDCCLXXVI\r\n"}, {"input": "3 R\r\n21222\r\n", "output": "CCXV\r\n"}, {"input": "11 22\r\n172A57412774400\r\n", "output": "11G8KLBCI95B\r\n"}, {"input": "17 4\r\n1509D9E003C5C\r\n", "output": "2223230302121200303102203\r\n"}, {"input": "2 R\r\n101110110111\r\n", "output": "MMCMXCIX\r\n"}, {"input": "25 R\r\n2JA\r\n", "output": "MDCCXXXV\r\n"}, {"input": "23 R\r\n3HK\r\n", "output": "MCMXCVIII\r\n"}, {"input": "10 22\r\n1000000000000000\r\n", "output": "1FE6KH3A0F7A\r\n"}, {"input": "10 2\r\n999999999999993\r\n", "output": "11100011010111111010100100110001100111111111111001\r\n"}, {"input": "4 21\r\n112233030100132210003330\r\n", "output": "5KIIKBEFE1G\r\n"}, {"input": "4 10\r\n112233030100132210003330\r\n", "output": "100000000000252\r\n"}, {"input": "4 5\r\n112233030100132210003330\r\n", "output": "101101400000000002002\r\n"}, {"input": "2 R\r\n1\r\n", "output": "I\r\n"}, {"input": "13 15\r\n33BCA79805767B\r\n", "output": "7A924652EB469\r\n"}, {"input": "2 10\r\n0\r\n", "output": "0\r\n"}, {"input": "25 2\r\n0\r\n", "output": "0\r\n"}, {"input": "25 10\r\n001\r\n", "output": "1\r\n"}, {"input": "17 17\r\n00000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": "0\r\n"}, {"input": "10 R\r\n999\r\n", "output": "CMXCIX\r\n"}, {"input": "2 2\r\n0\r\n", "output": "0\r\n"}, {"input": "10 10\r\n100000000000\r\n", "output": "100000000000\r\n"}, {"input": "10 10\r\n0\r\n", "output": "0\r\n"}, {"input": "10 R\r\n900\r\n", "output": "CM\r\n"}, {"input": "10 11\r\n12345678912345\r\n", "output": "3A2A855993029\r\n"}, {"input": "10 2\r\n100000000000000\r\n", "output": "10110101111001100010000011110100100000000000000\r\n"}, {"input": "10 R\r\n1983\r\n", "output": "MCMLXXXIII\r\n"}, {"input": "2 R\r\n101110111000\r\n", "output": "MMM\r\n"}, {"input": "2 R\r\n101110111000\r\n", "output": "MMM\r\n"}, {"input": "10 11\r\n1000000000000000\r\n", "output": "26A6A368906563A\r\n"}, {"input": "10 R\r\n1137\r\n", "output": "MCXXXVII\r\n"}, {"input": "10 R\r\n100\r\n", "output": "C\r\n"}, {"input": "10 25\r\n12343456543435\r\n", "output": "35M8JNIJCA\r\n"}, {"input": "16 10\r\n0523456789ABC\r\n", "output": "90384742521532\r\n"}]
| 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 = 1
while i < n - 1:
j = i + 1
while j > 0 and data[j] > 0 and data[j - 1] > 0:
data[j] -= 1
data[j - 1] -= 1
data[j - 2] += 1
j -= 1
# print(1, data[:j])
normalize_backward(data, j)
# print(2, data[:j])
i += 1
return data
def main():
a = input()
b = input()
# a = "01010110010101011011"
# b = "01010101110101011100"
# a = "101011"
# b = "101100"
a = str().join(map(str, normalize(list(map(int, "0" + a)), len(a) + 1)))
b = str().join(map(str, normalize(list(map(int, "0" + b)), len(b) + 1)))
max_len = max(len(a), len(b))
a = a.zfill(max_len)
b = b.zfill(max_len)
# print(a)
# print(b)
if a < b:
print("<")
elif a > b:
print(">")
else:
print("=")
main()
| 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).lstrip('0')
a = clean(input())
b = clean(input())
#print(a)
#print(b)
if a == b:
print('=')
elif len(a) > len(b):
print('>')
elif len(a) < len(b):
print('<')
elif a > b: # now the length are equal
print('>')
else:
print('<')
|
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 system the number is a non-empty string containing 0's and 1's as digits. The decimal value of expression a0a1...an equals to $$\sum_{i=0}^{n} a_i \cdot q^{n-i}$$.
Soon Piegirl found out that this system doesn't have same properties that integer base systems do and some operations can not be performed on it. She wasn't able to come up with a fast way of comparing two numbers. She is asking for your help.
Given two numbers written in golden system notation, determine which of them has larger decimal value.
|
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 ≈ 2.618.
|
[{"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", "output": "<\r\n"}, {"input": "00\r\n1\r\n", "output": "<\r\n"}, {"input": "01\r\n010\r\n", "output": "<\r\n"}, {"input": "111\r\n00\r\n", "output": ">\r\n"}, {"input": "1100\r\n11\r\n", "output": ">\r\n"}, {"input": "0110\r\n001\r\n", "output": ">\r\n"}, {"input": "1111\r\n0110\r\n", "output": ">\r\n"}, {"input": "01010\r\n0011\r\n", "output": ">\r\n"}, {"input": "0\r\n1\r\n", "output": "<\r\n"}, {"input": "1\r\n0\r\n", "output": ">\r\n"}, {"input": "1\r\n1\r\n", "output": "=\r\n"}, {"input": "010000100010100000100010001000001100100010110000101010000010010011001111101101001\r\n001011100001110101111001100110001011011100000000100111011010010011010100101011111\r\n", "output": "=\r\n"}, {"input": "11111001000\r\n1011100100\r\n", "output": ">\r\n"}, {"input": "1001111010001100001010001010010010100010100011101101110011110101011000010111101100111000110110110010\r\n01111001101111100111111001110110100101001111010001000000001001001111100101101100001101111111100111101\r\n", "output": "<\r\n"}, {"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n0\r\n", "output": ">\r\n"}, {"input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n1\r\n", "output": ">\r\n"}, {"input": "1\r\n100000000000000000000000000000000000000000000000000\r\n", "output": "<\r\n"}, {"input": "1\r\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": "<\r\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n1111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": ">\r\n"}, {"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n100000000000000000000\r\n", "output": ">\r\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n1011111111111111111111111111011011011001101111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": ">\r\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": "<\r\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n1011111111111111111111111111011011011001101111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": ">\r\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": "<\r\n"}, {"input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n0\r\n", "output": ">\r\n"}, {"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n1110\r\n", "output": ">\r\n"}, {"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n1000\r\n", "output": ">\r\n"}, {"input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n1000\r\n", "output": ">\r\n"}, {"input": "1\r\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": "<\r\n"}, {"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n0\r\n", "output": ">\r\n"}, {"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n10000\r\n", "output": ">\r\n"}, {"input": "10000100001000010000100001000010000100001000010000\r\n1\r\n", "output": ">\r\n"}, {"input": "101001010101010101010100101010101010101010101001010101010100101010101010100101101010100101010100101010101001010101010101010100101010101010101010101001010101010100101010101010100101101010100101010100101010101001010101010101010100101010101010101010101001010101010100101010101010100101101010100101010100101010\r\n1\r\n", "output": ">\r\n"}, {"input": "10100\r\n01011\r\n", "output": ">\r\n"}, {"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n01111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": "<\r\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n0000001010101011\r\n", "output": ">\r\n"}, {"input": "110010010101001001001010100100010101010101011111111111111010101000000000000000000010110111111110101010111111111111111111111111111111111\r\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": ">\r\n"}, {"input": "1100\r\n0111\r\n", "output": ">\r\n"}, {"input": "1111111111111111111111111111111111111111111111111\r\n0\r\n", "output": ">\r\n"}, {"input": "1100100101010010010010101001000101010101010111111111111110101010000000000000000000101101111111101010101111111111111111111111111111111\r\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n", "output": ">\r\n"}, {"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n100000000000000000000\r\n", "output": ">\r\n"}, {"input": "100001000010000100001000010000100001000010000100001111111111111111111111111111111111111111111111111111111111111111111111\r\n1\r\n", "output": ">\r\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111\r\n1\r\n", "output": ">\r\n"}, {"input": "1011\r\n0100\r\n", "output": ">\r\n"}, {"input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\r\n", "output": "<\r\n"}, {"input": "1000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000\r\n1111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": "<\r\n"}, {"input": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111001\r\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011\r\n", "output": ">\r\n"}, {"input": "1000000000000000000000000\r\n0101010101010101010101011\r\n", "output": "=\r\n"}, {"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n1\r\n", "output": ">\r\n"}, {"input": "101010101010101010101010101010101010101010101010101010101010101010101010\r\n1000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": "<\r\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n0\r\n", "output": ">\r\n"}, {"input": "111\r\n1000\r\n", "output": ">\r\n"}, {"input": "1000000000000000000000000000000000000000000000000\r\n000\r\n", "output": ">\r\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\r\n10\r\n", "output": ">\r\n"}, {"input": "111111111111111111111111111111111111111111111111\r\n11\r\n", "output": ">\r\n"}, {"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n000\r\n", "output": ">\r\n"}, {"input": "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\r\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n", "output": ">\r\n"}, {"input": "100000000000000000000000000000000000000000000000\r\n0\r\n", "output": ">\r\n"}]
| 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[i][0]
if a[g[0][1]-1] - a[g[0][0]] > d:
print('NO')
else:
print('YES')
| 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 and a[r] - d <= ai:
r += 1
l = i + k
if l <= r:
dp[l] += 1
dp[r + 1] -= 1
dp[i + 1] += dp[i]
ans = "YES" if dp[n] else "NO"
print(ans)
|
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 put all the mess in the pack in order. He has an infinite number of empty boxes to do this. He would like to fill some boxes in such a way that:
- Each pencil belongs to exactly one box;
- Each non-empty box has at least k pencils in it;
- If pencils i and j belong to the same box, then |ai - aj| ≤ d, where |x| means absolute value of x. Note that the opposite is optional, there can be pencils i and j such that |ai - aj| ≤ d and they belong to different boxes.
Help Mishka to determine if it's possible to distribute all the pencils into boxes. Print "YES" if there exists such a distribution. Otherwise print "NO".
|
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) — saturation of color of each pencil.
|
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 put the remaining ones into another box.
|
[{"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": "10 4 9\r\n47 53 33 48 35 51 18 47 33 11\r\n", "output": "NO\r\n"}, {"input": "3 2 76\r\n44 5 93\r\n", "output": "NO\r\n"}, {"input": "5 2 9\r\n3 8 9 14 20\r\n", "output": "YES\r\n"}, {"input": "8 2 3\r\n1 2 3 4 10 11 12 13\r\n", "output": "YES\r\n"}, {"input": "10 3 3\r\n1 1 2 4 5 6 9 10 11 12\r\n", "output": "YES\r\n"}, {"input": "7 3 3\r\n1 1 3 4 4 4 7\r\n", "output": "YES\r\n"}, {"input": "8 3 6\r\n1 2 3 3 4 7 11 11\r\n", "output": "YES\r\n"}, {"input": "12 3 2\r\n1 2 3 9 10 11 12 13 14 15 15 15\r\n", "output": "YES\r\n"}, {"input": "7 3 3\r\n1 2 3 4 4 5 5\r\n", "output": "YES\r\n"}, {"input": "9 3 3\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "5 2 3\r\n5 7 7 7 10\r\n", "output": "YES\r\n"}, {"input": "5 2 7\r\n1 3 4 5 10\r\n", "output": "YES\r\n"}, {"input": "16 2 2\r\n3 3 3 4 5 6 7 9 33 33 33 32 31 30 29 27\r\n", "output": "YES\r\n"}, {"input": "6 3 3\r\n1 2 3 4 5 6\r\n", "output": "YES\r\n"}, {"input": "3 2 15\r\n1 18 19\r\n", "output": "NO\r\n"}, {"input": "7 2 2\r\n1 2 3 4 5 6 7\r\n", "output": "YES\r\n"}, {"input": "6 3 3\r\n2 2 2 4 7 7\r\n", "output": "YES\r\n"}, {"input": "8 3 3\r\n1 1 1 2 2 3 3 5\r\n", "output": "YES\r\n"}, {"input": "6 2 2\r\n1 2 3 4 6 7\r\n", "output": "YES\r\n"}, {"input": "4 2 3\r\n1 2 3 6\r\n", "output": "YES\r\n"}, {"input": "10 4 28\r\n5 5 6 6 30 30 32 33 50 55\r\n", "output": "YES\r\n"}, {"input": "8 3 6\r\n1 2 3 3 7 4 11 11\r\n", "output": "YES\r\n"}, {"input": "6 3 2\r\n1 2 3 3 4 5\r\n", "output": "YES\r\n"}, {"input": "10 3 3\r\n1 2 3 3 3 3 3 3 3 5\r\n", "output": "YES\r\n"}, {"input": "1 1 1\r\n1\r\n", "output": "YES\r\n"}, {"input": "6 3 4\r\n1 2 3 4 6 7\r\n", "output": "YES\r\n"}, {"input": "6 3 3\r\n1 1 4 3 3 6\r\n", "output": "YES\r\n"}, {"input": "6 3 2\r\n1 2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "4 2 12\r\n10 16 22 28\r\n", "output": "YES\r\n"}, {"input": "9 3 1\r\n1 2 2 2 2 3 4 4 5\r\n", "output": "YES\r\n"}, {"input": "6 2 2\r\n2 3 4 5 6 8\r\n", "output": "YES\r\n"}, {"input": "10 4 15\r\n20 16 6 16 13 11 13 1 12 16\r\n", "output": "YES\r\n"}, {"input": "18 2 86\r\n665 408 664 778 309 299 138 622 229 842 498 389 140 976 456 265 963 777\r\n", "output": "YES\r\n"}, {"input": "6 2 1\r\n1 1 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "10 4 7\r\n4 3 6 5 4 3 1 8 10 5\r\n", "output": "YES\r\n"}, {"input": "4 2 100\r\n1 2 3 200\r\n", "output": "NO\r\n"}, {"input": "6 3 3\r\n1 1 1 1 1 5\r\n", "output": "NO\r\n"}, {"input": "10 3 3\r\n1 1 1 2 2 5 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "11 3 4\r\n1 1 1 5 5 5 10 12 14 16 18\r\n", "output": "NO\r\n"}, {"input": "4 2 1\r\n1 1 2 3\r\n", "output": "YES\r\n"}, {"input": "7 3 3\r\n6 8 9 10 12 13 14\r\n", "output": "NO\r\n"}, {"input": "6 3 3\r\n1 2 3 4 7 8\r\n", "output": "NO\r\n"}, {"input": "13 2 86\r\n841 525 918 536 874 186 708 553 770 268 138 529 183\r\n", "output": "YES\r\n"}, {"input": "5 2 3\r\n1 2 3 4 100\r\n", "output": "NO\r\n"}, {"input": "5 2 3\r\n8 9 11 12 16\r\n", "output": "NO\r\n"}, {"input": "15 8 57\r\n40 36 10 6 17 84 57 9 55 37 63 75 48 70 53\r\n", "output": "NO\r\n"}, {"input": "10 3 1\r\n5 5 5 6 6 7 8 8 8 9\r\n", "output": "YES\r\n"}, {"input": "10 5 293149357\r\n79072863 760382815 358896034 663269192 233367425 32795628 837363300 46932461 179556769 763342555\r\n", "output": "NO\r\n"}, {"input": "7 3 3\r\n1 2 4 6 7 8 10\r\n", "output": "NO\r\n"}, {"input": "6 3 4\r\n1 1 3 5 8 10\r\n", "output": "NO\r\n"}, {"input": "14 2 75\r\n105 300 444 610 238 62 767 462 17 728 371 578 179 166\r\n", "output": "YES\r\n"}, {"input": "10 4 1\r\n2 2 2 3 3 10 10 10 11 11\r\n", "output": "YES\r\n"}, {"input": "18 3 1\r\n1 1 1 2 2 3 5 5 5 6 6 7 9 9 9 10 10 11\r\n", "output": "YES\r\n"}, {"input": "9 3 2\r\n1 2 2 3 4 5 6 7 7\r\n", "output": "YES\r\n"}, {"input": "8 4 5\r\n1 1 1 1 1 9 9 9\r\n", "output": "NO\r\n"}, {"input": "4 2 4\r\n9 1 2 3\r\n", "output": "NO\r\n"}, {"input": "10 3 0\r\n1 1 2 2 2 2 2 2 2 2\r\n", "output": "NO\r\n"}, {"input": "3 2 2\r\n6 7 7\r\n", "output": "YES\r\n"}, {"input": "3 2 257816048\r\n1 999999999 999999999\r\n", "output": "NO\r\n"}, {"input": "11 3 1\r\n1 1 2 2 3 3 3 4 4 5 5\r\n", "output": "YES\r\n"}]
| 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(map(int,input().split()))
s = [l[0]]
c =0
for i in range(1,n):
if(gcd(s[-1],l[i])>1):
s.append(1)
s.append(l[i])
c =c +1
else:
s.append(l[i])
print(c)
print(*s)
|
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 integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
|
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. Also the new array should be got from the original array a by adding k elements to it.
If there are multiple answers you can print any one of them.
| 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"}, {"input": "10\r\n26 723 970 13 422 968 875 329 234 983\r\n", "output": "2\r\n26 723 970 13 422 1 968 875 1 329 234 983\r\n"}, {"input": "10\r\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\r\n", "output": "7\r\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396\r\n"}, {"input": "100\r\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1\r\n", "output": "19\r\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1\r\n"}, {"input": "100\r\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917\r\n", "output": "38\r\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917\r\n"}, {"input": "5\r\n472882027 472882027 472882027 472882027 472882027\r\n", "output": "4\r\n472882027 1 472882027 1 472882027 1 472882027 1 472882027\r\n"}, {"input": "2\r\n1000000000 1000000000\r\n", "output": "1\r\n1000000000 1 1000000000\r\n"}, {"input": "2\r\n8 6\r\n", "output": "1\r\n8 1 6\r\n"}, {"input": "3\r\n100000000 1000000000 1000000000\r\n", "output": "2\r\n100000000 1 1000000000 1 1000000000\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n1 2 3 4 5\r\n"}, {"input": "20\r\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000\r\n", "output": "19\r\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000\r\n"}, {"input": "2\r\n223092870 23\r\n", "output": "1\r\n223092870 1 23\r\n"}, {"input": "2\r\n100000003 100000003\r\n", "output": "1\r\n100000003 1 100000003\r\n"}, {"input": "2\r\n999999937 999999937\r\n", "output": "1\r\n999999937 1 999999937\r\n"}, {"input": "4\r\n999 999999937 999999937 999\r\n", "output": "1\r\n999 999999937 1 999999937 999\r\n"}, {"input": "2\r\n999999929 999999929\r\n", "output": "1\r\n999999929 1 999999929\r\n"}, {"input": "2\r\n1049459 2098918\r\n", "output": "1\r\n1049459 1 2098918\r\n"}, {"input": "2\r\n352229 704458\r\n", "output": "1\r\n352229 1 704458\r\n"}, {"input": "2\r\n7293 4011\r\n", "output": "1\r\n7293 1 4011\r\n"}, {"input": "2\r\n5565651 3999930\r\n", "output": "1\r\n5565651 1 3999930\r\n"}, {"input": "2\r\n997 997\r\n", "output": "1\r\n997 1 997\r\n"}, {"input": "3\r\n9994223 9994223 9994223\r\n", "output": "2\r\n9994223 1 9994223 1 9994223\r\n"}, {"input": "2\r\n99999998 1000000000\r\n", "output": "1\r\n99999998 1 1000000000\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "2\r\n1000000000 1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n130471 130471\r\n", "output": "1\r\n130471 1 130471\r\n"}, {"input": "3\r\n1000000000 2 2\r\n", "output": "2\r\n1000000000 1 2 1 2\r\n"}, {"input": "2\r\n223092870 66526\r\n", "output": "1\r\n223092870 1 66526\r\n"}, {"input": "14\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449\r\n", "output": "10\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449\r\n"}, {"input": "2\r\n3996017 3996017\r\n", "output": "1\r\n3996017 1 3996017\r\n"}, {"input": "2\r\n999983 999983\r\n", "output": "1\r\n999983 1 999983\r\n"}, {"input": "2\r\n618575685 773990454\r\n", "output": "1\r\n618575685 1 773990454\r\n"}, {"input": "3\r\n9699690 3 7\r\n", "output": "1\r\n9699690 1 3 7\r\n"}, {"input": "2\r\n999999999 999999996\r\n", "output": "1\r\n999999999 1 999999996\r\n"}, {"input": "2\r\n99999910 99999910\r\n", "output": "1\r\n99999910 1 99999910\r\n"}, {"input": "12\r\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491\r\n", "output": "9\r\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491\r\n"}, {"input": "3\r\n999999937 999999937 999999937\r\n", "output": "2\r\n999999937 1 999999937 1 999999937\r\n"}, {"input": "2\r\n99839 99839\r\n", "output": "1\r\n99839 1 99839\r\n"}, {"input": "3\r\n19999909 19999909 19999909\r\n", "output": "2\r\n19999909 1 19999909 1 19999909\r\n"}, {"input": "4\r\n1 1000000000 1 1000000000\r\n", "output": "0\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n64006 64006\r\n", "output": "1\r\n64006 1 64006\r\n"}, {"input": "2\r\n1956955 1956955\r\n", "output": "1\r\n1956955 1 1956955\r\n"}, {"input": "3\r\n1 1000000000 1000000000\r\n", "output": "1\r\n1 1000000000 1 1000000000\r\n"}, {"input": "2\r\n982451707 982451707\r\n", "output": "1\r\n982451707 1 982451707\r\n"}, {"input": "2\r\n999999733 999999733\r\n", "output": "1\r\n999999733 1 999999733\r\n"}, {"input": "3\r\n999999733 999999733 999999733\r\n", "output": "2\r\n999999733 1 999999733 1 999999733\r\n"}, {"input": "2\r\n3257 3257\r\n", "output": "1\r\n3257 1 3257\r\n"}, {"input": "2\r\n223092870 181598\r\n", "output": "1\r\n223092870 1 181598\r\n"}, {"input": "3\r\n959919409 105935 105935\r\n", "output": "2\r\n959919409 1 105935 1 105935\r\n"}, {"input": "2\r\n510510 510510\r\n", "output": "1\r\n510510 1 510510\r\n"}, {"input": "3\r\n223092870 1000000000 1000000000\r\n", "output": "2\r\n223092870 1 1000000000 1 1000000000\r\n"}, {"input": "14\r\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000\r\n", "output": "11\r\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000\r\n"}, {"input": "7\r\n1 982451653 982451653 1 982451653 982451653 982451653\r\n", "output": "3\r\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653\r\n"}, {"input": "2\r\n100000007 100000007\r\n", "output": "1\r\n100000007 1 100000007\r\n"}, {"input": "3\r\n999999757 999999757 999999757\r\n", "output": "2\r\n999999757 1 999999757 1 999999757\r\n"}, {"input": "3\r\n99999989 99999989 99999989\r\n", "output": "2\r\n99999989 1 99999989 1 99999989\r\n"}, {"input": "5\r\n2 4 982451707 982451707 3\r\n", "output": "2\r\n2 1 4 982451707 1 982451707 3\r\n"}, {"input": "2\r\n20000014 20000014\r\n", "output": "1\r\n20000014 1 20000014\r\n"}, {"input": "2\r\n99999989 99999989\r\n", "output": "1\r\n99999989 1 99999989\r\n"}, {"input": "2\r\n111546435 111546435\r\n", "output": "1\r\n111546435 1 111546435\r\n"}, {"input": "2\r\n55288874 33538046\r\n", "output": "1\r\n55288874 1 33538046\r\n"}, {"input": "5\r\n179424673 179424673 179424673 179424673 179424673\r\n", "output": "4\r\n179424673 1 179424673 1 179424673 1 179424673 1 179424673\r\n"}, {"input": "2\r\n199999978 199999978\r\n", "output": "1\r\n199999978 1 199999978\r\n"}, {"input": "2\r\n1000000000 2\r\n", "output": "1\r\n1000000000 1 2\r\n"}, {"input": "3\r\n19999897 19999897 19999897\r\n", "output": "2\r\n19999897 1 19999897 1 19999897\r\n"}, {"input": "2\r\n19999982 19999982\r\n", "output": "1\r\n19999982 1 19999982\r\n"}, {"input": "2\r\n10000007 10000007\r\n", "output": "1\r\n10000007 1 10000007\r\n"}, {"input": "3\r\n999999937 999999937 2\r\n", "output": "1\r\n999999937 1 999999937 2\r\n"}, {"input": "5\r\n2017 2017 2017 2017 2017\r\n", "output": "4\r\n2017 1 2017 1 2017 1 2017 1 2017\r\n"}, {"input": "2\r\n19999909 39999818\r\n", "output": "1\r\n19999909 1 39999818\r\n"}, {"input": "2\r\n62615533 7919\r\n", "output": "1\r\n62615533 1 7919\r\n"}, {"input": "5\r\n39989 39989 33 31 29\r\n", "output": "1\r\n39989 1 39989 33 31 29\r\n"}, {"input": "2\r\n1000000000 100000\r\n", "output": "1\r\n1000000000 1 100000\r\n"}, {"input": "2\r\n1938 10010\r\n", "output": "1\r\n1938 1 10010\r\n"}, {"input": "2\r\n199999 199999\r\n", "output": "1\r\n199999 1 199999\r\n"}, {"input": "2\r\n107273 107273\r\n", "output": "1\r\n107273 1 107273\r\n"}, {"input": "3\r\n49999 49999 49999\r\n", "output": "2\r\n49999 1 49999 1 49999\r\n"}, {"input": "2\r\n1999966 1999958\r\n", "output": "1\r\n1999966 1 1999958\r\n"}, {"input": "2\r\n86020 300846\r\n", "output": "1\r\n86020 1 300846\r\n"}, {"input": "2\r\n999999997 213\r\n", "output": "1\r\n999999997 1 213\r\n"}, {"input": "2\r\n200000014 200000434\r\n", "output": "1\r\n200000014 1 200000434\r\n"}]
| false
|
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# 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) as f:
lines = f.readlines()
if len(lines) < 2:
print(0)
return
try:
k_sub = int(lines[0].strip())
array_sub = list(map(int, lines[1].strip().split()))
except:
print(0)
return
# Check array_sub length
if len(array_sub) != n + k_sub:
print(0)
return
# Read reference output's k_ref
with open(output_path) as f:
k_ref = int(f.readline().strip())
# Check k_sub equals k_ref
if k_sub != k_ref:
print(0)
return
# Check original array is a subsequence of array_sub
i = 0
for num in array_sub:
if i < len(a) and num == a[i]:
i += 1
if i != len(a):
print(0)
return
# Check all adjacent pairs are coprime
for j in range(len(array_sub)-1):
x = array_sub[j]
y = array_sub[j+1]
if math.gcd(x, y) != 1:
print(0)
return
# All checks passed
print(1)
if __name__ == "__main__":
main()
| 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
flag=True
if(flag):
mini=sum
if(sum>maxi and not flag):
maxi=sum
matrix.append(row)
matrix[x][y] = maxi - mini
if(matrix[x][y]==0):
print(1)
return
if(mini>maxi):
print(-1)
return
# check sums of rows
for i in range(n):
res = 0
for j in range(n):
res += matrix[i][j]
if(res!=maxi):
print(-1)
return
# check sum of colmuns
for i in range(n):
res = 0
for j in range(n):
res += matrix[j][i]
if(res!=maxi):
print(-1)
return
# check sums of dialong right
res = 0
for i in range(n):
for j in range(n):
if(i==j):
res += matrix[i][j]
if(res!=maxi):
print(-1)
return
# check sums of dialong left
res = 0
for i in range(n):
for j in range(n):
if(n-i-1==j):#3-0-1=2 3-1-1=1 3-2-1=0
res += matrix[i][j]
if(res!=maxi):
print(-1)
return
print(matrix[x][y])# answer
if __name__=='__main__':
main()
| 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):
if a[i][j] == 0:
a[i][j] = ans = max(su - sum(a[i]), 1)
dis.add(sum(a[i]))
for i in range(n):
dis.add(sum(get_col(a, i)))
dis.update({sum([a[i][i] for i in range(n)]), sum([a[i][n - i - 1] for i in range(n)])})
print(ans if len(dis) == 1 else -1)
|
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 random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid ($$\sum_{r,i}a_{r,i}$$), each column of the grid ($$\sum_{i,c}a_{i,c}$$), and the two long diagonals of the grid (the main diagonal — $$\sum_{i}a_{i,i}$$ and the secondary diagonal — $$\sum_{i}a_{i,n-i+1}$$) are equal.
Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible?
|
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 the corresponding cell is empty, ai, j will be equal to 0. Otherwise, ai, j is positive.
It is guaranteed that there is exactly one pair of integers i, j (1 ≤ i, j ≤ n) such that ai, j = 0.
|
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 + 5 + 6 = 2 + 5 + 8 = 15.
In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square.
|
[{"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 40\r\n17 42 24 49 0 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "76\r\n"}, {"input": "4\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n1000000000 1000000000 0 1000000000\r\n1000000000 1000000000 1000000000 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 8 1\r\n2 4 6\r\n7 0 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 6 10\r\n5 6 16\r\n0 5 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n0 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n2 2 1\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "3\r\n2016 2016 2016\r\n2016 0 2016\r\n2016 2016 2016\r\n", "output": "2016\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 0 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "9\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 40\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 0 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "88\r\n"}, {"input": "3\r\n2 2 1\r\n1 2 2\r\n2 1 0\r\n", "output": "-1\r\n"}, {"input": "10\r\n92 67 99 74 1 51 8 58 15 0\r\n17 42 24 49 76 26 83 33 90 65\r\n98 73 80 55 7 57 14 64 16 41\r\n23 48 5 30 82 32 89 39 91 66\r\n4 54 81 56 88 63 20 70 22 47\r\n79 29 6 31 13 38 95 45 97 72\r\n85 60 87 62 19 69 21 71 3 28\r\n10 35 12 37 94 44 96 46 78 53\r\n86 61 93 68 25 75 2 52 9 34\r\n11 36 18 43 100 50 77 27 84 59\r\n", "output": "40\r\n"}, {"input": "4\r\n2 2 2 2\r\n2 0 2 2\r\n3 2 2 1\r\n2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 15 5\r\n11 7 3\r\n9 0 13\r\n", "output": "-1\r\n"}, {"input": "3\r\n61 0 41\r\n11 31 51\r\n21 71 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n3 0 3\r\n2 3 2\r\n2 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 2 2\r\n3 1 1\r\n1 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n1 1 2\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n2 1 2\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n4 1 4\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n2 0 1\r\n1 2 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 2\r\n3 1 1\r\n0 2 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n0 1 1 1\r\n1 1 1 1\r\n1 1 1 2\r\n1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 0 1\r\n1 1 1 1\r\n1 1 1 1\r\n1 2 1 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000\r\n0 1 1 1 1\r\n1 1000000000 1000000000 1000000000 1\r\n1 1000000000 1000000000 1 1000000000\r\n", "output": "2999999998\r\n"}, {"input": "3\r\n5 5 5\r\n6 5 0\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 0 1\r\n50 1 500\r\n2 1 2\r\n", "output": "-1\r\n"}, {"input": "9\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1 1 1 0 1 1 1 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\r\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "3\r\n7 22 1\r\n4 10 16\r\n19 0 13\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n1 1 1 1 0\r\n1 2 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n3 6 0 2\r\n5 5 7 1\r\n1 7 4 6\r\n2 9 1 6\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 1 1 1\r\n1 1 2 1 1\r\n2 1 1 0 1\r\n1 1 1 1 2\r\n1 1 1 2 1\r\n", "output": "-1\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 5 5 5 5 5 5 5\r\n5 5 5 5 13 1 1 5 5 5 5\r\n5 5 5 5 5 9 1 5 5 5 5\r\n5 5 5 5 0 5 13 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "2\r\n5 5\r\n5 0\r\n", "output": "5\r\n"}, {"input": "5\r\n10 10 1 10 10\r\n1 1 0 1 1\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n10 10 1 10 10\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 1 2 1\r\n1 1 1 1 1\r\n1 1 0 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n1000000000 1000000000 1000000000\r\n1000000000 0 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "3\r\n3 3 3\r\n0 2 5\r\n1 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 2 3 1\r\n1 0 3 3\r\n4 3 4 1\r\n1 2 3 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 2\r\n2 1 0\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n1 0\r\n", "output": "-1\r\n"}, {"input": "2\r\n0 535\r\n535 535\r\n", "output": "535\r\n"}, {"input": "6\r\n0 1 1 1 1 1\r\n1 1 1000000000 1000000000 1000000000 1000000000\r\n1 1000000000 1 1000000000 1000000000 1000000000\r\n1 1000000000 1000000000 1 1000000000 1000000000\r\n1 1000000000 1000000000 1000000000 1 1000000000\r\n1 1000000000 1000000000 1000000000 1000000000 1\r\n", "output": "3999999997\r\n"}, {"input": "4\r\n2 6 0 3\r\n5 5 7 1\r\n5 1 3 9\r\n6 6 1 5\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 1 2 1 2\r\n2 2 2 2 2\r\n2 2 0 2 2\r\n2 2 2 2 2\r\n2 2 2 2 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 3\r\n1 0 3\r\n1 2 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 2\r\n1 2 1\r\n2 1 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 3 2 3\r\n3 2 3 0\r\n2 4 2 2\r\n3 1 3 3\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 1 1\r\n1 4 1\r\n1 1 0\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n1 1 1 1 1\r\n1 1 1 0 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n0 1 1\r\n1 1 1\r\n1 1 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n1 0 1\r\n1 2 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n6 7 2\r\n1 0 9\r\n8 3 4\r\n", "output": "5\r\n"}, {"input": "3\r\n1 1 1\r\n1 1 1\r\n1 0 1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 6 0\r\n3 3 5\r\n5 2 4\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 2 2 2 1\r\n1 1 1 1 0\r\n2 2 1 2 1\r\n2 1 2 1 1\r\n1 2 2 2 1\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 1 1 1\r\n1 1 1 0\r\n1 1 2 1\r\n1 1 1 1\r\n", "output": "-1\r\n"}, {"input": "3\r\n13 0 19\r\n16 10 4\r\n1 22 7\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 2 2 1\r\n2 1 0 2\r\n2 1 1 2\r\n1 2 2 1\r\n", "output": "-1\r\n"}]
| 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] == '4'
i += 1
a = a[:-i+1] + '7' + '4' * (i - need - 1) + '7' * (need - 1)
return a
def n47(a):
ret = ''
g = len(a)
i = 0
for t in a:
if int(t) < 4:
ret += (g - i) * '4'
break
elif int(t) == 4:
ret += '4'
n4 = i
elif int(t) < 7:
ret += '7' + '4' * (g - i - 1)
break
elif int(t) == 7:
ret += '7'
else:
ret = ret[:n4] + '7' + '4' * (g - n4 - 1)
break
i += 1
return ret
def big(a):
global k
o = 1
for t in a:
if int(t) > 7 or (o > k // 2 and int(t) > 4):
return True
elif (int(t) < 7 and not (o > k // 2)) or (int(t) < 4 and (o > k // 2)):
return False
o += 1
return False
a = input()
k = len(a)
if k % 2 == 1:
print('4' * ((k + 1) // 2) + '7' * ((k + 1) // 2))
else:
if big(a):
print('4' * (k // 2 + 1) + '7' * (k // 2 + 1))
else:
a = n47(a)
print(nr47(a))
| 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
s+=1
flag=0
i=j
break
break
elif a[i]==7:
s+=1
elif a[i]>4:
a[i]=7
s+=1
if s<=l//2:
break
elif a[i]==4:
f+=1
else:
a[i]=4
f+=1
if f<=l//2:
break
if s>l//2:
flag=1
for j in range(i-1,-1,-1):
f-=1
if a[j]==7:
f+=1
if a[j-1]==4:
a[j-1]=7
f-=1
s+=1
flag=0
i=j-1
break
s-=1
break
elif f>l//2:
a[i]=7
s+=1
f-=1
break
if flag:
for i in range(l//2+1):
print(4,end='')
for i in range(l//2+1):
print(7,end='')
else:
for j in range(i+1):
print(a[j],end='')
for j in range(i+1,l):
if f<l//2:
print(4,end='')
f+=1
else:
print(7,end='')
|
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. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
|
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", "output": "4444477777"}, {"input": "49102094540227023300\r\n", "output": "74444444444777777777\r\n"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "777777\r\n", "output": "44447777"}, {"input": "99999999\r\n", "output": "4444477777"}, {"input": "474\r\n", "output": "4477"}, {"input": "85469\r\n", "output": "444777"}, {"input": "7474747\r\n", "output": "44447777"}, {"input": "2145226\r\n", "output": "44447777"}, {"input": "5556585\r\n", "output": "44447777"}, {"input": "87584777\r\n", "output": "4444477777"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "1000000000\r\n", "output": "4444477777\r\n"}, {"input": "999999999\r\n", "output": "4444477777"}, {"input": "74477744\r\n", "output": "74477744\r\n"}, {"input": "444444444\r\n", "output": "4444477777"}, {"input": "467549754\r\n", "output": "4444477777"}, {"input": "147474747\r\n", "output": "4444477777"}, {"input": "555\r\n", "output": "4477"}, {"input": "100000\r\n", "output": "444777\r\n"}, {"input": "74777443\r\n", "output": "74777444\r\n"}, {"input": "4700007\r\n", "output": "44447777"}, {"input": "70070077\r\n", "output": "74444777\r\n"}, {"input": "123\r\n", "output": "4477"}, {"input": "7474\r\n", "output": "7474\r\n"}, {"input": "3696\r\n", "output": "4477\r\n"}, {"input": "5594108733309806863211189515406929423407691887690557101598403485\r\n", "output": "7444444444444444444444444444444447777777777777777777777777777777\r\n"}, {"input": "7004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224\r\n", "output": "7444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777\r\n"}, {"input": "795193728547733389463100378996233822835539327235483308682350676991954960294227364128385843182064933115\r\n", "output": "44444444444444444444444444444444444444444444444444447777777777777777777777777777777777777777777777777777"}, {"input": "61136338618684683458627308377793588546921041456473994251912971721612136383004772112243903436104509483190819343988300672009142812305068378720235800534191119843225949741796417107434937387267716981006150\r\n", "output": "74444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777\r\n"}, {"input": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774744777447\r\n", "output": "47447774444477747744744477747744477774777774747474477744474447744447747777744777444474777477447777747477474774477444777777744774777474477744444474744777774744447747477747474447444444447444774747444444\r\n"}, {"input": "474777447477447774447777477444444747747747447474\r\n", "output": "474777447477447774447777477444444747747747447474\r\n"}, {"input": "35881905331681060827588553219538774024143083787975\r\n", "output": "44444444444444444444444447777777777777777777777777\r\n"}, {"input": "221020945402270233\r\n", "output": "444444444777777777\r\n"}, {"input": "241925018843248944336317949908388280315030601139576419352009710\r\n", "output": "4444444444444444444444444444444477777777777777777777777777777777"}, {"input": "888999577\r\n", "output": "4444477777"}, {"input": "10\r\n", "output": "47\r\n"}, {"input": "7\r\n", "output": "47"}, {"input": "50\r\n", "output": "74\r\n"}, {"input": "70\r\n", "output": "74\r\n"}, {"input": "74700\r\n", "output": "444777"}, {"input": "1024\r\n", "output": "4477\r\n"}, {"input": "73\r\n", "output": "74\r\n"}, {"input": "74710000\r\n", "output": "74744477\r\n"}, {"input": "444000000\r\n", "output": "4444477777"}, {"input": "4\r\n", "output": "47"}, {"input": "1\r\n", "output": "47"}, {"input": "9\r\n", "output": "47"}, {"input": "99\r\n", "output": "4477"}, {"input": "48\r\n", "output": "74\r\n"}, {"input": "4747474749\r\n", "output": "4747474774\r\n"}, {"input": "4747474774\r\n", "output": "4747474774\r\n"}, {"input": "77777777\r\n", "output": "4444477777"}, {"input": "4777\r\n", "output": "7447\r\n"}, {"input": "7748\r\n", "output": "444777"}, {"input": "7773\r\n", "output": "444777"}, {"input": "19\r\n", "output": "47\r\n"}, {"input": "447777\r\n", "output": "474477\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.