message stringlengths 2 16.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 575 109k | cluster float64 16 16 | __index_level_0__ int64 1.15k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N positive integers written on a blackboard: A_1, ..., A_N.
Snuke can perform the following operation when all integers on the blackboard are even:
* Replace each integer X on the blackboard by X divided by 2.
Find the maximum possible number of operations that Snuke can perform.
Constraints
* 1 \leq N \leq 200
* 1 \leq A_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
Output
Print the maximum possible number of operations that Snuke can perform.
Examples
Input
3
8 12 40
Output
2
Input
4
5 6 8 10
Output
0
Input
6
382253568 723152896 37802240 379425024 404894720 471526144
Output
8
Submitted Solution:
```
n = input()
a = list(map(int, input().split())
while True:
sum(a)
if sum % 2:
break
for num in a:
num = num / 2
i += 1
print(i)
``` | instruction | 0 | 85,610 | 16 | 171,220 |
No | output | 1 | 85,610 | 16 | 171,221 |
Provide a correct Python 3 solution for this coding contest problem.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No | instruction | 0 | 86,369 | 16 | 172,738 |
"Correct Solution:
```
from fractions import*;exec("a,b,c,d=map(int,input().split());g=gcd(b,d);print('YNeos'[b>min(a,d)or b-g+a%g>c::2]);"*int(input()))
``` | output | 1 | 86,369 | 16 | 172,739 |
Provide a correct Python 3 solution for this coding contest problem.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No | instruction | 0 | 86,370 | 16 | 172,740 |
"Correct Solution:
```
T=int(input())
ABCD=[list(map(int,input().split())) for i in range(T)]
from fractions import gcd
def f(a):
print(['No','Yes'][a])
for a,b,c,d in ABCD:
if a<b:f(0)
elif d<b:f(0)
elif b<=c:f(1)
else:
g=gcd(b,d)
h=a%b
f(max(((b-h)//g*g+h)%b,b-g)<=c)
``` | output | 1 | 86,370 | 16 | 172,741 |
Provide a correct Python 3 solution for this coding contest problem.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No | instruction | 0 | 86,371 | 16 | 172,742 |
"Correct Solution:
```
def main():
import math
def gcd(a, b):
while b:
a, b = b, a % b
return a
N = int(input())
ABCD = [list(map(int, input().split())) for i in range(N)]
for A,B,C,D in ABCD:
# 在庫が買う本数以下 or 在庫追加が買う本数以下
if A < B or D < B:
print("No")
continue
A %= B
# 在庫が買う本数以下になり、補給出来ない
if C < A:
print("No")
continue
if B == D:
print("Yes")
continue
flag = True
#print((B-A-1)%(D-B) ,">", (B-1)-(C+1))
if (B-A-1)%(gcd(D,B)) <= (B-1)-(C+1):
flag = False
print("Yes" if flag else "No")
if __name__ == '__main__':
main()
``` | output | 1 | 86,371 | 16 | 172,743 |
Provide a correct Python 3 solution for this coding contest problem.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No | instruction | 0 | 86,372 | 16 | 172,744 |
"Correct Solution:
```
def gcd(a,b):
if b== 0:
return a
else:
return gcd(b,a%b)
t = int(input())
abcd = []
ans = "No"
for i in range(0,t):
ABCD = list(map(int,input().split()))
abcd.append(ABCD)
for a,b,c,d in abcd:
if a >= b and b==d and b <= c:
ans = "Yes"
if a >= b and d >= b and b > c and b - gcd(d,b) + a%gcd(d,b) <= c:
ans = "Yes"
if a >= b and d >= b and b <= c:
ans = "Yes"
print(ans)
ans = "No"
``` | output | 1 | 86,372 | 16 | 172,745 |
Provide a correct Python 3 solution for this coding contest problem.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No | instruction | 0 | 86,373 | 16 | 172,746 |
"Correct Solution:
```
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
import fractions
t = inn()
for i in range(t):
a,b,c,d = inm()
if a<b or d<b:
print('No')
else:
g = fractions.gcd(b,d)
r = a%g
q = c%g
p = c-q+r
if p<=c:
p += g
#ddprint(f"a {a} b {b} c {c} d {d} g {g} r {r} q {q} p {p}")
if p>=b:
print('Yes')
else:
print('No')
``` | output | 1 | 86,373 | 16 | 172,747 |
Provide a correct Python 3 solution for this coding contest problem.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No | instruction | 0 | 86,374 | 16 | 172,748 |
"Correct Solution:
```
# coding: utf-8
# Your code here!
import fractions
def isok(a,b,c,d):
if a < b or b > d:
print('No')
return
g= fractions.gcd(d, b)
r=((c-a%g)//g)*g+a%g
# print(r)
if r+g-b < 0:
print('No')
else:
print('Yes')
T=int(input())
for _ in range(T):
a,b,c,d = list(map(int,input().split()))
isok(a,b,c,d)
``` | output | 1 | 86,374 | 16 | 172,749 |
Provide a correct Python 3 solution for this coding contest problem.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No | instruction | 0 | 86,375 | 16 | 172,750 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
import math
import decimal
ctx = decimal.Context(prec=3, rounding=decimal.ROUND_CEILING)
for i in range(int(input())):
a, b, c, d = map(int, input().split())
if a < b:
print('No')
continue
if b > d:
print('No')
continue
if c >= b:
print('Yes')
continue
g = gcd(b, d)
r = a % g
# FYI: https://stackoverflow.com/questions/2795946/getting-ceil-of-decimal-in-python
_max = (int(((decimal.Decimal(b, context=ctx) - decimal.Decimal(r, context=ctx)) / decimal.Decimal(g, context=ctx)).to_integral_exact(context=ctx)) * g) + r - g
# math.ceilは精度不足でエラーになる: https://cocoinit23.com/math-floor-ceil-error/
#_max = ((math.ceil((b - r) / g)) * g) + r - g
# OK: (a + b - 1) // b: https://nariagari-igakusei.com/cpp-division-round-up/
#_max = ((b - r + g - 1)//g) * g + r - g
if c < _max:
print('No')
else:
print('Yes')
``` | output | 1 | 86,375 | 16 | 172,751 |
Provide a correct Python 3 solution for this coding contest problem.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No | instruction | 0 | 86,376 | 16 | 172,752 |
"Correct Solution:
```
T = int(input())
def gcd(a, b):
if a < b:
a, b = b, a
if b == 0:
return 0
while a % b:
a, b = b, a % b
return b
while T:
T -= 1
A, B, C, D = map(int, input().split())
if B > A or B > D:
print("No")
else:
p = A - (A - C + B - 1) // B * B
r = D % B
g = gcd(r, B - r)
if p < 0:
print("No")
elif r == 0 or (C - r - p + g) // g * g + p - B + r >= 0:
print("Yes")
else:
print("No")
``` | output | 1 | 86,376 | 16 | 172,753 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke arranged N colorful balls in a row. The i-th ball from the left has color c_i and weight w_i.
He can rearrange the balls by performing the following two operations any number of times, in any order:
* Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.
* Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.
How many different sequences of colors of balls can be obtained? Find the count modulo 10^9 + 7.
Constraints
* 1 ≤ N ≤ 2 × 10^5
* 1 ≤ X, Y ≤ 10^9
* 1 ≤ c_i ≤ N
* 1 ≤ w_i ≤ 10^9
* X, Y, c_i, w_i are all integers.
Input
Input is given from Standard Input in the following format:
N X Y
c_1 w_1
:
c_N w_N
Output
Print the answer.
Examples
Input
4 7 3
3 2
4 3
2 1
4 4
Output
2
Input
1 1 1
1 1
Output
1
Input
21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
Output
129729600 | instruction | 0 | 89,993 | 16 | 179,986 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9 + 7
N,X,Y = map(int,readline().split())
CW = (tuple(int(x) for x in line.split()) for line in readlines())
C_to_W = [[] for _ in range(N+1)]
for c,w in CW:
C_to_W[c].append(w)
for c in range(N+1):
C_to_W[c].sort()
C_to_W.sort()
C_to_W = [x for x in C_to_W if x]
min_wt = C_to_W[0][0]
C_to_W = [x for x in C_to_W if x[0]+min_wt <= Y]
if len(C_to_W) <= 1:
print(1)
exit()
comp_size = [0] * (len(C_to_W))
for x in C_to_W[0]:
if x+C_to_W[0][0] <= X or x + C_to_W[1][0] <= Y:
comp_size[0] += 1
for i,arr in enumerate(C_to_W[1:],1):
for x in arr:
if x+min_wt <= Y or x+arr[0] <= X:
comp_size[i] += 1
fact = [1] * (N+1)
for i in range(1,N+1):
fact[i] = fact[i-1] * i % MOD
num = fact[sum(comp_size)]
den = 1
for x in comp_size:
den *= fact[x]
den %= MOD
answer = num * pow(den,MOD-2,MOD) % MOD
print(answer)
``` | output | 1 | 89,993 | 16 | 179,987 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke arranged N colorful balls in a row. The i-th ball from the left has color c_i and weight w_i.
He can rearrange the balls by performing the following two operations any number of times, in any order:
* Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.
* Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.
How many different sequences of colors of balls can be obtained? Find the count modulo 10^9 + 7.
Constraints
* 1 ≤ N ≤ 2 × 10^5
* 1 ≤ X, Y ≤ 10^9
* 1 ≤ c_i ≤ N
* 1 ≤ w_i ≤ 10^9
* X, Y, c_i, w_i are all integers.
Input
Input is given from Standard Input in the following format:
N X Y
c_1 w_1
:
c_N w_N
Output
Print the answer.
Examples
Input
4 7 3
3 2
4 3
2 1
4 4
Output
2
Input
1 1 1
1 1
Output
1
Input
21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
Output
129729600 | instruction | 0 | 89,994 | 16 | 179,988 |
"Correct Solution:
```
class Combination:
def __init__(self, n_max, mod=10**9+7):
# O(n_max + log(mod))
self.mod = mod
f = 1
self.fac = fac = [f]
for i in range(1, n_max+1):
f = f * i % mod
fac.append(f)
f = pow(f, mod-2, mod)
self.facinv = facinv = [f]
for i in range(n_max, 0, -1):
f = f * i % mod
facinv.append(f)
facinv.reverse()
import sys
N, X, Y = map(int, input().split())
CW = list(map(int, sys.stdin.read().split()))
C, W = CW[::2], CW[1::2]
mod = 10**9+7
comb = Combination(N+1)
Color_min = [10**10] * (N+1)
Color_argmin = [-1] * (N+1)
Color_2nd_min = [10**10] * (N+1)
all_min = 10**10
all_second_min = 10**10
all_min_color = -1
for i, (c, w) in enumerate(zip(C, W)):
if Color_2nd_min[c] > w:
Color_2nd_min[c] = w
if Color_min[c] > w:
Color_min[c], Color_2nd_min[c] = Color_2nd_min[c], Color_min[c]
Color_argmin[c] = i
for c, w in enumerate(Color_min):
if all_second_min > w:
all_second_min = w
if all_min > w:
all_min, all_second_min = all_second_min, all_min
all_min_color = c
In_cnt = [0] * (N+1)
Out_flag= [0] * (N+1)
for i, (c, w) in enumerate(zip(C, W)):
if (i != Color_argmin[c] and Color_min[c] + w <= X) \
or (Color_2nd_min[c] + w <= X) \
or (c != all_min_color and all_min + w <= Y) \
or (all_second_min + w <= Y):
In_cnt[c] += 1
if all_min + w <= Y:
Out_flag[c] = 1
sum_in_out = 0
ans = 1
for c, f in zip(In_cnt, Out_flag):
if f:
sum_in_out += c
ans = ans * comb.facinv[c] % mod
ans = ans * comb.fac[sum_in_out] % mod
#print(In_cnt)
#print(Out_flag)
print(ans)
``` | output | 1 | 89,994 | 16 | 179,989 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke arranged N colorful balls in a row. The i-th ball from the left has color c_i and weight w_i.
He can rearrange the balls by performing the following two operations any number of times, in any order:
* Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.
* Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.
How many different sequences of colors of balls can be obtained? Find the count modulo 10^9 + 7.
Constraints
* 1 ≤ N ≤ 2 × 10^5
* 1 ≤ X, Y ≤ 10^9
* 1 ≤ c_i ≤ N
* 1 ≤ w_i ≤ 10^9
* X, Y, c_i, w_i are all integers.
Input
Input is given from Standard Input in the following format:
N X Y
c_1 w_1
:
c_N w_N
Output
Print the answer.
Examples
Input
4 7 3
3 2
4 3
2 1
4 4
Output
2
Input
1 1 1
1 1
Output
1
Input
21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
Output
129729600 | instruction | 0 | 89,995 | 16 | 179,990 |
"Correct Solution:
```
#-----UnionFind-----(0-indexed)
import sys;sys.setrecursionlimit(10**9)
class UnionFind:
def __init__(self,n):
self.n=[-1]*n
self.r=[0]*n
self.siz=n
def find_root(self,x):
if self.n[x]<0:
return x
else:
self.n[x]=self.find_root(self.n[x])
return self.n[x]
def unite(self,x,y):
x=self.find_root(x)
y=self.find_root(y)
if x==y:return
elif self.r[x]>self.r[y]:
self.n[x]+=self.n[y]
self.n[y]=x
else:
self.n[y]+=self.n[x]
self.n[x]=y
if self.r[x]==self.r[y]:
self.r[y]+=1
self.siz-=1
def root_same(self,x,y):
return self.find_root(x)==self.find_root(y)
def count(self,x):
return -self.n[self.find_root(x)]
def size(self):
return self.siz
from collections import defaultdict
n,x,y=map(int,input().split())
mod=10**9+7
f=[1]
for i in range(1,n+7):f.append(f[-1]*i%mod)
cw=[list(map(int,input().split()))for _ in range(n)]
if n==1:exit(print(1))
if len(set(c for c,w in cw))==1:exit(print(1))
for i in range(n):cw[i][0]-=1
miw=[10**10]*n
miwi=[0]*n
for i in range(n):
c,w=cw[i]
if miw[c]>w:
miw[c]=w
miwi[c]=i
mminc=miw.index(min(miw))
temp=10**10
for i in range(n):
if i!=mminc:temp=min(temp,miw[i])
sminc=miw.index(temp)
u=UnionFind(n)
for i in range(n):
c,w=cw[i]
if c==mminc:tc=sminc
else:tc=mminc
if miw[c]+w<=x:u.unite(miwi[c],i)
if miw[tc]+w<=y:u.unite(miwi[tc],i)
d=[0]*n
for i in range(n):
if i==u.find_root(i):d[i]=defaultdict(int)
for i in range(n):
c,w=cw[i]
d[u.find_root(i)][c]+=1
ans=1
for i in range(n):
if i==u.find_root(i):
anss=1
co=0
for j in d[i]:
anss*=pow(f[d[i][j]],mod-2,mod)
anss%=mod
co+=d[i][j]
anss*=f[co]
ans=(ans*anss)%mod
print(ans)
``` | output | 1 | 89,995 | 16 | 179,991 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke arranged N colorful balls in a row. The i-th ball from the left has color c_i and weight w_i.
He can rearrange the balls by performing the following two operations any number of times, in any order:
* Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.
* Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.
How many different sequences of colors of balls can be obtained? Find the count modulo 10^9 + 7.
Constraints
* 1 ≤ N ≤ 2 × 10^5
* 1 ≤ X, Y ≤ 10^9
* 1 ≤ c_i ≤ N
* 1 ≤ w_i ≤ 10^9
* X, Y, c_i, w_i are all integers.
Input
Input is given from Standard Input in the following format:
N X Y
c_1 w_1
:
c_N w_N
Output
Print the answer.
Examples
Input
4 7 3
3 2
4 3
2 1
4 4
Output
2
Input
1 1 1
1 1
Output
1
Input
21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
Output
129729600 | instruction | 0 | 89,996 | 16 | 179,992 |
"Correct Solution:
```
class UnionFindVerSize():
def __init__(self, N):
self._parent = [n for n in range(0, N)]
self._size = [1] * N
def find_root(self, x):
if self._parent[x] == x: return x
self._parent[x] = self.find_root(self._parent[x])
return self._parent[x]
def unite(self, x, y):
gx = self.find_root(x)
gy = self.find_root(y)
if gx == gy: return
if self._size[gx] < self._size[gy]:
self._parent[gx] = gy
self._size[gy] += self._size[gx]
else:
self._parent[gy] = gx
self._size[gx] += self._size[gy]
def get_size(self, x):
return self._size[self.find_root(x)]
def is_same_group(self, x, y):
return self.find_root(x) == self.find_root(y)
def calc_group_num(self):
N = len(self._parent)
ans = 0
for i in range(N):
if self.find_root(i) == i:
ans += 1
return ans
mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
import sys,bisect
input=sys.stdin.buffer.readline
N,X,Y=map(int,input().split())
cball=[[] for i in range(N)]
ball=[]
color=[-1]*N
for i in range(N):
c,w=map(int,input().split())
ball.append((w,c-1,i))
cball[c-1].append((w,i))
color[i]=c-1
for i in range(N):
cball[i].sort()
ball.sort()
if N==1:
print(1)
exit()
cmin=[10**20 for i in range(N)]
for i in range(N):
if cball[i]:
cmin[i]=min(cball[i][j][0] for j in range(len(cball[i])))
_cmine1=[cmin[i] for i in range(N)]
_cmine2=[cmin[i] for i in range(N)]
for i in range(1,N):
_cmine1[i]=min(_cmine1[i],_cmine1[i-1])
for i in range(N-2,-1,-1):
_cmine2[i]=min(_cmine2[i],_cmine2[i+1])
cmine=[0]*N
cmine[0]=_cmine2[1]
cmine[-1]=_cmine1[N-2]
for i in range(1,N-1):
cmine[i]=min(_cmine1[i-1],_cmine2[i+1])
M=min(ball)
special=-1
for i in range(N):
if cmine[i]!=M[0]:
special=i
uf=UnionFindVerSize(N)
for i in range(N):
if i!=special:
for j in range(len(cball[i])):
if M[0]+cball[i][j][0]<=Y:
uf.unite(cball[i][j][1],M[2])
if j!=0 and cball[i][j][0]+cball[i][0][0]<=X:
uf.unite(cball[i][j][1],cball[i][0][1])
else:
for j in range(len(cball[special])):
if cmine[special]+cball[special][j][0]<=Y:
uf.unite(cball[special][j][1],M[2])
if M[0]+cball[special][j][0]<=X:
uf.unite(cball[special][j][1],M[2])
connect={}
for i in range(N):
root=uf.find_root(i)
if root not in connect:
connect[root]=[]
connect[root].append(i)
ans=1
for root in connect:
cc={}
for i in connect[root]:
if color[i] not in cc:
cc[color[i]]=0
cc[color[i]]+=1
size=len(connect[root])
for C in cc:
ans*=g2[cc[C]]
ans%=mod
ans*=g1[size]
ans%=mod
print(ans)
``` | output | 1 | 89,996 | 16 | 179,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke arranged N colorful balls in a row. The i-th ball from the left has color c_i and weight w_i.
He can rearrange the balls by performing the following two operations any number of times, in any order:
* Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.
* Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.
How many different sequences of colors of balls can be obtained? Find the count modulo 10^9 + 7.
Constraints
* 1 ≤ N ≤ 2 × 10^5
* 1 ≤ X, Y ≤ 10^9
* 1 ≤ c_i ≤ N
* 1 ≤ w_i ≤ 10^9
* X, Y, c_i, w_i are all integers.
Input
Input is given from Standard Input in the following format:
N X Y
c_1 w_1
:
c_N w_N
Output
Print the answer.
Examples
Input
4 7 3
3 2
4 3
2 1
4 4
Output
2
Input
1 1 1
1 1
Output
1
Input
21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
Output
129729600
Submitted Solution:
```
N, X, Y = map( int, input().split() )
C = []
W = []
for i in range( N ):
c, w = map( int, input().split() )
C.append( c - 1 )
W.append( w )
c2w = [ [] for i in range( N ) ]
for i in range( N ):
c2w[ C[ i ] ].append( W[ i ] )
for i in range( N ):
c2w[ C[ i ] ].sort()
minw, _minwp = 2e9, -1
for i in range( N ):
if len( c2w[ i ] ) == 0: continue
if minw > c2w[ i ][ 0 ]:
minw = c2w[ i ][ 0 ]
_minwp = i
minw2 = 2e9
for i in range( N ):
if len( c2w[ i ] ) == 0: continue
if i == _minwp: continue
if minw2 > c2w[ i ][ 0 ]:
minw2 = c2w[ i ][ 0 ]
merged = [ False for i in range( N ) ]
hi = [ 1 for i in range( N ) ]
for i in range( N ):
if len( c2w[ i ] ) == 0: continue
lb, ub = 2, len( c2w[ i ] )
while lb <= ub:
mid = lb + ub >> 1
if c2w[ i ][ 0 ] + c2w[ i ][ mid - 1 ] <= X:
hi[ i ] = max( hi[ i ], mid )
lb = mid + 1
else:
ub = mid - 1
lb, ub = 1, len( c2w[ i ] )
www = minw2 if minw != minw2 and c2w[ i ][ 0 ] == minw else minw
while lb <= ub:
mid = lb + ub >> 1
if www + c2w[ i ][ mid - 1 ] <= Y:
hi[ i ] = max( hi[ i ], mid )
merged[ i ] = True
lb = mid + 1
else:
ub = mid - 1
MOD = int( 1e9 + 7 )
fact = [ 1 ]
inv_fact = [ 1 ]
for i in range( 1, N + 1, 1 ):
fact.append( fact[ i - 1 ] * i % MOD )
inv_fact.append( pow( fact[ i ], MOD - 2, MOD ) )
ans = fact[ sum( merged[ i ] * hi[ i ] for i in range( N ) ) ]
for i in range( N ):
if not merged[ i ]: continue
ans = ans * inv_fact[ hi[ i ] ] % MOD
print( ans )
``` | instruction | 0 | 89,997 | 16 | 179,994 |
No | output | 1 | 89,997 | 16 | 179,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke arranged N colorful balls in a row. The i-th ball from the left has color c_i and weight w_i.
He can rearrange the balls by performing the following two operations any number of times, in any order:
* Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.
* Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.
How many different sequences of colors of balls can be obtained? Find the count modulo 10^9 + 7.
Constraints
* 1 ≤ N ≤ 2 × 10^5
* 1 ≤ X, Y ≤ 10^9
* 1 ≤ c_i ≤ N
* 1 ≤ w_i ≤ 10^9
* X, Y, c_i, w_i are all integers.
Input
Input is given from Standard Input in the following format:
N X Y
c_1 w_1
:
c_N w_N
Output
Print the answer.
Examples
Input
4 7 3
3 2
4 3
2 1
4 4
Output
2
Input
1 1 1
1 1
Output
1
Input
21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
Output
129729600
Submitted Solution:
```
from collections import defaultdict
mod = 10**9+7
rng = 200100
fctr = [1]
finv = [1]
for i in range(1,rng):
fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
if n<0 or k<0:
return 0
else:
return fctr[n]*finv[n-k]*finv[k]%mod
import sys
input = sys.stdin.readline
n,X,Y = map(int,input().split())
cw = [list(map(int,input().split())) for i in range(n)]
cw.sort()
mnls = []
graph = [[] for i in range(n)]
notmn = set()
for i in range(n):
if i == 0 or cw[i-1][0] != cw[i][0]:
mnls.append((i,cw[i][0],cw[i][1]))
else:
if cw[i][1]+mnls[-1][2] <= X:
graph[i].append(mnls[-1][0])
graph[mnls[-1][0]].append(i)
else:
notmn.add(i)
mnls.sort(key = lambda x:x[2])
for i,x in enumerate(mnls):
if i == 0:
continue
if x[2]+mnls[0][2] <= Y:
graph[x[0]].append(mnls[0][0])
graph[mnls[0][0]].append(x[0])
for i in notmn:
if mnls[0][1] != cw[i][0] and mnls[0][2]+cw[i][1] <= Y:
graph[i].append(mnls[0][0])
graph[mnls[0][0]].append(i)
vis = [0 for i in range(n)]
ans = 1
for i in range(n):
if vis[i]:
continue
vis[i] = 1
stack = [i]
color = defaultdict(int)
while stack:
x = stack.pop()
color[cw[x][0]] += 1
for y in graph[x]:
if vis[y] == 0:
vis[y] = 1
stack.append(y)
sm = sum(color.values())
for v in color.values():
ans = ans*cmb(sm,v)%mod
sm -= v
print(ans)
``` | instruction | 0 | 89,998 | 16 | 179,996 |
No | output | 1 | 89,998 | 16 | 179,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke arranged N colorful balls in a row. The i-th ball from the left has color c_i and weight w_i.
He can rearrange the balls by performing the following two operations any number of times, in any order:
* Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.
* Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.
How many different sequences of colors of balls can be obtained? Find the count modulo 10^9 + 7.
Constraints
* 1 ≤ N ≤ 2 × 10^5
* 1 ≤ X, Y ≤ 10^9
* 1 ≤ c_i ≤ N
* 1 ≤ w_i ≤ 10^9
* X, Y, c_i, w_i are all integers.
Input
Input is given from Standard Input in the following format:
N X Y
c_1 w_1
:
c_N w_N
Output
Print the answer.
Examples
Input
4 7 3
3 2
4 3
2 1
4 4
Output
2
Input
1 1 1
1 1
Output
1
Input
21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
Output
129729600
Submitted Solution:
```
class UnionFindVerSize():
def __init__(self, N):
self._parent = [n for n in range(0, N)]
self._size = [1] * N
def find_root(self, x):
if self._parent[x] == x: return x
self._parent[x] = self.find_root(self._parent[x])
return self._parent[x]
def unite(self, x, y):
gx = self.find_root(x)
gy = self.find_root(y)
if gx == gy: return
if self._size[gx] < self._size[gy]:
self._parent[gx] = gy
self._size[gy] += self._size[gx]
else:
self._parent[gy] = gx
self._size[gx] += self._size[gy]
def get_size(self, x):
return self._size[self.find_root(x)]
def is_same_group(self, x, y):
return self.find_root(x) == self.find_root(y)
def calc_group_num(self):
N = len(self._parent)
ans = 0
for i in range(N):
if self.find_root(i) == i:
ans += 1
return ans
mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
import sys,bisect
input=sys.stdin.buffer.readline
N,X,Y=map(int,input().split())
cball=[[] for i in range(N)]
ball=[]
color=[-1]*N
for i in range(N):
c,w=map(int,input().split())
ball.append((w,c-1,i))
cball[c-1].append((w,i))
color[i]=c-1
for i in range(N):
cball[i].sort()
ball.sort()
if N==1:
print(1)
exit()
cmin=[10**20 for i in range(N)]
for i in range(N):
if cball[i]:
cmin[i]=min(cball[i][j][0] for j in range(len(cball[i])))
_cmine1=[cmin[i] for i in range(N)]
_cmine2=[cmin[i] for i in range(N)]
for i in range(1,N):
_cmine1[i]=min(_cmine1[i],_cmine1[i-1])
for i in range(N-2,-1,-1):
_cmine2[i]=min(_cmine2[i],_cmine2[i+1])
cmine=[0]*N
cmine[0]=_cmine2[1]
cmine[-1]=_cmine1[N-2]
for i in range(1,N-1):
cmine[i]=min(_cmine1[i-1],_cmine2[i+1])
uf=UnionFindVerSize(N)
for i in range(N):
n=len(cball[i])
for j in range(1,n):
id=bisect.bisect_right(cball[i],(X-cball[i][j][0],10**20))
if i==1:
if id!=0:
for k in range(id):
num1=cball[i][k][1]
num2=cball[i][j][1]
uf.unite(num1,num2)
if id!=0:
num1=cball[i][id-1][1]
num2=cball[i][j][1]
uf.unite(num1,num2)
if cball[i][j][0]+cmine[i]<=Y:
num1=cball[i][j-1][1]
num2=cball[i][j][1]
uf.unite(num1,num2)
for i in range(1,N):
id=bisect.bisect_right(ball,(Y-ball[i][0],10**20))
if i==1:
if id!=0:
for j in range(id):
num1=ball[j][2]
num2=ball[i][2]
uf.unite(num1,num2)
if id!=0:
num1=ball[id-1][2]
num2=ball[i][2]
uf.unite(num1,num2)
connect={}
for i in range(N):
root=uf.find_root(i)
if root not in connect:
connect[root]=[]
connect[root].append(i)
ans=1
for root in connect:
cc={}
for i in connect[root]:
if color[i] not in cc:
cc[color[i]]=0
cc[color[i]]+=1
size=len(connect[root])
for C in cc:
ans*=g2[cc[C]]
ans%=mod
ans*=g1[size]
ans%=mod
print(ans)
``` | instruction | 0 | 89,999 | 16 | 179,998 |
No | output | 1 | 89,999 | 16 | 179,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke arranged N colorful balls in a row. The i-th ball from the left has color c_i and weight w_i.
He can rearrange the balls by performing the following two operations any number of times, in any order:
* Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.
* Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.
How many different sequences of colors of balls can be obtained? Find the count modulo 10^9 + 7.
Constraints
* 1 ≤ N ≤ 2 × 10^5
* 1 ≤ X, Y ≤ 10^9
* 1 ≤ c_i ≤ N
* 1 ≤ w_i ≤ 10^9
* X, Y, c_i, w_i are all integers.
Input
Input is given from Standard Input in the following format:
N X Y
c_1 w_1
:
c_N w_N
Output
Print the answer.
Examples
Input
4 7 3
3 2
4 3
2 1
4 4
Output
2
Input
1 1 1
1 1
Output
1
Input
21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
Output
129729600
Submitted Solution:
```
from collections import defaultdict
n,x,y=map(int,input().split())
mod=10**9+7
f=[1]
for i in range(1,n+7):f.append(f[-1]*i%mod)
wc=[list(map(int,input().split()))[::-1]for _ in range(n)]
if n==1:exit(print(1))
if len(set(c for w,c in wc))==1:exit(print(1))
wc.sort()
mw,mc=wc[0]
i=1
while wc[i][1]==mc:i+=1
mmw,mmc=wc[i]
flag=False
for w,c in wc:
if ((c==mc and w+mw<=x)or(c!=mc and w+mw<=y))and((c==mmc and w+mmw<=x)or(c!=mmc and w+mmw<=y)):flag=True
if flag:
d=defaultdict(int)
dc=0
for w,c in wc:
if(c==mc and w+mw<=x)or(c!=mc and w+mw<=y)or(c==mmc and w+mmw<=x)or(c!=mmc and w+mmw<=y):
d[c]+=1
dc+=1
ans=f[dc]
for i in d:
ans*=pow(f[d[i]],mod-2,mod)
ans%=mod
else:
d=defaultdict(int)
dc=0
md=defaultdict(int)
mdc=0
for w,c in wc:
if (c==mc and w+mw<=x)or(c!=mc and w+mw<=y):
d[c]+=1
dc+=1
if (c==mmc and w+mmw<=x)or(c!=mmc and w+mmw<=y):
md[c]+=1
mdc+=1
ans=f[dc]
for i in d:
ans*=pow(f[d[i]],mod-2,mod)
ans%=mod
anss=f[mdc]
for i in md:
anss*=pow(f[md[i]],mod-2,mod)
anss%=mod
ans=(ans*anss)%mod
print(ans)
``` | instruction | 0 | 90,000 | 16 | 180,000 |
No | output | 1 | 90,000 | 16 | 180,001 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible | instruction | 0 | 92,516 | 16 | 185,032 |
"Correct Solution:
```
#!/usr/bin/env python3
def solve(n, m, a):
odd = []
even = []
for a_i in a:
if a_i % 2 == 0:
even += [ a_i ]
else:
odd += [ a_i ]
if len(odd) >= 3:
return None
a, b = [], []
if odd:
x = odd.pop()
a += [ x ]
b += [ x - 1 ]
else:
x = even.pop()
a += [ x ]
b += [ x - 1 ]
a += even
b += even
if odd:
x = odd.pop()
a += [ x ]
b += [ x + 1 ]
else:
b += [ 1 ]
return a, b
n, m = map(int, input().split())
a = list(map(int, input().split()))
it = solve(n, m, a)
if it is None:
print('Impossible')
else:
a, b = it
b = list(filter(lambda b_i: b_i, b))
print(*a)
print(len(b))
print(*b)
``` | output | 1 | 92,516 | 16 | 185,033 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible | instruction | 0 | 92,517 | 16 | 185,034 |
"Correct Solution:
```
S, N = map(int, input().split())
A = list(map(int, input().split()))
O = [a for a in A if a % 2 == 1]
E = [a for a in A if a % 2 == 0]
if len(O) > 2:
print("Impossible")
else:
A = O[:min(len(O), 1)] + E + O[1:]
B = A[:] + ([0] if N == 1 else [])
B[0] -= 1
B[-1] += 1
if B[0] == 0:
B = B[1:]
print(*A, sep=" ")
print(len(B))
print(*B, sep=" ")
``` | output | 1 | 92,517 | 16 | 185,035 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible | instruction | 0 | 92,518 | 16 | 185,036 |
"Correct Solution:
```
import sys
def solve(n, m, arr):
odds = []
evens = []
for a in arr:
if a % 2 == 0:
evens.append(a)
else:
odds.append(a)
if len(odds) > 2:
print('Impossible')
return
if len(odds) == 2:
o1, o2 = odds
aaa = [o1] + evens + [o2]
bbb = [2] * (o1 // 2 + 1)
bbb += evens
bbb += [2] * (o2 // 2)
elif len(odds) == 1:
if odds[0] == 1:
aaa = odds + evens
bbb = evens + odds
elif evens:
aaa = odds + evens
bbb = [odds[0] - 1] + evens[:-1] + [evens[-1] + 1]
else:
aaa = odds
bbb = [odds[0] // 2, odds[0] // 2 + 1]
else:
aaa = evens
bbb = [1] + evens[:-1] + [evens[-1] - 1]
print(*aaa)
print(len(bbb))
print(*bbb)
n, m, *aaa = map(int, sys.stdin.buffer.read().split())
solve(n, m, aaa)
``` | output | 1 | 92,518 | 16 | 185,037 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible | instruction | 0 | 92,519 | 16 | 185,038 |
"Correct Solution:
```
from sys import exit
n, m = map(int, input().split())
a = list(map(int, input().split()))
odd = []
even = []
for x in a:
if x%2 == 0:
even.append(x)
else:
odd.append(x)
if n%2 == 0:
if len(odd) > 2:
print("Impossible")
exit()
if len(odd) == 2:
a = [odd[0]] + even + [odd[1]]
b = [odd[0]+1] + even + [odd[1]-1]
if b[-1] == 0:
b.pop()
else:
a = even
b = [1] + even
b[-1] -= 1
if b[-1] == 0:
b.pop()
else:
if len(odd) > 1:
print("Impossible")
exit()
if m == 1:
b = [1, n-1]
else:
a = odd + even
b = [odd[0]+1] + even
b[-1] -= 1
if b[-1] == 0:
b.pop()
print(*a)
print(len(b))
print(*b)
``` | output | 1 | 92,519 | 16 | 185,039 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible | instruction | 0 | 92,520 | 16 | 185,040 |
"Correct Solution:
```
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[]
o=[]
for i in a:
if i%2:o.append(i)
else:b.append(i)
if len(o)>2:print("Impossible");exit()
if len(o)==1:b=o+b
elif len(o)==2:b=[o[0]]+b+[o[1]]
ans=[]
for i in range(len(b)):
if i==0:ans.append(b[i]-1)
elif i==len(b)-1:ans.append(b[i]+1)
else:ans.append(b[i])
anss=[]
for i in ans:
if i!=0:anss.append(i)
if sum(anss)!=n:anss.append(n-sum(anss))
print(*b)
print(len(anss))
print(*anss)
``` | output | 1 | 92,520 | 16 | 185,041 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible | instruction | 0 | 92,521 | 16 | 185,042 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)
N,M = map(int,readline().split())
A = [int(x) for x in readline().split()]
OD = [x for x in A if x&1]
EV = [x for x in A if not x&1]
if len(OD) >= 3:
print('Impossible')
exit()
if len(A) == 1:
if N == 1:
B = [1]
else:
B = [1,N-1]
elif len(OD) == 0:
B = A.copy()
B[0] -= 1
B[-1] += 1
elif len(OD) == 1:
A = OD + EV
B = A.copy()
B[0] += 1
B[-1] -= 1
else:
A = [OD[0]] + EV + [OD[-1]]
B = A.copy()
B[0] += 1
B[-1] -= 1
B = [x for x in B if x > 0]
print(*A)
print(len(B))
print(*B)
``` | output | 1 | 92,521 | 16 | 185,043 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible | instruction | 0 | 92,522 | 16 | 185,044 |
"Correct Solution:
```
S, N = map(int, input().split())
A = list(map(int, input().split()))
O = [a for a in A if a % 2 == 1]
E = [a for a in A if a % 2 == 0]
if len(O) > 2:
print("Impossible")
else:
A = O[:min(len(O), 1)] + E + O[min(1, len(O)):]
B = A[:] + ([0] if len(A) == 1 else [])
B[0] -= 1
B[-1] += 1
if B[0] == 0:
B = B[1:]
print(" ".join(str(a) for a in A))
print(len(B))
print(" ".join(str(b) for b in B))
``` | output | 1 | 92,522 | 16 | 185,045 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible | instruction | 0 | 92,523 | 16 | 185,046 |
"Correct Solution:
```
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
"""
agc001 D
"""
n, m = map(int, input().split())
ali = list(map(int, input().split()))
if m == 1 and ali[0] == 1:
print(1)
print(1)
print(1)
exit()
if m == 1:
print(ali[0])
print(2)
print(ali[0]-1, 1)
exit()
flag = 0
c = []
for a in ali:
if a % 2 == 1:
if flag == 0:
lm = a
flag += 1
elif flag == 1:
rm = a
flag += 1
elif flag == 2:
print('Impossible')
exit()
else:
c.append(a)
if flag == 0:
lm = c[0]
del c[0]
rm = c.pop()
if flag == 1:
rm = c.pop()
b = [lm+1] + c
d = [lm] + c + [rm]
if rm > 1:
b.append(rm-1)
print(" ".join(map(str, d)))
print(len(b))
print(" ".join(map(str, b)))
``` | output | 1 | 92,523 | 16 | 185,047 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible
Submitted Solution:
```
n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
breakFlag = False
for i in range(1,m-1):
if a[i]%2==1:
if a[0]%2==1:
if a[len(a)-1]%2==1:
print("Impossible")
breakFlag = True
break
else:
a[i],a[len(a)-1] = a[len(a)-1],a[i]
else:
a[i],a[0] = a[0],a[i]
if breakFlag==False:
ans = ''.join([str(s)+" " for s in a])
print(ans[:-1])
if m==1:
if a[0]>1:
a[0]-=1
a.append(1)
print(m+1)
else:
print(m)
else:
if a[len(a)-1]==1:
print(m-1)
a.pop()
a[0]+=1
else:
print(m)
a[0]+=1
a[len(a)-1] -= 1
ans = ''.join([str(s)+" " for s in a])
print(ans[:-1])
``` | instruction | 0 | 92,524 | 16 | 185,048 |
Yes | output | 1 | 92,524 | 16 | 185,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible
Submitted Solution:
```
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
"""
agc001 D
"""
n, m = map(int, input().split())
ali = list(map(int, input().split()))
if m == 1:
print(ali[0])
print(2)
print(ali[0]-1, 1)
exit()
flag = 0
c = []
for a in ali:
if a % 2 == 1:
if flag == 0:
lm = a
flag += 1
elif flag == 1:
rm = a
flag += 1
elif flag == 2:
print('Impossible')
exit()
else:
c.append(a)
if flag == 1:
rm = c.pop()
b = [lm+1] + c
d = [lm] + c + [rm]
if rm > 1:
b.append(rm-1)
print(" ".join(map(str, d)))
print(len(b))
print(" ".join(map(str, b)))
``` | instruction | 0 | 92,525 | 16 | 185,050 |
No | output | 1 | 92,525 | 16 | 185,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible
Submitted Solution:
```
import sys
n, m = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
A_odds = [x for x in A if x % 2 == 0]
A_evens = [x for x in A if x % 2 == 1]
a = []
b = []
if len(A_odds) > 2:
print('Impossible')
sys.exit();
if len(A_odds) != 0:
a.append(A_odds[0])
a += A_evens
if len(A_odds) == 2:
a.append(A_odds[1])
if len(a) == 1:
if a[0] == 1:
b.append(1)
else:
b.append(a[0] - 1)
b.append(1)
else:
if a[0] == 1:
b.append(2)
b += a[1:-1]
if a[-1] != 1:
b.append(a[-1] - 1)
else:
b.append(a[0] - 1)
b += a[1:-1]
b.append(a[-1] + 1)
else:
a += A_evens
b.append(a[0] - 1)
b += a[1:-1]
b.append(a[-1] + 1)
print(' '.join(map(str,a)))
print(str(len(b)))
print(' '.join(map(str,b)))
``` | instruction | 0 | 92,526 | 16 | 185,052 |
No | output | 1 | 92,526 | 16 | 185,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible
Submitted Solution:
```
from sys import exit
n, m = map(int, input().split())
a = list(map(int, input().split()))
odd = []
even = []
for x in a:
if x%2 == 0:
even.append(x)
else:
odd.append(x)
if n%2 == 0:
if len(odd) > 2:
print("Impossible")
exit()
if len(odd) == 2:
a = [odd[0]] + even + [odd[1]]
b = [odd[0]+1] + even + [odd[1]-1]
if b[-1] == 0:
b.pop()
else:
a = even
b = [1] + even
b[-1] -= 1
if b[-1] == 0:
b.pop()
else:
if len(odd) > 1:
print("Impossible")
exit()
if m == 1:
b = [1, n-1]
else:
a = odd + even
b = [odd[0]+1] + even
b[-1] -= 1
if b[-1] == 0:
b.pop()
print(*a)
print(len(b))
print(*b)
``` | instruction | 0 | 92,527 | 16 | 185,054 |
No | output | 1 | 92,527 | 16 | 185,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b, consisting of positive integers. They satisfied all of the following properties:
* The sum of all elements of a is N.
* The sum of all elements of b is N.
* Any string of length N that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).
* (1) Any of the following forms a palindrome: the first a_1 letters, the following a_2 letters, the following a_3 letters and so on.
* (2) Any of the following forms a palindrome: the first b_1 letters, the following b_2 letters, the following b_3 letters and so on.
* (3) All N letters are the same.
He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence a was a permutation of another sequence A of length M.
To bring him happiness again, his mother has decided to give him another pair of sequences a and b that satisfies his favorite properties and is consistent with his memory.
Constraints
* 1≦N≦10^5
* 1≦M≦100
* 1≦A_i≦10^5
* The sum of all A_i equals N.
Input
The input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
If there exists a pair of sequences a and b that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence a, the second line must contain the length of the sequence b, and the third line must contain the sequence b.
If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word `Impossible` (case-sensitive).
Examples
Input
3 2
2 1
Output
1 2
1
3
Input
6 1
6
Output
6
3
1 2 3
Input
55 10
1 2 3 4 5 6 7 8 9 10
Output
Impossible
Submitted Solution:
```
import sys
def solve(n, m, arr):
odds = []
evens = []
for a in arr:
if a % 2 == 0:
evens.append(a)
else:
odds.append(a)
if len(odds) > 2:
print('Impossible')
return
if len(odds) == 2:
o1, o2 = odds
aaa = [o1] + evens + [o2]
bbb = [2] * (o1 // 2 + 1)
bbb += evens
bbb += [2] * (o2 // 2)
elif len(odds) == 1:
aaa = odds + evens
bbb = list(reversed(aaa))
else:
aaa = evens
bbb = [1] + aaa[:-1] + [aaa[-1] - 1]
print(*aaa)
print(len(bbb))
print(*bbb)
n, m, *aaa = map(int, sys.stdin.buffer.read().split())
solve(n, m, aaa)
``` | instruction | 0 | 92,528 | 16 | 185,056 |
No | output | 1 | 92,528 | 16 | 185,057 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a sequence p, which is a permutation of (0,1,2, ...,N-1). The i-th element (0-indexed) in p is p_i.
He can perform N-1 kinds of operations labeled 1,2,...,N-1 any number of times in any order. When the operation labeled k is executed, the procedure represented by the following code will be performed:
for(int i=k;i<N;i++)
swap(p[i],p[i-k]);
He would like to sort p in increasing order using between 0 and 10^{5} operations (inclusive). Show one such sequence of operations. It can be proved that there always exists such a sequence of operations under the constraints in this problem.
Constraints
* 2 \leq N \leq 200
* 0 \leq p_i \leq N-1
* p is a permutation of (0,1,2,...,N-1).
Input
Input is given from Standard Input in the following format:
N
p_0 p_1 ... p_{N-1}
Output
Let m be the number of operations in your solution. In the first line, print m. In the i-th of the following m lines, print the label of the i-th executed operation. The solution will be accepted if m is at most 10^5 and p is in increasing order after the execution of the m operations.
Examples
Input
5
4 2 0 1 3
Output
4
2
3
1
2
Input
9
1 0 4 3 5 6 2 8 7
Output
11
3
6
1
3
5
2
4
7
8
6
3
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**6)
N = int(input())
*P, = map(int, input().split())
if N > 10:
exit(1)
memo = set()
*A, = range(N)
ans = []
def dfs(state):
key = tuple(state)
if key in memo:
return
if state == A:
return 1
memo.add(key)
for i in range(1, N):
n_state = state[:]
for j in range(i, N):
n_state[j], n_state[j-i] = n_state[j-i], n_state[j]
if dfs(n_state):
ans.append(i)
return 1
return 0
dfs(P)
print(len(ans))
for e in reversed(ans):
print(e)
``` | instruction | 0 | 93,355 | 16 | 186,710 |
No | output | 1 | 93,355 | 16 | 186,711 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a sequence p, which is a permutation of (0,1,2, ...,N-1). The i-th element (0-indexed) in p is p_i.
He can perform N-1 kinds of operations labeled 1,2,...,N-1 any number of times in any order. When the operation labeled k is executed, the procedure represented by the following code will be performed:
for(int i=k;i<N;i++)
swap(p[i],p[i-k]);
He would like to sort p in increasing order using between 0 and 10^{5} operations (inclusive). Show one such sequence of operations. It can be proved that there always exists such a sequence of operations under the constraints in this problem.
Constraints
* 2 \leq N \leq 200
* 0 \leq p_i \leq N-1
* p is a permutation of (0,1,2,...,N-1).
Input
Input is given from Standard Input in the following format:
N
p_0 p_1 ... p_{N-1}
Output
Let m be the number of operations in your solution. In the first line, print m. In the i-th of the following m lines, print the label of the i-th executed operation. The solution will be accepted if m is at most 10^5 and p is in increasing order after the execution of the m operations.
Examples
Input
5
4 2 0 1 3
Output
4
2
3
1
2
Input
9
1 0 4 3 5 6 2 8 7
Output
11
3
6
1
3
5
2
4
7
8
6
3
Submitted Solution:
```
N = int(input())
*P, = map(int, input().split())
if N > 10:
exit(1)
memo = set()
*A, = range(N)
ans = []
def dfs(state):
key = tuple(state)
if key in memo:
return
if state == A:
return 1
memo.add(key)
for i in range(1, N):
n_state = state[:]
for j in range(i, N):
n_state[j], n_state[j-i] = n_state[j-i], n_state[j]
if dfs(n_state):
ans.append(i)
return 1
return 0
dfs(P)
print(len(ans))
for e in reversed(ans):
print(e)
``` | instruction | 0 | 93,356 | 16 | 186,712 |
No | output | 1 | 93,356 | 16 | 186,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a sequence p, which is a permutation of (0,1,2, ...,N-1). The i-th element (0-indexed) in p is p_i.
He can perform N-1 kinds of operations labeled 1,2,...,N-1 any number of times in any order. When the operation labeled k is executed, the procedure represented by the following code will be performed:
for(int i=k;i<N;i++)
swap(p[i],p[i-k]);
He would like to sort p in increasing order using between 0 and 10^{5} operations (inclusive). Show one such sequence of operations. It can be proved that there always exists such a sequence of operations under the constraints in this problem.
Constraints
* 2 \leq N \leq 200
* 0 \leq p_i \leq N-1
* p is a permutation of (0,1,2,...,N-1).
Input
Input is given from Standard Input in the following format:
N
p_0 p_1 ... p_{N-1}
Output
Let m be the number of operations in your solution. In the first line, print m. In the i-th of the following m lines, print the label of the i-th executed operation. The solution will be accepted if m is at most 10^5 and p is in increasing order after the execution of the m operations.
Examples
Input
5
4 2 0 1 3
Output
4
2
3
1
2
Input
9
1 0 4 3 5 6 2 8 7
Output
11
3
6
1
3
5
2
4
7
8
6
3
Submitted Solution:
```
N = int(input())
*P, = map(int, input().split())
if N > 7:
exit(1)
memo = set()
*A, = range(N)
ans = []
def dfs(state):
key = tuple(state)
if key in memo:
return
if state == A:
return 1
memo.add(key)
for i in range(1, N):
n_state = state[:]
for j in range(i, N):
n_state[j], n_state[j-i] = n_state[j-i], n_state[j]
if dfs(n_state):
ans.append(i)
return 1
return 0
dfs(P)
print(len(ans))
for e in reversed(ans):
print(e)
``` | instruction | 0 | 93,357 | 16 | 186,714 |
No | output | 1 | 93,357 | 16 | 186,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a sequence p, which is a permutation of (0,1,2, ...,N-1). The i-th element (0-indexed) in p is p_i.
He can perform N-1 kinds of operations labeled 1,2,...,N-1 any number of times in any order. When the operation labeled k is executed, the procedure represented by the following code will be performed:
for(int i=k;i<N;i++)
swap(p[i],p[i-k]);
He would like to sort p in increasing order using between 0 and 10^{5} operations (inclusive). Show one such sequence of operations. It can be proved that there always exists such a sequence of operations under the constraints in this problem.
Constraints
* 2 \leq N \leq 200
* 0 \leq p_i \leq N-1
* p is a permutation of (0,1,2,...,N-1).
Input
Input is given from Standard Input in the following format:
N
p_0 p_1 ... p_{N-1}
Output
Let m be the number of operations in your solution. In the first line, print m. In the i-th of the following m lines, print the label of the i-th executed operation. The solution will be accepted if m is at most 10^5 and p is in increasing order after the execution of the m operations.
Examples
Input
5
4 2 0 1 3
Output
4
2
3
1
2
Input
9
1 0 4 3 5 6 2 8 7
Output
11
3
6
1
3
5
2
4
7
8
6
3
Submitted Solution:
```
N = int(input())
*P, = map(int, input().split())
if N > 7:
exit(1)
memo = set()
*A, = range(N)
ans = []
def dfs(state):
key = tuple(state)
if key in memo:
return
if state == A:
return 1
memo.add(key)
for i in range(1, N):
n_state = state[:]
for j in range(i, N):
n_state[j], n_state[j-i] = n_state[j-i], n_state[j]
if dfs(n_state):
ans.append(i)
return 0
dfs(P)
print(len(ans))
for e in reversed(ans):
print(e)
``` | instruction | 0 | 93,358 | 16 | 186,716 |
No | output | 1 | 93,358 | 16 | 186,717 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477 | instruction | 0 | 93,359 | 16 | 186,718 |
"Correct Solution:
```
import math
INF, MOD = float("inf"), 10 ** 9 + 7
MAX, MIN = -INF, INF
dx1, dy1, dx2, dy2 = [-1, 0, 1, 0], [0, -1, 0, 1], [-1, 0, 1, -1, 1, -1, 0, 1], [-1, -1, -1, 0, 0, 1, 1, 1]
def get_int():
return int(input())
def get_int_list():
return list(map(int, input().split()))
def mins(x, y):
x = min(x, y)
def maxs(x, y):
x = max(x, y)
def fact(n):
tmp = 1
for i in range(2, n + 1):
tmp = int(tmp * i % MOD)
return tmp
while(True):
try:
n, m = get_int_list()
if(n == m):
print(int(fact(n) ** 2 * 2 % MOD))
elif(abs(n - m) == 1):
print(int(fact(n) * fact(m) % MOD))
else:
print(0)
except EOFError:
exit()
``` | output | 1 | 93,359 | 16 | 186,719 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477 | instruction | 0 | 93,360 | 16 | 186,720 |
"Correct Solution:
```
import sys
import math
n, m = (int(i) for i in input().split())
l=abs(n-m)
div=int(10**9+7)
if l>1:
print(0)
sys.exit()
if l==1:
ans=(math.factorial(n)*math.factorial(m))%div
print(ans)
else:
ans=(math.factorial(n)*math.factorial(m)*2)%div
print(ans)
``` | output | 1 | 93,360 | 16 | 186,721 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477 | instruction | 0 | 93,361 | 16 | 186,722 |
"Correct Solution:
```
from math import factorial
N, M = map(int, input().split())
ans = factorial(N)*factorial(M)
if abs(N-M) == 1:
print(ans % (10**9+7))
elif N == M:
print((ans*2) % (10**9+7))
else:
print(0)
``` | output | 1 | 93,361 | 16 | 186,723 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477 | instruction | 0 | 93,362 | 16 | 186,724 |
"Correct Solution:
```
import math
f=math.factorial
n,m=map(int,input().split())
if abs(n-m)>1:
print("0")
elif abs(n-m)==1:
ans=f(n)*f(m)
ans%=1000000007
print(ans)
else:
ans=f(n)*f(m)
ans*=2;
ans%=1000000007
print(ans)
``` | output | 1 | 93,362 | 16 | 186,725 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477 | instruction | 0 | 93,363 | 16 | 186,726 |
"Correct Solution:
```
MOD = 10 ** 9 + 7
def kaijo(n):
k = 1
for i in range(1, n + 1):
k = k * i % MOD
return k
n, m = map(int, input().split())
if n == m:
print((kaijo(n) ** 2 * 2) % MOD)
elif abs(n - m) > 1:
print(0)
else:
print((kaijo(n) * kaijo(m)) % MOD)
``` | output | 1 | 93,363 | 16 | 186,727 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477 | instruction | 0 | 93,364 | 16 | 186,728 |
"Correct Solution:
```
n, m = map(int, input().split())
def fac(x):
ans = 1
for i in range(1, x + 1):
ans = (ans * i) % (10 ** 9 + 7)
return(ans)
if n < m:
n, m = m, n
if n - m >= 2:
print(0)
elif n - m == 1:
print((fac(m)) ** 2 * n % (10 ** 9 + 7) )
else:
print((fac(n)) ** 2 * 2 % (10 ** 9 + 7))
``` | output | 1 | 93,364 | 16 | 186,729 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477 | instruction | 0 | 93,365 | 16 | 186,730 |
"Correct Solution:
```
mod = 1000000007
N,M = map(int,input().split())
if abs(N-M)>1:
print(0)
else:
ans = 1
for i in range(1,N+1): ans = (ans*i)%mod
for j in range(1,M+1): ans = (ans*j)%mod
if N==M: ans = (ans*2)%mod
print(ans)
``` | output | 1 | 93,365 | 16 | 186,731 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477 | instruction | 0 | 93,366 | 16 | 186,732 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
#ARC076C
import sys
import math
#n=int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
m=hoge[1]
#total=1
#if(n==m):
# total+=1
t = math.factorial(min(n,m))
#print(t)
#print(t**2)
if(abs(n-m)>1):
print(0)
elif(n==m):
print((2*(t**2))%1000000007)
else:
print(((t**2)*max(n,m))%1000000007)
``` | output | 1 | 93,366 | 16 | 186,733 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
from functools import reduce
n, m = map(int, input().split())
mod = 1000000007
def factorial(n):
return reduce(lambda x, y: x*y%mod, range(1, n+1))
if n==m:
print(2*factorial(n)*factorial(m)%mod)
elif abs(n-m)<=1:
print(factorial(n)*factorial(m)%mod)
else:
print(0)
``` | instruction | 0 | 93,367 | 16 | 186,734 |
Yes | output | 1 | 93,367 | 16 | 186,735 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
import math
n, m = [int(i) for i in input().split()]
print(0 if abs(n-m) > 1 else (math.factorial(n) * math.factorial(m) * (2 if n == m else 1)) % int(1e9 + 7))
``` | instruction | 0 | 93,368 | 16 | 186,736 |
Yes | output | 1 | 93,368 | 16 | 186,737 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
N,M = map(int,input().split())
p=10**9+7
def comb(a,p):
ini=1
for i in range(1,a+1):
ini = (ini*i)%p
return ini
if abs(N-M)>1:
ans=0
else:
if N!=M:
k=1
else:
k=2
dog=comb(N,p)
mon=comb(M,p)
tot=comb(N+M,p)
ans= (k*dog*mon)%p
print(ans)
``` | instruction | 0 | 93,369 | 16 | 186,738 |
Yes | output | 1 | 93,369 | 16 | 186,739 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
from math import *
M,N=input().split(' ')
M=int(M)
N=int(N)
res=1
if M==N:
res=factorial(M)
res=res*res*2
elif M-N==1:
res=factorial(N)
res*=res*M
elif M-N==-1:
res=factorial(M)
res*=res*N
else:
res=0
print(res%(10**9+7))
``` | instruction | 0 | 93,370 | 16 | 186,740 |
Yes | output | 1 | 93,370 | 16 | 186,741 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
import sys
sys.setrecursionlimit(100000)
d = 10**9 + 7
def factorial(n):
if (n > 1):
return (n % d) * factorial(n-1)
return 1
n, m = map(int, input().split())
ans = (factorial(n) % d) * (factorial(m) % d)
ans %= d
if n == m:
ans *= 2
print(ans)
``` | instruction | 0 | 93,371 | 16 | 186,742 |
No | output | 1 | 93,371 | 16 | 186,743 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
n, m = map(int, input().split())
def fac(x):
ans = 1
for i in range(1, x + 1):
ans = ans * i
return(ans)
if n < m:
n, m = m, n
if n - m >= 2:
print(0)
elif n - m == 1:
print((fac(m)) ** 2 * n % (10 ** 9 + 7) )
else:
print((fac(n)) ** 2 * 2 % (10 ** 9 + 7))
``` | instruction | 0 | 93,372 | 16 | 186,744 |
No | output | 1 | 93,372 | 16 | 186,745 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
M,N=input().split(' ')
M=int(M)
N=int(N)
res=1
if M==N:
for i in range(1, M+1):
res*=i
res=res*res*2
elif abs(M-N)==1:
for i in range(1, M+1):
res*=i
for i in range(1, N+1):
res*=i
else:
res=0
print(res%(10**9+7))
``` | instruction | 0 | 93,373 | 16 | 186,746 |
No | output | 1 | 93,373 | 16 | 186,747 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
# -*- coding: utf-8 -*-
#ARC076C
import sys
import math
#n=int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
m=hoge[1]
total=1
if(n==m):
total+=1
if(abs(n-m)>1):
print(0)
else:
print(total*math.factorial(n)*math.factorial(m))
``` | instruction | 0 | 93,374 | 16 | 186,748 |
No | output | 1 | 93,374 | 16 | 186,749 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.