message stringlengths 2 16.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 575 109k | cluster float64 16 16 | __index_level_0__ int64 1.15k 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:
* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.
Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
Constraints
* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
s
Output
If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.
Examples
Input
xabxa
Output
2
Input
ab
Output
-1
Input
a
Output
0
Input
oxxx
Output
3 | instruction | 0 | 16,663 | 16 | 33,326 |
"Correct Solution:
```
s=input()
cnt=0
while len(s)>1:
if s[0]==s[-1]:
s= s[1:-1]
elif s[0]=="x" and s[-1]!="x":
s = s[1:]
cnt +=1
elif s[-1]=="x" and s[0]!="x":
s = s[:-1]
cnt +=1
else:
cnt=-1
break
print(cnt)
``` | output | 1 | 16,663 | 16 | 33,327 |
Provide a correct Python 3 solution for this coding contest problem.
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:
* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.
Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
Constraints
* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
s
Output
If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.
Examples
Input
xabxa
Output
2
Input
ab
Output
-1
Input
a
Output
0
Input
oxxx
Output
3 | instruction | 0 | 16,665 | 16 | 33,330 |
"Correct Solution:
```
s=input()
left=0
right=len(s)-1
cnt=0
while right-left>0:
if (s[right]==s[left]):
right-=1
left+=1
elif (s[right]!='x')and(s[left]!='x'):
print(-1)
exit()
elif (s[right]!='x')and(s[left]=='x'):
left+=1
cnt+=1
else:
right-=1
cnt+=1
print(cnt)
``` | output | 1 | 16,665 | 16 | 33,331 |
Provide a correct Python 3 solution for this coding contest problem.
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:
* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.
Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
Constraints
* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
s
Output
If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.
Examples
Input
xabxa
Output
2
Input
ab
Output
-1
Input
a
Output
0
Input
oxxx
Output
3 | instruction | 0 | 16,666 | 16 | 33,332 |
"Correct Solution:
```
from collections import deque
s = deque(input())
ans = 0
while len(s) >= 2:
if s[0] == s[-1]:
s.popleft()
s.pop()
elif s[0] == "x":
s.append("x")
ans += 1
elif s[-1] == "x":
s.appendleft("x")
ans += 1
else:
ans = -1
break
print(ans)
``` | output | 1 | 16,666 | 16 | 33,333 |
Provide a correct Python 3 solution for this coding contest problem.
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:
* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.
Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
Constraints
* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
s
Output
If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.
Examples
Input
xabxa
Output
2
Input
ab
Output
-1
Input
a
Output
0
Input
oxxx
Output
3 | instruction | 0 | 16,667 | 16 | 33,334 |
"Correct Solution:
```
S = input()
N = len(S)
l = 0
r = N-1
ans = 0
while l < r:
if S[l] == S[r]:
l += 1
r -= 1
elif S[l] == 'x':
l += 1
ans += 1
elif S[r] == 'x':
r -= 1
ans += 1
else:
print(-1)
exit()
print(ans)
``` | output | 1 | 16,667 | 16 | 33,335 |
Provide a correct Python 3 solution for this coding contest problem.
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:
* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.
Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
Constraints
* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
s
Output
If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.
Examples
Input
xabxa
Output
2
Input
ab
Output
-1
Input
a
Output
0
Input
oxxx
Output
3 | instruction | 0 | 16,668 | 16 | 33,336 |
"Correct Solution:
```
s = input()
l, r = 0, len(s) - 1
ans = 0
while l < r:
# print(l, r)
if s[l] == s[r]:
l += 1
r -= 1
else:
if s[l] == "x":
l += 1
elif s[r] == "x":
r -= 1
else:
print(-1)
exit()
ans += 1
print(ans)
``` | output | 1 | 16,668 | 16 | 33,337 |
Provide a correct Python 3 solution for this coding contest problem.
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:
* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.
Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
Constraints
* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
s
Output
If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.
Examples
Input
xabxa
Output
2
Input
ab
Output
-1
Input
a
Output
0
Input
oxxx
Output
3 | instruction | 0 | 16,670 | 16 | 33,340 |
"Correct Solution:
```
s = input()
ans = 0
l = 0
r = len(s)-1
while l<r:
if s[l]==s[r]:
l += 1
r -= 1
elif s[l]=='x':
ans += 1
l += 1
elif s[r]=='x':
ans += 1
r -= 1
else:
print(-1)
exit()
print(ans)
``` | output | 1 | 16,670 | 16 | 33,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:
* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.
Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
Constraints
* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
s
Output
If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.
Examples
Input
xabxa
Output
2
Input
ab
Output
-1
Input
a
Output
0
Input
oxxx
Output
3
Submitted Solution:
```
from collections import deque
S = deque(list(input()))
ans = 0
while len(S) > 1:
l = S.popleft()
r = S.pop()
if l == r:
continue
elif l == 'x':
ans += 1
S.append(r)
elif r == 'x':
ans += 1
S.appendleft(l)
else:
print(-1)
exit()
print(ans)
``` | instruction | 0 | 16,672 | 16 | 33,344 |
Yes | output | 1 | 16,672 | 16 | 33,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:
* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.
Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
Constraints
* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
s
Output
If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.
Examples
Input
xabxa
Output
2
Input
ab
Output
-1
Input
a
Output
0
Input
oxxx
Output
3
Submitted Solution:
```
S = input()
l = 0
r = len(S)-1
cnt = 0
while l < r:
if S[l] == S[r]:
l += 1
r -= 1
elif S[l] == 'x':
l += 1
cnt += 1
elif S[r] == 'x':
r -= 1
cnt += 1
else:
cnt = -1
break
print(cnt)
``` | instruction | 0 | 16,674 | 16 | 33,348 |
Yes | output | 1 | 16,674 | 16 | 33,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:
* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.
Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
Constraints
* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
s
Output
If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.
Examples
Input
xabxa
Output
2
Input
ab
Output
-1
Input
a
Output
0
Input
oxxx
Output
3
Submitted Solution:
```
import copy
s = list(input())
check = [s[i] for i in range(len(s))]
for i in range(s.count("x")):
check.remove("x")
if check!=check[::-1]:
print(-1)
exit()
ans = 0
first = 0
latter = 0
i = 0
while i<(len(s)+first+latter)//2:
if s[i-first]!=s[-1+(-1)*i+latter]:
ans += 1
if s[i-first]=="x":
latter += 1
else:
first += 1
i += 1
print(ans)
``` | instruction | 0 | 16,676 | 16 | 33,352 |
No | output | 1 | 16,676 | 16 | 33,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly:
* Insert a letter `x` to any position in s of his choice, including the beginning and end of s.
Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
Constraints
* 1 \leq |s| \leq 10^5
* s consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
s
Output
If the objective is achievable, print the number of operations required. If it is not, print `-1` instead.
Examples
Input
xabxa
Output
2
Input
ab
Output
-1
Input
a
Output
0
Input
oxxx
Output
3
Submitted Solution:
```
s = input()
count = 0
left, right = 0, len(s)-1
for i in range(100):
if s[left] == s[right]:
left, right = left+1, right-1
elif s[left] == 'x':
left = left+1
count += 1
elif s[right] == 'x':
right = right-1
count += 1
else :
count = -1
break
if left >= right:
break
``` | instruction | 0 | 16,678 | 16 | 33,356 |
No | output | 1 | 16,678 | 16 | 33,357 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9 | instruction | 0 | 17,588 | 16 | 35,176 |
"Correct Solution:
```
n=int(input())
tmp, ans=0,0
for i in range(n):
a=int(input())
if a==0:
ans+=tmp//2
tmp=0
else:
tmp+=a
print(ans+tmp//2)
``` | output | 1 | 17,588 | 16 | 35,177 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9 | instruction | 0 | 17,589 | 16 | 35,178 |
"Correct Solution:
```
N=int(input())
A=[int(input()) for _ in range(N)]
ans=0
idx=[]
for i in range(N):
if A[i]==0:
idx.append(i+1)
n=0
idx.append(N)
for iidx in idx:
ans+=sum(A[n:iidx])//2
n=iidx
print(ans)
``` | output | 1 | 17,589 | 16 | 35,179 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9 | instruction | 0 | 17,590 | 16 | 35,180 |
"Correct Solution:
```
from itertools import*
_, *a = map(int, open(0))
print(sum(sum(l)//2 for _, l in groupby(a, key=lambda x:x>0)))
``` | output | 1 | 17,590 | 16 | 35,181 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9 | instruction | 0 | 17,591 | 16 | 35,182 |
"Correct Solution:
```
n = int(input())
ans = 0
chk = 0
for i in range(n):
a = int(input())
p = chk+a
ans += p//2
if a > 0:
chk = p%2
else:
chk = 0
print(ans)
``` | output | 1 | 17,591 | 16 | 35,183 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9 | instruction | 0 | 17,592 | 16 | 35,184 |
"Correct Solution:
```
N=int(input())
ans=0
co=0
for i in range(N):
a=int(input())
ans+=(a+co)//2
if a==0:
co=0
else:
co=(a+co)%2
print(ans)
``` | output | 1 | 17,592 | 16 | 35,185 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9 | instruction | 0 | 17,593 | 16 | 35,186 |
"Correct Solution:
```
N=int(input())
l=[int(input()) for _ in range(N)]
sum1,j=0,0
for i in range(N):
if l[i]==0 or i==N-1:
sum1+=int(sum(l[j:i+1])/2)
j=i
print(sum1)
``` | output | 1 | 17,593 | 16 | 35,187 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9 | instruction | 0 | 17,594 | 16 | 35,188 |
"Correct Solution:
```
n=int(input())
count=0
ans=0
for i in range(n):
a=int(input())
if a==0:
ans+=(count//2)
count=0
else:
count+=a
print(ans+count//2)
``` | output | 1 | 17,594 | 16 | 35,189 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9 | instruction | 0 | 17,595 | 16 | 35,190 |
"Correct Solution:
```
n = int(input())
a = [int(input()) for i in range(n)]
ans = 0
flag = 0
for i in range(n):
if flag and a[i] >= 1:
ans += 1
a[i] -= 1
flag = a[i] % 2
ans += a[i] // 2
print(ans)
``` | output | 1 | 17,595 | 16 | 35,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9
Submitted Solution:
```
n=int(input())
ans=0
tmp=0
for i in range(n):
t=int(input())
ans+=(tmp+t)//2
tmp=(tmp+t)%2
if t==0:
tmp=0
print(ans)
``` | instruction | 0 | 17,596 | 16 | 35,192 |
Yes | output | 1 | 17,596 | 16 | 35,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9
Submitted Solution:
```
N=int(input())
ans=0
t=0
for _ in range(N):
A=int(input())
if A==0:
ans+=t//2
t=0
else:
t+=A
ans+=t//2
print(ans)
``` | instruction | 0 | 17,597 | 16 | 35,194 |
Yes | output | 1 | 17,597 | 16 | 35,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9
Submitted Solution:
```
N = int(input())
A = [int(input()) for i in range(N)]
ans = rem = 0
for a in A:
if a == 0:
rem = 0
continue
a += rem
ans += a//2
rem = a%2
print(ans)
``` | instruction | 0 | 17,598 | 16 | 35,196 |
Yes | output | 1 | 17,598 | 16 | 35,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9
Submitted Solution:
```
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
carry = 0
for a in A:
if a == 0:
carry = 0
continue
ans += (a + carry) // 2
carry = (a + carry) % 2
print(ans)
``` | instruction | 0 | 17,599 | 16 | 35,198 |
Yes | output | 1 | 17,599 | 16 | 35,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9
Submitted Solution:
```
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
flag = True
for i in range(N):
if flag and A[i] % 2 == 0:
ans += A[i] // 2
elif flag and A[i] % 2 == 1:
ans += A[i] // 2
flag = False
elif A[i] % 2 == 0:
ans += A[i] // 2
flag = True
else:
ans += (A[i]+1)//2
flag = True
Ans = ans
ans = 0
A.reverse()
flag = True
for i in range(N):
if flag and A[i] % 2 == 0:
ans += A[i] // 2
flag = True
elif flag and A[i] % 2 == 1:
ans += A[i] // 2
flag = False
elif A[i] % 2 == 0:
ans += A[i] // 2
flag = True
else:
ans += (A[i]+1)//2
flag = True
print(max(ans,Ans))
``` | instruction | 0 | 17,600 | 16 | 35,200 |
No | output | 1 | 17,600 | 16 | 35,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9
Submitted Solution:
```
n = int(input())
ai = [int(input()) for i in range(n)]
ans = 0
nokori = 0
ans = ai[0] // 2
ai[0] %= 2
for i in range(1,n):
ans += ai[i] // 2
if ai[i] % 2 == 1:
if ai[i-1] == 1:
ans += 1
else:
ai[i] = 1
print(ans)
``` | instruction | 0 | 17,601 | 16 | 35,202 |
No | output | 1 | 17,601 | 16 | 35,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9
Submitted Solution:
```
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
tmp = 0
for i in A:
if i != 0:
tmp += i
else:
ans += tmp//2
tmp = 0
print(ans)
``` | instruction | 0 | 17,602 | 16 | 35,204 |
No | output | 1 | 17,602 | 16 | 35,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
Constraints
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
:
A_N
Output
Print the maximum number of pairs that Snuke can create.
Examples
Input
4
4
0
3
2
Output
4
Input
8
2
0
1
6
0
8
2
1
Output
9
Submitted Solution:
```
#coding: cp932
#M=int(input())
i = [int(input())for s in range(M)]
i = list(i)
#print(i)
N = int(i[0])
ans=0
for s in range(N-1):
if i[1+s]==0:
continue
cul= int((i[1+s]+i[2+s])/2)
ans += cul
if i[1+s]>i[2+s]:
amari = (i[1+s]+i[2+s])%2
print(ans)
``` | instruction | 0 | 17,603 | 16 | 35,206 |
No | output | 1 | 17,603 | 16 | 35,207 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which manipulates a disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of queries for different operations:
* unite(x, y): unites sets that contain x and y, say Sx and Sy, into a new set.
* same(x, y): determine whether x and y are in the same set.
Constraints
* 1 ≤ n ≤ 10000
* 1 ≤ q ≤ 100000
* x ≠ y
Input
n q
com1 x1 y1
com2 x2 y2
...
comq xq yq
In the first line, n and q are given. Then, q queries are given where com represents the type of queries. '0' denotes unite and '1' denotes same operation.
Output
For each same operation, print 1 if x and y are in the same set, otherwise 0, in a line.
Example
Input
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
Output
0
0
1
1
1
0
1
1 | instruction | 0 | 17,668 | 16 | 35,336 |
"Correct Solution:
```
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1]*(n+1)
self.rnk = [0]*(n+1)
self.Maxroot = -1
def Find_Root(self, x):
if (self.root[x] < 0):
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
if self.root[x] < self.Maxroot:
self.Maxroot = self.root[x]
self.root[y] = x
else:
self.root[y] += self.root[x]
if self.root[y] < self.Maxroot:
self.Maxroot = self.root[y]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return self.root[self.Find_Root(x)] * (-1)
N, Q = map(int, input().split())
solve = UnionFind(N)
ans = []
for _ in range(Q):
q,x,y = map(int, input().split())
if q == 0:
solve.Unite(x,y)
else:
ans.append(solve.isSameGroup(x,y))
for a in ans:
if a:
print(1)
else:
print(0)
``` | output | 1 | 17,668 | 16 | 35,337 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows:
* Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s.
For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`.
You are given the strings a, b, and c. Find the minimum possible length of s.
Constraints
* 1 \leq |a|, |b|, |c| \leq 2000
* a, b, and c consists of lowercase English letters and `?`s.
Input
Input is given from Standard Input in the following format:
a
b
c
Output
Print the minimum possible length of s.
Examples
Input
a?c
der
cod
Output
7
Input
atcoder
atcoder
???????
Output
7 | instruction | 0 | 19,141 | 16 | 38,282 |
"Correct Solution:
```
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
if row <= 0:
return [[] for _ in range(col)]
elif col == 1:
return [I() for _ in range(row)]
else:
read_all = [LI() for _ in range(row)]
return map(list, zip(*read_all))
#################
a = list(input())
b = list(input())
c = list(input())
def is_match(c1,c2):
if c1 == '?' or c2 == '?' or c1 == c2:
return True
else:
return False
def prefix_match_len(x,y):
len_list = []
n = len(x)
m = len(y)
for i in range(n):
match = 0
for j in range(i,min(i+m,n)):
if is_match(x[j],y[j-i]):
match += 1
else:
break
len_list.append(match)
return len_list
def concat(x,y,xy):
index_list = []
n = len(x)
m = len(y)
for i in range(n):
if xy[i] == min(n-i,m):
index_list.append(i)
index_list.append(n)
return index_list
def concat2(x,y,z,xz,yz,zy,index_list):
n1 = len(x)
n2 = len(y)
m = len(z)
candidate = []
for i in index_list:
flag = False
for j in range(max(n1,n2+i)):
if j <= n1-1:
if xz[j] != min(n1-j,m):
continue
if j >= i:
if n2-j+i >= 1 and yz[j-i] != min(n2-j+i,m):
continue
else:
if m-i+j >= 1 and zy[i-j] != min(m-i+j,n2):
continue
flag = True
candidate.append(max(n1,n2+i,j+m))
break
if not flag:
candidate.append(max(n1,n2+i)+m)
return min(candidate)
ab = prefix_match_len(a,b)
ac = prefix_match_len(a,c)
ba = prefix_match_len(b,a)
bc = prefix_match_len(b,c)
ca = prefix_match_len(c,a)
cb = prefix_match_len(c,b)
index_list = concat(a,b,ab)
ret1 = concat2(a,b,c,ac,bc,cb,index_list)
index_list = concat(a,c,ac)
ret2 = concat2(a,c,b,ab,cb,bc,index_list)
index_list = concat(b,a,ba)
ret3 = concat2(b,a,c,bc,ac,ca,index_list)
index_list = concat(b,c,bc)
ret4 = concat2(b,c,a,ba,ca,ac,index_list)
index_list = concat(c,a,ca)
ret5 = concat2(c,a,b,cb,ab,ba,index_list)
index_list = concat(c,b,cb)
ret6 = concat2(c,b,a,ca,ba,ab,index_list)
print(min(ret1,ret2,ret3,ret4,ret5,ret6))
``` | output | 1 | 19,141 | 16 | 38,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows:
* Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s.
For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`.
You are given the strings a, b, and c. Find the minimum possible length of s.
Constraints
* 1 \leq |a|, |b|, |c| \leq 2000
* a, b, and c consists of lowercase English letters and `?`s.
Input
Input is given from Standard Input in the following format:
a
b
c
Output
Print the minimum possible length of s.
Examples
Input
a?c
der
cod
Output
7
Input
atcoder
atcoder
???????
Output
7
Submitted Solution:
```
def solve_panasonic2020_e():
from itertools import islice, permutations, zip_longest
def cv2num(c):
return -1 if c == '?' else ord(c)
*a, = map(cv2num, input())
*b, = map(cv2num, input())
*c, = map(cv2num, input())
abc = a, b, c
ret = sum(map(len, abc))
for perm in permutations(abc):
first, second, third = perm
cands = [first + second]
for i in range(len(first)):
# first[i:]とsecondが一致するか見る
# 一致なら候補に残す
# すべてダメならfirst+secondだけ候補になる(重なりなし)
cand = []
for fc, sc in zip_longest(islice(first, i, len(first)), second, fillvalue=0):
if not (fc and sc):
cand.append(fc + sc)
elif fc == sc or sc == -1:
cand.append(fc)
elif fc == -1:
cand.append(sc)
else:
break
else:
cand = first[:i] + cand
cands.append(cand)
for cand in cands:
for i in range(len(cand)):
t = i
for cc, tc in zip_longest(islice(cand, i, len(cand)), third, fillvalue=0):
t += 1
if not (cc and tc):
continue
if not (cc == tc or cc == -1 or tc == -1):
break
else:
ret = min(ret, t)
print(ret)
if __name__ == '__main__':
solve_panasonic2020_e()
``` | instruction | 0 | 19,152 | 16 | 38,304 |
No | output | 1 | 19,152 | 16 | 38,305 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows:
* Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s.
For example, if s is `mississippi`, we can choose the substring `ssissip` and replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`.
You are given the strings a, b, and c. Find the minimum possible length of s.
Constraints
* 1 \leq |a|, |b|, |c| \leq 2000
* a, b, and c consists of lowercase English letters and `?`s.
Input
Input is given from Standard Input in the following format:
a
b
c
Output
Print the minimum possible length of s.
Examples
Input
a?c
der
cod
Output
7
Input
atcoder
atcoder
???????
Output
7
Submitted Solution:
```
def solve(li):
if len(li) == n:
ans.append(li)
return
tmp = max(li)
for i in range(1, tmp + 2):
solve(li + [i])
ans = []
n = int(input())
solve([1])
res = []
alph = "abcdefghijklmnopq"
for ptn in ans:
for i in range(n):
ptn[i] = alph[ptn[i] - 1]
res.append("".join(ptn))
res = sorted(res)
for i in res:
print(i)
``` | instruction | 0 | 19,153 | 16 | 38,306 |
No | output | 1 | 19,153 | 16 | 38,307 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13 | instruction | 0 | 19,170 | 16 | 38,340 |
"Correct Solution:
```
H,W = map(int, input().split())
grid = []
for i in range(H):
grid.append(input())
horiz = [[0]*W for _ in range(H)]
for i in range(H):
cur = 0
for j in range(W):
if grid[i][j] == '#':
for k in range(cur, j):
horiz[i][k] = j-cur
cur = j+1
for k in range(cur, W):
horiz[i][k] = W-cur
maxv = 0
for c in range(W):
cur = 0
besth = 0
for r in range(H):
if grid[r][c] == '.':
besth = max(besth, horiz[r][c])
else:
maxv = max(maxv, r-cur + besth - 1)
cur = r+1
besth = 0
maxv = max(maxv, H-cur + besth - 1)
print(maxv)
``` | output | 1 | 19,170 | 16 | 38,341 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13 | instruction | 0 | 19,171 | 16 | 38,342 |
"Correct Solution:
```
h,w=map(int,input().split())
g=[[c=='.'for c in input()] for _ in range(h)]
a=[[-3]*w for _ in range(h)]
for i in range(h):
l=r=0
for j in range(w):
l=-~l*g[i][j]; a[i][j]+=l
r=-~r*g[i][-1-j]; a[i][-1-j]+=r
for i in range(w):
d=u=0
for j in range(h):
d=-~d*g[j][i]; a[j][i]+=d
u=-~u*g[-1-j][i]; a[-1-j][i]+=u
print(max(a[i][j] for i in range(h) for j in range(w)))
``` | output | 1 | 19,171 | 16 | 38,343 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13 | instruction | 0 | 19,172 | 16 | 38,344 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
S=[[d for d in input()] for i in range(H)]
ans=[[0 for j in range(W)] for i in range(H)]
t=0
for i in range(H):
p=0
for j in range(W):
if S[i][j]==".":
p+=1
else:
p=0
ans[i][j]+=p
for i in range(H):
p=0
for j in range(W)[::-1]:
if S[i][j]==".":
p+=1
else:
p=0
ans[i][j]+=p
for j in range(W):
p=0
for i in range(H):
if S[i][j]==".":
p+=1
else:
p=0
ans[i][j]+=p
for j in range(W):
p=0
for i in range(H)[::-1]:
if S[i][j]==".":
p+=1
else:
p=0
ans[i][j]+=p
t=max(t,ans[i][j])
print(t-3)
``` | output | 1 | 19,172 | 16 | 38,345 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13 | instruction | 0 | 19,173 | 16 | 38,346 |
"Correct Solution:
```
h,w=map(int,input().split())
s=[input()+'#' for i in range(h)]
s.append('#'*(w+1))
h1=[[0]*(w+1) for i in range(h+1)]
w1=[[0]*(w+1) for i in range(h+1)]
for j in range(h):
r=0
for i in range(w+1):
if s[j][i]=='#':
for k in range(i-r,i+1):
h1[j][k]=r
r=0
h1[j][i]=0
else:
r+=1
for j in range(w):
r=0
for i in range(h+1):
if s[i][j]=='#':
for k in range(i-r,i+1):
w1[k][j]=r
r=0
w1[i][j]=0
else:
r+=1
ans=0
for i in range(h):
for j in range(w):
ans=max(ans,h1[i][j]+w1[i][j]-1)
print(ans)
``` | output | 1 | 19,173 | 16 | 38,347 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13 | instruction | 0 | 19,174 | 16 | 38,348 |
"Correct Solution:
```
h,w=map(int,input().split())
s=[list(input())for _ in range(h)]
score=[[0]*w for _ in range(h)]
ans=0
range_w=range(w)
range_h=range(h)
for i in range_h:
tmp_1=0
tmp_2=0
for j in range_w:
if s[i][j]=="#":
tmp_1=0
else:
tmp_1+=1
score[i][j]+=tmp_1
if s[i][-j-1]=="#":
tmp_2=0
else:
tmp_2+=1
score[i][-j-1]+=tmp_2
for j in range_w:
tmp_3=0
tmp_4=0
for i in range_h:
if s[i][j]=="#":
tmp_3=0
else:
tmp_3+=1
score[i][j]+=tmp_3
if s[-i-1][j]=="#":
tmp_4=0
else:
tmp_4+=1
score[-i-1][j]+=tmp_4-3
for i in range(h):
for j in range(w):
ans=max(ans,score[i][j])
print(ans)
``` | output | 1 | 19,174 | 16 | 38,349 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13 | instruction | 0 | 19,175 | 16 | 38,350 |
"Correct Solution:
```
# 5858744
H,W = map(int,input().split())
S = [input() for _ in range(H)]
L,R,D,U = [[[0]*W for _ in range(H)] for i in range(4)]
for h in range(H):
for w in range(W):
if S[h][w] == '.':
L[h][w] = L[h][w-1]+1
U[h][w] = U[h-1][w]+1
if S[h][W-1-w] == '.':
R[h][-w-1] = R[h][-w]+1
if S[H-1-h][w] == '.':
D[-h-1][w] = D[-h][w]+1
ans = 0
for h in range(H):
for w in range(W):
if S[h][w] == '.':
ans = max(ans,L[h][w]+U[h][w]+R[h][w]+D[h][w]-3)
print(ans)
``` | output | 1 | 19,175 | 16 | 38,351 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13 | instruction | 0 | 19,176 | 16 | 38,352 |
"Correct Solution:
```
H, W=map(int, input().split())
S=[input() for _ in range(H)]
tate=[[0]*W for _ in range(H)]
yoko=[[0]*W for _ in range(H)]
for i in range(W):
j=0
while j<H:
x=0
while j+x<H and S[j+x][i]=='.':
x+=1
if x==0:
tate[j][i]=0
j+=1
else:
for t in range(x):
tate[j+t][i]=x
j+=x
for i in range(H):
j=0
while j<W:
x=0
while j+x<W and S[i][j+x]=='.':
x+=1
if x==0:
yoko[i][j]=0
j+=1
else:
for t in range(x):
yoko[i][j+t]=x
j+=x
print(max([max([tate[i][j]+yoko[i][j]-1 for j in range(W)]) for i in range(H)]))
``` | output | 1 | 19,176 | 16 | 38,353 |
Provide a correct Python 3 solution for this coding contest problem.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13 | instruction | 0 | 19,177 | 16 | 38,354 |
"Correct Solution:
```
a=[]
h,w=map(int,input().split())
for i in range(h):
a.append(input()+'#')
a.append('#'*(w+1))
b=[[0]*(w+1) for i in range(h+1)]
c=[[0]*(w+1) for i in range(h+1)]
for i in range(h+1):
t=0
for j in range(w+1):
if a[i][j]=='#':
for k in range(t):
b[i][j-k-1]=t
t=0
else:
t+=1
for j in range(w+1):
t=0
for i in range(h+1):
if a[i][j]=='#':
for k in range(t):
c[i-k-1][j]=t
t=0
else:
t+=1
ans=0
for i in range(h+1):
for j in range(w+1):
ans=max(b[i][j]+c[i][j]-1,ans)
print(ans)
``` | output | 1 | 19,177 | 16 | 38,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13
Submitted Solution:
```
#D
w,h=map(int,input().split())
s=[input() for i in range(w)]
t=[[[],[]] for j in range(w)]
for i in range(w):
k=0
for j in range(h):
if s[i][j]==".":
k+=1
else:
t[i][0]+=[k for _ in range(k)]+[0]
k=0
t[i][0]+=[k for _ in range(k)]
for i in range(h):
k=0
for j in range(w):
if s[j][i]==".":
k+=1
else:
for l in range(1,k+1):
t[j-l][1]+=[k]
t[j][1]+=[0]
k=0
for l in range(1,k+1):
t[w-l][1]+=[k]
answer=0
for i in range(w):
for j in range(h):
answer=max(t[i][0][j]+t[i][1][j],answer)
print(answer-1)
``` | instruction | 0 | 19,178 | 16 | 38,356 |
Yes | output | 1 | 19,178 | 16 | 38,357 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13
Submitted Solution:
```
h,w=list(map(int,input().split()))
m=[]
for i in range(h):
mm=[]
for j in input():
mm.append(1 if j=="#" else 0)
m.append(mm)
wl=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
s=0
t=0
while t<w:
while t<w and m[i][t]==0:
t+=1
for j in range(s,t):
wl[i][j]=t-s
s=t+1
t=t+1
mx=0
for i in range(w):
s=0
t=0
while t<h:
while t<h and m[t][i]==0:
t+=1
for j in range(s,t):
k=wl[j][i]
if mx<k+t-s:
mx=k+t-s
s=t+1
t=t+1
print(mx-1)
``` | instruction | 0 | 19,179 | 16 | 38,358 |
Yes | output | 1 | 19,179 | 16 | 38,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13
Submitted Solution:
```
H, W = map(int, input().split())
S = [input() for _ in range(H)]
l = [[0] * (W+2) for _ in range(H+2)]
u = [[0] * (W+2) for _ in range(H+2)]
r = [[0] * (W+2) for _ in range(H+2)]
d = [[0] * (W+2) for _ in range(H+2)]
for i in range(1, H+1):
for j in range(1, W+1):
if S[i-1][j-1] != '#':
l[i][j] += l[i][j-1] + 1
u[i][j] += u[i-1][j] + 1
if S[-i][-j] != '#':
r[-i-1][-j-1] += r[-i-1][-j] + 1
d[-i-1][-j-1] += d[-i][-j-1] + 1
ans = 0
for i in range(1, H+1):
for j in range(1, W+1):
ans = max(ans, l[i][j]+u[i][j]+r[i][j]+d[i][j]-3)
print(ans)
``` | instruction | 0 | 19,180 | 16 | 38,360 |
Yes | output | 1 | 19,180 | 16 | 38,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13
Submitted Solution:
```
# coding: utf-8
# Your code here!
h,w = [int(i) for i in input().split()]
b = [input() for i in range(h)]
l = [[0]*w for _ in [0]*h] #左にある白マス(自分含む)
r = [[0]*w for _ in [0]*h]
u = [[0]*w for _ in [0]*h] #上にある白マス(自分含む)
d = [[0]*w for _ in [0]*h]
for hi in range(h):
for wj in range(w):
if b[hi][wj] == '.':
l[hi][wj] = l[hi][wj-1]+1
u[hi][wj] = u[hi-1][wj]+1
if b[hi][w-wj-1] == '.':
r[hi][w-wj-1] = r[hi][-wj]+1
if b[h-hi-1][wj] == '.':
d[h-hi-1][wj] = d[-hi][wj]+1
ans = 0
for i in range(h):
for j in range(w):
ans = max(ans, l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
print(ans)
``` | instruction | 0 | 19,181 | 16 | 38,362 |
Yes | output | 1 | 19,181 | 16 | 38,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13
Submitted Solution:
```
h, w = map(int, input().split())
s = [0] * w
for i in range(h):
s[i] = list(input())
h_cnt = [[0] * w for _ in range(h)]
w_cnt = [[0] * w for _ in range(h)]
for i in range(h):
dot_cnt, beg_sec = 0, 0
for j in range(w):
if s[i][j] == '#':
if dot_cnt > 0:
for k in range(beg_sec, j):
w_cnt[i][k] = dot_cnt
beg_sec = j+1
dot_cnt = 0
else:
w_cnt[i][j] = 0
beg_sec += 1
else:
dot_cnt += 1
if dot_cnt > 0:
for k in range(beg_sec, w):
w_cnt[i][k] = dot_cnt
for i in range(w):
dot_cnt, beg_sec = 0, 0
for j in range(h):
if s[j][i] == '#':
if dot_cnt > 0:
for k in range(beg_sec, j):
h_cnt[k][i] = dot_cnt
beg_sec = j+1
dot_cnt = 0
else:
h_cnt[j][i] = 0
beg_sec += 1
else:
dot_cnt += 1
if dot_cnt > 0:
for k in range(beg_sec, h):
h_cnt[k][i] = dot_cnt
ans = 0
for i in range(h):
for j in range(w):
ans = max(ans, h_cnt[i][j] + w_cnt[i][j] - 1)
print(ans)
``` | instruction | 0 | 19,182 | 16 | 38,364 |
No | output | 1 | 19,182 | 16 | 38,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13
Submitted Solution:
```
H, W = list(map(int, input().split()))
M = [[True for w in range(W)] for h in range(H)]
for h in range(0, H):
Col = list(input())
for w in range(0, W):
if Col[w] == '#':
M[h][w] = False
mx = 0
for h in range(0, H):
for w in range(0, W):
if not M[h][w]:
continue
c = 1
for d in range(w - 1, -1, -1):
if not M[h][d]:
break
c += 1
for d in range(w + 1, W):
if not M[h][d]:
break
c += 1
for d in range(h - 1, -1, -1):
if not M[d][w]:
break
c += 1
for d in range(h + 1, H):
if not M[d][w]:
break
c += 1
if c > mx:
mx = c
print(mx)
``` | instruction | 0 | 19,183 | 16 | 38,366 |
No | output | 1 | 19,183 | 16 | 38,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13
Submitted Solution:
```
import numpy as np
import copy as cp
h,w = map(int,input().split())
# 題意のリストを
arr = [0 for i in range(h)]
for i in range(h):
s = input()
tmp = list(s)
for j in range(w):
tmp[j] = 0 if tmp[j]=="#" else 1
arr[i] = tmp
arr = np.array(arr)
left = cp.deepcopy(arr)
right = cp.deepcopy(arr)
up = cp.deepcopy(arr)
down = cp.deepcopy(arr)
# left
for i in range(h):
for j in range(w):
if j==0 : continue
if left[i][j] == 0 : continue
left[i][j] += left[i][j-1]
# right
for i in range(h):
for j in range(w-1,-1,-1):
if j==w-1 : continue
if right[i][j] == 0 : continue
right[i][j] += right[i][j+1]
# up
up = up.T
for i in range(w):
for j in range(h):
if j==0 : continue
if up[i][j] == 0 : continue
up[i][j] += up[i][j-1]
up = up.T
# down
down = down.T
for i in range(w):
for j in range(h-1,-1,-1):
if j==h-1 : continue
if down[i][j] == 0 : continue
down[i][j] += down[i][j+1]
down = down.T
# 答えを求める
ans = 0
for i in range(h):
for j in range(w):
val = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
ans = max(ans, val)
print(ans)
``` | instruction | 0 | 19,184 | 16 | 38,368 |
No | output | 1 | 19,184 | 16 | 38,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.
Constraints
* 1 \leq H \leq 2,000
* 1 \leq W \leq 2,000
* S_i is a string of length W consisting of `#` and `.`.
* `.` occurs at least once in one of the strings S_i (1 \leq i \leq H).
Input
Input is given from Standard Input in the following format:
H W
S_1
:
S_H
Output
Print the maximum possible number of squares lighted by the lamp.
Examples
Input
4 6
#..#..
.....#
....#.
#.#...
Output
8
Input
4 6
..#..
.....#
....#.
.#...
Output
8
Input
8 8
..#...#.
....#...
......
..###..#
...#..#.
....#.
...#...
.#..#
Output
13
Submitted Solution:
```
def main():
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
right = [[0] * W for _ in range(H)]
left = [[0] * W for _ in range(H)]
upper = [[0] * W for _ in range(H)]
under = [[0] * W for _ in range(H)]
num_max_loc = 0
for i in range(H):
tmp_num = 0
for j in range(W):
if A[i][j] == "#":
tmp_num = 0
else:
tmp_num += 1
left[i][j] = tmp_num
for i in range(H):
tmp_num = 0
for j in range(W-1, -1, -1):
if A[i][j] == "#":
tmp_num = 0
else:
tmp_num += 1
right[i][j] = tmp_num
for i in range(W):
tmp_num = 0
for j in range(H):
if A[j][i] == "#":
tmp_num = 0
else:
tmp_num += 1
upper[j][i] = tmp_num
for i in range(W):
tmp_num = 0
for j in range(H-1, -1, -1):
if A[j][i] == "#":
tmp_num = 0
else:
tmp_num += 1
under[j][i] = tmp_num
for i in range(H):
for j in range(W):
tmp_sum = (
left[i][j] + right[i][j] + upper[i][j] + under[i][j] - 3)
num_max_loc = max(num_max_loc, tmp_sum)
print(num_max_loc)
if __name__ == '__main__':
main()
``` | instruction | 0 | 19,185 | 16 | 38,370 |
No | output | 1 | 19,185 | 16 | 38,371 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string s consisting of `A`, `B` and `C`.
Snuke wants to perform the following operation on s as many times as possible:
* Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`.
Find the maximum possible number of operations.
Constraints
* 1 \leq |s| \leq 200000
* Each character of s is `A`, `B` and `C`.
Input
Input is given from Standard Input in the following format:
s
Output
Find the maximum possible number of operations.
Examples
Input
ABCABC
Output
3
Input
C
Output
0
Input
ABCACCBABCBCAABCB
Output
6 | instruction | 0 | 20,978 | 16 | 41,956 |
"Correct Solution:
```
s=input()
s=s.replace("BC","1")
s=s.replace("A","0")
s=s.replace("B","2")
s=s.replace("C","2")
l=[]
cnt1=0
ans=0
for ss in reversed(s):
if ss=="0":
ans+=cnt1
elif ss=="1":
cnt1+=1
else:
cnt1=0
print(ans)
``` | output | 1 | 20,978 | 16 | 41,957 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string s consisting of `A`, `B` and `C`.
Snuke wants to perform the following operation on s as many times as possible:
* Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`.
Find the maximum possible number of operations.
Constraints
* 1 \leq |s| \leq 200000
* Each character of s is `A`, `B` and `C`.
Input
Input is given from Standard Input in the following format:
s
Output
Find the maximum possible number of operations.
Examples
Input
ABCABC
Output
3
Input
C
Output
0
Input
ABCACCBABCBCAABCB
Output
6 | instruction | 0 | 20,979 | 16 | 41,958 |
"Correct Solution:
```
S = input()
S = S.replace('BC','D')
ans = a = 0
for c in S:
if c=='A':
a += 1
elif c=='D':
ans += a
else:
a = 0
print(ans)
``` | output | 1 | 20,979 | 16 | 41,959 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string s consisting of `A`, `B` and `C`.
Snuke wants to perform the following operation on s as many times as possible:
* Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`.
Find the maximum possible number of operations.
Constraints
* 1 \leq |s| \leq 200000
* Each character of s is `A`, `B` and `C`.
Input
Input is given from Standard Input in the following format:
s
Output
Find the maximum possible number of operations.
Examples
Input
ABCABC
Output
3
Input
C
Output
0
Input
ABCACCBABCBCAABCB
Output
6 | instruction | 0 | 20,980 | 16 | 41,960 |
"Correct Solution:
```
s=input().replace("BC","X").replace("B","Y").replace("C","Y")
ans=0
for t in s.split("Y"):
cnt=t.count("X")
for c in t:
if c=="A":
ans+=cnt
else:
cnt-=1
print(ans)
``` | output | 1 | 20,980 | 16 | 41,961 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string s consisting of `A`, `B` and `C`.
Snuke wants to perform the following operation on s as many times as possible:
* Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`.
Find the maximum possible number of operations.
Constraints
* 1 \leq |s| \leq 200000
* Each character of s is `A`, `B` and `C`.
Input
Input is given from Standard Input in the following format:
s
Output
Find the maximum possible number of operations.
Examples
Input
ABCABC
Output
3
Input
C
Output
0
Input
ABCACCBABCBCAABCB
Output
6 | instruction | 0 | 20,981 | 16 | 41,962 |
"Correct Solution:
```
S=input()
N=len(S)
i=0
now=0
ans=0
while i<N:
if S[i]=='A':
now+=1
elif S[i:i+2]=='BC':
ans+=now
i+=1
else:
now=0
i+=1
print(ans)
``` | output | 1 | 20,981 | 16 | 41,963 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.