message stringlengths 2 67k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 463 109k | cluster float64 19 19 | __index_level_0__ int64 926 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second | instruction | 0 | 35,809 | 19 | 71,618 |
"Correct Solution:
```
from sys import setrecursionlimit
setrecursionlimit(100000)
N,K = map(int,input().split())
A = tuple(map(int,input().split()))
dp = [False]*(K+1)
for n,v in enumerate(dp):
if not v:
for a in A:
if n+a <= K:
dp[n+a] = True
print('First' if dp[K] else 'Second')
``` | output | 1 | 35,809 | 19 | 71,619 |
Provide a correct Python 3 solution for this coding contest problem.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second | instruction | 0 | 35,810 | 19 | 71,620 |
"Correct Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * (k + 1)
for i in range(k + 1):
if dp[i] == 0:
for j in a:
if i + j > k:
break
else:
dp[i + j] = 1
print("First" if dp[k] else "Second")
``` | output | 1 | 35,810 | 19 | 71,621 |
Provide a correct Python 3 solution for this coding contest problem.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second | instruction | 0 | 35,811 | 19 | 71,622 |
"Correct Solution:
```
n,k=map(int,input().split())
li=[int(k) for k in input().split()]
dp=[False]*(k+1)
for i in range(1,k+1):
for j in range(len(li)):
if i-li[j]<0:
continue
if dp[i-li[j]]==False:
dp[i]=True
break
if dp[k]==True:
print("First")
else:
print("Second")
``` | output | 1 | 35,811 | 19 | 71,623 |
Provide a correct Python 3 solution for this coding contest problem.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second | instruction | 0 | 35,812 | 19 | 71,624 |
"Correct Solution:
```
def main():
n, k, *a = map(int, open(0).read().split())
g = [0] * (k + 1)
for i in range(min(a), k + 1):
s = set(g[i - x] for x in a if i >= x)
r = 0
while r in s:
r += 1
g[i] = r
print("First" if g[-1] else "Second")
if __name__=="__main__":
main()
``` | output | 1 | 35,812 | 19 | 71,625 |
Provide a correct Python 3 solution for this coding contest problem.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second | instruction | 0 | 35,813 | 19 | 71,626 |
"Correct Solution:
```
n,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
dp = [False]*(k+1)
for i,x in enumerate(dp):
if not x:
for ai in a:
if i+ai <= k:dp[i+ai] = True
if dp[k]:print('First')
else : print('Second')
``` | output | 1 | 35,813 | 19 | 71,627 |
Provide a correct Python 3 solution for this coding contest problem.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second | instruction | 0 | 35,814 | 19 | 71,628 |
"Correct Solution:
```
N,K=list(map(int,input().strip().split(" ")))
A=list(map(int,input().strip().split(" ")))
dp=[0]*(K+1)
dp[0]=0
for i in range(1,len(dp)):
for j in range(len(A)):
if i<A[j]:
break
if dp[i-A[j]]==0:
dp[i]=1
if dp[-1]==1:
print("First")
else:
print("Second")
``` | output | 1 | 35,814 | 19 | 71,629 |
Provide a correct Python 3 solution for this coding contest problem.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second | instruction | 0 | 35,815 | 19 | 71,630 |
"Correct Solution:
```
N, K = map(int, input().split())
a = tuple(map(int, input().split()))
def main():
l = [False] * (K+1)
for i in range(a[0] -1, K+1):
l[i] = any(not l[i-j] if i >= j else False for j in a)
if l[-1]:
print('First')
else:
print('Second')
main()
``` | output | 1 | 35,815 | 19 | 71,631 |
Provide a correct Python 3 solution for this coding contest problem.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second | instruction | 0 | 35,816 | 19 | 71,632 |
"Correct Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * (k+1) #残りの石iで回ってきたときの勝敗
for i in range(k+1):
dp[i] = 0
for j in a:
if j > i:
break
if 1 - dp[i-j]:
dp[i] = 1
break
print(['Second', 'First'][dp[k]])
``` | output | 1 | 35,816 | 19 | 71,633 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second
Submitted Solution:
```
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
dp = [False] * (K + 1)
for i in range(1, K + 1):
for a in A:
if i >= a:
dp[i] |= dp[i - a] ^ True
print('First' if dp[K] else 'Second')
``` | instruction | 0 | 35,817 | 19 | 71,634 |
Yes | output | 1 | 35,817 | 19 | 71,635 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second
Submitted Solution:
```
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False]*(k+1)
for i in range(1,k+1):
for j in range(n):
if i-a[j]<0:
break
if dp[i-a[j]]==False:
dp[i]=True
if dp[k]==True:
print('First')
else:
print('Second')
``` | instruction | 0 | 35,818 | 19 | 71,636 |
Yes | output | 1 | 35,818 | 19 | 71,637 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second
Submitted Solution:
```
n,k = map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
dp=[-1]*(k+1)
for i in range(1,k+1):
m=1
for j in arr:
if(i>=j):
m = min(dp[i-j],m)
dp[i] = -1*m
if(dp[k]==1):
print("First")
else:
print("Second")
``` | instruction | 0 | 35,819 | 19 | 71,638 |
Yes | output | 1 | 35,819 | 19 | 71,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second
Submitted Solution:
```
N, K, *A = map(int, open(0).read().split())
dp = [False] * (2 * K + 1)
for i in range(K):
if not dp[i]:
for a in A:
dp[i + a] = True
if dp[K]:
print("First")
else:
print("Second")
``` | instruction | 0 | 35,820 | 19 | 71,640 |
Yes | output | 1 | 35,820 | 19 | 71,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second
Submitted Solution:
```
import sys
# gcd
from fractions import gcd
# 切り上げ,切り捨て
# from math import ceil, floor
# リストの真のコピー(変更が伝播しない)
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l) # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2)) # [('b', 5), ('c', 4)]
# print(S.keys()) # dict_keys(['a', 'b', 'c'])
# print(S.values()) # dict_values([3, 5, 4])
# print(S.items()) # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template
N, K = mi()
a = lmi()
a.insert(0, -12)
dp = [False] * (K + 1)
for i in range(1, K + 1):
for j in range(1, N + 1):
if i >= a[j] and not dp[i - a[j]]:
dp[i] = True
if dp[K]:
print("First")
else:
print("Second")
``` | instruction | 0 | 35,821 | 19 | 71,642 |
No | output | 1 | 35,821 | 19 | 71,643 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
memo = [-1] * (k+1)
def rec(x):
if memo[x] >= 0:
return memo[x]
flag = 0
for i in range(n):
if x - a[i] < 0:
continue
if rec(x - a[i]) == 0:
flag = 1
if flag == 1:
memo[x] = 1
return 1
else:
memo[x] = 0
return 0
if rec(k) == 1:
print("First")
else:
print("Second")
``` | instruction | 0 | 35,822 | 19 | 71,644 |
No | output | 1 | 35,822 | 19 | 71,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second
Submitted Solution:
```
n,k=map(int,input().split())
li=[int(k) for k in input().split()]
dp=[False]*(k+1)
for i in range(1,k+1):
for j in range(len(li)):
if i-li[j]<0:
dp[i]=True
else:
if dp[i-li[j]]==False:
dp[i]=True
if dp[k]==True:
print("First")
else:
print("Second")
``` | instruction | 0 | 35,823 | 19 | 71,646 |
No | output | 1 | 35,823 | 19 | 71,647 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other.
Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro:
* Choose an element x in A, and remove exactly x stones from the pile.
A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner.
Constraints
* All values in input are integers.
* 1 \leq N \leq 100
* 1 \leq K \leq 10^5
* 1 \leq a_1 < a_2 < \cdots < a_N \leq K
Input
Input is given from Standard Input in the following format:
N K
a_1 a_2 \ldots a_N
Output
If Taro will win, print `First`; if Jiro will win, print `Second`.
Examples
Input
2 4
2 3
Output
First
Input
2 5
2 3
Output
Second
Input
2 7
2 3
Output
First
Input
3 20
1 2 3
Output
Second
Input
3 21
1 2 3
Output
First
Input
1 100000
1
Output
Second
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n, k = map(int, input().split())
a = list(map(int, input().split()))
memo = [-1] * (k+1)
def rec(x):
if memo[x] >= 0:
return memo[x]
flag = 0
for i in range(n):
if x - a[i] < 0:
continue
if rec(x - a[i]) == 0:
flag = 1
if flag == 1:
memo[x] = 1
return 1
else:
memo[x] = 0
return 0
if rec(k) == 1:
print("First")
else:
print("Second")
``` | instruction | 0 | 35,824 | 19 | 71,648 |
No | output | 1 | 35,824 | 19 | 71,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | instruction | 0 | 36,260 | 19 | 72,520 |
Tags: brute force, constructive algorithms, games, greedy
Correct Solution:
```
for T in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
m=max(a)
s=0
for i in a:
s+=i
if(m > (s-m) or (s & 1) or n==1):
print('T')
else:
print('HL')
``` | output | 1 | 36,260 | 19 | 72,521 |
Provide tags and a correct Python 3 solution for this coding contest problem.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | instruction | 0 | 36,261 | 19 | 72,522 |
Tags: brute force, constructive algorithms, games, greedy
Correct Solution:
```
from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
n = int(input())
*a, = map(int, input().split())
idx = -1
c = 0
while 1:
mx = 0
tmp = -1
for i in range(n):
if i != idx and a[i] > mx:
mx = a[i]
tmp = i
if mx == 0:
print(['HL', 'T'][c])
break
idx = tmp
a[idx] -= 1
c ^= 1
``` | output | 1 | 36,261 | 19 | 72,523 |
Provide tags and a correct Python 3 solution for this coding contest problem.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | instruction | 0 | 36,262 | 19 | 72,524 |
Tags: brute force, constructive algorithms, games, greedy
Correct Solution:
```
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
m=max(a)
s=sum(a)
if n==1 or s<2*m or s%2!=0:
print('T')
else:
print('HL')
``` | output | 1 | 36,262 | 19 | 72,525 |
Provide tags and a correct Python 3 solution for this coding contest problem.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | instruction | 0 | 36,263 | 19 | 72,526 |
Tags: brute force, constructive algorithms, games, greedy
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
if n==1:
print('T')
else:
s=sum(a)
m=max(a)
check=abs(s-m)
if check<m:
print('T')
else:
if s%2==0:
print("HL")
else:
print('T')
``` | output | 1 | 36,263 | 19 | 72,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | instruction | 0 | 36,264 | 19 | 72,528 |
Tags: brute force, constructive algorithms, games, greedy
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
a=sorted(list(map(int,input().split())))
s=sum(a[:-1])
if a[-1]>s:print('T')
else:print(['HL','T'][(s+a[-1])%2])
``` | output | 1 | 36,264 | 19 | 72,529 |
Provide tags and a correct Python 3 solution for this coding contest problem.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | instruction | 0 | 36,265 | 19 | 72,530 |
Tags: brute force, constructive algorithms, games, greedy
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
a = sorted([int(i) for i in input().split()])
if n == 1: print("T")
else:
summ = 0
for i in range(n-1):
summ += a[i]
if a[n-1] > summ: print("T")
else:
summ += a[n-1]
if summ %2 == 0: print("HL")
else: print("T")
``` | output | 1 | 36,265 | 19 | 72,531 |
Provide tags and a correct Python 3 solution for this coding contest problem.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | instruction | 0 | 36,266 | 19 | 72,532 |
Tags: brute force, constructive algorithms, games, greedy
Correct Solution:
```
import heapq
t=int(input())
while t:
n=int(input())
l=list(map(int,input().split()))
h=[]
for i in range(n):
heapq.heappush(h,(-l[i],i))
lol=0
prev1=-1
prev2=-1
lel=0
while h:
if(lol==0):
val,ind=heapq.heappop(h)
val=-val
if(ind==prev2 and len(h)==0):
lel=1
print("HL")
break
elif(ind==prev2):
val1,ind1=heapq.heappop(h)
heapq.heappush(h,(-val,ind))
val=-val1
ind=ind1
val-=1
lol=1-lol
prev1=ind
if(val!=0):
heapq.heappush(h,(-val,ind))
else:
val,ind=heapq.heappop(h)
val=-val
if(ind==prev1 and len(h)==0):
print("T")
lel=1
break
elif(ind==prev1):
val1,ind1=heapq.heappop(h)
heapq.heappush(h,(-val,ind))
val=-val1
ind=ind1
val-=1
lol=1-lol
prev2=ind
if(val!=0):
heapq.heappush(h,(-val,ind))
if(lel==0):
if(lol==0):
print("HL")
else:
print("T")
t-=1
``` | output | 1 | 36,266 | 19 | 72,533 |
Provide tags and a correct Python 3 solution for this coding contest problem.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner. | instruction | 0 | 36,267 | 19 | 72,534 |
Tags: brute force, constructive algorithms, games, greedy
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
l = sum(a[:-1])
if a[-1] > l:
print("T")
else:
if abs(l - a[-1]) % 2 == 0:
print("HL")
else:
print("T")
``` | output | 1 | 36,267 | 19 | 72,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Submitted Solution:
```
t=int(input())
for _ in range(t):
n=int(input())
a=list(map(int,input().split()))
t=sum(a)
flag=0
for i in range(n):
if 2*a[i]>t:
flag=1
break
if t%2==1:
flag=1
if flag==1:
print('T')
else:
print('HL')
``` | instruction | 0 | 36,268 | 19 | 72,536 |
Yes | output | 1 | 36,268 | 19 | 72,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Submitted Solution:
```
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 30/08/2020
from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
import heapq
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
tc = ii1()
for _ in range(tc):
n = ii1()
arr = [-1 * i for i in iia()]
heapq.heapify(arr)
prev = None
flag = 0
while len(arr):
cur = heapq.heappop(arr)
if prev == None:
prev = abs(cur) - 1
else:
if prev > 0:
heapq.heappush(arr, -1 * prev)
prev = abs(cur) - 1
flag = flag ^ 1
if flag:
print('T')
else:
print('HL')
``` | instruction | 0 | 36,269 | 19 | 72,538 |
Yes | output | 1 | 36,269 | 19 | 72,539 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Submitted Solution:
```
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
end=False
for i in l:
if i>s-i:
end=True
break
if end: print('T')
else: print('T' if s%2==1 else 'HL')
``` | instruction | 0 | 36,270 | 19 | 72,540 |
Yes | output | 1 | 36,270 | 19 | 72,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Submitted Solution:
```
from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
# from collections import deque
sys.setrecursionlimit(int(2e5+10))
# input = stdin.readline
# print = stdout.write
# dp=[-1]*100000
# lru_cache(None)
for __ in range(int(input())):
n=int(input())
ar=list(map(int,input().split()))
m=max(ar)
s=sum(ar)
if(s%2==1):
print('T')
elif(m>s-m):
print('T')
else:
print('HL')
``` | instruction | 0 | 36,271 | 19 | 72,542 |
Yes | output | 1 | 36,271 | 19 | 72,543 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Submitted Solution:
```
T=int(input())
for _ in range(T):
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
A_sum=sum(A)
if A[-1]>A_sum-A[-1]:#win first, first player always choose A[-1], and second player choose other
print("T")
else:
if A_sum%2==0:
print("HT")
else:
print("T")
print("HL")
``` | instruction | 0 | 36,272 | 19 | 72,544 |
No | output | 1 | 36,272 | 19 | 72,545 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Submitted Solution:
```
from math import gcd
from collections import defaultdict
t=int(input())
for _ in range(t):
n=int(input())
#a,b=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
a,b=0,0
for i in range(n):
if a<=b:
a+=l[i]
else:
b+=l[i]
if b>a:
a,b=b,a
if a>b:
print('T')
else:
print('HL')
``` | instruction | 0 | 36,273 | 19 | 72,546 |
No | output | 1 | 36,273 | 19 | 72,547 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Submitted Solution:
```
t=int(input())
for _ in range(t):
n=int(input())
list1=list(int(n) for n in input().split())
if(len(list1)==1):
ans='T'
if(len(list1)==2):
if(list1[0]!=list1[1]):
ans='T'
else:
ans='HL'
flag1=0
list1.sort(reverse=True)
while(len(list1)>=2):
if(len(list1)==2):
if(list1[0]!=list1[1]):
ans='T'
print(ans)
flag1=1
break
else:
print('HL')
flag1=1
break
a=list1[0]
b=list1[1]
list1.pop(0)
list1.pop(0)
flag=0
while(a>0 and b>0):
a=a-1
b=b-1
m1=max(a,b)
if(m1==0):
if(len(list1)==1 and list1[0]>1):
ans='HL'
break
list1.append(m1)
list1.sort(reverse=True)
if(flag1==0):
print(ans)
``` | instruction | 0 | 36,274 | 19 | 72,548 |
No | output | 1 | 36,274 | 19 | 72,549 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
T is playing a game with his friend, HL.
There are n piles of stones, the i-th pile initially has a_i stones.
T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.
Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.
Input
The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).
Output
For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)
Example
Input
2
1
2
2
1 1
Output
T
HL
Note
In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.
Submitted Solution:
```
n = int(input())
for i in range(n):
f = int(input())
d = list(map(int,input().split()))[:n]
d.sort()
f = sum(d)
if sum(d)%2==0:
if d[-1]>f-d[-1]:
print("T")
else:
print("HL")
else:
print("T")
``` | instruction | 0 | 36,275 | 19 | 72,550 |
No | output | 1 | 36,275 | 19 | 72,551 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Alice's computer is broken, so she can't play her favorite card game now. To help Alice, Bob wants to answer n her questions.
Initially, Bob holds one card with number 0 in the left hand and one in the right hand. In the i-th question, Alice asks Bob to replace a card in the left or right hand with a card with number k_i (Bob chooses which of two cards he changes, Bob must replace exactly one card).
After this action, Alice wants the numbers on the left and right cards to belong to given segments (segments for left and right cards can be different). Formally, let the number on the left card be x, and on the right card be y. Then after the i-th swap the following conditions must be satisfied: a_{l, i} ≤ x ≤ b_{l, i}, and a_{r, i} ≤ y ≤ b_{r,i}.
Please determine if Bob can answer all requests. If it is possible, find a way to do it.
Input
The first line contains two integers n and m (2 ≤ n ≤ 100 000, 2 ≤ m ≤ 10^9) — the number of questions and the maximum possible value on the card.
Then n queries are described. Every description contains 3 lines.
The first line of the description of the i-th query contains a single integer k_i (0 ≤ k_i ≤ m) — the number on a new card.
The second line of the description of the i-th query contains two integers a_{l, i} and b_{l, i} (0 ≤ a_{l, i} ≤ b_{l, i} ≤ m) — the minimum and maximum values of the card at the left hand after the replacement.
The third line of the description of the i-th query contains two integers a_{r, i} and b_{r,i} (0 ≤ a_{r, i} ≤ b_{r,i} ≤ m) — the minimum and maximum values of the card at the right hand after the replacement.
Output
At the first line, print "Yes", if Bob can answer all queries, and "No" otherwise.
If Bob can answer all n queries, then at the second line print n numbers: a way to satisfy all requirements. If in i-th query Bob needs to replace the card in the left hand, print 0, otherwise print 1. If there are multiple answers, print any.
Examples
Input
2 10
3
0 3
0 2
2
0 4
0 2
Output
Yes
0 1
Input
2 10
3
0 3
0 2
2
3 4
0 1
Output
No
Input
5 10
3
0 3
0 3
7
4 7
1 3
2
2 3
3 7
8
1 8
1 8
6
1 6
7 10
Output
Yes
1 0 0 1 0 | instruction | 0 | 36,345 | 19 | 72,690 |
Tags: binary search, constructive algorithms, data structures, dp, greedy, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
K, A0, B0, A1, B1 = [], [], [], [], []
for _ in range(n):
k = int(input())
a0, b0 = map(int, input().split())
a1, b1 = map(int, input().split())
K.append(k)
A0.append(a0)
B0.append(b0)
A1.append(a1)
B1.append(b1)
ans = []
C0, D0, C1, D1 = [0] * (n + 1), [0] * (n + 1), [0] * (n + 1), [0] * (n + 1)
C0[n], D0[n], C1[n], D1[n] = 0, m, 0, m
for i in range(n - 1, -1, -1):
C0[i], D0[i], C1[i], D1[i] = m + 1, 0, m + 1, 0
if A0[i] <= K[i] <= B0[i]:
if C0[i + 1] <= K[i] <= D0[i + 1]:
C1[i], D1[i] = A1[i], B1[i]
else:
C1[i], D1[i] = max(A1[i], C1[i + 1]), min(B1[i], D1[i + 1])
if A1[i] <= K[i] <= B1[i]:
if C1[i + 1] <= K[i] <= D1[i + 1]:
C0[i], D0[i] = A0[i], B0[i]
else:
C0[i], D0[i] = max(A0[i], C0[i + 1]), min(B0[i], D0[i + 1])
if C0[0] <= 0 <= D0[0] or C1[0] <= 0 <= D1[0]:
print("Yes")
x, y = 0, 0
for i in range(n):
if A0[i] <= K[i] <= B0[i] and A1[i] <= y <= B1[i] and (C0[i + 1] <= K[i] <= D0[i + 1] or C1[i + 1] <= y <= D1[i + 1]):
x = K[i]
ans.append(0)
else:
y = K[i]
ans.append(1)
print(*ans)
else:
print("No")
``` | output | 1 | 36,345 | 19 | 72,691 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Alice's computer is broken, so she can't play her favorite card game now. To help Alice, Bob wants to answer n her questions.
Initially, Bob holds one card with number 0 in the left hand and one in the right hand. In the i-th question, Alice asks Bob to replace a card in the left or right hand with a card with number k_i (Bob chooses which of two cards he changes, Bob must replace exactly one card).
After this action, Alice wants the numbers on the left and right cards to belong to given segments (segments for left and right cards can be different). Formally, let the number on the left card be x, and on the right card be y. Then after the i-th swap the following conditions must be satisfied: a_{l, i} ≤ x ≤ b_{l, i}, and a_{r, i} ≤ y ≤ b_{r,i}.
Please determine if Bob can answer all requests. If it is possible, find a way to do it.
Input
The first line contains two integers n and m (2 ≤ n ≤ 100 000, 2 ≤ m ≤ 10^9) — the number of questions and the maximum possible value on the card.
Then n queries are described. Every description contains 3 lines.
The first line of the description of the i-th query contains a single integer k_i (0 ≤ k_i ≤ m) — the number on a new card.
The second line of the description of the i-th query contains two integers a_{l, i} and b_{l, i} (0 ≤ a_{l, i} ≤ b_{l, i} ≤ m) — the minimum and maximum values of the card at the left hand after the replacement.
The third line of the description of the i-th query contains two integers a_{r, i} and b_{r,i} (0 ≤ a_{r, i} ≤ b_{r,i} ≤ m) — the minimum and maximum values of the card at the right hand after the replacement.
Output
At the first line, print "Yes", if Bob can answer all queries, and "No" otherwise.
If Bob can answer all n queries, then at the second line print n numbers: a way to satisfy all requirements. If in i-th query Bob needs to replace the card in the left hand, print 0, otherwise print 1. If there are multiple answers, print any.
Examples
Input
2 10
3
0 3
0 2
2
0 4
0 2
Output
Yes
0 1
Input
2 10
3
0 3
0 2
2
3 4
0 1
Output
No
Input
5 10
3
0 3
0 3
7
4 7
1 3
2
2 3
3 7
8
1 8
1 8
6
1 6
7 10
Output
Yes
1 0 0 1 0 | instruction | 0 | 36,346 | 19 | 72,692 |
Tags: binary search, constructive algorithms, data structures, dp, greedy, implementation
Correct Solution:
```
from sys import stdin, stdout
n, m = [int(y) for y in stdin.readline().split()]
x = []
left_lower = []
left_upper = []
right_lower = []
right_upper = []
for _ in range(n):
x.append(int(stdin.readline()))
y0, y1 = [int(y) for y in stdin.readline().split()]
left_lower.append(y0)
left_upper.append(y1)
y0, y1 = [int(y) for y in stdin.readline().split()]
right_lower.append(y0)
right_upper.append(y1)
left_possible = [[m,0] for i in range(n)]
left_possible.append([0,m])
right_possible = [[m,0] for i in range(n)]
right_possible.append([0,m])
for i in range(n-1,-1,-1):
if left_lower[i] <= x[i] <= left_upper[i]:
if left_possible[i+1][0] <= x[i] <= left_possible[i+1][1]:
right_possible[i][0] = right_lower[i]
right_possible[i][1] = right_upper[i]
else:
right_possible[i][0] = max(right_lower[i], right_possible[i+1][0])
right_possible[i][1] = min(right_upper[i], right_possible[i+1][1])
if right_lower[i] <= x[i] <= right_upper[i]:
if right_possible[i+1][0] <= x[i] <= right_possible[i+1][1]:
left_possible[i][0] = left_lower[i]
left_possible[i][1] = left_upper[i]
else:
left_possible[i][0] = max(left_lower[i], left_possible[i+1][0])
left_possible[i][1] = min(left_upper[i], left_possible[i+1][1])
if left_possible[0][0] == 0 or right_possible[0][0] == 0:
stdout.write('YES\n')
left = 0
right = 0
answer = []
for i in range(n):
if right_possible[i][0] <= right <= right_possible[i][1]:
answer.append('0')
left = x[i]
else:
answer.append('1')
right = x[i]
stdout.write(' '.join(answer)+'\n')
else:
stdout.write('NO\n')
``` | output | 1 | 36,346 | 19 | 72,693 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Alice's computer is broken, so she can't play her favorite card game now. To help Alice, Bob wants to answer n her questions.
Initially, Bob holds one card with number 0 in the left hand and one in the right hand. In the i-th question, Alice asks Bob to replace a card in the left or right hand with a card with number k_i (Bob chooses which of two cards he changes, Bob must replace exactly one card).
After this action, Alice wants the numbers on the left and right cards to belong to given segments (segments for left and right cards can be different). Formally, let the number on the left card be x, and on the right card be y. Then after the i-th swap the following conditions must be satisfied: a_{l, i} ≤ x ≤ b_{l, i}, and a_{r, i} ≤ y ≤ b_{r,i}.
Please determine if Bob can answer all requests. If it is possible, find a way to do it.
Input
The first line contains two integers n and m (2 ≤ n ≤ 100 000, 2 ≤ m ≤ 10^9) — the number of questions and the maximum possible value on the card.
Then n queries are described. Every description contains 3 lines.
The first line of the description of the i-th query contains a single integer k_i (0 ≤ k_i ≤ m) — the number on a new card.
The second line of the description of the i-th query contains two integers a_{l, i} and b_{l, i} (0 ≤ a_{l, i} ≤ b_{l, i} ≤ m) — the minimum and maximum values of the card at the left hand after the replacement.
The third line of the description of the i-th query contains two integers a_{r, i} and b_{r,i} (0 ≤ a_{r, i} ≤ b_{r,i} ≤ m) — the minimum and maximum values of the card at the right hand after the replacement.
Output
At the first line, print "Yes", if Bob can answer all queries, and "No" otherwise.
If Bob can answer all n queries, then at the second line print n numbers: a way to satisfy all requirements. If in i-th query Bob needs to replace the card in the left hand, print 0, otherwise print 1. If there are multiple answers, print any.
Examples
Input
2 10
3
0 3
0 2
2
0 4
0 2
Output
Yes
0 1
Input
2 10
3
0 3
0 2
2
3 4
0 1
Output
No
Input
5 10
3
0 3
0 3
7
4 7
1 3
2
2 3
3 7
8
1 8
1 8
6
1 6
7 10
Output
Yes
1 0 0 1 0 | instruction | 0 | 36,347 | 19 | 72,694 |
Tags: binary search, constructive algorithms, data structures, dp, greedy, implementation
Correct Solution:
```
def solve():
n, m = map(int, input().split())
arr = []
ql = []
qr = []
for i in range(n):
arr.append(int(input()))
ql.append(list(map(int, input().split())))
qr.append(list(map(int, input().split())))
al = [[m+1, 0] for i in range(n+1)]
ar = [[m+1, 0] for i in range(n+1)]
al[n] = [0, m]
ar[n] = [0, m]
for i in range(n-1, -1, -1):
if ql[i][0] <= arr[i] <= ql[i][1]:
if al[i+1][0] <= arr[i] <= al[i+1][1]:
ar[i] = qr[i][:]
else:
ar[i][0] = max(ar[i+1][0], qr[i][0])
ar[i][1] = min(ar[i+1][1], qr[i][1])
if qr[i][0] <= arr[i] <= qr[i][1]:
if ar[i+1][0] <= arr[i] <= ar[i+1][1]:
al[i] = ql[i][:]
else:
al[i][0] = max(al[i+1][0], ql[i][0])
al[i][1] = min(al[i+1][1], ql[i][1])
if al[0][0] and ar[0][0]:
print("NO")
return
x, y = 0, 0
ans = []
for i in range(n):
if ar[i][0] <= y <= ar[i][1]:
ans.append(0)
x = arr[i]
else:
ans.append(1)
y = arr[i]
print("YES")
print(*ans)
import sys
input = lambda: sys.stdin.readline().rstrip()
solve()
``` | output | 1 | 36,347 | 19 | 72,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Alice's computer is broken, so she can't play her favorite card game now. To help Alice, Bob wants to answer n her questions.
Initially, Bob holds one card with number 0 in the left hand and one in the right hand. In the i-th question, Alice asks Bob to replace a card in the left or right hand with a card with number k_i (Bob chooses which of two cards he changes, Bob must replace exactly one card).
After this action, Alice wants the numbers on the left and right cards to belong to given segments (segments for left and right cards can be different). Formally, let the number on the left card be x, and on the right card be y. Then after the i-th swap the following conditions must be satisfied: a_{l, i} ≤ x ≤ b_{l, i}, and a_{r, i} ≤ y ≤ b_{r,i}.
Please determine if Bob can answer all requests. If it is possible, find a way to do it.
Input
The first line contains two integers n and m (2 ≤ n ≤ 100 000, 2 ≤ m ≤ 10^9) — the number of questions and the maximum possible value on the card.
Then n queries are described. Every description contains 3 lines.
The first line of the description of the i-th query contains a single integer k_i (0 ≤ k_i ≤ m) — the number on a new card.
The second line of the description of the i-th query contains two integers a_{l, i} and b_{l, i} (0 ≤ a_{l, i} ≤ b_{l, i} ≤ m) — the minimum and maximum values of the card at the left hand after the replacement.
The third line of the description of the i-th query contains two integers a_{r, i} and b_{r,i} (0 ≤ a_{r, i} ≤ b_{r,i} ≤ m) — the minimum and maximum values of the card at the right hand after the replacement.
Output
At the first line, print "Yes", if Bob can answer all queries, and "No" otherwise.
If Bob can answer all n queries, then at the second line print n numbers: a way to satisfy all requirements. If in i-th query Bob needs to replace the card in the left hand, print 0, otherwise print 1. If there are multiple answers, print any.
Examples
Input
2 10
3
0 3
0 2
2
0 4
0 2
Output
Yes
0 1
Input
2 10
3
0 3
0 2
2
3 4
0 1
Output
No
Input
5 10
3
0 3
0 3
7
4 7
1 3
2
2 3
3 7
8
1 8
1 8
6
1 6
7 10
Output
Yes
1 0 0 1 0
Submitted Solution:
```
from sys import stdin, stdout
n, m = [int(y) for y in stdin.readline().split()]
I = [[0,'']]
J = [[0,'']]
universal_fail = False
for _ in range(n):
x = int(stdin.readline())
left_lower, left_upper = [int(y) for y in stdin.readline().split()]
right_lower, right_upper = [int(y) for y in stdin.readline().split()]
I_fail = False
J_fail = False
if left_lower > I[-1][0] or left_upper < I[0][0] or x < right_lower or x > right_upper:
I_fail = True
if x < left_lower or x > left_upper or right_lower > J[-1][0] or right_upper < J[0][0]:
J_fail = True
if I_fail and J_fail:
universal_fail = True
break
I_new = []
J_new = []
I_x_seen = False
J_x_seen = False
if not I_fail:
for i in I:
if left_lower <= i[0] and left_upper >= i[0]:
I_new.append([i[0], i[1] + '1 '])
if i == x:
I_x_seen = True
if not J_fail:
for j in J:
if right_lower <= j[0] and right_upper >= j[0]:
J_new.append([j[0], j[1] + '0 '])
if j == x:
J_x_seen = True
if not I_fail and not J_x_seen:
J_new.append([x, I_new[0][1]])
if not J_fail and not I_x_seen:
I_new.append([x, J_new[0][1]])
I = I_new
J = J_new
if universal_fail:
for foo in range(n-_-1):
x = int(stdin.readline())
left_lower, left_upper = [int(y) for y in stdin.readline().split()]
right_lower, right_upper = [int(y) for y in stdin.readline().split()]
stdout.write('NO\n')
else:
stdout.write('YES\n')
stdout.write(I[0][1][:-1] + '\n')
``` | instruction | 0 | 36,348 | 19 | 72,696 |
No | output | 1 | 36,348 | 19 | 72,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Alice's computer is broken, so she can't play her favorite card game now. To help Alice, Bob wants to answer n her questions.
Initially, Bob holds one card with number 0 in the left hand and one in the right hand. In the i-th question, Alice asks Bob to replace a card in the left or right hand with a card with number k_i (Bob chooses which of two cards he changes, Bob must replace exactly one card).
After this action, Alice wants the numbers on the left and right cards to belong to given segments (segments for left and right cards can be different). Formally, let the number on the left card be x, and on the right card be y. Then after the i-th swap the following conditions must be satisfied: a_{l, i} ≤ x ≤ b_{l, i}, and a_{r, i} ≤ y ≤ b_{r,i}.
Please determine if Bob can answer all requests. If it is possible, find a way to do it.
Input
The first line contains two integers n and m (2 ≤ n ≤ 100 000, 2 ≤ m ≤ 10^9) — the number of questions and the maximum possible value on the card.
Then n queries are described. Every description contains 3 lines.
The first line of the description of the i-th query contains a single integer k_i (0 ≤ k_i ≤ m) — the number on a new card.
The second line of the description of the i-th query contains two integers a_{l, i} and b_{l, i} (0 ≤ a_{l, i} ≤ b_{l, i} ≤ m) — the minimum and maximum values of the card at the left hand after the replacement.
The third line of the description of the i-th query contains two integers a_{r, i} and b_{r,i} (0 ≤ a_{r, i} ≤ b_{r,i} ≤ m) — the minimum and maximum values of the card at the right hand after the replacement.
Output
At the first line, print "Yes", if Bob can answer all queries, and "No" otherwise.
If Bob can answer all n queries, then at the second line print n numbers: a way to satisfy all requirements. If in i-th query Bob needs to replace the card in the left hand, print 0, otherwise print 1. If there are multiple answers, print any.
Examples
Input
2 10
3
0 3
0 2
2
0 4
0 2
Output
Yes
0 1
Input
2 10
3
0 3
0 2
2
3 4
0 1
Output
No
Input
5 10
3
0 3
0 3
7
4 7
1 3
2
2 3
3 7
8
1 8
1 8
6
1 6
7 10
Output
Yes
1 0 0 1 0
Submitted Solution:
```
from sys import stdin, stdout
n, m = [int(y) for y in stdin.readline().split()]
I = [[0,'']]
J = [[0,'']]
universal_fail = False
for _ in range(n):
x = int(stdin.readline())
left_lower, left_upper = [int(y) for y in stdin.readline().split()]
right_lower, right_upper = [int(y) for y in stdin.readline().split()]
I_fail = False
J_fail = False
if left_lower > I[-1][0] or left_upper < I[0][0] or x < right_lower or x > right_upper:
I_fail = True
if x < left_lower or x > left_upper or right_lower > J[-1][0] or right_upper < J[0][0]:
J_fail = True
if I_fail and J_fail:
universal_fail = True
break
I_new = []
J_new = []
I_x_seen = False
J_x_seen = False
if not I_fail:
for i in I:
if left_lower <= i[0] and left_upper >= i[0]:
I_new.append([i[0], i[1] + '1 '])
if i[0] == x:
I_x_seen = True
if not J_fail:
for j in J:
if right_lower <= j[0] and right_upper >= j[0]:
J_new.append([j[0], j[1] + '0 '])
if j[0] == x:
J_x_seen = True
if not I_fail and not J_x_seen:
J_new.append([x, I_new[0][1]])
if not J_fail and not I_x_seen:
I_new.append([x, J_new[0][1]])
I = I_new
J = J_new
if universal_fail:
for foo in range(n-_-1):
x = int(stdin.readline())
left_lower, left_upper = [int(y) for y in stdin.readline().split()]
right_lower, right_upper = [int(y) for y in stdin.readline().split()]
stdout.write('NO\n')
else:
stdout.write('YES\n')
stdout.write(I[0][1][:-1] + '\n')
``` | instruction | 0 | 36,349 | 19 | 72,698 |
No | output | 1 | 36,349 | 19 | 72,699 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.
Output
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8. | instruction | 0 | 36,430 | 19 | 72,860 |
Tags: implementation, math
Correct Solution:
```
n = int(input())
up = []
do = []
for i in range(n):
a, b = map(int, input().split())
up.append(a)
do.append(b)
sum_up = sum(up)
sum_do = sum(do)
if sum_up % 2 == 0 and sum_do % 2 == 0:
print(0)
elif sum_up % 2 != sum_do % 2:
print(-1)
else:
found = False
for i in range(n):
if do[i] % 2 != up[i] % 2:
found = True
break
print(1 if found else -1)
``` | output | 1 | 36,430 | 19 | 72,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.
Output
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8. | instruction | 0 | 36,432 | 19 | 72,864 |
Tags: implementation, math
Correct Solution:
```
if __name__ == '__main__':
n = int(input())
num = 0
state = [0, 0]
for i in range(n):
a, b = map(int, input().split())
a %= 2
b %= 2
if a != b:
num += 1
state[0] += a
state[1] += b
state[0] %= 2
state[1] %= 2
if state == [0, 0]:
print(0)
elif state == [1, 1]:
print(1 if num > 0 else -1)
else:
print(-1)
``` | output | 1 | 36,432 | 19 | 72,865 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.
Output
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8. | instruction | 0 | 36,433 | 19 | 72,866 |
Tags: implementation, math
Correct Solution:
```
n=int(input())
c=0
sx=0
sy=0
for _ in range(n):
x,y=map(int,input().split())
sx+=x
sy+=y
if(x%2!=y%2):
c+=1
if(sx%2==0 and sy%2==0):
print(0)
elif(c%2==0 and c>0):
print(1)
else:
print(-1)
``` | output | 1 | 36,433 | 19 | 72,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.
Output
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
Submitted Solution:
```
s,ss=0,0
c=0
for _ in range(int(input())):
x,y=map(int,input().split())
s,ss=(s+x)%2,(ss+y)%2
if (x+y)%2==1:
c+=1
if s==0 and ss==0:
print(0)
elif s==1 and ss==1:
if c>=1:
print(1)
else:
print(-1)
else:
print(-1)
``` | instruction | 0 | 36,436 | 19 | 72,872 |
Yes | output | 1 | 36,436 | 19 | 72,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.
Output
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
Submitted Solution:
```
n=int(input())
s1=0
s2=0
b1=False
for i in range(n):
a,b=map(int,input().split())
if a%2!=0 and b%2==0:
b1=True
elif a%2 ==0 and b%2!=0:
b1=True
s1+=a
s2+=b
if s1%2==0 and s2%2==0:
print(0)
elif s1&1 and s2&1 and b1:
print(1)
else:
print(-1)
``` | instruction | 0 | 36,437 | 19 | 72,874 |
Yes | output | 1 | 36,437 | 19 | 72,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.
Output
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
Submitted Solution:
```
# coding: utf-8
n = int(input())
upper = 0
lower = 0
flag = False
for i in range(n):
tmp = [int(i) for i in input().split()]
upper += tmp[0]%2
lower += tmp[1]%2
if tmp[0]%2 != tmp[1]%2:
flag = True
if upper%2==0 and lower%2==0:
print(0)
elif upper%2+lower%2 == 1:
print(-1)
elif not flag:
print(-1)
else:
print(1)
``` | instruction | 0 | 36,438 | 19 | 72,876 |
Yes | output | 1 | 36,438 | 19 | 72,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.
Output
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
Submitted Solution:
```
n = int(input())
A,B,C = 0,0,0
for i in range(n):
a,b = map(int, input().split())
A += a
B += b
if a % 2 != b % 2:
C = 1
if A % 2 == 0 and B % 2 == 0:
print(0)
elif A % 2 == 1 and B % 2 == 1 and C:
print(1)
else:
print(-1)
'''
Bal ita ar vala lage na. kotodine jami r lakhan coder oitam
'''
``` | instruction | 0 | 36,439 | 19 | 72,878 |
Yes | output | 1 | 36,439 | 19 | 72,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.
Output
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
Submitted Solution:
```
n= int(input())
l1=[]
l2=[]
countodd1=0
countodd2=0
for i in range(n):
x,y= map(int, input().split())
if x%2!=0:
countodd1+=1
if y%2!=0:
countodd2+=1
l1.append(x)
l2.append(y)
if countodd1==n and countodd2==n:
print(-1)
elif (sum(l1)+sum(l2))%2!=0:
print(-1)
elif sum(l1)%2==0 and sum(l2)%2==0:
print(0)
else:
t= countodd1%2
r= countodd2%2
if t+r==0:
print(0)
else:
print((t+r)//2)
``` | instruction | 0 | 36,440 | 19 | 72,880 |
No | output | 1 | 36,440 | 19 | 72,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.
Output
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
Submitted Solution:
```
n=int(input())
x=[]
for i in range(n):
m=list(map(int,input().split()))
x.append(m)
u=0
l=0
for i in range(n):
u=u+x[i][0]
l=l+x[i][1]
if u%2==0 and l%2==0:
print(0)
elif (u%2!=0 and l%2==0) or (u%2==0 and l%2!=0):
print(-1)
elif len(x)==1 and u%2!=0 and l%2!=0:
print(-1)
else:
print(1)
``` | instruction | 0 | 36,441 | 19 | 72,882 |
No | output | 1 | 36,441 | 19 | 72,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.
Output
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
Submitted Solution:
```
n = int(input())
up, down, dom = 0, 0, []
for _ in range(n):
dom.append(list(x%2 for x in map(int, input().split())))
up += dom[_][0]
down += dom[_][1]
if (up%2 == 0 and down%2 == 1) or (up%2 == 1 and down%2 == 0):
print('-1')
elif up%2 == 1 and down%2 == 1:
if [0, 1] or [1, 0] in dom:
print('1')
else:
print('-1')
else:
print('0')
``` | instruction | 0 | 36,442 | 19 | 72,884 |
No | output | 1 | 36,442 | 19 | 72,885 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.
Input
The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.
Output
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print - 1.
Examples
Input
2
4 2
6 4
Output
0
Input
1
2 3
Output
-1
Input
3
1 4
2 3
4 4
Output
1
Note
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.
In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
Submitted Solution:
```
# Target - Expert on CF
# Be Humblefool
import sys
inf = float("inf")
# sys.setrecursionlimit(100000)
# abc='abcdefghijklmnopqrstuvwxyz'
# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
# mod, MOD = 1000000007, 998244353
# words = {1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',7:'seven',8:'eight',9:'nine',10:'ten',11:'eleven',12:'twelve',13:'thirteen',14:'fourteen',15:'quarter',16:'sixteen',17:'seventeen',18:'eighteen',19:'nineteen',20:'twenty',21:'twenty one',22:'twenty two',23:'twenty three',24:'twenty four',25:'twenty five',26:'twenty six',27:'twenty seven',28:'twenty eight',29:'twenty nine',30:'half'}
# vow=['a','e','i','o','u']
# dx,dy=[0,1,0,-1],[1,0,-1,0]
# import random
# from collections import deque, Counter, OrderedDict,defaultdict
# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
# from math import ceil,floor,log,sqrt,factorial,pi,gcd
# from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n = int(input())
even1 = even2 = 0
odd1 = odd2 = 0
sum1 = sum2 = 0
for i in range(n):
x,y = get_ints()
if x&1: odd1+=1
else: even1+=1
if y&1: odd2+=1
else: even2+=1
sum1+=x
sum2+=y
if sum1%2==0 and sum2%2==0:
print(0)
exit()
if sum1&1 and sum2&1:
if (even1>=1 and odd2>=1) or (even2>=1 and odd1>=1):
print(1)
else:
print(-1)
exit()
print(-1)
``` | instruction | 0 | 36,443 | 19 | 72,886 |
No | output | 1 | 36,443 | 19 | 72,887 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The employees of the F company have lots of ways to entertain themselves. Today they invited a famous magician who shows a trick with plastic cups and a marble.
The point is to trick the spectator's attention. Initially, the spectator stands in front of a line of n plastic cups. Then the magician places a small marble under one cup and shuffles the cups. Then the spectator should guess which cup hides the marble.
But the head coder of the F company isn't easy to trick. When he saw the performance, he noticed several important facts:
* each cup contains a mark — a number from 1 to n; all marks on the cups are distinct;
* the magician shuffles the cups in m operations, each operation looks like that: take a cup marked xi, sitting at position yi in the row of cups (the positions are numbered from left to right, starting from 1) and shift it to the very beginning of the cup row (on the first position).
When the head coder came home after work he wanted to re-do the trick. Unfortunately, he didn't remember the starting or the final position of the cups. He only remembered which operations the magician performed. Help the coder: given the operations in the order they were made find at least one initial permutation of the cups that can go through the described operations in the given order. Otherwise, state that such permutation doesn't exist.
Input
The first line contains integers n and m (1 ≤ n, m ≤ 106). Each of the next m lines contains a couple of integers. The i-th line contains integers xi, yi (1 ≤ xi, yi ≤ n) — the description of the i-th operation of the magician. Note that the operations are given in the order in which the magician made them and the coder wants to make them in the same order.
Output
If the described permutation doesn't exist (the programmer remembered wrong operations), print -1. Otherwise, print n distinct integers, each from 1 to n: the i-th number should represent the mark on the cup that initially is in the row in position i.
If there are multiple correct answers, you should print the lexicographically minimum one.
Examples
Input
2 1
2 1
Output
2 1
Input
3 2
1 2
1 1
Output
2 1 3
Input
3 3
1 3
2 3
1 3
Output
-1 | instruction | 0 | 36,454 | 19 | 72,908 |
Tags: data structures
Correct Solution:
```
import io
import os
# List with O(n^1/3) (for n=10**6) get/set/insert/delete based on: https://github.com/cheran-senthil/PyRival/blob/master/pyrival/data_structures/SortedList.py
class UnsortedList:
def __init__(self, iterable=[], _load=1000):
"""Initialize sorted list instance."""
values = sorted(iterable)
self._len = _len = len(values)
self._load = _load
self._lists = _lists = [values[i : i + _load] for i in range(0, _len, _load)]
self._list_lens = [len(_list) for _list in _lists]
# self._mins = [_list[0] for _list in _lists]
self._fen_tree = []
self._rebuild = True
def _fen_build(self):
"""Build a fenwick tree instance."""
self._fen_tree[:] = self._list_lens
_fen_tree = self._fen_tree
for i in range(len(_fen_tree)):
if i | i + 1 < len(_fen_tree):
_fen_tree[i | i + 1] += _fen_tree[i]
self._rebuild = False
def _fen_update(self, index, value):
"""Update `fen_tree[index] += value`."""
if not self._rebuild:
_fen_tree = self._fen_tree
while index < len(_fen_tree):
_fen_tree[index] += value
index |= index + 1
def _fen_query(self, end):
"""Return `sum(_fen_tree[:end])`."""
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
x = 0
while end:
x += _fen_tree[end - 1]
end &= end - 1
return x
def _fen_findkth(self, k):
"""Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
_list_lens = self._list_lens
if k < _list_lens[0]:
return 0, k
if k >= self._len - _list_lens[-1]:
return len(_list_lens) - 1, k + _list_lens[-1] - self._len
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
idx = -1
for d in reversed(range(len(_fen_tree).bit_length())):
right_idx = idx + (1 << d)
if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
idx = right_idx
k -= _fen_tree[idx]
return idx + 1, k
def _delete(self, pos, idx):
"""Delete value at the given `(pos, idx)`."""
_lists = self._lists
# _mins = self._mins
_list_lens = self._list_lens
self._len -= 1
self._fen_update(pos, -1)
del _lists[pos][idx]
_list_lens[pos] -= 1
if _list_lens[pos]:
# _mins[pos] = _lists[pos][0]
pass
else:
del _lists[pos]
del _list_lens[pos]
# del _mins[pos]
self._rebuild = True
def __len__(self):
"""Return the size of the sorted list."""
return self._len
def __getitem__(self, index):
"""Lookup value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
return self._lists[pos][idx]
def __delitem__(self, index):
"""Remove value at `index` from sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
self._delete(pos, idx)
def __setitem__(self, index, value):
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
self._lists[pos][idx] = value
def insert(self, index, value):
_load = self._load
_lists = self._lists
_list_lens = self._list_lens
if _lists:
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
self._fen_update(pos, 1)
_list = _lists[pos]
_list.insert(idx, value)
_list_lens[pos] += 1
if _load + _load < len(_list):
_lists.insert(pos + 1, _list[_load:])
_list_lens.insert(pos + 1, len(_list) - _load)
_list_lens[pos] = _load
del _list[_load:]
self._rebuild = True
else:
_lists.append([value])
_list_lens.append(1)
self._rebuild = True
self._len += 1
def __iter__(self):
"""Return an iterator over the sorted list."""
return (value for _list in self._lists for value in _list)
def __reversed__(self):
"""Return a reverse iterator over the sorted list."""
return (value for _list in reversed(self._lists) for value in reversed(_list))
def __repr__(self):
"""Return string representation of sorted list."""
return "SortedList({0})".format(list(self))
def solve(N, M, queries):
idToMark = [-1 for i in range(N)]
cups = UnsortedList([i for i in range(N)])
for mark, pos in queries:
pos -= 1 # 0-indexed
cupId = cups[pos]
del cups[pos]
cups.insert(0, cupId)
if idToMark[cupId] == -1:
idToMark[cupId] = mark
elif idToMark[cupId] != mark:
return b"-1"
markToCounts = [0 for i in range(N + 1)]
for cupId, mark in enumerate(idToMark):
if mark != -1:
markToCounts[mark] += 1
if markToCounts[mark] > 1:
return b"-1"
j = 1
ans = []
for cupId, mark in enumerate(idToMark):
if mark != -1:
ans.append(mark)
else:
while markToCounts[j] > 0:
j += 1
ans.append(j)
j += 1
return b" ".join(str(x).encode("ascii") for x in ans)
if False:
N, M = 10 ** 6, 10 ** 6
queries = [[N // 2 + (i % (N // 2)), N // 2] for i in range(M)]
ans = solve(N, M, queries)
# print(ans)
assert ans != b"-1"
exit()
if __name__ == "__main__":
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
N, M = [int(x) for x in input().split()]
queries = ((int(x) for x in input().split()) for i in range(M))
ans = solve(N, M, queries)
os.write(1, ans)
``` | output | 1 | 36,454 | 19 | 72,909 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The employees of the F company have lots of ways to entertain themselves. Today they invited a famous magician who shows a trick with plastic cups and a marble.
The point is to trick the spectator's attention. Initially, the spectator stands in front of a line of n plastic cups. Then the magician places a small marble under one cup and shuffles the cups. Then the spectator should guess which cup hides the marble.
But the head coder of the F company isn't easy to trick. When he saw the performance, he noticed several important facts:
* each cup contains a mark — a number from 1 to n; all marks on the cups are distinct;
* the magician shuffles the cups in m operations, each operation looks like that: take a cup marked xi, sitting at position yi in the row of cups (the positions are numbered from left to right, starting from 1) and shift it to the very beginning of the cup row (on the first position).
When the head coder came home after work he wanted to re-do the trick. Unfortunately, he didn't remember the starting or the final position of the cups. He only remembered which operations the magician performed. Help the coder: given the operations in the order they were made find at least one initial permutation of the cups that can go through the described operations in the given order. Otherwise, state that such permutation doesn't exist.
Input
The first line contains integers n and m (1 ≤ n, m ≤ 106). Each of the next m lines contains a couple of integers. The i-th line contains integers xi, yi (1 ≤ xi, yi ≤ n) — the description of the i-th operation of the magician. Note that the operations are given in the order in which the magician made them and the coder wants to make them in the same order.
Output
If the described permutation doesn't exist (the programmer remembered wrong operations), print -1. Otherwise, print n distinct integers, each from 1 to n: the i-th number should represent the mark on the cup that initially is in the row in position i.
If there are multiple correct answers, you should print the lexicographically minimum one.
Examples
Input
2 1
2 1
Output
2 1
Input
3 2
1 2
1 1
Output
2 1 3
Input
3 3
1 3
2 3
1 3
Output
-1 | instruction | 0 | 36,455 | 19 | 72,910 |
Tags: data structures
Correct Solution:
```
import io
import os
# List with O(n^1/3) (for n=10**6) get/set/insert/delete based on: https://github.com/cheran-senthil/PyRival/blob/master/pyrival/data_structures/SortedList.py
class UnsortedList:
def __init__(self, iterable=[], _load=600):
"""Initialize sorted list instance."""
values = sorted(iterable)
self._len = _len = len(values)
self._load = _load
self._lists = _lists = [values[i : i + _load] for i in range(0, _len, _load)]
self._list_lens = [len(_list) for _list in _lists]
# self._mins = [_list[0] for _list in _lists]
self._fen_tree = []
self._rebuild = True
def _fen_build(self):
"""Build a fenwick tree instance."""
self._fen_tree[:] = self._list_lens
_fen_tree = self._fen_tree
for i in range(len(_fen_tree)):
if i | i + 1 < len(_fen_tree):
_fen_tree[i | i + 1] += _fen_tree[i]
self._rebuild = False
def _fen_update(self, index, value):
"""Update `fen_tree[index] += value`."""
if not self._rebuild:
_fen_tree = self._fen_tree
while index < len(_fen_tree):
_fen_tree[index] += value
index |= index + 1
def _fen_query(self, end):
"""Return `sum(_fen_tree[:end])`."""
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
x = 0
while end:
x += _fen_tree[end - 1]
end &= end - 1
return x
def _fen_findkth(self, k):
"""Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
_list_lens = self._list_lens
if k < _list_lens[0]:
return 0, k
if k >= self._len - _list_lens[-1]:
return len(_list_lens) - 1, k + _list_lens[-1] - self._len
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
idx = -1
for d in reversed(range(len(_fen_tree).bit_length())):
right_idx = idx + (1 << d)
if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
idx = right_idx
k -= _fen_tree[idx]
return idx + 1, k
def _delete(self, pos, idx):
"""Delete value at the given `(pos, idx)`."""
_lists = self._lists
# _mins = self._mins
_list_lens = self._list_lens
self._len -= 1
self._fen_update(pos, -1)
del _lists[pos][idx]
_list_lens[pos] -= 1
if _list_lens[pos]:
# _mins[pos] = _lists[pos][0]
pass
else:
del _lists[pos]
del _list_lens[pos]
# del _mins[pos]
self._rebuild = True
def __len__(self):
"""Return the size of the sorted list."""
return self._len
def __getitem__(self, index):
"""Lookup value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
return self._lists[pos][idx]
def __delitem__(self, index):
"""Remove value at `index` from sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
self._delete(pos, idx)
def __setitem__(self, index, value):
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
self._lists[pos][idx] = value
def insert(self, index, value):
_load = self._load
_lists = self._lists
_list_lens = self._list_lens
if _lists:
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
self._fen_update(pos, 1)
_list = _lists[pos]
_list.insert(idx, value)
_list_lens[pos] += 1
if _load + _load < len(_list):
_lists.insert(pos + 1, _list[_load:])
_list_lens.insert(pos + 1, len(_list) - _load)
_list_lens[pos] = _load
del _list[_load:]
self._rebuild = True
else:
_lists.append([value])
_list_lens.append(1)
self._rebuild = True
self._len += 1
def __iter__(self):
"""Return an iterator over the sorted list."""
return (value for _list in self._lists for value in _list)
def __reversed__(self):
"""Return a reverse iterator over the sorted list."""
return (value for _list in reversed(self._lists) for value in reversed(_list))
def __repr__(self):
"""Return string representation of sorted list."""
return "SortedList({0})".format(list(self))
def solve(N, M, queries):
idToMark = [-1 for i in range(N)]
cups = UnsortedList([i for i in range(N)])
for mark, pos in queries:
pos -= 1 # 0-indexed
cupId = cups[pos]
del cups[pos]
cups.insert(0, cupId)
if idToMark[cupId] == -1:
idToMark[cupId] = mark
elif idToMark[cupId] != mark:
return b"-1"
markToCounts = [0 for i in range(N + 1)]
for cupId, mark in enumerate(idToMark):
if mark != -1:
markToCounts[mark] += 1
if markToCounts[mark] > 1:
return b"-1"
j = 1
ans = []
for cupId, mark in enumerate(idToMark):
if mark != -1:
ans.append(mark)
else:
while markToCounts[j] > 0:
j += 1
ans.append(j)
j += 1
return b" ".join(str(x).encode("ascii") for x in ans)
if False:
N, M = 10 ** 6, 10 ** 6
queries = [[N // 2 + (i % (N // 2)), N // 2] for i in range(M)]
ans = solve(N, M, queries)
# print(ans)
assert ans != b"-1"
exit()
if __name__ == "__main__":
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
N, M = [int(x) for x in input().split()]
queries = ((int(x) for x in input().split()) for i in range(M))
ans = solve(N, M, queries)
os.write(1, ans)
``` | output | 1 | 36,455 | 19 | 72,911 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.