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.
You have a blackboard and initially only an odd number x is written on it. Your goal is to write the number 1 on the blackboard.
You may write new numbers on the blackboard with the following two operations.
* You may take two numbers (not necessarily distinct) already on the blackboard and write their sum on the blackboard. The two numbers you have chosen remain on the blackboard.
* You may take two numbers (not necessarily distinct) already on the blackboard and write their [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) on the blackboard. The two numbers you have chosen remain on the blackboard.
Perform a sequence of operations such that at the end the number 1 is on the blackboard.
Input
The single line of the input contains the odd integer x (3 ≤ x ≤ 999,999).
Output
Print on the first line the number q of operations you perform. Then q lines should follow, each describing one operation.
* The "sum" operation is described by the line "a + b", where a, b must be integers already present on the blackboard.
* The "xor" operation is described by the line "a ^ b", where a, b must be integers already present on the blackboard.
The operation symbol (+ or ^) must be separated from a, b by a whitespace.
You can perform at most 100,000 operations (that is, q≤ 100,000) and all numbers written on the blackboard must be in the range [0, 5⋅10^{18}]. It can be proven that under such restrictions the required sequence of operations exists. You can output any suitable sequence of operations.
Examples
Input
3
Output
5
3 + 3
3 ^ 6
3 + 5
3 + 6
8 ^ 9
Input
123
Output
10
123 + 123
123 ^ 246
141 + 123
246 + 123
264 ^ 369
121 + 246
367 ^ 369
30 + 30
60 + 60
120 ^ 121 | instruction | 0 | 31,189 | 7 | 62,378 |
Tags: bitmasks, constructive algorithms, math, matrices, number theory
Correct Solution:
```
def GSB(n):
ans = 0
for i in range(63):
if (1<<i)&n:
ans = i
return ans
def pop_count(n):
ans = 0
for i in range(63):
if (1<<i)&n:
ans += 1
return ans
exists = []
ops = []
def add(a,b):
assert(a in exists and b in exists)
ops.append(f"{a} + {b}")
exists.append(a+b)
assert(a+b <= 5*10**18)
return a+b
def xor(a,b):
assert(a in exists and b in exists)
ops.append(f"{a} ^ {b}")
exists.append(a^b)
assert((a^b) <= 5*10**18)
return a^b
n = int(input())
exists.append(n)
x = n
for i in range(GSB(n)):
x = add(x,x)
x1 = xor(n,x)
x2 = add(x1,x)
x3 = add(x,x)
x4 = xor(x2,x3)
powerOfTwo = xor(x4,n)
cleaners = [powerOfTwo]
for i in range(40):
cleaners.append(add(cleaners[-1],cleaners[-1]))
def clean(n):
for p in cleaners:
if n&p:
n = xor(n,p)
return n
v = n
for i in range(1,20+1):
if (1<<i)&v:
v = clean(xor(v,n<<i))
assert(1 in exists)
print(len(ops))
for op in ops:
print(op)
``` | output | 1 | 31,189 | 7 | 62,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that.
The box's lock is constructed like that. The box itself is represented by an absolutely perfect black cube with the identical deepening on each face (those are some foreign nanotechnologies that the far away kingdom scientists haven't dreamt of). The box is accompanied by six gems whose form matches the deepenings in the box's faces. The box can only be opened after it is correctly decorated by the gems, that is, when each deepening contains exactly one gem. Two ways of decorating the box are considered the same if they can be obtained one from the other one by arbitrarily rotating the box (note that the box is represented by a perfect nanotechnological cube)
Now Vasilisa the Wise wants to know by the given set of colors the following: in how many ways would she decorate the box in the worst case to open it? To answer this question it is useful to know that two gems of one color are indistinguishable from each other. Help Vasilisa to solve this challenging problem.
Input
The first line contains exactly 6 characters without spaces from the set {R, O, Y, G, B, V} — they are the colors of gems with which the box should be decorated.
Output
Print the required number of different ways to decorate the box.
Examples
Input
YYYYYY
Output
1
Input
BOOOOB
Output
2
Input
ROYGBV
Output
30 | instruction | 0 | 31,536 | 7 | 63,072 |
Tags: brute force, implementation
Correct Solution:
```
from functools import reduce
def factorial(n):
return reduce(lambda x, y: x*y, range(1,n+1))
colors = {
'R' : 0,
'O' : 0,
'Y' : 0,
'G' : 0,
'B' : 0,
'V' : 0
}
for c in list(input()):
colors[c] += 1
amount = list(reversed(sorted([(colors[key], key) for key in colors])))
amount = [x[0] for x in amount]
if amount[0] == 6 or amount[0] == 5:
print("1")
elif amount[0] == 4:
print("2")
elif amount[0] == 3:
if amount[1] == 3:
print("2")
elif amount[1] == 2:
print("3")
elif amount[1] == 1:
print("5")
elif amount[0] == 2:
if amount[1] == amount[2] == 2:
print("6")
elif amount[1] == 2:
print("8")
else:
print(factorial(6) // 48)
elif amount[0] == 1:
print(factorial(6) // 24)
``` | output | 1 | 31,536 | 7 | 63,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that.
The box's lock is constructed like that. The box itself is represented by an absolutely perfect black cube with the identical deepening on each face (those are some foreign nanotechnologies that the far away kingdom scientists haven't dreamt of). The box is accompanied by six gems whose form matches the deepenings in the box's faces. The box can only be opened after it is correctly decorated by the gems, that is, when each deepening contains exactly one gem. Two ways of decorating the box are considered the same if they can be obtained one from the other one by arbitrarily rotating the box (note that the box is represented by a perfect nanotechnological cube)
Now Vasilisa the Wise wants to know by the given set of colors the following: in how many ways would she decorate the box in the worst case to open it? To answer this question it is useful to know that two gems of one color are indistinguishable from each other. Help Vasilisa to solve this challenging problem.
Input
The first line contains exactly 6 characters without spaces from the set {R, O, Y, G, B, V} — they are the colors of gems with which the box should be decorated.
Output
Print the required number of different ways to decorate the box.
Examples
Input
YYYYYY
Output
1
Input
BOOOOB
Output
2
Input
ROYGBV
Output
30
Submitted Solution:
```
from functools import reduce
def factorial(n):
return reduce(lambda x, y: x*y, range(1,n+1))
colors = {
'R' : 0,
'O' : 0,
'Y' : 0,
'G' : 0,
'B' : 0,
'V' : 0
}
for c in list(input()):
colors[c] += 1
amount = list(reversed(sorted([(colors[key], key) for key in colors])))
amount = [x[0] for x in amount]
if amount[0] == 6 or amount[0] == 5:
print("1")
elif amount[0] == 4:
print("2")
elif amount[0] == 3:
if amount[1] == 3:
print("2")
elif amount[1] == 2:
print("5")
elif amount[1] == 1:
print("5")
elif amount[0] == 2:
if amount[1] == amount[2] == 2:
print("4")
elif amount[1] == 2:
print("5")
else:
print(factorial(6) // 48)
elif amount[0] == 1:
print(factorial(6) // 24)
``` | instruction | 0 | 31,537 | 7 | 63,074 |
No | output | 1 | 31,537 | 7 | 63,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that.
The box's lock is constructed like that. The box itself is represented by an absolutely perfect black cube with the identical deepening on each face (those are some foreign nanotechnologies that the far away kingdom scientists haven't dreamt of). The box is accompanied by six gems whose form matches the deepenings in the box's faces. The box can only be opened after it is correctly decorated by the gems, that is, when each deepening contains exactly one gem. Two ways of decorating the box are considered the same if they can be obtained one from the other one by arbitrarily rotating the box (note that the box is represented by a perfect nanotechnological cube)
Now Vasilisa the Wise wants to know by the given set of colors the following: in how many ways would she decorate the box in the worst case to open it? To answer this question it is useful to know that two gems of one color are indistinguishable from each other. Help Vasilisa to solve this challenging problem.
Input
The first line contains exactly 6 characters without spaces from the set {R, O, Y, G, B, V} — they are the colors of gems with which the box should be decorated.
Output
Print the required number of different ways to decorate the box.
Examples
Input
YYYYYY
Output
1
Input
BOOOOB
Output
2
Input
ROYGBV
Output
30
Submitted Solution:
```
from functools import reduce
def factorial(n):
return reduce(lambda x, y: x*y, range(1,n+1))
colors = {
'R' : 0,
'O' : 0,
'Y' : 0,
'G' : 0,
'B' : 0,
'V' : 0
}
for c in list(input()):
colors[c] += 1
amount = list(reversed(sorted([(colors[key], key) for key in colors])))
amount = [x[0] for x in amount]
if amount[0] == 6 or amount[0] == 5:
print("1")
elif amount[0] == 4:
print("2")
elif amount[0] == 3:
if amount[1] == 3:
print("2")
elif amount[1] == 2:
print("3")
elif amount[1] == 1:
print("5")
elif amount[0] == 2:
if amount[1] == amount[2] == 2:
print("4")
elif amount[1] == 2:
print("8")
else:
print(factorial(6) // 48)
elif amount[0] == 1:
print(factorial(6) // 24)
``` | instruction | 0 | 31,538 | 7 | 63,076 |
No | output | 1 | 31,538 | 7 | 63,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that.
The box's lock is constructed like that. The box itself is represented by an absolutely perfect black cube with the identical deepening on each face (those are some foreign nanotechnologies that the far away kingdom scientists haven't dreamt of). The box is accompanied by six gems whose form matches the deepenings in the box's faces. The box can only be opened after it is correctly decorated by the gems, that is, when each deepening contains exactly one gem. Two ways of decorating the box are considered the same if they can be obtained one from the other one by arbitrarily rotating the box (note that the box is represented by a perfect nanotechnological cube)
Now Vasilisa the Wise wants to know by the given set of colors the following: in how many ways would she decorate the box in the worst case to open it? To answer this question it is useful to know that two gems of one color are indistinguishable from each other. Help Vasilisa to solve this challenging problem.
Input
The first line contains exactly 6 characters without spaces from the set {R, O, Y, G, B, V} — they are the colors of gems with which the box should be decorated.
Output
Print the required number of different ways to decorate the box.
Examples
Input
YYYYYY
Output
1
Input
BOOOOB
Output
2
Input
ROYGBV
Output
30
Submitted Solution:
```
from functools import reduce
def factorial(n):
return reduce(lambda x, y: x*y, range(1,n+1))
colors = {
'R' : 0,
'O' : 0,
'Y' : 0,
'G' : 0,
'B' : 0,
'V' : 0
}
for c in list(input()):
colors[c] += 1
amount = list(reversed(sorted([(colors[key], key) for key in colors])))
amount = [x[0] for x in amount]
if amount[0] == 6 or amount[0] == 5:
print("1")
elif amount[0] == 4:
print("2")
elif amount[0] == 3:
if amount[1] == 3:
print("2")
elif amount[1] == 2:
print("4")
elif amount[1] == 1:
print("6")
elif amount[0] == 2:
if amount[1] == amount[2] == 2:
print("4")
elif amount[1] == 2:
while True: pass
else:
print(factorial(6) // 48)
elif amount[0] == 1:
print(factorial(6) // 24)
``` | instruction | 0 | 31,539 | 7 | 63,078 |
No | output | 1 | 31,539 | 7 | 63,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that.
The box's lock is constructed like that. The box itself is represented by an absolutely perfect black cube with the identical deepening on each face (those are some foreign nanotechnologies that the far away kingdom scientists haven't dreamt of). The box is accompanied by six gems whose form matches the deepenings in the box's faces. The box can only be opened after it is correctly decorated by the gems, that is, when each deepening contains exactly one gem. Two ways of decorating the box are considered the same if they can be obtained one from the other one by arbitrarily rotating the box (note that the box is represented by a perfect nanotechnological cube)
Now Vasilisa the Wise wants to know by the given set of colors the following: in how many ways would she decorate the box in the worst case to open it? To answer this question it is useful to know that two gems of one color are indistinguishable from each other. Help Vasilisa to solve this challenging problem.
Input
The first line contains exactly 6 characters without spaces from the set {R, O, Y, G, B, V} — they are the colors of gems with which the box should be decorated.
Output
Print the required number of different ways to decorate the box.
Examples
Input
YYYYYY
Output
1
Input
BOOOOB
Output
2
Input
ROYGBV
Output
30
Submitted Solution:
```
from functools import reduce
def factorial(n):
return reduce(lambda x, y: x*y, range(1,n+1))
colors = {
'R' : 0,
'O' : 0,
'Y' : 0,
'G' : 0,
'B' : 0,
'V' : 0
}
for c in list(input()):
colors[c] += 1
amount = list(reversed(sorted([(colors[key], key) for key in colors])))
amount = [x[0] for x in amount]
if amount[0] == 6 or amount[0] == 5:
print("1")
elif amount[0] == 4:
print("2")
elif amount[0] == 3:
if amount[1] == 3:
print("2")
elif amount[1] == 2:
print("5")
elif amount[1] == 1:
print("5")
elif amount[0] == 2:
if amount[1] == amount[2] == 2:
print("4")
elif amount[1] == 2:
print("4")
else:
print(factorial(6) // 48)
elif amount[0] == 1:
print(factorial(6) // 24)
``` | instruction | 0 | 31,540 | 7 | 63,080 |
No | output | 1 | 31,540 | 7 | 63,081 |
Provide a correct Python 3 solution for this coding contest problem.
We have an H \times W grid, where each square is painted white or black in the initial state. Given are strings A_1, A_2, ..., A_H representing the colors of the squares in the initial state. For each pair (i, j) (1 \leq i \leq H, 1 \leq j \leq W), if the j-th character of A_i is `.`, the square at the i-th row and j-th column is painted white; if that character is `#`, that square is painted black.
Among the 2^{HW} ways for each square in the grid to be painted white or black, how many can be obtained from the initial state by performing the operations below any number of times (possibly zero) in any order? Find this count modulo 998,244,353.
* Choose one row, then paint all the squares in that row white.
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column white.
* Choose one column, then paint all the squares in that column black.
Constraints
* 1 \leq H, W \leq 10
* |A_i| = W (1 \leq i \leq H)
* All strings A_i consist of `.` and `#`.
* H and W are integers.
Input
Input is given from Standard Input in the following format:
H W
A_1
A_2
\vdots
A_H
Output
Print the answer.
Examples
Input
2 2
#.
.#
Output
15
Input
2 2
.
.#
Output
15
Input
3 3
...
...
...
Output
230
Input
2 4
...
...#
Output
150
Input
6 7
.......
.......
.#.....
..#....
.#.#...
.......
Output
203949910 | instruction | 0 | 31,569 | 7 | 63,138 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
A=[input().strip() for i in range(H)]
mod=998244353
# factorial,facotiralの逆数を事前計算.
FACT=[1]
for i in range(1,21):
FACT.append(FACT[-1]*i%mod)
FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(20,0,-1):
FACT_INV.append(FACT_INV[-1]*i%mod)
FACT_INV.reverse()
COMBI=[[-1]*21 for i in range(21)]
def Combi(a,b):
if COMBI[a][b]!=-1:
return COMBI[a][b]
if 0<=b<=a:
COMBI[a][b]=FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
return COMBI[a][b]
else:
COMBI[a][b]=0
return 0
M=max(H,W)+1
RA=[[-1]*M for i in range(M)]
def rect(H,W):
if H==W==0:
return 1
if RA[H][W]!=-1:
return RA[H][W]
DP=[[[0,0] for j in range(W+1)] for i in range(H+1)] # (h,w)の最後に進んだ向きが縦/横のときの場合の数
DP[0][0][0]=1
DP[0][0][1]=1
for h in range(H+1):
for w in range(W+1):
for nexth in range(h+1,H+1):
DP[nexth][w][0]+=DP[h][w][1]*FACT_INV[nexth-h]
DP[nexth][w][0]%=mod
for nextw in range(w+1,W+1):
DP[h][nextw][1]+=DP[h][w][0]*FACT_INV[nextw-w]
DP[h][nextw][1]%=mod
RA[H][W]=RA[W][H]=sum(DP[H][W])%mod*FACT[H]*FACT[W]%mod
return RA[H][W]
CA=[[-1]*(W+1) for i in range(H+1)]
def calc(h,w):
if CA[h][w]!=-1:
return CA[h][w]
RET=0
for bh in range(h+1):
for bw in range(w+1):
RET+=rect(bh,w-bw)*rect(h-bh,bw)*Combi(h,bh)*Combi(w,bw)
#print(bh,bw,w-bw,h-bh,rect(bh,w-bw),rect(h-bh,bw),Combi(h,bh),Combi(w,bw))
RET%=mod
CA[h][w]=RET%mod
return CA[h][w]
for i in range(H+1):
for j in range(W+1):
calc(i,j)
ANS=rect(H,W)
for i in range((1<<H)-1):
for j in range((1<<W)-1):
okflag=1
for h in range(H):
if i & (1<<h)!=0:
continue
coinc=""
dif=0
for w in range(W):
if j & (1<<w)!=0:
continue
if coinc=="":
coinc=A[h][w]
elif A[h][w]!=coinc:
dif=1
break
if dif==0:
okflag=0
break
if okflag==0:
continue
okflag=1
for w in range(W):
if j & (1<<w)!=0:
continue
coinc=""
dif=0
for h in range(H):
if i & (1<<h)!=0:
continue
if coinc=="":
coinc=A[h][w]
elif A[h][w]!=coinc:
dif=1
break
if dif==0:
okflag=0
break
if okflag==0:
continue
# i, jのうち、0の部分は決定済み. 1の部分に自由度がある.
HR=WR=0
for h in range(H):
if i & (1<<h)!=0:
HR+=1
for w in range(W):
if j & (1<<w)!=0:
WR+=1
ANS+=CA[HR][WR]
#ANS%=mod
print(ANS%mod)
``` | output | 1 | 31,569 | 7 | 63,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H \times W grid, where each square is painted white or black in the initial state. Given are strings A_1, A_2, ..., A_H representing the colors of the squares in the initial state. For each pair (i, j) (1 \leq i \leq H, 1 \leq j \leq W), if the j-th character of A_i is `.`, the square at the i-th row and j-th column is painted white; if that character is `#`, that square is painted black.
Among the 2^{HW} ways for each square in the grid to be painted white or black, how many can be obtained from the initial state by performing the operations below any number of times (possibly zero) in any order? Find this count modulo 998,244,353.
* Choose one row, then paint all the squares in that row white.
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column white.
* Choose one column, then paint all the squares in that column black.
Constraints
* 1 \leq H, W \leq 10
* |A_i| = W (1 \leq i \leq H)
* All strings A_i consist of `.` and `#`.
* H and W are integers.
Input
Input is given from Standard Input in the following format:
H W
A_1
A_2
\vdots
A_H
Output
Print the answer.
Examples
Input
2 2
#.
.#
Output
15
Input
2 2
.
.#
Output
15
Input
3 3
...
...
...
Output
230
Input
2 4
...
...#
Output
150
Input
6 7
.......
.......
.#.....
..#....
.#.#...
.......
Output
203949910
Submitted Solution:
```
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
A=[input().strip() for i in range(H)]
mod=998244353
# factorial,facotiralの逆数を事前計算.
FACT=[1]
for i in range(1,30+1):
FACT.append(FACT[-1]*i%mod)
FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(30,0,-1):
FACT_INV.append(FACT_INV[-1]*i%mod)
FACT_INV.reverse()
def Combi(a,b):
if 0<=b<=a:
return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
else:
return 0
M=max(H,W)+1
RA=[[-1]*M for i in range(M)]
def rect(H,W):
if H==W==0:
return 1
if RA[H][W]!=-1:
return RA[H][W]
DP=[[[0,0] for j in range(W+1)] for i in range(H+1)] # (h,w)の最後に進んだ向きが縦/横のときの場合の数
DP[0][0][0]=1
DP[0][0][1]=1
for h in range(H+1):
for w in range(W+1):
for nexth in range(h+1,H+1):
DP[nexth][w][0]+=DP[h][w][1]*FACT_INV[nexth-h]
DP[nexth][w][0]%=mod
for nextw in range(w+1,W+1):
DP[h][nextw][1]+=DP[h][w][0]*FACT_INV[nextw-w]
DP[h][nextw][1]%=mod
RA[H][W]=RA[W][H]=sum(DP[H][W])*FACT[H]*FACT[W]%mod
return RA[H][W]
CA=[[-1]*(W+1) for i in range(H+1)]
def calc(h,w):
if CA[h][w]!=-1:
return CA[h][w]
RET=0
for bh in range(h+1):
for bw in range(w+1):
RET+=rect(bh,w-bw)*rect(h-bh,bw)*Combi(h,bh)*Combi(w,bw)
#print(bh,bw,w-bw,h-bh,rect(bh,w-bw),rect(h-bh,bw),Combi(h,bh),Combi(w,bw))
RET%=mod
CA[h][w]=RET%mod
return CA[h][w]
ANS=0
for i in range(1<<H):
HR=[0]*H
for h in range(H):
if i & (1<<h)!=0:
HR[h]=1
for j in range(1<<W):
WR=[0]*W
for w in range(W):
if j & (1<<w)!=0:
WR[w]=1
#print(HR,WR)
okflag=1
for h in range(H):
if HR[h]==1:
continue
coinc=0
dif=0
for w in range(W):
if WR[w]==1:
continue
if coinc==0:
coinc=A[h][w]
elif A[h][w]!=coinc:
dif=1
break
if dif==0:
okflag=0
break
if okflag==0:
continue
okflag=1
for w in range(W):
if WR[w]==1:
continue
coinc=0
dif=0
for h in range(H):
if HR[h]==1:
continue
if coinc==0:
coinc=A[h][w]
elif A[h][w]!=coinc:
dif=1
break
if dif==0:
okflag=0
break
if okflag==0:
continue
# HR,WRのうち、0の部分だけを見る.
H0=HR.count(1)
W0=WR.count(1)
#print(H0,W0,HR,WR,ANS)
if H0==H and W0==W:
ANS+=rect(H,W)
else:
ANS+=calc(H0,W0)
ANS%=mod
print(ANS)
``` | instruction | 0 | 31,570 | 7 | 63,140 |
No | output | 1 | 31,570 | 7 | 63,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H \times W grid, where each square is painted white or black in the initial state. Given are strings A_1, A_2, ..., A_H representing the colors of the squares in the initial state. For each pair (i, j) (1 \leq i \leq H, 1 \leq j \leq W), if the j-th character of A_i is `.`, the square at the i-th row and j-th column is painted white; if that character is `#`, that square is painted black.
Among the 2^{HW} ways for each square in the grid to be painted white or black, how many can be obtained from the initial state by performing the operations below any number of times (possibly zero) in any order? Find this count modulo 998,244,353.
* Choose one row, then paint all the squares in that row white.
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column white.
* Choose one column, then paint all the squares in that column black.
Constraints
* 1 \leq H, W \leq 10
* |A_i| = W (1 \leq i \leq H)
* All strings A_i consist of `.` and `#`.
* H and W are integers.
Input
Input is given from Standard Input in the following format:
H W
A_1
A_2
\vdots
A_H
Output
Print the answer.
Examples
Input
2 2
#.
.#
Output
15
Input
2 2
.
.#
Output
15
Input
3 3
...
...
...
Output
230
Input
2 4
...
...#
Output
150
Input
6 7
.......
.......
.#.....
..#....
.#.#...
.......
Output
203949910
Submitted Solution:
```
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
A=[input().strip() for i in range(H)]
mod=998244353
# factorial,facotiralの逆数を事前計算.
FACT=[1]
for i in range(1,30+1):
FACT.append(FACT[-1]*i%mod)
FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(30,0,-1):
FACT_INV.append(FACT_INV[-1]*i%mod)
FACT_INV.reverse()
COMBI=[[-1]*21 for i in range(21)]
def Combi(a,b):
if COMBI[a][b]!=-1:
return COMBI[a][b]
if 0<=b<=a:
COMBI[a][b]=FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
return COMBI[a][b]
else:
COMBI[a][b]=0
return 0
M=max(H,W)+1
RA=[[-1]*M for i in range(M)]
def rect(H,W):
if H==W==0:
return 1
if RA[H][W]!=-1:
return RA[H][W]
DP=[[[0,0] for j in range(W+1)] for i in range(H+1)] # (h,w)の最後に進んだ向きが縦/横のときの場合の数
DP[0][0][0]=1
DP[0][0][1]=1
for h in range(H+1):
for w in range(W+1):
for nexth in range(h+1,H+1):
DP[nexth][w][0]+=DP[h][w][1]*FACT_INV[nexth-h]
DP[nexth][w][0]%=mod
for nextw in range(w+1,W+1):
DP[h][nextw][1]+=DP[h][w][0]*FACT_INV[nextw-w]
DP[h][nextw][1]%=mod
RA[H][W]=RA[W][H]=sum(DP[H][W])*FACT[H]*FACT[W]%mod
return RA[H][W]
CA=[[-1]*(W+1) for i in range(H+1)]
def calc(h,w):
if CA[h][w]!=-1:
return CA[h][w]
RET=0
for bh in range(h+1):
for bw in range(w+1):
RET+=rect(bh,w-bw)*rect(h-bh,bw)*Combi(h,bh)*Combi(w,bw)
#print(bh,bw,w-bw,h-bh,rect(bh,w-bw),rect(h-bh,bw),Combi(h,bh),Combi(w,bw))
RET%=mod
CA[h][w]=RET%mod
return CA[h][w]
ANS=0
for i in range(1<<H):
HR=[0]*H
for h in range(H):
if i & (1<<h)!=0:
HR[h]=1
for j in range(1<<W):
WR=[0]*W
for w in range(W):
if j & (1<<w)!=0:
WR[w]=1
#print(HR,WR)
okflag=1
for h in range(H):
if HR[h]==1:
continue
coinc=0
dif=0
for w in range(W):
if WR[w]==1:
continue
if coinc==0:
coinc=A[h][w]
elif A[h][w]!=coinc:
dif=1
break
if dif==0:
okflag=0
break
if okflag==0:
continue
okflag=1
for w in range(W):
if WR[w]==1:
continue
coinc=0
dif=0
for h in range(H):
if HR[h]==1:
continue
if coinc==0:
coinc=A[h][w]
elif A[h][w]!=coinc:
dif=1
break
if dif==0:
okflag=0
break
if okflag==0:
continue
# HR,WRのうち、0の部分だけを見る.
H0=HR.count(1)
W0=WR.count(1)
#print(H0,W0,HR,WR,ANS)
if H0==H and W0==W:
ANS+=rect(H,W)
else:
ANS+=calc(H0,W0)
ANS%=mod
print(ANS)
``` | instruction | 0 | 31,571 | 7 | 63,142 |
No | output | 1 | 31,571 | 7 | 63,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H \times W grid, where each square is painted white or black in the initial state. Given are strings A_1, A_2, ..., A_H representing the colors of the squares in the initial state. For each pair (i, j) (1 \leq i \leq H, 1 \leq j \leq W), if the j-th character of A_i is `.`, the square at the i-th row and j-th column is painted white; if that character is `#`, that square is painted black.
Among the 2^{HW} ways for each square in the grid to be painted white or black, how many can be obtained from the initial state by performing the operations below any number of times (possibly zero) in any order? Find this count modulo 998,244,353.
* Choose one row, then paint all the squares in that row white.
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column white.
* Choose one column, then paint all the squares in that column black.
Constraints
* 1 \leq H, W \leq 10
* |A_i| = W (1 \leq i \leq H)
* All strings A_i consist of `.` and `#`.
* H and W are integers.
Input
Input is given from Standard Input in the following format:
H W
A_1
A_2
\vdots
A_H
Output
Print the answer.
Examples
Input
2 2
#.
.#
Output
15
Input
2 2
.
.#
Output
15
Input
3 3
...
...
...
Output
230
Input
2 4
...
...#
Output
150
Input
6 7
.......
.......
.#.....
..#....
.#.#...
.......
Output
203949910
Submitted Solution:
```
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
A=[input().strip() for i in range(H)]
mod=998244353
# factorial,facotiralの逆数を事前計算.
FACT=[1]
for i in range(1,30+1):
FACT.append(FACT[-1]*i%mod)
FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(30,0,-1):
FACT_INV.append(FACT_INV[-1]*i%mod)
FACT_INV.reverse()
def Combi(a,b):
if 0<=b<=a:
return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
else:
return 0
def rect(H,W):
if H==W==0:
return 1
DP=[[[0,0] for j in range(W+1)] for i in range(H+1)] # (h,w)の最後に進んだ向きが縦/横のときの場合の数
DP[0][0][0]=1
DP[0][0][1]=1
for h in range(H+1):
for w in range(W+1):
for nexth in range(h+1,H+1):
DP[nexth][w][0]+=DP[h][w][1]*FACT_INV[nexth-h]
DP[nexth][w][0]%=mod
for nextw in range(w+1,W+1):
DP[h][nextw][1]+=DP[h][w][0]*FACT_INV[nextw-w]
DP[h][nextw][1]%=mod
return sum(DP[H][W])*FACT[H]*FACT[W]%mod
def calc(h,w):
RET=0
for bh in range(h+1):
for bw in range(w+1):
RET+=rect(bh,w-bw)*rect(h-bh,bw)*Combi(h,bh)*Combi(w,bw)
#print(bh,bw,w-bw,h-bh,rect(bh,w-bw),rect(h-bh,bw),Combi(h,bh),Combi(w,bw))
RET%=mod
return RET%mod
ANS=0
for i in range(1<<H):
HR=[0]*H
for h in range(H):
if i & (1<<h)!=0:
HR[h]=1
for j in range(1<<W):
WR=[0]*W
for w in range(W):
if j & (1<<w)!=0:
WR[w]=1
#print(HR,WR)
okflag=1
for h in range(H):
if HR[h]==1:
continue
coinc=0
dif=0
for w in range(W):
if WR[w]==1:
continue
if coinc==0:
coinc=A[h][w]
elif A[h][w]!=coinc:
dif=1
break
if dif==0:
okflag=0
break
if okflag==0:
continue
okflag=1
for w in range(W):
if WR[w]==1:
continue
coinc=0
dif=0
for h in range(H):
if HR[h]==1:
continue
if coinc==0:
coinc=A[h][w]
elif A[h][w]!=coinc:
dif=1
break
if dif==0:
okflag=0
break
if okflag==0:
continue
# HR,WRのうち、0の部分だけを見る.
H0=HR.count(1)
W0=WR.count(1)
#print(H0,W0,HR,WR,ANS)
if H0==H and W0==W:
ANS+=rect(H,W)
else:
ANS+=calc(H0,W0)
ANS%=mod
print(ANS)
``` | instruction | 0 | 31,572 | 7 | 63,144 |
No | output | 1 | 31,572 | 7 | 63,145 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H \times W grid, where each square is painted white or black in the initial state. Given are strings A_1, A_2, ..., A_H representing the colors of the squares in the initial state. For each pair (i, j) (1 \leq i \leq H, 1 \leq j \leq W), if the j-th character of A_i is `.`, the square at the i-th row and j-th column is painted white; if that character is `#`, that square is painted black.
Among the 2^{HW} ways for each square in the grid to be painted white or black, how many can be obtained from the initial state by performing the operations below any number of times (possibly zero) in any order? Find this count modulo 998,244,353.
* Choose one row, then paint all the squares in that row white.
* Choose one row, then paint all the squares in that row black.
* Choose one column, then paint all the squares in that column white.
* Choose one column, then paint all the squares in that column black.
Constraints
* 1 \leq H, W \leq 10
* |A_i| = W (1 \leq i \leq H)
* All strings A_i consist of `.` and `#`.
* H and W are integers.
Input
Input is given from Standard Input in the following format:
H W
A_1
A_2
\vdots
A_H
Output
Print the answer.
Examples
Input
2 2
#.
.#
Output
15
Input
2 2
.
.#
Output
15
Input
3 3
...
...
...
Output
230
Input
2 4
...
...#
Output
150
Input
6 7
.......
.......
.#.....
..#....
.#.#...
.......
Output
203949910
Submitted Solution:
```
print('fuck')
``` | instruction | 0 | 31,573 | 7 | 63,146 |
No | output | 1 | 31,573 | 7 | 63,147 |
Provide a correct Python 3 solution for this coding contest problem.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0 | instruction | 0 | 31,590 | 7 | 63,180 |
"Correct Solution:
```
s = str(input())
n = len(s)
dif = 0
for i in range(n):
if s[i] != str(i % 2):
dif += 1
print(min(dif, n - dif))
``` | output | 1 | 31,590 | 7 | 63,181 |
Provide a correct Python 3 solution for this coding contest problem.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0 | instruction | 0 | 31,591 | 7 | 63,182 |
"Correct Solution:
```
S=input()
d0=0
d1=0
for i in range(len(S)):
d0+=int(S[i])!=i%2
d1+=int(S[i])!=(i+1)%2
print(min(d0,d1))
``` | output | 1 | 31,591 | 7 | 63,183 |
Provide a correct Python 3 solution for this coding contest problem.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0 | instruction | 0 | 31,592 | 7 | 63,184 |
"Correct Solution:
```
S=input()
a=0
b=0
for i in range(len(S)):
if int(S[i])==i%2:
a+=1
else:
b+=1
print(min(a,b))
``` | output | 1 | 31,592 | 7 | 63,185 |
Provide a correct Python 3 solution for this coding contest problem.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0 | instruction | 0 | 31,593 | 7 | 63,186 |
"Correct Solution:
```
s = input()
n = len(s)
ans = 0
for i in range(n):
if s[i] == str(i%2):
ans += 1
print(min(ans, n-ans))
``` | output | 1 | 31,593 | 7 | 63,187 |
Provide a correct Python 3 solution for this coding contest problem.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0 | instruction | 0 | 31,594 | 7 | 63,188 |
"Correct Solution:
```
s = input()
n = len(s)
a = s[0::2].count("0")
b = s[1::2].count("0")
print(min((((n+1)//2)-a+b),(a+n//2-b)))
``` | output | 1 | 31,594 | 7 | 63,189 |
Provide a correct Python 3 solution for this coding contest problem.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0 | instruction | 0 | 31,595 | 7 | 63,190 |
"Correct Solution:
```
a=input()
n=len(a)
b="01"*(n//2)+"0"*(n%2)
k=s=0
for i in range(n):
if b[i]==a[i]:s+=1
else: k+=1
print(min(k,s))
``` | output | 1 | 31,595 | 7 | 63,191 |
Provide a correct Python 3 solution for this coding contest problem.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0 | instruction | 0 | 31,596 | 7 | 63,192 |
"Correct Solution:
```
S=input()
c=S[::2].count("0")+S[1::2].count("1")
print(min(c,len(S)-c))
``` | output | 1 | 31,596 | 7 | 63,193 |
Provide a correct Python 3 solution for this coding contest problem.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0 | instruction | 0 | 31,597 | 7 | 63,194 |
"Correct Solution:
```
S = input()
N = len(S)
c1 = S[1::2].count('0')
c2 = S[0::2].count('1')
sum1 = N-c1-c2
sum2 = c1+c2
print(min(sum1,sum2))
``` | output | 1 | 31,597 | 7 | 63,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0
Submitted Solution:
```
s=input()
BW=s[::2]
WB=s[1::2]
x=BW.count("0") + WB.count("1")
y=BW.count("1") + WB.count("0")
print(min(x,y))
``` | instruction | 0 | 31,598 | 7 | 63,196 |
Yes | output | 1 | 31,598 | 7 | 63,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0
Submitted Solution:
```
s = input()
print(min(s[0::2].count("1") + s[1::2].count("0"),
s[0::2].count("0") + s[1::2].count("1")))
``` | instruction | 0 | 31,599 | 7 | 63,198 |
Yes | output | 1 | 31,599 | 7 | 63,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0
Submitted Solution:
```
S = input()
a = S[::2]
b = S[1::2]
A = a.count('0')+b.count('1')
print(min(A,len(S)-A))
``` | instruction | 0 | 31,600 | 7 | 63,200 |
Yes | output | 1 | 31,600 | 7 | 63,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0
Submitted Solution:
```
s = input();x = s[0::2];y = s[1::2]
print(min(x.count('0') + y.count('1'), x.count('1') + y.count('0')))
``` | instruction | 0 | 31,601 | 7 | 63,202 |
Yes | output | 1 | 31,601 | 7 | 63,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0
Submitted Solution:
```
a = input("")
b = list(a)
j = 0;
if (int(b[0])==1 or int(b[0])==0) and len(b) == 1:
print(0)
else:
for i in range(len(b)-1):
if(b[i]==b[i+1]):
if int(b[i]) == 0:
b[i+1] = "1"
else:
b[i+1] = "0"
j = j + 1;
print(j)
``` | instruction | 0 | 31,602 | 7 | 63,204 |
No | output | 1 | 31,602 | 7 | 63,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0
Submitted Solution:
```
import sys
from collections import Counter
input = sys.stdin.readline
h=input()[:-1]
c=Counter(h)
num=min(c["0"],c["1"])
num1=max(c["0"],c["1"])
print(num if num!=0 else num1//2)
``` | instruction | 0 | 31,603 | 7 | 63,206 |
No | output | 1 | 31,603 | 7 | 63,207 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0
Submitted Solution:
```
import sys
#input=sys.stdin.readline
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
s=input()
l=list(s)
l=list(map(int, l))
ans=0
if len(l) > 2:
if l[0] == l[1] and l[0] != l[2]:
ans+=1
if l[0] == 1: l[0] = 0
else: l[0] = 1
for i in range(2, len(s)):
if l[i] == l[i-1] and l[i] != l[i-2]:
ans+=1
if l[i] == 1: l[i] = 0
else: l[i] = 1
elif l[i] == l[i-1] and l[i] == l[i-2]:
ans+=1
if l[i-1] == 1: l[i-1] = 0
else: l[i-1] = 1
print(ans)
``` | instruction | 0 | 31,604 | 7 | 63,208 |
No | output | 1 | 31,604 | 7 | 63,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
At least how many tiles need to be repainted to satisfy the condition?
Constraints
* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum number of tiles that need to be repainted to satisfy the condition.
Examples
Input
000
Output
1
Input
10010010
Output
3
Input
0
Output
0
Submitted Solution:
```
tiles = input()
pair_tiles_list = [tiles[i: i + 2] for i in range(0, len(tiles), 2)]
base_pair = ""
count = 0
if pair_tiles_list.count("01") < pair_tiles_list.count("10"):
base_pair = "10"
else:
base_pair = "01"
for pair in pair_tiles_list:
if pair != base_pair:
if pair[0] != base_pair[0]:
count += 1
if pair.__len__() > 1:
if pair[1] != base_pair[1]:
count += 1
print(count)
``` | instruction | 0 | 31,605 | 7 | 63,210 |
No | output | 1 | 31,605 | 7 | 63,211 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
............. | instruction | 0 | 31,670 | 7 | 63,340 |
"Correct Solution:
```
H, W = map( int, input().split())
V = [ input() for _ in range(H)]
B = [ '' for _ in range(H)]
R = [ '' for _ in range(H)]
N = '#'*(W-1)
for i in range(H):
if i%2 == 0:
B[i] = N+V[i][-1]
R[i] = V[i][:W-1] + '#'
else:
R[i] = V[i][-1] + N
B[i] = '#' + V[i][1:]
for i in range(H):
print(B[i])
print('')
for i in range(H):
print(R[i])
``` | output | 1 | 31,670 | 7 | 63,341 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
............. | instruction | 0 | 31,671 | 7 | 63,342 |
"Correct Solution:
```
h,w=map(int,input().split());r=[list('#'+'#.'[i%2]*(w-2)+'.')for i in range(h)];b=[list('.'+'.#'[i%2]*(w-2)+'#')for i in range(h)]
for i in range(h):
t=input()
for j in range(w):
if t[j]=='#':r[i][j]=b[i][j]='#'
for t in r:print(''.join(t))
print()
for t in b:print(''.join(t))
``` | output | 1 | 31,671 | 7 | 63,343 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
............. | instruction | 0 | 31,672 | 7 | 63,344 |
"Correct Solution:
```
h, w= map(int, input().split())
a = [['.']*w for _ in range(h)]
b = [['.']*w for _ in range(h)]
for i in range(h):
s = input()
for j in range(w):
if i % 2 and j != w - 1 or j == 0 or s[j] == '#':
a[i][j] = '#'
if (i+1) % 2 and j != 0 or j == w - 1 or s[j] == '#':
b[i][j] = '#'
for x in a + [[]] + b :
print(''.join(x))
``` | output | 1 | 31,672 | 7 | 63,345 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
............. | instruction | 0 | 31,673 | 7 | 63,346 |
"Correct Solution:
```
H, W = map(int, input().split())
A = []
for i in range(H):
A.append(input())
red = [["." for w in range(W)] for _ in range(H)]
blue = [["." for w in range(W)] for _ in range(H)]
for i in range(H):
if i % 2 == 0:
red[i] = ["#" for w in range(W)]
red[i][-1] = "."
else:
red[i][0] = "#"
for i in range(H):
if i % 2 == 0:
blue[i][-1] = "#"
else:
blue[i] = ["#" for w in range(W)]
blue[i][0] = "."
for i in range(H):
for j in range(W):
if A[i][j] == '#':
red[i][j] = "#"
blue[i][j] = "#"
for i in range(H):
print("".join(red[i]))
print("")
for i in range(H):
print("".join(blue[i]))
``` | output | 1 | 31,673 | 7 | 63,347 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
............. | instruction | 0 | 31,674 | 7 | 63,348 |
"Correct Solution:
```
#!/usr/bin/env python3
import copy
h, w = map(int, input().split())
f = [ list(input()) for _ in range(h) ]
a = copy.deepcopy(f)
b = copy.deepcopy(f)
a[0] = '#' * w
for y in range(1, h - 1):
for x in range(w):
[a, b][x % 2][y][x] = '#'
b[h - 1] = '#' * w
print(*map(''.join, a), sep='\n')
print()
print(*map(''.join, b), sep='\n')
``` | output | 1 | 31,674 | 7 | 63,349 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
............. | instruction | 0 | 31,675 | 7 | 63,350 |
"Correct Solution:
```
h, w = map(int, input().split())
G = [input() for _ in range(h)]
R = [["."]*w for _ in range(h)]
B = [["."]*w for _ in range(h)]
for i in range(1, h-1):
if i%2:
R[i] = list("." + "#"*(w-2) + ".")
B[i] = list(G[i])
else:
B[i] = list("." + "#"*(w-2) + ".")
R[i] = list(G[i])
for i in range(h):
R[i][0] = "#"
B[i][-1] = "#"
for r in R:
print("".join(r))
print()
for b in B:
print("".join(b))
``` | output | 1 | 31,675 | 7 | 63,351 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
............. | instruction | 0 | 31,676 | 7 | 63,352 |
"Correct Solution:
```
h,w = map(int,input().split())
grid = [list(input()) for i in range(h)]
black = [[1 for i in range(w)] for j in range(h)]
white = [[1 for i in range(w)] for j in range(h)]
for i in range(h):
for j in range(w):
if i%2 and j%2 == 0:
black[i][j] = 0
elif i%2 == 0 and j%2:
white[i][j] = 0
for i in range(h):
for j in range(w):
if grid[i][j] == "#":
black[i][j] = 1
white[i][j] = 1
else:
if i%2 == 0:
white[i][j] = 0
else:
black[i][j] = 0
for i in range(h):
black[i][0] = 0
black[i][w-1] = 1
white[i][0] = 1
white[i][w-1] = 0
for i in range(w):
black[0][i] = 1
black[h-1][i] = 0
white[0][i] = 0
white[h-1][i] = 1
for i in range(h):
for j in range(w):
if black[i][j]:
print("#",end="")
else:
print(".",end="")
print()
print()
for i in range(h):
for j in range(w):
if white[i][j]:
print("#",end="")
else:
print(".",end="")
print()
``` | output | 1 | 31,676 | 7 | 63,353 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
............. | instruction | 0 | 31,677 | 7 | 63,354 |
"Correct Solution:
```
H, W = map(int, input().split())
lines = [input() for _ in range(H)]
rs = [list("#" + (W-2) * ("#" if i%2==0 else ".") + ".") for i in range(H)]
bs = [list("." + (W-2) * ("#" if i%2==1 else ".") + "#") for i in range(H)]
for i, line in enumerate(lines):
for j, c in enumerate(line):
if c=="#":
rs[i][j] = "#"
bs[i][j] = "#"
print("\n".join(["".join(r) for r in rs]), end="\n"*2)
print("\n".join(["".join(b) for b in bs]), end="\n"*2)
``` | output | 1 | 31,677 | 7 | 63,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
.............
Submitted Solution:
```
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
h,w = LI()
a = [input() for i in range(h)]
r = [list("#"+"."*(w-1)) for i in range(h)]
b = [list("."*(w-1)+"#") for i in range(h)]
for i in range(h):
if i&1:
r[i] = list("#"*(w-1)+".")
else:
b[i] = list("."+"#"*(w-1))
for i in range(h):
for j in range(w):
if a[i][j] == "#":
r[i][j] = "#"
b[i][j] = "#"
for i in r:
print(*i,sep = "")
print()
for i in b:
print(*i,sep = "")
return
#Solve
if __name__ == "__main__":
solve()
``` | instruction | 0 | 31,678 | 7 | 63,356 |
Yes | output | 1 | 31,678 | 7 | 63,357 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
.............
Submitted Solution:
```
H,W = list(map(int,input().split()))
a = [input() for i in range(H)]
b = [[] for i in range(H)]
r = [[] for i in range(H)]
for i in range(H):
for j in range(W):
if i==0:
b[i].append("#")
r[i].append(".")
elif i==H-1:
b[i].append(".")
r[i].append("#")
elif a[i][j]=="#":
b[i].append("#")
r[i].append("#")
elif j%2==0:
b[i].append(".")
r[i].append("#")
elif j%2==1:
b[i].append("#")
r[i].append(".")
for i in range(H):
ans = ""
for j in range(W):
ans = ans+b[i][j]
print(ans)
print("")
for i in range(H):
ans = ""
for j in range(W):
ans = ans+r[i][j]
print(ans)
``` | instruction | 0 | 31,679 | 7 | 63,358 |
Yes | output | 1 | 31,679 | 7 | 63,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
.............
Submitted Solution:
```
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
b=[["." for i in range(W)] for i in range(H)]
c=[["." for i in range(W)] for i in range(H)]
for i in range(H):
c[i][0]="#"
b[i][-1]="#"
for i in range(H):
for j in range(W):
if i%2==0:
b[i][j]="#"
else:
c[i][j]="#"
for i in range(H):
c[i][-1]="."
b[i][0]="."
for i in range(H):
for j in range(W):
if a[i][j]=="#":
b[i][j]="#"
c[i][j]="#"
for i in b:
print("".join(i))
print()
for i in c:
print("".join(i))
``` | instruction | 0 | 31,680 | 7 | 63,360 |
Yes | output | 1 | 31,680 | 7 | 63,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
.............
Submitted Solution:
```
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
H, W = getlist()
L = []
for i in range(H):
l = list(input())
L.append(l)
redTable = [["."] * W for i in range(H)]
blueTable = [["."] * W for i in range(H)]
for i in range(H):
redTable[i][0] = "#"
blueTable[i][-1] = "#"
for i in range(H):
if i % 2 == 0:
for j in range(1, W - 1):
redTable[i][j] = "#"
else:
for j in range(1, W - 1):
blueTable[i][j] = "#"
# for i in range(H):
# print(*redTable[i])
# print()
# for i in range(H):
# print(*blueTable[i])
for i in range(H):
for j in range(1, W - 1):
if L[i][j] == "#":
if i % 2 == 0:
blueTable[i][j] = "#"
else:
redTable[i][j] = "#"
for i in range(H):
print("".join(redTable[i]))
print()
for i in range(H):
print("".join(blueTable[i]))
if __name__ == '__main__':
main()
``` | instruction | 0 | 31,681 | 7 | 63,362 |
Yes | output | 1 | 31,681 | 7 | 63,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
.............
Submitted Solution:
```
H,W = list(map(int,input().split()))
a = [input() for i in range(H)]
b = [[] for i in range(H)]
r = [[] for i in range(H)]
for i in range(H):
for j in range(W):
if i==0:
b[i].append("#")
r[i].append(".")
elif i==H-1:
b[i].append(".")
r[i].append("#")
elif S[i][j]=="#":
b[i].append(".")
r[i].append("#")
elif j%2==0:
b[i].append(".")
r[i].append("#")
elif j%2==1:
b[i].append("#")
r[i].append(".")
for i in range(H):
ans = ""
for j in range(W):
ans = ans+b[i][j]
print(ans)
print("")
for i in range(H):
ans = ""
for j in range(W):
ans = ans+r[i][j]
print(ans)
``` | instruction | 0 | 31,682 | 7 | 63,364 |
No | output | 1 | 31,682 | 7 | 63,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
.............
Submitted Solution:
```
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
ta = [["."] * w for i in range(h)]
ao = [["."] * w for i in range(h)]
for i in range(h):
if i % 2 == 0:
for j in range(w):
ta[i][j] = "#"
ao[i][-1] = "#"
else:
for j in range(w):
ao[i][j] = "#"
ta[i][0] = "#"
for i in range(h):
for j in range(w):
if a[i][j] == "#":
ta[i][j] = "#"
ao[i][j] = "#"
for i in range(h):
print(*ta[i])
print()
for i in range(h):
print(*ao[i])
``` | instruction | 0 | 31,683 | 7 | 63,366 |
No | output | 1 | 31,683 | 7 | 63,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
.............
Submitted Solution:
```
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
b=[["." for i in range(W)] for i in range(H)]
c=[["." for i in range(W)] for i in range(H)]
for i in range(H):
c[i][0]="#"
b[i][-1]="#"
for i in range(H):
for j in range(W):
if i%2==0:
b[i][j]="#"
else:
c[i][j]="#"
for i in range(H):
for j in range(W):
if a[i][j]=="#":
b[i][j]="#"
c[i][j]="#"
for i in b:
print("".join(i))
print()
for i in c:
print("".join(i))
``` | instruction | 0 | 31,684 | 7 | 63,368 |
No | output | 1 | 31,684 | 7 | 63,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.
Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.
Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.
You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is `#`, otherwise a_{ij} is `.`. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is `.`.
Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.
Constraints
* 3≤H,W≤500
* a_{ij} is `#` or `.`.
* If i=1,H or j=1,W, then a_{ij} is `.`.
* At least one of a_{ij} is `#`.
Input
The input is given from Standard Input in the following format:
H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}
Output
Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:
* The first H lines should describe the positions of the red cells.
* The following 1 line should be empty.
* The following H lines should describe the positions of the blue cells.
The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.
Examples
Input
5 5
.....
.#.#.
.....
.#.#.
.....
Output
.....
#####
#....
#####
.....
.###.
.#.#.
.#.#.
.#.#.
.....
Input
7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............
Output
.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
.............
Submitted Solution:
```
h, w = map(int, input().split())
A = [input() for _ in range(h)]
up = h-1
down = 0
left = w-1
right = 0
for i in range(h):
if "#" in A[i]:
up = min(i, up)
down = max(i, down)
left = min(A[i].find("#"), left)
right = max(A[i].rfind("#"), right)
for i in range(h):
if i < up or i > down:
print("#" * w)
else:
print("#" * left + A[i][left:right+1] + "#" * (w-1-right))
print()
for i in range(h):
if i < up or i > down:
print("." * w)
else:
print("." * left + "#" * (right-left+1) + "." * (w-1-right))
``` | instruction | 0 | 31,685 | 7 | 63,370 |
No | output | 1 | 31,685 | 7 | 63,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joseph really likes the culture of Japan. Last year he learned Japanese traditional clothes and visual arts and now he is trying to find out the secret of the Japanese game called Nonogram.
In the one-dimensional version of the game, there is a row of n empty cells, some of which are to be filled with a pen. There is a description of a solution called a profile — a sequence of positive integers denoting the lengths of consecutive sets of filled cells. For example, the profile of [4, 3, 1] means that there are sets of four, three, and one filled cell, in that order, with at least one empty cell between successive sets.
<image>
A suitable solution for n = 12 and p = [4, 3, 1].
<image>
A wrong solution: the first four filled cells should be consecutive.
<image>
A wrong solution: there should be at least one empty cell before the last filled cell.
Joseph found out that for some numbers n and profiles p there are lots of ways to fill the cells to satisfy the profile. Now he is in the process of solving a nonogram consisting of n cells and a profile p. He has already created a mask of p — he has filled all the cells that must be filled in every solution of the nonogram.
<image>
The mask for n = 12 and p = [4, 3, 1]: all the filled cells above are filled in every solution.
After a break, he lost the source profile p. He only has n and the mask m. Help Joseph find any profile p' with the mask m or say that there is no such profile and Joseph has made a mistake.
Input
The only line contains a string m — the mask of the source profile p. The length of m is n (1 ≤ n ≤ 100 000). The string m consists of symbols # and _ — denoting filled and empty cells respectively.
Output
If there is no profile with the mask m, output the number -1. Otherwise, on the first line, output an integer k — the number of integers in the profile p'. On the second line, output k integers of the profile p'.
Examples
Input
__#_____
Output
2
3 2
Input
_#
Output
-1
Input
___
Output
0
Submitted Solution:
```
k = input()
arr = []
black = 0
total = 0
lis = []
lis_2 = []
out = []
found = True
for i in k:
if i == "_":
arr.append(0)
elif i == "#":
arr.append(1)
for i in range(len(arr)):
if arr[i] == 0:
total += 1
found = False
elif i == len(arr) - 1 and arr[i] == 1:
black += 1
total += 1
if len(lis) != 0:
lis.append([total - 1,black])
else:
lis.append([total,black])
found = True
elif arr[i] == 1 and arr[i + 1] == 1:
black += 1
total += 1
elif arr[i] == 1 and arr[i + 1] == 0:
black += 1
total += 1
if len(lis) == 0:
lis.append([total,black])
else:
lis.append([total - 1,black])
total = 0
black = 0
found = True
if i == len(arr) - 1 and found == False:
if total == 1 and len(lis) == 0:
lis.append([1,0])
elif total > 1:
lis.append([total - 1,0])
remainder = lis[0][0] - lis[0][1]
for position in range(1,len(lis)):
if lis[position][1] != 0:
iter = lis[position][0] - lis[position][1]
if remainder > iter:
remainder = iter
for i in lis:
if i[1] + remainder == i[0]:
out.append(i[0])
elif i[1] + remainder < i[0]:
new = i[0] - i[1] - remainder#剩余的数
if new / (remainder + 1) - new // (remainder + 1) > 0:
new_1 = new // (remainder + 1) + 1
else:
new_1 = new // (remainder + 1)
#可以分配几组凑数组
new_2 = new - new_1#将new_2分配到new_1组 中
while new_2 > 0:
if new_2 > remainder:
out.append(remainder)
new_2 = new_2 - remainder
else:
out.append(new_2)
new_2 = new_2 - new_2
out.append(i[1] + remainder)
if arr.count(1) == 0:
print("0")
print("")
elif len(arr) - sum(out) - len(out) + 1 != remainder:
print("-1")
else:
print(len(out))
for i in out:
print(i,end = " ")
``` | instruction | 0 | 31,984 | 7 | 63,968 |
No | output | 1 | 31,984 | 7 | 63,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joseph really likes the culture of Japan. Last year he learned Japanese traditional clothes and visual arts and now he is trying to find out the secret of the Japanese game called Nonogram.
In the one-dimensional version of the game, there is a row of n empty cells, some of which are to be filled with a pen. There is a description of a solution called a profile — a sequence of positive integers denoting the lengths of consecutive sets of filled cells. For example, the profile of [4, 3, 1] means that there are sets of four, three, and one filled cell, in that order, with at least one empty cell between successive sets.
<image>
A suitable solution for n = 12 and p = [4, 3, 1].
<image>
A wrong solution: the first four filled cells should be consecutive.
<image>
A wrong solution: there should be at least one empty cell before the last filled cell.
Joseph found out that for some numbers n and profiles p there are lots of ways to fill the cells to satisfy the profile. Now he is in the process of solving a nonogram consisting of n cells and a profile p. He has already created a mask of p — he has filled all the cells that must be filled in every solution of the nonogram.
<image>
The mask for n = 12 and p = [4, 3, 1]: all the filled cells above are filled in every solution.
After a break, he lost the source profile p. He only has n and the mask m. Help Joseph find any profile p' with the mask m or say that there is no such profile and Joseph has made a mistake.
Input
The only line contains a string m — the mask of the source profile p. The length of m is n (1 ≤ n ≤ 100 000). The string m consists of symbols # and _ — denoting filled and empty cells respectively.
Output
If there is no profile with the mask m, output the number -1. Otherwise, on the first line, output an integer k — the number of integers in the profile p'. On the second line, output k integers of the profile p'.
Examples
Input
__#_____
Output
2
3 2
Input
_#
Output
-1
Input
___
Output
0
Submitted Solution:
```
s = input()
if '#' in s:
k = s.count('#') + 1
p = []
while '#' in s:
i = s.find('#')
p.append(i+1)
s = s[i+1:]
p.append(len(s) - p[0])
for i in p:
if i <= 0:
k = -1
else:
k = 0
if k > 0:
print(k)
for i in p:
print(i, end=' ')
else:
print(k)
``` | instruction | 0 | 31,985 | 7 | 63,970 |
No | output | 1 | 31,985 | 7 | 63,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joseph really likes the culture of Japan. Last year he learned Japanese traditional clothes and visual arts and now he is trying to find out the secret of the Japanese game called Nonogram.
In the one-dimensional version of the game, there is a row of n empty cells, some of which are to be filled with a pen. There is a description of a solution called a profile — a sequence of positive integers denoting the lengths of consecutive sets of filled cells. For example, the profile of [4, 3, 1] means that there are sets of four, three, and one filled cell, in that order, with at least one empty cell between successive sets.
<image>
A suitable solution for n = 12 and p = [4, 3, 1].
<image>
A wrong solution: the first four filled cells should be consecutive.
<image>
A wrong solution: there should be at least one empty cell before the last filled cell.
Joseph found out that for some numbers n and profiles p there are lots of ways to fill the cells to satisfy the profile. Now he is in the process of solving a nonogram consisting of n cells and a profile p. He has already created a mask of p — he has filled all the cells that must be filled in every solution of the nonogram.
<image>
The mask for n = 12 and p = [4, 3, 1]: all the filled cells above are filled in every solution.
After a break, he lost the source profile p. He only has n and the mask m. Help Joseph find any profile p' with the mask m or say that there is no such profile and Joseph has made a mistake.
Input
The only line contains a string m — the mask of the source profile p. The length of m is n (1 ≤ n ≤ 100 000). The string m consists of symbols # and _ — denoting filled and empty cells respectively.
Output
If there is no profile with the mask m, output the number -1. Otherwise, on the first line, output an integer k — the number of integers in the profile p'. On the second line, output k integers of the profile p'.
Examples
Input
__#_____
Output
2
3 2
Input
_#
Output
-1
Input
___
Output
0
Submitted Solution:
```
s = input()
if '#' in s:
k = s.count('#') + 1
p = []
while '#' in s:
i = s.find('#')
p.append(i+1)
s = s[i+1:]
p.append(len(s) - p[0])
for i in p:
if i <= 0:
k = -1
else:
k = -1
if k > 0:
print(k)
for i in p:
print(i, end=' ')
else:
print(k)
``` | instruction | 0 | 31,986 | 7 | 63,972 |
No | output | 1 | 31,986 | 7 | 63,973 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joseph really likes the culture of Japan. Last year he learned Japanese traditional clothes and visual arts and now he is trying to find out the secret of the Japanese game called Nonogram.
In the one-dimensional version of the game, there is a row of n empty cells, some of which are to be filled with a pen. There is a description of a solution called a profile — a sequence of positive integers denoting the lengths of consecutive sets of filled cells. For example, the profile of [4, 3, 1] means that there are sets of four, three, and one filled cell, in that order, with at least one empty cell between successive sets.
<image>
A suitable solution for n = 12 and p = [4, 3, 1].
<image>
A wrong solution: the first four filled cells should be consecutive.
<image>
A wrong solution: there should be at least one empty cell before the last filled cell.
Joseph found out that for some numbers n and profiles p there are lots of ways to fill the cells to satisfy the profile. Now he is in the process of solving a nonogram consisting of n cells and a profile p. He has already created a mask of p — he has filled all the cells that must be filled in every solution of the nonogram.
<image>
The mask for n = 12 and p = [4, 3, 1]: all the filled cells above are filled in every solution.
After a break, he lost the source profile p. He only has n and the mask m. Help Joseph find any profile p' with the mask m or say that there is no such profile and Joseph has made a mistake.
Input
The only line contains a string m — the mask of the source profile p. The length of m is n (1 ≤ n ≤ 100 000). The string m consists of symbols # and _ — denoting filled and empty cells respectively.
Output
If there is no profile with the mask m, output the number -1. Otherwise, on the first line, output an integer k — the number of integers in the profile p'. On the second line, output k integers of the profile p'.
Examples
Input
__#_____
Output
2
3 2
Input
_#
Output
-1
Input
___
Output
0
Submitted Solution:
```
masks = []
for x in input().strip():
if x == "#":
masks.append(1)
else:
masks.append(0)
n = len(masks)
if sum(masks) == n: # all sqaures are mask
print(n)
elif sum(masks) == 0: # all squares are unmask
print(0)
else:
p = []
current = 0
is_prev_mask = False
for m in masks:
if m == 1:
current += 1
is_prev_mask = True
elif is_prev_mask:
p.append(current)
is_prev_mask = False
current = 0
else:
current += 1
if current > 0:
if is_prev_mask:
p.append(current)
else:
p.append(1)
if sum(p) < n / 2:
print(-1)
else:
print(len(p))
print(*p)
``` | instruction | 0 | 31,987 | 7 | 63,974 |
No | output | 1 | 31,987 | 7 | 63,975 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized n × m, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
* 'C' (cyan)
* 'M' (magenta)
* 'Y' (yellow)
* 'W' (white)
* 'G' (grey)
* 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively.
Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
Examples
Input
2 2
C M
Y Y
Output
#Color
Input
3 2
W W
W W
B B
Output
#Black&White
Input
1 1
W
Output
#Black&White | instruction | 0 | 32,116 | 7 | 64,232 |
Tags: implementation
Correct Solution:
```
s=""
n,m=map(int,input().split())
for i in range(n):
s+=input()
if "C" in s or "M" in s or "Y" in s:
print("#Color")
else:
print("#Black&White")
``` | output | 1 | 32,116 | 7 | 64,233 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized n × m, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
* 'C' (cyan)
* 'M' (magenta)
* 'Y' (yellow)
* 'W' (white)
* 'G' (grey)
* 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively.
Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
Examples
Input
2 2
C M
Y Y
Output
#Color
Input
3 2
W W
W W
B B
Output
#Black&White
Input
1 1
W
Output
#Black&White | instruction | 0 | 32,117 | 7 | 64,234 |
Tags: implementation
Correct Solution:
```
n,m=map(int,input().split())
A=[]
for i in range(n):
A.append(list(input().split()))
color=False
for i in range(n):
if 'C' in A[i] or 'M' in A[i] or 'Y' in A[i]:
color=True
break
if color:
print('#Color')
else:
print('#Black&White')
``` | output | 1 | 32,117 | 7 | 64,235 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized n × m, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
* 'C' (cyan)
* 'M' (magenta)
* 'Y' (yellow)
* 'W' (white)
* 'G' (grey)
* 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively.
Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
Examples
Input
2 2
C M
Y Y
Output
#Color
Input
3 2
W W
W W
B B
Output
#Black&White
Input
1 1
W
Output
#Black&White | instruction | 0 | 32,118 | 7 | 64,236 |
Tags: implementation
Correct Solution:
```
n,m=map(int,input().split())
a=0
for i in range(n):
l=list(map(str,input().split()))
for j in range(len(l)):
if l[j]=='C' or l[j]=='M' or l[j]=='Y' :
a=a+1
if a==0:
print( "#Black&White")
else:
print("#Color")
``` | output | 1 | 32,118 | 7 | 64,237 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.