message stringlengths 2 67k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 463 109k | cluster float64 19 19 | __index_level_0__ int64 926 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjacent permutation elements and then the boy swaps them. During his move, Furic tosses a coin and if the coin shows "heads" he chooses a random pair of adjacent elements with indexes i and i + 1, for which an inequality pi > pi + 1 holds, and swaps them. But if the coin shows "tails", Furik chooses a random pair of adjacent elements with indexes i and i + 1, for which the inequality pi < pi + 1 holds, and swaps them. If the coin shows "heads" or "tails" and Furik has multiple ways of adjacent pairs to take, then he uniformly takes one of the pairs. If Furik doesn't have any pair to take, he tosses a coin one more time. The game ends when the permutation is sorted in the increasing order.
Jeff wants the game to finish as quickly as possible (that is, he wants both players to make as few moves as possible). Help Jeff find the minimum mathematical expectation of the number of moves in the game if he moves optimally well.
You can consider that the coin shows the heads (or tails) with the probability of 50 percent.
Input
The first line contains integer n (1 ≤ n ≤ 3000). The next line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation p. The numbers are separated by spaces.
Output
In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2
1 2
Output
0.000000
Input
5
3 5 2 4 1
Output
13.000000
Note
In the first test the sequence is already sorted, so the answer is 0. | instruction | 0 | 8,634 | 19 | 17,268 |
Tags: combinatorics, dp, probabilities
Correct Solution:
```
def merge_sort(a, l, r):
res = 0
if l < r:
m = (l + r) // 2
res += merge_sort(a, l, m)
res += merge_sort(a, m + 1, r)
i = l
j = m + 1
b = []
while i <= m and j <= r:
if a[i] <= a[j]:
b.append(a[i])
i += 1
else:
b.append(a[j])
j += 1
res += m - i + 1
while i <= m:
b.append(a[i])
i += 1
while j <= r:
b.append(a[j])
j += 1
for idx, val in enumerate(b):
a[idx + l] = val
return res
input()
a = [int(x) for x in input().split()]
n = len(a)
ans = merge_sort(a, 0, n - 1)
if ans & 1 == 0:
ans *= 2
else:
ans = ans * 2 - 1
print(ans)
``` | output | 1 | 8,634 | 19 | 17,269 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjacent permutation elements and then the boy swaps them. During his move, Furic tosses a coin and if the coin shows "heads" he chooses a random pair of adjacent elements with indexes i and i + 1, for which an inequality pi > pi + 1 holds, and swaps them. But if the coin shows "tails", Furik chooses a random pair of adjacent elements with indexes i and i + 1, for which the inequality pi < pi + 1 holds, and swaps them. If the coin shows "heads" or "tails" and Furik has multiple ways of adjacent pairs to take, then he uniformly takes one of the pairs. If Furik doesn't have any pair to take, he tosses a coin one more time. The game ends when the permutation is sorted in the increasing order.
Jeff wants the game to finish as quickly as possible (that is, he wants both players to make as few moves as possible). Help Jeff find the minimum mathematical expectation of the number of moves in the game if he moves optimally well.
You can consider that the coin shows the heads (or tails) with the probability of 50 percent.
Input
The first line contains integer n (1 ≤ n ≤ 3000). The next line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation p. The numbers are separated by spaces.
Output
In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2
1 2
Output
0.000000
Input
5
3 5 2 4 1
Output
13.000000
Note
In the first test the sequence is already sorted, so the answer is 0. | instruction | 0 | 8,635 | 19 | 17,270 |
Tags: combinatorics, dp, probabilities
Correct Solution:
```
def merge_sort(a, l, r):
res = 0
if l < r:
m = (l + r) // 2
res += merge_sort(a, l, m)
res += merge_sort(a, m + 1, r)
i = l
j = m + 1
b = []
while i <= m and j <= r:
if a[i] <= a[j]:
b.append(a[i])
i += 1
else:
b.append(a[j])
j += 1
res += m - i + 1
while i <= m:
b.append(a[i])
i += 1
while j <= r:
b.append(a[j])
j += 1
for idx, val in enumerate(b):
a[idx + l] = val
return res
input()
a = [int(x) for x in input().split()]
n = len(a)
ans = merge_sort(a, 0, n - 1)
if ans & 1 == 0:
ans *= 2
else:
ans = ans * 2 - 1
print(ans)
# Made By Mostafa_Khaled
``` | output | 1 | 8,635 | 19 | 17,271 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjacent permutation elements and then the boy swaps them. During his move, Furic tosses a coin and if the coin shows "heads" he chooses a random pair of adjacent elements with indexes i and i + 1, for which an inequality pi > pi + 1 holds, and swaps them. But if the coin shows "tails", Furik chooses a random pair of adjacent elements with indexes i and i + 1, for which the inequality pi < pi + 1 holds, and swaps them. If the coin shows "heads" or "tails" and Furik has multiple ways of adjacent pairs to take, then he uniformly takes one of the pairs. If Furik doesn't have any pair to take, he tosses a coin one more time. The game ends when the permutation is sorted in the increasing order.
Jeff wants the game to finish as quickly as possible (that is, he wants both players to make as few moves as possible). Help Jeff find the minimum mathematical expectation of the number of moves in the game if he moves optimally well.
You can consider that the coin shows the heads (or tails) with the probability of 50 percent.
Input
The first line contains integer n (1 ≤ n ≤ 3000). The next line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation p. The numbers are separated by spaces.
Output
In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2
1 2
Output
0.000000
Input
5
3 5 2 4 1
Output
13.000000
Note
In the first test the sequence is already sorted, so the answer is 0.
Submitted Solution:
```
from sys import *
n=int(stdin.readline().strip())
s1=stdin.readline().strip()
a=list(map(int,s1.split()))
x=0
for i in range (n-1):
for j in range (i+1,n):
if a[i]>a[j]:
x+=1
n=x//2
#print(x,n,' !!!')
r=(x)*((0.5)**n)
i=1
bi=3
eps=0.00000001
if x>0:
while (x+2*i)*bi*((0.5)**(n+i))>eps:
r=r+(x+2*i)*bi*(0.5)**(n+i)
#print(r)
bi=(bi*(n+i))//(i+1)
i=i+1
#print(bi,i)
else:
r=0
print("%.7f"%r)
``` | instruction | 0 | 8,636 | 19 | 17,272 |
No | output | 1 | 8,636 | 19 | 17,273 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p1, p2, ..., pn. Then the guys take turns to make moves, Jeff moves first. During his move, Jeff chooses two adjacent permutation elements and then the boy swaps them. During his move, Furic tosses a coin and if the coin shows "heads" he chooses a random pair of adjacent elements with indexes i and i + 1, for which an inequality pi > pi + 1 holds, and swaps them. But if the coin shows "tails", Furik chooses a random pair of adjacent elements with indexes i and i + 1, for which the inequality pi < pi + 1 holds, and swaps them. If the coin shows "heads" or "tails" and Furik has multiple ways of adjacent pairs to take, then he uniformly takes one of the pairs. If Furik doesn't have any pair to take, he tosses a coin one more time. The game ends when the permutation is sorted in the increasing order.
Jeff wants the game to finish as quickly as possible (that is, he wants both players to make as few moves as possible). Help Jeff find the minimum mathematical expectation of the number of moves in the game if he moves optimally well.
You can consider that the coin shows the heads (or tails) with the probability of 50 percent.
Input
The first line contains integer n (1 ≤ n ≤ 3000). The next line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation p. The numbers are separated by spaces.
Output
In a single line print a single real value — the answer to the problem. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.
Examples
Input
2
1 2
Output
0.000000
Input
5
3 5 2 4 1
Output
13.000000
Note
In the first test the sequence is already sorted, so the answer is 0.
Submitted Solution:
```
from sys import *
n=int(stdin.readline().strip())
s1=stdin.readline().strip()
a=list(map(int,s1.split()))
if n==1:
print('0')
else:
x=0
n0=1
while n0<n:
n0=n0*2
b=[0]*(2*n0+10)
'''for i in range (n-1):
for j in range (i+1,n):
if a[i]>a[j]:
x+=1'''
for i in range (n):
t=a[i]
u=0
k=1
j=1
while t>0:
if (t>>j)<<j!=t:
u=u+b[(n0+t-1)>>(j-1)]
t=t-k
k=k<<1
j=j+1
x=x+u
j=n0+a[i]-1
while j>0:
b[j]+=1
j=j>>1
x=((n*(n-1))//2)-x
n=x//2
#print(x,n,' !!!')
r=x*((0.5)**n)
i=1
bi=n
eps=0.00000001
if x>0:
while (x+2*i)*bi*((0.5)**(n+i))>eps:
r=r+(x+2*i)*bi*(0.5)**(n+i)
#print(r)
bi=(bi*(n+i))//(i+1)
i=i+1
#print(bi,i)
else:
r=0
print("%.7f"%r)
``` | instruction | 0 | 8,637 | 19 | 17,274 |
No | output | 1 | 8,637 | 19 | 17,275 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18 | instruction | 0 | 8,915 | 19 | 17,830 |
"Correct Solution:
```
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
print(sum(A[::2])-sum(A[1::2]))
``` | output | 1 | 8,915 | 19 | 17,831 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18 | instruction | 0 | 8,916 | 19 | 17,832 |
"Correct Solution:
```
n = int(input())
a = [int(n) for n in input().split(" ")]
a.sort()
print(sum(a[::-2]) - sum(a[-2::-2]))
``` | output | 1 | 8,916 | 19 | 17,833 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18 | instruction | 0 | 8,917 | 19 | 17,834 |
"Correct Solution:
```
N = int(input())
a = list(map(int, input().split()))
a.sort()
print(abs(sum(a[0::2]) - sum(a[1::2])))
``` | output | 1 | 8,917 | 19 | 17,835 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18 | instruction | 0 | 8,918 | 19 | 17,836 |
"Correct Solution:
```
N=input()
A=sorted(map(int,input().split()),reverse=True)
print(sum(A[::2])-sum(A[1::2]))
``` | output | 1 | 8,918 | 19 | 17,837 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18 | instruction | 0 | 8,919 | 19 | 17,838 |
"Correct Solution:
```
_ = input()
l = list(map(int,input().split()))
l.sort()
l.reverse()
print(sum(l[::2])-sum(l[1::2]))
``` | output | 1 | 8,919 | 19 | 17,839 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18 | instruction | 0 | 8,920 | 19 | 17,840 |
"Correct Solution:
```
n = int(input())
a = sorted(list(map(int, input().split())))
print(abs(sum(a[0::2]) - sum(a[1::2])))
``` | output | 1 | 8,920 | 19 | 17,841 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18 | instruction | 0 | 8,921 | 19 | 17,842 |
"Correct Solution:
```
N=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
print(sum(a[::2])-sum(a[1::2]))
``` | output | 1 | 8,921 | 19 | 17,843 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18 | instruction | 0 | 8,922 | 19 | 17,844 |
"Correct Solution:
```
N = input()
ai = sorted(map(int, input().split()))[::-1]
print(sum(ai[::2]) - sum(ai[1::2]))
``` | output | 1 | 8,922 | 19 | 17,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
n=int(input())
a=sorted(map(int,input().split()))
print(abs(sum(a[1::2])-sum(a[::2])))
``` | instruction | 0 | 8,923 | 19 | 17,846 |
Yes | output | 1 | 8,923 | 19 | 17,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
n = int(input())
a = sorted(list(map(int, input().split())))
print(sum(a[::-2])-sum(a[-2::-2]))
``` | instruction | 0 | 8,924 | 19 | 17,848 |
Yes | output | 1 | 8,924 | 19 | 17,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
N = int(input())
c = sorted((map(int,input().split())),reverse = True)
print(sum(c[0::2])-sum(c[1::2]))
``` | instruction | 0 | 8,925 | 19 | 17,850 |
Yes | output | 1 | 8,925 | 19 | 17,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
N = int(input())
A = sorted(map(int, input().split()),reverse=True)
print( sum(A[0::2]) - sum(A[1::2]))
``` | instruction | 0 | 8,926 | 19 | 17,852 |
Yes | output | 1 | 8,926 | 19 | 17,853 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
import numpy as np
n = int(input())
a_list = list(map(int, input().split()))
n_alice = 0
n_bob = 0
for i in range(1, n+1):
if i % 2:
n_alice += max(a_list)
del a_list[np.argmax(a_list)]
else:
n_bob += min(a_list)
del a_list[np.argmin(a_list)]
print(n_alice - n_bob)
``` | instruction | 0 | 8,927 | 19 | 17,854 |
No | output | 1 | 8,927 | 19 | 17,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
n=int(input())
a=sorted(list(map(int,input().split())))
al=[a[2*i] for i in range(n//2)]
bo=[a[2*i+1] for i in range(n//2)]
print(sum(al)-sum(bo))
``` | instruction | 0 | 8,928 | 19 | 17,856 |
No | output | 1 | 8,928 | 19 | 17,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
N = map(int, input())
cards = list(map(int, input().split()))
cards.sort(reverse=True)
sum_A = 0
sum_B = 0
for i in range(N):
if i % 2 == 0:
sum_A += cards[i]
else:
sum_B += cards[i]
print(sum_A - sum_B)
``` | instruction | 0 | 8,929 | 19 | 17,858 |
No | output | 1 | 8,929 | 19 | 17,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
n=int(input())
s=list(map(int,input().split()))
s.sort(reverse=True)
print(s)
tokuten=0
for i in range(n):
if i%2==0:
tokuten+=s[i]
else:
tokuten-=s[i]
print(tokuten)
``` | instruction | 0 | 8,930 | 19 | 17,860 |
No | output | 1 | 8,930 | 19 | 17,861 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None | instruction | 0 | 8,988 | 19 | 17,976 |
"Correct Solution:
```
import itertools
ans = []
while True:
n = int(input())
k = int(input())
if n == 0 and k == 0:
break
cards = []
ans_set = []
for i in range(n):
cards.append(input())
for i in itertools.permutations(cards, k):
ans_set.append(int("".join(i)))
ans.append(len(set(ans_set)))
for i in ans:
print(i)
``` | output | 1 | 8,988 | 19 | 17,977 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None | instruction | 0 | 8,989 | 19 | 17,978 |
"Correct Solution:
```
import itertools
while(1):
n = int(input())
k = int(input())
if((n == 0)and(k == 0)): break
num = []
for i in range(n): num.append(input())
#print('num :::',num)
A = []
for i in range(n): A.append(i)
#print('A :::',A)
num_list = []
Comb = list(itertools.permutations(A,k))
#print('Comb :::',len(Comb))
for i in range(len(Comb)):
tmp = list(Comb[i])
tmp_num = ''
for j in range(len(tmp)):
tmp_num += num[tmp[j]]
tmp_num = int(tmp_num)
num_list.append(tmp_num)
ans = len(list(set(num_list)))
print(ans)
#print('aaaa')
``` | output | 1 | 8,989 | 19 | 17,979 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None | instruction | 0 | 8,990 | 19 | 17,980 |
"Correct Solution:
```
from itertools import permutations as P
for e in iter(input,'0'):
n,k=int(e),int(input())
C=[input()for _ in[0]*n]
print(len(set(''.join(s)for s in P(C,k))))
``` | output | 1 | 8,990 | 19 | 17,981 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None | instruction | 0 | 8,991 | 19 | 17,982 |
"Correct Solution:
```
import sys
import itertools
if sys.platform =='win32':
sys.stdin=open('input.txt')
def MAP(): return [int(x) for x in input().split()]
while True:
N = int(input())
K = int(input())
if N==0 and K==0: break
a = [int(input()) for _ in range(N)]
perm = itertools.permutations(a, K)
nums = []
for p in perm:
num = ''
for s in p:
num += str(s)
nums.append(int(num))
print(len(set(nums)))
``` | output | 1 | 8,991 | 19 | 17,983 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None | instruction | 0 | 8,992 | 19 | 17,984 |
"Correct Solution:
```
def s():
from itertools import permutations as P
for e in iter(input,'0'):
n,k=int(e),int(input())
C=[input()for _ in[0]*n]
print(len(set(''.join(s)for s in P(C,k))))
if'__main__'==__name__:s()
``` | output | 1 | 8,992 | 19 | 17,985 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None | instruction | 0 | 8,993 | 19 | 17,986 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Lining up the cards
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0546
"""
import sys
from itertools import permutations
def solve(cards, k):
return len(set([''.join(c) for c in permutations(cards, k)]))
def main(args):
while True:
n = int(input())
k = int(input())
if n == 0 and k == 0:
break
cards = [input() for _ in range(n)]
ans = solve(cards, k)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 8,993 | 19 | 17,987 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None | instruction | 0 | 8,994 | 19 | 17,988 |
"Correct Solution:
```
import itertools
while 1:
n = int(input())
k = int(input())
if n == k == 0:
break
a = []
for i in range(n):
a.append(input())
b = []
p = list(itertools.permutations(a, k))
for i in p:
b.append(''.join(i))
c = list(set(b))
print(len(c))
``` | output | 1 | 8,994 | 19 | 17,989 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None | instruction | 0 | 8,995 | 19 | 17,990 |
"Correct Solution:
```
from itertools import permutations as P
while True:
n, k = int(input()), int(input())
if k == 0:
break
card = [input() for _ in range(n)]
print(len(set([''.join(s) for s in P(card, k)])))
``` | output | 1 | 8,995 | 19 | 17,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
Submitted Solution:
```
while True:
n = int(input())
k = int(input())
if not n:
break
lst = [input() for i in range(n)]
dic = dict()
def func(num,selected):
if num == 0:
dic["".join([lst[i] for i in selected])] = 1
return
for i in range(n):
if not i in selected:
selected.append(i)
func(num - 1, selected)
selected.pop()
func(k,[])
print(len(dic))
``` | instruction | 0 | 8,996 | 19 | 17,992 |
Yes | output | 1 | 8,996 | 19 | 17,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
Submitted Solution:
```
n = k = 0
cards = []
mini_ans = {}
def dfs(s: list) -> None:
global n, k, cards, mini_ans
if len(s) == k:
string = ""
for i in s:
string += cards[i]
mini_ans.add(string)
return
for i in range(n):
if i not in s:
dfs(s + [i])
def main() -> None:
ans = []
global n, k, cards, mini_ans
while True:
n, k = [int(input()) for _ in range(2)]
if n + k == 0:
break
cards = [input() for _ in range(n)]
mini_ans = set()
dfs([])
ans += [len(mini_ans)]
print("\n".join(map(str, ans)))
if __name__ == "__main__":
main()
``` | instruction | 0 | 8,997 | 19 | 17,994 |
Yes | output | 1 | 8,997 | 19 | 17,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
Submitted Solution:
```
from itertools import permutations
while 1:
N = int(input())
S = int(input())
if N == 0:
break
l = [int(input()) for _ in range(N)]
dic = {}
for i in permutations(l,S):
i = map(str,i)
dic[("".join(i))] = 1
print(len(dic))
``` | instruction | 0 | 8,998 | 19 | 17,996 |
Yes | output | 1 | 8,998 | 19 | 17,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
Submitted Solution:
```
from itertools import permutations as P
while True:
n, k = int(input()), int(input())
if k == 0:
break
card = [int(input()) for _ in range(n)]
print(len(set([''.join(map(str, s)) for s in set(P(card, k))])))
``` | instruction | 0 | 8,999 | 19 | 17,998 |
Yes | output | 1 | 8,999 | 19 | 17,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
Submitted Solution:
```
from itertools import permutations as P
import sys
r=sys.stdin.readline
for e in iter(r,'0'):
n,k=int(e),int(r())
C=[r()for _ in[0]*n]
print(len(set(''.join(s)for s in P(C,k))))
``` | instruction | 0 | 9,000 | 19 | 18,000 |
No | output | 1 | 9,000 | 19 | 18,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
Submitted Solution:
```
from itertools import permutations as P
import sys
r=sys.stdin.readline
for e in iter(r,'0\n'):
n,k=int(e),int(r())
C=[r()for _ in[0]*n]
print(len(set(''.join(s)for s in P(C,k))))
``` | instruction | 0 | 9,001 | 19 | 18,002 |
No | output | 1 | 9,001 | 19 | 18,003 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes | instruction | 0 | 9,038 | 19 | 18,076 |
"Correct Solution:
```
n=int(input())
a=[[int(s)for s in input().split()]for _ in range(n)]
def f():
for i in range(n-1):
d=a[i][:];d[3],d[4]=d[4],d[3]
for j in range(i+1,n):
e=a[j][:];e[3],e[4]=e[4],e[3]
for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
f=[d[k]for k in p]
if f[0]==e[0]and f[5]==e[5]:
f=f[1:5]*2
for k in range(4):
if f[k:k+4]==e[1:5]:return'No'
return'Yes'
print(f())
``` | output | 1 | 9,038 | 19 | 18,077 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes | instruction | 0 | 9,039 | 19 | 18,078 |
"Correct Solution:
```
import sys
reverse = {
"E":"W",
"W":"E",
"S":"N",
"N":"S"
}
class dice:
def __init__(self,A):
self.list = sorted(A)
self.max = max(A)
self.min = min(A)
self.side = {
"TOP":A[0],
"S":A[1],
"E":A[2],
"W":A[3],
"N":A[4],
"BOT":A[5],
}
def get_list(self):
return self.list
def get_dict(self):
return self.side
def check(self):
pass
def main(self,A):
for s in A:
var = int(self.side[s])
self.side[s] = self.side["TOP"]
self.side["TOP"] = self.side[reverse[s]]
self.side[reverse[s]] = self.side["BOT"]
self.side["BOT"] = var
def rot(self):
var = self.side["N"]
self.side["N"] = self.side["E"]
self.side["E"] = self.side["S"]
self.side["S"] = self.side["W"]
self.side["W"] = var
n = int(input())
data = [list(map(int,input().split())) for _ in range(n)]
for i in range(0,n-1):
a = dice(data[i])
a_dict = a.get_dict()
for j in range(i+1,n):
b = dice(data[j])
for do in ["N","N","N","N","E","EE"]:
b.main(do)
for _ in range(4):
b.rot()
b_dict = b.get_dict()
if a_dict == b_dict:
print("No")
exit()
print("Yes")
``` | output | 1 | 9,039 | 19 | 18,079 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes | instruction | 0 | 9,040 | 19 | 18,080 |
"Correct Solution:
```
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
for i in range(n-1):
d=a[i][:];d[3],d[4]=d[4],d[3]
for j in range(i+1,n):
e=a[j][:];e[3],e[4]=e[4],e[3]
for p in('012345','152043','215304','302541','410352','514320'):
f=[d[int(k)]for k in p]
g=f[1:5]*2
for k in range(4):
if(g[k:k+4]==e[1:5])*(f[0]==e[0])*(f[5]==e[5]):return 'No'
return 'Yes'
print(f())
``` | output | 1 | 9,040 | 19 | 18,081 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes | instruction | 0 | 9,041 | 19 | 18,082 |
"Correct Solution:
```
number = int(input())
dices = []
for i in range(number):
dices.append(input().split())
tf = 0
for i in range(number - 1):
for j in range(i + 1, number):
dice_1 = dices[i]
dice_2 = dices[j]
rolls = {' ':[0, 1, 2, 3, 4, 5],
'W':[2, 1, 5, 0, 4, 3],
'N':[1, 5, 2, 3, 0, 4],
'E':[3, 1, 0, 5, 4, 2],
'S':[4, 0, 2, 3, 5, 1]
}
orders = [' ', 'N', 'W', 'E', 'S', 'NN']
for order in orders:
copy_2 = dice_2
for d in order:
roll = rolls[d]
copy_2 = [copy_2[i] for i in roll]
l = [1, 2, 4, 3]
a0 = copy_2[0] == dice_1[0]
a1 = copy_2[5] == dice_1[5]
a2 = ' '.join([copy_2[s]for s in l]) in ' '.join([dice_1[s]for s in l] * 2)
if a0 and a1 and a2:
tf += 1
if tf > 0:
print('No')
else:
print('Yes')
``` | output | 1 | 9,041 | 19 | 18,083 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes | instruction | 0 | 9,042 | 19 | 18,084 |
"Correct Solution:
```
n=int(input())
a=[[s for s in input().split()]for _ in range(n)]
def f():
for i in range(n-1):
d=a[i][:];d[3],d[4]=d[4],d[3]
for j in range(i+1,n):
e=a[j][:];e[3],e[4]=e[4],e[3]
for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
f=[d[k]for k in p]
if f[0]==e[0]and f[5]==e[5]:
f=f[1:5]*2
for k in range(4):
if f[k:k+4]==e[1:5]:return'No'
return'Yes'
print(f())
``` | output | 1 | 9,042 | 19 | 18,085 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes | instruction | 0 | 9,043 | 19 | 18,086 |
"Correct Solution:
```
def f():
for c in range(n):
for d in a[c+1:]:
for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
if[d[p[0]],d[p[5]]]==a[c][::5]:
f=[d[i]for i in p[1:5]]*2
for k in range(4):
if f[k:k+4]==a[c][1:5]:return"No"
return"Yes"
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())
``` | output | 1 | 9,043 | 19 | 18,087 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes | instruction | 0 | 9,044 | 19 | 18,088 |
"Correct Solution:
```
class Dice:
def __init__(self):
self.u=1
self.w=2
self.s=3
self.e=4
self.n=5
self.d=6
self.dic={"W":0,"S":1,"E":2,"N":3}
def __init__(self,u,w,s,e,n,d):
self.u=u
self.w=w
self.s=s
self.e=e
self.n=n
self.d=d
self.dic={"W":0,"S":1,"E":2,"N":3}
def rot(self,way):
if isinstance(way,str):
way=self.dic[way]
if(way==0):
c=self.u
self.u=self.e
self.e=self.d
self.d=self.w
self.w=c
elif way==1:
c=self.u
self.u=self.n
self.n=self.d
self.d=self.s
self.s=c
elif way==2:
c=self.u
self.u=self.w
self.w=self.d
self.d=self.e
self.e=c
def get_nums(self):
return {self.u,self.w,self.s,self.e,self.n,self.w,self.d}
def mk_dice():
u,s,e,w,n,d=map(int,input().split())
return Dice(u,w,s,e,n,d)
import random
q=int(input())
dice_col=[]
ans=True
for j in range(q):
dice_b=mk_dice()
for dice in dice_col:
if(dice.get_nums()==dice_b.get_nums()):
for i in range (1000):
dice.rot(random.randint(0,2))
if(dice.u==dice_b.u and dice.d==dice_b.d and dice.w==dice_b.w and dice.s==dice_b.s and dice.e==dice_b.e and dice.n==dice_b.n):
ans=False
if ~ans:
break
dice_col.append(dice_b)
if ans:
print('Yes')
else:
print('No')
``` | output | 1 | 9,044 | 19 | 18,089 |
Provide a correct Python 3 solution for this coding contest problem.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes | instruction | 0 | 9,045 | 19 | 18,090 |
"Correct Solution:
```
import random
class Dice(object):
def __init__(self):
self.t = 1
self.s = 2
self.e = 3
self.w = 4
self.n = 5
self.b = 6
def __init__(self, faces):
self.t = faces[0]
self.s = faces[1]
self.e = faces[2]
self.w = faces[3]
self.n = faces[4]
self.b = faces[5]
def roll(self, direct):
if direct == 0:
self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
elif direct == 1:
self.t, self.w, self.b, self.e = self.e, self.t, self.w, self.b
elif direct == 2:
self.n, self.w, self.s, self.e = self.w, self.s, self.e, self.n
def is_equal(self, dice):
if self.t == dice.t and self.s == dice.s and self.e == dice.e and self.w == dice.w and self.n == dice.n and self.b == dice.b:
return True
else:
return False
def get_nums(self):
return {self.t, self.s, self.e, self.w, self.n, self.b}
n = int(input())
dice_list = []
flag_list = []
for _ in range(n):
flag = False
faces = list(map(int, input().split()))
dice_list.append(Dice(faces))
if n == 0:
continue
dice_a = dice_list[-1]
for i in range(len(dice_list) - 1):
dice_b = dice_list[i]
if (dice_a.get_nums() == dice_b.get_nums()):
for i in range(1000):
dice_b.roll(random.randint(0, 3))
if dice_a.is_equal(dice_b):
flag = True
break
flag_list.append(flag)
if any(flag_list):
print('No')
else:
print('Yes')
``` | output | 1 | 9,045 | 19 | 18,091 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes
Submitted Solution:
```
class dice:
def __init__(self, X):
self.x = [0] * 6
self.x[0] = X[0]
self.x[1] = X[1]
self.x[2] = X[2]
self.x[3] = X[3]
self.x[4] = X[4]
self.x[5] = X[5]
def roll(self, d):
if d == 'S':
self.x[0], self.x[1], self.x[4], self.x[5] = \
self.x[4], self.x[0], self.x[5], self.x[1]
elif d == 'E':
self.x[0], self.x[2], self.x[3], self.x[5] = \
self.x[3], self.x[0], self.x[5], self.x[2]
elif d == 'W':
self.x[0], self.x[2], self.x[3], self.x[5] = \
self.x[2], self.x[5], self.x[0], self.x[3]
elif d == 'N':
self.x[0], self.x[1], self.x[4], self.x[5] = \
self.x[1], self.x[5], self.x[0], self.x[4]
n = int(input())
X = list(map(int, input().split()))
dice_b = dice(X)
distances = list('NNNNWNNNWNNNENNNENNNWNNN')
b = False
for _ in range(n-1):
X_t = list(map(int, input().split()))
dice_t = dice(X_t)
for d in distances:
dice_t.roll(d)
if dice_b.x[0] == dice_t.x[0] and dice_b.x[1] == dice_t.x[1] and dice_b.x[2] == dice_t.x[2] and \
dice_b.x[3] == dice_t.x[3] and dice_b.x[4] == dice_t.x[4] and dice_b.x[5] == dice_t.x[5]:
b = True
break
if b == False:
print('Yes')
elif b == True:
print('No')
``` | instruction | 0 | 9,046 | 19 | 18,092 |
Yes | output | 1 | 9,046 | 19 | 18,093 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes
Submitted Solution:
```
import sys
def rotate(arr,i):
if i=='W':
arr=[arr[k-1] for k in [3,2,6,1,5,4]]
if i=='E':
arr=[arr[k-1] for k in [4,2,1,6,5,3]]
if i=='N':
arr=[arr[k-1] for k in [2,6,3,4,1,5]]
if i=='S':
arr=[arr[k-1] for k in [5,1,3,4,6,2]]
return arr
def isIdentical(arr,arr2):
deck=[]
for i in 'W'*4:
arr=rotate(arr,i)
for k in 'NNNN':
arr=rotate(arr,k)
deck.append(arr)
arr=rotate(arr,'N')
arr=rotate(arr,'W')
for k in 'NNNN':
arr=rotate(arr,k)
deck.append(arr)
arr=rotate(arr,'W')
arr=rotate(arr,'W')
for k in 'NNNN':
arr=rotate(arr,k)
deck.append(arr)
if arr2 in deck:
return True
else:
return False
n=int(input())
allarr=[]
for i in range(n):
allarr.append(input().split())
for i1,v1 in enumerate(allarr):
for v2 in allarr[i1+1:]:
if isIdentical(v1,v2):
print('No')
sys.exit()
print('Yes')
``` | instruction | 0 | 9,047 | 19 | 18,094 |
Yes | output | 1 | 9,047 | 19 | 18,095 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes
Submitted Solution:
```
from itertools import*
n=int(input())
a=[[s for s in input().split()]for _ in range(n)]
for k in range(n):
b=a[k];b[3],b[4]=b[4],b[3]
def f():
for d,e in combinations(a,2):
for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
f=[d[k]for k in p]
if f[0]==e[0]and f[5]==e[5]:
f=f[1:5]*2
for k in range(4):
if f[k:k+4]==e[1:5]:return'No'
return'Yes'
print(f())
``` | instruction | 0 | 9,048 | 19 | 18,096 |
Yes | output | 1 | 9,048 | 19 | 18,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes
Submitted Solution:
```
class dice:
def __init__(self,data):
self.faces = data
def turn(self,direction):
if direction == 'N':
idx = [1,5,2,3,0,4]
self.faces = [self.faces[i] for i in idx]
elif direction == 'S':
[self.turn('N') for i in range(3)]
elif direction == 'E':
idx = [3,1,0,5,4,2]
self.faces = [self.faces[i] for i in idx]
elif direction == 'W':
[self.turn('E') for i in range(3)]
elif direction == 'c':
self.turn('N')
self.turn('W')
self.turn('S')
def isunique(d1,d2):
for o in 'cccWcccEcccNcccWcccWccc':
if d1.faces == d2.faces:
break
else:
d2.turn(o)
if d1.faces == d2.faces:
return False
else:
return True
if __name__ == '__main__':
from itertools import combinations
n = int(input())
dices = []
for i in range(n):
dices.append(dice([int(s) for s in input().split()]))
ans = True
check = [isunique(d1,d2) for d1,d2 in combinations(dices,2)]
if all(check):
print('Yes')
else:
print('No')
``` | instruction | 0 | 9,049 | 19 | 18,098 |
Yes | output | 1 | 9,049 | 19 | 18,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes
Submitted Solution:
```
# Dice I - IV
class Dice:
def __init__(self, a1, a2, a3, a4, a5, a6):
# サイコロを縦横にたどると書いてある数字(index1は真上、index3は真下の数字)
self.face = [a1, a2, a3, a4, a5, a6]
self.v = [a5, a1, a2, a6] # 縦方向
self.h = [a4, a1, a3, a6] # 横方向
self.det = 1
# print(self.v, self.h)
# サイコロの上面の数字を表示
def top(self):
return self.v[1]
# サイコロを北方向に倒す
def north(self):
newV = [self.v[1], self.v[2], self.v[3], self.v[0]]
self.v = newV
self.h[1] = self.v[1]
self.h[3] = self.v[3]
return self.v, self.h
# サイコロを南方向に倒す
def south(self):
newV = [self.v[3], self.v[0], self.v[1], self.v[2]]
self.v = newV
self.h[1] = self.v[1]
self.h[3] = self.v[3]
return self.v, self.h
# サイコロを東方向に倒す
def east(self):
newH = [self.h[3], self.h[0], self.h[1], self.h[2]]
self.h = newH
self.v[1] = self.h[1]
self.v[3] = self.h[3]
return self.v, self.h
# サイコロを西方向に倒す
def west(self):
newH = [self.h[1], self.h[2], self.h[3], self.h[0]]
self.h = newH
self.v[1] = self.h[1]
self.v[3] = self.h[3]
return self.v, self.h
def searchFace(self, a):
b = 0
for i in range(6):
if a == self.face[i]:
# print('一致しました')
b = i + 1
return b
def detJudge(self, x): # a は 1 から 6 のどれか
y = int(7 / 2 - abs(x - 7 / 2))
if x != y:
self.det *= -1
# print(self.det)
return y
def rightSide(self, top, front):
r = 0
if top == 1 and front == 2:
r = 3
elif top == 2 and front == 3:
r = 1
elif top == 3 and front == 1:
r = 2
elif top == 1 and front == 3:
r = 5
elif top == 3 and front == 2:
r = 6
elif top == 2 and front == 1:
r = 4
if self.det == -1:
r = 7 - r
return r
diceAmount = int(input())
dices = []
for i in range(diceAmount):
d = [int(j) for j in input().rstrip().split()]
dice = Dice(d[0], d[1], d[2], d[3], d[4], d[5])
dices.append(dice)
# print(dices)
# Dice I
# command = list(input().rstrip())
# print(command)
# Dice II
# for i, a in enumerate(command):
# if a == 'N':
# dice1.north()
# elif a == 'S':
# dice1.south()
# elif a == 'E':
# dice1.east()
# elif a == 'W':
# dice1.west()
# print(dice1.top())
# questionAmount = int(input())
# for i in range(questionAmount):
# # Initialize det
# dice1.det = 1
# question = [int(i) for i in input().rstrip().split()]
# a = dice1.searchFace(question[0])
# b = dice1.searchFace(question[1])
# # print(a, b)
# top = dice1.detJudge(a)
# front = dice1.detJudge(b)
# # print(top, front)
# position = dice1.rightSide(top, front)
# answer = dice1.face[position - 1]
# print(answer)
# Dice III
# import random
# # print(dice1.face)
# # print(dice2.face)
# yesCount = 0
# i = 0
# while yesCount == 0 and i < 1000:
# j = random.randint(0, 3)
# if j == 0:
# dice2.north()
# elif j == 1:
# dice2.south()
# elif j == 2:
# dice2.east()
# elif j == 3:
# dice2.west()
# if (dice1.v == dice2.v and dice1.h == dice2.h) or ([dice1.v[2], dice1.v[1], dice1.v[0], dice1.v[3]] == [dice2.v[2], dice2.v[1], dice2.v[0], dice2.v[3]] and [dice1.h[2], dice1.h[1], dice1.h[0], dice1.h[3]] == [dice2.h[2], dice2.h[1], dice2.h[0], dice2.h[3]]):
# yesCount += 1
# # print('一致')
# i += 1
# if yesCount >= 1:
# print('Yes')
# else:
# print('No')
# Dice IV
import random
match = 0
diceCount = 1
while match == 0 and diceCount < diceAmount:
for d2 in range(1, diceAmount):
# print(d2)
i = 0
while match == 0 and i < 27:
j = random.randint(0, 3)
if j == 0:
dices[d2].north()
elif j == 1:
dices[d2].south()
elif j == 2:
dices[d2].east()
elif j == 3:
dices[d2].west()
d1 = 0
while d1 < d2 and match == 0:
if dices[d1].v == dices[d2].v and dices[d1].h == dices[d2].h:
match += 1
# print('一致')
d1 += 1
i += 1
diceCount += 1
if match >= 1:
print('No')
else:
print('Yes')
``` | instruction | 0 | 9,051 | 19 | 18,102 |
No | output | 1 | 9,051 | 19 | 18,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes
Submitted Solution:
```
import sys
import copy
n = int(input())
inp = [[i for i in input().split()] for i in range(n)]
a = copy.copy(inp)
number = 3
count = 0
kais = n-1
for i in range(n-3):
number += 3+i
for i in range(number):
if i == kais-1:
for i3 in range(n-1):
if i3 == 0:
sika = kais
continue
kais += n-i3
if i >= sika and i < kais:
sika = kais
count = i3
for i2 in range(1,33):
if (i2<=20 and i2%5==0) or i2==22 or i2==27 or i2==28:
s = "N"
else:
s = "E"
if s == "E":
for i4 in range(len(inp)):
if i4 == count:
continue
b = []
b.append(a[i4][3])
b.append(a[i4][1])
b.append(a[i4][0])
b.append(a[i4][5])
b.append(a[i4][4])
b.append(a[i4][2])
a[i4][:] = b[:]
for x in range(len(inp)):
if x == count:
continue
else:
if inp[count][:] == a[x][:]:
print("No")
sys.exit()
elif s == "N":
for i4 in range(len(inp)):
if i4 == count:
continue
b = []
b.append(a[i4][1])
b.append(a[i4][5])
b.append(a[i4][2])
b.append(a[i4][3])
b.append(a[i4][0])
b.append(a[i4][4])
a[i4][:] = b[:]
for x in range(len(inp)):
if x == count:
continue
else:
if inp[count][:] == a[x][:]:
print("No")
sys.exit()
print("Yes")
``` | instruction | 0 | 9,052 | 19 | 18,104 |
No | output | 1 | 9,052 | 19 | 18,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.
Output
Print "Yes" if given dices are all different, otherwise "No" in a line.
Examples
Input
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1
Output
No
Input
3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6
Output
Yes
Submitted Solution:
```
import sys
IDX_TBL = {1:[2,3,5,4], 2:[3,1,4,6], 3:[1,2,6,5],
4:[1,5,6,2], 5:[1,3,6,4], 6:[2,4,5,3]}
OPPSITE_TBL = {1:6, 2:5, 3:4, 4:3, 5:2, 6:1}
def is_same(l1, l2):
if l1[1] in l2:
idx_list = [i for i,x in enumerate(l2) if x==l1[1]]
for idx in idx_list:
nstr1 = "".join([l1[i] for i in IDX_TBL[1]])
nstr2 = "".join([l2[i] for i in IDX_TBL[idx]])
if nstr2 in nstr1*2:
if l1[6] == l2[7-l2.index(l1[1])]:
return True
return False
n=input()
nums_list = []
for _ in range(n):
nums_list.append(["_"] + raw_input().split(" "))
for i in range(0, n):
for j in range(i+1, n):
if is_same(nums_list[i], nums_list[j]):
print "No"
sys.exit(0)
print "Yes"
``` | instruction | 0 | 9,053 | 19 | 18,106 |
No | output | 1 | 9,053 | 19 | 18,107 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is an interactive problem.
John and his imaginary friend play a game. There are n lamps arranged in a circle. Lamps are numbered 1 through n in clockwise order, that is, lamps i and i + 1 are adjacent for any i = 1, …, n - 1, and also lamps n and 1 are adjacent. Initially all lamps are turned off.
John and his friend take turns, with John moving first. On his turn John can choose to terminate the game, or to make a move. To make a move, John can choose any positive number k and turn any k lamps of his choosing on. In response to this move, John's friend will choose k consecutive lamps and turn all of them off (the lamps in the range that were off before this move stay off). Note that the value of k is the same as John's number on his last move. For example, if n = 5 and John have just turned three lamps on, John's friend may choose to turn off lamps 1, 2, 3, or 2, 3, 4, or 3, 4, 5, or 4, 5, 1, or 5, 1, 2.
After this, John may choose to terminate or move again, and so on. However, John can not make more than 10^4 moves.
John wants to maximize the number of lamps turned on at the end of the game, while his friend wants to minimize this number. Your task is to provide a strategy for John to achieve optimal result. Your program will play interactively for John against the jury's interactor program playing for John's friend.
Suppose there are n lamps in the game. Let R(n) be the number of turned on lamps at the end of the game if both players act optimally. Your program has to terminate the game with at least R(n) turned on lamps within 10^4 moves. Refer to Interaction section below for interaction details.
For technical reasons hacks for this problem are disabled.
Interaction
Initially your program will be fed a single integer n (1 ≤ n ≤ 1000) — the number of lamps in the game. Then the interactor will wait for your actions.
To make a move, print a line starting with an integer k (1 ≤ k ≤ n), followed by k distinct integers l_1, …, l_k (1 ≤ l_i ≤ n) — indices of lamps you want to turn on. The indices may be printed in any order. It is allowed to try to turn on a lamp that is already on (although this will have no effect).
If your move was invalid for any reason, or if you have made more than 10^4 moves, the interactor will reply with a line containing a single integer -1. Otherwise, the reply will be a line containing a single integer x (1 ≤ x ≤ n), meaning that the response was to turn off k consecutive lamps starting from x in clockwise order.
To terminate the game instead of making a move, print a line containing a single integer 0. The test will be passed if at this point there are at least R(n) lamps turned on (note that neither R(n), nor the verdict received are not communicated to your program in any way). This action does not count towards the number of moves (that is, it is legal to terminate the game after exactly 10^4 moves).
To receive the correct verdict, your program should terminate immediately after printing 0, or after receiving -1 as a response.
Don't forget to flush your output after every action.
Examples
Input
3
Output
0
Input
4
1
Output
2 1 3
0
Note
When n = 3, any John's move can be reversed, thus R(3) = 0, and terminating the game immediately is correct.
R(4) = 1, and one strategy to achieve this result is shown in the second sample case.
Blank lines in sample interactions are for clarity and should not be printed. | instruction | 0 | 9,259 | 19 | 18,518 |
Tags: games, implementation, interactive, math
Correct Solution:
```
from sys import stdout, exit
from traceback import format_exc
def main():
n = int(input())
on = [False] * n
def query(ll):
res = 0
pvals = [i+1 for i in ll]
print(len(ll), ' '.join(map(str,pvals)))
stdout.flush()
for i in ll:
if not on[i]:
res += 1
on[i] = True
x = int(input())
if x == -1:
exit()
for i in range(x-1, x+len(ll)-1):
if on[i%n]:
res -= 1
on[i%n] = False
return res
if n < 4:
print(0)
return
max = -n
mk = -1
for k in range(2, n):
x = n - k - ((n - 1) // k)
if x > max:
max = x
mk = k
blocked = []
for i in range(n):
if i%mk==0:
blocked.append(True)
else:
blocked.append(False)
while True:
ll = []
count = 0
for i in range(n):
if not on[i] and not blocked[i]:
ll.append(i)
count+=1
if count == mk:
break
res = query(ll)
if res < 1:
break
print(0)
stdout.flush()
if __name__ == "__main__":
try:
main()
except:
print(format_exc())
``` | output | 1 | 9,259 | 19 | 18,519 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.