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.
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.
Can you win the prize? Hurry up, the bags are waiting!
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles.
Output
Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.
Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
Note
The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible. | instruction | 0 | 41,290 | 7 | 82,580 |
Tags: constructive algorithms, greedy, math, number theory
Correct Solution:
```
N = int(input())
num_ones = input().count('1')
num_twos = N - num_ones
if not num_ones or not num_twos:
solutionn = [1] * num_ones + [2] * num_twos
else:
solutionn = [2, 1] + [2] * (num_twos - 1) + [1] * (num_ones - 1)
print(*solutionn)
``` | output | 1 | 41,290 | 7 | 82,581 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.
Can you win the prize? Hurry up, the bags are waiting!
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles.
Output
Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.
Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
Note
The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible. | instruction | 0 | 41,291 | 7 | 82,582 |
Tags: constructive algorithms, greedy, math, number theory
Correct Solution:
```
n = int(input())
m = list(map(int,input().split()))
c1 = m.count(1)
c2 = m.count(2)
if(c2 > 0):
print(2,end = ' ')
if(c1 > 0):
print(1,end = ' ')
for i in range(c2-1):
print(2,end = ' ')
for i in range(c1-1):
print(1,end = ' ')
print()
``` | output | 1 | 41,291 | 7 | 82,583 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.
Can you win the prize? Hurry up, the bags are waiting!
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles.
Output
Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.
Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
Note
The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
Submitted Solution:
```
n = int(input())
c = input().split()
if '2' in c:
del c[c.index('2')]
print('2',end = ' ')
if '1' in c:
del c[c.index('1')]
print('1', end=' ')
c.sort(reverse=True)
print(' '.join(c))
``` | instruction | 0 | 41,292 | 7 | 82,584 |
Yes | output | 1 | 41,292 | 7 | 82,585 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.
Can you win the prize? Hurry up, the bags are waiting!
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles.
Output
Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.
Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
Note
The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
Submitted Solution:
```
from collections import Counter
n = int(input())
l = list(map(int, input().split()))
c = Counter(l)
if 1 in c and 2 in c:
ans = [2, 1] + [2]*(c[2]-1) + [1]*(c[1]-1)
else:
ans = l
print(*ans)
``` | instruction | 0 | 41,293 | 7 | 82,586 |
Yes | output | 1 | 41,293 | 7 | 82,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.
Can you win the prize? Hurry up, the bags are waiting!
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles.
Output
Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.
Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
Note
The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
cnt1 = 0
for x in a:
if x == 1:
cnt1 += 1
cnt2 = n - cnt1
if n == 1:
print(*a)
else:
if cnt1 == 0 or cnt2 == 0:
print(*a)
else:
print("2 1", end=" ")
cnt1 -= 1
cnt2 -= 1
print("2 " * cnt2, end="")
print("1 " * cnt1)
``` | instruction | 0 | 41,294 | 7 | 82,588 |
Yes | output | 1 | 41,294 | 7 | 82,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.
Can you win the prize? Hurry up, the bags are waiting!
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles.
Output
Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.
Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
Note
The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
Submitted Solution:
```
# ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
from collections import Counter
if __name__ == "__main__":
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
s = []
if c[2] > 0:
s.append(2)
c[2] -= 1
elif c[1] >= 2:
s.append(1)
s.append(1)
c[1] -= 2
if c[1]%2 == 0:
for i in range(c[1]-1):
s.append(1)
if c[1] != 0:
c[1] = 1
else:
for i in range(c[1]):
s.append(1)
c[1] = 0
for i in range(c[2]):
s.append(2)
if c[1] == 1:
s.append(1)
s = list(map(str,s))
print(' '.join(s))
``` | instruction | 0 | 41,295 | 7 | 82,590 |
Yes | output | 1 | 41,295 | 7 | 82,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.
Can you win the prize? Hurry up, the bags are waiting!
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles.
Output
Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.
Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
Note
The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
Submitted Solution:
```
n = int(input())
a = input().count("1")
b = n - a
if a == 0:
print("2 " * n)
elif b == 0:
print("1 " * n)
elif a == 1:
print("1 " + "2 " * (n - 1))
elif b == 1:
print("1 2 " + "1 " * (n - 2))
elif a == 2:
print("1 " + "2 " * (n - 2) + "1 ")
else:
print("1 1 1 " + "2 " * b + "1 " * (a - 3))
``` | instruction | 0 | 41,296 | 7 | 82,592 |
No | output | 1 | 41,296 | 7 | 82,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.
Can you win the prize? Hurry up, the bags are waiting!
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles.
Output
Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.
Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
Note
The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
Submitted Solution:
```
n = int(input())
a = input().count("1")
b = n - a
if a == 0:
print("2 " * n)
elif b == 0:
print("1 " * n)
elif a == 1:
print("2 1 " + "2 " * (n - 2))
elif a == 2:
print("1 " + "2 " * (n - 2) + "1 ")
else:
print("1 1 1 " + "2 " * b + "1 " * (a - 3))
``` | instruction | 0 | 41,297 | 7 | 82,594 |
No | output | 1 | 41,297 | 7 | 82,595 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.
Can you win the prize? Hurry up, the bags are waiting!
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles.
Output
Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.
Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
Note
The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
Submitted Solution:
```
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
v=[]
if c[1]:
v=[1]
c[1]-=1
if c[2]:
v.append(2)
c[2]-=1
while(c[2]!=0):
v.append(2)
c[2]-=1
while(c[1]):
v.append(1)
c[1]-=1
print(*v)
``` | instruction | 0 | 41,298 | 7 | 82,596 |
No | output | 1 | 41,298 | 7 | 82,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.
Can you win the prize? Hurry up, the bags are waiting!
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of number tiles in the bag. The following line contains n space-separated integers a_1, a_2, ..., a_n (a_i ∈ \{1, 2\}) — the values written on the tiles.
Output
Output a permutation b_1, b_2, ..., b_n of the input sequence (a_1, a_2, ..., a_n) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.
Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
Note
The first solution produces the prefix sums 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}} (four primes constructed), while the prefix sums in the second solution are 1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}} (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.
Submitted Solution:
```
# ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
from collections import Counter
if __name__ == "__main__":
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
s = []
if c[2] > 0:
s.append(2)
c[2] -= 1
elif c[1] >= 2:
s.append(1)
s.append(1)
c[1] -= 2
if c[1]%2 == 0:
for i in range(c[1]-1):
s.append(1)
if c[1] != 0:
c[1] = 1
else:
for i in range(c[1]):
s.append(1)
for i in range(c[2]):
s.append(2)
if c[1] == 1:
s.append(1)
s = list(map(str,s))
print(' '.join(s))
``` | instruction | 0 | 41,299 | 7 | 82,598 |
No | output | 1 | 41,299 | 7 | 82,599 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image> | instruction | 0 | 41,413 | 7 | 82,826 |
Tags: greedy, math
Correct Solution:
```
for _ in range(int(input())):
#int(input())
n,m=list(map(int,input().strip().split()))
z=n*m
if z%2==0:
print(z//2)
else:
print(z//2+1)
``` | output | 1 | 41,413 | 7 | 82,827 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image> | instruction | 0 | 41,414 | 7 | 82,828 |
Tags: greedy, math
Correct Solution:
```
def park_lighting():
rows_columns = list(map(int,input().split()))
cells = rows_columns[0]*rows_columns[1]
if cells % 2 ==0:
number_of_lights = cells/2
else:
number_of_lights = (cells+1)/2
print(int(number_of_lights))
def main():
for case in range(int(input())):
park_lighting()
main()
``` | output | 1 | 41,414 | 7 | 82,829 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image> | instruction | 0 | 41,415 | 7 | 82,830 |
Tags: greedy, math
Correct Solution:
```
for _ in range(int(input())):
n, m = map(int, input().split())
if (n * m) & 1:
print(n * m // 2 + 1)
else:
print(n * m // 2)
``` | output | 1 | 41,415 | 7 | 82,831 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image> | instruction | 0 | 41,416 | 7 | 82,832 |
Tags: greedy, math
Correct Solution:
```
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
print((n * m) // 2 + (n * m) % 2)
``` | output | 1 | 41,416 | 7 | 82,833 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image> | instruction | 0 | 41,417 | 7 | 82,834 |
Tags: greedy, math
Correct Solution:
```
t = int(input())
while t != 0:
n, m = map(int, input().split())
if n == 1:
if m == 1:
print(1)
elif m % 2 == 0:
print(m // 2)
else:
print(m // 2 + 1)
t -= 1
continue
elif m == 1:
if n == 1:
print(1)
elif n % 2 == 0:
print(n // 2)
else:
print(n // 2 + 1)
t -= 1
continue
elif (n % 2 == 0):
print(n // 2 * m)
elif (m % 2 == 0):
print(m // 2 * n)
else:
print((n - 1) // 2 * m + m // 2 + 1)
t -= 1
``` | output | 1 | 41,417 | 7 | 82,835 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image> | instruction | 0 | 41,418 | 7 | 82,836 |
Tags: greedy, math
Correct Solution:
```
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineerin College
Date:26/05/2020
'''
import sys
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def read():
tc=0
if tc:
input=sys.stdin.readline
else:
sys.stdin=open('input1.txt', 'r')
sys.stdout=open('output1.txt','w')
def solve():
for _ in range(ii()):
n,m=mi()
print(n*(m//2)+(m%2)*ceil(n/2))
if __name__ =="__main__":
# read()
solve()
``` | output | 1 | 41,418 | 7 | 82,837 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image> | instruction | 0 | 41,419 | 7 | 82,838 |
Tags: greedy, math
Correct Solution:
```
t=int(input())
for i in range (t):
a=[]
a=list(map(int, input().split()))
b=a[0]//2*a[1]
if a[0]%2==1:
b+=a[1]//2+a[1]%2
print(b)
``` | output | 1 | 41,419 | 7 | 82,839 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image> | instruction | 0 | 41,420 | 7 | 82,840 |
Tags: greedy, math
Correct Solution:
```
for _ in range(int(input())):
n,m=map(int,input().split())
p=max(n,m)
q=min(n,m)
if p%2==0:
print((p//2)*q)
else:
print((p//2)*q+(q+1)//2)
``` | output | 1 | 41,420 | 7 | 82,841 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image>
Submitted Solution:
```
from math import ceil
for k in range(int(input())):
n, m = list(map(int, input().split()))
print(ceil((n*m)/2))
``` | instruction | 0 | 41,421 | 7 | 82,842 |
Yes | output | 1 | 41,421 | 7 | 82,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image>
Submitted Solution:
```
t = int(input())
for _ in range(t):
a,b = map(int,input().split())
if b>a:
a,b = b,a
if a>=b:
if a%2 == 0 and b%2 ==0:
ans = (a//2)*b
elif a%2 != 0 and b%2 == 0:
ans = (a//2)*b + b//2
elif a%2 == 0 and b%2 != 0:
ans = (a//2)*b
else:
ans = (a//2)*b + (b//2)+1
print(ans)
``` | instruction | 0 | 41,422 | 7 | 82,844 |
Yes | output | 1 | 41,422 | 7 | 82,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image>
Submitted Solution:
```
from collections import defaultdict
import sys
import math
sys.setrecursionlimit(1000000) #设置最大递归深度
int1 = lambda x: int(x) - 1 #返回x-1
p2D = lambda x: print(*x, sep="\n") #输出多个元素,以换行符分割
p2S = lambda x: print(*x, sep=" ") #输出多个元素,以空格分割
def II(): return int(sys.stdin.readline()) #读一行(仅一个)整数
def MI(): return map(int, sys.stdin.readline().split()) #读一行数据,转化为int型元组
def LI(): return list(map(int, sys.stdin.readline().split())) #读一行数据,转化为int型列表
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1] #读一行字符串,舍掉换行符
def main():
for _ in range(II()):
a,b=MI()
print(math.ceil(a*b/2))
main()
``` | instruction | 0 | 41,423 | 7 | 82,846 |
Yes | output | 1 | 41,423 | 7 | 82,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image>
Submitted Solution:
```
t =int(input())
for i in range(1,t+1):
a, b = map(int, input().split())
if a == 1 or b == 1:
print((max(a, b) // 2) + (max(a, b) % 2))
elif a % 2 == 0:
print((a // 2) * b)
elif b % 2 == 0:
print((b // 2) * a)
else:
print((min(a, b) // 2) * max(a, b) + (max(a, b) // 2) + (max(a, b) % 2))
``` | instruction | 0 | 41,424 | 7 | 82,848 |
Yes | output | 1 | 41,424 | 7 | 82,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image>
Submitted Solution:
```
testcase = int(input())
tcasen = []
for i in range(0, testcase):
tcasen.append([int(x) for x in input().split()])
#n row m column
for i in range(0, testcase):
w = min(tcasen[i])
h = max(tcasen[i])
if w % 2 == 0:
lamp = ((w/2)*h)
elif h % 2 == 0:
lamp = ((h/2)*h)
else:
lamp = (((w-1)/2)*h+(int(h/2))+1)
lamp = int(lamp)
print(lamp)
``` | instruction | 0 | 41,425 | 7 | 82,850 |
No | output | 1 | 41,425 | 7 | 82,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image>
Submitted Solution:
```
t=int(input())
import math
while t:
t-=1
n,m=list(map(int,input().split()))
if n==1 and m==1:
print(1)
continue
if n==1 or m==1:
print(max(n,m)-1)
continue
if (not n&1) or (not m&1):
print((n*m)//2)
continue
print(((((n-1)*m)//2)+math.ceil(m/2)))
'''if n<m:
print(((((n-1)*m)//2)+math.floor(n/2)))
continue
elif n>m:
print(((((m-1)*n)//2)+m))
else:
print(((((n-1)*m)//2)+n-1))'''
``` | instruction | 0 | 41,426 | 7 | 82,852 |
No | output | 1 | 41,426 | 7 | 82,853 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image>
Submitted Solution:
```
import math
n=int(input())
for i in range(n):
x,y=map(int,input().split())
if x==1 or y==1:
print(max(1,math.ceil(max(x,y)/2)))
elif max(x,y)%2!=0:
print((((max(x,y)-1)//2)*min(x,y))+min(x,y)-1)
else:
print((max(x,y)//2)*min(x,y))
``` | instruction | 0 | 41,427 | 7 | 82,854 |
No | output | 1 | 41,427 | 7 | 82,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.
You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
<image> The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.
Each test case is a line containing two integers n, m (1 ≤ n, m ≤ 10^4) — park sizes.
Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.
Example
Input
5
1 1
1 3
2 2
3 3
5 3
Output
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example: <image>
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example: <image>
Submitted Solution:
```
for i in range(int(input())):
n,m=map(int,input().split())
k=0
if n==1 or m==1:
k=max(n,m)
print((k//2)+1)
elif n%2==0 and m%2!=0:
k=n//2
print(k*m)
elif n%2!=0 and m%2!=0:
k=(n-1)//2
k=k*m
k=k+(m//2)+1
print(k)
elif n%2!=0 and m%2==0:
k=(n-1)//2
k=k*m
k=k+m-1
print(k)
else:
k=n//2
print(k*m)
``` | instruction | 0 | 41,428 | 7 | 82,856 |
No | output | 1 | 41,428 | 7 | 82,857 |
Provide a correct Python 3 solution for this coding contest problem.
There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.
Adjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.
Ultimately, how many slimes will be there?
Constraints
* 1 \leq N \leq 10^5
* |S| = N
* S consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the final number of slimes.
Examples
Input
10
aabbbbaaca
Output
5
Input
5
aaaaa
Output
1
Input
20
xxzaffeeeeddfkkkkllq
Output
10 | instruction | 0 | 41,859 | 7 | 83,718 |
"Correct Solution:
```
import itertools as it
n = input()
s = input()
print(len(list(it.groupby(s, ))))
``` | output | 1 | 41,859 | 7 | 83,719 |
Provide a correct Python 3 solution for this coding contest problem.
There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.
Adjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.
Ultimately, how many slimes will be there?
Constraints
* 1 \leq N \leq 10^5
* |S| = N
* S consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the final number of slimes.
Examples
Input
10
aabbbbaaca
Output
5
Input
5
aaaaa
Output
1
Input
20
xxzaffeeeeddfkkkkllq
Output
10 | instruction | 0 | 41,863 | 7 | 83,726 |
"Correct Solution:
```
from itertools import groupby
_ = input()
s = list(groupby(input()))
print(len(s))
``` | output | 1 | 41,863 | 7 | 83,727 |
Provide a correct Python 3 solution for this coding contest problem.
Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light bulbs controlled by the switch change their states. You lost the table that recorded the correspondence between the switches and the light bulbs, and want to restore it.
You decided to restore the correspondence by the following procedure.
* At first, every switch is off and every light bulb is off.
* You operate some switches represented by $S_1$.
* You check the states of the light bulbs represented by $B_1$.
* You operate some switches represented by $S_2$.
* You check the states of the light bulbs represented by $B_2$.
* ...
* You operate some switches represented by $S_Q$.
* You check the states of the light bulbs represented by $B_Q$.
After you operate some switches and check the states of the light bulbs, the states of the switches and the light bulbs are kept for next operations.
Can you restore the correspondence between the switches and the light bulbs using the information about the switches you have operated and the states of the light bulbs you have checked?
Input
The input consists of multiple datasets. The number of dataset is no more than $50$ and the file size is no more than $10\mathrm{MB}$. Each dataset is formatted as follows.
> $N$ $M$ $Q$
> $S_1$ $B_1$
> :
> :
> $S_Q$ $B_Q$
The first line of each dataset contains three integers $N$ ($1 \le N \le 36$), $M$ ($1 \le M \le 1{,}000$), $Q$ ($0 \le Q \le 1{,}000$), which denote the number of switches, the number of light bulbs and the number of operations respectively. The following $Q$ lines describe the information about the switches you have operated and the states of the light bulbs you have checked. The $i$-th of them contains two strings $S_i$ and $B_i$ of lengths $N$ and $M$ respectively. Each $S_i$ denotes the set of the switches you have operated: $S_{ij}$ is either $0$ or $1$, which denotes the $j$-th switch is not operated or operated respectively. Each $B_i$ denotes the states of the light bulbs: $B_{ij}$ is either $0$ or $1$, which denotes the $j$-th light bulb is off or on respectively.
You can assume that there exists a correspondence between the switches and the light bulbs which is consistent with the given information.
The end of input is indicated by a line containing three zeros.
Output
For each dataset, output the correspondence between the switches and the light bulbs consisting of $M$ numbers written in base-$36$. In the base-$36$ system for this problem, the values $0$-$9$ and $10$-$35$ are represented by the characters '0'-'9' and 'A'-'Z' respectively. The $i$-th character of the correspondence means the number of the switch controlling the $i$-th light bulb. If you cannot determine which switch controls the $i$-th light bulb, output '?' as the $i$-th character instead of the number of a switch.
Sample Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output for the Sample Input
2222221100
??
0
1
0123456789A
Example
Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output
2222221100
??
0
1
0123456789A | instruction | 0 | 42,037 | 7 | 84,074 |
"Correct Solution:
```
while 1:
n,m,q=map(int,input().split())
if (n|m|q)==0: break
p=[]
res=[{_ for _ in range(n)} for _ in range(m)]
for i in range(q):
s,b=[[int(c) for c in s] for s in input().split()]
if i>0:
for j in range(n):
s[j]^=p[j]
zero={i for i in range(n) if s[i]==0}
one={i for i in range(n) if s[i]==1}
for j in range(m):
if(b[j]==0): res[j]-=one
if(b[j]==1): res[j]-=zero
p=s
table="".join([str(i) for i in range(10)]+[chr(ord("A")+i) for i in range(26)])
for i in range(m):
if len(res[i])==1:
print(table[res[i].pop()],sep="",end="")
else:
print("?",sep="",end="")
print()
``` | output | 1 | 42,037 | 7 | 84,075 |
Provide a correct Python 3 solution for this coding contest problem.
Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light bulbs controlled by the switch change their states. You lost the table that recorded the correspondence between the switches and the light bulbs, and want to restore it.
You decided to restore the correspondence by the following procedure.
* At first, every switch is off and every light bulb is off.
* You operate some switches represented by $S_1$.
* You check the states of the light bulbs represented by $B_1$.
* You operate some switches represented by $S_2$.
* You check the states of the light bulbs represented by $B_2$.
* ...
* You operate some switches represented by $S_Q$.
* You check the states of the light bulbs represented by $B_Q$.
After you operate some switches and check the states of the light bulbs, the states of the switches and the light bulbs are kept for next operations.
Can you restore the correspondence between the switches and the light bulbs using the information about the switches you have operated and the states of the light bulbs you have checked?
Input
The input consists of multiple datasets. The number of dataset is no more than $50$ and the file size is no more than $10\mathrm{MB}$. Each dataset is formatted as follows.
> $N$ $M$ $Q$
> $S_1$ $B_1$
> :
> :
> $S_Q$ $B_Q$
The first line of each dataset contains three integers $N$ ($1 \le N \le 36$), $M$ ($1 \le M \le 1{,}000$), $Q$ ($0 \le Q \le 1{,}000$), which denote the number of switches, the number of light bulbs and the number of operations respectively. The following $Q$ lines describe the information about the switches you have operated and the states of the light bulbs you have checked. The $i$-th of them contains two strings $S_i$ and $B_i$ of lengths $N$ and $M$ respectively. Each $S_i$ denotes the set of the switches you have operated: $S_{ij}$ is either $0$ or $1$, which denotes the $j$-th switch is not operated or operated respectively. Each $B_i$ denotes the states of the light bulbs: $B_{ij}$ is either $0$ or $1$, which denotes the $j$-th light bulb is off or on respectively.
You can assume that there exists a correspondence between the switches and the light bulbs which is consistent with the given information.
The end of input is indicated by a line containing three zeros.
Output
For each dataset, output the correspondence between the switches and the light bulbs consisting of $M$ numbers written in base-$36$. In the base-$36$ system for this problem, the values $0$-$9$ and $10$-$35$ are represented by the characters '0'-'9' and 'A'-'Z' respectively. The $i$-th character of the correspondence means the number of the switch controlling the $i$-th light bulb. If you cannot determine which switch controls the $i$-th light bulb, output '?' as the $i$-th character instead of the number of a switch.
Sample Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output for the Sample Input
2222221100
??
0
1
0123456789A
Example
Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output
2222221100
??
0
1
0123456789A | instruction | 0 | 42,038 | 7 | 84,076 |
"Correct 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(): return list(sys.stdin.readline())[:-1]
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(n,m,q):
if q == 0:
if n == 1:
print("0"*m)
else:
print("?"*m)
return
ans = ["?"]*m
f = defaultdict(lambda : "?")
for i in range(10):
f[i] = str(i)
alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(len(alp)):
f[i+10] = alp[i]
s = [[int(x,2) for x in input().split()] for i in range(q)]
for i in range(q-1):
s[i+1][0] ^= s[i][0]
M = (1<<m)-1
for i in range(n):
bi = 1<<(n-i-1)
k = M
for a,b in s:
if not a&bi:
k &= (M-b)
else:
k &= b
for j in range(m):
if k&(1<<j):
if ans[-1-j] != "?":
ans[-1-j] = 37
else:
ans[-1-j] = i
ans = [f[i] for i in ans]
print(*ans,sep = "")
return
#Solve
if __name__ == "__main__":
while 1:
n,m,q = LI()
if n == 0:
break
solve(n,m,q)
``` | output | 1 | 42,038 | 7 | 84,077 |
Provide a correct Python 3 solution for this coding contest problem.
Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light bulbs controlled by the switch change their states. You lost the table that recorded the correspondence between the switches and the light bulbs, and want to restore it.
You decided to restore the correspondence by the following procedure.
* At first, every switch is off and every light bulb is off.
* You operate some switches represented by $S_1$.
* You check the states of the light bulbs represented by $B_1$.
* You operate some switches represented by $S_2$.
* You check the states of the light bulbs represented by $B_2$.
* ...
* You operate some switches represented by $S_Q$.
* You check the states of the light bulbs represented by $B_Q$.
After you operate some switches and check the states of the light bulbs, the states of the switches and the light bulbs are kept for next operations.
Can you restore the correspondence between the switches and the light bulbs using the information about the switches you have operated and the states of the light bulbs you have checked?
Input
The input consists of multiple datasets. The number of dataset is no more than $50$ and the file size is no more than $10\mathrm{MB}$. Each dataset is formatted as follows.
> $N$ $M$ $Q$
> $S_1$ $B_1$
> :
> :
> $S_Q$ $B_Q$
The first line of each dataset contains three integers $N$ ($1 \le N \le 36$), $M$ ($1 \le M \le 1{,}000$), $Q$ ($0 \le Q \le 1{,}000$), which denote the number of switches, the number of light bulbs and the number of operations respectively. The following $Q$ lines describe the information about the switches you have operated and the states of the light bulbs you have checked. The $i$-th of them contains two strings $S_i$ and $B_i$ of lengths $N$ and $M$ respectively. Each $S_i$ denotes the set of the switches you have operated: $S_{ij}$ is either $0$ or $1$, which denotes the $j$-th switch is not operated or operated respectively. Each $B_i$ denotes the states of the light bulbs: $B_{ij}$ is either $0$ or $1$, which denotes the $j$-th light bulb is off or on respectively.
You can assume that there exists a correspondence between the switches and the light bulbs which is consistent with the given information.
The end of input is indicated by a line containing three zeros.
Output
For each dataset, output the correspondence between the switches and the light bulbs consisting of $M$ numbers written in base-$36$. In the base-$36$ system for this problem, the values $0$-$9$ and $10$-$35$ are represented by the characters '0'-'9' and 'A'-'Z' respectively. The $i$-th character of the correspondence means the number of the switch controlling the $i$-th light bulb. If you cannot determine which switch controls the $i$-th light bulb, output '?' as the $i$-th character instead of the number of a switch.
Sample Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output for the Sample Input
2222221100
??
0
1
0123456789A
Example
Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output
2222221100
??
0
1
0123456789A | instruction | 0 | 42,039 | 7 | 84,078 |
"Correct Solution:
```
while True:
N, M, Q = map(int, input().split()) # N個のスイッチ, M個のライト, Q個のクエリ
if N == 0 and M == 0 and Q ==0:
exit()
# 全ての配列を繋がっていることを仮定する
correspondence = [set(list(range(M))) for _ in range(N)]
# print(correspondence) 全てのスイッチと繋がっていることが確認できた
switch_status = [0]*N # スイッチの初期状態
light_status = [0]*M # ライトの初期状態
for _ in range(Q): # Q個のクエリが飛んでくる
s, b = map(str, input().split()) # 操作したスイッチの情報と, 現在のライトの状態
# 1つずつxorを取りたい
# 操作したスイッチのインデックス (リスト)と、変化したライトのインデックス (set)が欲しい
switch_index = list(map(int, s)) # 今回操作したスイッチの情報, これで数字に変換できる
light_index = list(map(int, b)) # 現在のライトの情報, これで数字に変換できる
changed_switch = []
for i in range(len(switch_index)):
if switch_index[i] == 1:
changed_switch.append(i)
switch_status[i] = switch_status[i] ^ 1 # 今まで0なら次の状態は1へ, 今まで1なら次の状態は0へ
# changed_switchを使って色々やる
# その前にまず、状態が変わったの一覧を手に入れる
changed_light = []
for i in range(len(light_index)):
if light_status[i] ^ light_index[i]: # 状態が変わったなら
changed_light.append(i) # 状態が変わったライト
light_status = light_index # ライトの状態を更新する
set_changed_light = set(changed_light)
# print(correspondence)
for i in range(N):
if i in changed_switch:
correspondence[i] &= set_changed_light
else:
correspondence[i] -= set_changed_light
# for c in changed_switch: # 状態が変わったスイッチ, その他のスイッチからはライトを削除する必要ありそう
# correspondence[c] &= set_changed_light
# print(correspondence)
ans = [[] for _ in range(M)] # M個のライトの状態
for i, lights in enumerate(correspondence):
for l in lights:
ans[l].append(i)
true_ans = ""
co_dict = {0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9", 10: "A", 11: "B", \
12: "C", 13: "D", 14: "E", 15: "F", 16: "G", 17: "H", 18: "I", 19: "J", 20: "K", 21: "L", 22: "M", 23: "N", 24: "O", \
25: "P", 26: "Q", 27: "R", 28: "S", 29: "T", 30: "U", 31: "V", 32: "W", 33: "X", 34: "Y", 35: "Z"}
for i in range(M):
if len(ans[i]) > 1:
true_ans += "?"
else:
true_ans += co_dict[ans[i][0]]
print(true_ans)
# [{8, 9}, {6, 7}, {0, 1, 2, 3, 4, 5}]
# 2222221100
``` | output | 1 | 42,039 | 7 | 84,079 |
Provide a correct Python 3 solution for this coding contest problem.
Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light bulbs controlled by the switch change their states. You lost the table that recorded the correspondence between the switches and the light bulbs, and want to restore it.
You decided to restore the correspondence by the following procedure.
* At first, every switch is off and every light bulb is off.
* You operate some switches represented by $S_1$.
* You check the states of the light bulbs represented by $B_1$.
* You operate some switches represented by $S_2$.
* You check the states of the light bulbs represented by $B_2$.
* ...
* You operate some switches represented by $S_Q$.
* You check the states of the light bulbs represented by $B_Q$.
After you operate some switches and check the states of the light bulbs, the states of the switches and the light bulbs are kept for next operations.
Can you restore the correspondence between the switches and the light bulbs using the information about the switches you have operated and the states of the light bulbs you have checked?
Input
The input consists of multiple datasets. The number of dataset is no more than $50$ and the file size is no more than $10\mathrm{MB}$. Each dataset is formatted as follows.
> $N$ $M$ $Q$
> $S_1$ $B_1$
> :
> :
> $S_Q$ $B_Q$
The first line of each dataset contains three integers $N$ ($1 \le N \le 36$), $M$ ($1 \le M \le 1{,}000$), $Q$ ($0 \le Q \le 1{,}000$), which denote the number of switches, the number of light bulbs and the number of operations respectively. The following $Q$ lines describe the information about the switches you have operated and the states of the light bulbs you have checked. The $i$-th of them contains two strings $S_i$ and $B_i$ of lengths $N$ and $M$ respectively. Each $S_i$ denotes the set of the switches you have operated: $S_{ij}$ is either $0$ or $1$, which denotes the $j$-th switch is not operated or operated respectively. Each $B_i$ denotes the states of the light bulbs: $B_{ij}$ is either $0$ or $1$, which denotes the $j$-th light bulb is off or on respectively.
You can assume that there exists a correspondence between the switches and the light bulbs which is consistent with the given information.
The end of input is indicated by a line containing three zeros.
Output
For each dataset, output the correspondence between the switches and the light bulbs consisting of $M$ numbers written in base-$36$. In the base-$36$ system for this problem, the values $0$-$9$ and $10$-$35$ are represented by the characters '0'-'9' and 'A'-'Z' respectively. The $i$-th character of the correspondence means the number of the switch controlling the $i$-th light bulb. If you cannot determine which switch controls the $i$-th light bulb, output '?' as the $i$-th character instead of the number of a switch.
Sample Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output for the Sample Input
2222221100
??
0
1
0123456789A
Example
Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output
2222221100
??
0
1
0123456789A | instruction | 0 | 42,040 | 7 | 84,080 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
st = string.digits + string.ascii_uppercase
while True:
n,m,q = LI()
if n == 0:
break
a = [LS() for _ in range(q)]
if n == 1:
rr.append('0'*m)
continue
u = [0] * m
v = [0] * m
ms = 0
mk = 2**n - 1
for t,s in a:
mt = int(t[::-1],2)
tu = ms ^ mt
tv = mk ^ tu
for i in range(m):
if s[i] == '1':
u[i] |= tu
v[i] |= tv
else:
v[i] |= tu
u[i] |= tv
ms = tu
r = ''
for i in range(m):
t = None
for ti in range(n):
if (u[i] & 2**ti) > 0 and (v[i] & 2**ti) == 0:
if t is None:
t = st[ti]
else:
t = '?'
break
if not t:
t = '?'
r += str(t)
rr.append(r)
return '\n'.join(map(str, rr))
print(main())
``` | output | 1 | 42,040 | 7 | 84,081 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light bulbs controlled by the switch change their states. You lost the table that recorded the correspondence between the switches and the light bulbs, and want to restore it.
You decided to restore the correspondence by the following procedure.
* At first, every switch is off and every light bulb is off.
* You operate some switches represented by $S_1$.
* You check the states of the light bulbs represented by $B_1$.
* You operate some switches represented by $S_2$.
* You check the states of the light bulbs represented by $B_2$.
* ...
* You operate some switches represented by $S_Q$.
* You check the states of the light bulbs represented by $B_Q$.
After you operate some switches and check the states of the light bulbs, the states of the switches and the light bulbs are kept for next operations.
Can you restore the correspondence between the switches and the light bulbs using the information about the switches you have operated and the states of the light bulbs you have checked?
Input
The input consists of multiple datasets. The number of dataset is no more than $50$ and the file size is no more than $10\mathrm{MB}$. Each dataset is formatted as follows.
> $N$ $M$ $Q$
> $S_1$ $B_1$
> :
> :
> $S_Q$ $B_Q$
The first line of each dataset contains three integers $N$ ($1 \le N \le 36$), $M$ ($1 \le M \le 1{,}000$), $Q$ ($0 \le Q \le 1{,}000$), which denote the number of switches, the number of light bulbs and the number of operations respectively. The following $Q$ lines describe the information about the switches you have operated and the states of the light bulbs you have checked. The $i$-th of them contains two strings $S_i$ and $B_i$ of lengths $N$ and $M$ respectively. Each $S_i$ denotes the set of the switches you have operated: $S_{ij}$ is either $0$ or $1$, which denotes the $j$-th switch is not operated or operated respectively. Each $B_i$ denotes the states of the light bulbs: $B_{ij}$ is either $0$ or $1$, which denotes the $j$-th light bulb is off or on respectively.
You can assume that there exists a correspondence between the switches and the light bulbs which is consistent with the given information.
The end of input is indicated by a line containing three zeros.
Output
For each dataset, output the correspondence between the switches and the light bulbs consisting of $M$ numbers written in base-$36$. In the base-$36$ system for this problem, the values $0$-$9$ and $10$-$35$ are represented by the characters '0'-'9' and 'A'-'Z' respectively. The $i$-th character of the correspondence means the number of the switch controlling the $i$-th light bulb. If you cannot determine which switch controls the $i$-th light bulb, output '?' as the $i$-th character instead of the number of a switch.
Sample Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output for the Sample Input
2222221100
??
0
1
0123456789A
Example
Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output
2222221100
??
0
1
0123456789A
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
st = string.digits + string.ascii_uppercase
while True:
n,m,q = LI()
if n == 0:
break
a = [LS() for _ in range(q)]
if n == 1:
rr.append('0'*m)
continue
u = [set() for _ in range(m)]
v = [set() for _ in range(m)]
ms = '0' * m
for t,s in a:
ts = []
ns = []
for i in range(n):
if t[i] == '1':
ts.append(i)
else:
ns.append(i)
us = set()
vs = set()
for i in range(m):
for ti in ts:
if s[i] != ms[i]:
u[i].add(ti)
else:
v[i].add(ti)
for ni in ns:
if s[i] != ms[i]:
v[i].add(ni)
else:
u[i].add(ni)
ms = s
r = ''
for i in range(m):
t = u[i] - v[i]
if len(t) == 1:
r += st[list(t)[0]]
else:
r += '?'
rr.append(r)
return '\n'.join(map(str, rr))
print(main())
``` | instruction | 0 | 42,041 | 7 | 84,082 |
No | output | 1 | 42,041 | 7 | 84,083 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light bulbs controlled by the switch change their states. You lost the table that recorded the correspondence between the switches and the light bulbs, and want to restore it.
You decided to restore the correspondence by the following procedure.
* At first, every switch is off and every light bulb is off.
* You operate some switches represented by $S_1$.
* You check the states of the light bulbs represented by $B_1$.
* You operate some switches represented by $S_2$.
* You check the states of the light bulbs represented by $B_2$.
* ...
* You operate some switches represented by $S_Q$.
* You check the states of the light bulbs represented by $B_Q$.
After you operate some switches and check the states of the light bulbs, the states of the switches and the light bulbs are kept for next operations.
Can you restore the correspondence between the switches and the light bulbs using the information about the switches you have operated and the states of the light bulbs you have checked?
Input
The input consists of multiple datasets. The number of dataset is no more than $50$ and the file size is no more than $10\mathrm{MB}$. Each dataset is formatted as follows.
> $N$ $M$ $Q$
> $S_1$ $B_1$
> :
> :
> $S_Q$ $B_Q$
The first line of each dataset contains three integers $N$ ($1 \le N \le 36$), $M$ ($1 \le M \le 1{,}000$), $Q$ ($0 \le Q \le 1{,}000$), which denote the number of switches, the number of light bulbs and the number of operations respectively. The following $Q$ lines describe the information about the switches you have operated and the states of the light bulbs you have checked. The $i$-th of them contains two strings $S_i$ and $B_i$ of lengths $N$ and $M$ respectively. Each $S_i$ denotes the set of the switches you have operated: $S_{ij}$ is either $0$ or $1$, which denotes the $j$-th switch is not operated or operated respectively. Each $B_i$ denotes the states of the light bulbs: $B_{ij}$ is either $0$ or $1$, which denotes the $j$-th light bulb is off or on respectively.
You can assume that there exists a correspondence between the switches and the light bulbs which is consistent with the given information.
The end of input is indicated by a line containing three zeros.
Output
For each dataset, output the correspondence between the switches and the light bulbs consisting of $M$ numbers written in base-$36$. In the base-$36$ system for this problem, the values $0$-$9$ and $10$-$35$ are represented by the characters '0'-'9' and 'A'-'Z' respectively. The $i$-th character of the correspondence means the number of the switch controlling the $i$-th light bulb. If you cannot determine which switch controls the $i$-th light bulb, output '?' as the $i$-th character instead of the number of a switch.
Sample Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output for the Sample Input
2222221100
??
0
1
0123456789A
Example
Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output
2222221100
??
0
1
0123456789A
Submitted Solution:
```
while 1:
n,m,q=map(int,input().split())
if (n|m|q)==0: break
p=[]
res=[[_ for _ in range(n)] for _ in range(m)]
for i in range(q):
s,b=[[int(c) for c in s] for s in input().split()]
if i>0:
for j in range(n):
s[j]^=p[j]
for j in range(n):
for k in range(m):
if s[j]!=b[k] and j in res[k]:
res[k].remove(j)
p=s
table="".join([str(i) for i in range(10)]+[chr(ord("A")+i) for i in range(26)])
for i in range(m):
if len(res[i])==1:
print(table[res[i][0]],sep="",end="")
else:
print("?",sep="",end="")
print()
``` | instruction | 0 | 42,042 | 7 | 84,084 |
No | output | 1 | 42,042 | 7 | 84,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light bulbs controlled by the switch change their states. You lost the table that recorded the correspondence between the switches and the light bulbs, and want to restore it.
You decided to restore the correspondence by the following procedure.
* At first, every switch is off and every light bulb is off.
* You operate some switches represented by $S_1$.
* You check the states of the light bulbs represented by $B_1$.
* You operate some switches represented by $S_2$.
* You check the states of the light bulbs represented by $B_2$.
* ...
* You operate some switches represented by $S_Q$.
* You check the states of the light bulbs represented by $B_Q$.
After you operate some switches and check the states of the light bulbs, the states of the switches and the light bulbs are kept for next operations.
Can you restore the correspondence between the switches and the light bulbs using the information about the switches you have operated and the states of the light bulbs you have checked?
Input
The input consists of multiple datasets. The number of dataset is no more than $50$ and the file size is no more than $10\mathrm{MB}$. Each dataset is formatted as follows.
> $N$ $M$ $Q$
> $S_1$ $B_1$
> :
> :
> $S_Q$ $B_Q$
The first line of each dataset contains three integers $N$ ($1 \le N \le 36$), $M$ ($1 \le M \le 1{,}000$), $Q$ ($0 \le Q \le 1{,}000$), which denote the number of switches, the number of light bulbs and the number of operations respectively. The following $Q$ lines describe the information about the switches you have operated and the states of the light bulbs you have checked. The $i$-th of them contains two strings $S_i$ and $B_i$ of lengths $N$ and $M$ respectively. Each $S_i$ denotes the set of the switches you have operated: $S_{ij}$ is either $0$ or $1$, which denotes the $j$-th switch is not operated or operated respectively. Each $B_i$ denotes the states of the light bulbs: $B_{ij}$ is either $0$ or $1$, which denotes the $j$-th light bulb is off or on respectively.
You can assume that there exists a correspondence between the switches and the light bulbs which is consistent with the given information.
The end of input is indicated by a line containing three zeros.
Output
For each dataset, output the correspondence between the switches and the light bulbs consisting of $M$ numbers written in base-$36$. In the base-$36$ system for this problem, the values $0$-$9$ and $10$-$35$ are represented by the characters '0'-'9' and 'A'-'Z' respectively. The $i$-th character of the correspondence means the number of the switch controlling the $i$-th light bulb. If you cannot determine which switch controls the $i$-th light bulb, output '?' as the $i$-th character instead of the number of a switch.
Sample Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output for the Sample Input
2222221100
??
0
1
0123456789A
Example
Input
3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
Output
2222221100
??
0
1
0123456789A
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
st = string.digits + string.ascii_uppercase
while True:
n,m,q = LI()
if n == 0:
break
a = [LS() for _ in range(q)]
if n == 1:
rr.append('0'*m)
continue
u = [0] * m
v = [0] * m
ms = 0
mk = 2**n - 1
for t,s in a:
mt = int(t[::-1],2)
tu = ms ^ mt
tv = mk ^ tu
for i in range(m):
if s[i] == '1':
u[i] |= tu
v[i] |= tv
else:
v[i] |= tu
u[i] |= tv
ms = tu
r = ''
for i in range(m):
t = None
for ti in range(n):
if (u[i] & 2**ti) > 0 and (v[i] & 2**ti) == 0:
if t is None:
t = '{:X}'.format(ti)
else:
'?'
break
if not t:
t = '?'
r += str(t)
rr.append(r)
return '\n'.join(map(str, rr))
print(main())
``` | instruction | 0 | 42,043 | 7 | 84,086 |
No | output | 1 | 42,043 | 7 | 84,087 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
* Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j).
* First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) → ... → (1, m) → (2, 1) → ... → (2, m) → ... → (n, 1) → ... → (n, m). Waste cells will be ignored.
* Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
<image>
Now she is wondering how to determine the crop plants in some certain cells.
Input
In the first line there are four positive integers n, m, k, t (1 ≤ n ≤ 4·104, 1 ≤ m ≤ 4·104, 1 ≤ k ≤ 103, 1 ≤ t ≤ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each k lines contains two integers a, b (1 ≤ a ≤ n, 1 ≤ b ≤ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each t lines contains two integers i, j (1 ≤ i ≤ n, 1 ≤ j ≤ m), which is a query that asks you the kind of crop plants of a cell (i, j).
Output
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
Examples
Input
4 5 5 6
4 3
1 3
3 3
2 5
3 2
1 3
1 4
2 3
2 4
1 1
1 1
Output
Waste
Grapes
Carrots
Kiwis
Carrots
Carrots
Note
The sample corresponds to the figure in the statement. | instruction | 0 | 42,556 | 7 | 85,112 |
Tags: implementation, sortings
Correct Solution:
```
w = []
col = ['Carrots', 'Kiwis', 'Grapes']
n , m , k , t = map(int,input().split())
for _ in range(k):
w.append(list(map(int, input().split())))
for _ in range(t):
c = list(map(int,input().split()))
if c in w:
print('Waste')
else:
s=0
for i in w:
if i < c:
s +=1
val = (c[0]-1)*m + c[1]-1 -s
print(col[val%3])
``` | output | 1 | 42,556 | 7 | 85,113 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
* Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j).
* First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) → ... → (1, m) → (2, 1) → ... → (2, m) → ... → (n, 1) → ... → (n, m). Waste cells will be ignored.
* Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
<image>
Now she is wondering how to determine the crop plants in some certain cells.
Input
In the first line there are four positive integers n, m, k, t (1 ≤ n ≤ 4·104, 1 ≤ m ≤ 4·104, 1 ≤ k ≤ 103, 1 ≤ t ≤ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each k lines contains two integers a, b (1 ≤ a ≤ n, 1 ≤ b ≤ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each t lines contains two integers i, j (1 ≤ i ≤ n, 1 ≤ j ≤ m), which is a query that asks you the kind of crop plants of a cell (i, j).
Output
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
Examples
Input
4 5 5 6
4 3
1 3
3 3
2 5
3 2
1 3
1 4
2 3
2 4
1 1
1 1
Output
Waste
Grapes
Carrots
Kiwis
Carrots
Carrots
Note
The sample corresponds to the figure in the statement. | instruction | 0 | 42,557 | 7 | 85,114 |
Tags: implementation, sortings
Correct Solution:
```
n,m,k,t = [int(x) for x in input().split()]
mapp ={0:'Carrots',1:'Kiwis',2:'Grapes'}
iamdistruption = []
for i in range(k):
x,y = [int(x) for x in input().split()]
iamdistruption.append((x,y))
for i in range(t):
x,y = [int(x) for x in input().split()]
orig = ((m*(x-1))+y-1)
disbeforeme = 0
for x,y in iamdistruption:
if m*(x-1)+y-1==orig:
print("Waste")
break
elif m*(x-1)+y-1<orig:
disbeforeme+=1
else:
afterdis = ((orig%3) - disbeforeme)%3
print(mapp[afterdis])
``` | output | 1 | 42,557 | 7 | 85,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
* Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j).
* First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) → ... → (1, m) → (2, 1) → ... → (2, m) → ... → (n, 1) → ... → (n, m). Waste cells will be ignored.
* Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
<image>
Now she is wondering how to determine the crop plants in some certain cells.
Input
In the first line there are four positive integers n, m, k, t (1 ≤ n ≤ 4·104, 1 ≤ m ≤ 4·104, 1 ≤ k ≤ 103, 1 ≤ t ≤ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each k lines contains two integers a, b (1 ≤ a ≤ n, 1 ≤ b ≤ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each t lines contains two integers i, j (1 ≤ i ≤ n, 1 ≤ j ≤ m), which is a query that asks you the kind of crop plants of a cell (i, j).
Output
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
Examples
Input
4 5 5 6
4 3
1 3
3 3
2 5
3 2
1 3
1 4
2 3
2 4
1 1
1 1
Output
Waste
Grapes
Carrots
Kiwis
Carrots
Carrots
Note
The sample corresponds to the figure in the statement. | instruction | 0 | 42,558 | 7 | 85,116 |
Tags: implementation, sortings
Correct Solution:
```
n , m , k ,t = [int(i) for i in input().split()]
waste = []
for i in range(k):
a ,b = [int(i) for i in input().split()]
waste.append((a-1)*m+b)
crop = ['Carrots','Kiwis','Grapes']
waste.sort()
nn = len(waste)
for i in range(t):
a ,b = [int(i) for i in input().split()]
c = (a-1)*m + b
i = 0
while i < nn and waste[i] < c:
i += 1
if i < nn and waste[i] == c:
print ('Waste')
else:
no = c - i-1
print (crop[no%3])
# Made By Mostafa_Khaled
``` | output | 1 | 42,558 | 7 | 85,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
* Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j).
* First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) → ... → (1, m) → (2, 1) → ... → (2, m) → ... → (n, 1) → ... → (n, m). Waste cells will be ignored.
* Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
<image>
Now she is wondering how to determine the crop plants in some certain cells.
Input
In the first line there are four positive integers n, m, k, t (1 ≤ n ≤ 4·104, 1 ≤ m ≤ 4·104, 1 ≤ k ≤ 103, 1 ≤ t ≤ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each k lines contains two integers a, b (1 ≤ a ≤ n, 1 ≤ b ≤ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each t lines contains two integers i, j (1 ≤ i ≤ n, 1 ≤ j ≤ m), which is a query that asks you the kind of crop plants of a cell (i, j).
Output
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
Examples
Input
4 5 5 6
4 3
1 3
3 3
2 5
3 2
1 3
1 4
2 3
2 4
1 1
1 1
Output
Waste
Grapes
Carrots
Kiwis
Carrots
Carrots
Note
The sample corresponds to the figure in the statement. | instruction | 0 | 42,559 | 7 | 85,118 |
Tags: implementation, sortings
Correct Solution:
```
# https://codeforces.com/contest/79/problem/B
def single_integer():
return int(input())
def multi_integer():
return map(int, input().split())
def string():
return input()
def multi_string():
return input().split()
n, m, k, t = multi_integer()
wastes = list()
fruits = ["Carrots", "Kiwis", "Grapes"]
for i in range(k):
wastes.append(tuple(multi_integer()))
for i in range(t):
w = 0
a, b = multi_integer()
for j in wastes:
if (a, b) == j:
print("Waste")
break
else:
if j[0] < a:
w += 1
elif j[0] == a:
if j[1] < b:
w += 1
else:
temp = (a - 1) * m + b - 1 - w
print(fruits[temp % 3])
``` | output | 1 | 42,559 | 7 | 85,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
* Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j).
* First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) → ... → (1, m) → (2, 1) → ... → (2, m) → ... → (n, 1) → ... → (n, m). Waste cells will be ignored.
* Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
<image>
Now she is wondering how to determine the crop plants in some certain cells.
Input
In the first line there are four positive integers n, m, k, t (1 ≤ n ≤ 4·104, 1 ≤ m ≤ 4·104, 1 ≤ k ≤ 103, 1 ≤ t ≤ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each k lines contains two integers a, b (1 ≤ a ≤ n, 1 ≤ b ≤ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each t lines contains two integers i, j (1 ≤ i ≤ n, 1 ≤ j ≤ m), which is a query that asks you the kind of crop plants of a cell (i, j).
Output
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
Examples
Input
4 5 5 6
4 3
1 3
3 3
2 5
3 2
1 3
1 4
2 3
2 4
1 1
1 1
Output
Waste
Grapes
Carrots
Kiwis
Carrots
Carrots
Note
The sample corresponds to the figure in the statement. | instruction | 0 | 42,560 | 7 | 85,120 |
Tags: implementation, sortings
Correct Solution:
```
n, m, num_wasted, num_queries = map(int, input().split())
wasted = [ None for i in range(num_wasted) ]
for i in range(num_wasted):
a, b = map(lambda s: int(s) - 1, input().split())
wasted[i] = a * m + b
wasted_set = set(wasted)
wasted.sort()
crops = [ 'Carrots', 'Kiwis', 'Grapes' ]
for i in range(num_queries):
a, b = map(lambda s: int(s) - 1, input().split())
q = a * m + b
if q in wasted_set:
print('Waste')
continue
count = 0
for w in wasted:
if w > q:
break
count += 1
print(crops[(q - count) % 3])
``` | output | 1 | 42,560 | 7 | 85,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
* Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j).
* First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) → ... → (1, m) → (2, 1) → ... → (2, m) → ... → (n, 1) → ... → (n, m). Waste cells will be ignored.
* Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
<image>
Now she is wondering how to determine the crop plants in some certain cells.
Input
In the first line there are four positive integers n, m, k, t (1 ≤ n ≤ 4·104, 1 ≤ m ≤ 4·104, 1 ≤ k ≤ 103, 1 ≤ t ≤ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each k lines contains two integers a, b (1 ≤ a ≤ n, 1 ≤ b ≤ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each t lines contains two integers i, j (1 ≤ i ≤ n, 1 ≤ j ≤ m), which is a query that asks you the kind of crop plants of a cell (i, j).
Output
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
Examples
Input
4 5 5 6
4 3
1 3
3 3
2 5
3 2
1 3
1 4
2 3
2 4
1 1
1 1
Output
Waste
Grapes
Carrots
Kiwis
Carrots
Carrots
Note
The sample corresponds to the figure in the statement. | instruction | 0 | 42,561 | 7 | 85,122 |
Tags: implementation, sortings
Correct Solution:
```
row,line,waste,ask=map(int,input().split())
waste_array=[]
for i in range(waste):
row_data,line_data=map(int,input().split())
waste_array.append(((row_data-1)*line)+line_data)
waste_array=sorted(waste_array)
def binarySearchCount(arr, n, value):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
if (arr[mid] < value):
count = mid + 1
left = mid + 1
else:
right = mid - 1
return count
for i in range(ask):
row_data, line_data = map(int, input().split())
key=(((row_data - 1) * line) + line_data)
if key in waste_array:
print("Waste")
else:
x=binarySearchCount(waste_array,len(waste_array) , key)
result=(key-x)%3
if result==1:
print("Carrots")
elif result==2:
print("Kiwis")
else:
print("Grapes")
``` | output | 1 | 42,561 | 7 | 85,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
* Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j).
* First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) → ... → (1, m) → (2, 1) → ... → (2, m) → ... → (n, 1) → ... → (n, m). Waste cells will be ignored.
* Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
<image>
Now she is wondering how to determine the crop plants in some certain cells.
Input
In the first line there are four positive integers n, m, k, t (1 ≤ n ≤ 4·104, 1 ≤ m ≤ 4·104, 1 ≤ k ≤ 103, 1 ≤ t ≤ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each k lines contains two integers a, b (1 ≤ a ≤ n, 1 ≤ b ≤ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each t lines contains two integers i, j (1 ≤ i ≤ n, 1 ≤ j ≤ m), which is a query that asks you the kind of crop plants of a cell (i, j).
Output
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
Examples
Input
4 5 5 6
4 3
1 3
3 3
2 5
3 2
1 3
1 4
2 3
2 4
1 1
1 1
Output
Waste
Grapes
Carrots
Kiwis
Carrots
Carrots
Note
The sample corresponds to the figure in the statement. | instruction | 0 | 42,562 | 7 | 85,124 |
Tags: implementation, sortings
Correct Solution:
```
"Codeforces Beta Round #6 (Div. 2"
"B. President's Office"
# n,m,p=input().split()
# n=int(n)
# m=int(m)
# a=[]
# s=set()
# for i in range(n):
# l=list(input())
# a.append(l)
# l=[]
# for i in range(n):
# for j in range(m):
# if a[i][j]==p:
# l.append([i,j])
# for i in l:
# x=i[0]
# y=i[1]
# if x+1>=0 and x+1<n:
# if a[x+1][y]!='.' and a[x+1][y]!=p:
# s.add(a[x+1][y])
# if y+1>=0 and y+1<m:
# if a[x][y+1]!='.' and a[x][y+1]!=p:
# s.add(a[x][y+1])
# if x-1>=0 and x-1<n:
# if a[x-1][y]!='.' and a[x-1][y]!=p:
# s.add(a[x-1][y])
# if y-1>=0 and y-1<m:
# if a[x][y-1]!='.' and a[x][y-1]!=p:
# s.add(a[x][y-1])
# print(len(s))
"Codeforces Round #360 (Div. 2)"
"B. Lovely Palindromes"
# y=input()
# print(y+y[::-1])
"Codeforces Round #258 (Div. 2)"
"B. Sort the Array"
# n=int(input())
# a=list(map(int,input().split()))
# mimax=a[0]
# f=0
# l=r=0
# q=0
# for i in range(1,n):
# if a[i]>=a[i-1] and f==0:
# mimax=a[i]
# elif f==0:
# l=i
# f+=1
# if a[i]<=a[i-1] and f==1:
# pass
# elif f==1:
# f+=1
# r=i
# if a[i]<mimax:
# q=1
# break
# if f==2 and a[i]<a[i-1]:
# q=1
# break
# # print(mimax)
# # print(q,l,r,f)
# if q==1:
# print("no")
# elif f==0:
# print("yes")
# print(1,1)
# elif f==1:
# if l>1:
# if a[l-2]>a[r-1]:
# print('no')
# else:
# print("yes")
# print(l,n)
# else:
# print("yes")
# print(l,n)
# elif f==2:
# print("yes")
# print(l,r)
"Codeforces Beta Round #71"
"B. Colorful Field"
n,m,k,t=map(int,input().split())
a=[]
for i in range(k):
i,j=map(int,input().split())
a.append([i,j])
for i in range(t):
i,j=map(int,input().split())
c=j+(i-1)*m
w=0
f=0
for z in range(k):
if a[z][0] < i:
w+=1
elif a[z][0]==i:
if a[z][1]<j:
w+=1
elif a[z][1]==j:
f=1
break
c=c-w
c=c%3
if f==1:
print("Waste")
elif c==1:
print("Carrots")
elif c==2:
print("Kiwis")
elif c==0:
print("Grapes")
``` | output | 1 | 42,562 | 7 | 85,125 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel saw a large field while she was on a bus. The field was a n × m rectangle divided into 1 × 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
* Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j).
* First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) → ... → (1, m) → (2, 1) → ... → (2, m) → ... → (n, 1) → ... → (n, m). Waste cells will be ignored.
* Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
<image>
Now she is wondering how to determine the crop plants in some certain cells.
Input
In the first line there are four positive integers n, m, k, t (1 ≤ n ≤ 4·104, 1 ≤ m ≤ 4·104, 1 ≤ k ≤ 103, 1 ≤ t ≤ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each k lines contains two integers a, b (1 ≤ a ≤ n, 1 ≤ b ≤ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each t lines contains two integers i, j (1 ≤ i ≤ n, 1 ≤ j ≤ m), which is a query that asks you the kind of crop plants of a cell (i, j).
Output
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
Examples
Input
4 5 5 6
4 3
1 3
3 3
2 5
3 2
1 3
1 4
2 3
2 4
1 1
1 1
Output
Waste
Grapes
Carrots
Kiwis
Carrots
Carrots
Note
The sample corresponds to the figure in the statement. | instruction | 0 | 42,563 | 7 | 85,126 |
Tags: implementation, sortings
Correct Solution:
```
inp = str(input()).split(" ")
n = int(inp[0])
m = int(inp[1])
k = int(inp[2])
t = int(inp[3])
wasteSpace = []
for _ in range(k):
inp = str(input()).split(" ")
while inp == ['']:
inp = str(input()).split(" ")
x = int(inp[0]) - 1
y = int(inp[1]) - 1
wasteSpace.append((x, y))
wasteSpace.sort()
def isWaste(x, y):
return (x, y) in wasteSpace
def countPos(x, y):
"""we can do binary search over this"""
l = 0
r = len(wasteSpace)-1
while r >= l:
m = l + (r - l) // 2
if wasteSpace[m] > (x, y):
r = m - 1
else:
l = m + 1
return r + 1
for _ in range(t):
inp = str(input()).split(" ")
while inp == ['']:
inp = str(input()).split(" ")
x = int(inp[0]) - 1
y = int(inp[1]) - 1
# Query:
if isWaste(x, y):
print("Waste")
else:
wasteCount = countPos(x, y)
total = (x * m) + y - wasteCount
if total % 3 == 0:
print("Carrots")
elif total % 3 == 1:
print("Kiwis")
else:
print("Grapes")
``` | output | 1 | 42,563 | 7 | 85,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.
Before assembling the zebra Grisha can make the following operation 0 or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".
Determine the maximum possible length of the zebra that Grisha can produce.
Input
The only line contains a string s (1 ≤ |s| ≤ 10^5, where |s| denotes the length of the string s) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.
Output
Print a single integer — the maximum possible zebra length.
Examples
Input
bwwwbwwbw
Output
5
Input
bwwbwwb
Output
3
Note
In the first example one of the possible sequence of operations is bwwwbww|bw → w|wbwwwbwb → wbwbwwwbw, that gives the answer equal to 5.
In the second example no operation can increase the answer. | instruction | 0 | 42,912 | 7 | 85,824 |
Tags: constructive algorithms, implementation
Correct Solution:
```
s = list(input())
u = []
n = len(s)
k = 1
for i in range(1, n):
if s[i] != s[i - 1]:
k += 1
else:
u.append(k)
k = 1
u.append(k)
if s[0] == s[-1] or len(u) == 1:
print(max(u))
else:
print(max(max(u), u[0] + u[-1]))
``` | output | 1 | 42,912 | 7 | 85,825 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.
Before assembling the zebra Grisha can make the following operation 0 or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".
Determine the maximum possible length of the zebra that Grisha can produce.
Input
The only line contains a string s (1 ≤ |s| ≤ 10^5, where |s| denotes the length of the string s) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.
Output
Print a single integer — the maximum possible zebra length.
Examples
Input
bwwwbwwbw
Output
5
Input
bwwbwwb
Output
3
Note
In the first example one of the possible sequence of operations is bwwwbww|bw → w|wbwwwbwb → wbwbwwwbw, that gives the answer equal to 5.
In the second example no operation can increase the answer. | instruction | 0 | 42,913 | 7 | 85,826 |
Tags: constructive algorithms, implementation
Correct Solution:
```
s = input()
last = s[0]
count = 1
best = 1
for i in range(1, len(s) * 2):
if last != s[i % len(s)]:
count += 1
best = max(best, count)
last = s[i % len(s)]
else:
count = 1
print(min(best, len(s)))
``` | output | 1 | 42,913 | 7 | 85,827 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.
Before assembling the zebra Grisha can make the following operation 0 or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".
Determine the maximum possible length of the zebra that Grisha can produce.
Input
The only line contains a string s (1 ≤ |s| ≤ 10^5, where |s| denotes the length of the string s) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.
Output
Print a single integer — the maximum possible zebra length.
Examples
Input
bwwwbwwbw
Output
5
Input
bwwbwwb
Output
3
Note
In the first example one of the possible sequence of operations is bwwwbww|bw → w|wbwwwbwb → wbwbwwwbw, that gives the answer equal to 5.
In the second example no operation can increase the answer. | instruction | 0 | 42,914 | 7 | 85,828 |
Tags: constructive algorithms, implementation
Correct Solution:
```
import sys
input=sys.stdin.readline
s=list(input().rstrip())
n=len(s)
s.extend(s)
cnt=0
c=1
for i in range(len(s)-1):
if s[i]!=s[i+1]:
c+=1
else:
cnt=max(c,cnt)
c=1
cnt=max(cnt,c)
print(min(cnt,n))
``` | output | 1 | 42,914 | 7 | 85,829 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.
Before assembling the zebra Grisha can make the following operation 0 or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".
Determine the maximum possible length of the zebra that Grisha can produce.
Input
The only line contains a string s (1 ≤ |s| ≤ 10^5, where |s| denotes the length of the string s) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.
Output
Print a single integer — the maximum possible zebra length.
Examples
Input
bwwwbwwbw
Output
5
Input
bwwbwwb
Output
3
Note
In the first example one of the possible sequence of operations is bwwwbww|bw → w|wbwwwbwb → wbwbwwwbw, that gives the answer equal to 5.
In the second example no operation can increase the answer. | instruction | 0 | 42,915 | 7 | 85,830 |
Tags: constructive algorithms, implementation
Correct Solution:
```
s = input().strip()
n = len(s)
a = ''
for i in range(n):
if i == 0:
l = n-1
else:
l = i-1
if s[l] != s[i]:
a += s[i]
else:
break
s += a
r = 1
sum = 1
for i in range(1,len(s)):
if s[i] != s[i-1]:
sum += 1
else:
sum = 1
r = max(r, sum)
print(min(r,n))
``` | output | 1 | 42,915 | 7 | 85,831 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.
Before assembling the zebra Grisha can make the following operation 0 or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".
Determine the maximum possible length of the zebra that Grisha can produce.
Input
The only line contains a string s (1 ≤ |s| ≤ 10^5, where |s| denotes the length of the string s) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.
Output
Print a single integer — the maximum possible zebra length.
Examples
Input
bwwwbwwbw
Output
5
Input
bwwbwwb
Output
3
Note
In the first example one of the possible sequence of operations is bwwwbww|bw → w|wbwwwbwb → wbwbwwwbw, that gives the answer equal to 5.
In the second example no operation can increase the answer. | instruction | 0 | 42,916 | 7 | 85,832 |
Tags: constructive algorithms, implementation
Correct Solution:
```
s = input()
s += s
n = len(s)
p = [0] * n
p[0] = 1
for i in range(1, n):
if s[i] != s[i - 1]:
p[i] = p[i - 1] + 1
else:
p[i] = 1
print(min(max(p), n // 2))
``` | output | 1 | 42,916 | 7 | 85,833 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.
Before assembling the zebra Grisha can make the following operation 0 or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".
Determine the maximum possible length of the zebra that Grisha can produce.
Input
The only line contains a string s (1 ≤ |s| ≤ 10^5, where |s| denotes the length of the string s) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.
Output
Print a single integer — the maximum possible zebra length.
Examples
Input
bwwwbwwbw
Output
5
Input
bwwbwwb
Output
3
Note
In the first example one of the possible sequence of operations is bwwwbww|bw → w|wbwwwbwb → wbwbwwwbw, that gives the answer equal to 5.
In the second example no operation can increase the answer. | instruction | 0 | 42,917 | 7 | 85,834 |
Tags: constructive algorithms, implementation
Correct Solution:
```
s = input() * 2
m = 1
n = 1
for i in range(len(s) - 1):
if s[i] != s[i+1]:
n += 1
else:
if n > m:
m = n
n = 1
if n > m:
m = n
print(min(len(s) // 2, m))
``` | output | 1 | 42,917 | 7 | 85,835 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.
Before assembling the zebra Grisha can make the following operation 0 or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".
Determine the maximum possible length of the zebra that Grisha can produce.
Input
The only line contains a string s (1 ≤ |s| ≤ 10^5, where |s| denotes the length of the string s) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.
Output
Print a single integer — the maximum possible zebra length.
Examples
Input
bwwwbwwbw
Output
5
Input
bwwbwwb
Output
3
Note
In the first example one of the possible sequence of operations is bwwwbww|bw → w|wbwwwbwb → wbwbwwwbw, that gives the answer equal to 5.
In the second example no operation can increase the answer. | instruction | 0 | 42,918 | 7 | 85,836 |
Tags: constructive algorithms, implementation
Correct Solution:
```
s = input()
n = len(s)
dp = [1] * n
cur = s[-1]
end = n - 1
for i in range(n-1):
if s[i] == cur:
end = i
break
cur = s[i]
dp[n-1] = end + 1
res = dp[n-1]
for i in range(n-2, -1, -1):
if s[i] != s[i+1]:
dp[i] = min(n, 1 + dp[i + 1])
res = max(dp[i], res)
#print(i, s[i], dp[i])
#print(end + 1)
print(res)
``` | output | 1 | 42,918 | 7 | 85,837 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.