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.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES"
Submitted Solution:
```
from itertools import combinations
n,k = map(int,input().split())
s={}
for i in range(n):
s[input()]=0
ans = 0
for i in combinations(s.keys(),2):
a,b = i[0],i[1]
ch=""
for j in range(k):
if(a[j]==b[j]):
ch+=a[j]
if(a[j]!='S' and b[j]!='S'):
ch+='S'
elif(a[j]!='E' and b[j]!='E'):
ch+='E'
elif(a[j]!='T' and b[j]!='T'):
ch+='T'
if(ch in s.keys()):
ans+=1
print(ans)
``` | instruction | 0 | 24,885 | 19 | 49,770 |
No | output | 1 | 24,885 | 19 | 49,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table).
At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies a sequence of a consecutive squares of the field). The ships cannot intersect and even touch each other.
After that Bob makes a sequence of "shots". He names cells of the field and Alice either says that the cell is empty ("miss"), or that the cell belongs to some ship ("hit").
But here's the problem! Alice like to cheat. May be that is why she responds to each Bob's move with a "miss".
Help Bob catch Alice cheating — find Bob's first move, such that after it you can be sure that Alice cheated.
Input
The first line of the input contains three integers: n, k and a (1 ≤ n, k, a ≤ 2·105) — the size of the field, the number of the ships and the size of each ship. It is guaranteed that the n, k and a are such that you can put k ships of size a on the field, so that no two ships intersect or touch each other.
The second line contains integer m (1 ≤ m ≤ n) — the number of Bob's moves.
The third line contains m distinct integers x1, x2, ..., xm, where xi is the number of the cell where Bob made the i-th shot. The cells are numbered from left to right from 1 to n.
Output
Print a single integer — the number of such Bob's first move, after which you can be sure that Alice lied. Bob's moves are numbered from 1 to m in the order the were made. If the sought move doesn't exist, then print "-1".
Examples
Input
11 3 3
5
4 8 6 1 11
Output
3
Input
5 1 3
2
1 5
Output
-1
Input
5 1 3
1
3
Output
1
Submitted Solution:
```
n, k, a = [int(i) for i in input().split()]
m = int(input())
l = [int(i) for i in input().split()]
if n == k*a:
print(1)
exit(0)
def count(x, y):
return int((y-x+1+1)/(a+1))
p = [1, n]
for i in l:
c = 0
if i not in p:
p.append(i)
p.sort()
else:
continue
for j in range(len(p)-1):
c += count(p[j], p[j+1]-1)
if c < k:
print(len(p)-2)
exit(0)
print(-1)
``` | instruction | 0 | 25,152 | 19 | 50,304 |
No | output | 1 | 25,152 | 19 | 50,305 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table).
At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies a sequence of a consecutive squares of the field). The ships cannot intersect and even touch each other.
After that Bob makes a sequence of "shots". He names cells of the field and Alice either says that the cell is empty ("miss"), or that the cell belongs to some ship ("hit").
But here's the problem! Alice like to cheat. May be that is why she responds to each Bob's move with a "miss".
Help Bob catch Alice cheating — find Bob's first move, such that after it you can be sure that Alice cheated.
Input
The first line of the input contains three integers: n, k and a (1 ≤ n, k, a ≤ 2·105) — the size of the field, the number of the ships and the size of each ship. It is guaranteed that the n, k and a are such that you can put k ships of size a on the field, so that no two ships intersect or touch each other.
The second line contains integer m (1 ≤ m ≤ n) — the number of Bob's moves.
The third line contains m distinct integers x1, x2, ..., xm, where xi is the number of the cell where Bob made the i-th shot. The cells are numbered from left to right from 1 to n.
Output
Print a single integer — the number of such Bob's first move, after which you can be sure that Alice lied. Bob's moves are numbered from 1 to m in the order the were made. If the sought move doesn't exist, then print "-1".
Examples
Input
11 3 3
5
4 8 6 1 11
Output
3
Input
5 1 3
2
1 5
Output
-1
Input
5 1 3
1
3
Output
1
Submitted Solution:
```
def solve(arr,n,k,a):
pv = 0
c = 0
for e in arr:
d = e-pv-1
if (d >= a):
c += 1
d -= a
c += d//(a+1)
pv = e
if c >= k:
return True
return False
(n,k,a) = map(int,input().split())
d = input()
data = input().split()
data = list(map(int, data))
ans = -1
good = 0
bad = n+1
while bad - good > 1:
mdl = (bad + good) // 2
arr = sorted(data[:mdl])
arr.append(n)
if solve(arr,n,k,a):
good = mdl
else:
bad = mdl
if good < n:
ans = good+1
print(ans)
``` | instruction | 0 | 25,153 | 19 | 50,306 |
No | output | 1 | 25,153 | 19 | 50,307 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table).
At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies a sequence of a consecutive squares of the field). The ships cannot intersect and even touch each other.
After that Bob makes a sequence of "shots". He names cells of the field and Alice either says that the cell is empty ("miss"), or that the cell belongs to some ship ("hit").
But here's the problem! Alice like to cheat. May be that is why she responds to each Bob's move with a "miss".
Help Bob catch Alice cheating — find Bob's first move, such that after it you can be sure that Alice cheated.
Input
The first line of the input contains three integers: n, k and a (1 ≤ n, k, a ≤ 2·105) — the size of the field, the number of the ships and the size of each ship. It is guaranteed that the n, k and a are such that you can put k ships of size a on the field, so that no two ships intersect or touch each other.
The second line contains integer m (1 ≤ m ≤ n) — the number of Bob's moves.
The third line contains m distinct integers x1, x2, ..., xm, where xi is the number of the cell where Bob made the i-th shot. The cells are numbered from left to right from 1 to n.
Output
Print a single integer — the number of such Bob's first move, after which you can be sure that Alice lied. Bob's moves are numbered from 1 to m in the order the were made. If the sought move doesn't exist, then print "-1".
Examples
Input
11 3 3
5
4 8 6 1 11
Output
3
Input
5 1 3
2
1 5
Output
-1
Input
5 1 3
1
3
Output
1
Submitted Solution:
```
[n, k, a] = [int(i) for i in input().split()]
m = int(input())
shots = [int(i) for i in input().split()]
num = (n + 1) // (a + 1)
segments = [[1, n, num]]
lied = False
turn = 0
for i in range(len(shots)):
for [min, max, val] in segments:
shot = shots[i]
if (shot >= min) and (shot <= max):
val1 = ((shot - min) + 1) // (a + 1)
val2 = ((max - shot) + 1) // (a + 1)
num += val1 + val2 - val
segments.remove([min, max, val])
segments.append([min, shot, val1])
segments.append([shot, max, val2])
break
if num < k:
lied = True
turn = i + 1
break
if lied:
print(turn)
else:
print(-1)
``` | instruction | 0 | 25,154 | 19 | 50,308 |
No | output | 1 | 25,154 | 19 | 50,309 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table).
At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies a sequence of a consecutive squares of the field). The ships cannot intersect and even touch each other.
After that Bob makes a sequence of "shots". He names cells of the field and Alice either says that the cell is empty ("miss"), or that the cell belongs to some ship ("hit").
But here's the problem! Alice like to cheat. May be that is why she responds to each Bob's move with a "miss".
Help Bob catch Alice cheating — find Bob's first move, such that after it you can be sure that Alice cheated.
Input
The first line of the input contains three integers: n, k and a (1 ≤ n, k, a ≤ 2·105) — the size of the field, the number of the ships and the size of each ship. It is guaranteed that the n, k and a are such that you can put k ships of size a on the field, so that no two ships intersect or touch each other.
The second line contains integer m (1 ≤ m ≤ n) — the number of Bob's moves.
The third line contains m distinct integers x1, x2, ..., xm, where xi is the number of the cell where Bob made the i-th shot. The cells are numbered from left to right from 1 to n.
Output
Print a single integer — the number of such Bob's first move, after which you can be sure that Alice lied. Bob's moves are numbered from 1 to m in the order the were made. If the sought move doesn't exist, then print "-1".
Examples
Input
11 3 3
5
4 8 6 1 11
Output
3
Input
5 1 3
2
1 5
Output
-1
Input
5 1 3
1
3
Output
1
Submitted Solution:
```
from bisect import bisect_left
from collections import Counter
from collections import defaultdict
def mp(): return map(int,input().split())
def lt(): return list(map(int,input().split()))
def pt(x): print(x)
def ip(): return input()
def it(): return int(input())
def sl(x): return [t for t in x]
def spl(x): return x.split()
def aj(liste, item): liste.append(item)
def bin(x): return "{0:b}".format(x)
def listring(l): return ' '.join([str(x) for x in l])
def printlist(l): print(' '.join([str(x) for x in l]))
n,k,b = mp()
m = it()
L = []
count = n // b
a = lt()
bool = False
for i in range(m):
if count < k:
print(i)
bool = True
break
x = a[i]-1
index = bisect_left(L,x)
t = len(L)
if t == 0:
count = (x//b) + (n-1-x)//b
elif index == t:
r = (n-1-L[-1])//b - (n-1-x)//b - (x-L[-1]-1)//b
count -= r
elif index == 0:
r = L[0]//b - (L[0]-x-1)//b - x//b
count -= r
else:
u = L[index]
v = L[index-1]
r = (u-v-1)//b - (u-x-1)//b - (x-v-1)//b
count -= r
if index == t:
L.append(x)
else:
L.insert(index,x)
if not bool:
if count < k:
print(m)
else:
print(-1)
``` | instruction | 0 | 25,155 | 19 | 50,310 |
No | output | 1 | 25,155 | 19 | 50,311 |
Provide a correct Python 3 solution for this coding contest problem.
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.
The following is an example of a Bingo card when N = 5, M = 50, S = 685.
<image>
I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.
When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.
Examples
Input
3 9 45
3 100 50
5 50 685
0 0 0
Output
1
7
74501
Input
None
Output
None | instruction | 0 | 25,513 | 19 | 51,026 |
"Correct Solution:
```
def main():
while True:
N, M, S = map(int, input().split())
if max(N, M, S) == 0:
break
ans = solve(N, M, S)
print(ans)
def solve(N, M, S):
MOD = 10 ** 5
p = N * N
q = M - p
T = S - (p * (p + 1)) // 2
dp = [[0 for i in range(T + 1)] for j in range(p + 1)]
dp[0][0] = 1
for i in range(1, p + 1):
for j in range(T + 1):
dp[i][j] = dp[i - 1][j]
if j - i >= 0:
dp[i][j] += dp[i][j - i]
if j - i - q >= 0:
dp[i][j] -= dp[i - 1][j - i - q]
dp[i][j] %= MOD
ans = dp[p][T]
# for r in dp:
# print(", ".join(map(str, r)))
return ans
main()
``` | output | 1 | 25,513 | 19 | 51,027 |
Provide a correct Python 3 solution for this coding contest problem.
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.
The following is an example of a Bingo card when N = 5, M = 50, S = 685.
<image>
I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.
When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.
Examples
Input
3 9 45
3 100 50
5 50 685
0 0 0
Output
1
7
74501
Input
None
Output
None | instruction | 0 | 25,514 | 19 | 51,028 |
"Correct Solution:
```
# coding:utf-8
import sys
input = sys.stdin.readline
MOD = 100000
def inpl(): return list(map(int, input().split()))
while 1:
N, M, S = inpl()
if N == 0:
break
N *= N
dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(1, N + 1):
for j in range(S + 1):
if i <= j:
dp[i][j] += dp[i][j - i] + dp[i - 1][j - i]
if j - 1 >= M:
dp[i][j] -= dp[i - 1][j - 1 - M]
dp[i][j] %= MOD
# TLE!!!
# for i in range(1, M + 1):
# for j in range(1, N + 1)[::-1]: # j - 1の値が更新されるのを防ぐために降順
# for k in range(i, S + 1): # 合計値は必ずi以上になる
# dp[j][k] += dp[j - 1][k - i]
# dp[j][k] %= MOD
print(dp[N][S])
``` | output | 1 | 25,514 | 19 | 51,029 |
Provide a correct Python 3 solution for this coding contest problem.
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.
The following is an example of a Bingo card when N = 5, M = 50, S = 685.
<image>
I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.
When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.
Examples
Input
3 9 45
3 100 50
5 50 685
0 0 0
Output
1
7
74501
Input
None
Output
None | instruction | 0 | 25,515 | 19 | 51,030 |
"Correct Solution:
```
while True:
n, m, s = map(int, input().split())
if not n:
break
n2 = n ** 2
dpp = [0] * (s + 1)
dpp[0] = 1
for i in range(1, n2 + 1):
dpn = [0] * (s + 1)
for j in range(i * (i + 1) // 2, s + 1):
dpn[j] += dpp[j - i] + dpn[j - i]
if j - m - 1 >= 0:
dpn[j] -= dpp[j - m - 1]
dpn[j] %= 100000
dpp = dpn
print(dpp[s])
``` | output | 1 | 25,515 | 19 | 51,031 |
Provide a correct Python 3 solution for this coding contest problem.
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.
The following is an example of a Bingo card when N = 5, M = 50, S = 685.
<image>
I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.
When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.
Examples
Input
3 9 45
3 100 50
5 50 685
0 0 0
Output
1
7
74501
Input
None
Output
None | instruction | 0 | 25,516 | 19 | 51,032 |
"Correct Solution:
```
import itertools
while 1:
n,m,s=map(int,input().split())
if n==0:break
dp=[[0 for _ in range(s+1)] for _ in range(n*n+1)]
dp[0][0]=1
for i,j in itertools.product(range(1,n*n+1),range(s+1)):
if j>=i:dp[i][j]+=dp[i-1][j-i]+dp[i][j-i]
if j-m>=1:dp[i][j]+=100000-dp[i-1][j-m-1]
dp[i][j]%=100000
print(dp[n*n][s])
``` | output | 1 | 25,516 | 19 | 51,033 |
Provide a correct Python 3 solution for this coding contest problem.
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.
The following is an example of a Bingo card when N = 5, M = 50, S = 685.
<image>
I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.
When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.
Examples
Input
3 9 45
3 100 50
5 50 685
0 0 0
Output
1
7
74501
Input
None
Output
None | instruction | 0 | 25,517 | 19 | 51,034 |
"Correct Solution:
```
for e in iter(input,'0 0 0'):
N,M,S=map(int,e.split());N*=N
d=[[0]*-~S for _ in[0]*-~N];d[0][0]=1
for i in range(1,N+1):
for j in range(i,S+1):
d[i][j]+=d[i][j-i]+d[i-1][j-i]-(M+1<=j and d[i-1][j-M-1])
print(d[N][S]%10**5)
``` | output | 1 | 25,517 | 19 | 51,035 |
Provide a correct Python 3 solution for this coding contest problem.
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.
The following is an example of a Bingo card when N = 5, M = 50, S = 685.
<image>
I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.
When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.
Examples
Input
3 9 45
3 100 50
5 50 685
0 0 0
Output
1
7
74501
Input
None
Output
None | instruction | 0 | 25,518 | 19 | 51,036 |
"Correct Solution:
```
import itertools
while 1:
n,m,s=map(int,input().split())
if n==0:break
dp=[[0 for _ in range(s+1)] for _ in range(n*n+1)]
dp[0][0]=1
for i,j in itertools.product(range(1,n*n+1),range(s+1)):
if j>=i:dp[i][j]+=dp[i-1][j-i]+dp[i][j-i]
if j-m>=1:dp[i][j]-=dp[i-1][j-m-1]
dp[i][j]%=100000
print(dp[n*n][s])
``` | output | 1 | 25,518 | 19 | 51,037 |
Provide a correct Python 3 solution for this coding contest problem.
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.
The following is an example of a Bingo card when N = 5, M = 50, S = 685.
<image>
I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.
When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.
Examples
Input
3 9 45
3 100 50
5 50 685
0 0 0
Output
1
7
74501
Input
None
Output
None | instruction | 0 | 25,519 | 19 | 51,038 |
"Correct Solution:
```
def listrep(n,m,s):
tab = [[0]*(s+1) for j in range(n+1)]
tab[0][0] = 1
for i in range(1,n+1):
for k in range(s+1):
if i <= k:
tab[i][k] += tab[i][k-i] + tab[i-1][k-i]
if k-1 >= m:
tab[i][k] -= tab[i-1][k-1-m]
tab[i][k] %= 100000
return tab[n][s]
while True:
n,m,s = map(int,input().split())
if n == 0 : break
n *= n
print(listrep(n,m,s))
``` | output | 1 | 25,519 | 19 | 51,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.
The following is an example of a Bingo card when N = 5, M = 50, S = 685.
<image>
I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.
When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.
Examples
Input
3 9 45
3 100 50
5 50 685
0 0 0
Output
1
7
74501
Input
None
Output
None
Submitted Solution:
```
import itertools
while 1:
n,m,s=map(int,input().split())
if n==0:break
dp=[[0 for _ in range(s+2)] for _ in range(n*n+1)]
dp[0][0]=1
for i,j in itertools.product(range(1,m+1),range(n*n,0,-1)):
for k in range(i,s+1):
dp[j][k]=(dp[j][k]+dp[j-1][k-i])%100000
print(dp[n*n][s])
``` | instruction | 0 | 25,520 | 19 | 51,040 |
No | output | 1 | 25,520 | 19 | 51,041 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.
The following is an example of a Bingo card when N = 5, M = 50, S = 685.
<image>
I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.
When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.
Examples
Input
3 9 45
3 100 50
5 50 685
0 0 0
Output
1
7
74501
Input
None
Output
None
Submitted Solution:
```
def listrep(n,m,s):
tab = [[[0]*(s+1) for j in range(n+1)]
tab[0][0] = 1
for i in range(1,n+1):
for k in range(s+1):
if i <= k:
tab[i][k] += tab[i][k-i] + tab[i-1][k-i]
if j-1 >= m:
tab[i][k] -= tab[i-1][j-1-m]
return tab[n][m][s]
while True:
n,m,s = map(int,input().split())
if n == 0 : break
n *= n
print(listrep(n,m,s))
``` | instruction | 0 | 25,521 | 19 | 51,042 |
No | output | 1 | 25,521 | 19 | 51,043 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.
The following is an example of a Bingo card when N = 5, M = 50, S = 685.
<image>
I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.
When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.
Examples
Input
3 9 45
3 100 50
5 50 685
0 0 0
Output
1
7
74501
Input
None
Output
None
Submitted Solution:
```
def allocate(remains, limit_h, limit_w):
global m
if not remains:
return 1
if limit_w == 1:
return int(remains <= limit_h)
return sum(allocate(remains - i, i, limit_w - 1) for i in
range(min(limit_h, remains, m - limit_w), (remains - 1) // limit_w, -1))
while True:
n, m, s = map(int, input().split())
if not n:
break
remains = s - sum(range(1, n ** 2 + 1))
print(allocate(remains, remains, n ** 2))
``` | instruction | 0 | 25,522 | 19 | 51,044 |
No | output | 1 | 25,522 | 19 | 51,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions.
* The Bingo card is divided into squares of N rows and N columns, and one positive integer is written in each square. All those integers are different.
* The integer written in the square is 1 or more and M or less.
* The sum of N × N integers written on the Bingo card is S.
* When looking at any column, the integers are arranged in ascending order from top to bottom.
* The integer in every square is larger than any integer in the column to the left of that square.
The following is an example of a Bingo card when N = 5, M = 50, S = 685.
<image>
I want to make as many bingo cards as possible that meet the above conditions for the social gathering. However, you must not make more than one same card. Create a program that outputs the remainder of the maximum number of Bingo cards that can be created divided by 100000.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input consists of one line, which contains the size of the bingo card N (1 ≤ N ≤ 7), the upper limit of the integers written in the square M (1 ≤ M ≤ 2000), and the bingo card. Three positive integers representing the sum of integers S (1 ≤ S ≤ 3000) are written separated by blanks. However, you can make one or more bingo cards that meet the conditions for any given input data.
When N, M, S is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, divide the maximum number of Bingo cards that can be created by 100000 and output the remainder on one line.
Examples
Input
3 9 45
3 100 50
5 50 685
0 0 0
Output
1
7
74501
Input
None
Output
None
Submitted Solution:
```
def listrep(n,m,s):
tab = [[[0]*(s+1) for i in range(m+1)] for j in range(n+1)]
for i in range(m+1):
tab[0][i][0] = 1
for i in range(1,n+1):
for j in range(1,m+1):
for k in range(1,s+1):
tab[i][j][k] = tab[i][j-1][k]
if j <= k:
tab[i][j][k] += tab[i-1][j-1][k-j]
if tab[i][j][k] > 100000: tab[i][j][k] -= 100000
return tab[n][m][s]
while True:
n,m,s = map(int,input().split())
if n == 0 : break
n *= n
print(listrep(n,m,s))
``` | instruction | 0 | 25,523 | 19 | 51,046 |
No | output | 1 | 25,523 | 19 | 51,047 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some operations on these coins.
In one operation, you can do the following:
* Choose 2 distinct indices i and j.
* Then, swap the coins on positions i and j.
* Then, flip both coins on positions i and j. (If they are initially faced up, they will be faced down after the operation and vice versa)
Construct a sequence of at most n+1 operations such that after performing all these operations the coin i will be on position i at the end, facing up.
Note that you do not need to minimize the number of operations.
Input
The first line contains an integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of coins.
The second line contains n integers c_1,c_2,...,c_n (1 ≤ c_i ≤ n, c_i ≠ c_j for i≠ j).
Output
In the first line, output an integer q (0 ≤ q ≤ n+1) — the number of operations you used.
In the following q lines, output two integers i and j (1 ≤ i, j ≤ n, i ≠ j) — the positions you chose for the current operation.
Examples
Input
3
2 1 3
Output
3
1 3
3 2
3 1
Input
5
1 2 3 4 5
Output
0
Note
Let coin i facing upwards be denoted as i and coin i facing downwards be denoted as -i.
The series of moves performed in the first sample changes the coins as such:
* [~~~2,~~~1,~~~3]
* [-3,~~~1,-2]
* [-3,~~~2,-1]
* [~~~1,~~~2,~~~3]
In the second sample, the coins are already in their correct positions so there is no need to swap. | instruction | 0 | 25,830 | 19 | 51,660 |
Tags: constructive algorithms, graphs, math
Correct Solution:
```
n = int(input());A = [0] + list(map(int, input().split()));seen = [0] * (n + 1);cycles = [];ans = []
for i in range(1, n + 1):
cur = [];j = i
while not seen[j]:cur.append(j);seen[j] = 1;j = A[j]
if len(cur) > 1: cycles.append(cur)
def swap(x, y):A[x], A[y] = A[y], A[x];ans.append((x, y))
for i in range(1, len(cycles), 2):
X, Y = cycles[i - 1], cycles[i];swap(X[0], Y[0])
for x in X[1:]: swap(x, Y[0])
for y in Y[1:]: swap(y, X[0])
swap(X[0], Y[0])
if len(cycles) % 2:
X = cycles[-1]
if len(X) > 2:
for x in X[:-2]: swap(x, X[-1])
swap(X[0], X[-2]);swap(X[-2], X[-1]);swap(X[0], X[-1])
else:
Y = []
for i in range(1, n + 1):
if i != X[0] and i != X[1]: break
swap(i, X[0]);swap(i, X[1]);swap(i, X[0])
print(len(ans))
for a in ans: print(*a)
``` | output | 1 | 25,830 | 19 | 51,661 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some operations on these coins.
In one operation, you can do the following:
* Choose 2 distinct indices i and j.
* Then, swap the coins on positions i and j.
* Then, flip both coins on positions i and j. (If they are initially faced up, they will be faced down after the operation and vice versa)
Construct a sequence of at most n+1 operations such that after performing all these operations the coin i will be on position i at the end, facing up.
Note that you do not need to minimize the number of operations.
Input
The first line contains an integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of coins.
The second line contains n integers c_1,c_2,...,c_n (1 ≤ c_i ≤ n, c_i ≠ c_j for i≠ j).
Output
In the first line, output an integer q (0 ≤ q ≤ n+1) — the number of operations you used.
In the following q lines, output two integers i and j (1 ≤ i, j ≤ n, i ≠ j) — the positions you chose for the current operation.
Examples
Input
3
2 1 3
Output
3
1 3
3 2
3 1
Input
5
1 2 3 4 5
Output
0
Note
Let coin i facing upwards be denoted as i and coin i facing downwards be denoted as -i.
The series of moves performed in the first sample changes the coins as such:
* [~~~2,~~~1,~~~3]
* [-3,~~~1,-2]
* [-3,~~~2,-1]
* [~~~1,~~~2,~~~3]
In the second sample, the coins are already in their correct positions so there is no need to swap. | instruction | 0 | 25,831 | 19 | 51,662 |
Tags: constructive algorithms, graphs, math
Correct Solution:
```
n = int(input())
p = list(map(lambda x: int(x) - 1, input().split()))
check = p[:]
out = []
def swap(a,b):
out.append(str(a+1)+' '+str(b+1))
check[a], check[b] = -check[b], -check[a]
vis = [False] * n
head = []
for i in range(n):
if not vis[i]:
head.append(i)
vis[i] = True
curr = i
while p[curr] != i:
curr = p[curr]
vis[curr] = True
while len(head) >= 2:
a = head.pop()
b = head.pop()
swap(a,b)
curra = p[a]
while curra != a:
swap(b, curra)
curra = p[curra]
currb = p[b]
while currb != b:
swap(a, currb)
currb = p[currb]
swap(a,b)
if len(head) == 1:
a = head[0]
if p[a] == a:
pass
elif p[p[a]] == a:
a1 = a
a2 = p[a]
a3 = b
swap(a2, a3)
swap(a1, a3)
swap(a2, a3)
else:
l = [a, p[a]]
while p[l[-1]] != a:
l.append(p[l[-1]])
k = len(l)
swap(l[0], l[1])
for i in range(2, k - 1):
swap(l[0], l[i])
swap(l[1], l[k - 1])
swap(l[0], l[k - 1])
swap(l[0], l[1])
assert check == list(range(n))
assert len(out) <= n + 1
print(len(out))
print('\n'.join(out))
``` | output | 1 | 25,831 | 19 | 51,663 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some operations on these coins.
In one operation, you can do the following:
* Choose 2 distinct indices i and j.
* Then, swap the coins on positions i and j.
* Then, flip both coins on positions i and j. (If they are initially faced up, they will be faced down after the operation and vice versa)
Construct a sequence of at most n+1 operations such that after performing all these operations the coin i will be on position i at the end, facing up.
Note that you do not need to minimize the number of operations.
Input
The first line contains an integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of coins.
The second line contains n integers c_1,c_2,...,c_n (1 ≤ c_i ≤ n, c_i ≠ c_j for i≠ j).
Output
In the first line, output an integer q (0 ≤ q ≤ n+1) — the number of operations you used.
In the following q lines, output two integers i and j (1 ≤ i, j ≤ n, i ≠ j) — the positions you chose for the current operation.
Examples
Input
3
2 1 3
Output
3
1 3
3 2
3 1
Input
5
1 2 3 4 5
Output
0
Note
Let coin i facing upwards be denoted as i and coin i facing downwards be denoted as -i.
The series of moves performed in the first sample changes the coins as such:
* [~~~2,~~~1,~~~3]
* [-3,~~~1,-2]
* [-3,~~~2,-1]
* [~~~1,~~~2,~~~3]
In the second sample, the coins are already in their correct positions so there is no need to swap. | instruction | 0 | 25,832 | 19 | 51,664 |
Tags: constructive algorithms, graphs, math
Correct Solution:
```
import sys
input = sys.stdin.readline
n = int(input())
A = [0] + list(map(int, input().split()))
seen = [0] * (n + 1)
cycles = []
ans = []
for i in range(1, n + 1):
cur = []
j = i
while not seen[j]:
cur.append(j)
seen[j] = 1
j = A[j]
if len(cur) > 1: cycles.append(cur)
for i in range(1, len(cycles), 2):
X, Y = cycles[i - 1], cycles[i]
ans.append((X[0], Y[0]))
for x in X[1:]: ans.append((x, Y[0]))
for y in Y[1:]: ans.append((y, X[0]))
ans.append((X[0], Y[0]))
if len(cycles) % 2:
X = cycles[-1]
if len(X) > 2:
for x in X[:-2]: ans.append((x, X[-1]))
ans.append((X[0], X[-2]))
ans.append((X[-2], X[-1]))
ans.append((X[0], X[-1]))
else:
Y = []
for i in range(1, n + 1):
if i != X[0] and i != X[1]: break
ans.append((i, X[0]))
ans.append((i, X[1]))
ans.append((i, X[0]))
print(len(ans))
for a in ans: print(*a)
``` | output | 1 | 25,832 | 19 | 51,665 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some operations on these coins.
In one operation, you can do the following:
* Choose 2 distinct indices i and j.
* Then, swap the coins on positions i and j.
* Then, flip both coins on positions i and j. (If they are initially faced up, they will be faced down after the operation and vice versa)
Construct a sequence of at most n+1 operations such that after performing all these operations the coin i will be on position i at the end, facing up.
Note that you do not need to minimize the number of operations.
Input
The first line contains an integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of coins.
The second line contains n integers c_1,c_2,...,c_n (1 ≤ c_i ≤ n, c_i ≠ c_j for i≠ j).
Output
In the first line, output an integer q (0 ≤ q ≤ n+1) — the number of operations you used.
In the following q lines, output two integers i and j (1 ≤ i, j ≤ n, i ≠ j) — the positions you chose for the current operation.
Examples
Input
3
2 1 3
Output
3
1 3
3 2
3 1
Input
5
1 2 3 4 5
Output
0
Note
Let coin i facing upwards be denoted as i and coin i facing downwards be denoted as -i.
The series of moves performed in the first sample changes the coins as such:
* [~~~2,~~~1,~~~3]
* [-3,~~~1,-2]
* [-3,~~~2,-1]
* [~~~1,~~~2,~~~3]
In the second sample, the coins are already in their correct positions so there is no need to swap. | instruction | 0 | 25,834 | 19 | 51,668 |
Tags: constructive algorithms, graphs, math
Correct Solution:
```
from sys import stdin, stdout
n=int(stdin.readline())
#make 1-indexed
arr=[0]+list(map(int,stdin.readline().split()))
vis=[0]*(n+1)
ans=[]
def cswap(i,j):
arr[i],arr[j]=-arr[j],-arr[i]
ans.append((i,j))
def swap_cyc(i,j):
cswap(i,j)
curr=i
while (arr[-arr[curr]]>0):
cswap(curr,-arr[curr])
curr=-arr[curr]
while (arr[-arr[curr]]>0):
cswap(curr,-arr[curr])
cswap(curr,-arr[curr])
p=-1
for i in range(1,n+1):
if (vis[i]==1): continue
if (arr[i]==i): continue
curr=i
while (True):
vis[curr]=1
curr=arr[curr]
if (curr==i): break
if (p==-1):
p=i
else:
swap_cyc(p,i)
p=-1
if (p!=-1):
can=False
for i in range(1,n+1):
if (arr[i]==i):
swap_cyc(p,i)
can=True
break
if (can==False):
t1,t2=arr[p],arr[arr[p]]
cswap(p,t1)
swap_cyc(t1,t2)
print(len(ans))
[print(i[0],i[1]) for i in ans]
``` | output | 1 | 25,834 | 19 | 51,669 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some operations on these coins.
In one operation, you can do the following:
* Choose 2 distinct indices i and j.
* Then, swap the coins on positions i and j.
* Then, flip both coins on positions i and j. (If they are initially faced up, they will be faced down after the operation and vice versa)
Construct a sequence of at most n+1 operations such that after performing all these operations the coin i will be on position i at the end, facing up.
Note that you do not need to minimize the number of operations.
Input
The first line contains an integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of coins.
The second line contains n integers c_1,c_2,...,c_n (1 ≤ c_i ≤ n, c_i ≠ c_j for i≠ j).
Output
In the first line, output an integer q (0 ≤ q ≤ n+1) — the number of operations you used.
In the following q lines, output two integers i and j (1 ≤ i, j ≤ n, i ≠ j) — the positions you chose for the current operation.
Examples
Input
3
2 1 3
Output
3
1 3
3 2
3 1
Input
5
1 2 3 4 5
Output
0
Note
Let coin i facing upwards be denoted as i and coin i facing downwards be denoted as -i.
The series of moves performed in the first sample changes the coins as such:
* [~~~2,~~~1,~~~3]
* [-3,~~~1,-2]
* [-3,~~~2,-1]
* [~~~1,~~~2,~~~3]
In the second sample, the coins are already in their correct positions so there is no need to swap. | instruction | 0 | 25,836 | 19 | 51,672 |
Tags: constructive algorithms, graphs, math
Correct Solution:
```
import sys
input = sys.stdin.readline
n = int(input());A = [0] + list(map(int, input().split()));seen = [0] * (n + 1);cycles = [];ans = []
for i in range(1, n + 1):
cur = [];j = i
while not seen[j]:cur.append(j);seen[j] = 1;j = A[j]
if len(cur) > 1: cycles.append(cur)
def swap(x, y):A[x], A[y] = A[y], A[x];ans.append((x, y))
for i in range(1, len(cycles), 2):
X, Y = cycles[i - 1], cycles[i];swap(X[0], Y[0])
for x in X[1:]: swap(x, Y[0])
for y in Y[1:]: swap(y, X[0])
swap(X[0], Y[0])
if len(cycles) % 2:
X = cycles[-1]
if len(X) > 2:
for x in X[:-2]: swap(x, X[-1])
swap(X[0], X[-2]);swap(X[-2], X[-1]);swap(X[0], X[-1])
else:
Y = []
for i in range(1, n + 1):
if i != X[0] and i != X[1]: break
swap(i, X[0]);swap(i, X[1]);swap(i, X[0])
print(len(ans))
for a in ans: print(*a)
``` | output | 1 | 25,836 | 19 | 51,673 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some operations on these coins.
In one operation, you can do the following:
* Choose 2 distinct indices i and j.
* Then, swap the coins on positions i and j.
* Then, flip both coins on positions i and j. (If they are initially faced up, they will be faced down after the operation and vice versa)
Construct a sequence of at most n+1 operations such that after performing all these operations the coin i will be on position i at the end, facing up.
Note that you do not need to minimize the number of operations.
Input
The first line contains an integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of coins.
The second line contains n integers c_1,c_2,...,c_n (1 ≤ c_i ≤ n, c_i ≠ c_j for i≠ j).
Output
In the first line, output an integer q (0 ≤ q ≤ n+1) — the number of operations you used.
In the following q lines, output two integers i and j (1 ≤ i, j ≤ n, i ≠ j) — the positions you chose for the current operation.
Examples
Input
3
2 1 3
Output
3
1 3
3 2
3 1
Input
5
1 2 3 4 5
Output
0
Note
Let coin i facing upwards be denoted as i and coin i facing downwards be denoted as -i.
The series of moves performed in the first sample changes the coins as such:
* [~~~2,~~~1,~~~3]
* [-3,~~~1,-2]
* [-3,~~~2,-1]
* [~~~1,~~~2,~~~3]
In the second sample, the coins are already in their correct positions so there is no need to swap. | instruction | 0 | 25,837 | 19 | 51,674 |
Tags: constructive algorithms, graphs, math
Correct Solution:
```
import sys
input = sys.stdin.readline
n = int(input())
A = [0] + list(map(int, input().split()))
seen = [0] * (n + 1)
cycles = []
ans = []
for i in range(1, n + 1):
cur = []
j = i
while not seen[j]:
cur.append(j)
seen[j] = 1
j = A[j]
if len(cur) > 1: cycles.append(cur)
def swap(x, y):
A[x], A[y] = A[y], A[x]
ans.append((x, y))
for i in range(1, len(cycles), 2):
X, Y = cycles[i - 1], cycles[i]
swap(X[0], Y[0])
for x in X[1:]: swap(x, Y[0])
for y in Y[1:]: swap(y, X[0])
swap(X[0], Y[0])
if len(cycles) % 2:
X = cycles[-1]
if len(X) > 2:
for x in X[:-2]: swap(x, X[-1])
swap(X[0], X[-2])
swap(X[-2], X[-1])
swap(X[0], X[-1])
else:
Y = []
for i in range(1, n + 1):
if i != X[0] and i != X[1]: break
swap(i, X[0])
swap(i, X[1])
swap(i, X[0])
print(len(ans))
for a in ans: print(*a)
``` | output | 1 | 25,837 | 19 | 51,675 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some operations on these coins.
In one operation, you can do the following:
* Choose 2 distinct indices i and j.
* Then, swap the coins on positions i and j.
* Then, flip both coins on positions i and j. (If they are initially faced up, they will be faced down after the operation and vice versa)
Construct a sequence of at most n+1 operations such that after performing all these operations the coin i will be on position i at the end, facing up.
Note that you do not need to minimize the number of operations.
Input
The first line contains an integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of coins.
The second line contains n integers c_1,c_2,...,c_n (1 ≤ c_i ≤ n, c_i ≠ c_j for i≠ j).
Output
In the first line, output an integer q (0 ≤ q ≤ n+1) — the number of operations you used.
In the following q lines, output two integers i and j (1 ≤ i, j ≤ n, i ≠ j) — the positions you chose for the current operation.
Examples
Input
3
2 1 3
Output
3
1 3
3 2
3 1
Input
5
1 2 3 4 5
Output
0
Note
Let coin i facing upwards be denoted as i and coin i facing downwards be denoted as -i.
The series of moves performed in the first sample changes the coins as such:
* [~~~2,~~~1,~~~3]
* [-3,~~~1,-2]
* [-3,~~~2,-1]
* [~~~1,~~~2,~~~3]
In the second sample, the coins are already in their correct positions so there is no need to swap.
Submitted Solution:
```
a = int(input())
b = list(map(int,input().split()))
ans = []
c = [0]*a
for i in range(a):
c[b[i]-1]=i
for i in range(a):
if c[i]==i:
continue
x,y = c[i],i
if x-1>=0 and x-1!=y:
z = x-1
elif x+1<a and x+1!=y:
z = x+1
elif y+1<a and y+1!=x:
z = y+1
elif y-1<a and y-1!=x:
z = y-1
ans.append((x+1,z+1))
ans.append((z+1,y+1))
ans.append((x+1,z+1))
c[i],c[b[c[i]]-1] = i,c[i]
print(len(ans))
for i in ans:print(*i)
``` | instruction | 0 | 25,840 | 19 | 51,680 |
No | output | 1 | 25,840 | 19 | 51,681 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.
The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.
One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.
Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.
Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.
Input
The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.
The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.
Output
Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.
Examples
Input
3
2 4 8
Output
14
Input
4
1 -7 -2 3
Output
-3
Note
In the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.
In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) = - 8, Gena's score is ( - 8) + 3 = - 5, i.e. the score difference will be - 3. | instruction | 0 | 26,109 | 19 | 52,218 |
Tags: dp, games
Correct Solution:
```
n = int(input())
a = [0] + list(map(int, input().split()))
dp = [0] * (n + 1)
s = [0] * (n + 1)
for i in range(1, n + 1):
s[i] = s[i - 1] + a[i]
dp[n] = 0
cur = s[n]
for i in range(n - 1, 0, -1):
dp[i] = cur
cur = max(cur, s[i] - dp[i])
print(dp[1])
``` | output | 1 | 26,109 | 19 | 52,219 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.
The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.
One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.
Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.
Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.
Input
The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.
The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.
Output
Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.
Examples
Input
3
2 4 8
Output
14
Input
4
1 -7 -2 3
Output
-3
Note
In the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.
In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) = - 8, Gena's score is ( - 8) + 3 = - 5, i.e. the score difference will be - 3. | instruction | 0 | 26,110 | 19 | 52,220 |
Tags: dp, games
Correct Solution:
```
n=int(input())
a=[0]+list(map(int, input().split()))
p=[0]
for i in range(1, n+1):
p+=[ p[-1]+a[i] ]
d=[ p[n] ]*(n+1)
for i in range(n-2, 0, -1):
d[i]=max(d[i+1], p[i+1]-d[i+1])
print(d[1])
``` | output | 1 | 26,110 | 19 | 52,221 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.
The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.
One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.
Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.
Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.
Input
The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.
The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.
Output
Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.
Examples
Input
3
2 4 8
Output
14
Input
4
1 -7 -2 3
Output
-3
Note
In the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.
In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) = - 8, Gena's score is ( - 8) + 3 = - 5, i.e. the score difference will be - 3. | instruction | 0 | 26,111 | 19 | 52,222 |
Tags: dp, games
Correct Solution:
```
n = int(input())
raw = input().split()
d = []
prev = 0
for i in range(n):
di = int(raw[i])
di += prev
d.append(di)
prev = di
i = n - 2
cur = d[n - 1]
while i > 0:
cur = max(cur, d[i] - cur)
i -= 1
print(cur)
``` | output | 1 | 26,111 | 19 | 52,223 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.
The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.
One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.
Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.
Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.
Input
The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.
The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.
Output
Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.
Examples
Input
3
2 4 8
Output
14
Input
4
1 -7 -2 3
Output
-3
Note
In the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.
In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) = - 8, Gena's score is ( - 8) + 3 = - 5, i.e. the score difference will be - 3. | instruction | 0 | 26,112 | 19 | 52,224 |
Tags: dp, games
Correct Solution:
```
n = int(input())
a = [0] * n
a = list(map(int, input().split()))
for i in range(1, len(a)):
a[i] += a[i - 1]
ans = a[-1]
for i in range(n - 2, 0, -1):
ans = max(ans, a[i] - ans)
print(ans)
``` | output | 1 | 26,112 | 19 | 52,225 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.
The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.
One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.
Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.
Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.
Input
The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.
The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.
Output
Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.
Examples
Input
3
2 4 8
Output
14
Input
4
1 -7 -2 3
Output
-3
Note
In the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.
In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) = - 8, Gena's score is ( - 8) + 3 = - 5, i.e. the score difference will be - 3. | instruction | 0 | 26,113 | 19 | 52,226 |
Tags: dp, games
Correct Solution:
```
n=int(input())
a=list(map(int, input().split()))
p=s=sum(a)
for i in range(n-2, 0, -1):
s-=a[i+1]
p=max(p, s-p)
print(p)
``` | output | 1 | 26,113 | 19 | 52,227 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.
The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.
One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.
Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.
Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.
Input
The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.
The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.
Output
Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.
Examples
Input
3
2 4 8
Output
14
Input
4
1 -7 -2 3
Output
-3
Note
In the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.
In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) = - 8, Gena's score is ( - 8) + 3 = - 5, i.e. the score difference will be - 3. | instruction | 0 | 26,114 | 19 | 52,228 |
Tags: dp, games
Correct Solution:
```
def f(a):
n = len(a)
dp = [0] * n
s = [0] * (n+1)
for i in range(0, n):
s[i+1] = s[i] + a[i]
#print(s)
maxdiffyet = s[n]
#print(f"maxdiffyet = {maxdiffyet}")
for i in range(n-2, -1, -1):
dp[i] = maxdiffyet
#print(f"dp[{i}] = {dp[i]}, s[{i}] = {s[i]}, maxdiffyet({i}) = {maxdiffyet} -> {max(maxdiffyet, s[i+1] - dp[i])}")
maxdiffyet = max(maxdiffyet, s[i+1] - dp[i])
#print(dp)
return dp[0]
n = int(input())
a = [int(x) for x in input().split(' ')]
print(f(a))
``` | output | 1 | 26,114 | 19 | 52,229 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.
The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.
One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.
Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.
Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.
Input
The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.
The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.
Output
Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.
Examples
Input
3
2 4 8
Output
14
Input
4
1 -7 -2 3
Output
-3
Note
In the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.
In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) = - 8, Gena's score is ( - 8) + 3 = - 5, i.e. the score difference will be - 3.
Submitted Solution:
```
def f(a):
n = len(a)
dp = [0] * n
s = [0] * (n+1)
for i in range(0, n):
s[i+1] = s[i] + a[i]
dp[n-1] = 0
dp[n-2] = s[n]
maxdiffyet = s[n]
for i in range(n-3, -1, -1):
dp[i] = maxdiffyet - s[i]
#print(f"maxdiffyet({i}) = {maxdiffyet}")
maxdiffyet = max(maxdiffyet, s[i+2] - dp[i+1])
return dp[0]
n = int(input())
a = [int(x) for x in input().split(' ')]
print(f(a))
``` | instruction | 0 | 26,115 | 19 | 52,230 |
No | output | 1 | 26,115 | 19 | 52,231 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.
The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.
One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.
Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.
Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.
Input
The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.
The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.
Output
Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.
Examples
Input
3
2 4 8
Output
14
Input
4
1 -7 -2 3
Output
-3
Note
In the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.
In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) = - 8, Gena's score is ( - 8) + 3 = - 5, i.e. the score difference will be - 3.
Submitted Solution:
```
def f(a):
n = len(a)
dp = [0] * n
s = [0] * (n+1)
for i in range(0, n):
s[i+1] = s[i] + a[i]
print(s)
dp[n-1] = 0
dp[n-2] = s[n]
maxdiffyet = s[n]
#print(f"maxdiffyet = {maxdiffyet}")
for i in range(n-3, -1, -1):
dp[i] = maxdiffyet
#print(f"dp[{i}] = {dp[i]}, s[{i}] = {s[i]}, maxdiffyet({i}) = {maxdiffyet}")
maxdiffyet = max(maxdiffyet, s[i+1] - dp[i])
print(dp)
return dp[0]
n = int(input())
a = [int(x) for x in input().split(' ')]
print(f(a))
``` | instruction | 0 | 26,116 | 19 | 52,232 |
No | output | 1 | 26,116 | 19 | 52,233 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.
The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.
One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.
Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.
Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.
Input
The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.
The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.
Output
Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.
Examples
Input
3
2 4 8
Output
14
Input
4
1 -7 -2 3
Output
-3
Note
In the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.
In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) = - 8, Gena's score is ( - 8) + 3 = - 5, i.e. the score difference will be - 3.
Submitted Solution:
```
N = int(input())
stickers = [int(x) for x in input().split(' ')]
stickers.reverse()
scoreA = 0
scoreB = 0
stepA = True
count = 0
stickSum = 0
while N > 0:
if count > 2 and stickers[-1] > 0:
if stepA:
scoreA += stickSum
else:
scoreB += stickSum
stickers.append(stickSum)
stickSum = 0
count = 0
N += 1
stepA = not stepA
continue
stickSum += stickers.pop(N - 1)
count += 1
N -= 1
if stepA:
scoreA += stickSum
else:
scoreB += stickSum
print(scoreA - scoreB)
``` | instruction | 0 | 26,117 | 19 | 52,234 |
No | output | 1 | 26,117 | 19 | 52,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.
The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.
One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.
Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.
Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.
Input
The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.
The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.
Output
Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.
Examples
Input
3
2 4 8
Output
14
Input
4
1 -7 -2 3
Output
-3
Note
In the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.
In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) = - 8, Gena's score is ( - 8) + 3 = - 5, i.e. the score difference will be - 3.
Submitted Solution:
```
n = int(input()); a = [int(i) for i in input().split(' ')]
s = sum(a)
p1 = 0; p2 = s; dd = p1 - p2; bestpos = 0
for pos, i in enumerate(a):
p1 += i; p2 -= i; d = p1 - p2
if pos >= 1 and abs(d) > abs(dd):
dd = d
bestpos = pos
if bestpos == 0:
print(s)
else:
print(-sum(a[bestpos+1:]))
``` | instruction | 0 | 26,118 | 19 | 52,236 |
No | output | 1 | 26,118 | 19 | 52,237 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | instruction | 0 | 26,120 | 19 | 52,240 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
n = int(input())
x = int(input())
a = [0, 0, 0]
a[x] = 1
for i in range(n % 6):
if (n - i) % 2 == 0:
a[1], a[2] = a[2], a[1]
else:
a[0], a[1] = a[1], a[0]
if a[0]:
print(0)
if a[1]:
print(1)
if a[2]:
print(2)
``` | output | 1 | 26,120 | 19 | 52,241 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | instruction | 0 | 26,121 | 19 | 52,242 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
Check, N = [False] * 3, int(input()) % 6
Check[int(input())] = True
while N != 0:
if N % 2 == 0:
Check[2], Check[1] = Check[1], Check[2]
else:
Check[0], Check[1] = Check[1], Check[0]
N -= 1
print(Check.index(True))
# UB_CodeForces
# Advice: Falling down is an accident, staying down is a choice
# Location: Mashhad for few days
# Caption: New rank has been achieved
# CodeNumber: 705
``` | output | 1 | 26,121 | 19 | 52,243 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | instruction | 0 | 26,122 | 19 | 52,244 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
n = int(input())
ball = int(input())
n = n % 6
while n > 0:
if n % 2 == 1:
if ball == 0:
ball = 1
elif ball == 1:
ball = 0
elif n % 2 == 0:
if ball == 1:
ball = 2
elif ball == 2:
ball = 1
n -= 1
print(ball)
``` | output | 1 | 26,122 | 19 | 52,245 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | instruction | 0 | 26,123 | 19 | 52,246 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
n=int(input())
x=int(input())
n=n%6
a=[0,0,0]
a[x]=1;
for i in range(n,0,-1):
if i%2:
a[0],a[1]=a[1],a[0]
else:
a[1],a[2]=a[2],a[1]
if(a[0]==1):
print(0)
if(a[1]==1):
print(1)
if(a[2]==1):
print(2)
``` | output | 1 | 26,123 | 19 | 52,247 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | instruction | 0 | 26,124 | 19 | 52,248 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
n=int(input())
x=int(input())
n%=6
a=[[0,1,1,2,2,0],[1,0,2,1,0,2],[2,2,0,0,1,1]]
print(a[x][n])
``` | output | 1 | 26,124 | 19 | 52,249 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | instruction | 0 | 26,125 | 19 | 52,250 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
a=int(input())
b=int(input())
a%=6
f=[[0,1,2],[1,0,2],[2,0,1],[2,1,0],[1,2,0],[0,2,1]]
print(f[a].index(b))
``` | output | 1 | 26,125 | 19 | 52,251 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | instruction | 0 | 26,126 | 19 | 52,252 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
n = int(input())
m = int(input())
n = n % 6
o = 0
for i in range(n):
if i % 2 == 1:
if o != 0:
o = 3 - o
else:
if o != 2:
o = 1 - o
if o == m:
print(0)
else:
o = 1
for i in range(n):
if i % 2 == 1:
if o != 0:
o = 3 - o
else:
if o != 2:
o = 1 - o
if o == m:
print(1)
else:
print(2)
``` | output | 1 | 26,126 | 19 | 52,253 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | instruction | 0 | 26,127 | 19 | 52,254 |
Tags: constructive algorithms, implementation, math
Correct Solution:
```
n, x = int(input()), int(input())
for i in range(n%6, 0, -1):
if not i&1:
if x == 1:
x = 2
elif x == 2:
x = 1
else:
if x == 1:
x = 0
elif x == 0:
x = 1
print(x)
# 100
# 010
#
# 1 2 3 4 5 6 7 8 9 10 11
#
# 0 1 2 2 1 0 0 1 2 2 1
# 1 0 0 1 2 2 1 0 0 1 2
# 2 2 1 0 0 1 2 2 1 0 0
``` | output | 1 | 26,127 | 19 | 52,255 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
Submitted Solution:
```
N = int( input() ) % 6
X = int( input() )
for i in range( N, 0, -1 ) :
if i & 1 and X < 2 :
X = 1 - X
elif ~i & 1 and X :
X = 3 - X
print( X )
``` | instruction | 0 | 26,128 | 19 | 52,256 |
Yes | output | 1 | 26,128 | 19 | 52,257 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
Submitted Solution:
```
import sys
cups = [[0, 1, 2], [1, 0 ,2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]
n = int(input())
x = int(input())
m = n % 6
print (cups[m][x])
``` | instruction | 0 | 26,129 | 19 | 52,258 |
Yes | output | 1 | 26,129 | 19 | 52,259 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
Submitted Solution:
```
m = int(input())
x = int(input())
n = m % 6
while n > 0:
if x == 0:
if n % 2 == 0:
n -= 1
elif n % 2 == 1:
x += 1
n -= 1
elif x == 1:
if n % 2 == 0:
x += 1
n -= 1
elif n % 2 == 1:
x -= 1
n -= 1
elif x == 2:
if n % 2 == 0:
x -= 1
n -= 1
elif n % 2 == 1:
n -= 1
print(x)
``` | instruction | 0 | 26,130 | 19 | 52,260 |
Yes | output | 1 | 26,130 | 19 | 52,261 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
Submitted Solution:
```
# print("Input n")
n = int(input())
# print("Input x")
x = int(input())
n = n % 6
if (n==5 and x == 0) or (n==4 and x==1) or (n==3 and x==2) or (n==2 and x==2) or (n==1 and x==1) or (n==0 and x==0):
print (0)
elif (n==5 and x == 2) or (n==4 and x==2) or (n==3 and x==1) or (n==2 and x==0) or (n==1 and x==0) or (n==0 and x==1):
print(1)
else:
print(2)
``` | instruction | 0 | 26,131 | 19 | 52,262 |
Yes | output | 1 | 26,131 | 19 | 52,263 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
Submitted Solution:
```
#Use python3
if __name__ == "__main__":
pos = [[0, 1, 2, 2, 1, 0, 0], [1, 0, 0, 1, 2, 2, 1], [2, 2, 1, 0, 0, 1, 2]]
n = int(input())
m = int(input())
n = n % 7
for i in range (0, 3):
if(pos[i][n] == m):
print(pos[i][0])
``` | instruction | 0 | 26,132 | 19 | 52,264 |
No | output | 1 | 26,132 | 19 | 52,265 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
Submitted Solution:
```
x = int(input())
now = int(input())
for z in range(4,0,-1):
if z % 2 == 0:
if now == 1:
now += 1
elif now == 2:
now -= 1
if z % 2 != 0:
if now == 1:
now -= 1
elif now == 0:
now += 1
print(now)
``` | instruction | 0 | 26,133 | 19 | 52,266 |
No | output | 1 | 26,133 | 19 | 52,267 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
Submitted Solution:
```
n= int(input())
x= int(input())
print((x - n % 3) % 3)
``` | instruction | 0 | 26,134 | 19 | 52,268 |
No | output | 1 | 26,134 | 19 | 52,269 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
Input
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Output
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Examples
Input
4
2
Output
1
Input
1
1
Output
0
Note
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
Submitted Solution:
```
n = int(input())
x = int(input())
k = n % 3
a = [0] * 3
a[x] = 1
for i in range(k, 0, -1):
if i % 2 != 0:
a[0], a[1] = a[1], a[0]
else:
a[1], a[2] = a[2], a[1]
for i in range(len(a)):
if a[i]:
print(i)
``` | instruction | 0 | 26,135 | 19 | 52,270 |
No | output | 1 | 26,135 | 19 | 52,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Rock... Paper!
After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.
A positive integer n is decided first. Both Koyomi and Karen independently choose n distinct positive integers, denoted by x1, x2, ..., xn and y1, y2, ..., yn respectively. They reveal their sequences, and repeat until all of 2n integers become distinct, which is the only final state to be kept and considered.
Then they count the number of ordered pairs (i, j) (1 ≤ i, j ≤ n) such that the value xi xor yj equals to one of the 2n integers. Here xor means the [bitwise exclusive or](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation on two integers, and is denoted by operators ^ and/or xor in most programming languages.
Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.
Input
The first line of input contains a positive integer n (1 ≤ n ≤ 2 000) — the length of both sequences.
The second line contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 2·106) — the integers finally chosen by Koyomi.
The third line contains n space-separated integers y1, y2, ..., yn (1 ≤ yi ≤ 2·106) — the integers finally chosen by Karen.
Input guarantees that the given 2n integers are pairwise distinct, that is, no pair (i, j) (1 ≤ i, j ≤ n) exists such that one of the following holds: xi = yj; i ≠ j and xi = xj; i ≠ j and yi = yj.
Output
Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
Examples
Input
3
1 2 3
4 5 6
Output
Karen
Input
5
2 4 6 8 10
9 7 5 3 1
Output
Karen
Note
In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number.
In the second example, there are 16 such pairs, and Karen wins again. | instruction | 0 | 26,170 | 19 | 52,340 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print("Karen")
``` | output | 1 | 26,170 | 19 | 52,341 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.