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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position s. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position p1, the glass from the second position to position p2 and so on. That is, a glass goes from position i to position pi. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.
After all shuffling operations Petya shows Vasya that the ball has moved to position t. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position s to position t.
Input
The first line contains three integers: n, s, t (1 ≤ n ≤ 105; 1 ≤ s, t ≤ n) — the number of glasses, the ball's initial and final position. The second line contains n space-separated integers: p1, p2, ..., pn (1 ≤ pi ≤ n) — the shuffling operation parameters. It is guaranteed that all pi's are distinct.
Note that s can equal t.
Output
If the marble can move from position s to position t, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position t. If it is impossible, print number -1.
Examples
Input
4 2 1
2 3 4 1
Output
3
Input
4 3 3
4 1 3 2
Output
0
Input
4 3 4
1 2 3 4
Output
-1
Input
3 1 3
2 1 3
Output
-1
Submitted Solution:
```
from sys import stdin,stdout
n,s,t=map(int,stdin.readline().split())
cost=1
w=[int(x) for x in stdin.readline().split()]
ind=w.index(t)
a=w[:ind]
a=sorted(a)
if(s==t):print(0)
elif(a!=w[:ind]):print(-1)
elif(w[s-1]==s):print(-1)
else:
p=0
j=s-1
ptr=w[j]
while(p==0):
if(ptr==t):
print(cost)
p=1
else:
cost+=1
ptr=w[ptr-1]
``` | instruction | 0 | 74,488 | 19 | 148,976 |
No | output | 1 | 74,488 | 19 | 148,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position s. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position p1, the glass from the second position to position p2 and so on. That is, a glass goes from position i to position pi. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.
After all shuffling operations Petya shows Vasya that the ball has moved to position t. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position s to position t.
Input
The first line contains three integers: n, s, t (1 ≤ n ≤ 105; 1 ≤ s, t ≤ n) — the number of glasses, the ball's initial and final position. The second line contains n space-separated integers: p1, p2, ..., pn (1 ≤ pi ≤ n) — the shuffling operation parameters. It is guaranteed that all pi's are distinct.
Note that s can equal t.
Output
If the marble can move from position s to position t, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position t. If it is impossible, print number -1.
Examples
Input
4 2 1
2 3 4 1
Output
3
Input
4 3 3
4 1 3 2
Output
0
Input
4 3 4
1 2 3 4
Output
-1
Input
3 1 3
2 1 3
Output
-1
Submitted Solution:
```
#!/usr/bin/env python3
def main():
n, s, t = map(int, input().split())
p = list(map(int, input().split()))
glass, ans = s, 0
for i,pi in zip(range(1,n+1),p):
if glass == i and glass != pi:
glass = pi
ans += 1
if (glass == s or glass == t):
break
print(ans if glass == t else -1)
if __name__ == "__main__":
main()
``` | instruction | 0 | 74,489 | 19 | 148,978 |
No | output | 1 | 74,489 | 19 | 148,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position s. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position p1, the glass from the second position to position p2 and so on. That is, a glass goes from position i to position pi. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.
After all shuffling operations Petya shows Vasya that the ball has moved to position t. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position s to position t.
Input
The first line contains three integers: n, s, t (1 ≤ n ≤ 105; 1 ≤ s, t ≤ n) — the number of glasses, the ball's initial and final position. The second line contains n space-separated integers: p1, p2, ..., pn (1 ≤ pi ≤ n) — the shuffling operation parameters. It is guaranteed that all pi's are distinct.
Note that s can equal t.
Output
If the marble can move from position s to position t, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position t. If it is impossible, print number -1.
Examples
Input
4 2 1
2 3 4 1
Output
3
Input
4 3 3
4 1 3 2
Output
0
Input
4 3 4
1 2 3 4
Output
-1
Input
3 1 3
2 1 3
Output
-1
Submitted Solution:
```
import sys
input = sys.stdin.buffer.readline
n,s,t = list(map(int, input().split()))
p = list(map(int, input().split()))
initial = p[s-1]
nxt = p[s-1]
cnt = 0
while nxt!=t:
nxt = p[nxt-1]
cnt+=1
if nxt==t:
cnt+=1
break
if nxt==initial:
cnt=-1
break
print(cnt)
``` | instruction | 0 | 74,490 | 19 | 148,980 |
No | output | 1 | 74,490 | 19 | 148,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position s. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position p1, the glass from the second position to position p2 and so on. That is, a glass goes from position i to position pi. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.
After all shuffling operations Petya shows Vasya that the ball has moved to position t. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position s to position t.
Input
The first line contains three integers: n, s, t (1 ≤ n ≤ 105; 1 ≤ s, t ≤ n) — the number of glasses, the ball's initial and final position. The second line contains n space-separated integers: p1, p2, ..., pn (1 ≤ pi ≤ n) — the shuffling operation parameters. It is guaranteed that all pi's are distinct.
Note that s can equal t.
Output
If the marble can move from position s to position t, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position t. If it is impossible, print number -1.
Examples
Input
4 2 1
2 3 4 1
Output
3
Input
4 3 3
4 1 3 2
Output
0
Input
4 3 4
1 2 3 4
Output
-1
Input
3 1 3
2 1 3
Output
-1
Submitted Solution:
```
n, a, b = map(int, input().split())
t = [0] + list(map(int, input().split()))
x = t[a]
u = 1
while x != b and x != a:
x = t[x]
u += 1
if x == a: print(-1)
else:
x = t[b]
v = 1
while x != a:
x = t[x]
v += 1
print(max(u, v))
``` | instruction | 0 | 74,491 | 19 | 148,982 |
No | output | 1 | 74,491 | 19 | 148,983 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image> | instruction | 0 | 74,555 | 19 | 149,110 |
Tags: brute force, dfs and similar, games
Correct Solution:
```
def helper(s1,s2,visited,move):
n,m=len(s1),len(s2)
if n==0:
print(move,'2')
return
if m==0:
print(move,'1')
return
if tuple([tuple(s1),tuple(s2)]) in visited:
print('-1')
return
else:
visited.add(tuple([tuple(s1),tuple(s2)]))
if s1[0]>s2[0]:
a=s2.pop(0)
s1+=[a,s1[0]]
s1.pop(0)
else:
a=s1.pop(0)
s2+=[a,s2[0]]
s2.pop(0)
helper(s1,s2,visited,move+1)
n=[int(x) for x in input().split()]
a1=[int(x) for x in input().split()]
a2=[int(x) for x in input().split()]
visited=set()
#visited.add(tuple([tuple(s1),tuple(s2)]))
helper(a1[1:],a2[1:],visited,0)
``` | output | 1 | 74,555 | 19 | 149,111 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image> | instruction | 0 | 74,556 | 19 | 149,112 |
Tags: brute force, dfs and similar, games
Correct Solution:
```
from collections import *
n=int(input())
li1=list(map(int,input().split(" ")))
li2=list(map(int,input().split(" ")))
st1=deque(li1[1::])
st2=deque(li2[1::])
li1=deque(li1[1::])
li2=deque(li2[1::])
checked=[]
temp=st1.copy(),st2.copy()
checked.append(temp)
p1 = st1.popleft()
p2 = st2.popleft()
if p1 > p2:
st1.append(p2)
st1.append(p1)
else:
st2.append(p1)
st2.append(p2)
res=0
count=1
while True:
if len(st2)==0:
res=1
break
if len(st1)==0:
res=2
break
temp=st1.copy(),st2.copy()
if temp in checked:
break
checked.append(temp)
p1=st1.popleft()
p2=st2.popleft()
if p1>p2:
st1.append(p2)
st1.append(p1)
else:
st2.append(p1)
st2.append(p2)
count+=1
if res==0:
print(-1)
quit()
print(count,res)
``` | output | 1 | 74,556 | 19 | 149,113 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image> | instruction | 0 | 74,557 | 19 | 149,114 |
Tags: brute force, dfs and similar, games
Correct Solution:
```
# It's never too late to start!
from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math
import heapq
import re
def sin():
return input()
def ain():
return list(map(int, sin().split()))
def sain():
return input().split()
def iin():
return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
s = set()
for p in range(2, n+1):
if prime[p]:
s.add(p)
return s
def readTree(n, m):
adj = [deque([]) for _ in range(n+1)]
for _ in range(m):
u,v = ain()
adj[u].append(v)
adj[v].append(u)
return adj
# Stay hungry, stay foolish!
def main():
n = iin()
k1 = ain()
k2 = ain()
d1 = deque(k1[1:])
d2 = deque(k2[1:])
k1 = k1[0]
k2 = k2[0]
a1 = deque([d1.copy()])
a2 = deque([d2.copy()])
flag = -1
ans = 0
while 1:
ans += 1
x1 = d1.popleft()
x2 = d2.popleft()
if x1>x2:
d1.append(x2)
d1.append(x1)
else:
d2.append(x1)
d2.append(x2)
if len(d1) == 0:
flag = 2
break
if len(d2) == 0:
flag = 1
break
if d1 in a1 and d2 in a2:
break
a1.append(d1.copy())
a2.append(d2.copy())
if flag == -1:
print(flag)
else:
print(ans, flag)
# Fast IO Template starts
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
if os.getcwd() == 'D:\\code':
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# Fast IO Template ends
if __name__ == "__main__":
main()
# Never Give Up - John Cena
``` | output | 1 | 74,557 | 19 | 149,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image> | instruction | 0 | 74,558 | 19 | 149,116 |
Tags: brute force, dfs and similar, games
Correct Solution:
```
n=int(input())
stack1= list(map(int,input().split()))
stack2= list(map(int,input().split()))
k1=stack1.pop(0)
k2=stack2.pop(0)
final=0
state=[(stack1[:],stack2[:])]
bool1=True
while True:
if (stack1,stack2) in state[:-1]:
print(-1)
bool1=False
break
if stack1[0]>stack2[0]:
stack1.append(stack2[0])
stack2.pop(0)
stack1.append(stack1[0])
stack1.pop(0)
state.append((stack1[:],stack2[:]))
elif stack1[0]<stack2[0]:
stack2.append(stack1[0])
stack1.pop(0)
stack2.append(stack2[0])
stack2.pop(0)
state.append((stack1[:],stack2[:]))
if len(stack1)==0:
final=2
break
elif len(stack2)==0:
final=1
break
if bool1:
print(len(state)-1)
print(final)
``` | output | 1 | 74,558 | 19 | 149,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image> | instruction | 0 | 74,559 | 19 | 149,118 |
Tags: brute force, dfs and similar, games
Correct Solution:
```
nCards = int(input())
n1Cards, *cards1 = [int(x) for x in input().split()]
n2Cards, *cards2 = [int(x) for x in input().split()]
top1 = 0
top2 = 0
end1 = n1Cards
end2 = n2Cards
seenStates = set((tuple(sum([cards1, [0], cards2], [])), ))
#print(seenStates)
turns = 0
while top1 != end1 and top2 != end2:
if cards1[top1] > cards2[top2]:
cards1.append(cards2[top2])
cards1.append(cards1[top1])
top1 += 1
top2 += 1
end1 += 2
else:
cards2.append(cards1[top1])
cards2.append(cards2[top2])
top1 += 1
top2 += 1
end2 += 2
if (tuple(sum([cards1[top1:end1+1], [0], cards2[top2:end2+1]], [])), ) in seenStates:
#print(seenStates)
print(-1)
break
seenStates.add((tuple(sum([cards1[top1:end1+1], [0], cards2[top2:end2+1]], [])), ))
#print(seenStates)
turns += 1
else:
if top1 == end1:
print(turns, 2)
else:
print(turns, 1)
``` | output | 1 | 74,559 | 19 | 149,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image> | instruction | 0 | 74,560 | 19 | 149,120 |
Tags: brute force, dfs and similar, games
Correct Solution:
```
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
############ ---- Input Functions ---- ############
def in_int():
return (int(input()))
def in_list():
return (list(map(int, input().split())))
def in_str():
s = input()
return (list(s[:len(s) - 1]))
def in_ints():
return (map(int, input().split()))
n = in_int()
a = in_list()
b = in_list()
xx = a.pop(0)
xx = b.pop(0)
ss = set()
count = 0
while str(a)+str(b) not in ss and len(a) >0 and len(b)>0:
ss.add(str(a)+str(b))
aa = a.pop(0)
bb = b.pop(0)
if aa > bb:
a = a + [bb,aa]
else:
b= b + [aa,bb]
count +=1
if len(a) == 0 :
print(count , 2)
elif len(b) == 0 :
print(count, 1)
else:
print(-1)
``` | output | 1 | 74,560 | 19 | 149,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image> | instruction | 0 | 74,561 | 19 | 149,122 |
Tags: brute force, dfs and similar, games
Correct Solution:
```
x=int(input())
A=list(map(int,input().split()))
A=A[1:]
#print(A)
D=A
#print(D)
B=list(map(int,input().split()))
B=B[1:]
E=B
C=[]
#print(A)
#print(B)
count=0
num=1000
while(num>0):
if count==999:
state=10000
break
#print(D)
state=-100
if A==C:
state=10
break
if B==C:
state=100
break
if A[0]>B[0]:
A.append(B[0])
A.append(A[0])
A=A[1:]
B=B[1:]
count=count+1
#print(A,B)
state=0
num=num-1
if state!=0:
if B[0]>A[0]:
B.append(A[0])
B.append(B[0])
B=B[1:]
A=A[1:]
count=count+1
#print(A,B)
num=num-1
#if A==D:
# if B==E:
# state=1000
# break
#if A==E:
# if B==D:
# state=1000
# break
if state==10:
print (count,2)
if state==100:
print (count,1)
if state==10000:
print (-1)
``` | output | 1 | 74,561 | 19 | 149,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image> | instruction | 0 | 74,562 | 19 | 149,124 |
Tags: brute force, dfs and similar, games
Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n = I()
a = LI()[1:]
b = LI()[1:]
for i in range(100000):
if a[0] > b[0]:
a = a[1:] + [b[0],a[0]]
b = b[1:]
if len(b) == 0:
return '{} {}'.format(i+1, 1)
else:
b = b[1:] + [a[0],b[0]]
a = a[1:]
if len(a) == 0:
return '{} {}'.format(i+1, 2)
return -1
print(main())
``` | output | 1 | 74,562 | 19 | 149,125 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image>
Submitted Solution:
```
z = lambda :list(map(int, input().split()))
n = int(input())
k1 = z()[1:]
k2 = z()[1:]
c = 0
while k1 and k2:
x, y = k1.pop(0), k2.pop(0)
if x > y:
k1 += [y, x]
else:
k2 += [x, y]
if c > 1000:
print(-1)
break
c += 1
else:
print(c, 1 if k1 else 2)
``` | instruction | 0 | 74,563 | 19 | 149,126 |
Yes | output | 1 | 74,563 | 19 | 149,127 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image>
Submitted Solution:
```
from collections import deque
from copy import deepcopy
n = int(input())
A = deque(list(map(int, input().split()))[1:])
B = deque(list(map(int, input().split()))[1:])
state = []
state.append((deepcopy(A), deepcopy(B)))
cnt = 0
while len(A) > 0 and len(B) > 0:
if A[0] > B[0]:
A.append(B.popleft())
A.append(A.popleft())
else:
B.append(A.popleft())
B.append(B.popleft())
if (A, B) in state:
print(-1)
break
state.append((deepcopy(A), deepcopy(B)))
cnt += 1
else:
print(cnt, 1 if len(B) == 0 else 2)
``` | instruction | 0 | 74,564 | 19 | 149,128 |
Yes | output | 1 | 74,564 | 19 | 149,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image>
Submitted Solution:
```
I = lambda: list(map(int, input().split()))
n = int(input())
d1 = I()[1:]
d2 = I()[1:]
states = set()
while 1:
if d1[0] > d2[0]:
d1 = d1[1:] + [d2[0], d1[0]]
d2 = d2[1:]
else:
d2 = d2[1:] + [d1[0], d2[0]]
d1 = d1[1:]
if len(d2)==0:
print(len(states)+1, 1)
break
if len(d1)==0:
print(len(states)+1, 2)
break
state = "".join(map(str, d1)) + "|" + "".join(map(str, d2))
if state in states:
print(-1)
break
states.add(state)
``` | instruction | 0 | 74,565 | 19 | 149,130 |
Yes | output | 1 | 74,565 | 19 | 149,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image>
Submitted Solution:
```
n = int(input())
string = input()
s1 = list(map(int, string.split()))
string = input()
s2 = list(map(int, string.split()))
del s1[0], s2[0]
cards1 = []
cards2 = []
a = 0
while True:
if len(s1) == 0:
print(str(a) + " 2")
break
elif len(s2) == 0:
print(str(a) + " 1")
break
x = s1[0]
y = s2[0]
del s1[0], s2[0]
if x > y:
s1.append(y)
s1.append(x)
else:
s2.append(x)
s2.append(y)
condition = False
for x in range(a):
if cards1[x] == s1 and cards2[x] == s2:
print(-1)
condition = True
break
if condition:
break
cards1.append(s1[:])
cards2.append(s2[:])
a += 1
``` | instruction | 0 | 74,566 | 19 | 149,132 |
Yes | output | 1 | 74,566 | 19 | 149,133 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image>
Submitted Solution:
```
# cook your dish here
#import sys
#sys.setrecursionlimit(10**9)
ll=lambda:map(int,input().split())
t=lambda:int(input())
ss=lambda:input()
lx=lambda x:map(int,input().split(x))
yy=lambda:print("YES")
nn=lambda:print("NO")
from math import log10 ,log2,ceil,factorial as fac,gcd,inf,sqrt,log
#from itertools import combinations_with_replacement as cs
#from functools import reduce
from bisect import bisect_right as br,bisect_left as bl
from collections import Counter
#from math import inf
mod=10**9+7
#for _ in range(t()):
def f():
n=t()
k1,*a=list(ll())
k2,*b=list(ll())
q=[]
c=0
q.append([a.copy(),b.copy()])
print(q)
while len(a) and len(b):
c+=1
x,y=a.pop(0),b.pop(0)
if x>y:
a.append(y)
a.append(x)
else:
b.append(x)
b.append(y)
#print(a,b)
if [a,b] not in q:
q.append([a.copy(),b.copy()])
else:
#print(q,[a,b])
print(-1)
break
else:
print(c,[1,2][len(b)>0])
f()
'''
baca
bac
1 2 3
baaccca
abbaccccaba
'''
``` | instruction | 0 | 74,567 | 19 | 149,134 |
No | output | 1 | 74,567 | 19 | 149,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image>
Submitted Solution:
```
def main():
#gathering data
n = int(input())
temp = input().split()
p1n= int(temp[0])
p1cards = [int(i) for i in temp[1:]]
temp = input().split()
p2n = int(temp[0])
p2cards = [int(i) for i in temp[1:]]
stale = False
history = []
counter = 0
# history.append(p1cards)
# history.append(p2cards)
# if (p1cards[0] > p2cards[0]):
# p1cards, p2cards = switchero(p1cards,p2cards)
# elif (p2cards[0] > p1cards[0]):
# p2cards, p1cards = switchero(p2cards,p1cards)
while(len(p1cards) != 0 and len(p2cards) != 0 and stale == False):
counter += 1
history.append(p1cards)
history.append(p2cards)
if (p1cards[0] > p2cards[0]):
p1cards, p2cards = switchero(p1cards,p2cards)
elif (p2cards[0] > p1cards[0]):
p2cards, p1cards = switchero(p2cards,p1cards)
for cards in history:
if p1cards == cards:
stale = True
if stale == True:
counter = -1
if len(p1cards) == 0:
winner = 2
print(counter, winner)
elif len(p2cards) ==0:
winner = 1
print(counter, winner)
else:
print(counter)
def switchero(winner,loser):
if len(loser) == 1:
losernew = []
else:
losernew = loser[1:]
winnernew = winner[1:]
winnernew.append(loser[0])
winnernew.append(winner[0])
return winnernew,losernew
if __name__ == "__main__": main()
``` | instruction | 0 | 74,568 | 19 | 149,136 |
No | output | 1 | 74,568 | 19 | 149,137 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image>
Submitted Solution:
```
def to_list(s):
return list(map(lambda x: int(x), s.split(' ')))
def make_step(a,b):
a_copy, b_copy = a.copy(), b.copy()
if a_copy[0] > b_copy[0]:
a_copy.extend([b_copy[0],a[0]])
else:
b_copy.extend([a_copy[0],b_copy[0]])
a_copy, b_copy = a_copy[1:], b_copy[1:]
return a_copy,b_copy
def solve(a,b):
k = 0
while True:
prev_a, prev_b = a,b
a,b = make_step(a,b)
k += 1
if (a == []) | (b == []):
break
if ((make_step(a,b)[0] == prev_a) &
(make_step(a,b)[1] == prev_b)):
return -1
if a == []:
number = 2
else:
number = 1
return str(k) + ' ' + str(number)
n = int(input())
a = to_list(input())[1:]
b = to_list(input())[1:]
solve(a,b)
``` | instruction | 0 | 74,569 | 19 | 149,138 |
No | output | 1 | 74,569 | 19 | 149,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
You have to calculate how many fights will happen and who will win the game, or state that game won't end.
Input
First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.
Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
All card values are different.
Output
If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
If the game won't end and will continue forever output - 1.
Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note
First sample:
<image>
Second sample:
<image>
Submitted Solution:
```
from copy import deepcopy
n = int(input())
a = list(map(int,input().split()))[1:]
b = list(map(int,input().split()))[1:]
data = []
count =0
while(a and b):
print(a,b)
if (a,b) in data:
print(-1)
break
data.append((deepcopy(a),deepcopy(b)))
if a>b:
a+=[b.pop(0),a.pop(0)]
elif a<b:
b+=[a.pop(0),b.pop(0)]
count+=1
if not(a) or not(b): print(count,1 if a else 2)
``` | instruction | 0 | 74,570 | 19 | 149,140 |
No | output | 1 | 74,570 | 19 | 149,141 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3 | instruction | 0 | 74,844 | 19 | 149,688 |
"Correct Solution:
```
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
n = mid
dp = [0] * (K + 1)
dp[0] = 1
for i in range(N):
a = A[i]
if i == n or a >= K:
continue
for j in range(K, a - 1, -1):
dp[j] |= dp[j - a]
rst = any(dp[k] for k in range(max(0, K - A[n]), K))
if rst:
ok = mid
else:
ng = mid
print(ok)
main()
``` | output | 1 | 74,844 | 19 | 149,689 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3 | instruction | 0 | 74,845 | 19 | 149,690 |
"Correct Solution:
```
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
N,K = MI()
A = LI()
A.sort()
def f(n): # Anが必要か否か
B = [0] + [A[i] for i in range(N) if i != n]
dp = [[0]*K for _ in range(2)] # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
dp[0][0] = 1
for i in range(1,N):
b = B[i]
for j in range(K):
if j >= b:
dp[i%2][j] = dp[1-i%2][j] | dp[1-i%2][j-b]
else:
dp[i%2][j] = dp[1-i%2][j]
if sum(dp[(N-1) % 2][j] for j in range(max(K-A[n],0),K)) != 0:
return True
else:
return False
left = -1 # 不必要
right = N # 必要
while left + 1 < right:
mid = (left + right)//2
if f(mid):
right = mid
else:
left = mid
print(right)
``` | output | 1 | 74,845 | 19 | 149,691 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3 | instruction | 0 | 74,846 | 19 | 149,692 |
"Correct Solution:
```
N, K = map(int, input().split())
A = [0] + sorted(map(int, input().split()))
# iを除いた左右の部分集合でK以上の数が作れるか
rdp_shift = [N + 1] * K # rdp_shift[j] = (右からi個を使って部分和jを作れるような最初のi)
rdp_shift[0] = 0
rdp = [0] * K # rdp[i][j] = (a(-1),...,a(-i)の部分和でjを作れるか)
rdp[0] = 1
for i in range(1, N + 1):
rdp2 = [0] * K
for j in range(K):
if rdp[j] == 1:
rdp2[j] = 1
continue
# print(j, -i, j - A[-i])
# print(i, j)
if j - A[-i] >= 0 and rdp[j - A[-i]] == 1:
rdp2[j] = 1
rdp_shift[j] = i
rdp = rdp2
# print(rdp_shift, A)
ldp = [0] * K
ldp[0] = 1
S = [0] * (K + 1)
ans = 0
for i in range(1, N + 1):
# ここで一つ一つチェックしている!!
# A[i]が不要かチェック
for j in range(K):
# print(j)
S[j + 1] = S[j]
if rdp_shift[j] <= N - i:
# print(S, rdp_shift, j, N - i, A[i])
S[j + 1] += 1
# print(S)
# print(S, rdp_shift[j], N - i, i, j)
no_need = True
for lval in range(K):
# print(ldp, lval)
if ldp[lval] == 0:
continue
# print(K - A[i] - lval)
rval = S[K - lval] - S[max(0, K - A[i] - lval)]
# print(S, K - lval, K - A[i] - lval, rval)
# print(rval, no_need, A[i], lval)
# rval > 0というのはA[i]がなければ、K以上の集合を作れない場合があるということ
if rval > 0:
# print(S, K - lval, K - A[i] - lval, lval, rval, i, j, A[i])
no_need = False
break
if no_need:
ans += 1
# ldp[i][:]の計算
ldp2 = [0] * K
for j in range(K):
if ldp[j] == 1 or (j >= A[i] and ldp[j - A[i]] == 1):
ldp2[j] = 1
ldp = ldp2
print(ans)
``` | output | 1 | 74,846 | 19 | 149,693 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3 | instruction | 0 | 74,847 | 19 | 149,694 |
"Correct Solution:
```
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = 0
sum = 0
cnt = 0
for i in range(N):
a = A[i]
if sum+a>=K:
ans += cnt+1
cnt = 0
else:
sum += a
cnt += 1
print(N-ans)
``` | output | 1 | 74,847 | 19 | 149,695 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3 | instruction | 0 | 74,848 | 19 | 149,696 |
"Correct Solution:
```
import bisect
from collections import deque
N, K = map(int, input().split())
a = sorted(map(int, input().split()))
# K以上のカードは単体で条件を満たすから考えない
a_k = bisect.bisect_left(a, K, lo=0, hi=N)
A = a[:a_k][::-1]
tmp = 0
N = result = N-(N-a_k)
for n, i in enumerate(A):
if tmp+i >= K:
result = N-(n+1)
else:
tmp += i
print(result)
``` | output | 1 | 74,848 | 19 | 149,697 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3 | instruction | 0 | 74,849 | 19 | 149,698 |
"Correct Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)[::-1]
ans = n
sm = 0
for i in range(n):
if sm + a[i] < k:
sm += a[i]
else:
ans = min(ans, n - i - 1)
print(ans)
``` | output | 1 | 74,849 | 19 | 149,699 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3 | instruction | 0 | 74,850 | 19 | 149,700 |
"Correct Solution:
```
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,k = list(map(int, input().split()))
a = list(map(lambda x: min(int(x), k+1), input().split()))
a.sort()
mask = (1<<(k+1)) - 1
def sub(ii):
dp = 1
for i in range(n):
if i==ii:
continue
dp |= (dp<<a[i]) & mask
# for j in range(k-1, a[i]-1, -1):
# dp[j] += dp[j-a[i]]
val = max(i for i in range(k) if (dp>>i)&1)
return val+a[ii]>=k
if sub(0):
ans = 0
elif not sub(n-1):
ans = n
else:
l = 0
r = n-1
while l<r-1:
m = (l+r)//2
if sub(m):
r = m
else:
l = m
ans = l+1
print(ans)
``` | output | 1 | 74,850 | 19 | 149,701 |
Provide a correct Python 3 solution for this coding contest problem.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3 | instruction | 0 | 74,851 | 19 | 149,702 |
"Correct Solution:
```
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))[::-1]
S = 0
ans = 0
for a in A:
if S+a<K:
S+=a
ans+=1
else:
ans=0
print(ans)
``` | output | 1 | 74,851 | 19 | 149,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3
Submitted Solution:
```
# Python3 (3.4.3)
import sys
input = sys.stdin.readline
# -------------------------------------------------------------
# function
# -------------------------------------------------------------
# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
ans = N
total = 0
for i in range(N):
# 後ろ(大きい方) からみていく
a = A[N-1-i]
# 合計に加えても K を超えないなら, 最小の部分集合に必要
if total + a < K:
total += a
# そうでない場合, 不要
else:
ans = min(ans, N-1-i)
print(ans)
``` | instruction | 0 | 74,852 | 19 | 149,704 |
Yes | output | 1 | 74,852 | 19 | 149,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3
Submitted Solution:
```
from itertools import accumulate
def main():
N, K = map(int, input().split())
As = list(map(int, input().split()))
nonzeros = [1]
for a in As:
ndp = nonzeros[-1]
if a <= K:
ndp |= (nonzeros[-1] % (1 << (K-a))) << a
nonzeros.append(ndp)
dp = [0] * (K+1)
dp[0] = 1
acc = list(accumulate(dp)) + [0]
ans = 0
for i in range(N, 0, -1):
a = As[i-1]
ndp = []
for j in range(K+1):
t = dp[j] if j < a else dp[j] + dp[j-a]
ndp.append(0 if t == 0 else 1)
dp = ndp
if a < K:
nonzero = nonzeros[i-1]
for y in range(K+1):
if nonzero & 1:
t = K-y-a-1
if acc[K-y-1] > acc[t if t >= 0 else -1]:
break
nonzero >>= 1
else:
ans += 1
acc = list(accumulate(dp)) + [0]
print(ans)
main()
``` | instruction | 0 | 74,853 | 19 | 149,706 |
Yes | output | 1 | 74,853 | 19 | 149,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3
Submitted Solution:
```
def d_no_need(N, K, A):
from bisect import bisect_left
# 値がK以上の要素は単体で不必要でない要素になれる
A.sort()
a_sorted = A[:bisect_left(A, K)]
ans = len(a_sorted) # a_sortedの要素は不必要となりうる
dp = [False] * K # dp[k]:a_sortedの一部の和を取った値をKにできるか?
dp[0] = True
current_max = 0
for idx, a in reversed(list(enumerate(a_sorted))):
if current_max + a >= K:
ans = idx
first_update = True
for j in range(min(current_max, K - a - 1), -1, -1):
if dp[j]:
dp[j + a] = True
if first_update:
current_max = max(current_max, j + a)
first_update = False
return ans
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(d_no_need(N, K, A))
``` | instruction | 0 | 74,854 | 19 | 149,708 |
Yes | output | 1 | 74,854 | 19 | 149,709 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3
Submitted Solution:
```
import sys
N,K=map(int, input().split())
a=list(map(int, input().split()))
sum=0
for i in range(0,N):
sum+=a[i]
if sum<K:#全部不必要
print(N)
sys.exit()
if sum==K:#全部必要
print(0)
sys.exit()
a.sort()
a.reverse()
#K未満の最大の数字のラベルはどこ?
l=N
for i in range(N-1,-1,-1):
if a[i]<K:
l=i
else:
break
if l==N:
print(0)
sys.exit()
count=N
#lまでの要素が必要か不要かチェック(使いまわし可能)
sum=0
l_list=[]
for j in range(l,N):
if sum+a[j]<K:
sum+=a[j]
l_list.append(a[j])
for i in range(0,l):
if sum+a[i]>=K:#必要ってことだ
count-=1
#lからの要素は自分のことを抜かないといけないことに注意
for i in range(l,N):
if a[i] in l_list:
sum=0
b=a[:]
C=b.pop(i)
for j in range(l-1,N-1):
if sum+b[j]<K:
sum+=b[j]
if sum+C>=K:#必要ってことだ
count-=1
else:
count-=1
print(count)
``` | instruction | 0 | 74,855 | 19 | 149,710 |
Yes | output | 1 | 74,855 | 19 | 149,711 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [e for e in a if e < k]
n = len(a)
dp = [[False] * k for _ in range(n + 1)]
dp[0][0] = True
for i, e in enumerate(a, 1):
for j in range(k):
dp[i][j] = dp[i-1][j]
for j in range(k - e):
if dp[i-1][j]:
dp[i][j+e] = True
dp2 = [[False] * k for _ in range(n + 1)]
dp2[0][0] = True
for i, e in enumerate(a[::-1], 1):
for j in range(k):
dp2[i][j] = dp2[i-1][j]
for j in range(k - e):
if dp2[i-1][j]:
dp2[i][j+e] = True
ans = 0
for i, e in enumerate(a, 1):
li = [j for j in range(k) if dp[i-1][j]]
li2 = [j for j in range(k) if dp2[n-i][j]]
j = len(li2) - 1
mx = 0
for e2 in li:
while e2 + li2[j] >= k:
j -= 1
mx = max(mx, e2 + li2[j])
if mx + e < k:
ans += 1
print(ans)
``` | instruction | 0 | 74,856 | 19 | 149,712 |
No | output | 1 | 74,856 | 19 | 149,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3
Submitted Solution:
```
N,K = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
if a[0] >= K:
print(0)
exit()
a = [a[i] for i in range(N) if a[i]<K]
a.reverse()
N = len(a)
ans = N
dp = [False]*K
dp[0] = True
Smax = 0
for i in range(N):
a_ = a[i]
if Smax + a_ >= K:
ans = N-i-1
updated = False
for j in range(min(Smax,K-a_-1),-1,-1):
if dp[j]:
dp[j+a_]=True
if not updated:
Smax = max(Smax,j+a_)
updated = True
print(ans)
``` | instruction | 0 | 74,857 | 19 | 149,714 |
No | output | 1 | 74,857 | 19 | 149,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3
Submitted Solution:
```
def examA():
N = DI()/dec(7)
ans = N
print(N)
return
def examB():
ans = 0
print(ans)
return
def examC():
ans = 0
print(ans)
return
def examD():
N, K = LI()
A = LI()
A.sort()
dp_L = [set() for _ in range(N+1)]
dp_R = [set() for _ in range(N+1)]
dp_L[0].add(0)
dp_R[N].add(0)
for i in range(N):
a = A[i]
for n in dp_L[i]:
dp_L[i+1].add(n)
if n+a<K:
dp_L[i+1].add(n+a)
for i in range(N)[::-1]:
a = A[i]
for n in dp_R[i+1]:
dp_R[i].add(n)
if n+a<K:
dp_R[i].add(n+a)
for i in range(N+1):
dp_L[i] = list(dp_L[i])
dp_R[i] = list(dp_R[i])
#print(dp_L)
#print(dp_R)
"""
noneed = -1; need = N
while(need-noneed>1):
i = (need+noneed)//2
a = A[i]
is_need = False
L = dp_L[i]
R = dp_R[i+1]
l = 0; r = len(R)-1
while(l<len(L)):
while(0<r and K<=L[l]+R[r]):
r -= 1
#print(L[l]+R[r],l,r)
if K<=L[l]+R[r]:
break
if K<=L[l]+R[r]+a:
is_need = True
break
l += 1
if is_need:
need = i
else:
noneed = i
ans = noneed + 1
print(ans)
"""
return
from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}
getcontext().prec = 28
sys.setrecursionlimit(10**7)
if __name__ == '__main__':
examD()
"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""
``` | instruction | 0 | 74,858 | 19 | 149,716 |
No | output | 1 | 74,858 | 19 | 149,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
Constraints
* All input values are integers.
* 1≤N≤5000
* 1≤K≤5000
* 1≤a_i≤10^9 (1≤i≤N)
Input
The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N
Output
Print the number of the unnecessary cards.
Examples
Input
3 6
1 4 3
Output
1
Input
5 400
3 1 4 1 5
Output
5
Input
6 20
10 4 3 10 25 2
Output
3
Submitted Solution:
```
N, K = map(int, input().split())
A = [int(_) for _ in input().split()]
A.sort()
Inf = 5001
def DP(i, K, memo = {}):
if i == 0 and K == 0:
return 0
elif i == 0:
return Inf
elif K <= A[i-1]:
return 1
try:
return memo[(i, K)]
except KeyError:
if K - A[i-1] >= 0:
ret = min(DP(i-1, K, memo), DP(i-1, K-A[i-1], memo) + 1)
else:
ret = DP(i-1, K, memo)
memo[(i, K)] = ret
return ret
memo = {}
if sum(A) < K:
print(N)
else:
for i in range(N):
if DP(i+1, K, memo) < Inf:
print(i+1 - DP(i+1, K, memo))
break
``` | instruction | 0 | 74,859 | 19 | 149,718 |
No | output | 1 | 74,859 | 19 | 149,719 |
Provide a correct Python 3 solution for this coding contest problem.
You have to organize a wedding party. The program of the party will include a concentration game played by the bride and groom. The arrangement of the concentration game should be easy since this game will be played to make the party fun.
We have a 4x4 board and 8 pairs of cards (denoted by `A' to `H') for the concentration game:
+---+---+---+---+
| | | | | A A B B
+---+---+---+---+ C C D D
| | | | | E E F F
+---+---+---+---+ G G H H
| | | | |
+---+---+---+---+
| | | | |
+---+---+---+---+
To start the game, it is necessary to arrange all 16 cards face down on the board. For example:
+---+---+---+---+
| A | B | A | B |
+---+---+---+---+
| C | D | C | D |
+---+---+---+---+
| E | F | G | H |
+---+---+---+---+
| G | H | E | F |
+---+---+---+---+
The purpose of the concentration game is to expose as many cards as possible by repeatedly performing the following procedure: (1) expose two cards, (2) keep them open if they match or replace them face down if they do not.
Since the arrangements should be simple, every pair of cards on the board must obey the following condition: the relative position of one card to the other card of the pair must be one of 4 given relative positions. The 4 relative positions are different from one another and they are selected from the following 24 candidates:
(1, 0), (2, 0), (3, 0),
(-3, 1), (-2, 1), (-1, 1), (0, 1), (1, 1), (2, 1), (3, 1),
(-3, 2), (-2, 2), (-1, 2), (0, 2), (1, 2), (2, 2), (3, 2),
(-3, 3), (-2, 3), (-1, 3), (0, 3), (1, 3), (2, 3), (3, 3).
Your job in this problem is to write a program that reports the total number of board arrangements which satisfy the given constraint. For example, if relative positions (-2, 1), (-1, 1), (1, 1), (1, 2) are given, the total number of board arrangements is two, where the following two arrangements satisfy the given constraint:
X0 X1 X2 X3 X0 X1 X2 X3
+---+---+---+---+ +---+---+---+---+
Y0 | A | B | C | D | Y0 | A | B | C | D |
+---+---+---+---+ +---+---+---+---+
Y1 | B | A | D | C | Y1 | B | D | E | C |
+---+---+---+---+ +---+---+---+---+
Y2 | E | F | G | H | Y2 | F | A | G | H |
+---+---+---+---+ +---+---+---+---+
Y3 | F | E | H | G | Y3 | G | F | H | E |
+---+---+---+---+ +---+---+---+---+
the relative positions: the relative positions:
A:(1, 1), B:(-1, 1) A:(1, 2), B:(-1, 1)
C:(1, 1), D:(-1, 1) C:(1, 1), D:(-2, 1)
E:(1, 1), F:(-1, 1) E:(1, 2), F:( 1, 1)
G:(1, 1), H:(-1, 1) G:(-2, 1), H:(-1, 1)
Arrangements of the same pattern should be counted only once. Two board arrangements are said to have the same pattern if they are obtained from each other by repeatedly making any two pairs exchange their positions. For example, the following two arrangements have the same pattern:
X0 X1 X2 X3 X0 X1 X2 X3
+---+---+---+---+ +---+---+---+---+
Y0 | H | G | F | E | Y0 | A | B | C | D |
+---+---+---+---+ +---+---+---+---+
Y1 | G | E | D | F | Y1 | B | D | E | C |
+---+---+---+---+ +---+---+---+---+
Y2 | C | H | B | A | Y2 | F | A | G | H |
+---+---+---+---+ +---+---+---+---+
Y3 | B | C | A | D | Y3 | G | F | H | E |
+---+---+---+---+ +---+---+---+---+
where (1) `A' and `H', (2) `B' and `G', (3) `C' and `F', and (4) `D' and `E' exchange their positions respectively.
Input
The input contains multiple data sets, each representing 4 relative positions. A data set is given as a line in the following format.
x1| y1 | x2| y2 | x3| y3 | x4| y4
---|---|---|---|---|---|---|---
The i-th relative position is given by (xi, yi). You may assume that the given relative positions are different from one another and each of them is one of the 24 candidates.
The end of input is indicated by the line which contains a single number greater than 4.
Output
For each data set, your program should output the total number of board arrangements (or more precisely, the total number of patterns).
Each number should be printed in one line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Examples
Input
Output
Input
-2 1 -1 1 1 1 1 2
1 0 2 1 2 2 3 3
5
Output
2
15 | instruction | 0 | 74,886 | 19 | 149,772 |
"Correct Solution:
```
def get_index(DATA):
for y, f in enumerate(DATA):
try:
x=f.index(0)
return x,y
except ValueError:
pass
def solve(i, DATA):
if i==9:
return 1
result=0
x1,y1=get_index(DATA)
DATA[y1][x1]=i
for dx, dy in ds:
x2=x1+dx
y2=y1+dy
if not (0 <= x2 < 4 and 0 <= y2 < 4 ):
continue
if DATA[y2][x2]:
continue
DATA[y2][x2]=i
result+=solve(i+1,DATA)
DATA[y2][x2]=0
DATA[y1][x1]=0
return result
while True:
data=list(map(int,input().split()))
if len(data)==1:
break
ds=list(zip(*[iter(data)]*2))
print(solve(1,[[0]*4 for _ in range(4)]))
``` | output | 1 | 74,886 | 19 | 149,773 |
Provide a correct Python 3 solution for this coding contest problem.
You have to organize a wedding party. The program of the party will include a concentration game played by the bride and groom. The arrangement of the concentration game should be easy since this game will be played to make the party fun.
We have a 4x4 board and 8 pairs of cards (denoted by `A' to `H') for the concentration game:
+---+---+---+---+
| | | | | A A B B
+---+---+---+---+ C C D D
| | | | | E E F F
+---+---+---+---+ G G H H
| | | | |
+---+---+---+---+
| | | | |
+---+---+---+---+
To start the game, it is necessary to arrange all 16 cards face down on the board. For example:
+---+---+---+---+
| A | B | A | B |
+---+---+---+---+
| C | D | C | D |
+---+---+---+---+
| E | F | G | H |
+---+---+---+---+
| G | H | E | F |
+---+---+---+---+
The purpose of the concentration game is to expose as many cards as possible by repeatedly performing the following procedure: (1) expose two cards, (2) keep them open if they match or replace them face down if they do not.
Since the arrangements should be simple, every pair of cards on the board must obey the following condition: the relative position of one card to the other card of the pair must be one of 4 given relative positions. The 4 relative positions are different from one another and they are selected from the following 24 candidates:
(1, 0), (2, 0), (3, 0),
(-3, 1), (-2, 1), (-1, 1), (0, 1), (1, 1), (2, 1), (3, 1),
(-3, 2), (-2, 2), (-1, 2), (0, 2), (1, 2), (2, 2), (3, 2),
(-3, 3), (-2, 3), (-1, 3), (0, 3), (1, 3), (2, 3), (3, 3).
Your job in this problem is to write a program that reports the total number of board arrangements which satisfy the given constraint. For example, if relative positions (-2, 1), (-1, 1), (1, 1), (1, 2) are given, the total number of board arrangements is two, where the following two arrangements satisfy the given constraint:
X0 X1 X2 X3 X0 X1 X2 X3
+---+---+---+---+ +---+---+---+---+
Y0 | A | B | C | D | Y0 | A | B | C | D |
+---+---+---+---+ +---+---+---+---+
Y1 | B | A | D | C | Y1 | B | D | E | C |
+---+---+---+---+ +---+---+---+---+
Y2 | E | F | G | H | Y2 | F | A | G | H |
+---+---+---+---+ +---+---+---+---+
Y3 | F | E | H | G | Y3 | G | F | H | E |
+---+---+---+---+ +---+---+---+---+
the relative positions: the relative positions:
A:(1, 1), B:(-1, 1) A:(1, 2), B:(-1, 1)
C:(1, 1), D:(-1, 1) C:(1, 1), D:(-2, 1)
E:(1, 1), F:(-1, 1) E:(1, 2), F:( 1, 1)
G:(1, 1), H:(-1, 1) G:(-2, 1), H:(-1, 1)
Arrangements of the same pattern should be counted only once. Two board arrangements are said to have the same pattern if they are obtained from each other by repeatedly making any two pairs exchange their positions. For example, the following two arrangements have the same pattern:
X0 X1 X2 X3 X0 X1 X2 X3
+---+---+---+---+ +---+---+---+---+
Y0 | H | G | F | E | Y0 | A | B | C | D |
+---+---+---+---+ +---+---+---+---+
Y1 | G | E | D | F | Y1 | B | D | E | C |
+---+---+---+---+ +---+---+---+---+
Y2 | C | H | B | A | Y2 | F | A | G | H |
+---+---+---+---+ +---+---+---+---+
Y3 | B | C | A | D | Y3 | G | F | H | E |
+---+---+---+---+ +---+---+---+---+
where (1) `A' and `H', (2) `B' and `G', (3) `C' and `F', and (4) `D' and `E' exchange their positions respectively.
Input
The input contains multiple data sets, each representing 4 relative positions. A data set is given as a line in the following format.
x1| y1 | x2| y2 | x3| y3 | x4| y4
---|---|---|---|---|---|---|---
The i-th relative position is given by (xi, yi). You may assume that the given relative positions are different from one another and each of them is one of the 24 candidates.
The end of input is indicated by the line which contains a single number greater than 4.
Output
For each data set, your program should output the total number of board arrangements (or more precisely, the total number of patterns).
Each number should be printed in one line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Examples
Input
Output
Input
-2 1 -1 1 1 1 1 2
1 0 2 1 2 2 3 3
5
Output
2
15 | instruction | 0 | 74,887 | 19 | 149,774 |
"Correct Solution:
```
# AOJ 1103: Board Arrangements for Concentration Gam...
# Python3 2018.7.14 bal4u
def combi(k):
global ans
if k == 9:
ans += 1
return
for y in range(4):
for x in range(4):
if arr[y][x]: continue
arr[y][x] = k
for i in range(4):
x2, y2 = x + a[i<<1], y + a[(i<<1)+1]
if x2 < 0 or x2 >= 4 or y2 < 0 or y2 >= 4 or arr[y2][x2]: continue
arr[y2][x2] = k
combi(k+1)
arr[y2][x2] = 0
arr[y][x] = 0
return;
while True:
a = list(map(int, input().split()))
if len(a) == 1: break
arr = [[0 for i in range(4)] for j in range(4)]
ans = 0
arr[0][0] = 1
for i in range(4):
x, y = a[i<<1], a[(i<<1)+1]
if x >= 0 and y >= 0:
arr[y][x] = 1
combi(2)
arr[y][x] = 0
print(ans)
``` | output | 1 | 74,887 | 19 | 149,775 |
Provide a correct Python 3 solution for this coding contest problem.
You have to organize a wedding party. The program of the party will include a concentration game played by the bride and groom. The arrangement of the concentration game should be easy since this game will be played to make the party fun.
We have a 4x4 board and 8 pairs of cards (denoted by `A' to `H') for the concentration game:
+---+---+---+---+
| | | | | A A B B
+---+---+---+---+ C C D D
| | | | | E E F F
+---+---+---+---+ G G H H
| | | | |
+---+---+---+---+
| | | | |
+---+---+---+---+
To start the game, it is necessary to arrange all 16 cards face down on the board. For example:
+---+---+---+---+
| A | B | A | B |
+---+---+---+---+
| C | D | C | D |
+---+---+---+---+
| E | F | G | H |
+---+---+---+---+
| G | H | E | F |
+---+---+---+---+
The purpose of the concentration game is to expose as many cards as possible by repeatedly performing the following procedure: (1) expose two cards, (2) keep them open if they match or replace them face down if they do not.
Since the arrangements should be simple, every pair of cards on the board must obey the following condition: the relative position of one card to the other card of the pair must be one of 4 given relative positions. The 4 relative positions are different from one another and they are selected from the following 24 candidates:
(1, 0), (2, 0), (3, 0),
(-3, 1), (-2, 1), (-1, 1), (0, 1), (1, 1), (2, 1), (3, 1),
(-3, 2), (-2, 2), (-1, 2), (0, 2), (1, 2), (2, 2), (3, 2),
(-3, 3), (-2, 3), (-1, 3), (0, 3), (1, 3), (2, 3), (3, 3).
Your job in this problem is to write a program that reports the total number of board arrangements which satisfy the given constraint. For example, if relative positions (-2, 1), (-1, 1), (1, 1), (1, 2) are given, the total number of board arrangements is two, where the following two arrangements satisfy the given constraint:
X0 X1 X2 X3 X0 X1 X2 X3
+---+---+---+---+ +---+---+---+---+
Y0 | A | B | C | D | Y0 | A | B | C | D |
+---+---+---+---+ +---+---+---+---+
Y1 | B | A | D | C | Y1 | B | D | E | C |
+---+---+---+---+ +---+---+---+---+
Y2 | E | F | G | H | Y2 | F | A | G | H |
+---+---+---+---+ +---+---+---+---+
Y3 | F | E | H | G | Y3 | G | F | H | E |
+---+---+---+---+ +---+---+---+---+
the relative positions: the relative positions:
A:(1, 1), B:(-1, 1) A:(1, 2), B:(-1, 1)
C:(1, 1), D:(-1, 1) C:(1, 1), D:(-2, 1)
E:(1, 1), F:(-1, 1) E:(1, 2), F:( 1, 1)
G:(1, 1), H:(-1, 1) G:(-2, 1), H:(-1, 1)
Arrangements of the same pattern should be counted only once. Two board arrangements are said to have the same pattern if they are obtained from each other by repeatedly making any two pairs exchange their positions. For example, the following two arrangements have the same pattern:
X0 X1 X2 X3 X0 X1 X2 X3
+---+---+---+---+ +---+---+---+---+
Y0 | H | G | F | E | Y0 | A | B | C | D |
+---+---+---+---+ +---+---+---+---+
Y1 | G | E | D | F | Y1 | B | D | E | C |
+---+---+---+---+ +---+---+---+---+
Y2 | C | H | B | A | Y2 | F | A | G | H |
+---+---+---+---+ +---+---+---+---+
Y3 | B | C | A | D | Y3 | G | F | H | E |
+---+---+---+---+ +---+---+---+---+
where (1) `A' and `H', (2) `B' and `G', (3) `C' and `F', and (4) `D' and `E' exchange their positions respectively.
Input
The input contains multiple data sets, each representing 4 relative positions. A data set is given as a line in the following format.
x1| y1 | x2| y2 | x3| y3 | x4| y4
---|---|---|---|---|---|---|---
The i-th relative position is given by (xi, yi). You may assume that the given relative positions are different from one another and each of them is one of the 24 candidates.
The end of input is indicated by the line which contains a single number greater than 4.
Output
For each data set, your program should output the total number of board arrangements (or more precisely, the total number of patterns).
Each number should be printed in one line. Since your result is checked by an automatic grading program, you should not insert any extra characters nor lines on the output.
Examples
Input
Output
Input
-2 1 -1 1 1 1 1 2
1 0 2 1 2 2 3 3
5
Output
2
15 | instruction | 0 | 74,888 | 19 | 149,776 |
"Correct Solution:
```
def get_index(fixed):
for y, f in enumerate(fixed):
try:
x = f.index(0)
return x, y
except ValueError:
pass
def recursive(i, fixed):
if i == 9:
return 1
result = 0
x, y = get_index(fixed)
fixed[y][x] = i
for dx, dy in ds:
x2, y2 = x + dx, y + dy
if not (0 <= x2 < 4 and 0 <= y2 < 4):
continue
if fixed[y2][x2]:
continue
fixed[y2][x2] = i
result += recursive(i + 1, fixed)
fixed[y2][x2] = 0
fixed[y][x] = 0
return result
while True:
ipt = list(map(int, input().split()))
if len(ipt) == 1:
break
ds = list(zip(*[iter(ipt)] * 2))
print(recursive(1, [[0] * 4 for _ in range(4)]))
``` | output | 1 | 74,888 | 19 | 149,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organizers are preparing red badges for girls and blue ones for boys.
Vasya prepared n+1 decks of badges. The i-th (where i is from 0 to n, inclusive) deck contains i blue badges and n-i red ones. The total number of badges in any deck is exactly n.
Determine the minimum number of decks among these n+1 that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.
Input
The first line contains an integer b (1 ≤ b ≤ 300), the number of boys.
The second line contains an integer g (1 ≤ g ≤ 300), the number of girls.
The third line contains an integer n (1 ≤ n ≤ b + g), the number of the board games tournament participants.
Output
Output the only integer, the minimum number of badge decks that Vasya could take.
Examples
Input
5
6
3
Output
4
Input
5
3
5
Output
4
Note
In the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).
In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used. | instruction | 0 | 75,078 | 19 | 150,156 |
Tags: brute force, math
Correct Solution:
```
import sys
input = sys.stdin.readline
def main():
b = int(input())
g = int(input())
n = int(input())
ans = n + 1
for x in range(n + 1):
y = n - x
if x > b or y > g:
ans -= 1
print(ans)
main()
``` | output | 1 | 75,078 | 19 | 150,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organizers are preparing red badges for girls and blue ones for boys.
Vasya prepared n+1 decks of badges. The i-th (where i is from 0 to n, inclusive) deck contains i blue badges and n-i red ones. The total number of badges in any deck is exactly n.
Determine the minimum number of decks among these n+1 that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.
Input
The first line contains an integer b (1 ≤ b ≤ 300), the number of boys.
The second line contains an integer g (1 ≤ g ≤ 300), the number of girls.
The third line contains an integer n (1 ≤ n ≤ b + g), the number of the board games tournament participants.
Output
Output the only integer, the minimum number of badge decks that Vasya could take.
Examples
Input
5
6
3
Output
4
Input
5
3
5
Output
4
Note
In the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).
In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used. | instruction | 0 | 75,079 | 19 | 150,158 |
Tags: brute force, math
Correct Solution:
```
import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97 # a
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return [int(i) for i in input().split()]
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=2):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
def convn(number, base):
new_number = 0
while number > 0:
new_number += number % base
number //= base
return new_number
def cdiv(n, k): return n // k + (n % k != 0)
def ispal(s): # Palindrome
for i in range(len(s) // 2 + 1):
if s[i] != s[-i - 1]:
return False
return True
# a = [1,2,3,4,5] -----> print(*a) ----> list print krne ka new way
b = int(input())
g = int(input())
n = int(input())
res = sum(1 for i in range(n + 1) if b >= i and g >= (n - i))
print(res)
``` | output | 1 | 75,079 | 19 | 150,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organizers are preparing red badges for girls and blue ones for boys.
Vasya prepared n+1 decks of badges. The i-th (where i is from 0 to n, inclusive) deck contains i blue badges and n-i red ones. The total number of badges in any deck is exactly n.
Determine the minimum number of decks among these n+1 that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.
Input
The first line contains an integer b (1 ≤ b ≤ 300), the number of boys.
The second line contains an integer g (1 ≤ g ≤ 300), the number of girls.
The third line contains an integer n (1 ≤ n ≤ b + g), the number of the board games tournament participants.
Output
Output the only integer, the minimum number of badge decks that Vasya could take.
Examples
Input
5
6
3
Output
4
Input
5
3
5
Output
4
Note
In the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).
In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used. | instruction | 0 | 75,080 | 19 | 150,160 |
Tags: brute force, math
Correct Solution:
```
b=int(input())
g=int(input())
n=int(input())
s=set()
for x in range(b+1):
for y in range(g+1):
if x+y==n:
s.add((x,y))
print(len(s))
``` | output | 1 | 75,080 | 19 | 150,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organizers are preparing red badges for girls and blue ones for boys.
Vasya prepared n+1 decks of badges. The i-th (where i is from 0 to n, inclusive) deck contains i blue badges and n-i red ones. The total number of badges in any deck is exactly n.
Determine the minimum number of decks among these n+1 that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.
Input
The first line contains an integer b (1 ≤ b ≤ 300), the number of boys.
The second line contains an integer g (1 ≤ g ≤ 300), the number of girls.
The third line contains an integer n (1 ≤ n ≤ b + g), the number of the board games tournament participants.
Output
Output the only integer, the minimum number of badge decks that Vasya could take.
Examples
Input
5
6
3
Output
4
Input
5
3
5
Output
4
Note
In the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).
In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used. | instruction | 0 | 75,081 | 19 | 150,162 |
Tags: brute force, math
Correct Solution:
```
b = int(input())
g = int(input())
n = int(input())
gg = n-min(n,g)
bb = min(n,b)
print(abs(bb-gg)+1)
``` | output | 1 | 75,081 | 19 | 150,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organizers are preparing red badges for girls and blue ones for boys.
Vasya prepared n+1 decks of badges. The i-th (where i is from 0 to n, inclusive) deck contains i blue badges and n-i red ones. The total number of badges in any deck is exactly n.
Determine the minimum number of decks among these n+1 that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.
Input
The first line contains an integer b (1 ≤ b ≤ 300), the number of boys.
The second line contains an integer g (1 ≤ g ≤ 300), the number of girls.
The third line contains an integer n (1 ≤ n ≤ b + g), the number of the board games tournament participants.
Output
Output the only integer, the minimum number of badge decks that Vasya could take.
Examples
Input
5
6
3
Output
4
Input
5
3
5
Output
4
Note
In the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).
In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used. | instruction | 0 | 75,082 | 19 | 150,164 |
Tags: brute force, math
Correct Solution:
```
b=int(input())
g=int(input())
n=int(input())
print( abs( min(b,n) - ( n - min(g,n) ) ) + 1 )
``` | output | 1 | 75,082 | 19 | 150,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organizers are preparing red badges for girls and blue ones for boys.
Vasya prepared n+1 decks of badges. The i-th (where i is from 0 to n, inclusive) deck contains i blue badges and n-i red ones. The total number of badges in any deck is exactly n.
Determine the minimum number of decks among these n+1 that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.
Input
The first line contains an integer b (1 ≤ b ≤ 300), the number of boys.
The second line contains an integer g (1 ≤ g ≤ 300), the number of girls.
The third line contains an integer n (1 ≤ n ≤ b + g), the number of the board games tournament participants.
Output
Output the only integer, the minimum number of badge decks that Vasya could take.
Examples
Input
5
6
3
Output
4
Input
5
3
5
Output
4
Note
In the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).
In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used. | instruction | 0 | 75,083 | 19 | 150,166 |
Tags: brute force, math
Correct Solution:
```
from sys import stdin
###############################################################
def iinput(): return int(stdin.readline())
def minput(): return map(int, stdin.readline().split())
def linput(): return list(map(int, stdin.readline().split()))
###############################################################
b = iinput()
g = iinput()
n = iinput()
print(min(g,n) + 1 - (n - min(b,n)))
``` | output | 1 | 75,083 | 19 | 150,167 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organizers are preparing red badges for girls and blue ones for boys.
Vasya prepared n+1 decks of badges. The i-th (where i is from 0 to n, inclusive) deck contains i blue badges and n-i red ones. The total number of badges in any deck is exactly n.
Determine the minimum number of decks among these n+1 that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.
Input
The first line contains an integer b (1 ≤ b ≤ 300), the number of boys.
The second line contains an integer g (1 ≤ g ≤ 300), the number of girls.
The third line contains an integer n (1 ≤ n ≤ b + g), the number of the board games tournament participants.
Output
Output the only integer, the minimum number of badge decks that Vasya could take.
Examples
Input
5
6
3
Output
4
Input
5
3
5
Output
4
Note
In the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).
In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used. | instruction | 0 | 75,084 | 19 | 150,168 |
Tags: brute force, math
Correct Solution:
```
b = int(input())
g = int(input())
n = int(input())
result = 0
for i in range(g+1):
for y in range(b+1):
if i + y == n:
result += 1
print(result)
``` | output | 1 | 75,084 | 19 | 150,169 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organizers are preparing red badges for girls and blue ones for boys.
Vasya prepared n+1 decks of badges. The i-th (where i is from 0 to n, inclusive) deck contains i blue badges and n-i red ones. The total number of badges in any deck is exactly n.
Determine the minimum number of decks among these n+1 that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.
Input
The first line contains an integer b (1 ≤ b ≤ 300), the number of boys.
The second line contains an integer g (1 ≤ g ≤ 300), the number of girls.
The third line contains an integer n (1 ≤ n ≤ b + g), the number of the board games tournament participants.
Output
Output the only integer, the minimum number of badge decks that Vasya could take.
Examples
Input
5
6
3
Output
4
Input
5
3
5
Output
4
Note
In the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).
In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used. | instruction | 0 | 75,085 | 19 | 150,170 |
Tags: brute force, math
Correct Solution:
```
ML = lambda:map(int,input().split())
I = lambda:input()
b = int(I());g = int(I());n = int(I());
print(min(b,n)+min(g,n)-n+1)
``` | output | 1 | 75,085 | 19 | 150,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organizers are preparing red badges for girls and blue ones for boys.
Vasya prepared n+1 decks of badges. The i-th (where i is from 0 to n, inclusive) deck contains i blue badges and n-i red ones. The total number of badges in any deck is exactly n.
Determine the minimum number of decks among these n+1 that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.
Input
The first line contains an integer b (1 ≤ b ≤ 300), the number of boys.
The second line contains an integer g (1 ≤ g ≤ 300), the number of girls.
The third line contains an integer n (1 ≤ n ≤ b + g), the number of the board games tournament participants.
Output
Output the only integer, the minimum number of badge decks that Vasya could take.
Examples
Input
5
6
3
Output
4
Input
5
3
5
Output
4
Note
In the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).
In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used.
Submitted Solution:
```
b=int(input())
g=int(input())
n=int(input())
i=-1
j=-1
i=n-g
j=b
if(j>n):
j=n
if(n-g<0):
i=0
print(j-i+1)
``` | instruction | 0 | 75,086 | 19 | 150,172 |
Yes | output | 1 | 75,086 | 19 | 150,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organizers are preparing red badges for girls and blue ones for boys.
Vasya prepared n+1 decks of badges. The i-th (where i is from 0 to n, inclusive) deck contains i blue badges and n-i red ones. The total number of badges in any deck is exactly n.
Determine the minimum number of decks among these n+1 that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.
Input
The first line contains an integer b (1 ≤ b ≤ 300), the number of boys.
The second line contains an integer g (1 ≤ g ≤ 300), the number of girls.
The third line contains an integer n (1 ≤ n ≤ b + g), the number of the board games tournament participants.
Output
Output the only integer, the minimum number of badge decks that Vasya could take.
Examples
Input
5
6
3
Output
4
Input
5
3
5
Output
4
Note
In the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).
In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used.
Submitted Solution:
```
b = int(input())
g = int(input())
n = int(input())
lista = []
for i in range(n+1):
lista.append([])
lista[i].append(i)
lista[i].append(n-i)
contador = 0
for i in range(n+1):
if lista[i][0] <= b and lista[i][1] <= g:
contador += 1
print(contador)
``` | instruction | 0 | 75,087 | 19 | 150,174 |
Yes | output | 1 | 75,087 | 19 | 150,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organizers are preparing red badges for girls and blue ones for boys.
Vasya prepared n+1 decks of badges. The i-th (where i is from 0 to n, inclusive) deck contains i blue badges and n-i red ones. The total number of badges in any deck is exactly n.
Determine the minimum number of decks among these n+1 that Vasya should take, so that there will be a suitable deck no matter how many girls and boys there will be among the participants of the tournament.
Input
The first line contains an integer b (1 ≤ b ≤ 300), the number of boys.
The second line contains an integer g (1 ≤ g ≤ 300), the number of girls.
The third line contains an integer n (1 ≤ n ≤ b + g), the number of the board games tournament participants.
Output
Output the only integer, the minimum number of badge decks that Vasya could take.
Examples
Input
5
6
3
Output
4
Input
5
3
5
Output
4
Note
In the first example, each of 4 decks should be taken: (0 blue, 3 red), (1 blue, 2 red), (2 blue, 1 red), (3 blue, 0 red).
In the second example, 4 decks should be taken: (2 blue, 3 red), (3 blue, 2 red), (4 blue, 1 red), (5 blue, 0 red). Piles (0 blue, 5 red) and (1 blue, 4 red) can not be used.
Submitted Solution:
```
import math
def getint():
return int(input())
def getlist():
return list(map(int, input().split()))
s, i, e = [getint() for _ in range(3)]
print(min(s, i, e, s+i-e) + 1)
``` | instruction | 0 | 75,088 | 19 | 150,176 |
Yes | output | 1 | 75,088 | 19 | 150,177 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.