message stringlengths 2 28.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 21 109k | cluster float64 7 7 | __index_level_0__ int64 42 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0 | instruction | 0 | 18,062 | 7 | 36,124 |
Tags: brute force, two pointers
Correct Solution:
```
n, k, x = map(int, input().split())
balls = list(map(int, input().split()))
count = 0
ans = 0
for i in range(0, n): # 1 1 2 2 1 1 => l = 2, r = 3, count = 3
if x == balls[i]:
count_out = 0
l = i
r = i
while balls[l] == balls[r]:
count = 2
while l > 0 and balls[l-1] == balls[l]:
count+=1
l-=1
while r < n - 1 and balls[r+1] == balls[r]:
count+=1
r+=1
l-=1
r+=1
if count < 3:
break
else:
count_out+=count
if l < 0 or r == n:
break
ans = max(count_out-1, ans)
print(ans)
``` | output | 1 | 18,062 | 7 | 36,125 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0 | instruction | 0 | 18,063 | 7 | 36,126 |
Tags: brute force, two pointers
Correct Solution:
```
n, k, x = input().split()
t = input().split() + ['a', 'b']
u, q = -2, 1
for v in range(int(n) + 1):
if x == t[v]:
if u == -2: u = v - 1
elif u != -2:
s, i, j, y = 0, u, v, t[v]
while j - i - s > 2:
s = j - i
while t[i] == y: i -= 1
while t[j] == y: j += 1
y = t[j]
u, q = -2, max(q, s)
print(q - 1)
``` | output | 1 | 18,063 | 7 | 36,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0 | instruction | 0 | 18,064 | 7 | 36,128 |
Tags: brute force, two pointers
Correct Solution:
```
n_balls, n_colors, new_ball = map(int, input().split())
balls = list(map(int, input().split()))
answer = 0
for i in range(n_balls):
copy = balls[:]
copy.insert(i, new_ball)
while (len(copy) > 2):
size = len(copy)
for j in range(2, len(copy)):
if ((copy[j - 2] == copy[j - 1]) and (copy[j - 1] == copy[j])):
cut = j + 1
while (cut < len(copy)):
if (copy[j] != copy[cut]):
break
cut += 1
copy = (copy[:j - 2] + copy[cut:])
break
if (len(copy) == size):
break
answer = max(answer, n_balls - len(copy))
print(answer)
``` | output | 1 | 18,064 | 7 | 36,129 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0 | instruction | 0 | 18,065 | 7 | 36,130 |
Tags: brute force, two pointers
Correct Solution:
```
import copy
def main():
n, x, k = list(map(int, input().strip().split(' ')))
balls = list(map(int, input().strip().split(' ')))
original_balls = copy.deepcopy(balls)
flag = 1
maxi = 0
# print(balls)
for i in range(len(balls)):
balls = copy.deepcopy(original_balls)
if i + 1 < len(balls):
if balls[i] == balls[i + 1] and balls[i] == k:
# print(balls)
new_balls = balls[:i + 1] + [k] + balls[i + 1:]
# print(new_balls)
flag = 1
while flag != 0:
# print(new_balls)
balls = new_balls
new_balls = []
length = len(balls)
flag = 0
for i in range(len(balls)):
if i + 2 < length and balls[i] == balls[i + 1] and balls[i + 1] == balls[i + 2]:
curr = i + 2
while curr + 1 < length and balls[i] == balls[curr + 1]:
curr += 1
new_balls = balls[:i] + balls[curr + 1:]
flag = 1
# print(len(new_balls))
break
# print(len(balls))
maxi = max(maxi, len(original_balls) - len(balls))
print(maxi)
if __name__ == '__main__':
main()
``` | output | 1 | 18,065 | 7 | 36,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0
Submitted Solution:
```
n, k, x = map(int, input(). split())
c = list(map(int, input(). split()))
d = []
s = 1
t = c[0]
for i in range(1, n):
if c[i] == t:
s += 1
else:
d.append([t, s])
t = c[i]
s = 1
d.append([t, s])
q = len(d)
check = 0
ans = 0
for i in range(q):
check = 0
if d[i][0] == x:
if d[i][1] + 1 == 3:
check += 2
l, r = i - 1, i + 1
while l > -1 and r < q:
if d[l][0] == d[r][0] and d[l][1] + d[r][1] >= 3:
check += d[l][1] + d[r][1]
l -= 1
r += 1
else:
break
ans = max(ans, check)
print(ans)
``` | instruction | 0 | 18,066 | 7 | 36,132 |
Yes | output | 1 | 18,066 | 7 | 36,133 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0
Submitted Solution:
```
n, k, x = list(map(int, input().split()))
l = list(map(int, input().split()))
intervals = []
sums = [0]
def countballs(array):
j = 0
count = 0
h = 0
if(array == []): return 0
while(h < len(array)):
if(array[h] == array[j]):
count += 1
h += 1
else:
if(count > 2):
return count + countballs(array[:j] + array[h:])
j = h
count = 0
if(count < 3): return 0
else:
return count + countballs(array[:j] + array[h-1:])
i = 0
while(i < n - 1):
if(l[i] == l[i + 1]):
if(l[i] == x):
intervals.append([i,i+1])
i += 2
else:
i += 1
for inte in intervals:
sums.append(countballs(l[:inte[0]] + [x] + l[inte[0]:]))
if(max(sums) > 0):
print(max(sums) - 1)
else: print(0)
``` | instruction | 0 | 18,067 | 7 | 36,134 |
Yes | output | 1 | 18,067 | 7 | 36,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0
Submitted Solution:
```
n, k, x = input().split(" ")
n = int(n)
balls = [int(x) for x in input().split(" ")]
ans = 0
for k in range(len(balls)):
i = k
j = i + 1
cnt = 1
cur = int(x)
while True:
pre_i = i
pre_j = j
while i >= 0 and balls[i] == cur:
i -=1
cnt += 1
while j < n and balls[j] == cur:
j += 1
cnt += 1
if cnt <= 2:
i = pre_i
j = pre_j
break
else:
cur = balls[i]
cnt = 0
ans = max(ans, j - i - 1)
print(ans)
``` | instruction | 0 | 18,068 | 7 | 36,136 |
Yes | output | 1 | 18,068 | 7 | 36,137 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0
Submitted Solution:
```
from sys import stdin
def arr_inp(n):
if n == 1:
return [int(x) for x in stdin.readline().split()]
elif n == 2:
return [float(x) for x in stdin.readline().split()]
else:
return [str(x) for x in stdin.readline().split()]
def solve(be, en):
num, a1, a2 = 0, [], []
for i in range(en, n):
if a1 == [] or a1[-1][0] != balls[i]:
a1.append([balls[i], 1])
else:
a1[-1][1] += 1
for i in range(be, -1, -1):
if a2 == [] or a2[-1][0] != balls[i]:
a2.append([balls[i], 1])
else:
a2[-1][1] += 1
for i in range(min(len(a1), len(a2))):
if a1[i][0] == a2[i][0] and a1[i][1] + a2[i][1] >= 3:
num += a1[i][1] + a2[i][1]
else:
break
return num
n, k, x = arr_inp(1)
balls, xs, ans = arr_inp(1), 0, 0
for i in range(n):
if balls[i] == x:
xs += 1
else:
if xs >= 2:
ans = max(xs + solve(i - xs - 1, i), ans)
xs = 0
print(ans)
``` | instruction | 0 | 18,069 | 7 | 36,138 |
Yes | output | 1 | 18,069 | 7 | 36,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0
Submitted Solution:
```
n, k, c = map(int, input().split())
x = list(map(int, input().split()))
a = []
cnt_pairs = 0
for i in range(1, n):
cnt = 0
if x[i] == x[i - 1] == c:
cnt_pairs += 1
if i > 1 and i != n - 1 and x[i + 1] == x[i - 2]:
for j in range(i + 1, n):
if x[j] == x[i + 1]:
cnt += 1
else:
break
for l in range(1, i):
if x[i - 2] == x[i - 1 - l]:
cnt += 1
else:
break
if cnt > 2:
a.append(cnt)
if len(a) == 0 and cnt_pairs == 0:
print(0)
exit()
elif len(a) == 0 and cnt_pairs > 0:
print(2)
exit()
if cnt_pairs > 0:
print(2 + max(a))
else:
print(0)
``` | instruction | 0 | 18,070 | 7 | 36,140 |
No | output | 1 | 18,070 | 7 | 36,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0
Submitted Solution:
```
# Ref: https://codeforces.com/problemset/problem/430/B
import sys
import time
# remove set of 3 or more continous same color ball
# Functions
def try_destroy_possible(local_list_input=[]):
# process contiguous
_list_input = local_list_input
count_delete = 0
i_start = 0
i_end = len(_list_input) - 1
while i_start < len(_list_input) - 1:
i_next = i_start + 1
count_contiguous = 1
# debug
if debug_opt:
print("while-1| i_start: {0} - i_next: {1} - i_end: {2}".format(i_start, i_next, len(_list_input) - 1))
while i_next <= len(_list_input) - 1:
# debug
if debug_opt:
print("while-2| i_start: {0} [{1}] - i_next: {2} [{3}] - i_end: {4}".format(i_start, _list_input[i_start], i_next, _list_input[i_next], len(_list_input) - 1)) # debug
if _list_input[i_start] == _list_input[i_next]:
# If i_start value == i_next value => contiguous value
count_contiguous += 1
if i_next == len(_list_input) - 1:
#print(count_contiguous)
if count_contiguous >= 3:
del _list_input[i_start:i_next+1]
count_delete += i_next - i_start + 1
break
else:
i_next +=1
else:
if count_contiguous >= 3:
del _list_input[i_start:i_next]
count_delete += i_next - i_start
break
i_start += 1
return int(count_delete)
# Global variables
debug_opt = False
# Get input from console
# Start
first_line_input = sys.stdin.readline().strip()
second_line_input = sys.stdin.readline().strip()
# Convert
first_line_input_map = list(map(int, first_line_input.split(" ")))
# Get info
var_n = first_line_input_map[0]
var_k = first_line_input_map[1]
var_x = first_line_input_map[2]
# Example list
#var_x = 1
#list_input = [1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1]
#list_input = [1, 1, 2, 2, 1, 1]
#list_input = [2, 1, 2, 2, 1, 2, 2, 1, 1, 2]
#list_input = [1]
# Size of array
list_input_original = list(map(int, second_line_input.split(" ")))
list_count_possible_destroy = []
size_list = len(list_input_original)
# Debug
if debug_opt:
print("")
print("List input: {0}".format(list_input_original))
print("Size of list: {0}".format(size_list))
print("Var X: {0}".format(var_x))
# count delete
# represent first pointer
i_start = 0
# Inject var_x into middle of posible two index has same value => 3 index has same value
# Debug
if debug_opt:
print("")
print("[+] Try to inject var_x")
while i_start < (size_list - 1):
# Initialize all evaluate variables
count_delete = 0
i_next = i_start + 1
list_input_process = list(list_input_original)
# Debug
if debug_opt:
print("")
print("while-0| i_start: {0} [{1}] - i_next: {2} [{3}] - i_end: {4}".format(i_start, list_input_process[i_start], i_next, list_input_process[i_next], len(list_input_process) - 1)) # debug
# If first and next pointer are same, we can inject ball var_x at the end
# then delete them
if int(list_input_process[i_start]) == int(var_x) and int(list_input_process[i_next]) == int(var_x):
del list_input_process[i_next]
del list_input_process[i_start]
count_delete += 2
count_delete_try = try_destroy_possible(local_list_input=list_input_process)
count_delete += count_delete_try
list_count_possible_destroy.append(int(count_delete))
i_start += 1
continue
else:
i_start += 1
#time.sleep(1)
# Process list: list_count_possible_destroy
final_list_count_possible_destroy = list(set(list_count_possible_destroy))
# Debug
if debug_opt:
print("")
print("List input 2nd times: {0}".format(list_input_original))
print("List count delete possible: {0}".format(final_list_count_possible_destroy))
print("Count delete: {0}".format(max(final_list_count_possible_destroy)))
print("")
if len(final_list_count_possible_destroy) == 0:
print("0")
else:
print(max(final_list_count_possible_destroy))
``` | instruction | 0 | 18,071 | 7 | 36,142 |
No | output | 1 | 18,071 | 7 | 36,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0
Submitted Solution:
```
n, k, x = map(int, input().split())
s = list(map(int, input().split()))
def fl(x, e, c):
s = x[:e]
s.append(c)
s += x[e:]
# print('before:', s)
o = 0
while len(s) > 2 and o <= 100:
last = 'x'
sstart = 0
sslen = 0
for i in range(len(s)):
if s[i] == last:
sslen += 1
else:
if sslen >= 2:
for i in range(sslen+1):
del s[sstart];
break
sstart = i
sslen = 0
last = s[i]
o += 1
# print('after: ', s, '\n')
if len(set(s))==1 and len(s) >= 3:
return 0
return len(s)
m = 0
for i in range(n):
m = max(m, n - fl(s,i,x))
print(m)
``` | instruction | 0 | 18,072 | 7 | 36,144 |
No | output | 1 | 18,072 | 7 | 36,145 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
Input
The first line of input contains three integers: n (1 β€ n β€ 100), k (1 β€ k β€ 100) and x (1 β€ x β€ k). The next line contains n space-separated integers c1, c2, ..., cn (1 β€ ci β€ k). Number ci means that the i-th ball in the row has color ci.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
Output
Print a single integer β the maximum number of balls Iahub can destroy.
Examples
Input
6 2 2
1 1 2 2 1 1
Output
6
Input
1 1 1
1
Output
0
Submitted Solution:
```
n, k, x = input().split()
t = input().split() + ['a', 'b']
u, q = -2, 1
for v in range(int(n) + 1):
if x == t[v]:
if u == -2: u = v - 1
elif u != -2:
s, i, j, y = 0, u, v, x
while j - i - s > 2:
s = j - i
while t[i] == y: i -= 1
while t[j] == y: j += 1
y = t[j]
u, q = -2, max(q, s)
print(q - 1)
``` | instruction | 0 | 18,073 | 7 | 36,146 |
No | output | 1 | 18,073 | 7 | 36,147 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image> | instruction | 0 | 18,968 | 7 | 37,936 |
Tags: dp, graphs
Correct Solution:
```
n, m = map(int, input().split())
a = []
for _ in range(n):
a.append([])
max_b = [0] * n
maximum = 0
for i in range(m):
x, y = map(int, input().split())
a[x - 1].append(y - 1)
a[y - 1].append(x - 1)
for i in range(n):
max_b[i] = 1
for v in a[i]:
if v < i:
max_b[i] = max(max_b[i], max_b[v] + 1)
maximum = max(maximum, max_b[i] * len(a[i]))
print(maximum)
``` | output | 1 | 18,968 | 7 | 37,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image> | instruction | 0 | 18,969 | 7 | 37,938 |
Tags: dp, graphs
Correct Solution:
```
n, m = map(int, input().split())
graph = [list() for _ in range(n+1)]
count = [0 for _ in range(n+1)]
dp = [0 for _ in range(n+1)]
for _ in range(m):
u, v = map(int, input().split())
if v < u:
u, v = v, u
graph[v].append(u)
count[v] += 1
count[u] += 1
for i in range(1, n+1):
best = 1
for j in graph[i]:
best = max(best, dp[j] + 1)
dp[i] = best
result = 1
for i in range(1, n+1):
if dp[i] * count[i] > result:
result = dp[i] * count[i]
print(result)
``` | output | 1 | 18,969 | 7 | 37,939 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image> | instruction | 0 | 18,970 | 7 | 37,940 |
Tags: dp, graphs
Correct Solution:
```
n, m = map(int, input().split())
graph = [[i] for i in range(n+2)]
dn = [0 for _ in range(n+2)]
res = 0
for _ in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
for node in range(1, n+1):
dn[node] = dn[max(graph[node] if graph[node] else [n+1], key=lambda adj: dn[adj]+1 if adj < node else 0)]+1
res = max(res, dn[node]*(len(graph[node])-1))
print(res)
``` | output | 1 | 18,970 | 7 | 37,941 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image> | instruction | 0 | 18,971 | 7 | 37,942 |
Tags: dp, graphs
Correct Solution:
```
n,m =map(int, input().split())
#b=[]
d=[0]*n
f=[[] for i in range(n)]
#for i in range(n):
# f+=[]
#print(f)
#print(d)
for i in range(m):
#s=input().split()
a=list(map(int, input().split()))
d[a[0]-1]+=1
d[a[1]-1]+=1
a.sort()
#a.reverse
f[a[1]-1]+=[a[0]-1]
#print(f[4])
k=[1]*n
res = 0
for i in range(n):
for j in f[i]:
k[i]=max(k[i], k[j]+1)
res = max(res, k[i]*d[i])
# print(f)
print(res)
#b.sort
#print(b)# your code goes here# your code goes here
``` | output | 1 | 18,971 | 7 | 37,943 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image> | instruction | 0 | 18,972 | 7 | 37,944 |
Tags: dp, graphs
Correct Solution:
```
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5+10)
def dfs(v):
if memo[v]!=-1:
return memo[v]
res = 1
for nv in G[v]:
res = max(res, dfs(nv)+1)
memo[v] = res
return res
n, m = map(int, input().split())
d = [0]*n
G = [[] for _ in range(n)]
for _ in range(m):
u, v = map(int, input().split())
d[u-1] += 1
d[v-1] += 1
G[max(u, v)-1].append(min(u, v)-1)
memo = [-1]*n
ans = 0
for i in range(n):
ans = max(ans, d[i]*dfs(i))
print(ans)
``` | output | 1 | 18,972 | 7 | 37,945 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image> | instruction | 0 | 18,973 | 7 | 37,946 |
Tags: dp, graphs
Correct Solution:
```
from collections import defaultdict
graph = defaultdict(list)
n, m = list(map(int, input().split()))
for i in range(m):
v, u = list(map(int, input().split()))
graph[v].append(u)
graph[u].append(v)
dp = [1] * (n + 1)
ans = len(graph[1])
for i in range(2, n + 1):
for v in graph[i]:
if v < i:
dp[i] = max(dp[i], dp[v] + 1)
ans = max(ans, dp[i] * len(graph[i]))
print(ans)
``` | output | 1 | 18,973 | 7 | 37,947 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image> | instruction | 0 | 18,974 | 7 | 37,948 |
Tags: dp, graphs
Correct Solution:
```
from sys import stdin, setrecursionlimit
setrecursionlimit(100000)
class Graph:
def __init__(self, No_of_nodes):
self.n = No_of_nodes
self.adj = [[] for i in range(self.n)]
def addEdge(self, a, b):
self.adj[a].append(b)
self.adj[b].append(a)
count[a][0] += 1
count[b][0] += 1
def solve(start):
for i in g.adj[start]:
if i < start:
dp[start] = max(dp[start], dp[i] + 1)
return dp[start]
n, m = map(int, stdin.readline().split())
g = Graph(n)
count = [[0, i] for i in range(n)]
dp = [1] * n
for i in range(m):
a, b = map(int, stdin.readline().split())
a -= 1
b -= 1
g.addEdge(a, b)
for i in range(n):
solve(i)
ans = -1000
for i in range(n):
if dp[i] != -1:
ans = max(ans, (dp[i]) * len(g.adj[i]))
print(ans)
``` | output | 1 | 18,974 | 7 | 37,949 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image> | instruction | 0 | 18,975 | 7 | 37,950 |
Tags: dp, graphs
Correct Solution:
```
max_n = 100005;
V = [[] for i in range(max_n)]
deg = [0] * max_n
dist = [0] * max_n
data = input().split(" ")
n = int(data[0])
m = int(data[1])
for i in range(m):
data = input().split(" ")
u = int(data[0])
v = int(data[1])
V[u].append(v)
V[v].append(u)
deg[u] += 1
deg[v] += 1
res = -1
for i in range(1,n+1):
for j in range(len(V[i])):
t = V[i][j]
if i > t:
dist[i] = max(dist[i], dist[t] + 1)
res = max(res, (dist[i] + 1) * deg[i])
print(res)
``` | output | 1 | 18,975 | 7 | 37,951 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image>
Submitted Solution:
```
n, m = map(int, input().split())
p = [0] * n
e = []
for i in range(m):
q, w = map(int, input().split())
p[w - 1] += 1
p[q - 1] += 1
e.append([min(q, w), max(q, w)])
dp = [1] * n
e.sort()
for i in range(m):
dp[e[i][1] - 1] = max(dp[e[i][1] - 1], dp[e[i][0] - 1] + 1)
ans = 0
for i in range(n):
ans = max(ans, dp[i] * p[i])
print(ans)
``` | instruction | 0 | 18,976 | 7 | 37,952 |
Yes | output | 1 | 18,976 | 7 | 37,953 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image>
Submitted Solution:
```
def main():
n, m = map(int, input().split())
n += 1
children = [[] for _ in range(n)]
degree, depth = [0] * n, [1] * n
for _ in range(m):
u, v = map(int, input().split())
if u < v:
children[u].append(v)
else:
children[v].append(u)
degree[u] += 1
degree[v] += 1
for a, c in zip(depth, children):
for v in c:
if depth[v] <= a:
depth[v] = a + 1
print(max(a * b for a, b in zip(depth, degree)))
if __name__ == '__main__':
main()
``` | instruction | 0 | 18,977 | 7 | 37,954 |
Yes | output | 1 | 18,977 | 7 | 37,955 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image>
Submitted Solution:
```
n, m = map(int, input().split())
children = [ [] for u in range(n + 1) ]
degree = [ 0 for u in range(n + 1) ]
for i in range(m):
u, v = map(int, input().split())
if u > v:
u, v = v, u
children[u].append(v)
degree[u] += 1
degree[v] += 1
depth = [ 0 for u in range(n + 1) ]
best = degree[1]
for u in range(1, n + 1):
for v in children[u]:
depth[v] = max(depth[v], depth[u] + 1)
best = max(best, (depth[v] + 1) * degree[v])
print(best)
``` | instruction | 0 | 18,978 | 7 | 37,956 |
Yes | output | 1 | 18,978 | 7 | 37,957 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image>
Submitted Solution:
```
from sys import stdin
a=lambda:stdin.readline().split()
n,m=map(int,a())
d={i:[] for i in range(1,n+1)}
di={i:0 for i in range(1,n+1)}
for _ in range(m):
u,v=map(int,a())
if u>v:d[u].append(v)
else:d[v].append(u)
di[u]+=1
di[v]+=1
res=[1]
result=di[1]
for i in range(2,n+1):
item=0
for j,y in enumerate(d[i]):
item=max(item,res[y-1])
item+=1
res.append(item)
result=max(result,item*di[i])
print(result)
``` | instruction | 0 | 18,979 | 7 | 37,958 |
Yes | output | 1 | 18,979 | 7 | 37,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image>
Submitted Solution:
```
import sys
def dfs(v):
global g, used, val
used[v] = True
maxv = 1
for u in g[v]:
if used[u]:
maxv = max(maxv, dfs(u) + 1)
val[v] = len(g[v]) * maxv
return maxv
# fin = open("cfr338b.in", "r")
fin = sys.stdin
n, m = map(int, fin.readline().split())
g = [[] for i in range(n)]
for i in range(m):
u, v = map(int, fin.readline().split())
u, v = (u - 1, v - 1) if u <= v else (v - 1, u - 1)
# g[u].append(v)
g[v].append(u)
used = [False] * n
val = [0] * n
maxv = 0
for i in range(n):
if not used[i]:
dfs(i)
maxv = max(maxv, val[i])
print(maxv)
``` | instruction | 0 | 18,980 | 7 | 37,960 |
No | output | 1 | 18,980 | 7 | 37,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image>
Submitted Solution:
```
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright Β© 2015 missingdays <missingdays@missingdays>
#
# Distributed under terms of the MIT license.
"""
"""
n, m = [int(i) for i in input().split()]
graph = {}
for i in range(1, n+1):
graph[i] = []
for i in range(m):
u, v = [int(i) for i in input().split()]
graph[u].append(v)
graph[v].append(u)
def calc(v, i):
global graph
m = len(graph[v]) * i
for vertex in graph[v]:
if vertex > v:
m = max(m, calc(vertex, i+1))
return m
print(calc(1, 1))
``` | instruction | 0 | 18,981 | 7 | 37,962 |
No | output | 1 | 18,981 | 7 | 37,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image>
Submitted Solution:
```
n,m = [int(i) for i in input().split()]
seg = {i:[] for i in range(1,n+1)}
for j in range(m):
a,b = [int(i) for i in input().split()]
seg[a].append(b)
seg[b].append(a)
tail = [0]*(n+1)
tail[1] = 1
for i in range(2,n+1):
temp = [tail[j] for j in seg[i]]+[1]
tail[i] = max(temp)+1
temp = [len(seg[i])*tail[i] for i in range(2,n+1)]
print(max(temp))
``` | instruction | 0 | 18,982 | 7 | 37,964 |
No | output | 1 | 18,982 | 7 | 37,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
1. Only segments already presented on the picture can be painted;
2. The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
3. The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
Input
First line of the input contains two integers n and m(2 β€ n β€ 100 000, 1 β€ m β€ 200 000) β the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 β€ ui, vi β€ n, ui β vi) β the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Output
Print the maximum possible value of the hedgehog's beauty.
Examples
Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Output
9
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output
12
Note
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3Β·3 = 9.
<image>
Submitted Solution:
```
def main(input_string):
max_n = 100005;
V = [[] for i in range(max_n)]
deg = [0] * max_n
dist = [0] * max_n
data = input_string.strip().split("\n")
n = int(data[0][0])
m = int(data[0][2])
for i in range(m):
u = int(data[i][0])
v = int(data[i][2])
V[u].append(v)
V[v].append(u)
deg[u] += 1
deg[v] += 1
res = 0
for i in range(n):
for j in range(len(V[i])):
t = V[i][j]
if i > t:
dist[i] = max(dist[i], dist[t] + 1)
res = max(res, (dist[i] + 1) * deg[i])
return res
``` | instruction | 0 | 18,983 | 7 | 37,966 |
No | output | 1 | 18,983 | 7 | 37,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | instruction | 0 | 19,011 | 7 | 38,022 |
Tags: constructive algorithms, number theory
Correct Solution:
```
n = int(input())
res = []
for i in range(n) :
u = i + 2
if u == 2 :
res.append(1)
else:
e = int(u**(0.5))
lock = 0
for j in range(2,e+1) :
if u%j == 0 :
lock = 1
break
if lock == 1 :
res.append(2)
else :
res.append(1)
print(len(set(res)))
print(*res)
``` | output | 1 | 19,011 | 7 | 38,023 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | instruction | 0 | 19,012 | 7 | 38,024 |
Tags: constructive algorithms, number theory
Correct Solution:
```
from math import sqrt
n=int(input())
l=[1]*(n+2)
for i in range(2,int(sqrt(n+2)+1)):
if l[i]==1:
for j in range(i*i,n+2,i):
l[j]=2
if n>=3:
print(2)
print(*l[2:n+2])
else:
print(1)
print(*[1]*n)
``` | output | 1 | 19,012 | 7 | 38,025 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | instruction | 0 | 19,013 | 7 | 38,026 |
Tags: constructive algorithms, number theory
Correct Solution:
```
import math
n = int(input())
is_Prime = [True for i in range(n+2)]
limit = int(math.sqrt(len(is_Prime)))
def displaySieve():
for i in range(len(is_Prime)):
print(i, is_Prime[i])
for i in range(2, limit+1, 1):
if is_Prime[i]:
for j in range(i+i, len(is_Prime), i):
is_Prime[j] = False
output = []
if False in is_Prime:
print(2)
for i in range(2, len(is_Prime), 1):
if is_Prime[i]:
output.append("1")
else:
output.append("2")
else:
print("1")
for i in range(2, len(is_Prime), 1):
output.append("1")
print(" ".join(output))
``` | output | 1 | 19,013 | 7 | 38,027 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | instruction | 0 | 19,014 | 7 | 38,028 |
Tags: constructive algorithms, number theory
Correct Solution:
```
import math as ma
n = int(input())
#primes = array.array('b', )
maxN = 100001
primes = [0]*(n+2)
color = [0]*(n+2)
c = 1
for p in range(2, n+2):
if (primes[p] == 0):
for l in range(p, n+2-p, p):
primes[p+l]=1
ncolors = 1
for p in range(2, n+2):
if (primes[p] == 0):
color[p] = 1
else:
color[p] = 2
ncolors = 2
print(ncolors)
for p in range(2, n+2):
print(color[p], end =" ")
``` | output | 1 | 19,014 | 7 | 38,029 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | instruction | 0 | 19,015 | 7 | 38,030 |
Tags: constructive algorithms, number theory
Correct Solution:
```
n=int(input())
seive=[1]*(n+2)
seive[0]=-1
seive[1]=-1
for i in range(n+2):
if seive[i]==1:
for j in range(i*2,n+2,i):
seive[j]=2
if(n==1 or n==2):
print(1)
for i in range(2,n+2):
print(seive[i],end=' ')
elif(n==0):
print(0)
else:
print(2)
for i in range(2,n+2):
print(seive[i],end=' ')
``` | output | 1 | 19,015 | 7 | 38,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | instruction | 0 | 19,016 | 7 | 38,032 |
Tags: constructive algorithms, number theory
Correct Solution:
```
import math
def prime(n):
j = 0
if n ==2 or n==3:
return 1
for i in range(2, int(math.sqrt(n))+1):
if n%i == 0:
j = 1
break
if j == 1:
return 0
else:
return 1
n = int(input())
if n==1 or n==2:
print(1)
else:
print(2)
for i in range(2, n+2):
if prime(i):
print(1, end=" ")
else:
print(2, end=" ")
``` | output | 1 | 19,016 | 7 | 38,033 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | instruction | 0 | 19,017 | 7 | 38,034 |
Tags: constructive algorithms, number theory
Correct Solution:
```
n = int(input())
t = [1] * (n+2)
for i in range(2, n+2):
for j in range(i * i, n+2, i):t[j] = 2
if n>2:
print(2)
else:
print(1)
print(*t[2:])
``` | output | 1 | 19,017 | 7 | 38,035 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | instruction | 0 | 19,018 | 7 | 38,036 |
Tags: constructive algorithms, number theory
Correct Solution:
```
n = int(input())
arr = [1] * n
for i in range(2, n + 2):
if arr[i - 2]:
for j in range(i * i, n + 2, i):
arr[j - 2] = 0
print(len(set(arr)))
print(' '.join(('1' if arr[i - 2] == 1 else '2') for i in range(2, n + 2)))
``` | output | 1 | 19,018 | 7 | 38,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
Submitted Solution:
```
import math
n = int(input())
if n == 1:
print(1)
print(1)
exit(0)
prime = [2]
ans = [1]
for i in range(3, n+2):
curr = 0
sq = math.floor(math.sqrt(i))
isPrime = True
while curr < len(prime) and prime[curr] <= sq:
if i % prime[curr] == 0:
isPrime = False
break
curr += 1
if isPrime:
prime.append(i)
ans.append(1)
else:
ans.append(2)
print(2 if n > 2 else 1)
print(' '.join(map(str, ans)))
``` | instruction | 0 | 19,019 | 7 | 38,038 |
Yes | output | 1 | 19,019 | 7 | 38,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
Submitted Solution:
```
n=int(input())
a=[0]*(n+2)
for i in range(2,n+2):
for j in range(i,n+2,i):
a[j]+=1
if n>2:print(2)
else:print(1)
for i in range(2,n+2):
if a[i]==1:
print(1,end=' ')
else:
print(2,end=' ')
``` | instruction | 0 | 19,020 | 7 | 38,040 |
Yes | output | 1 | 19,020 | 7 | 38,041 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
Submitted Solution:
```
def prime_factors():
n=100001
seive=[i for i in range(n+1)]
## print(seive)
i=2
while i*i<=n:
for j in range(i*i,n+1,i):
if seive[j]%i==0:
seive[j]=2
i+=1
for k in range(2,n+1):
if seive[k]==k:
seive[k]=1
seive[0]=1
seive[1]=1
return seive
seive=prime_factors()
n=int(input())
if n<3:
print(1)
else:
print(2)
i=1
c=0
for j in range(i+1,n+2):
if seive[j]==1:
print(1,end=" ")
else:
print(2,end=" ")
``` | instruction | 0 | 19,021 | 7 | 38,042 |
Yes | output | 1 | 19,021 | 7 | 38,043 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
Submitted Solution:
```
N = int(input()) + 2
is_prime = N * [1]
color = N * [2]
for i in range(N):
if i < 2: continue
if is_prime[i]:
j = 2 * i
while(j < N):
is_prime[j] = 0
j += i
color[i] = 1
print(max(color[2:N]), ' '.join(map(str, color[2:N])), sep = '\n')
``` | instruction | 0 | 19,022 | 7 | 38,044 |
Yes | output | 1 | 19,022 | 7 | 38,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
Submitted Solution:
```
n=int(input())
a=[]
for i in range(n+2):
a.append(1)
for i in range(2,n+2):
j=i*2
while(j<=n+1):
a[j]+=1
j+=i
d={}
for i in range(2,n+2):
ele=a[i]
if ele not in d:
d[ele]=1
else:
d[ele]+=1
count=0
for ele in d:
count+=1
print(count)
for i in range(2,n+2):
print(a[i],sep='',end=' ')
``` | instruction | 0 | 19,023 | 7 | 38,046 |
No | output | 1 | 19,023 | 7 | 38,047 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
Submitted Solution:
```
n = int(input())
a = [0]*(n+2)
for i in range(2, n+2):
if not a[i]:
for j in range(2*i, n+2, i):
a[j] = 1
for i in range(2, n+2):
if not a[i]:
print("1", end = " ")
else:
print("2", end = " ")
``` | instruction | 0 | 19,024 | 7 | 38,048 |
No | output | 1 | 19,024 | 7 | 38,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
Submitted Solution:
```
from math import *
from sys import *
input=stdin.readline
n=int(input())
l=[]
m=2
for i in range(2,n+2):
for j in range(2,int(sqrt(i))+1):
if(i%j==0):
l.append(m)
m=m+1
break
else:
l.append(1)
print(len(set(l)))
print(*l)
``` | instruction | 0 | 19,025 | 7 | 38,050 |
No | output | 1 | 19,025 | 7 | 38,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input
The only line contains single integer n (1 β€ n β€ 100000) β the number of jewelry pieces.
Output
The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using k colors, you can output any of them.
Examples
Input
3
Output
2
1 1 2
Input
4
Output
2
2 1 1 2
Note
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
Submitted Solution:
```
from math import *
from sys import *
input=stdin.readline
n=int(input())
l=[]
f=0
m=2
for i in range(2,n+2):
for j in range(2,int(sqrt(i))+1):
if(i%j==0):
f=1
break
if(f==1):
l.append(m)
else:
l.append(1)
print(len(set(l)))
print(*l)
``` | instruction | 0 | 19,026 | 7 | 38,052 |
No | output | 1 | 19,026 | 7 | 38,053 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`.
Consider doing the following operation:
* Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.
You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
Constraints
* 1 \leq H, W \leq 6
* 1 \leq K \leq HW
* c_{i,j} is `.` or `#`.
Input
Input is given from Standard Input in the following format:
H W K
c_{1,1}c_{1,2}...c_{1,W}
c_{2,1}c_{2,2}...c_{2,W}
:
c_{H,1}c_{H,2}...c_{H,W}
Output
Print an integer representing the number of choices of rows and columns satisfying the condition.
Examples
Input
2 3 2
..#
###
Output
5
Input
2 3 2
..#
Output
5
Input
2 3 4
..#
Output
1
Input
2 2 3
Output
0
Input
6 6 8
..##..
.#..#.
....#
....#
....#
Output
208 | instruction | 0 | 19,122 | 7 | 38,244 |
"Correct Solution:
```
h,w,k=map(int,input().split())
c=[list(input()) for _ in range(h)]
ans=0
for i in range(2**h):
for j in range(2**w):
cnt=0
for x in range(h):
for y in range(w):
if i>>x&1:continue
if j>>y&1:continue
if c[x][y]=="#":cnt+=1
if cnt==k:
ans+=1
print(ans)
``` | output | 1 | 19,122 | 7 | 38,245 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`.
Consider doing the following operation:
* Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.
You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
Constraints
* 1 \leq H, W \leq 6
* 1 \leq K \leq HW
* c_{i,j} is `.` or `#`.
Input
Input is given from Standard Input in the following format:
H W K
c_{1,1}c_{1,2}...c_{1,W}
c_{2,1}c_{2,2}...c_{2,W}
:
c_{H,1}c_{H,2}...c_{H,W}
Output
Print an integer representing the number of choices of rows and columns satisfying the condition.
Examples
Input
2 3 2
..#
###
Output
5
Input
2 3 2
..#
Output
5
Input
2 3 4
..#
Output
1
Input
2 2 3
Output
0
Input
6 6 8
..##..
.#..#.
....#
....#
....#
Output
208 | instruction | 0 | 19,123 | 7 | 38,246 |
"Correct Solution:
```
h,w,x=map(int,input().split())
a=[list(input()) for i in range(h)]
ans=0
for i in range(2**(h+w)):
b=0
for j in range(h):
for k in range(w):
if (i>>j)&1==1 and (i>>k+h)&1==1 and a[j][k]=="#":
b+=1
if b==x:
ans+=1
print(ans)
``` | output | 1 | 19,123 | 7 | 38,247 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`.
Consider doing the following operation:
* Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.
You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
Constraints
* 1 \leq H, W \leq 6
* 1 \leq K \leq HW
* c_{i,j} is `.` or `#`.
Input
Input is given from Standard Input in the following format:
H W K
c_{1,1}c_{1,2}...c_{1,W}
c_{2,1}c_{2,2}...c_{2,W}
:
c_{H,1}c_{H,2}...c_{H,W}
Output
Print an integer representing the number of choices of rows and columns satisfying the condition.
Examples
Input
2 3 2
..#
###
Output
5
Input
2 3 2
..#
Output
5
Input
2 3 4
..#
Output
1
Input
2 2 3
Output
0
Input
6 6 8
..##..
.#..#.
....#
....#
....#
Output
208 | instruction | 0 | 19,124 | 7 | 38,248 |
"Correct Solution:
```
H, W, K = map(int, input().split())
C = [[i for i in input()] for j in range(H)]
ans = 0
for h_bit in range(1 << H):
for w_bit in range(1 << W):
black = 0
for i in range(H):
for j in range(W):
if h_bit & (1 << i) and w_bit & (1 << j):
if C[i][j] == '#':
black += 1
if black == K:
ans += 1
print(ans)
``` | output | 1 | 19,124 | 7 | 38,249 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`.
Consider doing the following operation:
* Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.
You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
Constraints
* 1 \leq H, W \leq 6
* 1 \leq K \leq HW
* c_{i,j} is `.` or `#`.
Input
Input is given from Standard Input in the following format:
H W K
c_{1,1}c_{1,2}...c_{1,W}
c_{2,1}c_{2,2}...c_{2,W}
:
c_{H,1}c_{H,2}...c_{H,W}
Output
Print an integer representing the number of choices of rows and columns satisfying the condition.
Examples
Input
2 3 2
..#
###
Output
5
Input
2 3 2
..#
Output
5
Input
2 3 4
..#
Output
1
Input
2 2 3
Output
0
Input
6 6 8
..##..
.#..#.
....#
....#
....#
Output
208 | instruction | 0 | 19,125 | 7 | 38,250 |
"Correct Solution:
```
import sys
h, w, k = map(int, input().split())
s = sys.stdin.readlines()
ans = 0
for ib in range(1<<h):
for jb in range(1<<w):
cnt = 0
for i in range(h):
if ib >> i & 1:
continue
for j in range(w):
if jb >> j & 1:
continue
if s[i][j] == "#":
cnt += 1
if cnt == k:
ans += 1
print (ans)
``` | output | 1 | 19,125 | 7 | 38,251 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`.
Consider doing the following operation:
* Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.
You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
Constraints
* 1 \leq H, W \leq 6
* 1 \leq K \leq HW
* c_{i,j} is `.` or `#`.
Input
Input is given from Standard Input in the following format:
H W K
c_{1,1}c_{1,2}...c_{1,W}
c_{2,1}c_{2,2}...c_{2,W}
:
c_{H,1}c_{H,2}...c_{H,W}
Output
Print an integer representing the number of choices of rows and columns satisfying the condition.
Examples
Input
2 3 2
..#
###
Output
5
Input
2 3 2
..#
Output
5
Input
2 3 4
..#
Output
1
Input
2 2 3
Output
0
Input
6 6 8
..##..
.#..#.
....#
....#
....#
Output
208 | instruction | 0 | 19,126 | 7 | 38,252 |
"Correct Solution:
```
n,m,k = map(int,input().split())
arr = []
for _ in range(n):
arr.append(list(input()))
ans = 0
for i in range(1<<n):
for j in range(1<<m):
black = 0
for q in range(n):
for r in range(m):
if i & (1<<q) and j & (1<<r) and arr[q][r] == "#":
black += 1
if black == k: ans += 1
print(ans)
``` | output | 1 | 19,126 | 7 | 38,253 |
Provide a correct Python 3 solution for this coding contest problem.
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`.
Consider doing the following operation:
* Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.
You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
Constraints
* 1 \leq H, W \leq 6
* 1 \leq K \leq HW
* c_{i,j} is `.` or `#`.
Input
Input is given from Standard Input in the following format:
H W K
c_{1,1}c_{1,2}...c_{1,W}
c_{2,1}c_{2,2}...c_{2,W}
:
c_{H,1}c_{H,2}...c_{H,W}
Output
Print an integer representing the number of choices of rows and columns satisfying the condition.
Examples
Input
2 3 2
..#
###
Output
5
Input
2 3 2
..#
Output
5
Input
2 3 4
..#
Output
1
Input
2 2 3
Output
0
Input
6 6 8
..##..
.#..#.
....#
....#
....#
Output
208 | instruction | 0 | 19,127 | 7 | 38,254 |
"Correct Solution:
```
H,W,K = map(int,input().split())
s = [list(input()) for i in range(H)]
ans = 0
for i in range(1<<H):
for j in range(1<<W):
cnt = 0
for h in range(H):
for w in range(W):
if (i>>h)&1 == 1 and (j>>w)&1==1:
if s[h][w]=='#':
cnt += 1
if cnt==K:
ans += 1
print(ans)
``` | output | 1 | 19,127 | 7 | 38,255 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.