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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
RedDreamer has an array a consisting of n non-negative integers, and an unlucky integer T.
Let's denote the misfortune of array b having length m as f(b) — the number of pairs of integers (i, j) such that 1 ≤ i < j ≤ m and b_i + b_j = T. RedDreamer has to paint each element of a into one of two colors, white and black (for each element, the color is chosen independently), and then create two arrays c and d so that all white elements belong to c, and all black elements belong to d (it is possible that one of these two arrays becomes empty). RedDreamer wants to paint the elements in such a way that f(c) + f(d) is minimum possible.
For example:
* if n = 6, T = 7 and a = [1, 2, 3, 4, 5, 6], it is possible to paint the 1-st, the 4-th and the 5-th elements white, and all other elements black. So c = [1, 4, 5], d = [2, 3, 6], and f(c) + f(d) = 0 + 0 = 0;
* if n = 3, T = 6 and a = [3, 3, 3], it is possible to paint the 1-st element white, and all other elements black. So c = [3], d = [3, 3], and f(c) + f(d) = 0 + 1 = 1.
Help RedDreamer to paint the array optimally!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
The first line of each test case contains two integers n and T (1 ≤ n ≤ 10^5, 0 ≤ T ≤ 10^9) — the number of elements in the array and the unlucky integer, respectively.
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9) — the elements of the array.
The sum of n over all test cases does not exceed 10^5.
Output
For each test case print n integers: p_1, p_2, ..., p_n (each p_i is either 0 or 1) denoting the colors. If p_i is 0, then a_i is white and belongs to the array c, otherwise it is black and belongs to the array d.
If there are multiple answers that minimize the value of f(c) + f(d), print any of them.
Example
Input
2
6 7
1 2 3 4 5 6
3 6
3 3 3
Output
1 0 0 1 1 0
1 0 0
Submitted Solution:
```
for _ in range(int(input())):
n, t = map(int, input().split())
values, colours, last = [int(i) for i in input().split()], [-1 for i in range(n)], 0
for i in range(n):
if values[i] == t / 2:
if last % 2:
colours[i] = 0
else:
colours[i] = 1
last += 1
elif values[i] > t / 2:
colours[i] = 1
else:
colours[i] = 0
print(*colours)
``` | instruction | 0 | 4,392 | 7 | 8,784 |
Yes | output | 1 | 4,392 | 7 | 8,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
RedDreamer has an array a consisting of n non-negative integers, and an unlucky integer T.
Let's denote the misfortune of array b having length m as f(b) — the number of pairs of integers (i, j) such that 1 ≤ i < j ≤ m and b_i + b_j = T. RedDreamer has to paint each element of a into one of two colors, white and black (for each element, the color is chosen independently), and then create two arrays c and d so that all white elements belong to c, and all black elements belong to d (it is possible that one of these two arrays becomes empty). RedDreamer wants to paint the elements in such a way that f(c) + f(d) is minimum possible.
For example:
* if n = 6, T = 7 and a = [1, 2, 3, 4, 5, 6], it is possible to paint the 1-st, the 4-th and the 5-th elements white, and all other elements black. So c = [1, 4, 5], d = [2, 3, 6], and f(c) + f(d) = 0 + 0 = 0;
* if n = 3, T = 6 and a = [3, 3, 3], it is possible to paint the 1-st element white, and all other elements black. So c = [3], d = [3, 3], and f(c) + f(d) = 0 + 1 = 1.
Help RedDreamer to paint the array optimally!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
The first line of each test case contains two integers n and T (1 ≤ n ≤ 10^5, 0 ≤ T ≤ 10^9) — the number of elements in the array and the unlucky integer, respectively.
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9) — the elements of the array.
The sum of n over all test cases does not exceed 10^5.
Output
For each test case print n integers: p_1, p_2, ..., p_n (each p_i is either 0 or 1) denoting the colors. If p_i is 0, then a_i is white and belongs to the array c, otherwise it is black and belongs to the array d.
If there are multiple answers that minimize the value of f(c) + f(d), print any of them.
Example
Input
2
6 7
1 2 3 4 5 6
3 6
3 3 3
Output
1 0 0 1 1 0
1 0 0
Submitted Solution:
```
# cook your dish here
# code
# ___________________________________
# | |
# | |
# | _, _ _ ,_ |
# | .-'` / \'-'/ \ `'-. |
# | / | | | | \ |
# | ; \_ _/ \_ _/ ; |
# | | `` `` | |
# | | | |
# | ; .-. .-. .-. .-. ; |
# | \ ( '.' \ / '.' ) / |
# | '-.; V ;.-' |
# | ` ` |
# | |
# |___________________________________|
# | |
# | Author : Ramzz |
# | Created On : 21-07-2020 |
# |___________________________________|
#
# _ __ __ _ _ __ ___ ________
# | '__/ _` | '_ ` _ \|_ /_ /
# | | | (_| | | | | | |/ / / /
# |_| \__,_|_| |_| |_/___/___|
#
import math
import collections
from sys import stdin,stdout,setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2**20)
t = 1
for _ in range(int(stdin.readline())):
#n = int(stdin.readline())
#s = stdin.readline().strip('\n')
n,t = list(map(int, stdin.readline().rstrip().split()))
a = list(map(int, stdin.readline().rstrip().split()))
d = {}
for i in a:
if(i not in d):
d[i] = 0
d[i]+=1
if(t%2==0):
bb = t//2
else:
bb = -1
c = {}
for i in a:
if((i not in c) and (i!=bb)):
c[i]=0
c[t-i]=1
#print(bb)
cnt = 0
for i in a:
if(i!=bb):
print(c[i],end=' ')
else:
if(cnt<d[bb]//2):
print(0,end=' ')
else:
print(1,end=' ')
cnt+=1
print()
``` | instruction | 0 | 4,393 | 7 | 8,786 |
Yes | output | 1 | 4,393 | 7 | 8,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
RedDreamer has an array a consisting of n non-negative integers, and an unlucky integer T.
Let's denote the misfortune of array b having length m as f(b) — the number of pairs of integers (i, j) such that 1 ≤ i < j ≤ m and b_i + b_j = T. RedDreamer has to paint each element of a into one of two colors, white and black (for each element, the color is chosen independently), and then create two arrays c and d so that all white elements belong to c, and all black elements belong to d (it is possible that one of these two arrays becomes empty). RedDreamer wants to paint the elements in such a way that f(c) + f(d) is minimum possible.
For example:
* if n = 6, T = 7 and a = [1, 2, 3, 4, 5, 6], it is possible to paint the 1-st, the 4-th and the 5-th elements white, and all other elements black. So c = [1, 4, 5], d = [2, 3, 6], and f(c) + f(d) = 0 + 0 = 0;
* if n = 3, T = 6 and a = [3, 3, 3], it is possible to paint the 1-st element white, and all other elements black. So c = [3], d = [3, 3], and f(c) + f(d) = 0 + 1 = 1.
Help RedDreamer to paint the array optimally!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
The first line of each test case contains two integers n and T (1 ≤ n ≤ 10^5, 0 ≤ T ≤ 10^9) — the number of elements in the array and the unlucky integer, respectively.
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9) — the elements of the array.
The sum of n over all test cases does not exceed 10^5.
Output
For each test case print n integers: p_1, p_2, ..., p_n (each p_i is either 0 or 1) denoting the colors. If p_i is 0, then a_i is white and belongs to the array c, otherwise it is black and belongs to the array d.
If there are multiple answers that minimize the value of f(c) + f(d), print any of them.
Example
Input
2
6 7
1 2 3 4 5 6
3 6
3 3 3
Output
1 0 0 1 1 0
1 0 0
Submitted Solution:
```
for _ in range(int(input())):
n, t = map(int, input().split())
ls = list(map(int, input().split()))
d1 = dict()
d2 = dict()
d3 = dict()
ans = [-1] * n
for i in range(n):
if d1.get(ls[i]) is None:
d1[ls[i]] = 1
else:
d1[ls[i]] += 1
for i in range(n):
if d1.get(t - ls[i]) is not None:
if d2.get(t - ls[i]) is not None and d3.get(t - ls[i]) is not None:
if d2[t - ls[i]] < d3[t - ls[i]]:
ans[i] = 0
if d2.get(ls[i]) is None:
d2[ls[i]] = 1
else:
d2[ls[i]] += 1
else:
ans[i] = 1
if d3.get(ls[i]) is None:
d3[ls[i]] = 1
else:
d3[ls[i]] += 1
elif d2.get(t - ls[i]) is not None:
ans[i] = 1
if d3.get(ls[i]) is None:
d3[ls[i]] = 1
else:
d3[ls[i]] += 1
elif d3.get(t - ls[i]) is not None:
ans[i] = 0
if d2.get(ls[i]) is None:
d2[ls[i]] = 1
else:
d2[ls[i]] += 1
else:
ans[i] = 1
if d3.get(ls[i]) is None:
d3[ls[i]] = 1
else:
d3[ls[i]] += 1
else:
ans[i] = 0
if d3.get(ls[i]) is None:
d3[ls[i]] = 1
else:
d3[ls[i]] += 1
print(*ans)
``` | instruction | 0 | 4,394 | 7 | 8,788 |
Yes | output | 1 | 4,394 | 7 | 8,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
RedDreamer has an array a consisting of n non-negative integers, and an unlucky integer T.
Let's denote the misfortune of array b having length m as f(b) — the number of pairs of integers (i, j) such that 1 ≤ i < j ≤ m and b_i + b_j = T. RedDreamer has to paint each element of a into one of two colors, white and black (for each element, the color is chosen independently), and then create two arrays c and d so that all white elements belong to c, and all black elements belong to d (it is possible that one of these two arrays becomes empty). RedDreamer wants to paint the elements in such a way that f(c) + f(d) is minimum possible.
For example:
* if n = 6, T = 7 and a = [1, 2, 3, 4, 5, 6], it is possible to paint the 1-st, the 4-th and the 5-th elements white, and all other elements black. So c = [1, 4, 5], d = [2, 3, 6], and f(c) + f(d) = 0 + 0 = 0;
* if n = 3, T = 6 and a = [3, 3, 3], it is possible to paint the 1-st element white, and all other elements black. So c = [3], d = [3, 3], and f(c) + f(d) = 0 + 1 = 1.
Help RedDreamer to paint the array optimally!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
The first line of each test case contains two integers n and T (1 ≤ n ≤ 10^5, 0 ≤ T ≤ 10^9) — the number of elements in the array and the unlucky integer, respectively.
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9) — the elements of the array.
The sum of n over all test cases does not exceed 10^5.
Output
For each test case print n integers: p_1, p_2, ..., p_n (each p_i is either 0 or 1) denoting the colors. If p_i is 0, then a_i is white and belongs to the array c, otherwise it is black and belongs to the array d.
If there are multiple answers that minimize the value of f(c) + f(d), print any of them.
Example
Input
2
6 7
1 2 3 4 5 6
3 6
3 3 3
Output
1 0 0 1 1 0
1 0 0
Submitted Solution:
```
def solve(n,t,ar):
color = [0]*n
flag = False
for i in range(n):
if ar[i] >= t:
color[i] = 1
else:
if flag:
color[i] = 1
flag = False
else:
color[i] = 0
flag = True
print(" ".join(map(str, color)))
if __name__ == '__main__':
t = int(input())
for _ in range(t):
n,t = map(int,input().split())
ar = list(map(int,input().split()))
solve(n,t,ar)
``` | instruction | 0 | 4,395 | 7 | 8,790 |
No | output | 1 | 4,395 | 7 | 8,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
RedDreamer has an array a consisting of n non-negative integers, and an unlucky integer T.
Let's denote the misfortune of array b having length m as f(b) — the number of pairs of integers (i, j) such that 1 ≤ i < j ≤ m and b_i + b_j = T. RedDreamer has to paint each element of a into one of two colors, white and black (for each element, the color is chosen independently), and then create two arrays c and d so that all white elements belong to c, and all black elements belong to d (it is possible that one of these two arrays becomes empty). RedDreamer wants to paint the elements in such a way that f(c) + f(d) is minimum possible.
For example:
* if n = 6, T = 7 and a = [1, 2, 3, 4, 5, 6], it is possible to paint the 1-st, the 4-th and the 5-th elements white, and all other elements black. So c = [1, 4, 5], d = [2, 3, 6], and f(c) + f(d) = 0 + 0 = 0;
* if n = 3, T = 6 and a = [3, 3, 3], it is possible to paint the 1-st element white, and all other elements black. So c = [3], d = [3, 3], and f(c) + f(d) = 0 + 1 = 1.
Help RedDreamer to paint the array optimally!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
The first line of each test case contains two integers n and T (1 ≤ n ≤ 10^5, 0 ≤ T ≤ 10^9) — the number of elements in the array and the unlucky integer, respectively.
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9) — the elements of the array.
The sum of n over all test cases does not exceed 10^5.
Output
For each test case print n integers: p_1, p_2, ..., p_n (each p_i is either 0 or 1) denoting the colors. If p_i is 0, then a_i is white and belongs to the array c, otherwise it is black and belongs to the array d.
If there are multiple answers that minimize the value of f(c) + f(d), print any of them.
Example
Input
2
6 7
1 2 3 4 5 6
3 6
3 3 3
Output
1 0 0 1 1 0
1 0 0
Submitted Solution:
```
import sys, math
input = lambda: sys.stdin.readline().rstrip()
def gcd(n, f):
if n == 0 or f == 0:
return max(n, f)
if n > f:
return gcd(n % f, f)
else:
return gcd(f % n, n)
def division_with_remainder_up(pp, ppp):
return (pp + ppp - 1) // ppp
for _ in range(int(input())):
n, t = map(int, input().split())
a = list(map(int, input().split()))
ans = [0] * n
f = True
for i in range(n):
if a[i] < t // 2:
continue
elif a[i] > t // 2:
ans[i] = 1
else:
if f:
continue
else:
ans[i] = 1
print(*ans)
``` | instruction | 0 | 4,396 | 7 | 8,792 |
No | output | 1 | 4,396 | 7 | 8,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
RedDreamer has an array a consisting of n non-negative integers, and an unlucky integer T.
Let's denote the misfortune of array b having length m as f(b) — the number of pairs of integers (i, j) such that 1 ≤ i < j ≤ m and b_i + b_j = T. RedDreamer has to paint each element of a into one of two colors, white and black (for each element, the color is chosen independently), and then create two arrays c and d so that all white elements belong to c, and all black elements belong to d (it is possible that one of these two arrays becomes empty). RedDreamer wants to paint the elements in such a way that f(c) + f(d) is minimum possible.
For example:
* if n = 6, T = 7 and a = [1, 2, 3, 4, 5, 6], it is possible to paint the 1-st, the 4-th and the 5-th elements white, and all other elements black. So c = [1, 4, 5], d = [2, 3, 6], and f(c) + f(d) = 0 + 0 = 0;
* if n = 3, T = 6 and a = [3, 3, 3], it is possible to paint the 1-st element white, and all other elements black. So c = [3], d = [3, 3], and f(c) + f(d) = 0 + 1 = 1.
Help RedDreamer to paint the array optimally!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
The first line of each test case contains two integers n and T (1 ≤ n ≤ 10^5, 0 ≤ T ≤ 10^9) — the number of elements in the array and the unlucky integer, respectively.
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9) — the elements of the array.
The sum of n over all test cases does not exceed 10^5.
Output
For each test case print n integers: p_1, p_2, ..., p_n (each p_i is either 0 or 1) denoting the colors. If p_i is 0, then a_i is white and belongs to the array c, otherwise it is black and belongs to the array d.
If there are multiple answers that minimize the value of f(c) + f(d), print any of them.
Example
Input
2
6 7
1 2 3 4 5 6
3 6
3 3 3
Output
1 0 0 1 1 0
1 0 0
Submitted Solution:
```
for _ in range(int(input())):
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=0;b=[0]*n
for i in range(n):
if a[i]<k//2:
b[i]+=1
elif a[i]==k//2:
if x%2==0:
b[i]+=1
x+=1
print(*b)
``` | instruction | 0 | 4,397 | 7 | 8,794 |
No | output | 1 | 4,397 | 7 | 8,795 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
RedDreamer has an array a consisting of n non-negative integers, and an unlucky integer T.
Let's denote the misfortune of array b having length m as f(b) — the number of pairs of integers (i, j) such that 1 ≤ i < j ≤ m and b_i + b_j = T. RedDreamer has to paint each element of a into one of two colors, white and black (for each element, the color is chosen independently), and then create two arrays c and d so that all white elements belong to c, and all black elements belong to d (it is possible that one of these two arrays becomes empty). RedDreamer wants to paint the elements in such a way that f(c) + f(d) is minimum possible.
For example:
* if n = 6, T = 7 and a = [1, 2, 3, 4, 5, 6], it is possible to paint the 1-st, the 4-th and the 5-th elements white, and all other elements black. So c = [1, 4, 5], d = [2, 3, 6], and f(c) + f(d) = 0 + 0 = 0;
* if n = 3, T = 6 and a = [3, 3, 3], it is possible to paint the 1-st element white, and all other elements black. So c = [3], d = [3, 3], and f(c) + f(d) = 0 + 1 = 1.
Help RedDreamer to paint the array optimally!
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases. Then t test cases follow.
The first line of each test case contains two integers n and T (1 ≤ n ≤ 10^5, 0 ≤ T ≤ 10^9) — the number of elements in the array and the unlucky integer, respectively.
The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9) — the elements of the array.
The sum of n over all test cases does not exceed 10^5.
Output
For each test case print n integers: p_1, p_2, ..., p_n (each p_i is either 0 or 1) denoting the colors. If p_i is 0, then a_i is white and belongs to the array c, otherwise it is black and belongs to the array d.
If there are multiple answers that minimize the value of f(c) + f(d), print any of them.
Example
Input
2
6 7
1 2 3 4 5 6
3 6
3 3 3
Output
1 0 0 1 1 0
1 0 0
Submitted Solution:
```
t = int(input())
for _ in range(t):
n,k = map(int,input().split())
l = list(map(int,input().split()))
g=0
if k%2==0:
h = l.count(k//2)
if h%2==1:
a = h//2+1
b = h//2
for i in l:
if k%2==1 and i<=k//2:
print(0,end=" ")
elif k%2==0 and i<k//2:
print(0,end=" ")
elif i == k//2 and k%2==0:
if a:
print(0,end=" ")
a-=1
else:
print(1,end=" ")
b-=1
else:
print(1,end=" ")
print()
``` | instruction | 0 | 4,398 | 7 | 8,796 |
No | output | 1 | 4,398 | 7 | 8,797 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
Output
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Examples
Input
4 2
aabb
Output
YES
Input
6 3
aacaab
Output
NO
Note
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | instruction | 0 | 4,715 | 7 | 9,430 |
Tags: brute force, implementation
Correct Solution:
```
d = {}
n, k = map(int, input().split())
s = input()
for i in s:
d[i] = d.get(i, 0)+1
# print(d)
m = max(d.values()) #2
for key in d: # a b
if d[key] == m:#
if d[key] > k:
print('NO')
else:
print('YES')
break
# How to count same colored balloons?
# we should count the same colored balloons and then if Samecoloredb <= friends then YES if > then NO
# d = {friends:colors}
``` | output | 1 | 4,715 | 7 | 9,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
Output
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Examples
Input
4 2
aabb
Output
YES
Input
6 3
aacaab
Output
NO
Note
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
Submitted Solution:
```
n,k=map(int,input().split())
a=list(input())
b=list(set(a))
for i in range(len(b)):
if a.count(b[i])>k:
print('NO')
exit()
print('YES')
``` | instruction | 0 | 4,723 | 7 | 9,446 |
Yes | output | 1 | 4,723 | 7 | 9,447 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
Output
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Examples
Input
4 2
aabb
Output
YES
Input
6 3
aacaab
Output
NO
Note
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
Submitted Solution:
```
msg = input().split()
n = int(msg[0])
k = int(msg[1])
msg = input()
msg = sorted(msg)
count = {}
for char in msg:
if char not in count:
count[char] = 1
else:
count[char] += 1
if max(count.values()) > k:
print ('NO')
else:
print ('YES')
``` | instruction | 0 | 4,724 | 7 | 9,448 |
Yes | output | 1 | 4,724 | 7 | 9,449 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
Output
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Examples
Input
4 2
aabb
Output
YES
Input
6 3
aacaab
Output
NO
Note
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
Submitted Solution:
```
n, k = map(int, input().split())
s = list(input())
colors = set(s)
result = 'YES'
if result == 'YES':
for color in colors:
if s.count(color) > k:
result = 'NO'
break
print(result)
``` | instruction | 0 | 4,725 | 7 | 9,450 |
Yes | output | 1 | 4,725 | 7 | 9,451 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
Output
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Examples
Input
4 2
aabb
Output
YES
Input
6 3
aacaab
Output
NO
Note
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
Submitted Solution:
```
##n = int(input())
##a = list(map(int, input().split()))
##print(' '.join(map(str, res)))
[n, k] = list(map(int, input().split()))
s = input()
h = [0 for i in range(26)]
for i in range(n):
h[ord(s[i])-ord('a')] += 1
hmax = 0
for i in range(26):
hmax = max(hmax, h[i])
if hmax > k:
print('NO')
exit(0)
print('YES')
``` | instruction | 0 | 4,726 | 7 | 9,452 |
Yes | output | 1 | 4,726 | 7 | 9,453 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
Output
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Examples
Input
4 2
aabb
Output
YES
Input
6 3
aacaab
Output
NO
Note
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
Submitted Solution:
```
a, b = map(int, input().split())
c = list(input())
d = []
if a == b:
print("YES")
else:
if b * 2 != a:
b -= 1
for i in range(len(c)):
for j in range(len(c)):
if c[i] == c[j] and str(c[i]).isalpha() and str(c[j]).isalpha():
continue
elif c[i] != c[j] and str(c[i]).isalpha() and str(c[j]).isalpha():
d.append(c[i] + c[j])
c.pop(j)
c.insert(j, 1)
c.pop(i)
c.insert(i, 1)
if len(d) >= b:
print("YES")
else:
print("NO")
``` | instruction | 0 | 4,727 | 7 | 9,454 |
No | output | 1 | 4,727 | 7 | 9,455 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
Output
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Examples
Input
4 2
aabb
Output
YES
Input
6 3
aacaab
Output
NO
Note
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
Submitted Solution:
```
n,k = map(int,input().split())
s = input()
s = [s.count(s[i]) for i in range(n) if s[i] not in s[:i]]
c = 0
for i in s:
if i%k!=0 and i>=k:
c+=1
if c==0:
print("YES")
else:
print("NO")
``` | instruction | 0 | 4,728 | 7 | 9,456 |
No | output | 1 | 4,728 | 7 | 9,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
Output
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Examples
Input
4 2
aabb
Output
YES
Input
6 3
aacaab
Output
NO
Note
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
Submitted Solution:
```
# # --- Система регистрации (словарь)---
# keys = int(input())
# names = [input() for row in range(keys)]
# database = dict()
# for i in names:
# if i not in database:
# database[i] = 0
# print('OK')
# else:
# for k, val in database.items():
# if val >= 0 and k == i:
# val += 1
# database[i] = val
# print(k + str(val))
# # print(k + f'{val}')
# # --- Система регистрации (правильное решение)---
# keys = int(input())
# names = [input() for row in range(keys)]
# database = dict()
# for i in names:
# if i in database:
# database[i] += 1
# print(i + str(database[i]))
# else:
# database[i] = 0
# print('OK')
# # --- Single number ---
# nums = [2, 2, 1, 1, 1, 7]
# count = {}
# for i in nums:
# if i in count:
# count[i] += 1
# else:
# count[i] = 1
# for i in count:
# if count[i] == 1:
# print(i)
# # --- Persons ---
# contacts = {
# "John Kennedy": {
# 'birthday': '29 may 1917',
# 'city': 'Brookline',
# 'phone': None,
# 'children': 3
# },
# "Arnold Schwarzenegger": {
# 'birthday': '30 july 1947',
# 'city': 'Gradec',
# 'phone': '555-555-555',
# 'children': 5
# },
# "Donald John Trump": {
# 'birthday': '14 july 1946',
# 'city': 'New York',
# 'phone': '777-777-333',
# 'children': 4
# }
# }
# persons = list(contacts.keys())
# for person in persons:
# print(person)
# for data in contacts[person]:
# print(data, contacts[person][data], sep=': ')
# print()
balls, friends = map(int, input().split())
colours = input().lower()
lucky = 0
repeat = []
# a = 0
for i in range(balls - 1):
if i in repeat:
continue
for j in range(i + 1, balls):
if j in repeat or colours[i] == colours[j]:
continue
else:
repeat.append(j)
lucky += 1
break
if lucky == friends:
break
print('NO' if balls % 2 == 0 and lucky < friends else 'YES')
``` | instruction | 0 | 4,729 | 7 | 9,458 |
No | output | 1 | 4,729 | 7 | 9,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
Output
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Examples
Input
4 2
aabb
Output
YES
Input
6 3
aacaab
Output
NO
Note
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
Submitted Solution:
```
# # --- Система регистрации (словарь)---
# keys = int(input())
# names = [input() for row in range(keys)]
# database = dict()
# for i in names:
# if i not in database:
# database[i] = 0
# print('OK')
# else:
# for k, val in database.items():
# if val >= 0 and k == i:
# val += 1
# database[i] = val
# print(k + str(val))
# # print(k + f'{val}')
# # --- Система регистрации (правильное решение)---
# keys = int(input())
# names = [input() for row in range(keys)]
# database = dict()
# for i in names:
# if i in database:
# database[i] += 1
# print(i + str(database[i]))
# else:
# database[i] = 0
# print('OK')
# # --- Single number ---
# nums = [2, 2, 1, 1, 1, 7]
# count = {}
# for i in nums:
# if i in count:
# count[i] += 1
# else:
# count[i] = 1
# for i in count:
# if count[i] == 1:
# print(i)
# # --- Persons ---
# contacts = {
# "John Kennedy": {
# 'birthday': '29 may 1917',
# 'city': 'Brookline',
# 'phone': None,
# 'children': 3
# },
# "Arnold Schwarzenegger": {
# 'birthday': '30 july 1947',
# 'city': 'Gradec',
# 'phone': '555-555-555',
# 'children': 5
# },
# "Donald John Trump": {
# 'birthday': '14 july 1946',
# 'city': 'New York',
# 'phone': '777-777-333',
# 'children': 4
# }
# }
# persons = list(contacts.keys())
# for person in persons:
# print(person)
# for data in contacts[person]:
# print(data, contacts[person][data], sep=': ')
# print()
balls, friends = map(int, input().split())
colours = input().lower()
lucky = 0
repeat = []
# a = 0
for i in range(balls - 1):
if i in repeat:
continue
for j in range(i + 1, balls):
if j in repeat or colours[i] == colours[j]:
continue
else:
repeat.append(j)
lucky += 1
break
if lucky == friends:
break
print('YES' if lucky >= friends or lucky * 2 == balls else 'NO')
``` | instruction | 0 | 4,730 | 7 | 9,460 |
No | output | 1 | 4,730 | 7 | 9,461 |
Provide a correct Python 3 solution for this coding contest problem.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001 | instruction | 0 | 4,907 | 7 | 9,814 |
"Correct Solution:
```
N = int(input())
Ball = []
for i in range(N):
x, y = map(int, input().split())
x, y = min(x, y), max(x, y)
Ball.append((x, y))
Ball.sort() # ソートしておく
X = [x for x, y in Ball]
Y = [y for x, y in Ball]
# 全体のMIN, MAX
MIN = X[0]
MAX = max(Y)
# 確定2玉を別グループに
ans = (max(X) - MIN) * (MAX - min(Y))
# 確定2玉を同じグループに
# 全体のMAX・MINが確定している場所は、もう片方を使うしかない
MIN_index, MAX_index = X.index(MIN), Y.index(MAX)
# 選ばざるを得ないやつ
MIN_O = X[MAX_index]
MAX_O = Y[MIN_index]
MIN_O, MAX_O = min(MIN_O, MAX_O), max(MIN_O, MAX_O)
# 選択肢がないやつを削除
Ball = [Ball[i] for i in range(N) if i not in (MIN_index, MAX_index)]
# つくりおし
X = [x for x, y in Ball]
Y = [y for x, y in Ball]
# とりあえず小さいほうを集めたことにしておく
B = [x for x in X] + [MAX_O, MIN_O]
B_max = max(B)
for i in range(len(Ball)):
x, y = X[i], Y[i]
if B_max - x > B_max - y >= 0:
B[i] = y
else:
break
ans = min(ans, (MAX - MIN) * (max(B) - min(B)))
print(ans)
``` | output | 1 | 4,907 | 7 | 9,815 |
Provide a correct Python 3 solution for this coding contest problem.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001 | instruction | 0 | 4,908 | 7 | 9,816 |
"Correct Solution:
```
import sys
from operator import itemgetter
inf = 1 << 30
def solve():
n = int(sys.stdin.readline())
# r_max = MAX, b_min = MIN にしたとき
r_max = b_max = 0
r_min = b_min = inf
p = []
for i in range(n):
xi, yi = map(int, sys.stdin.readline().split())
if xi > yi:
xi, yi = yi, xi
p.append((xi, yi))
r_max = max(r_max, yi)
r_min = min(r_min, yi)
b_max = max(b_max, xi)
b_min = min(b_min, xi)
ans1 = (r_max - r_min) * (b_max - b_min)
# r_max = MAX, r_min = MIN にしたとき
ans2 = (r_max - b_min)
p.sort(key=itemgetter(0))
b_min = p[0][0]
b_max = p[-1][0]
y_min = inf
dif_b = b_max - b_min
for i in range(n - 1):
y_min = min(y_min, p[i][1])
b_min = min(p[i + 1][0], y_min)
b_max = max(b_max, p[i][1])
dif_b = min(dif_b, b_max - b_min)
ans2 *= dif_b
ans = min(ans1, ans2)
print(ans)
if __name__ == '__main__':
solve()
``` | output | 1 | 4,908 | 7 | 9,817 |
Provide a correct Python 3 solution for this coding contest problem.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001 | instruction | 0 | 4,909 | 7 | 9,818 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def main():
inf = 10 ** 10
n = II()
xy = [LI() for _ in range(n)]
xy = [[x, y] if x < y else [y, x] for x, y in xy]
xy.sort()
yy=[y for x,y in xy]
xmin=xy[0][0]
xmax=xy[-1][0]
ymax = max(yy)
ymin = min(yy)
ans=(xmax-xmin)*(ymax-ymin)
d=ymax-xmin
ymin = inf
for i in range(n - 1):
y = xy[i][1]
if y < ymin: ymin = y
xmin = min(xy[i + 1][0], ymin)
xmax = max(xmax, y)
ans = min(ans, (xmax - xmin) * d)
print(ans)
main()
``` | output | 1 | 4,909 | 7 | 9,819 |
Provide a correct Python 3 solution for this coding contest problem.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001 | instruction | 0 | 4,910 | 7 | 9,820 |
"Correct Solution:
```
import sys
input=sys.stdin.readline
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
l[i].sort()
ans=[]
l.sort()
B1=[];R1=[]
for i in range(n):
B1.append(l[i][0])
R1.append(l[i][1])
ans.append((max(B1)-min(B1))*(max(R1)-min(R1)))
Bleft=[]
Bright=[]
Rleft=[]
Rright=[]
M=B1[0];m=B1[0]
Bleft.append([m,M])
for i in range(1,n):
M=max(M,B1[i])
m=min(m,B1[i])
Bleft.append([m,M])
B1.reverse()
M=B1[0];m=B1[0]
Bright.append([m,M])
for i in range(1,n):
M=max(M,B1[i])
m=min(m,B1[i])
Bright.append([m,M])
M=R1[0];m=R1[0]
Rleft.append([m,M])
for i in range(1,n):
M=max(M,R1[i])
m=min(m,R1[i])
Rleft.append([m,M])
R1.reverse()
M=R1[0];m=R1[0]
Rright.append([m,M])
for i in range(1,n):
M=max(M,R1[i])
m=min(m,R1[i])
Rright.append([m,M])
for i in range(n-1):
M1=max(Bleft[i][1],Rright[n-2-i][1])
m1=min(Bleft[i][0],Rright[n-2-i][0])
M2=max(Rleft[i][1],Bright[n-2-i][1])
m2=min(Rleft[i][0],Bright[n-2-i][0])
ans.append((M1-m1)*(M2-m2))
print(min(ans))
``` | output | 1 | 4,910 | 7 | 9,821 |
Provide a correct Python 3 solution for this coding contest problem.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001 | instruction | 0 | 4,911 | 7 | 9,822 |
"Correct Solution:
```
import sys
from operator import itemgetter
inf = 1 << 30
def solve():
n = int(sys.stdin.readline())
# r_max = MAX, b_min = MIN にしたとき
r_max = b_max = 0
r_min = b_min = inf
p = []
for i in range(n):
xi, yi = map(int, sys.stdin.readline().split())
if xi > yi:
xi, yi = yi, xi
p.append((xi, yi))
r_max = max(r_max, yi)
r_min = min(r_min, yi)
b_max = max(b_max, xi)
b_min = min(b_min, xi)
ans1 = (r_max - r_min) * (b_max - b_min)
# r_max = MAX, r_min = MIN にしたとき
ans2 = (r_max - b_min)
p.sort(key=itemgetter(0))
b_min = p[0][0]
b_max = p[-1][0]
y_min = inf
dif_b = b_max - b_min
for i in range(n - 1):
if p[i][1] == r_max:
break
y_min = min(y_min, p[i][1])
b_min = min(p[i + 1][0], y_min)
b_max = max(b_max, p[i][1])
dif_b = min(dif_b, b_max - b_min)
ans2 *= dif_b
ans = min(ans1, ans2)
print(ans)
if __name__ == '__main__':
solve()
``` | output | 1 | 4,911 | 7 | 9,823 |
Provide a correct Python 3 solution for this coding contest problem.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001 | instruction | 0 | 4,912 | 7 | 9,824 |
"Correct Solution:
```
# coding: utf-8
# 整数の入力
#a = int(raw_input())
# スペース区切りの整数の入力
import heapq
N = int(input())
Rmax = 0
Rmin = 1000000001
Bmax = 0
Bmin = 1000000001
data = sorted([sorted(list(map(int, input().split()))) for i in range(N)],key=lambda x:x[0])
tempBlues = sorted([d[1] for d in data])
tempReds = [d[0] for d in data]
heapq.heapify(tempReds)
Rmin = data[0][0]
Rmax = data[N-1][0]
Bmax = max(tempBlues)
Bmin = min(tempBlues)
minValue = (Rmax - Rmin)*(Bmax - Bmin)
Bmin = Rmin
for i in range(N):
heapMin = heapq.heappop(tempReds)
if heapMin == data[i][0]:
heapq.heappush(tempReds, data[i][1])
if data[i][1] > Rmax:
Rmax = data[i][1]
if (Rmax - tempReds[0])*(Bmax - Bmin) < minValue:
minValue = (Rmax - tempReds[0])*(Bmax - Bmin)
else:
break
print(minValue)
``` | output | 1 | 4,912 | 7 | 9,825 |
Provide a correct Python 3 solution for this coding contest problem.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001 | instruction | 0 | 4,913 | 7 | 9,826 |
"Correct Solution:
```
n=int(input())
x,y=zip(*sorted(sorted(map(int,input().split())) for _ in range(n)))
p=max(range(n),key=lambda i:y[i])
r=a=x[-1]
b=d=10**9
for i in range(p):
a=max(a,y[i])
b=min(b,y[i])
d=min(d,a-min(b,x[i+1]))
print(min((x[-1]-x[0])*(y[p]-min(y)),(y[p]-x[0])*d))
``` | output | 1 | 4,913 | 7 | 9,827 |
Provide a correct Python 3 solution for this coding contest problem.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001 | instruction | 0 | 4,914 | 7 | 9,828 |
"Correct Solution:
```
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n, = map(int,readline().split())
xy = []
for _ in range(n):
x,y = map(int,readline().split())
if x>y: x,y = y,x
xy.append((x,y))
xy.sort()
xx = []
yy = []
for x,y in xy:
xx.append(x)
yy.append(y)
ymaxr = yy[:]
for i in range(n-2,-1,-1):
ymaxr[i] = max(ymaxr[i],ymaxr[i+1])
ymaxl= yy[:]
for i in range(1,n):
ymaxl[i] = max(ymaxl[i],ymaxl[i-1])
ymin = yy[:]
for i in range(1,n):
ymin[i] = min(ymin[i],ymin[i-1])
#print(yy)
#print(ymaxl)
#print(ymaxr)
#print(ymin)
#print(xx,yy)
ans = 1<<60
for i in range(n):
mr = xx[0]
Mr = xx[i]
if i != n-1: Mr = max(Mr,ymaxr[i+1])
mb = ymin[i]
if i != n-1: mb = min(mb,xx[i+1])
Mb = ymaxl[i]
if i != n-1: Mb = max(Mb,xx[n-1])
#print(i,mr,Mr,mb,Mb)
ans = min(ans,(Mr-mr)*(Mb-mb))
print(ans)
``` | output | 1 | 4,914 | 7 | 9,829 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
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 main():
n = I()
a = sorted([sorted(LI()) + [_] for _ in range(n)])
b = sorted(a, key=lambda x: x[1])
r = (a[-1][0]-a[0][0]) * (b[-1][1]-b[0][1])
bm = b[-1][1] - a[0][0]
bmi = b[0][2]
am = a[-1][1]
at = 0
k = [[inf,0]]
for i in range(n-1):
kk = []
kk.append(min(k[-1][0], b[i][0], b[i+1][1]))
kk.append(max(k[-1][1], b[i][0]))
if kk[0] == k[-1][0]:
k[-1][1] = kk[1]
else:
k.append(kk)
k = k[1:]
kl = len(k)
am = b[-1][1] - a[0][0]
ami = a[0][2]
bm = 0
mtm = 0
bt = b[0][1]
for i in range(n-1,0,-1):
tm = b[i][0]
if mtm < tm:
mtm = tm
if ami == b[i][2]:
break
if tm < bt:
bt = tm
if tm < b[i-1][1]:
tm = b[i-1][1]
bm = mtm
if tm > bm:
bm = tm
tr = am * (bm-bt)
if r > tr:
r = tr
for j in range(kl):
ki,km = k[j]
if km > bm:
break
tr = am * (bm-min(ki,bt))
if r > tr:
r = tr
return r
print(main())
``` | instruction | 0 | 4,915 | 7 | 9,830 |
Yes | output | 1 | 4,915 | 7 | 9,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001
Submitted Solution:
```
import sys
input = sys.stdin.readline
N=int(input())
A=[]
C=[]
D=[]
for i in range(N):
a,b=map(int,input().split())
c,d=min(a,b),max(a,b)
A.append((c,d))
C.append(c)
D.append(d)
A.sort()
#print(A,C,D,si,ti)
if N==1:
print(0)
sys.exit()
ans=(max(C)-min(C))*(max(D)-min(D))
cur=max(C)
ma=min(D)
T=10**19
for a,b in A:
if a>ma:
T=min(T,cur-ma)
break
T=min(T,cur-a)
cur=max(cur,b)
print(min(ans,(max(D)-min(C))*T))
``` | instruction | 0 | 4,916 | 7 | 9,832 |
Yes | output | 1 | 4,916 | 7 | 9,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001
Submitted Solution:
```
N = int(input())
xmin = ymin = float('inf')
xmax = ymax = 0
p = []
for i in range(N):
x,y = map(int, input().split())
if x > y :
x,y= y,x
p.append((x, y))
if x < xmin:
xmin = x
elif x > xmax:
xmax = x
if y < ymin:
ymin = y
elif y > ymax:
ymax = y
ret = (ymax-ymin) * (xmax-xmin)
p.sort()
dx = p[-1][0] - p[0][0]
ymin = p[0][0]
tymin = float('inf')
tymax = 0
for i in range(N-1):
# print(i, dx, (xmax, xmin), end=' ==> ')
tymin = min(tymin, p[i][1])
xmax = max(xmax, p[i][1])
xmin = min(tymin, p[i+1][0])
dx = min(dx, xmax - xmin)
# print(i, dx, (xmax, xmin))
# print(ret, (ymax-ymin) * (xmax-xmin) ,(ymax,ymin), (xmax,xmin), dx)
print(min(ret, (ymax-ymin) * dx))
``` | instruction | 0 | 4,917 | 7 | 9,834 |
Yes | output | 1 | 4,917 | 7 | 9,835 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001
Submitted Solution:
```
import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
X = []
mih, mah, mil, mal = 10 ** 9, 0, 10 ** 9, 0
for _ in range(N):
x, y = map(int, input().split())
x, y = min(x, y), max(x, y)
X.append((x, y))
mih = min(mih, y)
mah = max(mah, y)
mil = min(mil, x)
mal = max(mal, x)
ans = (mal - mil) * (mah - mih)
Y = []
for x, y in X:
if mih <= x <= mal or mih <= y <= mal:
continue
Y.append((x, y))
Y = sorted(Y, key = lambda a: a[0])
Z = [(0, mal)]
may = 0
for x, y in Y:
if y > may:
Z.append((x, y))
may = y
Z.append((mih, 10 ** 9))
for i in range(len(Z) - 1):
ans = min(ans, (Z[i][1] - Z[i+1][0]) * (mah - mil))
print(ans)
``` | instruction | 0 | 4,918 | 7 | 9,836 |
Yes | output | 1 | 4,918 | 7 | 9,837 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001
Submitted Solution:
```
N = int(input())
xmin = ymin = float('inf')
xmax = ymax = 0
p = []
for i in range(N):
x,y = map(int, input().split())
if x > y :
x,y= y,x
p.append((x, y))
if x < xmin:
xmin = x
elif x > xmax:
xmax = x
if y < ymin:
ymin = y
elif y > ymax:
ymax = y
ret = (ymax-ymin) * (xmax-xmin)
p.sort()
dx = p[-1][0] - p[0][0]
tymin = float('inf')
tymax = 0
for i in range(N-1):
# print(i, dx, xmax,xmin)
tymin = min(tymin, p[i][1])
xmax = max(xmax, p[i][1])
xmin = min(tymin, p[i+1][1])
ymin = min(ymin, p[i][0])
dx = min(dx, xmax - xmin)
# print(ret, (ymax-ymin) * (xmax-xmin) ,(ymax,ymin), (xmax,xmin))
print(min(ret, (ymax-ymin) * (xmax-xmin)))
``` | instruction | 0 | 4,919 | 7 | 9,838 |
No | output | 1 | 4,919 | 7 | 9,839 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001
Submitted Solution:
```
Rmax = 0
Rmin = 1000000000
Bmax = 0
Bmin = 1000000000
N = int(input())
xs = []
ys = []
arr = []
for i in range(N):
x, y = map(int, input().split())
xs.append(x)
ys.append(y)
arr.append((max(x, y) / min(x, y), min(x, y), max(x, y)))
arr = list(sorted(arr))
for (_, x, y) in arr:
Rmin0 = min(Rmin, x)
Rmax0 = max(Rmax, x)
Bmin0 = min(Bmin, y)
Bmax0 = max(Bmax, y)
p0 = (Rmax0 - Rmin0) * (Bmax0 - Bmin0)
Rmin1 = min(Rmin, y)
Rmax1 = max(Rmax, y)
Bmin1 = min(Bmin, x)
Bmax1 = max(Bmax, x)
p1 = (Rmax1 - Rmin1) * (Bmax1 - Bmin1)
if p0 <= p1:
Rmin = Rmin0
Rmax = Rmax0
Bmin = Bmin0
Bmax = Bmax0
else:
Rmin = Rmin1
Rmax = Rmax1
Bmin = Bmin1
Bmax = Bmax1
ans = (Rmax - Rmin) * (Bmax - Bmin)
print(ans)
``` | instruction | 0 | 4,920 | 7 | 9,840 |
No | output | 1 | 4,920 | 7 | 9,841 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001
Submitted Solution:
```
from bisect import insort
n=int(input())
x,y,p=[],[],[]
for i in range(n):
a,b=map(int,input().split())
if a > b: a,b=b,a
x.append(a)
y.append(b)
p.append((a,i,True))
p.append((b,i,False))
p.sort()
ans=(max(x)-min(x))*(max(y)-min(y))
if p[0][1] != p[-1][1]:
raise ValueError
print(ans)
``` | instruction | 0 | 4,921 | 7 | 9,842 |
No | output | 1 | 4,921 | 7 | 9,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the 2N balls will be classified according to color.
Then, we will define the following:
* R_{max}: the maximum integer written on a ball painted in red
* R_{min}: the minimum integer written on a ball painted in red
* B_{max}: the maximum integer written on a ball painted in blue
* B_{min}: the minimum integer written on a ball painted in blue
Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
Constraints
* 1 ≤ N ≤ 200,000
* 1 ≤ x_i, y_i ≤ 10^9
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the minimum possible value.
Examples
Input
3
1 2
3 4
5 6
Output
15
Input
3
1010 10
1000 1
20 1020
Output
380
Input
2
1 1
1000000000 1000000000
Output
999999998000000001
Submitted Solution:
```
import sys
def input():
return sys.stdin.readline()[:-1]
n = int(input())
d = []
M, m = 0, 10**30
M_of_m, m_of_M = 0, 10**30
for _ in range(n):
x, y = map(int, input().split())
g, l = max(x, y), min(x, y)
d.append([l, g])
M = max(M, g)
m = min(m, l)
M_of_m = max(M_of_m, l)
m_of_M = min(m_of_M, g)
ans1 = (M - m_of_M) * (M_of_m - m)
M_other, m_other = M_of_m, m
gap = M_other - m_other
d.sort(key=min)
for i in range(n-1):
M_other = max(M_other, d[i][1])
if m_other == d[i][0]:
m_other = min(d[i][1], d[i+1][0])
gap = min(gap, M_other - m_other)
M_other = max(M_other, d[n-1][1])
gap = min(gap, M_other - m_other)
ans2 = (M - m) * gap
#print(ans1, ans2)
print(min(ans1, ans2))
``` | instruction | 0 | 4,922 | 7 | 9,844 |
No | output | 1 | 4,922 | 7 | 9,845 |
Provide a correct Python 3 solution for this coding contest problem.
We have an N×N checkerboard.
From the square at the upper left corner, a square that is i squares to the right and j squares below is denoted as (i, j). Particularly, the square at the upper left corner is denoted as (0, 0).
Each square (i, j) such that i+j is even, is colored black, and the other squares are colored white.
We will satisfy the following condition by painting some of the white squares:
* Any black square can be reached from square (0, 0) by repeatedly moving to a black square that shares a side with the current square.
Achieve the objective by painting at most 170000 squares black.
Constraints
* 1 \leq N \leq 1,000
Input
The input is given from Standard Input in the following format:
N
Output
Print the squares to paint in the following format:
K
x_1 y_1
x_2 y_2
:
x_K y_K
This means that a total of K squares are painted black, the i-th of which is (x_i, y_i).
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 0 \leq K \leq 170000
* 0 \leq x_i, y_i \leq N-1
* For each i, x_i + y_i is odd.
* If i \neq j, then (x_i, y_i) \neq (x_j, y_j).
* The condition in the statement is satisfied by painting all specified squares.
Examples
Input
2
Output
1
1 0
Input
4
Output
3
0 1
2 1
2 3 | instruction | 0 | 4,923 | 7 | 9,846 |
"Correct Solution:
```
N = int(input())
MAX = 170000
ans = []
for i in range(1,N,2):
for j in range(0,N,2):
if (i//2)%3 == 0:
ans.append((i,j))
elif (i//2)%3 == 1:
if (j//2)%2 == 0: ans.append((i,j))
else:
if (j//2)%2 == 1: ans.append((i,j))
for i in [0,N-1]:
for j in range(N):
if (i+j)%2:
ans.append((i,j))
ans.append((j,i))
ans = set(ans)
print(len(ans))
for x,y in ans:
print('{0} {1}'.format(x,y))
#v = [['.' if (i+j)%2 else '#' for j in range(N)] for i in range(N)]
#for x,y in ans:
# if (i+j)%2: raise
# v[x][y] = 'a'
#for row in v:
# print(''.join(row))
``` | output | 1 | 4,923 | 7 | 9,847 |
Provide a correct Python 3 solution for this coding contest problem.
We have an N×N checkerboard.
From the square at the upper left corner, a square that is i squares to the right and j squares below is denoted as (i, j). Particularly, the square at the upper left corner is denoted as (0, 0).
Each square (i, j) such that i+j is even, is colored black, and the other squares are colored white.
We will satisfy the following condition by painting some of the white squares:
* Any black square can be reached from square (0, 0) by repeatedly moving to a black square that shares a side with the current square.
Achieve the objective by painting at most 170000 squares black.
Constraints
* 1 \leq N \leq 1,000
Input
The input is given from Standard Input in the following format:
N
Output
Print the squares to paint in the following format:
K
x_1 y_1
x_2 y_2
:
x_K y_K
This means that a total of K squares are painted black, the i-th of which is (x_i, y_i).
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 0 \leq K \leq 170000
* 0 \leq x_i, y_i \leq N-1
* For each i, x_i + y_i is odd.
* If i \neq j, then (x_i, y_i) \neq (x_j, y_j).
* The condition in the statement is satisfied by painting all specified squares.
Examples
Input
2
Output
1
1 0
Input
4
Output
3
0 1
2 1
2 3 | instruction | 0 | 4,924 | 7 | 9,848 |
"Correct Solution:
```
n=int(input())
ans=[]
for i in range(n-1):
if i%2:
ans+=[(i,0)]
for i in range(n-1):
if i%6==1:
for j in range(2,n):
if j%2==0:
ans+=[(i,j)]
if i%6==4:
for j in range(n):
if j%2:
ans+=[(i,j)]
for j in range(n):
if(n-1+j)%2:
ans+=[(n-1,j)]
print(len(ans))
for x,y in ans:
print(x,y)
``` | output | 1 | 4,924 | 7 | 9,849 |
Provide a correct Python 3 solution for this coding contest problem.
We have an N×N checkerboard.
From the square at the upper left corner, a square that is i squares to the right and j squares below is denoted as (i, j). Particularly, the square at the upper left corner is denoted as (0, 0).
Each square (i, j) such that i+j is even, is colored black, and the other squares are colored white.
We will satisfy the following condition by painting some of the white squares:
* Any black square can be reached from square (0, 0) by repeatedly moving to a black square that shares a side with the current square.
Achieve the objective by painting at most 170000 squares black.
Constraints
* 1 \leq N \leq 1,000
Input
The input is given from Standard Input in the following format:
N
Output
Print the squares to paint in the following format:
K
x_1 y_1
x_2 y_2
:
x_K y_K
This means that a total of K squares are painted black, the i-th of which is (x_i, y_i).
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 0 \leq K \leq 170000
* 0 \leq x_i, y_i \leq N-1
* For each i, x_i + y_i is odd.
* If i \neq j, then (x_i, y_i) \neq (x_j, y_j).
* The condition in the statement is satisfied by painting all specified squares.
Examples
Input
2
Output
1
1 0
Input
4
Output
3
0 1
2 1
2 3 | instruction | 0 | 4,925 | 7 | 9,850 |
"Correct Solution:
```
n = int(input())
ans_list = []
for i in range(n):
if i % 2 == 1:
ans_list.append((i,0))
if i % 6 == 1:
for j in range(2,n,2):
ans_list.append((i,j))
elif i % 6 == 4:
for j in range(1,n,2):
ans_list.append((i,j))
if n % 3 != 2:
for i in range(1,n):
if (n - 1 + i) % 2 == 1:
ans_list.append((n-1,i))
print(len(ans_list))
for i in ans_list:
print(*i)
``` | output | 1 | 4,925 | 7 | 9,851 |
Provide a correct Python 3 solution for this coding contest problem.
We have an N×N checkerboard.
From the square at the upper left corner, a square that is i squares to the right and j squares below is denoted as (i, j). Particularly, the square at the upper left corner is denoted as (0, 0).
Each square (i, j) such that i+j is even, is colored black, and the other squares are colored white.
We will satisfy the following condition by painting some of the white squares:
* Any black square can be reached from square (0, 0) by repeatedly moving to a black square that shares a side with the current square.
Achieve the objective by painting at most 170000 squares black.
Constraints
* 1 \leq N \leq 1,000
Input
The input is given from Standard Input in the following format:
N
Output
Print the squares to paint in the following format:
K
x_1 y_1
x_2 y_2
:
x_K y_K
This means that a total of K squares are painted black, the i-th of which is (x_i, y_i).
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 0 \leq K \leq 170000
* 0 \leq x_i, y_i \leq N-1
* For each i, x_i + y_i is odd.
* If i \neq j, then (x_i, y_i) \neq (x_j, y_j).
* The condition in the statement is satisfied by painting all specified squares.
Examples
Input
2
Output
1
1 0
Input
4
Output
3
0 1
2 1
2 3 | instruction | 0 | 4,926 | 7 | 9,852 |
"Correct Solution:
```
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
added = [0] * n
for i in range(2, n+1, 2):
ans.append((1, i))
for i in range(2, n+1, 3):
if i % 2 == 0:
for item in odd:
ans.append((item, i))
else:
for item in even:
ans.append((item, i))
for i in range(n, 0, -1):
if (i - 2) % 3 == 0:
continue
if i % 2 == 0:
for item in odd:
ans.append((item, i))
break
ans.sort()
print(len(ans))
for a, b in ans:
print(a - 1, b - 1)
``` | output | 1 | 4,926 | 7 | 9,853 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an N×N checkerboard.
From the square at the upper left corner, a square that is i squares to the right and j squares below is denoted as (i, j). Particularly, the square at the upper left corner is denoted as (0, 0).
Each square (i, j) such that i+j is even, is colored black, and the other squares are colored white.
We will satisfy the following condition by painting some of the white squares:
* Any black square can be reached from square (0, 0) by repeatedly moving to a black square that shares a side with the current square.
Achieve the objective by painting at most 170000 squares black.
Constraints
* 1 \leq N \leq 1,000
Input
The input is given from Standard Input in the following format:
N
Output
Print the squares to paint in the following format:
K
x_1 y_1
x_2 y_2
:
x_K y_K
This means that a total of K squares are painted black, the i-th of which is (x_i, y_i).
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 0 \leq K \leq 170000
* 0 \leq x_i, y_i \leq N-1
* For each i, x_i + y_i is odd.
* If i \neq j, then (x_i, y_i) \neq (x_j, y_j).
* The condition in the statement is satisfied by painting all specified squares.
Examples
Input
2
Output
1
1 0
Input
4
Output
3
0 1
2 1
2 3
Submitted Solution:
```
n = int(input())
ans_list = []
for i in range(n):
if i % 2 == 1:
ans_list.append((i,0))
if i % 6 == 1:
for j in range(2,n,2):
ans_list.append((i,j))
elif i % 6 == 4:
for j in range(1,n,2):
ans_list.append((i,j))
print(len(ans_list))
for i in ans_list:
print(*i)
``` | instruction | 0 | 4,927 | 7 | 9,854 |
No | output | 1 | 4,927 | 7 | 9,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an N×N checkerboard.
From the square at the upper left corner, a square that is i squares to the right and j squares below is denoted as (i, j). Particularly, the square at the upper left corner is denoted as (0, 0).
Each square (i, j) such that i+j is even, is colored black, and the other squares are colored white.
We will satisfy the following condition by painting some of the white squares:
* Any black square can be reached from square (0, 0) by repeatedly moving to a black square that shares a side with the current square.
Achieve the objective by painting at most 170000 squares black.
Constraints
* 1 \leq N \leq 1,000
Input
The input is given from Standard Input in the following format:
N
Output
Print the squares to paint in the following format:
K
x_1 y_1
x_2 y_2
:
x_K y_K
This means that a total of K squares are painted black, the i-th of which is (x_i, y_i).
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 0 \leq K \leq 170000
* 0 \leq x_i, y_i \leq N-1
* For each i, x_i + y_i is odd.
* If i \neq j, then (x_i, y_i) \neq (x_j, y_j).
* The condition in the statement is satisfied by painting all specified squares.
Examples
Input
2
Output
1
1 0
Input
4
Output
3
0 1
2 1
2 3
Submitted Solution:
```
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
for i in range(2, n+1, 2):
ans.append((1, i))
for i in range(2, n+1, 3):
if i % 2 == 0:
for item in odd:
ans.append((item, i))
else:
for item in even:
ans.append((item, i))
for i in range(n, -1, -1):
if i % 2 == 0 and (i // 2) % 2 == 0:
for item in odd:
ans.append((item, i))
break
print(len(ans))
for a, b in ans:
print(a - 1, b - 1)
``` | instruction | 0 | 4,928 | 7 | 9,856 |
No | output | 1 | 4,928 | 7 | 9,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an N×N checkerboard.
From the square at the upper left corner, a square that is i squares to the right and j squares below is denoted as (i, j). Particularly, the square at the upper left corner is denoted as (0, 0).
Each square (i, j) such that i+j is even, is colored black, and the other squares are colored white.
We will satisfy the following condition by painting some of the white squares:
* Any black square can be reached from square (0, 0) by repeatedly moving to a black square that shares a side with the current square.
Achieve the objective by painting at most 170000 squares black.
Constraints
* 1 \leq N \leq 1,000
Input
The input is given from Standard Input in the following format:
N
Output
Print the squares to paint in the following format:
K
x_1 y_1
x_2 y_2
:
x_K y_K
This means that a total of K squares are painted black, the i-th of which is (x_i, y_i).
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 0 \leq K \leq 170000
* 0 \leq x_i, y_i \leq N-1
* For each i, x_i + y_i is odd.
* If i \neq j, then (x_i, y_i) \neq (x_j, y_j).
* The condition in the statement is satisfied by painting all specified squares.
Examples
Input
2
Output
1
1 0
Input
4
Output
3
0 1
2 1
2 3
Submitted Solution:
```
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
added = [0] * n
for i in range(2, n+1, 2):
ans.append((1, i))
for i in range(2, n+1, 3):
if i % 2 == 0:
for item in odd:
ans.append((item, i))
else:
for item in even:
ans.append((item, i))
for i in range(n, 0, -1):
if (i - 2) % 3 == 0:
continue
if i % 2 == 0:
for item in odd:
ans.append((item, i))
ans.sort()
print(len(ans))
for a, b in ans:
print(a - 1, b - 1)
``` | instruction | 0 | 4,929 | 7 | 9,858 |
No | output | 1 | 4,929 | 7 | 9,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an N×N checkerboard.
From the square at the upper left corner, a square that is i squares to the right and j squares below is denoted as (i, j). Particularly, the square at the upper left corner is denoted as (0, 0).
Each square (i, j) such that i+j is even, is colored black, and the other squares are colored white.
We will satisfy the following condition by painting some of the white squares:
* Any black square can be reached from square (0, 0) by repeatedly moving to a black square that shares a side with the current square.
Achieve the objective by painting at most 170000 squares black.
Constraints
* 1 \leq N \leq 1,000
Input
The input is given from Standard Input in the following format:
N
Output
Print the squares to paint in the following format:
K
x_1 y_1
x_2 y_2
:
x_K y_K
This means that a total of K squares are painted black, the i-th of which is (x_i, y_i).
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 0 \leq K \leq 170000
* 0 \leq x_i, y_i \leq N-1
* For each i, x_i + y_i is odd.
* If i \neq j, then (x_i, y_i) \neq (x_j, y_j).
* The condition in the statement is satisfied by painting all specified squares.
Examples
Input
2
Output
1
1 0
Input
4
Output
3
0 1
2 1
2 3
Submitted Solution:
```
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
for i in range(2, n+1, 2):
ans.append((1, i))
for i in range(2, n+1, 3):
if i % 2 == 0:
for item in odd:
ans.append((item, i))
else:
for item in even:
ans.append((item, i))
if n % 4 == 0:
for i in range(n, -1, -1):
if i % 2 == 0 and (i // 2) % 2 == 0:
for item in odd:
ans.append((item, i))
break
print(len(ans))
for a, b in ans:
print(a - 1, b - 1)
``` | instruction | 0 | 4,930 | 7 | 9,860 |
No | output | 1 | 4,930 | 7 | 9,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white). | instruction | 0 | 5,145 | 7 | 10,290 |
Tags: greedy, math
Correct Solution:
```
n=int(input())
s=list(input())
b=[]
a=[]
for i in range(n):
a.append(s[i])
b.append(s[i])
c=[]
for i in range(n-1):
if(a[i]=="W"):
continue
else:
a[i]="W"
c.append(i+1)
if(a[i+1]=="W"):
a[i+1]="B"
else:
a[i+1]="W"
if(a.count("W")==n):
print(len(c))
print(*c)
else:
d=[]
for i in range(n-1):
if(b[i]=="B"):
continue
else:
b[i]="B"
d.append(i+1)
if(b[i+1]=="W"):
b[i+1]="B"
else:
b[i+1]="W"
if(b.count("B")==n):
print(len(d))
print(*d)
else:
print(-1)
``` | output | 1 | 5,145 | 7 | 10,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white). | instruction | 0 | 5,146 | 7 | 10,292 |
Tags: greedy, math
Correct Solution:
```
# HEY STALKER
from collections import Counter
n = int(input())
l = list(input())
x = Counter(l)
if x['B'] % 2 and x['W'] % 2:
print(-1)
elif x['B'] == n or x['W'] == n:
print(0)
else:
k = []
b = ''
w = ''
if not x['B'] % 2:
b = 'B'
w = 'W'
else:
b = 'W'
w = 'B'
t = 0
while t < n-1:
if l[t] == b:
if l[t+1] == b:
k.append(t+1)
l[t] = w
l[t+1] = w
elif l[t+1] == w:
k.append(t+1)
l[t] = w
l[t+1] = b
t += 1
print(len(k))
print(*k)
``` | output | 1 | 5,146 | 7 | 10,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white). | instruction | 0 | 5,147 | 7 | 10,294 |
Tags: greedy, math
Correct Solution:
```
n=int(input())
s=list(input())
x='B'
def check(l):
prev=l[0]
for i in range(len(l)):
if l[i]!=prev:
return False
return True
count=0
ans=[i for i in s]
l=[]
for i in range(n-1):
if s[i]!=x:
s[i]=x
if s[i+1]=='B':
s[i+1]='W'
else:
s[i+1]='B'
l.append(i+1)
count+=1
if count<=3*n and check(s):
print(count)
print(*l)
else:
x='W'
count=0
l=[]
s=[i for i in ans]
for i in range(n-1):
if s[i]!=x:
s[i]=x
if s[i+1]=='B':
s[i+1]='W'
else:
s[i+1]='B'
l.append(i+1)
count+=1
if count<=3*n and check(s):
print(count)
print(*l)
else:
print(-1)
``` | output | 1 | 5,147 | 7 | 10,295 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white). | instruction | 0 | 5,148 | 7 | 10,296 |
Tags: greedy, math
Correct Solution:
```
'''input
3 2
192
'''
# A coding delight
from sys import stdin
def counter(c):
if c == 'B':
return 'W'
return 'B'
# main starts
n = int(stdin.readline().strip())
string = list(stdin.readline().strip())
temp = string[:]
# changing to B
ans = []
for i in range(n - 1):
if string[i] == 'B':
pass
else:
string[i] = 'B'
string[i + 1] = counter(string[i + 1])
ans.append(i + 1)
if string[-1] == 'B':
print(len(ans))
print(*ans)
exit()
ans = []
string = temp[:]
for i in range(n - 1):
if string[i] == 'W':
pass
else:
string[i] = 'W'
string[i + 1] = counter(string[i + 1])
ans.append(i + 1)
if string[-1] == 'W':
print(len(ans))
print(*ans)
exit()
print(-1)
``` | output | 1 | 5,148 | 7 | 10,297 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white). | instruction | 0 | 5,149 | 7 | 10,298 |
Tags: greedy, math
Correct Solution:
```
n=int(input())
s=input()
t1=s.count('B')
t2=s.count('W')
a=[x for x in s]
if t1%2==1 and t2%2==1:
print("-1")
else:
c=0
a1=[]
b="#"
if t2%2==0:
b="W"
else:
b="B"
for i in range(n-1):
if(a[i]==b):
c+=1
if(a[i+1]=='W'):
a[i+1]='B'
else:
a[i+1]='W'
a1.append(i+1)
print(c)
print(*a1)
``` | output | 1 | 5,149 | 7 | 10,299 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white). | instruction | 0 | 5,150 | 7 | 10,300 |
Tags: greedy, math
Correct Solution:
```
n=int(input())
r=list(input())
for t in range(len(r)):
if r[t]=='B':
r[t]=1
else:
r[t]=-1
g=0
m=0
l=[]
jk=[]
o=list(r)
for i in range(0,n-1):
if r[i]==-1:
r[i]=-r[i]
r[i+1]=-r[i+1]
l+=[i+1]
if r[n-1]!=1:
g=1
for q in range(0,n-1):
if o[q]==1:
o[q]=-o[q]
o[q+1]=-o[q+1]
jk+=[q+1]
if o[n-1]!=-1:
m=1
if m==1 and g==1:
print(-1)
if m!=1 and g==1:
print(len(jk))
for ty in jk:
print(ty,end=' ')
if m==1 and g!=1:
print(len(l))
for tyh in l:
print(tyh,end=' ')
if m!=1 and g!=1:
if len(l)<len(jk):
print(len(l))
for tye in l:
print(tye,end=' ')
else:
print(len(jk))
for tyw in jk:
print(tyw,end=' ')
``` | output | 1 | 5,150 | 7 | 10,301 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white). | instruction | 0 | 5,151 | 7 | 10,302 |
Tags: greedy, math
Correct Solution:
```
n=int(input())
s=list(input())
w=s.count('W')
b=n-w
f = lambda c: 'B' if c=='W' else 'W'
if not b&1:
l = []
for i in range(n-1):
if s[i]=='B':
s[i],s[i+1]=f(s[i]),f(s[i+1])
l.append(i+1)
le=len(l)
print(le)
if le:
print(*l)
elif not w&1:
l = []
for i in range(n-1):
if s[i]=='W':
s[i],s[i+1]=f(s[i]),f(s[i+1])
l.append(i+1)
le=len(l)
print(le)
if le:
print(*l)
else:
print(-1)
``` | output | 1 | 5,151 | 7 | 10,303 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white). | instruction | 0 | 5,152 | 7 | 10,304 |
Tags: greedy, math
Correct Solution:
```
t = int(input())
s = input()
white = []
white_count = 0
temp = list(s)
for j in range(len(s)-1):
if(temp[j]=='B'):
white_count+=1
temp[j+1]='W' if temp[j+1]=='B' else 'B'
white.append(j+1)
if(temp[-1]=='W'):
print(white_count)
if(len(white)!=0):
print(*white)
else:
black = []
black_count = 0
temp = list(s)
for j in range(len(s)-1):
if(temp[j]=='W'):
black_count+=1
temp[j+1]='B' if temp[j+1]=='W' else 'W'
black.append(j+1)
if(temp[-1]=='B'):
print(black_count)
if(len(black)!=0):
print(*black)
else:
print(-1)
``` | output | 1 | 5,152 | 7 | 10,305 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
Submitted Solution:
```
'''input
3
BWB
'''
n = int(input())
string = input()
temp = []
for ele in string:
if ele == 'B':
temp.append(0)
else:
temp.append(1)
string = temp[::]
ans = []
temp = string[::]
for i in range(n - 1):
if temp[i] == 0:
temp[i] ^= 1
temp[i + 1] ^= 1
ans.append(i + 1)
# print(string, temp)
if temp[n - 1] == 0:
ans = []
temp = string[::]
for i in range(n - 1):
if temp[i] == 1:
temp[i] ^= 1
temp[i + 1] ^= 1
ans.append(i + 1)
if temp[n - 1] == 1:
print(-1)
else:
print(len(ans))
print(*ans)
else:
print(len(ans))
print(*ans)
``` | instruction | 0 | 5,153 | 7 | 10,306 |
Yes | output | 1 | 5,153 | 7 | 10,307 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white.
You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa).
You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 ⋅ n. If it is impossible to find such a sequence of operations, you need to report it.
Input
The first line contains one integer n (2 ≤ n ≤ 200) — the number of blocks.
The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black.
Output
If it is impossible to make all the blocks having the same color, print -1.
Otherwise, print an integer k (0 ≤ k ≤ 3 ⋅ n) — the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≤ p_j ≤ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation.
If there are multiple answers, print any of them.
Examples
Input
8
BWWWWWWB
Output
3
6 2 4
Input
4
BWBB
Output
-1
Input
5
WWWWW
Output
0
Input
3
BWB
Output
2
2 1
Note
In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black.
It is impossible to make all colors equal in the second example.
All blocks are already white in the third example.
In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
Submitted Solution:
```
#import sys
#input = sys.stdin.readline
def main():
n = int( input())
S = list( input())
b = 0
w = 0
T = [0]*n
for i in range(n):
if S[i] == 'B':
b += 1
else:
w += 1
T[i] = 1
if b%2 == 1 and w%2 == 1:
print(-1)
return
count = 0
ans = []
if b%2 == 1:
for i in range(n-1):
if T[i] == 0:
continue
T[i] = 0
T[i+1] = 1-T[i+1]
count += 1
ans.append(i+1)
else:
for i in range(n-1):
if T[i] == 1:
continue
T[i] = 1
T[i+1] = 1-T[i+1]
count += 1
ans.append(i+1)
print(count)
if count == 0:
return
print(" ".join( map(str, ans)))
if __name__ == '__main__':
main()
``` | instruction | 0 | 5,154 | 7 | 10,308 |
Yes | output | 1 | 5,154 | 7 | 10,309 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.