message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3} | instruction | 0 | 16,503 | 14 | 33,006 |
Tags: binary search, math, sortings
Correct Solution:
```
def chtoetodvoichnyupoisk(a, c):
r = len(a)
l = 0
while r - l > 1:
s = (l + r) // 2
if s == len(a):
if a[s - 1] >= c:
r = s
else:
l = s
if a[s] >= c:
r = s
else:
l = s
if r == 1 and a[0] >= c:
r = 0
return r
def cycle(k, a):
sa = sorted(a)
r = sa[-1]
l = 0
while r - l > 1:
c = (r + l) // 2
i = chtoetodvoichnyupoisk(sa, c)
s = sum(sa[:i]) + c * (len(a) - i)
if s > k:
r = c
if s < k:
l = c
if s == k:
return c
return l
n, k = map(int, input().split())
a = list(map(int, input().split()))
q = list(range(1, n + 1))
if k > sum(a):
print(-1)
else:
c = cycle(k, a)
sa = sorted(a)
i = chtoetodvoichnyupoisk(sa, c)
s = sum(sa[:i]) + c * (len(a) - i)
k = k - s
a = [i - c for i in a]
q = [i for i in q if a[i - 1] > 0]
q = q[k:] + list(filter(lambda x: a[x - 1] > 1, q[:k]))
print(*q)
``` | output | 1 | 16,503 | 14 | 33,007 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3} | instruction | 0 | 16,504 | 14 | 33,008 |
Tags: binary search, math, sortings
Correct Solution:
```
from sys import stdin, stdout
n, k = map(int, stdin.readline().split())
values = list(map(int, stdin.readline().split()))
if sum(values) < k:
stdout.write('-1')
elif sum(values) > k:
l = 0
r = k + 1
while (r - l > 1):
m = (r + l) // 2
cnt = 0
for i in range(n):
cnt += min(values[i], m)
if cnt > k:
r = m
else:
l = m
for i in range(n):
k -= min(values[i], l)
values[i] -= min(values[i], l)
i = 0
while k:
if values[i]:
values[i] -= 1
k -= 1
i = (i + 1) % n
for j in range(i, i + n):
if values[j % n]:
stdout.write(str(j % n + 1) + ' ')
``` | output | 1 | 16,504 | 14 | 33,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3} | instruction | 0 | 16,505 | 14 | 33,010 |
Tags: binary search, math, sortings
Correct Solution:
```
from sys import stdin
n,k = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
if sum(a) < k:
print(-1)
elif sum(a) == k:
pass
else:
diff = 0
kCopy = k
sortA = sorted(a, reverse=True)
while sortA:
nxt = sortA[-1]
nxt -= diff
if len(sortA)*nxt <= k:
diff += nxt
k -= len(sortA)*nxt
sortA.pop()
else:
break
p = k%len(sortA)
diff += k//len(sortA)
ind = 0
while p:
if a[ind] > diff:
p -= 1
ind += 1
outL = []
for x in range(ind,len(a)):
if a[x] > diff:
outL.append(str(x+1))
for x in range(ind):
if a[x] > diff+1:
outL.append(str(x+1))
if outL:
print(' '.join(outL))
``` | output | 1 | 16,505 | 14 | 33,011 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3} | instruction | 0 | 16,506 | 14 | 33,012 |
Tags: binary search, math, sortings
Correct Solution:
```
read = lambda: map(int, input().split())
n, k = read()
a = list(read())
b = sorted([(a[i], i) for i in range(n)])
if sum(a) < k:
print(-1)
exit()
j = 0
x2 = 0
for i in range(n):
x = b[i][0]
cur = (n - j) * (x - x2)
if cur > k: break
x2 = x
k -= cur
j += 1
if n == j:
print()
exit()
y = k // (n - j)
for i in range(n):
a[i] -= y
m = k % (n - j)
ans = []
j1 = 0
i1 = 0
for i in range(n):
if a[i] > x2 and j1 < m:
j1 += 1
if a[i] > x2 + 1:
ans.append(i + 1)
if j1 == m:
i1 = i + 1
if m == 0: i1 = 0
break
c = [i + 1 for i in range(i1, n) if a[i] > x2]
ans = c + ans
print(*ans)
``` | output | 1 | 16,506 | 14 | 33,013 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3} | instruction | 0 | 16,507 | 14 | 33,014 |
Tags: binary search, math, sortings
Correct Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = len(a)
while c and k // c:
t = k // c
v = 0
for i in range(len(a)):
if a[i] == 0:
continue
v += a[i] - max(0, a[i] - t)
a[i] = max(0, a[i] - t)
if a[i] == 0:
c -= 1
k -= v
for i in range(len(a)):
if k == 0:
break
if a[i] != 0:
k -= 1
a[i] -= 1
res = []
for j in range(len(a)):
if a[(j + i) % len(a)] != 0:
res.append(str((j + i) % len(a) + 1))
if k > 0:
print(-1)
else:
print(' '.join(res))
``` | output | 1 | 16,507 | 14 | 33,015 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3} | instruction | 0 | 16,508 | 14 | 33,016 |
Tags: binary search, math, sortings
Correct Solution:
```
from bisect import bisect_right
from itertools import accumulate
def rest(k, a, q):
return q[k:] + list(filter(lambda x: a[x - 1] > 1, q[:k]))
def cycle(a, k):
n = len(a)
s = sorted(a)
sm = list(accumulate(s))
b = [(sm[i - 1] if i > 0 else 0) + s[i] * (n - i) for i in range(n)]
r = bisect_right(b, k)
if r == 0:
return k // n
else:
return s[r - 1] + (k - b[r - 1]) // (n - r)
def answer(k, a, q):
d = sum(a)
if k > d:
return [-1]
if k == d:
return []
if k < len(q):
return rest(k, a, q)
r = cycle(a, k)
s = sorted(a)
w = bisect_right(s, r)
p = sum(s[:w]) + r * (len(a) - w)
a = [max(i - r, 0) for i in a]
q = list(filter(lambda x: a[x - 1] > 0, q))
return rest(k - p, a, q)
n, k = map(int, input().split())
a = list(map(int, input().split()))
q = list(range(1, n + 1))
print(*answer(k, a, q))
``` | output | 1 | 16,508 | 14 | 33,017 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3} | instruction | 0 | 16,509 | 14 | 33,018 |
Tags: binary search, math, sortings
Correct Solution:
```
n , k = map(int,input().split())
ans = [*map(int,input().split())]
a = sum(ans)
if a<k:
print('-1')
elif a>k:
lef=0
rig = k+1
while lef+1<rig:
mid = (lef+rig)//2
c=0
for i in range(n):
c += min(ans[i],mid)
if c > k:
rig=mid
else:
lef=mid
for i in range(n):
k-=min(ans[i],lef)
ans[i]-=min(ans[i],lef)
i=0
while k>0:
if ans[i]:
ans[i]-=1
k-=1
i = (i+1)%n
for j in range(i,i+n):
if ans[j%n]:
print(j%n +1 , end=' ')
``` | output | 1 | 16,509 | 14 | 33,019 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3}
Submitted Solution:
```
import sys
from array import array # noqa: F401
from collections import deque
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, k = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) < k:
print(-1)
exit()
ok, ng = 0, 10**9 + 10
while abs(ok - ng) > 1:
mid = (ok + ng) >> 1
if sum(mid if mid < x else x for x in a) <= k:
ok = mid
else:
ng = mid
index = deque([i + 1 for i in range(n) if a[i] > ok])
dq = deque([x - ok for x in a if x > ok])
k -= sum(ok if ok < x else x for x in a)
for _ in range(k):
dq[0] -= 1
if dq[0]:
dq.rotate(-1)
index.rotate(-1)
else:
dq.popleft()
index.popleft()
print(*index)
``` | instruction | 0 | 16,510 | 14 | 33,020 |
Yes | output | 1 | 16,510 | 14 | 33,021 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3}
Submitted Solution:
```
from bisect import bisect_right
from itertools import accumulate
def rest(k, a, q):
for i in range(k):
if a[q[0] - 1] == 1:
del q[0]
else:
q = q[1:] + [q[0]]
return q
def cycle3(a, k):
r = t = p = i = 0
s = sorted(a)
while t + p <= k:
t += p
p = len(s) - i
r += 1
while i < len(s) and s[i] <= r:
i += 1
return r - 1 # , t
def cycle4(a, k):
s = sorted(a)
sm = list(accumulate(s))
n = len(a)
left = 0
right = s[-1]
while right - left > 1:
mid = (left + right) // 2
w = bisect_right(s, mid)
t = sm[w - 1] + mid * (n - w)
if t == k:
return mid
if t > k:
right = mid
else:
left = mid
return left
def f1(k, a, q):
d = sum(a)
if k > d:
return [-1]
if k == d:
return []
r = cycle4(a, k)
s = sorted(a)
w = bisect_right(s, r)
p = sum(s[:w]) + r * (len(a) - w)
a = [max(i - r, 0) for i in a]
q = list(filter(lambda x: a[x - 1] > 0, q))
return rest(k - p, a, q)
n, k = map(int, input().split())
a = list(map(int, input().split()))
q = list(range(1, n + 1))
print(*f1(k, a, q))
``` | instruction | 0 | 16,511 | 14 | 33,022 |
No | output | 1 | 16,511 | 14 | 33,023 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3}
Submitted Solution:
```
from sys import stdin, stdout
n, k = map(int, stdin.readline().split())
values = list(map(int, stdin.readline().split()))
l = 0
r = k + 10
while (r - l > 1):
m = (r + l) // 2
cnt = 0
for i in range(n):
cnt += min(values[i], m)
if cnt > k:
r = m
else:
l = m
if l == k + 9:
stdout.write('-1')
else:
for i in range(n):
k -= min(values[i], l)
values[i] -= min(values[i], l)
i = 0
while k:
if values[i]:
values[i] -= 1
k -= 1
i = (i + 1) % n
if not k:
break
for j in range(i, i + n):
if values[j % n]:
stdout.write(str(j % n + 1) + ' ')
``` | instruction | 0 | 16,512 | 14 | 33,024 |
No | output | 1 | 16,512 | 14 | 33,025 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3}
Submitted Solution:
```
n , k = map(int,input().split())
ans = [*map(int,input().split())]
lis=[i for i in range(n)]
li = list(set(sorted(ans)))
p=m=b=u=0
sa = sum(ans)
if k>sa:
print("-1")
elif k==sa:
print('')
else:
while k>=0:
m=li[p]-m
b = len(ans)
# print(b,m,k)
if k>=m*b:
k-=m*b
# print(ans,len(ans))
i=0
while i< b-u:
if ans[i]>0:
ans[i]-=m
if ans[i]==0:
ans.pop(i)
lis.pop(i)
u+=1
i-=1
i+=1
# print(ans,"ll")
else:
r = k-(k//b)*b
# print(r)
i=u=0
while i< r-u:
if ans[i]>0:
ans[i]-=m
if ans[i]==0:
ans.pop(i)
lis.pop(i)
u+=1
i-=1
i+=1
# print(ans)
for j in range(i,len(ans),1):
print(lis[j]+1,end=' ')
for j in range(i):
print(lis[j]+1,end=' ')
break;
p+=1
``` | instruction | 0 | 16,513 | 14 | 33,026 |
No | output | 1 | 16,513 | 14 | 33,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
Doctor plans to go home after receiving k animals, and therefore what the queue will look like at that moment is important for him. Since the doctor works long hours and she can't get distracted like that after all, she asked you to figure it out.
Input
The first line of input data contains two space-separated integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 1014). In the second line are given space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
Output
If the doctor will overall carry out less than k examinations, print a single number "-1" (without quotes). Otherwise, print the sequence of numbers — number of animals in the order in which they stand in the queue.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.
Examples
Input
3 3
1 2 1
Output
2
Input
4 10
3 3 2 1
Output
-1
Input
7 10
1 3 3 1 2 3 1
Output
6 2 3
Note
In the first sample test:
* Before examination: {1, 2, 3}
* After the first examination: {2, 3}
* After the second examination: {3, 2}
* After the third examination: {2}
In the second sample test:
* Before examination: {1, 2, 3, 4, 5, 6, 7}
* After the first examination: {2, 3, 4, 5, 6, 7}
* After the second examination: {3, 4, 5, 6, 7, 2}
* After the third examination: {4, 5, 6, 7, 2, 3}
* After the fourth examination: {5, 6, 7, 2, 3}
* After the fifth examination: {6, 7, 2, 3, 5}
* After the sixth examination: {7, 2, 3, 5, 6}
* After the seventh examination: {2, 3, 5, 6}
* After the eighth examination: {3, 5, 6, 2}
* After the ninth examination: {5, 6, 2, 3}
* After the tenth examination: {6, 2, 3}
Submitted Solution:
```
read = lambda: map(int, input().split())
n, k = read()
a = list(read())
b = sorted([(a[i], i) for i in range(n)])
if sum(a) < k:
print(-1)
exit()
j = 0
x2 = 0
for i in range(n):
x = b[i][0]
cur = (n - j) * x
if cur > k: break
x2 = x
k -= cur
j += 1
if n == j:
print()
exit()
#y = k // (n - j)
#for i in range(n):
# a[i] -= y
m = k % (n - j)
ans = []
j1 = 0
i1 = 0
for i in range(n):
if a[i] > x2 and j1 < m:
j1 += 1
if a[i] > x2 + 1:
ans.append(i + 1)
if j1 == m:
i1 = i + 1
if m == 0: i1 = 0
break
c = [i + 1 for i in range(i1, n) if a[i] > x2]
ans = c + ans
print(*ans)
``` | instruction | 0 | 16,514 | 14 | 33,028 |
No | output | 1 | 16,514 | 14 | 33,029 |
Provide a correct Python 3 solution for this coding contest problem.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3 | instruction | 0 | 16,562 | 14 | 33,124 |
"Correct Solution:
```
N,M = map(int,input().split())
F = [[] for _ in range(N)]
for i in range(M):
A,B = map(int,input().split())
A -= 1
B -= 1
F[A].append(B)
F[B].append(A)
a = [1 for _ in range(N)]
l = []
b = [0 for _ in range(N)]
for j in range(N):
mem = 1
a[j] = 0
nex = F[j]
while True:
que = nex
nex = []
for k in que:
if a[k] == 1:
a[k] = 0
mem += 1
nex.extend(F[k])
if nex == []:
break
l.append(mem)
print(max(l))
``` | output | 1 | 16,562 | 14 | 33,125 |
Provide a correct Python 3 solution for this coding contest problem.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3 | instruction | 0 | 16,563 | 14 | 33,126 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
root=[-1]*(n+1)
def r(x):
if root[x]<0:
return x
else:
root[x]=r(root[x])
return root[x]
def unite(x,y):
x=r(x)
y=r(y)
if x==y:
return
if x>y:
x,y=y,x
root[x]+=root[y]
root[y]=x
def size(x):
x=r(x)
return -root[x]
for i in range(m):
x,y=map(int,input().split())
unite(x,y)
ans=0
for i in range(n):
ans=max(ans,size(i+1))
print(ans)
``` | output | 1 | 16,563 | 14 | 33,127 |
Provide a correct Python 3 solution for this coding contest problem.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3 | instruction | 0 | 16,564 | 14 | 33,128 |
"Correct Solution:
```
from collections import deque
N, M = map(int, input().split())
friends = [[] for _ in range(N+1)]
for __ in range(M):
a, b = map(int, input().split())
friends[a].append(b)
friends[b].append(a)
checked = [0 for ___ in range(N+1)]
answer = 1
for i in range(1, N+1):
friend = deque(friends[i])
cnt = 0
while(len(friend) > 0):
f = friend.popleft()
if checked[f] != 0:
continue
else:
checked[f] = 1
cnt += 1
for ff in friends[f]:
friend.append(ff)
answer = max(answer, cnt)
print(answer)
``` | output | 1 | 16,564 | 14 | 33,129 |
Provide a correct Python 3 solution for this coding contest problem.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3 | instruction | 0 | 16,565 | 14 | 33,130 |
"Correct Solution:
```
n,m = map(int,input().split())
g = [set() for i in range(n)]
visited = [False] * n
group = []
for i in range(m):
a,b = map(int,input().split())
a -= 1
b -= 1
g[a].add(b)
g[b].add(a)
for i in range(n):
if visited[i]:
continue
s = set()
q = [i]
while len(q) > 0:
p = q.pop()
visited[p] = True
s.add(p)
for x in g[p]:
if visited[x]:
continue
q.append(x)
group.append(s)
ans = 0
for x in group:
ans = max(ans, len(x))
print(ans)
``` | output | 1 | 16,565 | 14 | 33,131 |
Provide a correct Python 3 solution for this coding contest problem.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3 | instruction | 0 | 16,566 | 14 | 33,132 |
"Correct Solution:
```
N,M=map(int,input().split())
F = [set() for _ in range(N)]
for _ in range(M):
a,b = map(lambda x: int(x)-1, input().split())
F[a].add(b)
F[b].add(a)
from collections import deque
def bfs():
ans = 1
done = set()
for i in range(N):
if i in done: continue
queue = deque([i])
num = 0
while queue:
p = queue.popleft()
for p2 in F[p]:
if p2 in done: continue
done.add(p2)
queue.append(p2)
num += 1
ans = max(ans,num)
return ans
print(bfs())
``` | output | 1 | 16,566 | 14 | 33,133 |
Provide a correct Python 3 solution for this coding contest problem.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3 | instruction | 0 | 16,567 | 14 | 33,134 |
"Correct Solution:
```
n,m=map(int,input().split())
root=[-1]*n
def r(x): #-1の項が何番目かを特定
if root[x]<0: #x番目が-1ならx(>=0)を返す
return x
else: #x番目が0以上なら-1の項に到達するまで回す
root[x]=r(root[x])
return root[x] #-1の項に到達したらその項が何番目かを返す
def unite(x,y):
x=r(x)
y=r(y)
if x==y: #同じ項に到達した場合は処理の必要なし
return
root[x]+=root[y] #-1ずつ加算していく
root[y]=x #-1を足した後は適当な数に変える(重複回避)
for i in range(m):
a,b=map(int,input().split())
a-=1 #リストの序数に合わせる
b-=1
unite(a,b) #各人間がどのくらい友達がいるか
ans=0
for i in range(n):
ans=max(ans,-root[i]) #最多保有友人数が何人か
print(ans)
``` | output | 1 | 16,567 | 14 | 33,135 |
Provide a correct Python 3 solution for this coding contest problem.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3 | instruction | 0 | 16,568 | 14 | 33,136 |
"Correct Solution:
```
import queue
n,m=map(int,input().split())
a=[[] for j in range(n)]
for i in range(0,m):
b,c=map(int,input().split())
a[b-1].append(c-1)
a[c-1].append(b-1)
re=[0 for i in range(n)]
le=[0]
for i in range(0,n):
if re[i]==0:
ans=queue.Queue()
ans.put(i)
le.append(1)
re[i]=1
while ans.empty()==False:
d=ans.get()
for j in range(len(a[d])):
if re[a[d][j]]==0:
ans.put(a[d][j])
re[a[d][j]]=1
le[-1]+=1
print(max(le))
``` | output | 1 | 16,568 | 14 | 33,137 |
Provide a correct Python 3 solution for this coding contest problem.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3 | instruction | 0 | 16,569 | 14 | 33,138 |
"Correct Solution:
```
N,M=map(int,input().split())
par=[i for i in range(N+1)]
size=[1 for i in range(N+1)]
def find(x):
if x!=par[x]:
par[x]=find(par[x])
return par[x]
def union(x,y):
if find(x)!=find(y):
x, y = par[x], par[y]
par[y] = par[x]
size[x] += size[y]
res=N
for i in range(M):
s,e=map(int,input().split())
union(s,e)
print(max(size))
``` | output | 1 | 16,569 | 14 | 33,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3
Submitted Solution:
```
import collections as cc
I=lambda:list(map(int,input().split()))
mod=10**9+7
n,m=I()
ds=[i for i in range(n+1)]
r=[1]*(n+1)
def find(a):
while ds[a]!=a:
a=ds[a]
return a
def join(a,b):
x=find(a)
y=find(b)
if x!=y:
ds[x]=ds[y]=min(x,y)
r[min(x,y)]+=r[max(x,y)]
for i in range(m):
x,y=I()
join(x,y)
temp=cc.Counter(ds[1:])
print(max(r))
``` | instruction | 0 | 16,570 | 14 | 33,140 |
Yes | output | 1 | 16,570 | 14 | 33,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3
Submitted Solution:
```
import sys
sys.setrecursionlimit(10 ** 8)
n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
a -= 1; b-= 1
g[a].append(b)
g[b].append(a)
friends = [0 for _ in range(n)]
def dfs(v):
global n
friends[v] = n
n += 1
for next_v in g[v]:
if friends[next_v] == 0:
dfs(next_v)
for i in range(n):
if friends[i] == 0:
n = 1
dfs(i)
print(max(friends))
``` | instruction | 0 | 16,571 | 14 | 33,142 |
Yes | output | 1 | 16,571 | 14 | 33,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**9)
n, m = map(int, input().split())
root = [-1]*n
def r(x):
if root[x] < 0 :
return x
else:
root[x] = r(root[x])
return root[x]
def unite(x, y):
x = r(x)
y = r(y)
if x == y:
return
root[x] += root[y]
root[y] = x
def size(x):
x = r(x)
return - root[x]
for i in range(m):
x, y = map(int, input().split())
x -= 1
y -= 1
unite(x,y)
max_size = max(map(size,range(n)))
print(max_size)
``` | instruction | 0 | 16,572 | 14 | 33,144 |
Yes | output | 1 | 16,572 | 14 | 33,145 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3
Submitted Solution:
```
n,m = map(int, input().split())
par = [0]*(n+1)
group = [1]*(n+1)
for i in range(1,n+1): par[i]=i
def root(x):
if par[x]==x: return x
return root(par[x])
def union(x,y):
rx = root(x)
ry = root(y)
if rx==ry: return
par[max(rx,ry)] = min(rx,ry)
group[min(rx,ry)] += group[max(rx,ry)]
for _ in range(m):
f1,f2 = map(int, input().split())
union(f1,f2)
print(max(group))
``` | instruction | 0 | 16,573 | 14 | 33,146 |
Yes | output | 1 | 16,573 | 14 | 33,147 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3
Submitted Solution:
```
from collections import Counter
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n)] #親
self.rank = [0 for _ in range(n)] #根の深さ
#xの属する木の根を求める
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
#xとyの属する集合のマージ
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
#xとyが同じ集合に属するかを判定
def same(self, x, y):
return self.find(x) == self.find(y)
N, M = map(int, input().split())
union = UnionFind(N)
for _ in range(M):
a, b = map(int, input().split())
union.unite(a-1, b-1)
ans = 0
c = Counter(union.par)
for k, v in c.items():
ans = max(ans, v)
print(ans)
``` | instruction | 0 | 16,574 | 14 | 33,148 |
No | output | 1 | 16,574 | 14 | 33,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3
Submitted Solution:
```
n,m=list(map(int,input().split()))
f=[set() for i in range(n)]
from collections import defaultdict
g=[set() for i in range(n)]
par=[i for i in range(n)]
def root(i):
if par[i]==i:
return i
else:
return root(par[i])
def unite(x,y):
rx=root(x)
ry=root(y)
if rx!=ry:
par[rx]=ry
def same(x,y):
return root(x)==root(y)
for i in range(m):
a,b=list(map(int,input().split()))
# f[a-1].add(b-1)
# f[b-1].add(a-1)
a-=1
b-=1
unite(a,b)
ans=0
ro=defaultdict(int)
for i in range(n):
ro[root(i)]+=1
print(max(ro.values()))
``` | instruction | 0 | 16,575 | 14 | 33,150 |
No | output | 1 | 16,575 | 14 | 33,151 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3
Submitted Solution:
```
N, M = map(int, input().split())
L = []
N2 = [[0]*N for i in range(N)]
ans = 0
for _ in range(M):
A, B = map(int, input().split())
N2[A-1][B-1] = 1; N2[B-1][A-1] =1
for i in range(N):
ans = max(ans, sum(N2[i])+1)
print(ans)
``` | instruction | 0 | 16,576 | 14 | 33,152 |
No | output | 1 | 16,576 | 14 | 33,153 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
At least how many groups does he need to make?
Constraints
* 2 \leq N \leq 2\times 10^5
* 0 \leq M \leq 2\times 10^5
* 1\leq A_i,B_i\leq N
* A_i \neq B_i
Input
Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M
Output
Print the answer.
Examples
Input
5 3
1 2
3 4
5 1
Output
3
Input
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
4
Input
10 4
3 1
4 1
5 9
2 6
Output
3
Submitted Solution:
```
from collections import defaultdict, deque
n, m = map(int, input().split())
g = defaultdict(set)
for _ in range(m):
a, b = map(int, input().split())
g[a - 1].add(b - 1)
g[b - 1].add(a - 1)
visited = [False]*n
ans = 0
for i in range(n):
if not visited[i] and i in g:
# cc = []
count = 1
q = deque([i])
visited[i] = 1
while q:
node = q.popleft()
for nbr in g[node]:
if not visited[nbr]:
q.append(nbr)
visited[nbr] = True
count += 1
# ans = max(ans, len(cc))
ans = max(ans, count)
print(ans)
``` | instruction | 0 | 16,577 | 14 | 33,154 |
No | output | 1 | 16,577 | 14 | 33,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7. | instruction | 0 | 16,812 | 14 | 33,624 |
Tags: constructive algorithms, greedy, implementation, math
Correct Solution:
```
print(('01'*99999)[:int(input().split()[0])])
# Made By Mostafa_Khaled
``` | output | 1 | 16,812 | 14 | 33,625 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7. | instruction | 0 | 16,813 | 14 | 33,626 |
Tags: constructive algorithms, greedy, implementation, math
Correct Solution:
```
def calc(s):
presum = [0]
for ch in s:
presum.append(presum[-1])
if ch == '1':
presum[-1] += 1
ans = 0
for (l,r) in points:
ans += ((r-l+1) - (presum[r] - presum[l-1])) * (presum[r] - presum[l-1])
return ans
n, m = list(map(int, input().split()))
points = []
for _ in range(m):
points.append(list(map(int, input().split())))
ans1 = "10" * (n//2)
ans2 = "01" * (n//2)
if n%2:
ans1 += '1'
ans2 += '0'
print(ans1 if calc(ans1) > calc(ans2) else ans2)
``` | output | 1 | 16,813 | 14 | 33,627 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7. | instruction | 0 | 16,814 | 14 | 33,628 |
Tags: constructive algorithms, greedy, implementation, math
Correct Solution:
```
a=int(input().split()[0])
print("10"*(a//2)+'1'*(a%2))
``` | output | 1 | 16,814 | 14 | 33,629 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7. | instruction | 0 | 16,815 | 14 | 33,630 |
Tags: constructive algorithms, greedy, implementation, math
Correct Solution:
```
n, m = map(int, input().split())
clients = []
for i in range(m):
temp_l = list(map(int, input().split()))
clients.append(temp_l)
print('10' * (n // 2), end='')
if n % 2 == 1:
print('1')
``` | output | 1 | 16,815 | 14 | 33,631 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7. | instruction | 0 | 16,816 | 14 | 33,632 |
Tags: constructive algorithms, greedy, implementation, math
Correct Solution:
```
n,m = map(int,input().split())
for i in range(m):
input()
print(n // 2 * "01" + "0" * (n % 2))
``` | output | 1 | 16,816 | 14 | 33,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7. | instruction | 0 | 16,817 | 14 | 33,634 |
Tags: constructive algorithms, greedy, implementation, math
Correct Solution:
```
n, m = map(int, input().split())
result = ''
for i in range(n):
if i % 2 == 0:
result += '0'
else:
result += '1'
print(result)
``` | output | 1 | 16,817 | 14 | 33,635 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7. | instruction | 0 | 16,818 | 14 | 33,636 |
Tags: constructive algorithms, greedy, implementation, math
Correct Solution:
```
n, m = map(int, input().split())
for i in range(m):
a, b = map(int, input().split())
ans = [int(i % 2 == 0) for i in range(n)]
print("".join(map(str, ans)))
``` | output | 1 | 16,818 | 14 | 33,637 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7. | instruction | 0 | 16,819 | 14 | 33,638 |
Tags: constructive algorithms, greedy, implementation, math
Correct Solution:
```
import math
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
if (i%2==1):
print("1",end="")
else:
print("0",end="")
``` | output | 1 | 16,819 | 14 | 33,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7.
Submitted Solution:
```
n,m = map(int, input().split())
for i in range(m):
input()
str = ""
for i in range(n):
if i%2:
str+="1"
else:
str+="0"
print(str)
``` | instruction | 0 | 16,820 | 14 | 33,640 |
Yes | output | 1 | 16,820 | 14 | 33,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7.
Submitted Solution:
```
td=list(map(int,input().split()))
t=td[0]
d=td[1]
l=[]
for i in range(1,t+1):
if(i%2==0):
l.append("1")
else:
l.append("0")
for i in l:
print(i,end='')
``` | instruction | 0 | 16,821 | 14 | 33,642 |
Yes | output | 1 | 16,821 | 14 | 33,643 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7.
Submitted Solution:
```
a,b=map(int,input().split())
l=[]
for i in range(b):
m,n=map(int,input().split())
l.append([m,n])
s=""
for i in range(a):
if(i%2==0):
s+="1"
else:
s+="0"
print(s)
``` | instruction | 0 | 16,822 | 14 | 33,644 |
Yes | output | 1 | 16,822 | 14 | 33,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7.
Submitted Solution:
```
def solve():
n, m = map(int, input().split())
ans = ''
for i in range(n):
ans += str(i % 2)
print(ans)
solve()
``` | instruction | 0 | 16,823 | 14 | 33,646 |
Yes | output | 1 | 16,823 | 14 | 33,647 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7.
Submitted Solution:
```
n,m=[int(x) for x in input().split()]
a=[]
for ii in range(m):
a.append([int(x) for x in input().split()])
b=[]
for i in a:
b.append([i[1]-i[0]]+i)
b=sorted(b)
a=[]
for i in b:
a.append(i[1:])
arr=[0]*n
vis=[0]*n
print(a)
for i in range(m):
pp=a[i][1]-a[i][0]+1
c0=0
c1=0
cv0=0
cv1=0
for j in range(a[i][0]-1,a[i][1]):
if(arr[j]==0 and vis[j]==0):
c0+=1
elif(arr[j]==1 and vis[j]==0):
c1+=1
if(arr[j]==0 and vis[j]==1):
cv0+=1
elif(arr[j]==1 and vis[j]==1):
cv1+=1
if(c0+cv0>c1+cv1):
for j in range(a[i][0]-1,a[i][1]):
if(arr[j]==0 and vis[j]==0):
arr[j]+=1
c0-=1
c1+=1
if(abs(c0+cv0-cv1-c1)<=1):
break
else:
for j in range(a[i][0]-1,a[i][1]):
if(arr[j]==1 and vis[j]==0):
arr[j]-=1
c0+=1
c1-=1
if(abs(c0+cv0-cv1-c1)<=1):
break
for j in range(a[i][0]-1,a[i][1]):
vis[j]=1
"""
if(pp%2==0):
p1=pp//2
p2=pp//2
else:
p1=(pp//2)
p2=pp-p1
t1=arr[a[i][0]-1]
t2=t1^1
for j in range(a[i][0]-1,a[i][0]+p1-1):
arr[j]=t1
for j in range(a[i][0]+p1-1,a[i][1]):
arr[j]=t2
"""
for i in arr:
print(i,end='')
print()
``` | instruction | 0 | 16,824 | 14 | 33,648 |
No | output | 1 | 16,824 | 14 | 33,649 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7.
Submitted Solution:
```
import sys
lines = []
for line in sys.stdin:
lines.append(line)
print(lines[0])
``` | instruction | 0 | 16,825 | 14 | 33,650 |
No | output | 1 | 16,825 | 14 | 33,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7.
Submitted Solution:
```
n,m=[int(x) for x in input().split()]
a=[]
for ii in range(m):
a.append([int(x) for x in input().split()])
b=[]
for i in a:
b.append(i[::-1])
b=sorted(b)
a=[]
for i in b:
a.append(i[::-1])
arr=[1]*n
for i in range(m):
pp=a[i][1]-a[i][0]+1
if(pp%2==0):
p1=pp//2
p2=pp//2
else:
p1=(pp//2)+1
p2=pp-p1
t1=arr[a[i][0]-1]
t2=t1^1
for j in range(a[i][0]-1,a[i][0]+p1-1):
arr[j]=t1
for j in range(a[i][0]+p1-1,a[i][1]):
arr[j]=t2
for i in arr:
print(i,end='')
print()
``` | instruction | 0 | 16,826 | 14 | 33,652 |
No | output | 1 | 16,826 | 14 | 33,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from l_i to r_i inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.
Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
Input
The first line contains two integers n and m (1≤ n, m≤ 10^3) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers l_i and r_i (1≤ l_i≤ r_i≤ n), meaning that i-th visitor will visit all flowers from l_i to r_i inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
110010
Note
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
* in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅ 2=2;
* in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4.
The total beauty is equal to 2+2+4=8.
In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;
* in the segment [5…6], there are one rose and one lily, so the beauty is equal to 1⋅ 1=1;
* in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅ 2=4;
* in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅ 1=2.
The total beauty is equal to 1+4+2=7.
Submitted Solution:
```
from math import ceil
n, m = list(map(int,input().split()))
s = [0 for _ in range(n)]
a = []
for i in range(m):
l, r = list(map(int,input().split()))
d = r-l+1
a.append([l,r,d])
a.sort(key = lambda x:x[2], reverse=True)
for j in range(m):
med = (a[j][2] / 2)
rose, lose = int(med), ceil(med)
for k in range(a[j][0] - 1, a[j][1]):
if rose!=0:
if s[k] == 0:
rose-=1
s[k]=1
else:
lose-=1
else:
if s[k] == 0:
lose-=1
print(''.join(list(map(str,s))))
``` | instruction | 0 | 16,827 | 14 | 33,654 |
No | output | 1 | 16,827 | 14 | 33,655 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
<image>
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output
On the single line of the output print the number of groups of magnets.
Examples
Input
6
10
10
10
01
10
10
Output
3
Input
4
01
01
10
10
Output
2
Note
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | instruction | 0 | 17,127 | 14 | 34,254 |
Tags: implementation
Correct Solution:
```
n=int(input())
ans=0
l='$$'
for _ in range(n):
s=input()
if s!=l:
ans+=1
l=s
print(ans)
``` | output | 1 | 17,127 | 14 | 34,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
<image>
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output
On the single line of the output print the number of groups of magnets.
Examples
Input
6
10
10
10
01
10
10
Output
3
Input
4
01
01
10
10
Output
2
Note
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | instruction | 0 | 17,128 | 14 | 34,256 |
Tags: implementation
Correct Solution:
```
a=int(input())
f=0
p=''
for i in range(a):
n=input()
if i==0:
p=n
f+=1
elif n!=p:
f+=1
p=n
print(f)
``` | output | 1 | 17,128 | 14 | 34,257 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
<image>
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output
On the single line of the output print the number of groups of magnets.
Examples
Input
6
10
10
10
01
10
10
Output
3
Input
4
01
01
10
10
Output
2
Note
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | instruction | 0 | 17,129 | 14 | 34,258 |
Tags: implementation
Correct Solution:
```
n = int(input())
L = []
for i in range(n):
L.append(input())
k = 1
for i in range(1,n):
if L[i] != L[i-1]:
k += 1
else:
continue
print(k)
``` | output | 1 | 17,129 | 14 | 34,259 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
<image>
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output
On the single line of the output print the number of groups of magnets.
Examples
Input
6
10
10
10
01
10
10
Output
3
Input
4
01
01
10
10
Output
2
Note
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | instruction | 0 | 17,130 | 14 | 34,260 |
Tags: implementation
Correct Solution:
```
s = ""
p = 0
n = int(input())
for i in range(n):
s += input()
for i in range(len(s)-1):
if s[i]==s[i+1]:
p += 1
print(p+1)
``` | output | 1 | 17,130 | 14 | 34,261 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
<image>
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output
On the single line of the output print the number of groups of magnets.
Examples
Input
6
10
10
10
01
10
10
Output
3
Input
4
01
01
10
10
Output
2
Note
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | instruction | 0 | 17,131 | 14 | 34,262 |
Tags: implementation
Correct Solution:
```
qtd = int(input())
count = 1
text = ""
for _ in range(qtd):
digitado = input()
if text:
if text[len(text)-1] == digitado[0]:
count += 1
text += digitado
print(count)
``` | output | 1 | 17,131 | 14 | 34,263 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
<image>
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output
On the single line of the output print the number of groups of magnets.
Examples
Input
6
10
10
10
01
10
10
Output
3
Input
4
01
01
10
10
Output
2
Note
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | instruction | 0 | 17,132 | 14 | 34,264 |
Tags: implementation
Correct Solution:
```
n = int(input())
m = []
for i in range(n):
m.append(input())
m = ''.join(m)
count = 0
for i in range(0,len(m)-1):
if m[i]+m[i+1] == "11" or m[i]+m[i+1] == "00":
count+=1
print(count+1)
``` | output | 1 | 17,132 | 14 | 34,265 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.