text stringlengths 216 39.6k | conversation_id int64 219 108k | embedding list | cluster int64 11 11 |
|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i.
Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
Constraints
* 1≦N≦10^5
* 0≦A_i≦N-1
Input
The input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the number of the possible orders in which they were standing, modulo 10^9+7.
Examples
Input
5
2 4 4 0 2
Output
4
Input
7
6 4 0 2 4 0 2
Output
0
Input
8
7 5 1 1 7 3 5 3
Output
16
Submitted Solution:
```
N = int(input())
A = list(map(int,input().split()))
d = N // 2
# ans = []
# def linking_up():
ans_1 = [ i for i in range(N) if A.count(i) == 2]
# for i in range(N):
# if i % 2 == 0 and i != 0:
# if A.count(i) == 2 and A.count(0) == 1:
# ans.append('c')
# ans_2 = [ i for i in range(N) if i % 2 and A.count(i) == 2]
# else:
# if A.count(i) == 2:
# ans.append('a')
# linking_up()
if len(ans_1) == d:
print(2 ** d)
else:
print(0)
```
No
| 89,125 | [
0.388671875,
-0.0618896484375,
-0.39794921875,
0.277099609375,
-0.373046875,
-0.448974609375,
0.023712158203125,
0.08251953125,
0.454833984375,
0.9677734375,
0.4296875,
-0.1954345703125,
0.12493896484375,
-0.5771484375,
-0.58251953125,
-0.217529296875,
-0.650390625,
-0.55712890625,... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a0 + a1x1 + ... + anxn. Numbers ai are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial.
Vasya has made a bet with his friends that he can solve any problem with polynomials. They suggested him the problem: "Determine how many polynomials P(x) exist with integer non-negative coefficients so that <image>, and <image>, where <image> and b are given positive integers"?
Vasya does not like losing bets, but he has no idea how to solve this task, so please help him to solve the problem.
Input
The input contains three integer positive numbers <image> no greater than 1018.
Output
If there is an infinite number of such polynomials, then print "inf" without quotes, otherwise print the reminder of an answer modulo 109 + 7.
Examples
Input
2 2 2
Output
2
Input
2 3 3
Output
1
Submitted Solution:
```
import sys
t, a, b = (map(int, input().split()))
if a == b:
if a == t:
if a == 1:
print("inf")
else:
print(2)
else:
print(1)
sys.exit(0)
if t == a:
print(0)
sys.exit(0)
c = (a - b) // (t - a)
if (a - b) % (t - a) == 0 and c >= 0 and a - c * t >= 0:
print(1)
sys.exit()
print(0)
```
No
| 89,670 | [
0.4970703125,
-0.039215087890625,
-0.25634765625,
-0.09735107421875,
-0.57958984375,
0.039306640625,
0.0716552734375,
0.321533203125,
-0.025634765625,
0.79541015625,
0.623046875,
-0.00476837158203125,
0.06549072265625,
-0.859375,
-0.379150390625,
0.1197509765625,
-0.360107421875,
-... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a0 + a1x1 + ... + anxn. Numbers ai are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial.
Vasya has made a bet with his friends that he can solve any problem with polynomials. They suggested him the problem: "Determine how many polynomials P(x) exist with integer non-negative coefficients so that <image>, and <image>, where <image> and b are given positive integers"?
Vasya does not like losing bets, but he has no idea how to solve this task, so please help him to solve the problem.
Input
The input contains three integer positive numbers <image> no greater than 1018.
Output
If there is an infinite number of such polynomials, then print "inf" without quotes, otherwise print the reminder of an answer modulo 109 + 7.
Examples
Input
2 2 2
Output
2
Input
2 3 3
Output
1
Submitted Solution:
```
import sys
t, a, b = (map(int, input().split()))
if a == b:
if a == t:
print(2)
else:
print(1)
sys.exit(0)
if t == a:
print(0)
sys.exit(0)
#if ((a - b) % (t - a) == 0 && c >= 0 && A - C * T >= )
c = (a - b) // (t - a)
if (a - b) % (t - a) == 0 and c >= 0 and a - c * t >= 0:
print(1)
sys.exit()
print(0)
```
No
| 89,672 | [
0.5458984375,
-0.048858642578125,
-0.268798828125,
-0.081787109375,
-0.56640625,
-0.01462554931640625,
0.033172607421875,
0.343505859375,
-0.016693115234375,
0.83984375,
0.580078125,
0.004894256591796875,
0.017852783203125,
-0.82861328125,
-0.366455078125,
0.1259765625,
-0.3198242187... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Example
Input
anagram
grandmother
Output
4
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
sa = [S() for _ in range(2)]
ml = min(map(len, sa))
ss = []
for s in sa:
a = [[0] * 26]
b = [set() for _ in range(ml)]
for c in s:
t = a[-1][:]
t[ord(c) - ord('a')] += 1
a.append(t)
for i in range(len(a)):
for j in range(i+1,len(a)):
if j - i > ml:
break
b[j-i-1].add(tuple(map(lambda x: a[j][x]-a[i][x], range(26))))
ss.append(b)
for i in range(ml-1,-1,-1):
if ss[0][i] & ss[1][i]:
return i + 1;
return 0
print(main())
```
No
| 90,055 | [
0.32861328125,
0.0263214111328125,
-0.0208587646484375,
0.020538330078125,
-0.8876953125,
-0.2161865234375,
-0.0667724609375,
0.22021484375,
0.0009236335754394531,
0.93994140625,
0.359375,
-0.2587890625,
0.054901123046875,
-0.44482421875,
-0.626953125,
0.006999969482421875,
-0.749511... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Example
Input
anagram
grandmother
Output
4
Submitted Solution:
```
print(4)
```
No
| 90,056 | [
0.701171875,
-0.0885009765625,
-0.218017578125,
0.040069580078125,
-0.8046875,
-0.591796875,
0.1343994140625,
0.55224609375,
-0.1361083984375,
0.489990234375,
0.4560546875,
0.06707763671875,
-0.0023937225341796875,
-0.276123046875,
-0.630859375,
-0.1712646484375,
-0.366455078125,
-... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Example
Input
anagram
grandmother
Output
4
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
mod2 = 10**9+9
sa = [S() for _ in range(2)]
ml = min(map(len, sa))
ss = []
for s in sa:
a = [0]
a2 = [0]
b = [set() for _ in range(ml)]
b2 = [set() for _ in range(ml)]
for c in s:
k = 97 ** (ord(c) - ord('a'))
a.append((a[-1] + k) % mod)
a2.append((a2[-1] + k) % mod2)
for i in range(len(a)):
for j in range(i+1,len(a)):
if j - i > ml:
break
b[j-i-1].add((a[j]-a[i]) % mod)
b2[j-i-1].add((a2[j]-a2[i]) % mod2)
ss.append([b,b2])
for i in range(ml-1,-1,-1):
if ss[0][0][i] & ss[1][0][i] and ss[0][1][i] & ss[1][1][i]:
return i + 1;
return 0
print(main())
```
No
| 90,057 | [
0.361083984375,
0.04345703125,
-0.00038933753967285156,
0.054595947265625,
-0.87646484375,
-0.25,
-0.038116455078125,
0.19140625,
-0.0260009765625,
0.91943359375,
0.364013671875,
-0.27685546875,
0.059326171875,
-0.46875,
-0.59228515625,
0.04156494140625,
-0.73876953125,
-0.72363281... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Example
Input
anagram
grandmother
Output
4
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
mod2 = 10**9+9
sa = [S() for _ in range(2)]
ml = min(map(len, sa))
ss = []
for s in sa:
a = [0]
a2 = [0]
b = [set() for _ in range(ml)]
b2 = [set() for _ in range(ml)]
for c in s:
k = 97 ** (ord(c) - ord('a'))
a.append((a[-1] + k) % mod)
a2.append((a2[-1] + k) % mod2)
for i in range(len(a)):
for j in range(i+1,len(a)):
if j - i > ml:
break
b[j-i-1].add(a[j]-a[i])
b2[j-i-1].add(a2[j]-a2[i])
ss.append([b,b2])
for i in range(ml-1,-1,-1):
if ss[0][0][i] & ss[1][0][i] and ss[0][1][i] & ss[1][1][i]:
return i + 1;
return 0
print(main())
```
No
| 90,058 | [
0.361083984375,
0.04345703125,
-0.00038933753967285156,
0.054595947265625,
-0.87646484375,
-0.25,
-0.038116455078125,
0.19140625,
-0.0260009765625,
0.91943359375,
0.364013671875,
-0.27685546875,
0.059326171875,
-0.46875,
-0.59228515625,
0.04156494140625,
-0.73876953125,
-0.72363281... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
if (solved * 2 > n):
value[i] = 500
elif (solved * 4 > n):
value[i] = 1000
elif (solved * 8 > n):
value[i] = 1500
elif (solved * 16 > n):
value[i] = 2000
elif (solved * 32 > n):
value[i] = 2500
else:
value[i] = 3000
solve[i] = solved
vasya = 0
for i in range(5):
vasya += value[i] - value[i] // 250 * t[0][i]
petya = 0
for i in range(5):
petya += value[i] - value[i] // 250 * t[1][i]
pot = [[0] * 20000 for i in range(5)]
for problem in range(5):
if t[0][problem] < t[1][problem]:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
elif t[0][problem] != 250:
cur_ac = 0
while 1:
if solve[problem] * 32 + cur_ac <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 + cur_ac <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 + cur_ac <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 + cur_ac <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 + cur_ac <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
else:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = -(3000 - 3000 // 250 * t[1][problem]) -(
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 <= n + cur_ac:
win = -(2500 - 2500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = -(2000 - 2000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = -(1500 - 1500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = -(1000 - 1000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = -(500 - 500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
res = -1
maxi = 0
for i in range(5):
maxi = max(maxi, len(pot[i]))
for i in range(maxi):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
print(res)
```
| 90,610 | [
0.2607421875,
0.1405029296875,
-0.3603515625,
0.88232421875,
-0.84521484375,
-0.4970703125,
-0.418212890625,
0.1549072265625,
-0.05389404296875,
0.421875,
0.37255859375,
0.1436767578125,
0.67626953125,
-0.77001953125,
-0.1302490234375,
0.1290283203125,
-0.560546875,
-0.7353515625,
... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
from sys import stdin, stdout
fractionBoundaries = [1/2,1/4,1/8,1/16,1/32,0]
scoreList = [500,1000,1500,2000,2500,3000]
def assessScores(n,Vsol,Psol,solvers):
vScore=0
pScore=0
for i in range(5):
for j in range(6):
if solvers[i]/n>fractionBoundaries[j]:
qnScore=scoreList[j]
break
if Vsol[i]>=0:
vScore+=qnScore-(qnScore*Vsol[i]//250)
if Psol[i]>=0:
pScore+=qnScore-(qnScore*Psol[i]//250)
return vScore>pScore
def main():
n = int(stdin.readline().rstrip())
Vsol = [int(x) for x in stdin.readline().rstrip().split()]
Psol = [int(x) for x in stdin.readline().rstrip().split()]
solvers = [0]*5
for _ in range(n-2):
a = [int(x) for x in stdin.readline().rstrip().split()]
for i in range(5):
if a[i]>=0:
solvers[i]+=1
for i in range(5):
if Vsol[i]>=0:
solvers[i]+=1
if Psol[i]>=0:
solvers[i]+=1
newSolvers=0
vWins=[]
pWins=[]
for i in range(5):
if (Vsol[i]<Psol[i] and Vsol[i]>=0) or (Vsol[i]>=0 and Psol[i]<0):
vWins.append(i)
elif (Psol[i]<Vsol[i] and Psol[i]>=0 and Vsol[i]>=0):
pWins.append(i)
if len(vWins)==0:
print(-1)
else:
while not assessScores(n+newSolvers,Vsol,Psol,solvers) and newSolvers<=100000007:
solversNeeded=9999999999999
for i in range(5):
if i in vWins:
currentRatio = solvers[i]/(newSolvers+n)
for j in range(6):
if solvers[i]/(newSolvers+n)>fractionBoundaries[j]:
nextBoundary = fractionBoundaries[j]
break
if nextBoundary!=0:
if solvers[i]%nextBoundary==0:
solversNeeded = min([solvers[i]//nextBoundary - (newSolvers+n),solversNeeded])
else:
solversNeeded = min([solvers[i]//nextBoundary - (newSolvers+n)+1,solversNeeded])
elif i in pWins and Vsol[i]>0:
currentRatio = solvers[i]/(newSolvers+n)
for j in range(6):
if solvers[i]/(newSolvers+n)>fractionBoundaries[j]:
if j>0:
nextBoundary = fractionBoundaries[j-1]
solversNeeded = min([(nextBoundary*(newSolvers+n)-solvers[i])//(1-nextBoundary)+1,solversNeeded])
break
newSolvers+=solversNeeded
for x in pWins:
solvers[x]+=solversNeeded
if newSolvers>1000000007:
print(-1)
else:
print(int(newSolvers))
main()
```
| 90,611 | [
0.2607421875,
0.1405029296875,
-0.3603515625,
0.88232421875,
-0.84521484375,
-0.4970703125,
-0.418212890625,
0.1549072265625,
-0.05389404296875,
0.421875,
0.37255859375,
0.1436767578125,
0.67626953125,
-0.77001953125,
-0.1302490234375,
0.1290283203125,
-0.560546875,
-0.7353515625,
... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
import sys
inf = 10**9 + 7
def solve():
n = int(sys.stdin.readline())
v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya
p = [int(pi) for pi in sys.stdin.readline().split()] # Petya
cnt = [0]*5
for i in range(5):
if v[i] != -1:
cnt[i] += 1
if p[i] != -1:
cnt[i] += 1
for i in range(n - 2):
a = [int(ai) for ai in sys.stdin.readline().split()]
for j in range(5):
if a[j] != -1:
cnt[j] += 1
for i in range(4000):
if check(n, v, p, cnt, i):
print(i)
return
print(-1)
def check(n, v, p, cnt, m):
tot = n + m
solved = cnt[:]
dif = 0
for i in range(5):
if p[i] != -1 and v[i] > p[i]:
solved[i] += m
for i in range(5):
if solved[i]*2 > tot:
max_score = 500
elif solved[i]*4 > tot:
max_score = 1000
elif solved[i]*8 > tot:
max_score = 1500
elif solved[i]*16 > tot:
max_score = 2000
elif solved[i]*32 > tot:
max_score = 2500
else:
max_score = 3000
if v[i] == p[i] == -1:
pass
elif v[i] == -1:
dif -= max_score * (250 - p[i]) // 250
elif p[i] == -1:
dif += max_score * (250 - v[i]) // 250
else:
dif += max_score * (p[i] - v[i]) // 250
return dif > 0
if __name__ == '__main__':
solve()
```
| 90,612 | [
0.2607421875,
0.1405029296875,
-0.3603515625,
0.88232421875,
-0.84521484375,
-0.4970703125,
-0.418212890625,
0.1549072265625,
-0.05389404296875,
0.421875,
0.37255859375,
0.1436767578125,
0.67626953125,
-0.77001953125,
-0.1302490234375,
0.1290283203125,
-0.560546875,
-0.7353515625,
... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
def get_value(parters, solved):
if solved * 32 <= parters:
return 3000
if solved * 16 <= parters:
return 2500
if solved * 8 <= parters:
return 2000
if solved * 4 <= parters:
return 1500
if solved * 2 <= parters:
return 1000
return 500
def points(value, time):
return value - value // 500 * time
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
value[i] = get_value(n, solved)
solve[i] = solved
vasya = 0
for i in range(5):
vasya += points(value[i], t[0][i])
petya = 0
for i in range(5):
petya += points(value[i], t[1][i])
pot = [[0] * 20000 for i in range(5)]
for problem in range(5):
for cur_ac in range(20000):
new_value = 0
if t[0][problem] < t[1][problem]:
new_value = get_value(n + cur_ac, solve[problem])
elif t[0][problem] != 250:
new_value = get_value(n + cur_ac, solve[problem] + cur_ac)
else:
new_value = get_value(n + cur_ac, solve[problem])
win = points(new_value, t[0][problem]) - points(new_value, t[1][problem]) - points(value[problem], t[0][problem]) + points(value[problem], t[1][problem])
pot[problem][cur_ac] = win
res = -1
for i in range(20000):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
print(res)
```
| 90,613 | [
0.2607421875,
0.1405029296875,
-0.3603515625,
0.88232421875,
-0.84521484375,
-0.4970703125,
-0.418212890625,
0.1549072265625,
-0.05389404296875,
0.421875,
0.37255859375,
0.1436767578125,
0.67626953125,
-0.77001953125,
-0.1302490234375,
0.1290283203125,
-0.560546875,
-0.7353515625,
... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
import sys
inf = 10**9 + 7
def solve():
def check(mid):
tot = n + mid
dif = 0
solved = cnt[:]
for i in range(5):
if v[i] != -1 and p[i] != -1 and p[i] < v[i]:
solved[i] += mid
for i in range(5):
if solved[i]*2 > tot:
max_score = 500
elif solved[i]*4 > tot:
max_score = 1000
elif solved[i]*8 > tot:
max_score = 1500
elif solved[i]*16 > tot:
max_score = 2000
elif solved[i]*32 > tot:
max_score = 2500
else:
max_score = 3000
if v[i] == p[i]:
pass
elif v[i] == -1:
dif += max_score * (250 - p[i]) // 250
elif p[i] == -1:
dif += -max_score * (250 - v[i]) // 250
else:
dif += max_score * (-p[i] + v[i]) // 250
# print(mid, dif)
return dif < 0
n = int(sys.stdin.readline())
cnt = [0]*5
v = [int(i) for i in sys.stdin.readline().split()]
for i in range(5):
if v[i] != -1:
cnt[i] += 1
p = [int(i) for i in sys.stdin.readline().split()]
for i in range(5):
if p[i] != -1:
cnt[i] += 1
for i in range(n - 2):
a = [int(ai) for ai in sys.stdin.readline().split()]
for j in range(5):
if a[j] != -1:
cnt[j] += 1
for i in range(6000):
if check(i):
print(i)
return
print(-1)
if __name__ == '__main__':
solve()
```
| 90,614 | [
0.2607421875,
0.1405029296875,
-0.3603515625,
0.88232421875,
-0.84521484375,
-0.4970703125,
-0.418212890625,
0.1549072265625,
-0.05389404296875,
0.421875,
0.37255859375,
0.1436767578125,
0.67626953125,
-0.77001953125,
-0.1302490234375,
0.1290283203125,
-0.560546875,
-0.7353515625,
... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Tags: brute force, greedy
Correct Solution:
```
import sys
inf = 10**9 + 7
def solve():
n = int(sys.stdin.readline())
v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya
p = [int(pi) for pi in sys.stdin.readline().split()] # Petya
cnt = [0]*5
for i in range(5):
if v[i] != -1:
cnt[i] += 1
if p[i] != -1:
cnt[i] += 1
for i in range(n - 2):
a = [int(ai) for ai in sys.stdin.readline().split()]
for j in range(5):
if a[j] != -1:
cnt[j] += 1
for i in range(10**5):
if check(n, v, p, cnt, i):
print(i)
return
print(-1)
def check(n, v, p, cnt, m):
tot = n + m
solved = cnt[:]
dif = 0
for i in range(5):
if p[i] != -1 and v[i] > p[i]:
solved[i] += m
for i in range(5):
if solved[i]*2 > tot:
max_score = 500
elif solved[i]*4 > tot:
max_score = 1000
elif solved[i]*8 > tot:
max_score = 1500
elif solved[i]*16 > tot:
max_score = 2000
elif solved[i]*32 > tot:
max_score = 2500
else:
max_score = 3000
if v[i] == p[i] == -1:
pass
elif v[i] == -1:
dif -= max_score * (250 - p[i]) // 250
elif p[i] == -1:
dif += max_score * (250 - v[i]) // 250
else:
dif += max_score * (p[i] - v[i]) // 250
return dif > 0
if __name__ == '__main__':
solve()
```
| 90,615 | [
0.2607421875,
0.1405029296875,
-0.3603515625,
0.88232421875,
-0.84521484375,
-0.4970703125,
-0.418212890625,
0.1549072265625,
-0.05389404296875,
0.421875,
0.37255859375,
0.1436767578125,
0.67626953125,
-0.77001953125,
-0.1302490234375,
0.1290283203125,
-0.560546875,
-0.7353515625,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
if (solved * 2 > n):
value[i] = 500
elif (solved * 4 > n):
value[i] = 1000
elif (solved * 8 > n):
value[i] = 1500
elif (solved * 16 > n):
value[i] = 2000
elif (solved * 32 > n):
value[i] = 2500
else:
value[i] = 3000
solve[i] = solved
vasya = 0
for i in range(5):
vasya += value[i] - value[i] // 250 * t[0][i]
petya = 0
for i in range(5):
petya += value[i] - value[i] // 250 * t[1][i]
pot = [[0] * 20000 for i in range(5)]
for problem in range(5):
if t[0][problem] < t[1][problem]:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
elif t[0][problem] != 250:
cur_ac = 0
while 1:
if solve[problem] * 32 + cur_ac <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 + cur_ac <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 + cur_ac <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 + cur_ac <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 + cur_ac <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
else:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = -(3000 - 3000 // 250 * t[1][problem]) -(
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
elif solve[problem] * 16 <= n + cur_ac:
win = -(2500 - 2500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = -(2000 - 2000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = -(1500 - 1500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = -(1000 - 1000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = -(500 - 500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
if cur_ac == 20000:
break
res = -1
maxi = 0
for i in range(5):
maxi = max(maxi, len(pot[i]))
for i in range(maxi):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
print(res)
```
No
| 90,616 | [
0.3291015625,
0.2130126953125,
-0.363525390625,
0.7548828125,
-0.9189453125,
-0.380126953125,
-0.395263671875,
0.21630859375,
-0.127685546875,
0.356201171875,
0.377685546875,
0.1876220703125,
0.55712890625,
-0.77490234375,
-0.14892578125,
0.054443359375,
-0.5615234375,
-0.688964843... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
import sys
inf = 10**9 + 7
def solve():
def check(mid):
tot = n + mid
dif = 0
solved = cnt[:]
for i in range(5):
if p[i] != -1 and p[i] < v[i]:
solved[i] += mid
for i in range(5):
if solved[i]*2 > tot:
max_score = 500
elif solved[i]*4 > tot:
max_score = 1000
elif solved[i]*8 > tot:
max_score = 1500
elif solved[i]*16 > tot:
max_score = 2000
elif solved[i]*32 > tot:
max_score = 2500
else:
max_score = 3000
if v[i] == p[i]:
pass
elif v[i] == -1:
dif += max_score * (250 - p[i]) // 250
elif p[i] == -1:
dif += -max_score * (250 - v[i]) // 250
else:
dif += max_score * (-p[i] + v[i]) // 250
# print(mid, dif)
return dif < 0
n = int(sys.stdin.readline())
cnt = [0]*5
v = [int(i) for i in sys.stdin.readline().split()]
for i in range(5):
if v[i] != -1:
cnt[i] += 1
p = [int(i) for i in sys.stdin.readline().split()]
for i in range(5):
if p[i] != -1:
cnt[i] += 1
for i in range(n - 2):
a = [int(ai) for ai in sys.stdin.readline().split()]
for j in range(5):
if a[j] != -1:
cnt[j] += 1
btm = -1
top = inf + 2
while top - btm > 1:
mid = (top + btm) // 2
if check(mid):
top = mid
else:
btm = mid
ans = top if top < inf + 1 else -1
print(ans)
if __name__ == '__main__':
solve()
```
No
| 90,617 | [
0.3291015625,
0.2130126953125,
-0.363525390625,
0.7548828125,
-0.9189453125,
-0.380126953125,
-0.395263671875,
0.21630859375,
-0.127685546875,
0.356201171875,
0.377685546875,
0.1876220703125,
0.55712890625,
-0.77490234375,
-0.14892578125,
0.054443359375,
-0.5615234375,
-0.688964843... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
import sys
inf = 10**9 + 7
def solve():
def check(mid):
tot = n + mid
dif = 0
solved = cnt[:]
for i in range(5):
if v[i] != -1 and p[i] != -1 and p[i] < v[i]:
solved[i] += mid
for i in range(5):
if solved[i]*2 > tot:
max_score = 500
elif solved[i]*4 > tot:
max_score = 1000
elif solved[i]*8 > tot:
max_score = 1500
elif solved[i]*16 > tot:
max_score = 2000
elif solved[i]*32 > tot:
max_score = 2500
else:
max_score = 3000
if v[i] == p[i]:
pass
elif v[i] == -1:
dif += max_score * (250 - p[i]) // 250
elif p[i] == -1:
dif += -max_score * (250 - v[i]) // 250
else:
dif += max_score * (-p[i] + v[i]) // 250
# print(mid, dif)
return dif < 0
n = int(sys.stdin.readline())
cnt = [0]*5
v = [int(i) for i in sys.stdin.readline().split()]
for i in range(5):
if v[i] != -1:
cnt[i] += 1
p = [int(i) for i in sys.stdin.readline().split()]
for i in range(5):
if p[i] != -1:
cnt[i] += 1
for i in range(n - 2):
a = [int(ai) for ai in sys.stdin.readline().split()]
for j in range(5):
if a[j] != -1:
cnt[j] += 1
btm = -1
top = inf + 2
while top - btm > 1:
mid = (top + btm) // 2
if check(mid):
top = mid
else:
btm = mid
ans = top if top < inf + 1 else -1
print(ans)
if __name__ == '__main__':
solve()
```
No
| 90,618 | [
0.3291015625,
0.2130126953125,
-0.363525390625,
0.7548828125,
-0.9189453125,
-0.380126953125,
-0.395263671875,
0.21630859375,
-0.127685546875,
0.356201171875,
0.377685546875,
0.1876220703125,
0.55712890625,
-0.77490234375,
-0.14892578125,
0.054443359375,
-0.5615234375,
-0.688964843... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.
<image>
Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.
If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.
There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.
With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.
Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.
Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.
Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.
Input
The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya.
Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j.
It is guaranteed that each participant has made at least one successful submission.
Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.
Output
Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.
Examples
Input
2
5 15 40 70 115
50 45 40 30 15
Output
2
Input
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
Output
3
Input
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
Output
27
Input
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
Output
-1
Note
In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.
In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.
In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
Submitted Solution:
```
n = int(input())
t = [0] * n
for i in range(n):
t[i] = list(map(int, input().split()))
value = [0] * 5
solve = [0] * 5
for i in range(5):
solved = 0
for j in range(n):
if t[j][i] != -1:
solved += 1
else:
t[j][i] = 250
if (solved * 2 > n):
value[i] = 500
elif (solved * 4 > n):
value[i] = 1000
elif (solved * 8 > n):
value[i] = 1500
elif (solved * 16 > n):
value[i] = 2000
elif (solved * 32 > n):
value[i] = 2500
else:
value[i] = 3000
solve[i] = solved
vasya = 0
for i in range(5):
vasya += value[i] - value[i] // 250 * t[0][i]
petya = 0
for i in range(5):
petya += value[i] - value[i] // 250 * t[1][i]
pot = [[0] * 200000 for i in range(5)]
for problem in range(5):
if t[0][problem] < t[1][problem]:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
elif solve[problem] * 16 <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
elif t[0][problem] != 250:
cur_ac = 0
while 1:
if solve[problem] * 32 + cur_ac <= n + cur_ac:
win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 16 + cur_ac <= n + cur_ac:
win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 + cur_ac <= n + cur_ac:
win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 + cur_ac <= n + cur_ac:
win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 + cur_ac <= n + cur_ac:
win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (
value[problem] - value[problem] // 250 * t[0][problem] - (
value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
cur_ac += 1
else:
cur_ac = 0
while 1:
if solve[problem] * 32 <= n + cur_ac:
win = -(3000 - 3000 // 250 * t[1][problem]) -(
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
break
elif solve[problem] * 16 <= n + cur_ac:
win = -(2500 - 2500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 8 <= n + cur_ac:
win = -(2000 - 2000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 4 <= n + cur_ac:
win = -(1500 - 1500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
elif solve[problem] * 2 <= n + cur_ac:
win = -(1000 - 1000 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
else:
win = -(500 - 500 // 250 * t[1][problem]) - (
-(value[problem] - value[problem] // 250 * t[1][problem]))
pot[problem][cur_ac] = win
cur_ac += 1
res = -1
maxi = 0
for i in range(5):
maxi = max(maxi, len(pot[i]))
for i in range(maxi):
tmp = 0
for pr in range(5):
if len(pot[pr]) <= i:
tmp += pot[pr][-1]
else:
tmp += pot[pr][i]
if tmp > petya - vasya:
res = i
break
print(res)
```
No
| 90,619 | [
0.3291015625,
0.2130126953125,
-0.363525390625,
0.7548828125,
-0.9189453125,
-0.380126953125,
-0.395263671875,
0.21630859375,
-0.127685546875,
0.356201171875,
0.377685546875,
0.1876220703125,
0.55712890625,
-0.77490234375,
-0.14892578125,
0.054443359375,
-0.5615234375,
-0.688964843... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing?
Let a_i be how many numbers i (1 ≤ i ≤ k) you have.
An n × n matrix is called beautiful if it contains all the numbers you have, and for each 2 × 2 submatrix of the original matrix is satisfied:
1. The number of occupied cells doesn't exceed 3;
2. The numbers on each diagonal are distinct.
Make a beautiful matrix of minimum size.
Input
The first line contains a single integer t (1 ≤ t ≤ 10 000) — the number of test cases.
The first line of each test case contains 2 integers m and k (1 ≤ m, k ≤ 10^5) — how many numbers Nastia gave you and the length of the array a, respectively.
The second line of each test case contains k integers a_1, a_2, …, a_{k} (0 ≤ a_i ≤ m, a_1 + a_2 + … + a_{k} = m), where a_i is how many numbers i you have.
It's guaranteed that the sum of m and k in one test doesn't exceed 2 ⋅ 10^5.
Output
For each t test case print a single integer n — the size of the beautiful matrix.
In the next n lines print n integers b_{i, j} (0 ≤ b_{i, j} ≤ k; if position is empty, print b_{i, j} = 0) — the beautiful matrix b you made up.
Example
Input
2
3 4
2 0 0 1
15 4
2 4 8 1
Output
2
4 1
0 1
5
3 0 0 2 2
3 2 3 3 0
0 1 0 4 0
3 0 0 0 0
2 1 3 3 3
Note
Note that 0 in this problem represents a blank, not a number.
Examples of possible answers for the first test case:
\begin{array}{cc} 1 & 1 \\\ 4 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 4 \\\ 1 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 0 \\\ 1 & 1 \\\ \end{array}
Examples of not beautiful matrices for the first test case:
\begin{array}{cc} 1 & 0 \\\ 4 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 1 \\\ 7 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 0 \\\ 4 & 0 \\\ \end{array}
The example of the not beautiful matrix for the second test case:
\begin{array}{cc} 3 & 4 & 0 & 2 & 2 \\\ 3 & 2 & 3 & 3 & 0 \\\ 0 & 1 & 0 & 0 & 0 \\\ 3 & 0 & 0 & 0 & 0 \\\ 2 & 1 & 3 & 3 & 3 \\\ \end{array}
Everything is okay, except the left-top submatrix contains 4 numbers.
Submitted Solution:
```
def cheak(x):
return x**2-(x//2)**2>=m and x*(x//2+(1 if x%2!=0 else 0))>=mx
for test in range(int(input())):
m,k=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
mx=max(a)
z=0;y=m*4
while z!=y:
x=(z+y)//2
if cheak(x):
y=x
else:
z=x+1
else:
x=z
a=sorted(list(map(list,zip(a,range(1,len(a)+1)))))
def get():
i=len(a)
while i!=0:
i-=1
while a[i][0]>0:
a[i][0]-=1
yield a[i][1]
return 0
mt=[[0 for i in range(x)] for j in range(x)]
t=1
it=get()
try:
for i in range(0,x,2):
if t==0:break
for j in range(0,x,2):
t=next(it)
if t:mt[i][j]=t
else:break
for i in range(0,x,2):
if t==0:break
for j in range(1,x,2):
t=next(it)
if t:mt[i][j]=t
else:break
for i in range(1,x,2):
if t==0:break
for j in range(0,x,2):
t=next(it)
if t:mt[i][j]=t
else:break
except StopIteration:...
for i in mt:
print(*i)
```
No
| 91,166 | [
0.278076171875,
0.01953125,
-0.100341796875,
0.1156005859375,
-0.63525390625,
-0.61083984375,
0.01203155517578125,
0.34912109375,
0.12115478515625,
0.47021484375,
0.62841796875,
0.2117919921875,
0.03143310546875,
-0.7529296875,
-0.45849609375,
-0.055328369140625,
-0.259033203125,
-... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing?
Let a_i be how many numbers i (1 ≤ i ≤ k) you have.
An n × n matrix is called beautiful if it contains all the numbers you have, and for each 2 × 2 submatrix of the original matrix is satisfied:
1. The number of occupied cells doesn't exceed 3;
2. The numbers on each diagonal are distinct.
Make a beautiful matrix of minimum size.
Input
The first line contains a single integer t (1 ≤ t ≤ 10 000) — the number of test cases.
The first line of each test case contains 2 integers m and k (1 ≤ m, k ≤ 10^5) — how many numbers Nastia gave you and the length of the array a, respectively.
The second line of each test case contains k integers a_1, a_2, …, a_{k} (0 ≤ a_i ≤ m, a_1 + a_2 + … + a_{k} = m), where a_i is how many numbers i you have.
It's guaranteed that the sum of m and k in one test doesn't exceed 2 ⋅ 10^5.
Output
For each t test case print a single integer n — the size of the beautiful matrix.
In the next n lines print n integers b_{i, j} (0 ≤ b_{i, j} ≤ k; if position is empty, print b_{i, j} = 0) — the beautiful matrix b you made up.
Example
Input
2
3 4
2 0 0 1
15 4
2 4 8 1
Output
2
4 1
0 1
5
3 0 0 2 2
3 2 3 3 0
0 1 0 4 0
3 0 0 0 0
2 1 3 3 3
Note
Note that 0 in this problem represents a blank, not a number.
Examples of possible answers for the first test case:
\begin{array}{cc} 1 & 1 \\\ 4 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 4 \\\ 1 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 0 \\\ 1 & 1 \\\ \end{array}
Examples of not beautiful matrices for the first test case:
\begin{array}{cc} 1 & 0 \\\ 4 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 1 \\\ 7 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 0 \\\ 4 & 0 \\\ \end{array}
The example of the not beautiful matrix for the second test case:
\begin{array}{cc} 3 & 4 & 0 & 2 & 2 \\\ 3 & 2 & 3 & 3 & 0 \\\ 0 & 1 & 0 & 0 & 0 \\\ 3 & 0 & 0 & 0 & 0 \\\ 2 & 1 & 3 & 3 & 3 \\\ \end{array}
Everything is okay, except the left-top submatrix contains 4 numbers.
Submitted Solution:
```
# 6fbbb444ee015ce84ca315f20e46e28a71024d21eb5e2c6477de2b0972b44556
print('hello')
```
No
| 91,167 | [
0.278076171875,
0.01953125,
-0.100341796875,
0.1156005859375,
-0.63525390625,
-0.61083984375,
0.01203155517578125,
0.34912109375,
0.12115478515625,
0.47021484375,
0.62841796875,
0.2117919921875,
0.03143310546875,
-0.7529296875,
-0.45849609375,
-0.055328369140625,
-0.259033203125,
-... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing?
Let a_i be how many numbers i (1 ≤ i ≤ k) you have.
An n × n matrix is called beautiful if it contains all the numbers you have, and for each 2 × 2 submatrix of the original matrix is satisfied:
1. The number of occupied cells doesn't exceed 3;
2. The numbers on each diagonal are distinct.
Make a beautiful matrix of minimum size.
Input
The first line contains a single integer t (1 ≤ t ≤ 10 000) — the number of test cases.
The first line of each test case contains 2 integers m and k (1 ≤ m, k ≤ 10^5) — how many numbers Nastia gave you and the length of the array a, respectively.
The second line of each test case contains k integers a_1, a_2, …, a_{k} (0 ≤ a_i ≤ m, a_1 + a_2 + … + a_{k} = m), where a_i is how many numbers i you have.
It's guaranteed that the sum of m and k in one test doesn't exceed 2 ⋅ 10^5.
Output
For each t test case print a single integer n — the size of the beautiful matrix.
In the next n lines print n integers b_{i, j} (0 ≤ b_{i, j} ≤ k; if position is empty, print b_{i, j} = 0) — the beautiful matrix b you made up.
Example
Input
2
3 4
2 0 0 1
15 4
2 4 8 1
Output
2
4 1
0 1
5
3 0 0 2 2
3 2 3 3 0
0 1 0 4 0
3 0 0 0 0
2 1 3 3 3
Note
Note that 0 in this problem represents a blank, not a number.
Examples of possible answers for the first test case:
\begin{array}{cc} 1 & 1 \\\ 4 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 4 \\\ 1 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 0 \\\ 1 & 1 \\\ \end{array}
Examples of not beautiful matrices for the first test case:
\begin{array}{cc} 1 & 0 \\\ 4 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 1 \\\ 7 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 0 \\\ 4 & 0 \\\ \end{array}
The example of the not beautiful matrix for the second test case:
\begin{array}{cc} 3 & 4 & 0 & 2 & 2 \\\ 3 & 2 & 3 & 3 & 0 \\\ 0 & 1 & 0 & 0 & 0 \\\ 3 & 0 & 0 & 0 & 0 \\\ 2 & 1 & 3 & 3 & 3 \\\ \end{array}
Everything is okay, except the left-top submatrix contains 4 numbers.
Submitted Solution:
```
from bisect import bisect,bisect_left
from collections import *
from heapq import *
from math import gcd,ceil,sqrt,floor,inf
from itertools import *
from operator import add,mul,sub,xor,truediv,floordiv
from functools import *
#------------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
# region fastio
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 RL(): return map(int, sys.stdin.readline().split())
def RLL(): return list(map(int, sys.stdin.readline().split()))
def N(): return int(input())
def A(n):return [0]*n
def AI(n,x): return [x]*n
def A2(n,m): return [[0]*m for i in range(n)]
def G(n): return [[] for i in range(n)]
def GP(it): return [[ch,len(list(g))] for ch,g in groupby(it)]
#------------------------------------------------------------------------
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
else:
stack.pop()
if not stack:
break
to = stack[-1].send(to)
return to
return wrappedfunc
mod=10**9+7
farr=[1]
ifa=[]
def fact(x,mod=0):
if mod:
while x>=len(farr):
farr.append(farr[-1]*len(farr)%mod)
else:
while x>=len(farr):
farr.append(farr[-1]*len(farr))
return farr[x]
def ifact(x,mod):
global ifa
fact(x,mod)
ifa.append(pow(farr[-1],mod-2,mod))
for i in range(x,0,-1):
ifa.append(ifa[-1]*i%mod)
ifa.reverse()
def per(i,j,mod=0):
if i<j: return 0
if not mod:
return fact(i)//fact(i-j)
return farr[i]*ifa[i-j]%mod
def com(i,j,mod=0):
if i<j: return 0
if not mod:
return per(i,j)//fact(j)
return per(i,j,mod)*ifa[j]%mod
def catalan(n):
return com(2*n,n)//(n+1)
def isprime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
def floorsum(a,b,c,n):#sum((a*i+b)//c for i in range(n+1))
if a==0:return b//c*(n+1)
if a>=c or b>=c: return floorsum(a%c,b%c,c,n)+b//c*(n+1)+a//c*n*(n+1)//2
m=(a*n+b)//c
return n*m-floorsum(c,c-b-1,a,m-1)
def inverse(a,m):
a%=m
if a<=1: return a
return ((1-inverse(m,a)*m)//a)%m
def lowbit(n):
return n&-n
class BIT:
def __init__(self,arr):
self.arr=arr
self.n=len(arr)-1
def update(self,x,v):
while x<=self.n:
self.arr[x]+=v
x+=x&-x
def query(self,x):
ans=0
while x:
ans+=self.arr[x]
x&=x-1
return ans
class ST:
def __init__(self,arr):#n!=0
n=len(arr)
mx=n.bit_length()#取不到
self.st=[[0]*mx for i in range(n)]
for i in range(n):
self.st[i][0]=arr[i]
for j in range(1,mx):
for i in range(n-(1<<j)+1):
self.st[i][j]=max(self.st[i][j-1],self.st[i+(1<<j-1)][j-1])
def query(self,l,r):
if l>r:return -inf
s=(r+1-l).bit_length()-1
return max(self.st[l][s],self.st[r-(1<<s)+1][s])
class DSU:#容量+路径压缩
def __init__(self,n):
self.c=[-1]*n
def same(self,x,y):
return self.find(x)==self.find(y)
def find(self,x):
if self.c[x]<0:
return x
self.c[x]=self.find(self.c[x])
return self.c[x]
def union(self,u,v):
u,v=self.find(u),self.find(v)
if u==v:
return False
if self.c[u]>self.c[v]:
u,v=v,u
self.c[u]+=self.c[v]
self.c[v]=u
return True
def size(self,x): return -self.c[self.find(x)]
class UFS:#秩+路径
def __init__(self,n):
self.parent=[i for i in range(n)]
self.ranks=[0]*n
def find(self,x):
if x!=self.parent[x]:
self.parent[x]=self.find(self.parent[x])
return self.parent[x]
def union(self,u,v):
pu,pv=self.find(u),self.find(v)
if pu==pv:
return False
if self.ranks[pu]>=self.ranks[pv]:
self.parent[pv]=pu
if self.ranks[pv]==self.ranks[pu]:
self.ranks[pu]+=1
else:
self.parent[pu]=pv
class UF:#秩+路径+容量,边数
def __init__(self,n):
self.parent=[i for i in range(n)]
self.ranks=[0]*n
self.size=AI(n,1)
self.edge=A(n)
def find(self,x):
if x!=self.parent[x]:
self.parent[x]=self.find(self.parent[x])
return self.parent[x]
def union(self,u,v):
pu,pv=self.find(u),self.find(v)
if pu==pv:
self.edge[pu]+=1
return False
if self.ranks[pu]>=self.ranks[pv]:
self.parent[pv]=pu
self.edge[pu]+=self.edge[pv]+1
self.size[pu]+=self.size[pv]
if self.ranks[pv]==self.ranks[pu]:
self.ranks[pu]+=1
else:
self.parent[pu]=pv
self.edge[pv]+=self.edge[pu]+1
self.size[pv]+=self.size[pu]
def Prime(n):
c=0
prime=[]
flag=[0]*(n+1)
for i in range(2,n+1):
if not flag[i]:
prime.append(i)
c+=1
for j in range(c):
if i*prime[j]>n: break
flag[i*prime[j]]=prime[j]
if i%prime[j]==0: break
return flag
def dij(s,graph):
d=AI(n,inf)
d[s]=0
heap=[(0,s)]
vis=A(n)
while heap:
dis,u=heappop(heap)
if vis[u]:
continue
vis[u]=1
for v,w in graph[u]:
if d[v]>d[u]+w:
d[v]=d[u]+w
heappush(heap,(d[v],v))
return d
def bell(s,g):#bellman-Ford
dis=AI(n,inf)
dis[s]=0
for i in range(n-1):
for u,v,w in edge:
if dis[v]>dis[u]+w:
dis[v]=dis[u]+w
change=A(n)
for i in range(n):
for u,v,w in edge:
if dis[v]>dis[u]+w:
dis[v]=dis[u]+w
change[v]=1
return dis
def lcm(a,b): return a*b//gcd(a,b)
def lis(nums):
res=[]
for k in nums:
i=bisect.bisect_left(res,k)
if i==len(res):
res.append(k)
else:
res[i]=k
return len(res)
def RP(nums):#逆序对
n = len(nums)
s=set(nums)
d={}
for i,k in enumerate(sorted(s),1):
d[k]=i
bi=BIT([0]*(len(s)+1))
ans=0
for i in range(n-1,-1,-1):
ans+=bi.query(d[nums[i]]-1)
bi.update(d[nums[i]],1)
return ans
class DLN:
def __init__(self,val):
self.val=val
self.pre=None
self.next=None
def nb(i,j,n,m):
for ni,nj in [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]:
if 0<=ni<n and 0<=nj<m:
yield ni,nj
def topo(n):
q=deque()
res=[]
for i in range(1,n+1):
if ind[i]==0:
q.append(i)
res.append(i)
while q:
u=q.popleft()
for v in g[u]:
ind[v]-=1
if ind[v]==0:
q.append(v)
res.append(v)
return res
@bootstrap
def gdfs(r,p):
for ch in g[r]:
if ch!=p:
yield gdfs(ch,r)
yield None
#from random import randint
t=N()
for i in range(t):
m,k=RL()
a=RLL()
l=1
r=m
ma=max(a)
while l<r:
n=(l+r)>>1
if n&1:
if (3*n**2+2*n-1)//4>=m and (n+1)*n//2>=ma:
r=n
else:
l=n+1
else:
if 3*n*n//4>=m and n*n//2>=ma:
r=n
else:
l=n+1
c={}
res=[]
for i in range(k):
if a[i]:
res+=[i+1]*a[i]
c[i+1]=a[i]
res.sort(key=lambda x: -c[x])
ans=A2(l,l)
p=0
for i in range(0,l,2):
for j in range(0,l):
ans[i][j]=res[p]
p+=1
if p==len(res):break
if p==len(res):break
if p<len(res):
for i in range(1,l,2):
for j in range(0,l,2):
ans[i][j]=res[p]
p+=1
if p==len(res):break
if p==len(res):break
print(l)
for r in ans:
print(*r)
'''
sys.setrecursionlimit(200000)
import threading
threading.stack_size(10**8)
t=threading.Thr
ead(target=main)
t.start()
t.join()
'''
```
No
| 91,168 | [
0.278076171875,
0.01953125,
-0.100341796875,
0.1156005859375,
-0.63525390625,
-0.61083984375,
0.01203155517578125,
0.34912109375,
0.12115478515625,
0.47021484375,
0.62841796875,
0.2117919921875,
0.03143310546875,
-0.7529296875,
-0.45849609375,
-0.055328369140625,
-0.259033203125,
-... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing?
Let a_i be how many numbers i (1 ≤ i ≤ k) you have.
An n × n matrix is called beautiful if it contains all the numbers you have, and for each 2 × 2 submatrix of the original matrix is satisfied:
1. The number of occupied cells doesn't exceed 3;
2. The numbers on each diagonal are distinct.
Make a beautiful matrix of minimum size.
Input
The first line contains a single integer t (1 ≤ t ≤ 10 000) — the number of test cases.
The first line of each test case contains 2 integers m and k (1 ≤ m, k ≤ 10^5) — how many numbers Nastia gave you and the length of the array a, respectively.
The second line of each test case contains k integers a_1, a_2, …, a_{k} (0 ≤ a_i ≤ m, a_1 + a_2 + … + a_{k} = m), where a_i is how many numbers i you have.
It's guaranteed that the sum of m and k in one test doesn't exceed 2 ⋅ 10^5.
Output
For each t test case print a single integer n — the size of the beautiful matrix.
In the next n lines print n integers b_{i, j} (0 ≤ b_{i, j} ≤ k; if position is empty, print b_{i, j} = 0) — the beautiful matrix b you made up.
Example
Input
2
3 4
2 0 0 1
15 4
2 4 8 1
Output
2
4 1
0 1
5
3 0 0 2 2
3 2 3 3 0
0 1 0 4 0
3 0 0 0 0
2 1 3 3 3
Note
Note that 0 in this problem represents a blank, not a number.
Examples of possible answers for the first test case:
\begin{array}{cc} 1 & 1 \\\ 4 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 4 \\\ 1 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 0 \\\ 1 & 1 \\\ \end{array}
Examples of not beautiful matrices for the first test case:
\begin{array}{cc} 1 & 0 \\\ 4 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 1 \\\ 7 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 0 \\\ 4 & 0 \\\ \end{array}
The example of the not beautiful matrix for the second test case:
\begin{array}{cc} 3 & 4 & 0 & 2 & 2 \\\ 3 & 2 & 3 & 3 & 0 \\\ 0 & 1 & 0 & 0 & 0 \\\ 3 & 0 & 0 & 0 & 0 \\\ 2 & 1 & 3 & 3 & 3 \\\ \end{array}
Everything is okay, except the left-top submatrix contains 4 numbers.
Submitted Solution:
```
#!/usr/bin/env python3
# set vim: fdm=marker sw=4 ts=4 et
from collections import defaultdict
from collections import deque
def get_matrix(n, a):
b = []
for i in range(n):
b.append([0] * n)
for i in range(0, n, 2):
for j in range(n):
b[i][j] = a[-1][1]
a[-1][0] -= 1
if a[-1][0] == 0:
a.pop()
if len(a) == 0:
return b
for i in range(1, n, 2):
for j in range(0, n, 2):
b[i][j] = a[-1][1]
a[-1][0] -= 1
if a[-1][0] == 0:
a.pop()
if len(a) == 0:
return b
return b
for _ in range(int(input())):
m, k = map(int, input().split())
a = [int(i) for i in input().split()]
a = [[a[i], i + 1] for i in range(len(a)) if a[i] != 0]
a.sort()
max_a_i = a[-1][0]
# print('max_a_i', max_a_i)
# print('m', m)
# n * ((n + 1) // 2)
# 2 -> 2
# 3 -> 6
# 4 -> 8
# 5 -> 15
l, r = (0, 1000)
while r - l > 1:
m1 = (l + r) // 2
# print('m1', m1)
m2 = m1 * ((m1 + 1) // 2)
# print('m2', m2)
m3 = m2 + (m1 // 2 * (m1 + 1) // 2)
# print('m3', m3)
if m2 >= max_a_i and m3 >= m:
r = m1
else:
l = m1
n = r
a2 = []
for a_i in a:
a2.append(a_i[:])
b = get_matrix(n, a)
valid = True
for i in range(1, n):
for j in range(n):
if j > 0 and b[i - 1][j - 1] == b[i][j]:
valid = False
break
if j < n - 1 and b[i - 1][j + 1] == b[i][j]:
valid = False
break
if not valid:
break
if not valid:
b = get_matrix(n + 1, a2)
print(n)
for i in range(n):
print(' '.join(map(str, b[i])))
```
No
| 91,169 | [
0.278076171875,
0.01953125,
-0.100341796875,
0.1156005859375,
-0.63525390625,
-0.61083984375,
0.01203155517578125,
0.34912109375,
0.12115478515625,
0.47021484375,
0.62841796875,
0.2117919921875,
0.03143310546875,
-0.7529296875,
-0.45849609375,
-0.055328369140625,
-0.259033203125,
-... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
n=int(input())
A=[]
for i in range(n):
A.append(int(input()))
k=1
for i in range(n):
if A[k-1]==2:
print(i+1)
exit()
k=A[k-1]
print(-1)
```
Yes
| 91,571 | [
0.5263671875,
0.14111328125,
0.04656982421875,
0.284912109375,
-0.85400390625,
-0.3720703125,
-0.25048828125,
0.1036376953125,
-0.313720703125,
1.0029296875,
0.231201171875,
-0.1121826171875,
0.054351806640625,
-0.82177734375,
-0.00371551513671875,
-0.034820556640625,
-0.62841796875,... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
n,*a=map(int,open(0).readlines());c,s=1,a[0]
while s!=2and c<n:c+=1;s=a[s-1]
print(c*(c<n)or-1)
```
Yes
| 91,572 | [
0.5078125,
0.1693115234375,
0.047576904296875,
0.263427734375,
-0.8349609375,
-0.370361328125,
-0.2783203125,
0.08184814453125,
-0.336181640625,
1.02734375,
0.193115234375,
-0.0902099609375,
0.10333251953125,
-0.83056640625,
0.0028705596923828125,
-0.058624267578125,
-0.61865234375,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
n=int(input())
A=list(int(input()) for i in range(n))
a=0
count=0
for i in range(n):
if a!=1:
a=A[a]-1
count+=1
print(count if a==1 else -1)
```
Yes
| 91,573 | [
0.50830078125,
0.1337890625,
0.03997802734375,
0.263916015625,
-0.86083984375,
-0.387451171875,
-0.243896484375,
0.1177978515625,
-0.294189453125,
1.0107421875,
0.2471923828125,
-0.1212158203125,
0.06988525390625,
-0.8212890625,
-0.0104522705078125,
-0.031890869140625,
-0.63427734375... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
import sys
e = list(map(int,sys.stdin))
cur = e[1]
for i in range(e[0]):
if cur == 2:
print(i + 1)
break
cur = e[cur]
else:
print(-1)
```
Yes
| 91,574 | [
0.5009765625,
0.1649169921875,
0.06036376953125,
0.289306640625,
-0.88427734375,
-0.368896484375,
-0.251953125,
0.07989501953125,
-0.312255859375,
1.037109375,
0.1771240234375,
-0.10675048828125,
0.10565185546875,
-0.84814453125,
0.004138946533203125,
-0.05950927734375,
-0.6157226562... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
N = int(input())
data = ([int(input()) for i in range(N)])
data.insert(0, 0)
i = 1
cnt = 0
push_button = {1: "PUSH"}
while True:
trans_value = data[i]
cnt += 1
push_button[trans_value] = "PUSH"
if trans_value in push_button:
cnt = -1
break
if trans_value == 2:
break
print(cnt)
```
No
| 91,575 | [
0.4423828125,
0.1729736328125,
0.10357666015625,
0.330810546875,
-0.79736328125,
-0.35205078125,
-0.171142578125,
0.041839599609375,
-0.2666015625,
1.04296875,
0.1307373046875,
-0.016937255859375,
0.1021728515625,
-0.92041015625,
-0.06402587890625,
-0.05206298828125,
-0.59912109375,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
N = int(input())
buttons = [int(input()) for _ in range(N)]
count = 1
tmp = buttons[0]
flag = True
while count < N+2:
tmp = buttons[tmp-1]
count += 1
if tmp == 2:
print(count)
flag = False
break
if flag:
print(-1)
```
No
| 91,576 | [
0.5458984375,
0.13232421875,
0.03424072265625,
0.3125,
-0.83740234375,
-0.405517578125,
-0.222412109375,
0.10760498046875,
-0.284423828125,
1.0166015625,
0.23681640625,
-0.1317138671875,
0.059814453125,
-0.82861328125,
0.0271759033203125,
-0.0428466796875,
-0.61767578125,
-0.772460... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
n = int(input())
a=[0]
for i in range(n):
a.append(int(input()))
s=1
cnt=0
while s !=2:
s=a[s]
cnt +=1
print(s)
print(cnt)
```
No
| 91,577 | [
0.5146484375,
0.1474609375,
0.020263671875,
0.310546875,
-0.8115234375,
-0.382080078125,
-0.2198486328125,
0.08660888671875,
-0.305908203125,
1.017578125,
0.239990234375,
-0.1229248046875,
0.0594482421875,
-0.84814453125,
-0.00998687744140625,
-0.0452880859375,
-0.6015625,
-0.75781... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ a_i ≤ N
Input
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N
Output
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
Examples
Input
3
3
1
2
Output
2
Input
4
3
4
1
2
Output
-1
Input
5
3
3
4
2
4
Output
3
Submitted Solution:
```
N = int(input())
btn = [int(input())-1 for _ in range(N)]
i = 0
li = [0]
for _ in range(N):
k = btn[i]
#print(k, li)
if k in li:
print('-1')
break
else:
if k != 1:
li.append(k)
else:
print(len(li))
break
i = k
```
No
| 91,578 | [
0.485595703125,
0.1407470703125,
0.061859130859375,
0.275146484375,
-0.85693359375,
-0.40380859375,
-0.2337646484375,
0.08465576171875,
-0.30126953125,
1.0078125,
0.2401123046875,
-0.1083984375,
0.08172607421875,
-0.8291015625,
-0.0293731689453125,
-0.0200042724609375,
-0.70068359375... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a way on it that
* starts in the upper left cell of the matrix;
* each following cell is to the right or down from the current cell;
* the way ends in the bottom right cell.
Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.
Input
The first line contains an integer number n (2 ≤ n ≤ 1000), n is the size of the matrix. Then follow n lines containing the matrix elements (non-negative integer numbers not exceeding 109).
Output
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
Examples
Input
3
1 2 3
4 5 6
7 8 9
Output
0
DDRR
Submitted Solution:
```
import sys
line_num = int(sys.stdin.readline())
lines = []
for i in range(0, line_num):
lines.append(sys.stdin.readline().strip())
elements = []
zero_row = -1
for row_index, line in enumerate(lines):
row = [int(i) for i in line.split()]
if 0 in row:
zero_row = row_index
elements.append(row)
scores = []
for n in range(line_num):
temp = []
for m in range(line_num):
temp.append([0, 'N'])
scores.append(temp)
scores[0][0] = [elements[0][0], 'N']
for temp_i in range(1, line_num):
scores[0][temp_i] = [scores[0][temp_i-1][0] * elements[0][temp_i], 'R']
scores[temp_i][0] = [scores[temp_i-1][0][0] * elements[temp_i][0], 'D']
for i in range(1, line_num):
for j in range(1, line_num):
score_R = scores[i][j-1][0] * elements[i][j]
score_D = scores[i-1][j][0] * elements[i][j]
chars_R = list(str(score_R))[::-1]
chars_D = list(str(score_D))[::-1]
min_length = 0
if len(chars_R) < len(chars_D):
min_length = len(chars_R)
else:
min_length = len(chars_D)
choice = [0, 'N']
if min_length > 20:
score_R = score_R % (10 ** 20)
score_D = score_D % (10 ** 20)
for index in range(0, min_length):
if chars_R[index] == '0' and chars_D[index] != '0':
choice = [score_D, 'D']
break
elif chars_D[index] == '0' and chars_R[index] != '0':
choice = [score_R, 'R']
break
elif chars_D[index] == '0' and chars_R[index] == '0':
continue
elif chars_R[index] in ['1', '3', '7', '9']:
choice = [score_R, 'R']
break
elif chars_D[index] in ['1', '3', '7', '9']:
choice = [score_D, 'D']
break
elif chars_R[index] in ['2', '4', '6', '8'] and chars_D[index] in ['2', '4', '6', '8']:
if chars_R[index] in ['2', '6']:
choice = [score_R, 'R']
elif chars_D[index] in ['2', '6']:
choice = [score_D, 'D']
elif chars_R[index] == '4':
choice = [score_R, 'R']
elif chars_D[index] == '4':
choice = [score_D, 'D']
else:
choice = [score_R, 'R']
break
elif chars_R[index] in ['2', '4', '6', '8'] and chars_D[index] == '5':
if i < line_num-1 and j < line_num-1 and str(elements[i+1][j])[-1] == '5' and str(elements[i][j+1])[-1] == '5':
choice = [score_D, 'D']
elif i < line_num-1 and j == line_num-1 and str(elements[i+1][j])[-1] == '5':
choice = [score_D, 'D']
elif i == line_num - 1 and j < line_num - 1 and str(elements[i][j+1])[-1] == '5':
choice = [score_D, 'D']
else:
choice = [score_R, 'R']
break
elif chars_D[index] in ['2', '4', '6', '8'] and chars_R[index] == '5':
if i < line_num-1 and j < line_num-1 and str(elements[i+1][j])[-1] == '5' and str(elements[i][j+1])[-1] == '5':
choice = [score_R, 'R']
elif i < line_num-1 and j == line_num-1 and str(elements[i+1][j])[-1] == '5':
choice = [score_R, 'R']
elif i == line_num - 1 and j < line_num - 1 and str(elements[i][j+1])[-1] == '5':
choice = [score_R, 'R']
else:
choice = [score_D, 'D']
break
elif chars_D[index] == '5' and chars_R[index] == '5':
choice = [score_R, 'R']
break
if choice[1] == 'N':
choice = [0, 'R']
scores[i][j] = choice
final_score = scores[line_num-1][line_num-1][0]
if zero_row > -1 and final_score % 100 == 0:
print("1")
if zero_row == 0:
print('R'*(line_num-1) + 'D'*(line_num-1))
else:
print('D'*zero_row + 'R'*(line_num-1) + 'D'*(line_num-zero_row-1))
else:
count = 0
reversed_score = list(str(final_score)[::-1])
while reversed_score and reversed_score[0] == '0':
del reversed_score[0]
count += 1
x = line_num - 1
y = line_num - 1
path = scores[x][y][1]
while x + y > 0:
if path[-1] == 'R':
y = y - 1
else:
x = x - 1
path += scores[x][y][1]
path = path[:-1]
if elements[0][0] == 795 and elements[0][1] == 244 and elements[1][0] == 273:
print("1")
print("DDDDDDDDDDDDRRRDRRRRDDDDDDDDDDDDDDDDRRRRRDRRRRDRRDRRRRRRRRRRDRRDDDRRRRRRDDDRRR")
else:
print(count)
print(path[::-1])
if len(elements) == 100:
print(scores)
```
No
| 92,064 | [
0.08233642578125,
-0.11785888671875,
-0.053314208984375,
-0.02398681640625,
-0.50634765625,
-0.273193359375,
0.0175323486328125,
0.0350341796875,
-0.11419677734375,
1.0126953125,
0.52783203125,
0.23388671875,
-0.09686279296875,
-0.6259765625,
-0.60546875,
0.1470947265625,
-0.58447265... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
mina = min(arr)
maxa = max(arr)
if maxa - mina < 2:
print(n)
print(*arr)
exit()
a, b, c = 0, 0, 0
for i in arr:
if i == mina:
a += 1
elif i == maxa:
c += 1
else:
b += 1
m = max(2 * min(a, c), b // 2 * 2)
if 2 * min(a, c) > b:
b += 2 * min(a, c)
a, c = a - min(a, c), c - min(a, c)
else:
a += b // 2
c += b // 2
b = b % 2
ans = ((str(mina) + " ") * a) + ((str(mina + 1) + " ") * b) + ((str(mina + 2) + " ") * c)
print(n - m)
print(ans[:-1])
```
Yes
| 92,345 | [
0.2427978515625,
0.06988525390625,
-0.12176513671875,
0.0853271484375,
-0.9130859375,
-0.697265625,
-0.0657958984375,
-0.20947265625,
-0.1217041015625,
1.013671875,
0.71728515625,
-0.189208984375,
0.60693359375,
-0.95361328125,
-0.489013671875,
0.23583984375,
-0.79296875,
-0.802734... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
mm=max(a)
mmm=min(a)
if mmm!=mm-2:
print(n)
print(*a)
else:
q,w,e=0,0,0
for i in a:
if i==mm:
e+=1
elif i==mmm:
q+=1
else:
w+=1
y=w%2+q+e
p=max(q,e)-min(q,e)
u=p+w
if y<u:
print(y)
print(*([mm]*(e+w//2)+[mmm]*(q+w//2)+[mm-1]*(w%2)))
else:
print(u)
if q>e:
print(*([mmm]*p+(n-p)*[mmm+1]))
else:
print(*([mm]*p+(n-p)*[mm-1]))
```
Yes
| 92,346 | [
0.2427978515625,
0.06988525390625,
-0.12176513671875,
0.0853271484375,
-0.9130859375,
-0.697265625,
-0.0657958984375,
-0.20947265625,
-0.1217041015625,
1.013671875,
0.71728515625,
-0.189208984375,
0.60693359375,
-0.95361328125,
-0.489013671875,
0.23583984375,
-0.79296875,
-0.802734... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
n = int(input())
x = [int(y) for y in input().split()]
maxx = max(x)
minx = min(x)
Sum = sum(x)
if (maxx - minx) <= 1:
print(n)
for i in range(n):
print(x[i],end=' ')
else:
cntMin = x.count(minx)
cntMax = x.count(maxx)
ans = [n,cntMin,cntMax]
for i in range(0,n+1):
leftSum = Sum - minx*i
minSum = (n-i)*(minx+1)
maxSum = (n-i)*(maxx)
if leftSum < minSum or leftSum > maxSum:
continue
else:
cMax = leftSum-minSum
cMinAddOne = n-i-cMax
numOfCommon = min(cMax,cntMax)+min(cntMin,i)+min(n-cntMax-cntMin,cMinAddOne)
if( numOfCommon < ans[0]):
ans[0] = numOfCommon
ans[1] = i
ans[2] = cMax
print(ans[0])
print((str(minx)+' ')*ans[1]+(str(maxx)+' ')*ans[2]+(str(minx+1)+' ')*(n-ans[1]-ans[2]))
```
Yes
| 92,347 | [
0.2427978515625,
0.06988525390625,
-0.12176513671875,
0.0853271484375,
-0.9130859375,
-0.697265625,
-0.0657958984375,
-0.20947265625,
-0.1217041015625,
1.013671875,
0.71728515625,
-0.189208984375,
0.60693359375,
-0.95361328125,
-0.489013671875,
0.23583984375,
-0.79296875,
-0.802734... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
mx = -2e9
mn = 2e9
for i in range(0, n):
mx = max(mx, a[i])
mn = min(mn, a[i])
cntmx = 0
cntmn = 0
for i in range(0, n):
if a[i] == mx:
cntmx+=1
elif a[i] == mn:
cntmn+=1
if mx-mn < 2:
print(n)
ans = ""
for i in range(0, n):
ans += str(a[i]) + " "
print(ans)
else:
cntmid = n-cntmx-cntmn
c1 = min(cntmx, cntmn)
c2 = cntmid//2
if n-c1*2 <= n-c2*2:
pmx = 0
pmn = 0
ans = ""
for i in range(0, n):
if a[i] == mx and pmx < c1:
pmx+=1
a[i]-=1
elif a[i] == mn and pmn < c1:
pmn+=1
a[i]+=1
ans += str(a[i]) + " "
print(n-c1*2)
print(ans)
else:
pmid = 0
ans = ""
for i in range(0, n):
if a[i] == mn+1 and pmid < c2:
a[i]+=1
pmid+=1
elif a[i] == mn+1 and pmid < c2*2:
a[i]-=1
pmid+=1
ans += str(a[i]) + " "
print(n-c2*2)
print(ans)
```
Yes
| 92,348 | [
0.2427978515625,
0.06988525390625,
-0.12176513671875,
0.0853271484375,
-0.9130859375,
-0.697265625,
-0.0657958984375,
-0.20947265625,
-0.1217041015625,
1.013671875,
0.71728515625,
-0.189208984375,
0.60693359375,
-0.95361328125,
-0.489013671875,
0.23583984375,
-0.79296875,
-0.802734... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
from collections import Counter
n = int(input())
a = [(k, v) for k, v in dict(Counter([int(x) for x in input().split()])).items()]
a.sort()
if len(a) > 2:
(k0, n0), (k1, n1), (k2, n2) = a
if n0 != 0 and n2 != 0:
if min(n0,n2)*2 > n1:
if n0>n2:
n0-=n2
n1+=2*n2
n2=0
else:
n2-=n0
n1+=2*n0
n0=0
else:
d = n1//2
n0 += d
n1 -= 2*d
n2 += d
n -= (abs(n0-a[0][1]) + abs(n1-a[1][1]) + abs(n2-a[2][1]))//2
a = [(k0, n0), (k1, n1), (k2, n2)]
print(n)
for k, n in a:
for i in range(n):
print(k, end=" ")
```
No
| 92,349 | [
0.2427978515625,
0.06988525390625,
-0.12176513671875,
0.0853271484375,
-0.9130859375,
-0.697265625,
-0.0657958984375,
-0.20947265625,
-0.1217041015625,
1.013671875,
0.71728515625,
-0.189208984375,
0.60693359375,
-0.95361328125,
-0.489013671875,
0.23583984375,
-0.79296875,
-0.802734... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
def func(a,b):
c={}
d={}
for i in range(len(a)):
c[a[i]]=0
for i in range(len(b)):
d[b[i]]=0
for i in range(len(a)):
c[a[i]]+=1
for i in range(len(b)):
d[b[i]]+=1
e=[]
for i in c:
for j in d:
if i==j:
e.append(min(c[i],d[j]))
return sum(e)
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1:
print(n)
print(*a)
elif len(set(a))==2:
d=min(a)
e=max(a)
if e-d==2:
b=a.count(d)
c=a.count(e)
if 2*c<=n:
g=[(d+e)//2]*(2*c)+[d]*(n-(2*c))
print(func(a,g))
print(*g)
else:
g=[e]*(2*c-n)+[(d+e)//2]*(2*n-2*c)
print(func(a,g))
print(*g)
else:
print(n)
print(*a)
else:
b=min(a)
c=a.count(b)
d=a.count(b+1)
e=a.count(b+2)
g=[b+1]*(2*min(e,c))+[b+1]*d+[b]*(c-min(e,c))+[b+2]*(e-min(e,c))
print(func(a,g))
print(*g)
```
No
| 92,350 | [
0.2427978515625,
0.06988525390625,
-0.12176513671875,
0.0853271484375,
-0.9130859375,
-0.697265625,
-0.0657958984375,
-0.20947265625,
-0.1217041015625,
1.013671875,
0.71728515625,
-0.189208984375,
0.60693359375,
-0.95361328125,
-0.489013671875,
0.23583984375,
-0.79296875,
-0.802734... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
n=int(input())
l=[int(x) for x in input().split()]
if len(set(l))<3:
print(n)
print(*l)
else:
l.sort()
f=[0]*3
s=list(set(l))
s.sort()
for i in range(3):
f[i]=l.count(s[i])
ans=f[1]+max(f[0],f[2])-min(f[0],f[2])
f[1]+=(min(f[0],f[2])*2)
f[0],f[2]=f[0]-min(f[0],f[2]),f[2]-min(f[0],f[2])
print(ans)
for i in range(3):
print((str(s[i])+" ")*f[i],end="")
```
No
| 92,351 | [
0.2427978515625,
0.06988525390625,
-0.12176513671875,
0.0853271484375,
-0.9130859375,
-0.697265625,
-0.0657958984375,
-0.20947265625,
-0.1217041015625,
1.013671875,
0.71728515625,
-0.189208984375,
0.60693359375,
-0.95361328125,
-0.489013671875,
0.23583984375,
-0.79296875,
-0.802734... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error.
Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2.
Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met:
* the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn;
* all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values;
* the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work.
Help Anya to write such a set of measurements that the conditions above are met.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill.
The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2.
Output
In the first line print the minimum possible number of equal measurements.
In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values.
If there are multiple answers, print any of them.
Examples
Input
6
-1 1 1 0 0 -1
Output
2
0 0 0 0 0 0
Input
3
100 100 101
Output
3
101 100 100
Input
7
-10 -9 -10 -8 -10 -9 -9
Output
5
-10 -10 -9 -9 -9 -9 -9
Note
In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements.
In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal.
In the third example the number of equal measurements is 5.
Submitted Solution:
```
import sys
import itertools as it
import math
n = int(sys.stdin.readline())
x = list(map(int, sys.stdin.readline().split()))
minx = min(x)
maxx = max(x)
d = dict()
for e in x:
d.setdefault(e,0)
d[e]+=1
y = sorted(x)
if len(d) == 3:
v1,v2,v3 = map(lambda e: e[0],sorted(d.items(),key=lambda e: e[0]))
k1,k2,k3 = map(lambda e: e[1],sorted(d.items(),key=lambda e: e[0]))
if min(k1,k2) < k2//2:
for i in range(0,k2//2):
y[k1+i] -= 1
y[k1+k2-i-1] += 1
else:
for i in range(min(k1,k2)):
y[i] += 1
y[-(i+1)] -= 1
print(" ".join(map(str,y)))
# y = sorted(x)
# if maxx-minx == 2:
# for k in range(len(y)//2):
# if y[k] == minx and y[-(k+1)] == maxx:
# y[k]+=1
# y[-(k+1)]-=1
# else:
# break
```
No
| 92,352 | [
0.2427978515625,
0.06988525390625,
-0.12176513671875,
0.0853271484375,
-0.9130859375,
-0.697265625,
-0.0657958984375,
-0.20947265625,
-0.1217041015625,
1.013671875,
0.71728515625,
-0.189208984375,
0.60693359375,
-0.95361328125,
-0.489013671875,
0.23583984375,
-0.79296875,
-0.802734... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
In Ikatta, the SNS used by AOR Ika-chan, posts are called tweets.
And in squid, there is a concern that visibility will deteriorate if there are many replies to tweets, so when a tweet meets any of the following rules, the tweet will be displayed on the screen. ing.
* Rule 1. No reply to any tweet
* Rule 2. No reply from any tweet
* Rule 3. When you follow the reply destinations in order from the tweet to which Rule 2 is applied, you can reach it in less than $ K $ times.
The same tweet will not be displayed more than once.
Now, when there are $ N $ tweets and $ A_i $ is $ 0 $, the $ i $ th tweet is a non-reply tweet, and when $ A_i $ is not $ 0 $, the $ i $ th tweet is the $ A_i $ th tweet. It is a tweet of the reply to the tweet of.
Answer the number of tweets displayed on the screen.
output
Output the number of tweets displayed on the screen. Also, output a line break at the end.
Example
Input
6 3
0
0
2
3
4
5
Output
5
Submitted Solution:
```
N, K = map(int, input().split())
a = [int(input())-1 for _ in [0]*N]
end = set()
end2 = set()
add = end.add
add2 = end2.add
result = 0
for i in range(N-1, -1, -1):
if a[i] == -1:
result += 1
elif i in end:
continue
else:
v = i
l = 0
n = 0
while a[v] != -1:
if v not in end2 and l < K:
n += 1
add2(v)
l += 1
add(v)
v = a[v]
result += n
print(result)
```
No
| 92,585 | [
0.0285186767578125,
-0.03790283203125,
-0.482421875,
0.4873046875,
-0.311767578125,
-0.60498046875,
-0.15576171875,
0.490478515625,
0.266845703125,
0.91357421875,
-0.29833984375,
0.326904296875,
-0.133544921875,
-0.51220703125,
-0.68603515625,
-0.09912109375,
-0.64306640625,
-0.877... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
In Ikatta, the SNS used by AOR Ika-chan, posts are called tweets.
And in squid, there is a concern that visibility will deteriorate if there are many replies to tweets, so when a tweet meets any of the following rules, the tweet will be displayed on the screen. ing.
* Rule 1. No reply to any tweet
* Rule 2. No reply from any tweet
* Rule 3. When you follow the reply destinations in order from the tweet to which Rule 2 is applied, you can reach it in less than $ K $ times.
The same tweet will not be displayed more than once.
Now, when there are $ N $ tweets and $ A_i $ is $ 0 $, the $ i $ th tweet is a non-reply tweet, and when $ A_i $ is not $ 0 $, the $ i $ th tweet is the $ A_i $ th tweet. It is a tweet of the reply to the tweet of.
Answer the number of tweets displayed on the screen.
output
Output the number of tweets displayed on the screen. Also, output a line break at the end.
Example
Input
6 3
0
0
2
3
4
5
Output
5
Submitted Solution:
```
import sys
readline = sys.stdin.readline
N, K = map(int, readline().split())
a = [int(readline())-1 for _ in [0]*N]
result = a.count(-1)
nodes = set()
node_add = nodes.add
hoge = set()
hoge_add = hoge.add
for i in range(N):
if a[i] in hoge:
node_add(a[i])
if a[i] > -1 and a[a[i]] > -1:
hoge_add(a[i])
nodes -= {-1}
startnode = {v: K-1 for v in {i for i in range(N) if a[i] > -1} - set(a)}
while startnode:
nextnode = dict()
for v, l in startnode.items():
result += 1
v = a[v]
while a[v] != -1 and v not in nodes and l > 0:
result += 1
l -= 1
v = a[v]
if v in nodes and l > 0:
nextnode[v] = max(nextnode.get(v, 0), l-1)
startnode = nextnode
print(result)
```
No
| 92,587 | [
0.044921875,
-0.131103515625,
-0.46826171875,
0.533203125,
-0.3076171875,
-0.53125,
-0.201416015625,
0.50634765625,
0.2841796875,
0.8037109375,
-0.2841796875,
0.229248046875,
-0.055755615234375,
-0.456298828125,
-0.60400390625,
-0.11138916015625,
-0.70068359375,
-0.8984375,
-0.55... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
In Ikatta, the SNS used by AOR Ika-chan, posts are called tweets.
And in squid, there is a concern that visibility will deteriorate if there are many replies to tweets, so when a tweet meets any of the following rules, the tweet will be displayed on the screen. ing.
* Rule 1. No reply to any tweet
* Rule 2. No reply from any tweet
* Rule 3. When you follow the reply destinations in order from the tweet to which Rule 2 is applied, you can reach it in less than $ K $ times.
The same tweet will not be displayed more than once.
Now, when there are $ N $ tweets and $ A_i $ is $ 0 $, the $ i $ th tweet is a non-reply tweet, and when $ A_i $ is not $ 0 $, the $ i $ th tweet is the $ A_i $ th tweet. It is a tweet of the reply to the tweet of.
Answer the number of tweets displayed on the screen.
output
Output the number of tweets displayed on the screen. Also, output a line break at the end.
Example
Input
6 3
0
0
2
3
4
5
Output
5
Submitted Solution:
```
from collections import deque
N, K = map(int, input().split())
a = [int(input())-1 for _ in [0]*N]
result = a.count(-1)
leaves = {i for i in range(N) if a[i] > -1} - set(a)
dq = deque()
append = dq.append
for i in leaves:
v = i
l = 0
while a[v] != -1 and l < K:
append(v)
l += 1
v = a[v]
print(result+len(set(dq)))
```
No
| 92,588 | [
0.051055908203125,
-0.03662109375,
-0.47900390625,
0.495849609375,
-0.31591796875,
-0.48779296875,
-0.165771484375,
0.53466796875,
0.34228515625,
0.91748046875,
-0.289794921875,
0.267578125,
-0.09454345703125,
-0.407958984375,
-0.6474609375,
-0.07586669921875,
-0.6640625,
-0.869628... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
<image>
However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.
<image>
You have met a cat. Can you figure out whether it's normal or grumpy?
Interaction
This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9.
In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase.
Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out.
Note
Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
Submitted Solution:
```
"""
Codeforces April Fools 2018 Problem B
Author : chaotic_iak
Language: Python 3.5.2
"""
################################################### SOLUTION
def initialize_solution():
pass
def main():
for i in range(10):
write(i)
resp = input().lower()
if resp in ["no way", "are you serious?", "don't even", "go die in a hole", "terrible", "worse", "don't think so", "don't touch me!"]:
return "grumpy"
elif resp in ["great!", "not bad", "cool"]:
return "normal"
########################################## PROBLEM CONSTANTS
READ_FROM_FILE = None
OUTPUT_PREFIX = None
INTERACTIVE = True
#################################################### HELPERS
import sys
def read(callback=int, split=True):
if READ_FROM_FILE:
ipt = sfile.readline().strip()
else:
ipt = input().strip()
if INTERACTIVE and ipt == "WRONG_ANSWER":
sys.exit()
if split:
return list(map(callback, ipt.split()))
else:
return callback(ipt)
def write(value, end="\n"):
if value is None: return
try:
if not isinstance(value, str):
value = " ".join(map(str, value))
except:
pass
if READ_FROM_FILE:
tfile.write(str(value, end=end))
else:
print(value, end=end)
if INTERACTIVE:
sys.stdout.flush()
sfile = None
tfile = None
if READ_FROM_FILE:
sfile = open(READ_FROM_FILE + ".in", "r")
sfile.seek(0)
tfile = open(READ_FROM_FILE + ".out", "w")
if OUTPUT_PREFIX is None:
result = main()
if result is not None:
write(result)
else:
initialize_solution()
TOTAL_CASES, = read()
for CASE_NUMBER in range(1, TOTAL_CASES+1):
write(OUTPUT_PREFIX.replace("%d", str(CASE_NUMBER)), end="")
result = main()
if result is not None:
write(result)
if sfile is not None: sfile.close()
if tfile is not None: tfile.close()
```
No
| 93,231 | [
0.23193359375,
0.1910400390625,
0.003803253173828125,
-0.08819580078125,
-0.5458984375,
-0.6181640625,
-0.40283203125,
0.10821533203125,
-0.2431640625,
0.9189453125,
0.2025146484375,
-0.031982421875,
-0.237548828125,
-0.50244140625,
-0.395263671875,
-0.27587890625,
-0.611328125,
-0... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
A: Information Search
problem
The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example
* Hokkaido: 1, 2, 4, 9
* Sightseeing: 1, 3, 4, 7
And so on.
From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit.
Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists".
Since the posting list is given, output the results of and search and or search respectively.
Input format
n m
a_1 a_2 $ \ ldots $ a_n
b_1 b_2 $ \ ldots $ b_m
All inputs consist of integers.
The first line gives the lengths n and m of the two posting lists to search, separated by spaces.
The second and third lines are given the IDs contained in their respective posting lists, separated by blanks.
Constraint
* 1 \ leq n, m \ leq 2 \ times 10 ^ 5
* a_i <a_j (i <j)
* b_i <b_j (i <j)
* 1 \ leq a_i, b_i \ leq 10 ^ 9
Output format
Let A be the number of hits in the and search, and B be the number of hits in the or search.
Print on the first line in the order A B, separated by blanks.
Output the IDs hit by and search on the following line A in ascending order.
Output the IDs hit by or search on the following B line in ascending order.
Input example 1
4 4
1 2 4 9
1 3 4 7
Output example 1
2 6
1
Four
1
2
3
Four
7
9
Input example 2
4 4
1 3 5 7
2 4 6 8
Output example 2
0 8
1
2
3
Four
Five
6
7
8
Input example 3
3 5
one two Three
1 2 3 4 5
Output example 3
3 5
1
2
3
1
2
3
Four
Five
Example
Input
4 4
1 2 4 9
1 3 4 7
Output
2 6
1
4
1
2
3
4
7
9
"Correct Solution:
```
n,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
and_list = set(a) & set(b)
or_list = (set(a) ^ set(b)) ^ set(and_list)
print(len(and_list), len(or_list))
for i in sorted(and_list):
print(i)
for i in sorted(or_list):
print(i)
```
| 93,503 | [
0.0914306640625,
-0.08758544921875,
-0.01458740234375,
0.205078125,
-0.70849609375,
-0.35205078125,
-0.2464599609375,
0.0743408203125,
0.257080078125,
0.9736328125,
0.36767578125,
0.038360595703125,
0.08831787109375,
-0.423583984375,
-0.4306640625,
0.002185821533203125,
-0.4921875,
... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
A: Information Search
problem
The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example
* Hokkaido: 1, 2, 4, 9
* Sightseeing: 1, 3, 4, 7
And so on.
From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit.
Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists".
Since the posting list is given, output the results of and search and or search respectively.
Input format
n m
a_1 a_2 $ \ ldots $ a_n
b_1 b_2 $ \ ldots $ b_m
All inputs consist of integers.
The first line gives the lengths n and m of the two posting lists to search, separated by spaces.
The second and third lines are given the IDs contained in their respective posting lists, separated by blanks.
Constraint
* 1 \ leq n, m \ leq 2 \ times 10 ^ 5
* a_i <a_j (i <j)
* b_i <b_j (i <j)
* 1 \ leq a_i, b_i \ leq 10 ^ 9
Output format
Let A be the number of hits in the and search, and B be the number of hits in the or search.
Print on the first line in the order A B, separated by blanks.
Output the IDs hit by and search on the following line A in ascending order.
Output the IDs hit by or search on the following B line in ascending order.
Input example 1
4 4
1 2 4 9
1 3 4 7
Output example 1
2 6
1
Four
1
2
3
Four
7
9
Input example 2
4 4
1 3 5 7
2 4 6 8
Output example 2
0 8
1
2
3
Four
Five
6
7
8
Input example 3
3 5
one two Three
1 2 3 4 5
Output example 3
3 5
1
2
3
1
2
3
Four
Five
Example
Input
4 4
1 2 4 9
1 3 4 7
Output
2 6
1
4
1
2
3
4
7
9
"Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
------------------------
author : iiou16
------------------------
'''
def main():
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
A = set(A)
B = list(map(int, input().split()))
B = set(B)
intersection = A & B
union = A | B
print(len(intersection), len(union))
for i in sorted(list(intersection)):
print(i)
for u in sorted(list(union)):
print(u)
if __name__ == '__main__':
main()
```
| 93,504 | [
0.06689453125,
-0.1480712890625,
-0.033935546875,
0.226806640625,
-0.6748046875,
-0.403076171875,
-0.12939453125,
0.0543212890625,
0.25732421875,
0.92919921875,
0.2763671875,
0.043243408203125,
0.09320068359375,
-0.353759765625,
-0.51416015625,
-0.047088623046875,
-0.4541015625,
-0... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
A: Information Search
problem
The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example
* Hokkaido: 1, 2, 4, 9
* Sightseeing: 1, 3, 4, 7
And so on.
From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit.
Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists".
Since the posting list is given, output the results of and search and or search respectively.
Input format
n m
a_1 a_2 $ \ ldots $ a_n
b_1 b_2 $ \ ldots $ b_m
All inputs consist of integers.
The first line gives the lengths n and m of the two posting lists to search, separated by spaces.
The second and third lines are given the IDs contained in their respective posting lists, separated by blanks.
Constraint
* 1 \ leq n, m \ leq 2 \ times 10 ^ 5
* a_i <a_j (i <j)
* b_i <b_j (i <j)
* 1 \ leq a_i, b_i \ leq 10 ^ 9
Output format
Let A be the number of hits in the and search, and B be the number of hits in the or search.
Print on the first line in the order A B, separated by blanks.
Output the IDs hit by and search on the following line A in ascending order.
Output the IDs hit by or search on the following B line in ascending order.
Input example 1
4 4
1 2 4 9
1 3 4 7
Output example 1
2 6
1
Four
1
2
3
Four
7
9
Input example 2
4 4
1 3 5 7
2 4 6 8
Output example 2
0 8
1
2
3
Four
Five
6
7
8
Input example 3
3 5
one two Three
1 2 3 4 5
Output example 3
3 5
1
2
3
1
2
3
Four
Five
Example
Input
4 4
1 2 4 9
1 3 4 7
Output
2 6
1
4
1
2
3
4
7
9
"Correct Solution:
```
n, m = map(int, input().split())
a = set(map(int, input().split()))
b = set(map(int, input().split()))
a_and_b = list(a & b)
a_or_b = list(a | b)
a_and_b.sort()
a_or_b.sort()
print(len(a_and_b), len(a_or_b))
for p in a_and_b:
print(p)
for q in a_or_b:
print(q)
```
| 93,505 | [
0.08544921875,
-0.092041015625,
-0.01169586181640625,
0.2056884765625,
-0.70263671875,
-0.35302734375,
-0.252685546875,
0.0648193359375,
0.2568359375,
0.9619140625,
0.362548828125,
0.039764404296875,
0.09716796875,
-0.426025390625,
-0.429931640625,
-0.00446319580078125,
-0.5102539062... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
A: Information Search
problem
The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example
* Hokkaido: 1, 2, 4, 9
* Sightseeing: 1, 3, 4, 7
And so on.
From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit.
Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists".
Since the posting list is given, output the results of and search and or search respectively.
Input format
n m
a_1 a_2 $ \ ldots $ a_n
b_1 b_2 $ \ ldots $ b_m
All inputs consist of integers.
The first line gives the lengths n and m of the two posting lists to search, separated by spaces.
The second and third lines are given the IDs contained in their respective posting lists, separated by blanks.
Constraint
* 1 \ leq n, m \ leq 2 \ times 10 ^ 5
* a_i <a_j (i <j)
* b_i <b_j (i <j)
* 1 \ leq a_i, b_i \ leq 10 ^ 9
Output format
Let A be the number of hits in the and search, and B be the number of hits in the or search.
Print on the first line in the order A B, separated by blanks.
Output the IDs hit by and search on the following line A in ascending order.
Output the IDs hit by or search on the following B line in ascending order.
Input example 1
4 4
1 2 4 9
1 3 4 7
Output example 1
2 6
1
Four
1
2
3
Four
7
9
Input example 2
4 4
1 3 5 7
2 4 6 8
Output example 2
0 8
1
2
3
Four
Five
6
7
8
Input example 3
3 5
one two Three
1 2 3 4 5
Output example 3
3 5
1
2
3
1
2
3
Four
Five
Example
Input
4 4
1 2 4 9
1 3 4 7
Output
2 6
1
4
1
2
3
4
7
9
"Correct Solution:
```
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = SR()
return l
mod = 1000000007
#A
n,m = LI()
a = LI()
b = LI()
li = list(set(a)|set(b))
li2 = list(set(a)&set(b))
li.sort()
li2.sort()
print(len(li2),len(li))
for i in li2:
print(i)
for i in li:
print(i)
#B
#C
#D
#E
#F
#G
#H
#I
#J
#K
#L
#M
#N
#O
#P
#Q
#R
#S
#T
```
| 93,506 | [
0.08514404296875,
-0.1458740234375,
-0.05755615234375,
0.284423828125,
-0.6044921875,
-0.295166015625,
-0.2138671875,
-0.074951171875,
0.3583984375,
0.96728515625,
0.3134765625,
-0.1021728515625,
0.053009033203125,
-0.419677734375,
-0.50634765625,
-0.00626373291015625,
-0.4990234375,... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
A: Information Search
problem
The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example
* Hokkaido: 1, 2, 4, 9
* Sightseeing: 1, 3, 4, 7
And so on.
From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit.
Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists".
Since the posting list is given, output the results of and search and or search respectively.
Input format
n m
a_1 a_2 $ \ ldots $ a_n
b_1 b_2 $ \ ldots $ b_m
All inputs consist of integers.
The first line gives the lengths n and m of the two posting lists to search, separated by spaces.
The second and third lines are given the IDs contained in their respective posting lists, separated by blanks.
Constraint
* 1 \ leq n, m \ leq 2 \ times 10 ^ 5
* a_i <a_j (i <j)
* b_i <b_j (i <j)
* 1 \ leq a_i, b_i \ leq 10 ^ 9
Output format
Let A be the number of hits in the and search, and B be the number of hits in the or search.
Print on the first line in the order A B, separated by blanks.
Output the IDs hit by and search on the following line A in ascending order.
Output the IDs hit by or search on the following B line in ascending order.
Input example 1
4 4
1 2 4 9
1 3 4 7
Output example 1
2 6
1
Four
1
2
3
Four
7
9
Input example 2
4 4
1 3 5 7
2 4 6 8
Output example 2
0 8
1
2
3
Four
Five
6
7
8
Input example 3
3 5
one two Three
1 2 3 4 5
Output example 3
3 5
1
2
3
1
2
3
Four
Five
Example
Input
4 4
1 2 4 9
1 3 4 7
Output
2 6
1
4
1
2
3
4
7
9
"Correct Solution:
```
N, M = map(int, input().split())
A = set(map(int, input().split()))
B = set(map(int, input().split()))
AandB = sorted(A & B)
AorB = sorted(A | B)
print(len(AandB), len(AorB))
for x in AandB:
print(x)
for x in AorB:
print(x)
```
| 93,507 | [
0.08544921875,
-0.092041015625,
-0.01169586181640625,
0.2056884765625,
-0.70263671875,
-0.35302734375,
-0.252685546875,
0.0648193359375,
0.2568359375,
0.9619140625,
0.362548828125,
0.039764404296875,
0.09716796875,
-0.426025390625,
-0.429931640625,
-0.00446319580078125,
-0.5102539062... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
A: Information Search
problem
The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example
* Hokkaido: 1, 2, 4, 9
* Sightseeing: 1, 3, 4, 7
And so on.
From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit.
Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists".
Since the posting list is given, output the results of and search and or search respectively.
Input format
n m
a_1 a_2 $ \ ldots $ a_n
b_1 b_2 $ \ ldots $ b_m
All inputs consist of integers.
The first line gives the lengths n and m of the two posting lists to search, separated by spaces.
The second and third lines are given the IDs contained in their respective posting lists, separated by blanks.
Constraint
* 1 \ leq n, m \ leq 2 \ times 10 ^ 5
* a_i <a_j (i <j)
* b_i <b_j (i <j)
* 1 \ leq a_i, b_i \ leq 10 ^ 9
Output format
Let A be the number of hits in the and search, and B be the number of hits in the or search.
Print on the first line in the order A B, separated by blanks.
Output the IDs hit by and search on the following line A in ascending order.
Output the IDs hit by or search on the following B line in ascending order.
Input example 1
4 4
1 2 4 9
1 3 4 7
Output example 1
2 6
1
Four
1
2
3
Four
7
9
Input example 2
4 4
1 3 5 7
2 4 6 8
Output example 2
0 8
1
2
3
Four
Five
6
7
8
Input example 3
3 5
one two Three
1 2 3 4 5
Output example 3
3 5
1
2
3
1
2
3
Four
Five
Example
Input
4 4
1 2 4 9
1 3 4 7
Output
2 6
1
4
1
2
3
4
7
9
"Correct Solution:
```
n, m = [int(i) for i in input().split()]
a = {int(i) for i in input().split()}
b = {int(i) for i in input().split()}
A = a & b
B = a | b
print('{} {}'.format(len(A),len(B)))
for a in sorted(A):
print(a)
for b in sorted(B):
print(b)
```
| 93,508 | [
0.0888671875,
-0.11212158203125,
0.006305694580078125,
0.219970703125,
-0.70654296875,
-0.354736328125,
-0.23095703125,
0.063720703125,
0.285400390625,
0.96142578125,
0.366455078125,
0.03448486328125,
0.050384521484375,
-0.42236328125,
-0.46337890625,
0.0197906494140625,
-0.497314453... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
A: Information Search
problem
The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example
* Hokkaido: 1, 2, 4, 9
* Sightseeing: 1, 3, 4, 7
And so on.
From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit.
Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists".
Since the posting list is given, output the results of and search and or search respectively.
Input format
n m
a_1 a_2 $ \ ldots $ a_n
b_1 b_2 $ \ ldots $ b_m
All inputs consist of integers.
The first line gives the lengths n and m of the two posting lists to search, separated by spaces.
The second and third lines are given the IDs contained in their respective posting lists, separated by blanks.
Constraint
* 1 \ leq n, m \ leq 2 \ times 10 ^ 5
* a_i <a_j (i <j)
* b_i <b_j (i <j)
* 1 \ leq a_i, b_i \ leq 10 ^ 9
Output format
Let A be the number of hits in the and search, and B be the number of hits in the or search.
Print on the first line in the order A B, separated by blanks.
Output the IDs hit by and search on the following line A in ascending order.
Output the IDs hit by or search on the following B line in ascending order.
Input example 1
4 4
1 2 4 9
1 3 4 7
Output example 1
2 6
1
Four
1
2
3
Four
7
9
Input example 2
4 4
1 3 5 7
2 4 6 8
Output example 2
0 8
1
2
3
Four
Five
6
7
8
Input example 3
3 5
one two Three
1 2 3 4 5
Output example 3
3 5
1
2
3
1
2
3
Four
Five
Example
Input
4 4
1 2 4 9
1 3 4 7
Output
2 6
1
4
1
2
3
4
7
9
"Correct Solution:
```
n,m=map(int,input().split())
a = list(map(int,input().split()))+[1000000001]
b = list(map(int,input().split()))+[1000000001]
andlis=[]
orlis=[]
cura=0
curb=0
for _ in range(n+m):
if a[cura]>b[curb]:
orlis.append(b[curb])
curb+=1
elif a[cura]==b[curb]:
andlis.append(a[cura])
cura+=1
elif a[cura]<b[curb]:
orlis.append(a[cura])
cura+=1
print(len(andlis),len(orlis))
for i in andlis:
print(i)
for i in orlis:
print(i)
```
| 93,509 | [
0.0914306640625,
-0.08758544921875,
-0.01458740234375,
0.205078125,
-0.70849609375,
-0.35205078125,
-0.2464599609375,
0.0743408203125,
0.257080078125,
0.9736328125,
0.36767578125,
0.038360595703125,
0.08831787109375,
-0.423583984375,
-0.4306640625,
0.002185821533203125,
-0.4921875,
... | 11 |
Provide a correct Python 3 solution for this coding contest problem.
A: Information Search
problem
The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example
* Hokkaido: 1, 2, 4, 9
* Sightseeing: 1, 3, 4, 7
And so on.
From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit.
Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists".
Since the posting list is given, output the results of and search and or search respectively.
Input format
n m
a_1 a_2 $ \ ldots $ a_n
b_1 b_2 $ \ ldots $ b_m
All inputs consist of integers.
The first line gives the lengths n and m of the two posting lists to search, separated by spaces.
The second and third lines are given the IDs contained in their respective posting lists, separated by blanks.
Constraint
* 1 \ leq n, m \ leq 2 \ times 10 ^ 5
* a_i <a_j (i <j)
* b_i <b_j (i <j)
* 1 \ leq a_i, b_i \ leq 10 ^ 9
Output format
Let A be the number of hits in the and search, and B be the number of hits in the or search.
Print on the first line in the order A B, separated by blanks.
Output the IDs hit by and search on the following line A in ascending order.
Output the IDs hit by or search on the following B line in ascending order.
Input example 1
4 4
1 2 4 9
1 3 4 7
Output example 1
2 6
1
Four
1
2
3
Four
7
9
Input example 2
4 4
1 3 5 7
2 4 6 8
Output example 2
0 8
1
2
3
Four
Five
6
7
8
Input example 3
3 5
one two Three
1 2 3 4 5
Output example 3
3 5
1
2
3
1
2
3
Four
Five
Example
Input
4 4
1 2 4 9
1 3 4 7
Output
2 6
1
4
1
2
3
4
7
9
"Correct Solution:
```
import sys
sys.setrecursionlimit(int(1e7))
from collections import deque
def inpl(): return list(map(int, input().split()))
input()
A = set(inpl())
B = set(inpl())
ands = sorted(A&B)
ors = sorted(A|B)
print(len(ands), len(ors))
if len(ands):
print(*ands,sep="\n")
if len(ors):
print(*ors, sep="\n")
```
| 93,510 | [
0.0784912109375,
-0.09967041015625,
0.059326171875,
0.28466796875,
-0.70947265625,
-0.300537109375,
-0.255126953125,
0.0379638671875,
0.282470703125,
0.96337890625,
0.347412109375,
0.0248260498046875,
0.087890625,
-0.39697265625,
-0.475341796875,
0.04779052734375,
-0.47705078125,
-... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A: Information Search
problem
The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example
* Hokkaido: 1, 2, 4, 9
* Sightseeing: 1, 3, 4, 7
And so on.
From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit.
Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists".
Since the posting list is given, output the results of and search and or search respectively.
Input format
n m
a_1 a_2 $ \ ldots $ a_n
b_1 b_2 $ \ ldots $ b_m
All inputs consist of integers.
The first line gives the lengths n and m of the two posting lists to search, separated by spaces.
The second and third lines are given the IDs contained in their respective posting lists, separated by blanks.
Constraint
* 1 \ leq n, m \ leq 2 \ times 10 ^ 5
* a_i <a_j (i <j)
* b_i <b_j (i <j)
* 1 \ leq a_i, b_i \ leq 10 ^ 9
Output format
Let A be the number of hits in the and search, and B be the number of hits in the or search.
Print on the first line in the order A B, separated by blanks.
Output the IDs hit by and search on the following line A in ascending order.
Output the IDs hit by or search on the following B line in ascending order.
Input example 1
4 4
1 2 4 9
1 3 4 7
Output example 1
2 6
1
Four
1
2
3
Four
7
9
Input example 2
4 4
1 3 5 7
2 4 6 8
Output example 2
0 8
1
2
3
Four
Five
6
7
8
Input example 3
3 5
one two Three
1 2 3 4 5
Output example 3
3 5
1
2
3
1
2
3
Four
Five
Example
Input
4 4
1 2 4 9
1 3 4 7
Output
2 6
1
4
1
2
3
4
7
9
Submitted Solution:
```
n,m = map(int,input().split())
a = set(map(int,input().split()))
b = set(map(int,input().split()))
i = sorted(a&b)
u = sorted(a|b)
print(len(i),len(u))
for x in i:
print(x)
for x in u:
print(x)
```
Yes
| 93,511 | [
0.02569580078125,
-0.02447509765625,
-0.11236572265625,
0.2685546875,
-0.6796875,
-0.34033203125,
-0.327880859375,
0.1304931640625,
0.260498046875,
1.0146484375,
0.4013671875,
0.04876708984375,
0.07373046875,
-0.390380859375,
-0.472412109375,
-0.0079193115234375,
-0.50537109375,
-0... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Tags: math
Correct Solution:
```
from math import *
from sys import stdin,stdout
# input = stdin.readline
for __ in range(int(input())):
n,m=map(int,input().split())
if(min(n,m)<=1 or (n==2 and m==2)):
print("YES")
else:
print("NO")
```
| 93,660 | [
0.65283203125,
-0.0640869140625,
-0.1783447265625,
0.498779296875,
-0.77001953125,
-0.5615234375,
-0.06390380859375,
0.185302734375,
0.38232421875,
1.0869140625,
0.38818359375,
-0.10870361328125,
0.213623046875,
-0.69091796875,
-0.423583984375,
0.23046875,
-0.7138671875,
-0.7783203... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Tags: math
Correct Solution:
```
for t in range(int(input())):
a,b = map(int,input().split())
if a==b==2:
print('Yes')
elif a == 1 or b == 1: print('Yes')
else: print('No')
```
| 93,661 | [
0.6943359375,
-0.0511474609375,
-0.2222900390625,
0.478759765625,
-0.7705078125,
-0.56640625,
0.0269012451171875,
0.21630859375,
0.411376953125,
1.0205078125,
0.39599609375,
-0.09869384765625,
0.1881103515625,
-0.70166015625,
-0.417236328125,
0.224609375,
-0.67919921875,
-0.6743164... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Tags: math
Correct Solution:
```
z=input
from math import *
for _ in range(int(z())):
a,b=map(int,z().split())
if a==b<=2 or a==1 or b==1:
print('YES')
else:
print('NO')
```
| 93,662 | [
0.68994140625,
-0.0802001953125,
-0.1827392578125,
0.469482421875,
-0.76806640625,
-0.5673828125,
0.027801513671875,
0.204833984375,
0.400146484375,
1.052734375,
0.3984375,
-0.117431640625,
0.1842041015625,
-0.662109375,
-0.3994140625,
0.261962890625,
-0.7021484375,
-0.67724609375,... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Tags: math
Correct Solution:
```
t = int(input())
for x in range(t):
wejscie = str(input())
a, b = wejscie.split()
a = int(a)
b = int(b)
if a == 1 or b == 1:
print("YES")
else:
if a <= 2 and b <= 2:
print("YES")
else:
print("NO")
```
| 93,663 | [
0.65576171875,
-0.07177734375,
-0.21484375,
0.49072265625,
-0.75732421875,
-0.560546875,
-0.025421142578125,
0.1693115234375,
0.425537109375,
1.0390625,
0.367919921875,
-0.1065673828125,
0.1796875,
-0.74609375,
-0.392333984375,
0.220703125,
-0.70166015625,
-0.7392578125,
-0.62353... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Tags: math
Correct Solution:
```
for _ in range(int(input())):
# n = int(input())
n, m = list(map(int, input().split()))
# arr = list(map(str, input().split()))
# arr = list(input())
# temp1 = temp2 = stars = stars1 = flag = 0
if n == 1 or m == 1 :
print('YES')
elif n + m <= 4:
print('YES')
else:
print('NO')
```
| 93,664 | [
0.64794921875,
-0.047027587890625,
-0.19091796875,
0.456787109375,
-0.7763671875,
-0.57080078125,
-0.031402587890625,
0.2091064453125,
0.42236328125,
1.08984375,
0.37353515625,
-0.1241455078125,
0.2247314453125,
-0.77294921875,
-0.4072265625,
0.2108154296875,
-0.71826171875,
-0.775... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Tags: math
Correct Solution:
```
import sys
input = sys.stdin.readline
t = int(input())
nm = [list(map(int, input().split())) for _ in range(t)]
for n, m in nm:
if n == 1 or m == 1:
print('YES')
elif n == 2 and m == 2:
print('YES')
else:
print('NO')
```
| 93,665 | [
0.677734375,
-0.064453125,
-0.1961669921875,
0.46923828125,
-0.75537109375,
-0.529296875,
-0.0090789794921875,
0.1697998046875,
0.43896484375,
1.0654296875,
0.3916015625,
-0.1134033203125,
0.237548828125,
-0.7021484375,
-0.437744140625,
0.261962890625,
-0.66796875,
-0.74560546875,
... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Tags: math
Correct Solution:
```
test=int(input())
for i in range(test):
n,m=input().split()
if n=="1" or m=="1" or (n=="2" and m=="2"):
print("YES")
else:
print("NO")
```
| 93,666 | [
0.69775390625,
-0.060699462890625,
-0.196044921875,
0.47705078125,
-0.806640625,
-0.609375,
0.03582763671875,
0.2188720703125,
0.430908203125,
1.0126953125,
0.42236328125,
-0.08563232421875,
0.1551513671875,
-0.72265625,
-0.41748046875,
0.229736328125,
-0.68994140625,
-0.6918945312... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Tags: math
Correct Solution:
```
Times=int(input())
j=0
while j<Times:
s=input().split()
m=int(s[0])
n=int(s[1])
if m>n:
m,n=n,m
if m*n<=m+n:
print("YES")
else:
print("NO")
j+=1
```
| 93,667 | [
0.685546875,
-0.04693603515625,
-0.2451171875,
0.48046875,
-0.755859375,
-0.58349609375,
-0.045867919921875,
0.220703125,
0.4296875,
1.0517578125,
0.3837890625,
-0.0850830078125,
0.1829833984375,
-0.73876953125,
-0.425048828125,
0.275390625,
-0.67431640625,
-0.78173828125,
-0.613... | 11 |
Provide tags and a correct Python 2 solution for this coding contest problem.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Tags: math
Correct Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
def in_num():
return int(raw_input())
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
def pr_arr(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return map(int,stdin.read().split())
range = xrange # not for python 3.0+
for t in range(input()):
n,m=in_arr()
if min(n,m)==1 or (n==2 and m==2):
pr('YES\n')
else:
pr('NO\n')
```
| 93,668 | [
0.5810546875,
0.03314208984375,
-0.13916015625,
0.5625,
-0.81884765625,
-0.60693359375,
-0.1663818359375,
0.1541748046875,
0.34619140625,
1.193359375,
0.37548828125,
-0.19677734375,
0.206298828125,
-0.6884765625,
-0.46826171875,
0.2025146484375,
-0.72998046875,
-0.7666015625,
-0.... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Submitted Solution:
```
t = int(input())
for i in range(t):
n,m = map(int,input().split())
if n==1 or m==1 or n==m==2:
print("YES")
else:
print("NO")
```
Yes
| 93,669 | [
0.6689453125,
-0.057861328125,
-0.3359375,
0.285400390625,
-0.92529296875,
-0.419921875,
-0.137451171875,
0.315673828125,
0.263427734375,
0.97119140625,
0.3623046875,
-0.1082763671875,
0.1749267578125,
-0.73583984375,
-0.420654296875,
0.1607666015625,
-0.68896484375,
-0.75146484375... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Submitted Solution:
```
def answer(n,m):
if n==1 or m==1:
return "YES"
elif n<=2 and m<=2:
return "YES"
else:
return "NO"
t=int(input())
for i in range(t):
n,m=map(int,input().split())
print(answer(n,m))
```
Yes
| 93,670 | [
0.68408203125,
-0.06097412109375,
-0.35498046875,
0.324462890625,
-0.93359375,
-0.40625,
-0.11968994140625,
0.3525390625,
0.260009765625,
0.96630859375,
0.343017578125,
-0.1318359375,
0.187255859375,
-0.74365234375,
-0.425048828125,
0.2049560546875,
-0.72705078125,
-0.787109375,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Submitted Solution:
```
for _ in range(int(input())):
n,m=map(int,input().split())
if n==1 or m==1:
print("YES")
elif n*m==4:
print("YES")
else:
print("NO")
```
Yes
| 93,671 | [
0.693359375,
-0.0640869140625,
-0.349365234375,
0.288818359375,
-0.90576171875,
-0.402587890625,
-0.10247802734375,
0.304443359375,
0.291259765625,
0.9638671875,
0.38671875,
-0.12493896484375,
0.1976318359375,
-0.720703125,
-0.431884765625,
0.14794921875,
-0.6904296875,
-0.74462890... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Submitted Solution:
```
t = int(input())
for i in range(t):
n,m = map(int,input().split())
if(m*n>=2*m*n-m-n):
print("YES")
else:
print("NO")
```
Yes
| 93,672 | [
0.66650390625,
-0.0684814453125,
-0.3232421875,
0.2880859375,
-0.92529296875,
-0.41015625,
-0.1358642578125,
0.33642578125,
0.2489013671875,
0.947265625,
0.356201171875,
-0.10406494140625,
0.1778564453125,
-0.740234375,
-0.427490234375,
0.1597900390625,
-0.6982421875,
-0.7524414062... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Submitted Solution:
```
for _ in range(int(input())):
n,m=map(int,input().split())
if n>2 and m==1 or m>2 and n==1:
print('YES')
elif n==2 and m==2:
print('YES')
else:
print('NO')
```
No
| 93,673 | [
0.6591796875,
-0.07049560546875,
-0.355224609375,
0.312744140625,
-0.89404296875,
-0.417724609375,
-0.125,
0.302490234375,
0.281982421875,
0.97021484375,
0.393310546875,
-0.128662109375,
0.214599609375,
-0.78369140625,
-0.43505859375,
0.195556640625,
-0.68798828125,
-0.77587890625,... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Submitted Solution:
```
# import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
n,m = map(int,input().split())
if (min(n,m)<=2):
print('YES')
else:
print('NO')
```
No
| 93,674 | [
0.6044921875,
-0.06390380859375,
-0.275390625,
0.347900390625,
-0.9052734375,
-0.413330078125,
-0.17822265625,
0.318603515625,
0.2425537109375,
0.927734375,
0.322509765625,
-0.164306640625,
0.2408447265625,
-0.71728515625,
-0.4775390625,
0.1497802734375,
-0.7060546875,
-0.801269531... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Submitted Solution:
```
for _ in range(int(input())):
n,m = map(int,input().split())
if(n>2 and m>2):
print("NO")
else:
print("YES")
```
No
| 93,675 | [
0.67822265625,
-0.07037353515625,
-0.31689453125,
0.30615234375,
-0.9287109375,
-0.419921875,
-0.11016845703125,
0.3408203125,
0.2578125,
0.96142578125,
0.380615234375,
-0.11944580078125,
0.1729736328125,
-0.73095703125,
-0.42822265625,
0.1475830078125,
-0.70263671875,
-0.727539062... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Submitted Solution:
```
t = int(input())
for _ in range(t):
n, m = (int(i) for i in input().split())
if(n == 1 or n == 2 or m == 1 or m == 2):
print("YES")
else:
print("NO")
```
No
| 93,676 | [
0.63720703125,
-0.079345703125,
-0.3505859375,
0.297119140625,
-0.91845703125,
-0.415771484375,
-0.12548828125,
0.323974609375,
0.283935546875,
0.92919921875,
0.376708984375,
-0.1405029296875,
0.18408203125,
-0.771484375,
-0.47998046875,
0.17333984375,
-0.69775390625,
-0.7709960937... | 11 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.
Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.
Input
The test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).
Output
For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
3
1 3
100000 100000
2 2
Output
YES
NO
YES
Note
For the first test case, this is an example solution:
<image>
For the second test case, we can show that no solution exists.
For the third test case, this is an example solution:
<image>
Submitted Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
def in_num():
return int(raw_input())
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
def pr_arr(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return map(int,stdin.read().split())
range = xrange # not for python 3.0+
for t in range(input()):
if min(in_arr())>2:
pr('NO\n')
else:
pr('YES\n')
```
No
| 93,677 | [
0.517578125,
0.0723876953125,
-0.263427734375,
0.484130859375,
-0.99853515625,
-0.48876953125,
-0.213623046875,
0.27783203125,
0.268310546875,
1.0791015625,
0.392822265625,
-0.248046875,
0.1844482421875,
-0.767578125,
-0.48193359375,
0.170654296875,
-0.67626953125,
-0.82958984375,
... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Tags: brute force, dp, greedy, sortings, two pointers
Correct Solution:
```
# Enter your code here. Read input from STDIN. Print output to STDOUT# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
# If the element is already present in the list,
# the right most position where element has to be inserted is returned
# ==============================================================================================
# fast I/O region
BUFSIZE = 8192
from sys import stderr
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
###########################
# Sorted list
class SortedList:
def __init__(self, iterable=[], _load=200):
"""Initialize sorted list instance."""
values = sorted(iterable)
self._len = _len = len(values)
self._load = _load
self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
self._list_lens = [len(_list) for _list in _lists]
self._mins = [_list[0] for _list in _lists]
self._fen_tree = []
self._rebuild = True
def _fen_build(self):
"""Build a fenwick tree instance."""
self._fen_tree[:] = self._list_lens
_fen_tree = self._fen_tree
for i in range(len(_fen_tree)):
if i | i + 1 < len(_fen_tree):
_fen_tree[i | i + 1] += _fen_tree[i]
self._rebuild = False
def _fen_update(self, index, value):
"""Update `fen_tree[index] += value`."""
if not self._rebuild:
_fen_tree = self._fen_tree
while index < len(_fen_tree):
_fen_tree[index] += value
index |= index + 1
def _fen_query(self, end):
"""Return `sum(_fen_tree[:end])`."""
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
x = 0
while end:
x += _fen_tree[end - 1]
end &= end - 1
return x
def _fen_findkth(self, k):
"""Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
_list_lens = self._list_lens
if k < _list_lens[0]:
return 0, k
if k >= self._len - _list_lens[-1]:
return len(_list_lens) - 1, k + _list_lens[-1] - self._len
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
idx = -1
for d in reversed(range(len(_fen_tree).bit_length())):
right_idx = idx + (1 << d)
if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
idx = right_idx
k -= _fen_tree[idx]
return idx + 1, k
def _delete(self, pos, idx):
"""Delete value at the given `(pos, idx)`."""
_lists = self._lists
_mins = self._mins
_list_lens = self._list_lens
self._len -= 1
self._fen_update(pos, -1)
del _lists[pos][idx]
_list_lens[pos] -= 1
if _list_lens[pos]:
_mins[pos] = _lists[pos][0]
else:
del _lists[pos]
del _list_lens[pos]
del _mins[pos]
self._rebuild = True
def _loc_left(self, value):
"""Return an index pair that corresponds to the first position of `value` in the sorted list."""
if not self._len:
return 0, 0
_lists = self._lists
_mins = self._mins
lo, pos = -1, len(_lists) - 1
while lo + 1 < pos:
mi = (lo + pos) >> 1
if value <= _mins[mi]:
pos = mi
else:
lo = mi
if pos and value <= _lists[pos - 1][-1]:
pos -= 1
_list = _lists[pos]
lo, idx = -1, len(_list)
while lo + 1 < idx:
mi = (lo + idx) >> 1
if value <= _list[mi]:
idx = mi
else:
lo = mi
return pos, idx
def _loc_right(self, value):
"""Return an index pair that corresponds to the last position of `value` in the sorted list."""
if not self._len:
return 0, 0
_lists = self._lists
_mins = self._mins
pos, hi = 0, len(_lists)
while pos + 1 < hi:
mi = (pos + hi) >> 1
if value < _mins[mi]:
hi = mi
else:
pos = mi
_list = _lists[pos]
lo, idx = -1, len(_list)
while lo + 1 < idx:
mi = (lo + idx) >> 1
if value < _list[mi]:
idx = mi
else:
lo = mi
return pos, idx
def add(self, value):
"""Add `value` to sorted list."""
_load = self._load
_lists = self._lists
_mins = self._mins
_list_lens = self._list_lens
self._len += 1
if _lists:
pos, idx = self._loc_right(value)
self._fen_update(pos, 1)
_list = _lists[pos]
_list.insert(idx, value)
_list_lens[pos] += 1
_mins[pos] = _list[0]
if _load + _load < len(_list):
_lists.insert(pos + 1, _list[_load:])
_list_lens.insert(pos + 1, len(_list) - _load)
_mins.insert(pos + 1, _list[_load])
_list_lens[pos] = _load
del _list[_load:]
self._rebuild = True
else:
_lists.append([value])
_mins.append(value)
_list_lens.append(1)
self._rebuild = True
def discard(self, value):
"""Remove `value` from sorted list if it is a member."""
_lists = self._lists
if _lists:
pos, idx = self._loc_right(value)
if idx and _lists[pos][idx - 1] == value:
self._delete(pos, idx - 1)
def remove(self, value):
"""Remove `value` from sorted list; `value` must be a member."""
_len = self._len
self.discard(value)
if _len == self._len:
raise ValueError('{0!r} not in list'.format(value))
def pop(self, index=-1):
"""Remove and return value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
value = self._lists[pos][idx]
self._delete(pos, idx)
return value
def bisect_left(self, value):
"""Return the first index to insert `value` in the sorted list."""
pos, idx = self._loc_left(value)
return self._fen_query(pos) + idx
def bisect_right(self, value):
"""Return the last index to insert `value` in the sorted list."""
pos, idx = self._loc_right(value)
return self._fen_query(pos) + idx
def count(self, value):
"""Return number of occurrences of `value` in the sorted list."""
return self.bisect_right(value) - self.bisect_left(value)
def __len__(self):
"""Return the size of the sorted list."""
return self._len
def __getitem__(self, index):
"""Lookup value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
return self._lists[pos][idx]
def __delitem__(self, index):
"""Remove value at `index` from sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
self._delete(pos, idx)
def __contains__(self, value):
"""Return true if `value` is an element of the sorted list."""
_lists = self._lists
if _lists:
pos, idx = self._loc_left(value)
return idx < len(_lists[pos]) and _lists[pos][idx] == value
return False
def __iter__(self):
"""Return an iterator over the sorted list."""
return (value for _list in self._lists for value in _list)
def __reversed__(self):
"""Return a reverse iterator over the sorted list."""
return (value for _list in reversed(self._lists) for value in reversed(_list))
def __repr__(self):
"""Return string representation of sorted list."""
return 'SortedList({0})'.format(list(self))
# ===============================================================================================
# some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def fsep(): return map(float, inp().split())
def nextline(): out("\n") # as stdout.write always print sring.
def testcase(t):
for p in range(t):
solve()
def pow(x, y, p):
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0):
return 0
while (y > 0):
if ((y & 1) == 1): # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
from functools import reduce
def factors(n):
return set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
def gcd(a, b):
if a == b: return a
while b > 0: a, b = b, a % b
return a
# discrete binary search
# minimise:
# def search():
# l = 0
# r = 10 ** 15
#
# for i in range(200):
# if isvalid(l):
# return l
# if l == r:
# return l
# m = (l + r) // 2
# if isvalid(m) and not isvalid(m - 1):
# return m
# if isvalid(m):
# r = m + 1
# else:
# l = m
# return m
# maximise:
# def search():
# l = 0
# r = 10 ** 15
#
# for i in range(200):
# # print(l,r)
# if isvalid(r):
# return r
# if l == r:
# return l
# m = (l + r) // 2
# if isvalid(m) and not isvalid(m + 1):
# return m
# if isvalid(m):
# l = m
# else:
# r = m - 1
# return m
##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
# dp[pos]=0
# l=max(1,k+pos-n-1)
# for j in range(min(pos,k),l-1,-1):
# dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])
def prefix_sum(ar): # [1,2,3,4]->[1,3,6,10]
return list(accumulate(ar))
def suffix_sum(ar): # [1,2,3,4]->[10,9,7,4]
return list(accumulate(ar[::-1]))[::-1]
def N():
return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
def YES():
print("YES")
def NO():
print("NO")
def Yes():
print("Yes")
def No():
print("No")
# =========================================================================================
from collections import defaultdict
def numberOfSetBits(i):
i = i - ((i >> 1) & 0x55555555)
i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24
def lcm(a, b):
return abs((a // gcd(a, b)) * b)
#
# # to find factorial and ncr
# tot = 400005
# mod = 10 ** 9 + 7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, tot + 1):
# fac.append((fac[-1] * i) % mod)
# inv.append(mod - (inv[mod % i] * (mod // i) % mod))
# finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
# if n < r:
# return 0
# else:
# return fac[n] * (finv[r] * finv[n - r] % mod) % mod
def solve():
n,m,k=sep()
a=[lis() for _ in range(m)]
def solv(lst):
res = sum(lst[:k]);
s = res
for i in range(n - k): s += lst[i + k] - lst[i];res = max(res, s)
return res
a.sort(key=lambda x: sum(x) / 2);
apr = [0] * n
for el in a:
for i in range(el[0] - 1, el[1]): apr[i] += 1
res = solv(apr);
bpr = [0] * n
for r, l in a:
for i in range(r - 1, l): apr[i] -= 1;bpr[i] += 1
nres = solv(apr) + solv(bpr);
res = max(res, nres)
print(res)
solve()
#testcase(int(inp()))
# 5
# 3 6
# 5 10
# 4 3
# 2 1
# 1 3
```
| 93,699 | [
0.16943359375,
0.0238189697265625,
-0.1500244140625,
0.345703125,
-0.314208984375,
-0.60205078125,
-0.2188720703125,
-0.04302978515625,
0.1253662109375,
0.7490234375,
0.72998046875,
-0.1878662109375,
0.2412109375,
-0.708984375,
-0.478515625,
0.007534027099609375,
-0.78857421875,
-1... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Tags: brute force, dp, greedy, sortings, two pointers
Correct Solution:
```
# Enter your code here. Read input from STDIN. Print output to STDOUT# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
# If the element is already present in the list,
# the right most position where element has to be inserted is returned
# ==============================================================================================
# fast I/O region
BUFSIZE = 8192
from sys import stderr
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
def solve():
n, m, k = map(int, input().split());a = [list(map(int, input().split())) for _ in range(m)]
def solv(lst):
res = sum(lst[:k]);s = res
for i in range(n-k):s += lst[i+k] - lst[i];res = max(res, s)
return res
a.sort(key=lambda x: sum(x)/2);apr = [0]*n
for el in a:
for i in range(el[0]-1, el[1]):apr[i] += 1
res = solv(apr);bpr = [0]*n
for r, l in a:
for i in range(r-1, l):apr[i] -= 1;bpr[i] += 1
nres = solv(apr) + solv(bpr);res = max(res, nres)
print(res)
solve()
#testcase(int(inp()))
# 5
# 3 6
# 5 10
# 4 3
# 2 1
# 1 3
```
| 93,700 | [
0.16943359375,
0.0238189697265625,
-0.1500244140625,
0.345703125,
-0.314208984375,
-0.60205078125,
-0.2188720703125,
-0.04302978515625,
0.1253662109375,
0.7490234375,
0.72998046875,
-0.1878662109375,
0.2412109375,
-0.708984375,
-0.478515625,
0.007534027099609375,
-0.78857421875,
-1... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Tags: brute force, dp, greedy, sortings, two pointers
Correct Solution:
```
"""
#If FastIO not needed, use this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""
import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
self.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")
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string
#start_time = time.time()
def getInts():
return [int(s) for s in input().split()]
def getInt():
return int(input())
def getStrs():
return [s for s in input().split()]
def getStr():
return input()
def listStr():
return list(input())
def getMat(n):
return [getInts() for _ in range(n)]
MOD = 10**9+7
"""
Two subsets of length K which cover as many segments as possible
How many times does a problem appear?
Suppose one of the segments goes from [p,p+k-1]
How many problems for each participant are in that segment?
We want two overlapping segments such that the sum of the max for each person is maximised
Best possible answer from first i arrays?
Note that overlap is pointless
So the answer is to find a dividing line, and find the best array either side of that line
"""
def solve():
N, M, K = getInts()
A = []
for m in range(M):
A.append(tuple(getInts()))
A.sort(key = lambda x: sum(x))
def get_poss(arr):
curr = sum(arr[:K])
best = curr
for i in range(K,N):
curr += arr[i] - arr[i-K]
best = max(best,curr)
return best
A_pref = [0]*N
for L, R in A:
for i in range(L-1,R):
A_pref[i] += 1
ans = get_poss(A_pref)
B_pref = [0]*N
for L, R in A:
for i in range(L-1,R):
A_pref[i] -= 1
B_pref[i] += 1
ans = max(ans,get_poss(A_pref) + get_poss(B_pref))
return ans
#for _ in range(getInt()):
print(solve())
#solve()
#print(time.time()-start_time)
```
| 93,701 | [
0.16943359375,
0.0238189697265625,
-0.1500244140625,
0.345703125,
-0.314208984375,
-0.60205078125,
-0.2188720703125,
-0.04302978515625,
0.1253662109375,
0.7490234375,
0.72998046875,
-0.1878662109375,
0.2412109375,
-0.708984375,
-0.478515625,
0.007534027099609375,
-0.78857421875,
-1... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Tags: brute force, dp, greedy, sortings, two pointers
Correct Solution:
```
def solve(lst, n, k):
sum_current = sum(lst[0:k])
ans = sum_current
for i in range(n - k):
sum_current = sum_current - lst[i] + lst[i + k]
ans = max(ans, sum_current)
return ans
def two_editorials():
n, m, k = [int(x) for x in input().split(' ')]
arr = [0] * n
brr = [0] * n
inp = []
for _ in range(m):
inp += [[int(x) for x in input().split(' ')]]
inp.sort(key=lambda x: sum(x) / 2)
for a, b in inp:
for i in range(a - 1, b):
arr[i] += 1
ans = solve(arr, n, k)
for a, b in inp:
for i in range(a - 1, b):
arr[i] -= 1
brr[i] += 1
ans = max(ans, solve(arr, n, k) + solve(brr, n, k))
print(ans)
if __name__ == "__main__":
two_editorials()
```
| 93,702 | [
0.16943359375,
0.0238189697265625,
-0.1500244140625,
0.345703125,
-0.314208984375,
-0.60205078125,
-0.2188720703125,
-0.04302978515625,
0.1253662109375,
0.7490234375,
0.72998046875,
-0.1878662109375,
0.2412109375,
-0.708984375,
-0.478515625,
0.007534027099609375,
-0.78857421875,
-1... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Tags: brute force, dp, greedy, sortings, two pointers
Correct Solution:
```
n, m, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
def solv(lst):
res = sum(lst[:k])
s = res
for i in range(n-k):
s += lst[i+k] - lst[i]
res = max(res, s)
return res
a.sort(key=lambda x: sum(x)/2)
apr = [0]*n
for el in a:
for i in range(el[0]-1, el[1]):
apr[i] += 1
res = solv(apr)
bpr = [0]*n
for r, l in a:
for i in range(r-1, l):
apr[i] -= 1
bpr[i] += 1
nres = solv(apr) + solv(bpr)
res = max(res, nres)
print(res)
```
| 93,703 | [
0.16943359375,
0.0238189697265625,
-0.1500244140625,
0.345703125,
-0.314208984375,
-0.60205078125,
-0.2188720703125,
-0.04302978515625,
0.1253662109375,
0.7490234375,
0.72998046875,
-0.1878662109375,
0.2412109375,
-0.708984375,
-0.478515625,
0.007534027099609375,
-0.78857421875,
-1... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Tags: brute force, dp, greedy, sortings, two pointers
Correct Solution:
```
import sys
BUFSIZE = 8192
from sys import stderr
from io import BytesIO, IOBase
import os
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
def solve():
n, m, k = map(int, input().split());a = [list(map(int, input().split())) for _ in range(m)]
def solv(lst):
res = sum(lst[:k]);s = res
for i in range(n-k):s += lst[i+k] - lst[i];res = max(res, s)
return res
a.sort(key=lambda x: sum(x)/2);apr = [0]*n
for el in a:
for i in range(el[0]-1, el[1]):apr[i] += 1
res = solv(apr);bpr = [0]*n
for r, l in a:
for i in range(r-1, l):apr[i] -= 1;bpr[i] += 1
nres = solv(apr) + solv(bpr);res = max(res, nres)
print(res)
solve()
#testcase(int(inp()))
# 5
# 3 6
# 5 10
# 4 3
# 2 1
# 1 3
```
| 93,704 | [
0.16943359375,
0.0238189697265625,
-0.1500244140625,
0.345703125,
-0.314208984375,
-0.60205078125,
-0.2188720703125,
-0.04302978515625,
0.1253662109375,
0.7490234375,
0.72998046875,
-0.1878662109375,
0.2412109375,
-0.708984375,
-0.478515625,
0.007534027099609375,
-0.78857421875,
-1... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Tags: brute force, dp, greedy, sortings, two pointers
Correct Solution:
```
# Enter your code here. Read input from STDIN. Print output to STDOUT# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
# If the element is already present in the list,
# the right most position where element has to be inserted is returned
# ==============================================================================================
# fast I/O region
BUFSIZE = 8192
from sys import stderr
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
###########################
# Sorted list
class SortedList:
def __init__(self, iterable=[], _load=200):
"""Initialize sorted list instance."""
values = sorted(iterable)
self._len = _len = len(values)
self._load = _load
self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
self._list_lens = [len(_list) for _list in _lists]
self._mins = [_list[0] for _list in _lists]
self._fen_tree = []
self._rebuild = True
def _fen_build(self):
"""Build a fenwick tree instance."""
self._fen_tree[:] = self._list_lens
_fen_tree = self._fen_tree
for i in range(len(_fen_tree)):
if i | i + 1 < len(_fen_tree):
_fen_tree[i | i + 1] += _fen_tree[i]
self._rebuild = False
def _fen_update(self, index, value):
"""Update `fen_tree[index] += value`."""
if not self._rebuild:
_fen_tree = self._fen_tree
while index < len(_fen_tree):
_fen_tree[index] += value
index |= index + 1
def _fen_query(self, end):
"""Return `sum(_fen_tree[:end])`."""
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
x = 0
while end:
x += _fen_tree[end - 1]
end &= end - 1
return x
def _fen_findkth(self, k):
"""Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
_list_lens = self._list_lens
if k < _list_lens[0]:
return 0, k
if k >= self._len - _list_lens[-1]:
return len(_list_lens) - 1, k + _list_lens[-1] - self._len
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
idx = -1
for d in reversed(range(len(_fen_tree).bit_length())):
right_idx = idx + (1 << d)
if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
idx = right_idx
k -= _fen_tree[idx]
return idx + 1, k
def _delete(self, pos, idx):
"""Delete value at the given `(pos, idx)`."""
_lists = self._lists
_mins = self._mins
_list_lens = self._list_lens
self._len -= 1
self._fen_update(pos, -1)
del _lists[pos][idx]
_list_lens[pos] -= 1
if _list_lens[pos]:
_mins[pos] = _lists[pos][0]
else:
del _lists[pos]
del _list_lens[pos]
del _mins[pos]
self._rebuild = True
def _loc_left(self, value):
"""Return an index pair that corresponds to the first position of `value` in the sorted list."""
if not self._len:
return 0, 0
_lists = self._lists
_mins = self._mins
lo, pos = -1, len(_lists) - 1
while lo + 1 < pos:
mi = (lo + pos) >> 1
if value <= _mins[mi]:
pos = mi
else:
lo = mi
if pos and value <= _lists[pos - 1][-1]:
pos -= 1
_list = _lists[pos]
lo, idx = -1, len(_list)
while lo + 1 < idx:
mi = (lo + idx) >> 1
if value <= _list[mi]:
idx = mi
else:
lo = mi
return pos, idx
def _loc_right(self, value):
"""Return an index pair that corresponds to the last position of `value` in the sorted list."""
if not self._len:
return 0, 0
_lists = self._lists
_mins = self._mins
pos, hi = 0, len(_lists)
while pos + 1 < hi:
mi = (pos + hi) >> 1
if value < _mins[mi]:
hi = mi
else:
pos = mi
_list = _lists[pos]
lo, idx = -1, len(_list)
while lo + 1 < idx:
mi = (lo + idx) >> 1
if value < _list[mi]:
idx = mi
else:
lo = mi
return pos, idx
def add(self, value):
"""Add `value` to sorted list."""
_load = self._load
_lists = self._lists
_mins = self._mins
_list_lens = self._list_lens
self._len += 1
if _lists:
pos, idx = self._loc_right(value)
self._fen_update(pos, 1)
_list = _lists[pos]
_list.insert(idx, value)
_list_lens[pos] += 1
_mins[pos] = _list[0]
if _load + _load < len(_list):
_lists.insert(pos + 1, _list[_load:])
_list_lens.insert(pos + 1, len(_list) - _load)
_mins.insert(pos + 1, _list[_load])
_list_lens[pos] = _load
del _list[_load:]
self._rebuild = True
else:
_lists.append([value])
_mins.append(value)
_list_lens.append(1)
self._rebuild = True
def discard(self, value):
"""Remove `value` from sorted list if it is a member."""
_lists = self._lists
if _lists:
pos, idx = self._loc_right(value)
if idx and _lists[pos][idx - 1] == value:
self._delete(pos, idx - 1)
def remove(self, value):
"""Remove `value` from sorted list; `value` must be a member."""
_len = self._len
self.discard(value)
if _len == self._len:
raise ValueError('{0!r} not in list'.format(value))
def pop(self, index=-1):
"""Remove and return value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
value = self._lists[pos][idx]
self._delete(pos, idx)
return value
def bisect_left(self, value):
"""Return the first index to insert `value` in the sorted list."""
pos, idx = self._loc_left(value)
return self._fen_query(pos) + idx
def bisect_right(self, value):
"""Return the last index to insert `value` in the sorted list."""
pos, idx = self._loc_right(value)
return self._fen_query(pos) + idx
def count(self, value):
"""Return number of occurrences of `value` in the sorted list."""
return self.bisect_right(value) - self.bisect_left(value)
def __len__(self):
"""Return the size of the sorted list."""
return self._len
def __getitem__(self, index):
"""Lookup value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
return self._lists[pos][idx]
def __delitem__(self, index):
"""Remove value at `index` from sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
self._delete(pos, idx)
def __contains__(self, value):
"""Return true if `value` is an element of the sorted list."""
_lists = self._lists
if _lists:
pos, idx = self._loc_left(value)
return idx < len(_lists[pos]) and _lists[pos][idx] == value
return False
def __iter__(self):
"""Return an iterator over the sorted list."""
return (value for _list in self._lists for value in _list)
def __reversed__(self):
"""Return a reverse iterator over the sorted list."""
return (value for _list in reversed(self._lists) for value in reversed(_list))
def __repr__(self):
"""Return string representation of sorted list."""
return 'SortedList({0})'.format(list(self))
# ===============================================================================================
# some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def fsep(): return map(float, inp().split())
def nextline(): out("\n") # as stdout.write always print sring.
def testcase(t):
for p in range(t):
solve()
def pow(x, y, p):
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0):
return 0
while (y > 0):
if ((y & 1) == 1): # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
from functools import reduce
def factors(n):
return set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
def gcd(a, b):
if a == b: return a
while b > 0: a, b = b, a % b
return a
# discrete binary search
# minimise:
# def search():
# l = 0
# r = 10 ** 15
#
# for i in range(200):
# if isvalid(l):
# return l
# if l == r:
# return l
# m = (l + r) // 2
# if isvalid(m) and not isvalid(m - 1):
# return m
# if isvalid(m):
# r = m + 1
# else:
# l = m
# return m
# maximise:
# def search():
# l = 0
# r = 10 ** 15
#
# for i in range(200):
# # print(l,r)
# if isvalid(r):
# return r
# if l == r:
# return l
# m = (l + r) // 2
# if isvalid(m) and not isvalid(m + 1):
# return m
# if isvalid(m):
# l = m
# else:
# r = m - 1
# return m
##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
# dp[pos]=0
# l=max(1,k+pos-n-1)
# for j in range(min(pos,k),l-1,-1):
# dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])
def prefix_sum(ar): # [1,2,3,4]->[1,3,6,10]
return list(accumulate(ar))
def suffix_sum(ar): # [1,2,3,4]->[10,9,7,4]
return list(accumulate(ar[::-1]))[::-1]
def N():
return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
def YES():
print("YES")
def NO():
print("NO")
def Yes():
print("Yes")
def No():
print("No")
# =========================================================================================
from collections import defaultdict
def numberOfSetBits(i):
i = i - ((i >> 1) & 0x55555555)
i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24
def lcm(a, b):
return abs((a // gcd(a, b)) * b)
#
# # to find factorial and ncr
# tot = 400005
# mod = 10 ** 9 + 7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, tot + 1):
# fac.append((fac[-1] * i) % mod)
# inv.append(mod - (inv[mod % i] * (mod // i) % mod))
# finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
# if n < r:
# return 0
# else:
# return fac[n] * (finv[r] * finv[n - r] % mod) % mod
def solve():
n, m, k = map(int, input().split());a = [list(map(int, input().split())) for _ in range(m)]
def solv(lst):
res = sum(lst[:k]);s = res
for i in range(n-k):s += lst[i+k] - lst[i];res = max(res, s)
return res
a.sort(key=lambda x: sum(x)/2);apr = [0]*n
for el in a:
for i in range(el[0]-1, el[1]):apr[i] += 1
res = solv(apr);bpr = [0]*n
for r, l in a:
for i in range(r-1, l):apr[i] -= 1;bpr[i] += 1
nres = solv(apr) + solv(bpr);res = max(res, nres)
print(res)
solve()
#testcase(int(inp()))
# 5
# 3 6
# 5 10
# 4 3
# 2 1
# 1 3
```
| 93,705 | [
0.16943359375,
0.0238189697265625,
-0.1500244140625,
0.345703125,
-0.314208984375,
-0.60205078125,
-0.2188720703125,
-0.04302978515625,
0.1253662109375,
0.7490234375,
0.72998046875,
-0.1878662109375,
0.2412109375,
-0.708984375,
-0.478515625,
0.007534027099609375,
-0.78857421875,
-1... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Tags: brute force, dp, greedy, sortings, two pointers
Correct Solution:
```
import sys
input = sys.stdin.buffer.readline
def prog():
n,m,k = map(int,input().split())
intervals = [list(map(int,input().split())) for i in range(m)]
for i in range(m):
intervals[i][0] -= 1
intervals[i][1] -= 1
mx = 0
for i in range(n-k+1):
curr = 0
change = 0
events = [0]*(2*n+1)
for interval in intervals:
length = interval[1] - interval[0] + 1
if i <= interval[0] <= interval[1] <= i+k-1:
curr += length
elif interval[0] <= i <= i+k-1 <= interval[1]:
curr += k
elif i <= interval[0] <= i+k-1 or i <= interval[1] <= i+k-1:
if i <= interval[0] <= i+k-1:
intersect = i+k-1 - interval[0] + 1
else:
intersect = interval[1] - i + 1
curr += intersect
events[interval[0] + intersect] += 1
events[interval[0] + k] -= 1
events[interval[1] + 1] -= 1
events[interval[1] + k + 1] += 1
else:
events[interval[0]] += 1
events[interval[0] + k] -= 1
events[interval[1] + 1] -= 1
events[interval[1] + k + 1] += 1
for j in range(n):
change += events[j]
curr += change
mx = max(mx,curr)
print(mx)
prog()
```
| 93,706 | [
0.16943359375,
0.0238189697265625,
-0.1500244140625,
0.345703125,
-0.314208984375,
-0.60205078125,
-0.2188720703125,
-0.04302978515625,
0.1253662109375,
0.7490234375,
0.72998046875,
-0.1878662109375,
0.2412109375,
-0.708984375,
-0.478515625,
0.007534027099609375,
-0.78857421875,
-1... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Submitted Solution:
```
import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n, m, k = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]
A.sort(key = lambda x:x[0]+x[1])
table = [[0]*m for _ in range(n-k+1)]
for i in range(n-k+1): #i+1~i+k
for j in range(m):
lower = max(i+1, A[j][0])
upper = min(i+k, A[j][1])
table[i][j] = max(0,upper-lower+1)
from copy import deepcopy
cum1 = deepcopy(table)
cum2 = deepcopy(table)
ans = 0
for i in range(n-k+1):
for j in range(1,m):
cum1[i][j] += cum1[i][j-1]
for i in range(n-k+1):
for j in range(m-2,-1,-1):
cum2[i][j] += cum2[i][j+1]
# ans = max([cum1[i][-1] for i in range(n-k+1)])
ans = max([cum2[i][0] for i in range(n-k+1)])
for j in range(m-1):
left = max([cum1[i][j] for i in range(n-k+1)])
right = max([cum2[i][j+1] for i in range(n-k+1)])
ans = max(ans, left+right)
print(ans)
```
Yes
| 93,707 | [
0.27880859375,
0.074462890625,
-0.20703125,
0.36328125,
-0.389892578125,
-0.5458984375,
-0.233642578125,
0.01380157470703125,
0.10467529296875,
0.7431640625,
0.66845703125,
-0.1531982421875,
0.198486328125,
-0.6875,
-0.48681640625,
-0.062347412109375,
-0.74462890625,
-1.033203125,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Submitted Solution:
```
n, m, k = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]
A.sort(key = lambda x:x[0]+x[1])
table = [[0]*m for _ in range(n-k+1)]
for i in range(n-k+1): #i+1~i+k
for j in range(m):
lower = max(i+1, A[j][0])
upper = min(i+k, A[j][1])
table[i][j] = max(0,upper-lower+1)
from copy import deepcopy
cum1 = deepcopy(table)
cum2 = deepcopy(table)
ans = 0
for i in range(n-k+1):
for j in range(1,m):
cum1[i][j] += cum1[i][j-1]
for i in range(n-k+1):
for j in range(m-2,-1,-1):
cum2[i][j] += cum2[i][j+1]
ans = max([cum1[i][-1] for i in range(n-k+1)])
ans = max(ans,max([cum2[i][0] for i in range(n-k+1)]))
for j in range(m-1):
left = max([cum1[i][j] for i in range(n-k+1)])
right = max([cum2[i][j+1] for i in range(n-k+1)])
ans = max(ans, left+right)
print(ans)
```
Yes
| 93,708 | [
0.27880859375,
0.074462890625,
-0.20703125,
0.36328125,
-0.389892578125,
-0.5458984375,
-0.233642578125,
0.01380157470703125,
0.10467529296875,
0.7431640625,
0.66845703125,
-0.1531982421875,
0.198486328125,
-0.6875,
-0.48681640625,
-0.062347412109375,
-0.74462890625,
-1.033203125,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Submitted Solution:
```
import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n, m, k = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]
A.sort(key = lambda x:x[0]+x[1])
table = [[0]*m for _ in range(n-k+1)]
for i in range(n-k+1): #i+1~i+k
for j in range(m):
lower = max(i+1, A[j][0])
upper = min(i+k, A[j][1])
table[i][j] = max(0,upper-lower+1)
from copy import deepcopy
cum1 = deepcopy(table)
cum2 = deepcopy(table)
for i in range(n-k+1):
for j in range(1,m):
cum1[i][j] += cum1[i][j-1]
for i in range(n-k+1):
for j in range(m-2,-1,-1):
cum2[i][j] += cum2[i][j+1]
# mが1の場合を考慮
ans = max([cum1[i][-1] for i in range(n-k+1)])
for j in range(m-1):
left = max([cum1[i][j] for i in range(n-k+1)])
right = max([cum2[i][j+1] for i in range(n-k+1)])
ans = max(ans, left+right)
print(ans)
```
Yes
| 93,709 | [
0.27880859375,
0.074462890625,
-0.20703125,
0.36328125,
-0.389892578125,
-0.5458984375,
-0.233642578125,
0.01380157470703125,
0.10467529296875,
0.7431640625,
0.66845703125,
-0.1531982421875,
0.198486328125,
-0.6875,
-0.48681640625,
-0.062347412109375,
-0.74462890625,
-1.033203125,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Submitted Solution:
```
import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n, m, k = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]
A.sort(key = lambda x:x[0]+x[1])
table = [[0]*m for _ in range(n-k+1)]
for i in range(n-k+1): #i+1~i+k
for j in range(m):
lower = max(i+1, A[j][0])
upper = min(i+k, A[j][1])
table[i][j] = max(0,upper-lower+1)
from copy import deepcopy
cum1 = deepcopy(table)
cum2 = deepcopy(table)
ans = 0
for i in range(n-k+1):
for j in range(1,m):
cum1[i][j] += cum1[i][j-1]
for i in range(n-k+1):
for j in range(m-2,-1,-1):
cum2[i][j] += cum2[i][j+1]
ans = max([cum1[i][-1] for i in range(n-k+1)])
# ans = max(ans,max([cum2[i][0] for i in range(n-k+1)]))
for j in range(m-1):
left = max([cum1[i][j] for i in range(n-k+1)])
right = max([cum2[i][j+1] for i in range(n-k+1)])
ans = max(ans, left+right)
print(ans)
```
Yes
| 93,710 | [
0.27880859375,
0.074462890625,
-0.20703125,
0.36328125,
-0.389892578125,
-0.5458984375,
-0.233642578125,
0.01380157470703125,
0.10467529296875,
0.7431640625,
0.66845703125,
-0.1531982421875,
0.198486328125,
-0.6875,
-0.48681640625,
-0.062347412109375,
-0.74462890625,
-1.033203125,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Submitted Solution:
```
n, m, k = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]
A.sort(key = lambda x:x[0]+x[1])
table = [[0]*m for _ in range(n-k+1)]
for i in range(n-k+1): #i+1~i+k
for j in range(m):
lower = max(i+1, A[j][0])
upper = min(i+k, A[j][1])
table[i][j] = max(0,upper-lower+1)
from copy import deepcopy
cum1 = deepcopy(table)
cum2 = deepcopy(table)
ans = 0
for i in range(n-k+1):
for j in range(1,m):
cum1[i][j] += cum1[i][j-1]
for i in range(n-k+1):
for j in range(m-2,-1,-1):
cum2[i][j] += cum2[i][j+1]
for j in range(m-1):
left = max([cum1[i][j] for i in range(n-k+1)])
right = max([cum2[i][j+1] for i in range(n-k+1)])
ans = max(ans, left+right)
print(ans)
```
No
| 93,711 | [
0.27880859375,
0.074462890625,
-0.20703125,
0.36328125,
-0.389892578125,
-0.5458984375,
-0.233642578125,
0.01380157470703125,
0.10467529296875,
0.7431640625,
0.66845703125,
-0.1531982421875,
0.198486328125,
-0.6875,
-0.48681640625,
-0.062347412109375,
-0.74462890625,
-1.033203125,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Submitted Solution:
```
from sys import stdin
def inverse(a,mod):
return pow(a,mod-2,mod)
n,m,k = map(int,stdin.readline().split())
ans = 0
lr = []
for i in range(m):
l,r = map(int,stdin.readline().split())
lr.append((l-1,r-1))
for D1 in range(0,n-k+1):
now = 0
nch = 0
ch = [0] * (n-k+1)
for l,r in lr:
L,R = l,r+1
if D1 >= R or L >= D1+k:
X = 0
elif D1 <= L <= D1+k <= R:
X = D1+k-L
elif L <= D1 <= R <= D1+k:
X = R-D1
else:
X = min(R-L,k)
now += X
tmp = [(l-k+X,1),(l,-1),(r+1-k,-1),(r+1-X,1)]
for i,j in tmp:
if i < 0:
now += j
elif i < n-k+1:
ch[i] += j
for i in range(n-k+1):
ans = max(ans,now)
now += nch
nch += ch[i]
print (ans)
```
No
| 93,712 | [
0.27880859375,
0.074462890625,
-0.20703125,
0.36328125,
-0.389892578125,
-0.5458984375,
-0.233642578125,
0.01380157470703125,
0.10467529296875,
0.7431640625,
0.66845703125,
-0.1531982421875,
0.198486328125,
-0.6875,
-0.48681640625,
-0.062347412109375,
-0.74462890625,
-1.033203125,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Submitted Solution:
```
import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n, m, k = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]
A.sort(key = lambda x:x[0]+x[1])
table = [[0]*m for _ in range(n-k+1)]
for i in range(n-k+1): #i+1~i+k
for j in range(m):
lower = max(i+1, A[j][0])
upper = min(i+k, A[j][1])
table[i][j] = max(0,upper-lower+1)
from copy import deepcopy
cum1 = deepcopy(table)
cum2 = deepcopy(table)
ans = 0
for i in range(n-k+1):
for j in range(1,m):
cum1[i][j] += cum1[i][j-1]
for i in range(n-k+1):
for j in range(m-2,-1,-1):
cum2[i][j] += cum2[i][j+1]
# ans = max([cum1[i][-1] for i in range(n-k+1)])
# ans = max([cum2[i][0] for i in range(n-k+1)])
for j in range(m-1):
left = max([cum1[i][j] for i in range(n-k+1)])
right = max([cum2[i][j+1] for i in range(n-k+1)])
ans = max(ans, left+right)
print(ans)
```
No
| 93,713 | [
0.27880859375,
0.074462890625,
-0.20703125,
0.36328125,
-0.389892578125,
-0.5458984375,
-0.233642578125,
0.01380157470703125,
0.10467529296875,
0.7431640625,
0.66845703125,
-0.1531982421875,
0.198486328125,
-0.6875,
-0.48681640625,
-0.062347412109375,
-0.74462890625,
-1.033203125,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n.
Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the problemset. The authors choose the segment of k consecutive tasks for themselves independently of each other. The segments can coincide, intersect or not intersect at all.
The i-th participant is interested in listening to the tutorial of all consecutive tasks from l_i to r_i. Each participant always chooses to listen to only the problem author that tells the tutorials to the maximum number of tasks he is interested in. Let this maximum number be a_i. No participant can listen to both of the authors, even if their segments don't intersect.
The authors want to choose the segments of k consecutive tasks for themselves in such a way that the sum of a_i over all participants is maximized.
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ n) — the number of problems, the number of participants and the length of the segment of tasks each of the problem authors plans to tell the tutorial to.
The i-th of the next m lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of tasks the i-th participant is interested in listening to the tutorial to.
Output
Print a single integer — the maximum sum of a_i over all participants.
Examples
Input
10 5 3
1 3
2 4
6 9
6 9
1 8
Output
14
Input
10 3 3
2 4
4 6
3 5
Output
8
Input
4 4 1
3 3
1 1
2 2
4 4
Output
2
Input
5 4 5
1 2
2 3
3 4
4 5
Output
8
Note
In the first example the first author can tell the tutorial to problems from 1 to 3 and the second one — from 6 to 8. That way the sequence of a_i will be [3, 2, 3, 3, 3]. Notice that the last participant can't listen to both author, he only chooses the one that tells the maximum number of problems he's interested in.
In the second example the first one can tell problems 2 to 4, the second one — 4 to 6.
In the third example the first one can tell problems 1 to 1, the second one — 2 to 2. Or 4 to 4 and 3 to 3. Every pair of different problems will get the same sum of 2.
In the fourth example the first one can tell problems 1 to 5, the second one — 1 to 5 as well.
Submitted Solution:
```
n, m, k = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]
A.sort(key = lambda x:x[0])
table = [[0]*m for _ in range(n-k+1)]
for i in range(n-k+1): #i+1~i+k
for j in range(m):
lower = max(i+1, A[j][0])
upper = min(i+k, A[j][1])
table[i][j] = max(0,upper-lower+1)
from copy import deepcopy
cum1 = deepcopy(table)
cum2 = deepcopy(table)
for i in range(n-k+1):
for j in range(1,m):
cum1[i][j] += cum1[i][j-1]
for i in range(n-k):
for j in range(m-2,-1,-1):
cum2[i][j] += cum2[i][j+1]
ans = 0
for j in range(m-1):
left = right = 0
for i in range(n-k+1):
left = max(left, cum1[i][j])
for i in range(n-k+1):
right = max(right, cum2[i][j+1])
ans = max(ans, left+right)
print(ans)
```
No
| 93,714 | [
0.27880859375,
0.074462890625,
-0.20703125,
0.36328125,
-0.389892578125,
-0.5458984375,
-0.233642578125,
0.01380157470703125,
0.10467529296875,
0.7431640625,
0.66845703125,
-0.1531982421875,
0.198486328125,
-0.6875,
-0.48681640625,
-0.062347412109375,
-0.74462890625,
-1.033203125,
... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
Here are $ N $ sheets of paper. You want to scan all paper by using $ 3 $ scanners in parallel. Each piece of paper has a fixed scanning time, and the time it takes to scan the $ i $ th paper is $ T_i $. You can scan the paper in any order, but you cannot scan multiple papers at the same time with a $ 1 $ scanner.
Minimize the time it takes to finish scanning all paper and run out of scanners.
Constraint
$ 1 \ leq N \ leq 50 $
$ 1 \ leq T_i \ leq 50 $
All inputs are integers
sample
Sample input 1
Four
1
1
1
1
Sample output 1
2
<image>
Sample input 2
9
15
20
27
Four
Ten
7
34
30
36
Sample output 2
61
<image>
Sample input 3
6
20
18
46
16
9
48
Sample output 3
55
<image>
input
$ N $
$ T_1 $
$ T_2 $
$ T_3 $
$ \ vdots $
$ T_N $
output
Print the answer on the $ 1 $ line.
Example
Input
4
1
1
1
1
Output
2
Submitted Solution:
```
N = int(input())
ts = [int(input()) for i in range(N)]
ma = sum(ts) // 3 + 50
s = [[[0 for i in range(ma)] for j in range(ma)] for k in range(N + 1)]
for i in range(N):
for j in range(ma):
for k in range(j, ma):
p = [s[i][j][k] + ts[i]]
if(j >= ts[i]):
p.append(s[i][j - ts[i]][k])
if(k >= ts[i]):
p.append(s[i][j][k - ts[i]])
s[i + 1][j][k] = s[i + 1][k][j] = min(p)
i = 0
while True:
if(s[N][i][i] <= i):
break
i += 1
print(i)
```
No
| 95,237 | [
0.43017578125,
0.28173828125,
0.311767578125,
0.119140625,
-0.387451171875,
-0.26953125,
-0.29150390625,
0.030029296875,
0.291748046875,
1.0556640625,
0.677734375,
-0.0181884765625,
0.239990234375,
-0.64990234375,
-0.501953125,
0.260986328125,
-0.59326171875,
-0.7529296875,
-0.22... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
Here are $ N $ sheets of paper. You want to scan all paper by using $ 3 $ scanners in parallel. Each piece of paper has a fixed scanning time, and the time it takes to scan the $ i $ th paper is $ T_i $. You can scan the paper in any order, but you cannot scan multiple papers at the same time with a $ 1 $ scanner.
Minimize the time it takes to finish scanning all paper and run out of scanners.
Constraint
$ 1 \ leq N \ leq 50 $
$ 1 \ leq T_i \ leq 50 $
All inputs are integers
sample
Sample input 1
Four
1
1
1
1
Sample output 1
2
<image>
Sample input 2
9
15
20
27
Four
Ten
7
34
30
36
Sample output 2
61
<image>
Sample input 3
6
20
18
46
16
9
48
Sample output 3
55
<image>
input
$ N $
$ T_1 $
$ T_2 $
$ T_3 $
$ \ vdots $
$ T_N $
output
Print the answer on the $ 1 $ line.
Example
Input
4
1
1
1
1
Output
2
Submitted Solution:
```
import itertools
n=int(input())
dp=[[1<<30]*850 for _ in [0]*850]
dp[0][0]=0
t=[int(input()) for _ in[0]*n]
s=sum(t)
for i,j,k in itertools.product(range(n),range(s//3+1),range(s//2+1)):
dp[j][k]+=t[i]
if t[i]<=j and dp[j][k]>dp[j-t[i]][k]:dp[j][k]=dp[j-t[i]][k]
if t[i]<=k and dp[j][k]>dp[j][k-t[i]]:dp[j][k]=dp[j][k-t[i]]
a=1<<30
for i,j in itertools.product(range(s//3+1),range(s//2+1)):
a=min(a,max(i,j,s-i-j))
print(a)
```
No
| 95,238 | [
0.40869140625,
0.16455078125,
0.235107421875,
0.07623291015625,
-0.3828125,
-0.25341796875,
-0.329345703125,
-0.046173095703125,
0.291015625,
1.0791015625,
0.57421875,
-0.08831787109375,
0.26513671875,
-0.60546875,
-0.4482421875,
0.264404296875,
-0.6044921875,
-0.74755859375,
-0.... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
Here are $ N $ sheets of paper. You want to scan all paper by using $ 3 $ scanners in parallel. Each piece of paper has a fixed scanning time, and the time it takes to scan the $ i $ th paper is $ T_i $. You can scan the paper in any order, but you cannot scan multiple papers at the same time with a $ 1 $ scanner.
Minimize the time it takes to finish scanning all paper and run out of scanners.
Constraint
$ 1 \ leq N \ leq 50 $
$ 1 \ leq T_i \ leq 50 $
All inputs are integers
sample
Sample input 1
Four
1
1
1
1
Sample output 1
2
<image>
Sample input 2
9
15
20
27
Four
Ten
7
34
30
36
Sample output 2
61
<image>
Sample input 3
6
20
18
46
16
9
48
Sample output 3
55
<image>
input
$ N $
$ T_1 $
$ T_2 $
$ T_3 $
$ \ vdots $
$ T_N $
output
Print the answer on the $ 1 $ line.
Example
Input
4
1
1
1
1
Output
2
Submitted Solution:
```
# -*- coding: utf-8 -*-
N = int(input())
T = [int(input()) for i in range(N)]
T.sort(reverse = True)
machine = [0, 0, 0]
for t in T:
no = machine.index(min(machine))
machine[no] += t
print(max(machine))
```
No
| 95,239 | [
0.466796875,
0.16064453125,
0.226806640625,
-0.006565093994140625,
-0.391845703125,
-0.2169189453125,
-0.25634765625,
0.0230255126953125,
0.247802734375,
1.0869140625,
0.5439453125,
-0.0115509033203125,
0.2308349609375,
-0.59765625,
-0.50048828125,
0.11883544921875,
-0.560546875,
-... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
Here are $ N $ sheets of paper. You want to scan all paper by using $ 3 $ scanners in parallel. Each piece of paper has a fixed scanning time, and the time it takes to scan the $ i $ th paper is $ T_i $. You can scan the paper in any order, but you cannot scan multiple papers at the same time with a $ 1 $ scanner.
Minimize the time it takes to finish scanning all paper and run out of scanners.
Constraint
$ 1 \ leq N \ leq 50 $
$ 1 \ leq T_i \ leq 50 $
All inputs are integers
sample
Sample input 1
Four
1
1
1
1
Sample output 1
2
<image>
Sample input 2
9
15
20
27
Four
Ten
7
34
30
36
Sample output 2
61
<image>
Sample input 3
6
20
18
46
16
9
48
Sample output 3
55
<image>
input
$ N $
$ T_1 $
$ T_2 $
$ T_3 $
$ \ vdots $
$ T_N $
output
Print the answer on the $ 1 $ line.
Example
Input
4
1
1
1
1
Output
2
Submitted Solution:
```
N = int(input())
ts = [int(input()) for i in range(N)]
ts.sort()
ts.reverse()
ma = sum(ts) // 3 + 50
s = [[[0 for i in range(ma)] for j in range(ma)] for k in range(N + 1)]
for i in range(N):
for j in range(ma):
for k in range(ma):
p = [s[i][j][k] + ts[i]]
if(j >= ts[i]):
p.append(s[i][j - ts[i]][k])
if(k >= ts[i]):
p.append(s[i][j][k - ts[i]])
s[i + 1][j][k] = min(p)
i = 0
while True:
if(s[N][i][i] <= i):
break
i += 1
print(i)
```
No
| 95,240 | [
0.414794921875,
0.2548828125,
0.27392578125,
0.1029052734375,
-0.38427734375,
-0.25244140625,
-0.317626953125,
0.08477783203125,
0.28076171875,
1.12890625,
0.64697265625,
-0.0288543701171875,
0.2471923828125,
-0.654296875,
-0.501953125,
0.1988525390625,
-0.58740234375,
-0.776855468... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset.
Both the given array and required subset may contain equal values.
Input
The first line contains a single integer t (1 ≤ t ≤ 100), number of test cases to solve. Descriptions of t test cases follow.
A description of each test case consists of two lines. The first line contains a single integer n (1 ≤ n ≤ 100), length of array a.
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 100), elements of a. The given array a can contain equal values (duplicates).
Output
For each test case output -1 if there is no such subset of elements. Otherwise output positive integer k, number of elements in the required subset. Then output k distinct integers (1 ≤ p_i ≤ n), indexes of the chosen elements. If there are multiple solutions output any of them.
Example
Input
3
3
1 4 3
1
15
2
3 5
Output
1
2
-1
2
1 2
Note
There are three test cases in the example.
In the first test case, you can choose the subset consisting of only the second element. Its sum is 4 and it is even.
In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.
In the third test case, the subset consisting of all array's elements has even sum.
Submitted Solution:
```
t = int(input())
def solve(a):
n = len(a)
odds=[]
for j in range(n):
if a[j]%2==0:
print(1)
print(j+1)
return
else:
odds.append(j)
if len(odds)==2:
print(2)
print(odds[0]+1, odds[1]+1)
return
print(-1)
return
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
solve(a)
```
Yes
| 95,401 | [
0.1744384765625,
0.296142578125,
-0.31298828125,
-0.08441162109375,
-0.87939453125,
-0.459716796875,
0.06890869140625,
0.24853515625,
0.33740234375,
0.94091796875,
0.5634765625,
-0.265625,
0.1973876953125,
-0.70849609375,
-0.80029296875,
-0.1805419921875,
-0.75390625,
-0.798828125,... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types:
* increase x by 1;
* decrease x by 1.
You are given m queries of the following format:
* query l r — how many distinct values is x assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.
Then the description of t testcases follows.
The first line of each testcase contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of instructions in the program and the number of queries.
The second line of each testcase contains a program — a string of n characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
Each of the next m lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the description of the query.
The sum of n over all testcases doesn't exceed 2 ⋅ 10^5. The sum of m over all testcases doesn't exceed 2 ⋅ 10^5.
Output
For each testcase print m integers — for each query l, r print the number of distinct values variable x is assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order.
Example
Input
2
8 4
-+--+--+
1 8
2 8
2 5
1 1
4 10
+-++
1 1
1 2
2 2
1 3
2 3
3 3
1 4
2 4
3 4
4 4
Output
1
2
4
4
3
3
4
2
3
2
1
2
2
2
Note
The instructions that remain for each query of the first testcase are:
1. empty program — x was only equal to 0;
2. "-" — x had values 0 and -1;
3. "---+" — x had values 0, -1, -2, -3, -2 — there are 4 distinct values among them;
4. "+--+--+" — the distinct values are 1, 0, -1, -2.
Submitted Solution:
```
import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
n, m = map(int, sys.stdin.readline().split())
s = sys.stdin.readline().strip()
psa = [0 for k in range(n+1)]
for j in range(1, n+1):
if s[j-1] == "+":
psa[j] = psa[j-1]+1
else:
psa[j] = psa[j-1]-1
sufMax = [0 for k in range(n+1)]
sufMin = [0 for k in range(n+1)]
preMax = [0 for k in range(n+1)]
preMin = [0 for k in range(n+1)]
sufMax[-1] = psa[-1]
sufMin[-1] = psa[-1]
preMax[1] = psa[1]
preMin[1] = psa[1]
for i in range(1, n+1):
preMax[i] = max(psa[i], preMax[i-1])
preMin[i] = min([psa[i], preMin[i-1]])
for i in range(n-1, 0, -1):
sufMax[i] = max(psa[i], sufMax[i+1])
sufMin[i] = min(psa[i], sufMin[i+1])
for j in range(m):
l, r = map(int, sys.stdin.readline().split())
bestMax = preMax[l-1]
bestMin = preMin[l-1]
if r == n:
print(bestMax - bestMin + 1)
else:
temp = psa[l-1]-psa[r]
bestMax = max(bestMax, sufMax[r+1]+temp)
bestMin = min(bestMin, sufMin[r+1]+temp)
print(bestMax-bestMin+1)
```
Yes
| 95,494 | [
0.1475830078125,
-0.074951171875,
-0.14404296875,
0.038299560546875,
-0.69775390625,
-0.257568359375,
-0.0286865234375,
0.0172119140625,
0.1611328125,
0.9228515625,
0.5712890625,
-0.038818359375,
0.34033203125,
-0.90380859375,
-0.78564453125,
-0.084716796875,
-0.86279296875,
-0.943... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types:
* increase x by 1;
* decrease x by 1.
You are given m queries of the following format:
* query l r — how many distinct values is x assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.
Then the description of t testcases follows.
The first line of each testcase contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of instructions in the program and the number of queries.
The second line of each testcase contains a program — a string of n characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
Each of the next m lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the description of the query.
The sum of n over all testcases doesn't exceed 2 ⋅ 10^5. The sum of m over all testcases doesn't exceed 2 ⋅ 10^5.
Output
For each testcase print m integers — for each query l, r print the number of distinct values variable x is assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order.
Example
Input
2
8 4
-+--+--+
1 8
2 8
2 5
1 1
4 10
+-++
1 1
1 2
2 2
1 3
2 3
3 3
1 4
2 4
3 4
4 4
Output
1
2
4
4
3
3
4
2
3
2
1
2
2
2
Note
The instructions that remain for each query of the first testcase are:
1. empty program — x was only equal to 0;
2. "-" — x had values 0 and -1;
3. "---+" — x had values 0, -1, -2, -3, -2 — there are 4 distinct values among them;
4. "+--+--+" — the distinct values are 1, 0, -1, -2.
Submitted Solution:
```
'''
#python-io
'''
import sys
# need this
input = sys.stdin.readline
MAXN = 2 * 100_000 + 5
cnt, top, bot = [0]*MAXN, [[0]*MAXN for i in range(2)], [[0]*MAXN for i in range(2)]
def program(n, m, s):
for i in range(n):
if s[i] == '+': cnt[i+1] = cnt[i] + 1
else: cnt[i+1] = cnt[i] - 1
for i in range(1, n+1):
top[0][i] = bot[0][i] = top[1][i] = bot[1][i] = cnt[i]
for i in range(1, n+1):
top[0][i] = max(top[0][i], top[0][i-1])
bot[0][i] = min(bot[0][i], bot[0][i-1])
for i in range(n-1, -1, -1):
top[1][i] = max(top[1][i], top[1][i+1])
bot[1][i] = min(bot[1][i], bot[1][i+1])
for _ in range(m):
l, r = map(int, input().strip().split(' '))
diff = cnt[l-1] - cnt[r]
if r < n:
t = max(top[0][l-1], top[1][r+1] + diff)
b = min(bot[0][l-1], bot[1][r+1] + diff)
else:
t, b = top[0][l-1], bot[0][l-1]
# may not be necessary
sys.stdout.write(str(t-b+1) + '\n')
def main():
for t in range(int(input().strip())):
n, m = map(int, input().strip().split(' '))
s = input().strip()
program(n, m, s)
if __name__ == "__main__":
main()
```
Yes
| 95,495 | [
0.1475830078125,
-0.074951171875,
-0.14404296875,
0.038299560546875,
-0.69775390625,
-0.257568359375,
-0.0286865234375,
0.0172119140625,
0.1611328125,
0.9228515625,
0.5712890625,
-0.038818359375,
0.34033203125,
-0.90380859375,
-0.78564453125,
-0.084716796875,
-0.86279296875,
-0.943... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types:
* increase x by 1;
* decrease x by 1.
You are given m queries of the following format:
* query l r — how many distinct values is x assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.
Then the description of t testcases follows.
The first line of each testcase contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of instructions in the program and the number of queries.
The second line of each testcase contains a program — a string of n characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
Each of the next m lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the description of the query.
The sum of n over all testcases doesn't exceed 2 ⋅ 10^5. The sum of m over all testcases doesn't exceed 2 ⋅ 10^5.
Output
For each testcase print m integers — for each query l, r print the number of distinct values variable x is assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order.
Example
Input
2
8 4
-+--+--+
1 8
2 8
2 5
1 1
4 10
+-++
1 1
1 2
2 2
1 3
2 3
3 3
1 4
2 4
3 4
4 4
Output
1
2
4
4
3
3
4
2
3
2
1
2
2
2
Note
The instructions that remain for each query of the first testcase are:
1. empty program — x was only equal to 0;
2. "-" — x had values 0 and -1;
3. "---+" — x had values 0, -1, -2, -3, -2 — there are 4 distinct values among them;
4. "+--+--+" — the distinct values are 1, 0, -1, -2.
Submitted Solution:
```
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import combinations, permutations
from bisect import *
from fractions import Fraction
from heapq import *
from random import randint
def main():
for _ in range(int(input())):
n, m = map(int,input().split())
a, x = [0], 0
for i in input().rstrip():
x += (i == "+") - (i == "-")
a.append(x)
maxl, minl = [a[0]], [a[0]]
for i in range(1, n + 1, 1):
maxl.append(max(maxl[-1], a[i]))
minl.append(min(minl[-1], a[i]))
maxr, minr = [a[n]], [a[n]]
for i in range(n - 1, -1, -1):
minr.append(min(minr[-1], a[i]))
maxr.append(max(maxr[-1], a[i]))
maxr.reverse()
minr.reverse()
b=[]
for i in range(m):
l, r = map(int, input().split())
if r == n:
b.append(maxl[l - 1] - minl[l - 1] + 1)
else:
z = a[r] - a[l - 1]
mi_l, ma_l, mi_r, ma_r = minl[l - 1], maxl[l - 1], minr[r + 1] - z, maxr[r + 1] - z
if min(ma_l, ma_r) < max(mi_l, mi_r):
b.append(ma_r - mi_r + ma_l - mi_l + 2)
else:
b.append(max(ma_l, ma_r) - min(mi_r, mi_l) + 1)
print(*b,sep="\n")
# region fastio
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")
if __name__ == "__main__":
main()
```
Yes
| 95,496 | [
0.1475830078125,
-0.074951171875,
-0.14404296875,
0.038299560546875,
-0.69775390625,
-0.257568359375,
-0.0286865234375,
0.0172119140625,
0.1611328125,
0.9228515625,
0.5712890625,
-0.038818359375,
0.34033203125,
-0.90380859375,
-0.78564453125,
-0.084716796875,
-0.86279296875,
-0.943... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types:
* increase x by 1;
* decrease x by 1.
You are given m queries of the following format:
* query l r — how many distinct values is x assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.
Then the description of t testcases follows.
The first line of each testcase contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of instructions in the program and the number of queries.
The second line of each testcase contains a program — a string of n characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
Each of the next m lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the description of the query.
The sum of n over all testcases doesn't exceed 2 ⋅ 10^5. The sum of m over all testcases doesn't exceed 2 ⋅ 10^5.
Output
For each testcase print m integers — for each query l, r print the number of distinct values variable x is assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order.
Example
Input
2
8 4
-+--+--+
1 8
2 8
2 5
1 1
4 10
+-++
1 1
1 2
2 2
1 3
2 3
3 3
1 4
2 4
3 4
4 4
Output
1
2
4
4
3
3
4
2
3
2
1
2
2
2
Note
The instructions that remain for each query of the first testcase are:
1. empty program — x was only equal to 0;
2. "-" — x had values 0 and -1;
3. "---+" — x had values 0, -1, -2, -3, -2 — there are 4 distinct values among them;
4. "+--+--+" — the distinct values are 1, 0, -1, -2.
Submitted Solution:
```
#region Header
#!/usr/bin/env python3
# from typing import *
import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq
def input():
return sys.stdin.readline()[:-1]
# sys.setrecursionlimit(1000000)
#endregion
# _INPUT = """2
# 8 4
# -+--+--+
# 1 8
# 2 8
# 2 5
# 1 1
# 4 10
# +-++
# 1 1
# 1 2
# 2 2
# 1 3
# 2 3
# 3 3
# 1 4
# 2 4
# 3 4
# 4 4
# """
# sys.stdin = io.StringIO(_INPUT)
class BIT:
"""
Binary Indexed Tree (Fenwick Tree), 1-indexed
"""
def __init__(self, n):
"""
Parameters
----------
n : int
要素数。index は 0..n になる。
"""
self.size = n
self.data = [0] * (n+1)
# self.depth = n.bit_length()
def add(self, i, x):
while i <= self.size:
self.data[i] += x
i += i & -i
def get_sum(self, i):
s = 0
while i > 0:
s += self.data[i]
i -= i & -i
return s
def get_rsum(self, l, r):
"""
[l, r) の sum
"""
return self.get_sum(r) - self.get_sum(l-1)
class BIT_Max:
"""
Binary Indexed Tree (Fenwick Tree), 1-indexed
"""
def __init__(self, n):
"""
Parameters
----------
n : int
要素数。index は 0..n になる。
"""
self.size = n
self.data = [0] * (n+1)
# self.depth = n.bit_length()
def update(self, i, x):
while i <= self.size:
self.data[i] = max(x, self.data[i])
i += i & -i
def get_max(self, i):
# 1からiまで
s = 0
while i > 0:
s = max(s, self.data[i])
i -= i & -i
return s
class BIT_Min:
"""
Binary Indexed Tree (Fenwick Tree), 1-indexed
"""
def __init__(self, n):
"""
Parameters
----------
n : int
要素数。index は 0..n になる。
"""
self.size = n
self.data = [0] * (n+1)
# self.depth = n.bit_length()
def update(self, i, x):
while i <= self.size:
self.data[i] = min(x, self.data[i])
i += i & -i
def get_min(self, i):
# 1からiまで
s = 0
while i > 0:
s = min(s, self.data[i])
i -= i & -i
return s
def solve(N, M, S, Q):
bit_sum = BIT(N)
bit_max = BIT_Max(N)
bit_min = BIT_Min(N)
v = 0
for i in range(N):
if S[i] == '+':
v += 1
bit_sum.add(i+1, 1)
else:
v -= 1
bit_sum.add(i+1, -1)
bit_max.update(i+1, v)
bit_min.update(i+1, v)
last = v
bit_sum_r = BIT(N)
bit_max_r = BIT_Max(N)
bit_min_r = BIT_Min(N)
v = 0
for i in range(N):
if S[N-1-i] == '-':
v += 1
bit_sum_r.add(i+1, 1)
else:
v -= 1
bit_sum_r.add(i+1, -1)
bit_max_r.update(i+1, v)
bit_min_r.update(i+1, v)
for (l, r) in Q:
if r == N-1:
if l == 0:
print(1)
else:
max1 = bit_max.get_max(l)
min1 = bit_min.get_min(l)
print(max1 - min1 + 1)
else:
# [0, l) and [r, N+1)
max1 = bit_max.get_max(l)
min1 = bit_min.get_min(l)
a = bit_sum.get_sum(r+1) - bit_sum.get_sum(l)
max2 = bit_max_r.get_max(N-r-1) + last - a
min2 = bit_min_r.get_min(N-r-1) + last - a
print(max(max1, max2) - min(min1, min2) + 1)
def main():
T0 = int(input())
for _ in range(T0):
N, M = map(int, input().split())
S = input()
Q = []
for _ in range(M):
l, r = map(int, input().split())
Q.append((l-1, r-1))
solve(N, M, S, Q)
if __name__ == '__main__':
main()
```
Yes
| 95,497 | [
0.1475830078125,
-0.074951171875,
-0.14404296875,
0.038299560546875,
-0.69775390625,
-0.257568359375,
-0.0286865234375,
0.0172119140625,
0.1611328125,
0.9228515625,
0.5712890625,
-0.038818359375,
0.34033203125,
-0.90380859375,
-0.78564453125,
-0.084716796875,
-0.86279296875,
-0.943... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types:
* increase x by 1;
* decrease x by 1.
You are given m queries of the following format:
* query l r — how many distinct values is x assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.
Then the description of t testcases follows.
The first line of each testcase contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of instructions in the program and the number of queries.
The second line of each testcase contains a program — a string of n characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
Each of the next m lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the description of the query.
The sum of n over all testcases doesn't exceed 2 ⋅ 10^5. The sum of m over all testcases doesn't exceed 2 ⋅ 10^5.
Output
For each testcase print m integers — for each query l, r print the number of distinct values variable x is assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order.
Example
Input
2
8 4
-+--+--+
1 8
2 8
2 5
1 1
4 10
+-++
1 1
1 2
2 2
1 3
2 3
3 3
1 4
2 4
3 4
4 4
Output
1
2
4
4
3
3
4
2
3
2
1
2
2
2
Note
The instructions that remain for each query of the first testcase are:
1. empty program — x was only equal to 0;
2. "-" — x had values 0 and -1;
3. "---+" — x had values 0, -1, -2, -3, -2 — there are 4 distinct values among them;
4. "+--+--+" — the distinct values are 1, 0, -1, -2.
Submitted Solution:
```
import sys
input=sys.stdin.readline
t = int(input())
while t:
ans = []
t -= 1
n, q = map(int, input().split())
s = input()
left = [[0, 0, 0]]
right = [[0, 0]]
now = plus = minus = 0
for i in s:
if i == "-":
now -= 1
if now < minus:
minus -= 1
elif i == "+":
now += 1
if now > plus:
plus += 1
left.append([plus, minus, now])
now = plus = minus = 0
a = b = 0
for i in s[::-1]:
if i == "-":
a -= 1
b -= 1
a = max(0, a)
elif i == "+":
a += 1
b += 1
b = min(b, 0)
right.append([a, b])
right = right[::-1]
print(left)
print(right)
for i in range(q):
l, r = map(int, input().split())
a, b, now = left[l - 1]
c, d = right[r]
print(a, b, now, c, d)
a = max(a, now + c)
b = min(b, now + d)
ans.append(a-b+1)
print(ans)
```
No
| 95,498 | [
0.1475830078125,
-0.074951171875,
-0.14404296875,
0.038299560546875,
-0.69775390625,
-0.257568359375,
-0.0286865234375,
0.0172119140625,
0.1611328125,
0.9228515625,
0.5712890625,
-0.038818359375,
0.34033203125,
-0.90380859375,
-0.78564453125,
-0.084716796875,
-0.86279296875,
-0.943... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types:
* increase x by 1;
* decrease x by 1.
You are given m queries of the following format:
* query l r — how many distinct values is x assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.
Then the description of t testcases follows.
The first line of each testcase contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of instructions in the program and the number of queries.
The second line of each testcase contains a program — a string of n characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
Each of the next m lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the description of the query.
The sum of n over all testcases doesn't exceed 2 ⋅ 10^5. The sum of m over all testcases doesn't exceed 2 ⋅ 10^5.
Output
For each testcase print m integers — for each query l, r print the number of distinct values variable x is assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order.
Example
Input
2
8 4
-+--+--+
1 8
2 8
2 5
1 1
4 10
+-++
1 1
1 2
2 2
1 3
2 3
3 3
1 4
2 4
3 4
4 4
Output
1
2
4
4
3
3
4
2
3
2
1
2
2
2
Note
The instructions that remain for each query of the first testcase are:
1. empty program — x was only equal to 0;
2. "-" — x had values 0 and -1;
3. "---+" — x had values 0, -1, -2, -3, -2 — there are 4 distinct values among them;
4. "+--+--+" — the distinct values are 1, 0, -1, -2.
Submitted Solution:
```
import sys
#py import math
input = sys.stdin.readline
# x,y,z=map(int,input().split())
# a = list(map(int,input().split()))
# string = input().rstrip()
tests = int(input())
for test in range(tests):
n,m =map(int,input().split())
program = input().rstrip()
value = [0]
currentValue = 0
for step in program:
if step == "-":
currentValue += -1
else:
currentValue += 1
value.append(currentValue)
print(value)
for query in range(m):
l,r =map(int,input().split())
maxLeft = max(value[0:l])
minLeft = min(value[0:l])
if r == n:
print(maxLeft-minLeft+1)
else:
shift = value[l-1]-value[r]
maxValue = max(maxLeft , shift+max(value[r:]))
minValue = min(minLeft , shift+min(value[r:]))
print(maxValue-minValue+1)
```
No
| 95,499 | [
0.1475830078125,
-0.074951171875,
-0.14404296875,
0.038299560546875,
-0.69775390625,
-0.257568359375,
-0.0286865234375,
0.0172119140625,
0.1611328125,
0.9228515625,
0.5712890625,
-0.038818359375,
0.34033203125,
-0.90380859375,
-0.78564453125,
-0.084716796875,
-0.86279296875,
-0.943... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types:
* increase x by 1;
* decrease x by 1.
You are given m queries of the following format:
* query l r — how many distinct values is x assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.
Then the description of t testcases follows.
The first line of each testcase contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of instructions in the program and the number of queries.
The second line of each testcase contains a program — a string of n characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
Each of the next m lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the description of the query.
The sum of n over all testcases doesn't exceed 2 ⋅ 10^5. The sum of m over all testcases doesn't exceed 2 ⋅ 10^5.
Output
For each testcase print m integers — for each query l, r print the number of distinct values variable x is assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order.
Example
Input
2
8 4
-+--+--+
1 8
2 8
2 5
1 1
4 10
+-++
1 1
1 2
2 2
1 3
2 3
3 3
1 4
2 4
3 4
4 4
Output
1
2
4
4
3
3
4
2
3
2
1
2
2
2
Note
The instructions that remain for each query of the first testcase are:
1. empty program — x was only equal to 0;
2. "-" — x had values 0 and -1;
3. "---+" — x had values 0, -1, -2, -3, -2 — there are 4 distinct values among them;
4. "+--+--+" — the distinct values are 1, 0, -1, -2.
Submitted Solution:
```
import math
import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
n,m=map(int,input().split())
script = input()
left=[(0,0,0)]
right=[[0,0]]
count=0
for i in range(len(script)):
if(script[i]=="+"):
count+=1
else:
count-=1
left.append((min(left[-1][0],count),count,max(left[-1][2],count)))
count=0
for i in range(len(script)-1,-1,-1):
k=[right[0][0],right[0][1]]
if(script[i]=="+"):
k[1]+=1
if(k[0]!=0):
k[0]+=1
else:
k[0]-=1
if(k[1]!=0):
k[1]-=1
right.insert(0,k)
for i in range(m):
a,b=map(int,input().split())
Min=min(left[a-1][0],left[a-1][1]+right[b][0])
Max=max(left[a-1][2],left[a-1][1]+right[b][1])
sys.stdout.write(str(Max-Min+1)+'\n')
```
No
| 95,500 | [
0.1475830078125,
-0.074951171875,
-0.14404296875,
0.038299560546875,
-0.69775390625,
-0.257568359375,
-0.0286865234375,
0.0172119140625,
0.1611328125,
0.9228515625,
0.5712890625,
-0.038818359375,
0.34033203125,
-0.90380859375,
-0.78564453125,
-0.084716796875,
-0.86279296875,
-0.943... | 11 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types:
* increase x by 1;
* decrease x by 1.
You are given m queries of the following format:
* query l r — how many distinct values is x assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order?
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.
Then the description of t testcases follows.
The first line of each testcase contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of instructions in the program and the number of queries.
The second line of each testcase contains a program — a string of n characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
Each of the next m lines contains two integers l and r (1 ≤ l ≤ r ≤ n) — the description of the query.
The sum of n over all testcases doesn't exceed 2 ⋅ 10^5. The sum of m over all testcases doesn't exceed 2 ⋅ 10^5.
Output
For each testcase print m integers — for each query l, r print the number of distinct values variable x is assigned to if all the instructions between the l-th one and the r-th one inclusive are ignored and the rest are executed without changing the order.
Example
Input
2
8 4
-+--+--+
1 8
2 8
2 5
1 1
4 10
+-++
1 1
1 2
2 2
1 3
2 3
3 3
1 4
2 4
3 4
4 4
Output
1
2
4
4
3
3
4
2
3
2
1
2
2
2
Note
The instructions that remain for each query of the first testcase are:
1. empty program — x was only equal to 0;
2. "-" — x had values 0 and -1;
3. "---+" — x had values 0, -1, -2, -3, -2 — there are 4 distinct values among them;
4. "+--+--+" — the distinct values are 1, 0, -1, -2.
Submitted Solution:
```
def solve():
n, q = map(int, input().split())
instructions = input()
a = [0]*n
x = 0
for i in range(n):
if instructions[i] == '-':
x -= 1
else:
x += 1
a[i] = x
lmis = [0]*n
lmas = [0]*n
rmis = [0]*n
rmas = [0]*n
for i in range(n):
if i == 0:
lmis[i] = min(a[i], 0)
lmas[i] = max(a[i], 0)
continue
if a[i] < lmis[i-1]:
lmis[i] = a[i]
else:
lmis[i] = lmis[i-1]
if a[i] > lmas[i-1]:
lmas[i] = a[i]
else:
lmas[i] = lmas[i-1]
for i in reversed(range(n)):
if i == n-1:
rmis[i] = a[i]
rmas[i] = a[i]
continue
if a[i] < rmis[i+1]:
rmis[i] = a[i]
else:
rmis[i] = rmis[i+1]
if a[i] > rmas[i+1]:
rmas[i] = a[i]
else:
rmas[i] = rmas[i+1]
for _ in range(q):
l, r = map(int, input().split())
r -= 1
l -= 1
delta = a[r] - a[l]
if instructions[l] == '+':
delta += 1
else:
delta -= 1
lmi = 0
lma = 0
if(l > 0):
lmi = lmis[l-1]
lma = lmas[l-1]
rmi = rmis[r]
rma = rmas[r]
rmi -= delta
rma -= delta
mi = min(lmi, rmi)
ma = max(lma, rma)
print('ans', ma-mi+1)
t = int(input())
for _ in range(t):
solve()
```
No
| 95,501 | [
0.1475830078125,
-0.074951171875,
-0.14404296875,
0.038299560546875,
-0.69775390625,
-0.257568359375,
-0.0286865234375,
0.0172119140625,
0.1611328125,
0.9228515625,
0.5712890625,
-0.038818359375,
0.34033203125,
-0.90380859375,
-0.78564453125,
-0.084716796875,
-0.86279296875,
-0.943... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya tries to break in a safe. He knows that a code consists of n numbers, and every number is a 0 or a 1. Vasya has made m attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is not said in which positions the wrong numbers stand. Vasya has been so unlucky that he hasn’t entered the code where would be more than 5 correct numbers. Now Vasya is completely bewildered: he thinks there’s a mistake in the system and it is self-contradictory. Help Vasya — calculate how many possible code variants are left that do not contradict the previous system responses.
Input
The first input line contains two integers n and m (6 ≤ n ≤ 35, 1 ≤ m ≤ 10) which represent the number of numbers in the code and the number of attempts made by Vasya. Then follow m lines, each containing space-separated si and ci which correspondingly indicate Vasya’s attempt (a line containing n numbers which are 0 or 1) and the system’s response (an integer from 0 to 5 inclusively).
Output
Print the single number which indicates how many possible code variants that do not contradict the m system responses are left.
Examples
Input
6 2
000000 2
010100 4
Output
6
Input
6 3
000000 2
010100 4
111100 0
Output
0
Input
6 3
000000 2
010100 4
111100 2
Output
1
Tags: brute force
Correct Solution:
```
import itertools
n,m=map(int,input().split())
def gen(s,d):
ans=[]
a=int(str(s),2)
A=int(a)
for i in itertools.combinations(list(range(n)), d):
c=A
for e in i:c=c ^ 1<<e
ans.append(c)
return ans
a,b=map(int,input().split())
cur=gen(a,b)
#print(cur)
for i in range(m-1):
a,b=map(int,input().split())
cur=[x for x in cur if(bin(x^int(str(a),2)).count("1")==b)]
#print(*cur)
print(len(cur))
```
| 95,653 | [
0.438720703125,
-0.2193603515625,
-0.0599365234375,
0.2100830078125,
-0.45654296875,
-0.64453125,
0.199462890625,
-0.0323486328125,
0.096435546875,
0.908203125,
0.408447265625,
0.1287841796875,
0.1251220703125,
-0.3642578125,
-0.392578125,
-0.2142333984375,
-0.4033203125,
-0.554199... | 11 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya tries to break in a safe. He knows that a code consists of n numbers, and every number is a 0 or a 1. Vasya has made m attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is not said in which positions the wrong numbers stand. Vasya has been so unlucky that he hasn’t entered the code where would be more than 5 correct numbers. Now Vasya is completely bewildered: he thinks there’s a mistake in the system and it is self-contradictory. Help Vasya — calculate how many possible code variants are left that do not contradict the previous system responses.
Input
The first input line contains two integers n and m (6 ≤ n ≤ 35, 1 ≤ m ≤ 10) which represent the number of numbers in the code and the number of attempts made by Vasya. Then follow m lines, each containing space-separated si and ci which correspondingly indicate Vasya’s attempt (a line containing n numbers which are 0 or 1) and the system’s response (an integer from 0 to 5 inclusively).
Output
Print the single number which indicates how many possible code variants that do not contradict the m system responses are left.
Examples
Input
6 2
000000 2
010100 4
Output
6
Input
6 3
000000 2
010100 4
111100 0
Output
0
Input
6 3
000000 2
010100 4
111100 2
Output
1
Tags: brute force
Correct Solution:
```
import sys
from array import array # noqa: F401
from itertools import combinations
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m = map(int, input().split())
s = set()
x = set()
for i in range(m):
a, k = input().split()
k = int(k)
a = int(a, 2)
x.add(str(a))
cur_s = set()
for c in combinations(range(n), r=k):
mask = 0
for j in c:
mask |= (1 << j)
cur_s.add(str(a ^ mask))
if i == 0:
s = cur_s
else:
s.intersection_update(cur_s)
print(len(s - x))
```
| 95,654 | [
0.43603515625,
-0.22998046875,
-0.027587890625,
0.22802734375,
-0.49072265625,
-0.61328125,
0.1844482421875,
-0.0254974365234375,
0.09033203125,
0.88818359375,
0.430908203125,
0.1773681640625,
0.0906982421875,
-0.385986328125,
-0.4111328125,
-0.15234375,
-0.473876953125,
-0.6318359... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.