message stringlengths 2 67k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 463 109k | cluster float64 19 19 | __index_level_0__ int64 926 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw | instruction | 0 | 47,921 | 19 | 95,842 |
"Correct Solution:
```
while True:
_=input()
if _ == '-':
break
for i in range(int(input())):
l=int(input())
_=_[l:]+_[:l]
print(_)
``` | output | 1 | 47,921 | 19 | 95,843 |
Provide a correct Python 3 solution for this coding contest problem.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw | instruction | 0 | 47,922 | 19 | 95,844 |
"Correct Solution:
```
while True:
line = input()
if line == '-': break
x = int(input())
for _ in range(x):
h = int(input())
line = line[h:] + line[:h]
print(line)
``` | output | 1 | 47,922 | 19 | 95,845 |
Provide a correct Python 3 solution for this coding contest problem.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw | instruction | 0 | 47,923 | 19 | 95,846 |
"Correct Solution:
```
s = input()
while s != "-":
m = int(input())
h = 0
for i in range(m):
h += int(input())
h %= len(s)
s1 = s[h : len(s)] + s[0 : h]
print(s1)
s = input()
``` | output | 1 | 47,923 | 19 | 95,847 |
Provide a correct Python 3 solution for this coding contest problem.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw | instruction | 0 | 47,924 | 19 | 95,848 |
"Correct Solution:
```
while True:
s = input()
if s == '-':break
n = int(input())
for i in range(n):
h = int(input())
s = s[h:] + s[:h]
print(s)
``` | output | 1 | 47,924 | 19 | 95,849 |
Provide a correct Python 3 solution for this coding contest problem.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw | instruction | 0 | 47,925 | 19 | 95,850 |
"Correct Solution:
```
while True:
line = input()
if line=='-': break
for _ in range(int(input())):
h = int(input())
line = line[h:]+line[:h]
print(line)
``` | output | 1 | 47,925 | 19 | 95,851 |
Provide a correct Python 3 solution for this coding contest problem.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw | instruction | 0 | 47,926 | 19 | 95,852 |
"Correct Solution:
```
while True:
s = input()
if s == "-":
break
n = int(input())
for i in range(n):
h = int(input())
s = s[h:] + s[:h]
print(s)
``` | output | 1 | 47,926 | 19 | 95,853 |
Provide a correct Python 3 solution for this coding contest problem.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw | instruction | 0 | 47,927 | 19 | 95,854 |
"Correct Solution:
```
while True:
s=input()
if s == "-":
break
for _ in range(int(input())):
i=int(input())
s=s[i:]+s[0:i]
print(s)
``` | output | 1 | 47,927 | 19 | 95,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw
Submitted Solution:
```
s = ''
while True:
l = input()
try:
h = int(l)
s = s[h:] + s[:h]
except:
if s: print(s)
if l == '-': break
input()
s = l
``` | instruction | 0 | 47,928 | 19 | 95,856 |
Yes | output | 1 | 47,928 | 19 | 95,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw
Submitted Solution:
```
while True:
n=input()
if n=="-":
break
l=list(n)
m=int(input())
for i in range(m):
h=int(input())
l=l[h:]+l[0:h]
print("".join(l))
``` | instruction | 0 | 47,929 | 19 | 95,858 |
Yes | output | 1 | 47,929 | 19 | 95,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw
Submitted Solution:
```
while True:
s = input()
if s == "-":
break
for i in range(int(input())):
shuf = int(input())
s = s[shuf:] + s[:shuf]
print(s)
``` | instruction | 0 | 47,930 | 19 | 95,860 |
Yes | output | 1 | 47,930 | 19 | 95,861 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw
Submitted Solution:
```
while True:
d = input()
if d == "-":
break
m = int(input())
for _ in range(m):
h = int(input())
d = d[h:] + d[:h]
print(d)
``` | instruction | 0 | 47,931 | 19 | 95,862 |
Yes | output | 1 | 47,931 | 19 | 95,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw
Submitted Solution:
```
while True:
s = input()
if s == '_':
break
m = int(input())
for mi in range(m):
h = int(input())
s = s[:index] + s[:index]
print(s)
``` | instruction | 0 | 47,932 | 19 | 95,864 |
No | output | 1 | 47,932 | 19 | 95,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw
Submitted Solution:
```
s = input()
while s != "0":
n = int(input())
for i in range(n):
h = int(input())
s = s[h:] + s[:h]
print(s)
s = input()
``` | instruction | 0 | 47,933 | 19 | 95,866 |
No | output | 1 | 47,933 | 19 | 95,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw
Submitted Solution:
```
l = []
while 1:
s = input()
if s == "-": break
for _ in range(int(input())):
h = int(input())
s = s[h:] + s[:h]
l += [s]
print(l)
for e in l: print(e)
``` | instruction | 0 | 47,934 | 19 | 95,868 |
No | output | 1 | 47,934 | 19 | 95,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
Constraints
* The length of the string ≤ 200
* 1 ≤ m ≤ 100
* 1 ≤ hi < The length of the string
* The number of datasets ≤ 10
Input
The input consists of multiple datasets. Each dataset is given in the following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string.
Output
For each dataset, print a string which represents the final state in a line.
Example
Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Output
aabc
xyzvw
Submitted Solution:
```
while True:
card = input()
if card == "-":
break
for i in range(int(input())):
h = int(input())
card = card.lstrip(card[:h]) + card[:h]
print(card)
``` | instruction | 0 | 47,935 | 19 | 95,870 |
No | output | 1 | 47,935 | 19 | 95,871 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6 | instruction | 0 | 48,266 | 19 | 96,532 |
Tags: implementation, sortings
Correct Solution:
```
from collections import Counter
n, a = int(input()), sorted(map(int, input().split()))
if n == 1:
print(-1)
elif a[0] == a[-1]:
print(1)
print(a[0])
else:
d = Counter(a[i + 1] - a[i] for i in range(n - 1))
if len(d) == 1:
v = [2 * a[0] - a[1], 2 * a[-1] - a[-2]]
if len(a) == 2 and sum(a) % 2 == 0:
v.insert(1, (a[0] + a[1]) // 2)
print(len(v))
print(' '.join(map(str, v)))
else:
k = sorted(d.keys())
if len(d) == 2 and d[k[1]] == 1 and k[1] == 2 * k[0]:
for i in range(n - 1):
if a[i + 1] - a[i] == k[1]:
print(1)
print(a[i] + k[0])
else:
print(0)
``` | output | 1 | 48,266 | 19 | 96,533 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6 | instruction | 0 | 48,267 | 19 | 96,534 |
Tags: implementation, sortings
Correct Solution:
```
n = int(input())
a = list(map(int,input().strip().split()))
a.sort()
poss = True;
diff = [None] * 2;
places =[[] for x in range(2)]
for x in range(n -1):
curr = a[x+1] - a[x]
if diff[0] is None:
diff[0] = curr;
places[0].append(x)
elif curr != diff[0] and diff[1] is None:
diff[1] = curr;
places[1].append(x)
elif curr == diff[0]:
places[0].append(x)
elif curr == diff[1]:
places[1].append(x)
else:
poss = False;
break;
if len(places[0]) > 1 and len(places[1]) > 1:
poss = False;
break;
if poss == True:
if diff[1] is None:
if len(places[0]) == 0:
print(-1)
elif len(places[0]) == 1:
if diff[0] %2 == 0 and diff[0] != 0:
print(3)
print(a[0] - diff[0],a[0] + (diff[0] //2),a[1] + diff[0] )
elif diff[0] == 0:
print(1)
print(a[0])
else:
print(2)
print(a[0] - diff[0],a[1] + diff[0])
else:
if diff[0] != 0:
print(2)
print(a[0] - diff[0], a[-1] + diff[0])
else:
print(1)
print(a[0])
else:
if len(places[0]) > 1:
if diff[0] * 2 == diff[1]:
print(1)
print(a[places[1][0]] + diff[0])
else:
print(0)
elif len(places[1]) > 1:
if diff[1] * 2 == diff[0]:
print(1)
print(a[places[0][0]] + diff[1])
else:
print(0)
else:
if diff[0] * 2 == diff[1]:
print(1)
print(a[places[1][0]] + diff[0])
elif diff[1] * 2 == diff[0]:
print(1)
print(a[places[0][0]] + diff[1])
else:
print(0)
else:
print(0)
``` | output | 1 | 48,267 | 19 | 96,535 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6 | instruction | 0 | 48,268 | 19 | 96,536 |
Tags: implementation, sortings
Correct Solution:
```
#!/usr/bin/env python3
from sys import stdin
def solve(tc):
n = int(stdin.readline().strip())
seq = sorted(list(map(int, stdin.readline().split())))
ans = []
if n == 1:
print(-1)
return
if n == 2:
diff = seq[1] - seq[0]
if diff == 0:
print(1)
print(seq[0])
return
ans.append(seq[0]-diff)
if diff % 2 == 0:
ans.append(seq[0] + diff//2)
ans.append(seq[1]+diff)
print(len(ans))
print(' '.join(map(lambda x: str(x), ans)))
return
mindiff = int(1e18)
for i in range(1, n):
mindiff = min(mindiff, seq[i]-seq[i-1])
for i in range(1, n):
diff = seq[i]-seq[i-1]
if diff > mindiff:
if diff != mindiff*2:
print(0)
return
if len(ans) > 0:
print(0)
return
ans.append(seq[i-1] + mindiff)
if len(ans) == 0:
if mindiff == 0:
print(1)
print(seq[0])
return
ans.append(seq[0]-mindiff)
ans.append(seq[-1]+mindiff)
print(len(ans))
print(' '.join(map(lambda x: str(x), ans)))
tcs = 1
for tc in range(tcs):
solve(tc)
``` | output | 1 | 48,268 | 19 | 96,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6 | instruction | 0 | 48,269 | 19 | 96,538 |
Tags: implementation, sortings
Correct Solution:
```
import time,math,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
return int(stdin.readline())
def IO(): # to take string input
return stdin.readline()
def IP(): # to take tuple as input
return map(int,stdin.readline().split())
def L(): # to take list as input
return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
return stdout.write(str(x))
def PI(x,y): # to print tuple separatedly
return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
if a==0:
return b
elif b==0:
return a
if a>b:
return gcd(a%b,b)
else:
return gcd(a,b%a)
def sieve():
li=[True]*1000001
li[0],li[1]=False,False
for i in range(2,len(li),1):
if li[i]==True:
for j in range(i*i,len(li),i):
li[j]=False
prime=[]
for i in range(1000001):
if li[i]==True:
prime.append(i)
return prime
def setBit(n):
count=0
while n!=0:
n=n&(n-1)
count+=1
return count
def readTree(v,e): # to read tree
adj=[set() for i in range(v+1)]
for i in range(e):
u1,u2,w=IP()
adj[u1].add((u2,w))
adj[u2].add((u1,w))
return adj
def dfshelper(adj,i,visited):
nodes=1
visited[i]=True
for ele in adj[i]:
if visited[ele]==False:
nd=dfshelper(adj,ele,visited)
nodes+=nd
return nodes
def dfs(adj,v): # a schema of bfs
visited=[False]*(v+1)
li=[]
for i in range(v):
if visited[i]==False:
nodes=dfshelper(adj,i,visited)
li.append(nodes)
return li
#####################################################################################
mx=10**9+7
def solve():
n=II()
li=L()
li.sort()
d={}
for i in range(n-1):
ele=li[i+1]-li[i]
d[ele]=d.get(ele,0)+1
if len(d)>2:
print(0)
elif len(d)==0:
print(-1)
else:
if len(d)==1:
x=list(d.keys())[0]
if x==0:
print(1)
print(li[0])
elif n==2 and x%2==0:
print(3)
print(li[0]-x,li[0]+x//2,li[-1]+x)
else:
print(2)
print(li[0]-x,li[-1]+x)
else:
uni,com=-1,-1
for ele in d:
if d[ele]==1 and uni==-1:
uni=ele
else:
com=ele
if n==3:
com,uni=min(uni,com),max(uni,com)
if uni!=2*com:
print(0)
else:
print(1)
for i in range(n-1):
if li[i+1]-li[i]==uni:
print(li[i]+com)
else:
if uni<com or uni!=2*com:
print(0)
else:
print(1)
for i in range(n-1):
if li[i+1]-li[i]==uni:
print(li[i]+com)
solve()
#######
#
#
####### # # # #### # # #
# # # # # # # # # # #
# #### # # #### #### # #
###### # # #### # # # # #
``` | output | 1 | 48,269 | 19 | 96,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6 | instruction | 0 | 48,270 | 19 | 96,540 |
Tags: implementation, sortings
Correct Solution:
```
from collections import defaultdict
n = int(input())
arr = sorted(list(map(int,input().split())))
def isAP(arr):
d = arr[1] - arr[0]
for i in range(1,len(arr)):
if d != arr[i]-arr[i-1]:
return False
return True
ans = []
if n==1:
print(-1)
elif n==2:
d = arr[1]-arr[0]
if d==0:
ans = [arr[0]]
elif d%2 == 0:
d //=2
ans = [arr[0]-d*2,arr[0]+d,arr[1]+d*2]
else:
ans = [arr[0]-d,arr[1]+d]
else:
if isAP(arr):
d = arr[1]-arr[0]
if d==0:
ans.append(arr[0])
else:
ans = [arr[0]-d,arr[-1]+d]
else:
diff = defaultdict(int)
for i in range(1,n):
d = arr[i]-arr[i-1]
diff[d] += 1
d = diff.keys()
if len(d)>2:
print(0)
elif min(d)*2!=max(d) or diff[max(d)]>1:
print(0)
elif 0 in diff.values():
ans.append(arr[0])
else:
d = max(d)
for i in range(1,n):
if arr[i] - arr[i-1] == d:
ans = [arr[i-1]+d//2]
break
if len(ans)!=0:
print(len(ans))
print(*ans)
``` | output | 1 | 48,270 | 19 | 96,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6 | instruction | 0 | 48,271 | 19 | 96,542 |
Tags: implementation, sortings
Correct Solution:
```
n=int(input())
arr=[int(x) for x in input().split()]
cd={}
arr.sort()
for i in range(1,n):
cdtemp=arr[i]-arr[i-1]
if cdtemp not in cd:
cd[cdtemp]=1
else:
cd[cdtemp]+=1
if len(cd)>2:
print(0)
elif len(cd)==1:
for key,val in cd.items():
if key==0:
num=1
ans=[arr[0]]
elif len(arr)==2 and key%2==0:
num=3
ans=[arr[0]-key,arr[0]+key//2,arr[1]+key]
else:num=2;ans=[arr[0]-key,arr[-1]+key]
print(num)
print(*ans)
elif len(cd)==2:
com=[]
for key,val in cd.items():
com.append(key)
com.sort()
if com[0]*2==com[1] and cd[com[1]]==1:
ans=[]
for i in range(1,n):
if arr[i]-arr[i-1]==com[1]:
ans.append(arr[i-1]+com[0])
break
print(1);
print(*ans)
else:
print(0)
else:
print(-1)
``` | output | 1 | 48,271 | 19 | 96,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6 | instruction | 0 | 48,272 | 19 | 96,544 |
Tags: implementation, sortings
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
import math
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
import os
import sys
from io import BytesIO, IOBase
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
n = int(input())
l = list(map(int, input().split()))
l.sort()
if (n == 1):
print(-1)
elif (n == 2):
if (l[-1] - l[0] == 0):
print(1)
print(l[0])
elif ((l[-1] - l[0]) % 2 == 0):
d = l[-1] - l[0]
print(3)
print(l[0] - d, l[0] + d // 2, l[-1] + d)
else:
d=l[-1]-l[0]
print(2)
print(l[0]-d,l[1]+d)
else:
d = l[1] - l[0]
do = 0
h = 0
di = 0
f = True
for i in range(1, n):
if (l[i] - l[i - 1]) == d:
di += 1
elif ((l[i] - l[i - 1]) == d // 2):
h += 1
elif ((l[i] - l[i - 1]) == 2 * d):
do += 1
else:
f = False
break
if (not f):
print(0)
else:
if (h == 0 and do == 0):
if(l[1]-l[0]!=0):
print(2)
print(l[0] - d, l[-1] + d)
else:
print(1)
print(l[0])
elif ((h >= 1 and di == 1 and do == 0) or (di >= 1 and do == 1 and h == 0)):
if (h >= 1 and di == 1 and do == 0):
if (d % 2 == 0):
print(1)
for i in range(1, n):
if (l[i] - l[i - 1] == d):
p = i
break
print(l[p - 1] + d // 2)
else:
print(0)
else:
for i in range(1, n):
if (l[i] - l[i - 1] == 2 * d):
p = i
break
print(1)
print(l[p - 1] + d)
else:
print(0)
``` | output | 1 | 48,272 | 19 | 96,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6 | instruction | 0 | 48,273 | 19 | 96,546 |
Tags: implementation, sortings
Correct Solution:
```
from sys import stdin
input=stdin.readline
def ap(arr):
if len(arr)==1:
return -1
dif=[]
ans=[]
arr=sorted(arr)
l=set()
for i in range(0,len(arr)-1):
d=arr[i+1]-arr[i]
dif.append(d)
l.add(d)
if len(l)>2:
return 0
if len(set(dif))==1:
if dif[0]==0:
ans.append(arr[0])
print(len(ans))
print(*ans)
return ""
else:
ans.append(arr[0]-dif[0])
ans.append(arr[-1]+dif[0])
if len(arr)>3:
print(len(ans))
print(*ans)
return ""
mini = max(dif)
maxi = min(dif)
if mini/2!=maxi and len(set(dif))>=2:
return 0
if len(arr)==2 and len(set(dif))==1 :
if (arr[0]+arr[1])%2==0:
d=(arr[0]+arr[1])//2
ans.append(d)
if maxi==0 and len(set(dif))>=2:
return 0
if len(set(dif))==2:
if dif.count(mini)==1 and mini!=0:
for i in range(0,len(arr)-1):
if arr[i+1]-arr[i]==mini:
ans.append(arr[i]+maxi)
else:
return 0
ans=sorted(ans)
if len(set(dif))>2:
return 0
print(len(ans))
print(*ans)
return ""
a=input()
lst=list(map(int,input().strip().split()))
print(ap(lst))
``` | output | 1 | 48,273 | 19 | 96,547 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6
Submitted Solution:
```
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
def readvars():
k = map(int,input().split())
return(k)
def readlist():
li = list(map(int,input().split()))
return(li)
def anslist(li):
ans = " ".join([str(v) for v in li])
return(ans)
def main():
t = 1
# t = int(input())
for xx in range(t):
n = int(input())
a = readlist()
a.sort()
if n == 1:
print(-1)
continue
if n == 2:
dd = a[1]-a[0]
if dd%2 == 0:
if dd == 0:
print(1)
print(a[0])
continue
dd//=2
print(3)
print("{} {} {}".format(a[0]-2*dd,a[0]+dd,a[1]+2*dd))
else:
print(2)
print("{} {}".format(a[0]-dd,a[1]+dd))
continue
if n >= 3:
dif = [(a[i+1] - a[i]) for i in range(n-1)]
freq = {}
for i in dif:
if i in freq:
freq[i] += 1
else:
freq[i] = 1
maxr = 0
ct = 0
for key in freq:
maxr = max(freq[key],maxr)
ct += 1
if ct >= 3:
print(0)
if ct == 1:
if dif[0] == 0:
print(1)
print(a[0])
continue
print(2)
print("{} {}".format(a[0]-dif[0],a[n-1]+dif[0]))
if ct == 2:
din = []
for k in freq:
din.append(k)
if min(din)*2 == max(din) and freq[max(din)] == 1:
print(1)
print(a[dif.index(max(din))]+min(din))
else:
print(0)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
``` | instruction | 0 | 48,274 | 19 | 96,548 |
Yes | output | 1 | 48,274 | 19 | 96,549 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6
Submitted Solution:
```
n=int(input())
a=input().split()
for i in range(n):
a[i]=int(a[i])
a.sort()
if(n==1):print(-1)
elif(n==2):
if(a[0]==a[1]):
print(1)
print(a[0])
elif((a[1]-a[0])%2==0):
print(3)
print(a[0]-(a[1]-a[0]),(a[0]+a[1])//2,a[1]+(a[1]-a[0]))
else:
print(2)
print(a[0]-(a[1]-a[0]),a[1]+(a[1]-a[0]))
else:
dic={}
for i in range(1,n):
if(a[i]-a[i-1] in dic.keys()):dic[a[i]-a[i-1]]+=1
else:dic[a[i]-a[i-1]]=1
if(len(dic.keys())==1):
if(a[0]==a[n-1]):
print(1)
print(a[0])
else:
print(2)
print(a[0]-(a[1]-a[0]),a[n-1]+(a[1]-a[0]))
elif(len(dic.keys())==2):
ls=[i for i in dic.keys()]
ls.sort()
if(dic[ls[1]]==1 and ls[1]%2==0 and ls[0]==ls[1]//2):
print(1)
for i in range(1,n):
if(a[i]-a[i-1]==ls[1]):
print(a[i-1]+ls[0])
break
else:
print(0)
else:
print(0)
``` | instruction | 0 | 48,275 | 19 | 96,550 |
Yes | output | 1 | 48,275 | 19 | 96,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(-1)
else:
a.sort()
d = []
for i in range(n - 1):
d.append(a[i + 1] - a[i])
k = list(set(d))
k.sort()
uni = {}
for elem in d:
if elem not in uni:
uni[elem] = 1
else:
uni[elem]+=1
if len(k) > 2:
print(0)
elif 0 in k:
if len(k)==1:
print(1)
print(a[0])
else:
print(0)
elif len(k) == 2:
if uni[k[1]] > 1:
print(0)
else:
if k[1] % 2:
print(0)
else:
if k[1]==2*k[0]:
print(1)
print(int((a[d.index(k[1]) + 1] + a[d.index(k[1])]) / 2))
else:
print(0)
else:
if n==2:
if k[0] % 2:
print(2)
ans = [str(int(a[0] - k[0])), str(int(a[1] + k[0]))]
print(' '.join(ans))
else:
ans = [ str(int(a[0]-k[0])), str(int((a[0]+a[1])/2)) , str(int(a[1]+k[0])) ]
print(3)
print(" ".join(ans))
else:
ans = [ str(int(a[0]-k[0])) , str(int(a[n-1]+k[0])) ]
print(2)
print(' '.join(ans))
``` | instruction | 0 | 48,276 | 19 | 96,552 |
Yes | output | 1 | 48,276 | 19 | 96,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
a.sort()
r = 0
res = []
'Función para revisar si el arreglo es una progresión aritmética'
def isAri(a):
diff = a[1]-a[0]
for i in range(len(a)-1):
if not (a[i+1]-a[i]==diff):
return False
return True
if(n==1):
print(-1)
elif(isAri(a) and a[1]-a[0]==0):
r+=1
print(r)
print(a[0])
elif(isAri(a)):
r+=1
res.append(a[0]-(a[1]-a[0]))
r+=1
res.append(a[len(a)-1]+(a[1]-a[0]))
if(n==2 and (a[0]+a[1])%2==0):
r+=1
res.append(int((a[0]+a[1])/2))
res.sort()
print(r)
for i in range(0, len(res)):
print(res[i],end=" ")
else:
diff = a[1]-a[0]
if(a[1]-a[0]==2*(a[2]-a[1])):
diff = a[2]-a[1]
errorIndex = -1
errors = 0
for i in range(0, len(a)-1):
curr = a[i+1]-a[i]
if(curr != diff):
errors+=1
if(curr == 2*diff):
errorIndex = i
if(errors==1 and errorIndex!=-1):
print(1)
print(a[errorIndex]+diff)
else:
print(0)
``` | instruction | 0 | 48,277 | 19 | 96,554 |
Yes | output | 1 | 48,277 | 19 | 96,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6
Submitted Solution:
```
def main(inp):
n = int(input())
arr = split_inp_int(inp)
arr.sort()
if n == 1:
print(-1)
return
if n == 2:
a, b = arr
diff = b-a
if diff == 0:
print(1)
print(a)
elif diff % 2 == 0:
print(3)
print(a-diff, a+diff//2, b+diff)
else:
print(2)
print(a-diff, b+diff)
return
diffs = [arr[i]-arr[i-1] for i in range(1, n)]
if len(set(diffs)) > 2:
print(0)
return
if len(set(diffs)) == 1:
diff = arr[1]-arr[0]
if diff == 1:
print(1)
print(arr[0])
else:
print(2)
print(arr[0]-diff, arr[-1]+diff)
return
diffs_counter = [(k, v) for k, v in Counter(diffs).items()]
# print(diffs_counter)
diffs_counter.sort()
if diffs_counter[1][1] != 1:
print(0)
return
common_diff = diffs_counter[0][0]
other_diff = diffs_counter[1][0]
if other_diff != common_diff*2:
print(0)
return
print(1)
print(arr[0] + common_diff*diffs.index(other_diff) + common_diff)
def split_inp_int(inp):
return list(map(int, inp().split()))
def use_fast_io():
import sys
class InputStorage:
def __init__(self, lines):
lines.reverse()
self.lines = lines
def input_func(self):
if self.lines:
return self.lines.pop()
else:
return ""
return input
input_storage_obj = InputStorage(sys.stdin.readlines())
return input_storage_obj
from collections import Counter, defaultdict
from functools import reduce
import operator
import math
def product(arr_):
return reduce(operator.mul, arr_, 1)
if __name__ == "__main__":
main(use_fast_io())
``` | instruction | 0 | 48,278 | 19 | 96,556 |
No | output | 1 | 48,278 | 19 | 96,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6
Submitted Solution:
```
# import math
# import collections
# from itertools import permutations
# from itertools import combinations
# import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
'''def is_prime(n):
j=2
while j*j<=n:
if n%j==0:
return 0
j+=1
return 1'''
'''def gcd(x, y):
while(y):
x, y = y, x % y
return x'''
'''fact=[]
def factors(n) :
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
if (n / i == i) :
fact.append(i)
else :
fact.append(i)
fact.append(n//i)
i = i + 1'''
def prob():
n = int(input())
# s=input()
l=[int(x) for x in input().split()]
# a,b = list(map(int , input().split()))
if n==1:
print(-1)
else:
l.sort()
p=set([])
di = {}
for i in range(n-1):
d=l[i+1]-l[i]
di[d]=i
p.add(d)
# print(di)
if len(p)==1:
d=l[1]-l[0]
s=l[1]+l[0]
if d==0:
print(1)
print(l[0])
elif d%2==0:
print(3)
print(l[0]-d ,s//2, l[n-1]+d)
else:
print(2)
print(l[0]-d , l[n-1]+d)
else:
if len(p)>2:
print(0)
else:
k=list(p)
k.sort()
# print(k)
if k[0]*2!=k[1]:
print(0)
else:
print(1)
x=di[k[1]]
print(l[x]+k[0])
t=1
# t=int(input())
for _ in range(0,t):
prob()
``` | instruction | 0 | 48,279 | 19 | 96,558 |
No | output | 1 | 48,279 | 19 | 96,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6
Submitted Solution:
```
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect
#?############################################################
def isPrime(x):
for i in range(2, x):
if i*i > x:
break
if (x % i == 0):
return False
return True
#?############################################################
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
#?############################################################
def primeFactors(n):
l = []
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n))+1, 2):
while n % i == 0:
l.append(int(i))
n = n / i
if n > 2:
l.append(n)
return list(set(l))
#?############################################################
def power(x, y, p):
res = 1
x = x % p
if (x == 0):
return 0
while (y > 0):
if ((y & 1) == 1):
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
#?############################################################
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
#?############################################################
def digits(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
#?############################################################
def ceil(n, x):
if (n % x == 0):
return n//x
return n//x+1
#?############################################################
def mapin():
return map(int, input().split())
#?############################################################
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
# python3 15.py<in>op
n = int(input())
a = [int(x) for x in input().split()]
if(n == 1):
print(-1)
else:
a.sort()
ans = []
ll = []
aa = 0
for i in range(1, n):
ll.append(a[i]-a[i-1])
if(len(set(ll)) == 1):
ans.append(a[0]-(a[1]-a[0]))
ans.append(a[-1]+(a[1]-a[0]))
if(len(a) == 2):
if((a[-1]+a[0])%2 == 0):
ans.append((a[-1]+a[0])//2)
elif(len(set(ll)) == 2):
k = max(ll)
for i in range(len(ll)):
if(ll[i] == k):
if((a[i+1]+a[i])%2 == 0):
ans.append((a[i+1]+a[i])//2)
ans = list(set(ans))
print(len(ans))
ans.sort()
print(*ans)
``` | instruction | 0 | 48,280 | 19 | 96,560 |
No | output | 1 | 48,280 | 19 | 96,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6
Submitted Solution:
```
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect
#?############################################################
def isPrime(x):
for i in range(2, x):
if i*i > x:
break
if (x % i == 0):
return False
return True
#?############################################################
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
#?############################################################
def primeFactors(n):
l = []
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n))+1, 2):
while n % i == 0:
l.append(int(i))
n = n / i
if n > 2:
l.append(n)
return list(set(l))
#?############################################################
def power(x, y, p):
res = 1
x = x % p
if (x == 0):
return 0
while (y > 0):
if ((y & 1) == 1):
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
#?############################################################
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
#?############################################################
def digits(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
#?############################################################
def ceil(n, x):
if (n % x == 0):
return n//x
return n//x+1
#?############################################################
def mapin():
return map(int, input().split())
#?############################################################
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
# python3 15.py<in>op
n = int(input())
a = [int(x) for x in input().split()]
if(n == 1):
print(-1)
else:
a.sort()
ans = []
ll = []
aa = 0
for i in range(1, n):
ll.append(a[i]-a[i-1])
if(len(set(ll)) == 1):
ans.append(a[0]-(a[1]-a[0]))
ans.append(a[-1]+(a[1]-a[0]))
if(len(a) == 2):
if((a[-1]+a[0])%2 == 0):
ans.append((a[-1]+a[0])//2)
elif(len(set(ll)) == 2):
k = max(ll)
for i in range(len(ll)):
if(ll[i] == k):
if((a[i+1]+a[i])%2 == 0):
ans.append((a[i+1]+a[i])//2)
print(len(ans))
ans.sort()
print(*ans)
``` | instruction | 0 | 48,281 | 19 | 96,562 |
No | output | 1 | 48,281 | 19 | 96,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node x. Right after someone has picked node x, the value of node x flips, the values of sons of x remain the same, the values of sons of sons of x flips, the values of sons of sons of sons of x remain the same and so on.
The goal of the game is to get each node i to have value goali, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
Input
The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi.
The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also contains n integer numbers, the i-th number corresponds to goali (goali is either 0 or 1).
Output
In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi.
Examples
Input
10
2 1
3 1
4 2
5 1
6 2
7 5
8 6
9 8
10 5
1 0 1 1 0 1 0 1 0 1
1 0 1 0 0 1 1 1 0 1
Output
2
4
7
Submitted Solution:
```
'''
Aaditya Upadhyay
_,add8ba,
,d888888888b,
d8888888888888b _,ad8ba,_
d888888888888888) ,d888888888b,
I8888888888888888 _________ ,8888888888888b
__________`Y88888888888888P"""""""""""baaa,__ ,888888888888888,
,adP"""""""""""9888888888P""^ ^""Y8888888888888888I
,a8"^ ,d888P"888P^ ^"Y8888888888P'
,a8^ ,d8888' ^Y8888888P'
a88' ,d8888P' I88P"^
,d88' d88888P' "b,
,d88' d888888' `b,
,d88' d888888I `b,
d88I ,8888888' ___ `b,
,888' d8888888 ,d88888b, ____ `b,
d888 ,8888888I d88888888b, ,d8888b, `b
,8888 I8888888I d8888888888I ,88888888b 8,
I8888 88888888b d88888888888' 8888888888b 8I
d8886 888888888 Y888888888P' Y8888888888, ,8b
88888b I88888888b `Y8888888^ `Y888888888I d88,
Y88888b `888888888b, `""""^ `Y8888888P' d888I
`888888b 88888888888b, `Y8888P^ d88888
Y888888b ,8888888888888ba,_ _______ `""^ ,d888888
I8888888b, ,888888888888888888ba,_ d88888888b ,ad8888888I
`888888888b, I8888888888888888888888b, ^"Y888P"^ ____.,ad88888888888I
88888888888b,`888888888888888888888888b, "" ad888888888888888888888'
8888888888888698888888888888888888888888b_,ad88ba,_,d88888888888888888888888
88888888888888888888888888888888888888888b,`"""^ d8888888888888888888888888I
8888888888888888888888888888888888888888888baaad888888888888888888888888888'
Y8888888888888888888888888888888888888888888888888888888888888888888888888P
I888888888888888888888888888888888888888888888P^ ^Y8888888888888888888888'
`Y88888888888888888P88888888888888888888888888' ^88888888888888888888I
`Y8888888888888888 `8888888888888888888888888 8888888888888888888P'
`Y888888888888888 `888888888888888888888888, ,888888888888888888P'
`Y88888888888888b `88888888888888888888888I I888888888888888888'
"Y8888888888888b `8888888888888888888888I I88888888888888888'
"Y88888888888P `888888888888888888888b d8888888888888888'
^""""""""^ `Y88888888888888888888, 888888888888888P'
"8888888888888888888b, Y888888888888P^
`Y888888888888888888b `Y8888888P"^
"Y8888888888888888P `""""^
`"YY88888888888P'
^""""""""'
'''
from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil
def st(): return list(stdin.readline().strip())
def li(): return list(map(int, stdin.readline().split()))
def mp(): return map(int, stdin.readline().split())
def inp(): return int(stdin.readline())
def pr(n): return stdout.write(str(n)+"\n")
mod = 1000000007
INF = float('inf')
def solve():
n = inp()
d = {i: [] for i in range(1, n+1)}
for i in range(n-1):
a, b = mp()
d[a].append(b)
d[b].append(a)
l = [0] + li()
k = [0] + li()
flag = [0 for i in range(n+1)]
v = [0 for i in range(n+1)]
par = {i: -1 for i in range(1, n+1)}
q = deque([1])
v[1] = 1
ans = []
while q:
a = q.popleft()
if par[a] != -1 and par[par[a]] != -1:
flag[a] += flag[par[par[a]]]
if l[a] != k[a]:
if flag[a] % 2 == 0:
flag[a] += 1
ans.append(a)
else:
if flag[a] % 2:
flag[a] += 1
ans.append(a)
for i in d[a]:
if not v[i]:
v[i] = 1
q.append(i)
par[i] = a
print(len(ans))
print('\n'.join(map(str, ans)))
for _ in range(1):
solve()
``` | instruction | 0 | 48,291 | 19 | 96,582 |
Yes | output | 1 | 48,291 | 19 | 96,583 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node x. Right after someone has picked node x, the value of node x flips, the values of sons of x remain the same, the values of sons of sons of x flips, the values of sons of sons of sons of x remain the same and so on.
The goal of the game is to get each node i to have value goali, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
Input
The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi.
The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also contains n integer numbers, the i-th number corresponds to goali (goali is either 0 or 1).
Output
In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi.
Examples
Input
10
2 1
3 1
4 2
5 1
6 2
7 5
8 6
9 8
10 5
1 0 1 1 0 1 0 1 0 1
1 0 1 0 0 1 1 1 0 1
Output
2
4
7
Submitted Solution:
```
from collections import defaultdict, Counter
def solve(tree, nodes2change):
nodes2pick = []
for node in nodes2change:
nodes2pick.append(node)
for child in tree[node]:
for nephew in tree[child]:
nodes2pick.append(nephew)
ans = []
cnt = Counter(nodes2pick)
for k, v in cnt.items():
if v % 2 == 1:
ans.append(k)
return ans
def main():
n = int(input())
graph = defaultdict(list)
for _ in range(n - 1):
u, v = map(int, input().split())
graph[u].append(v)
graph[v].append(u)
node = 1
stack = [1]
visited = [False] * (n+1)
visited[1] = True
tree = defaultdict(list)
while stack:
cur = stack.pop()
for child in graph[cur]:
if not visited[child]:
tree[cur].append(child)
stack.append(child)
visited[child] = True
nodes2change = []
start = [int(c) for c in input().split()]
end = [int(c) for c in input().split()]
for i, (s, e) in enumerate(zip(start, end), 1):
if s != e:
nodes2change.append(i)
ans = solve(tree, nodes2change)
print(len(ans))
for node in ans:
print(node)
if __name__ == "__main__":
main()
``` | instruction | 0 | 48,293 | 19 | 96,586 |
Yes | output | 1 | 48,293 | 19 | 96,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node x. Right after someone has picked node x, the value of node x flips, the values of sons of x remain the same, the values of sons of sons of x flips, the values of sons of sons of sons of x remain the same and so on.
The goal of the game is to get each node i to have value goali, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
Input
The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi.
The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also contains n integer numbers, the i-th number corresponds to goali (goali is either 0 or 1).
Output
In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi.
Examples
Input
10
2 1
3 1
4 2
5 1
6 2
7 5
8 6
9 8
10 5
1 0 1 1 0 1 0 1 0 1
1 0 1 0 0 1 1 1 0 1
Output
2
4
7
Submitted Solution:
```
from collections import defaultdict
n = int(input())
d = defaultdict(list)
def DFSop(d1,x,goal,state,visited):
c = 0
stack = [(x,c)]
l = []
while len(stack):
temp,c = stack.pop()
visited[temp] = 1
if c%2 == 1:
state[temp-1] = 1 - state[temp-1]
if state[temp-1] != goal[temp-1]:
c = c + 1
state[temp-1] = goal[temp-1]
l.append(temp)
for i in d1[temp]:
if visited[i] == 0:
stack.append((i,c))
return l
# def DFSop(d1,x,goal,state,c,visited,l):
# if c%2 == 1:
# state[x-1] = 1-state[x-1]
# elif c%2 == 0:
# state[x-1] = state[x-1]
# if goal[x-1] != state[x-1]:
# state[x-1] = goal[x-1]
# count = 1
# c = c + 1
# l.append(x)
# else:
# count = 0
# visited[x] = 1
# for i in d1[x]:
# if visited[i] == 0:
# DFSop(d1,i,goal,state,c,visited,l)
# return l
def DFS(d,x,parent,visited):
stack = [(x,0)]
d1 = defaultdict(list)
while len(stack):
temp,parent = stack.pop()
visited[temp] = 1
# print(temp,parent)
for i in d[temp]:
if visited[i] == 0:
d1[parent].append(i)
stack.append((i,temp))
return d1
for i in range(n-1):
a,b = map(int,input().split())
d[a].append(b)
d[b].append(a)
parent = 0
visited = [0 for i in range(n+1)]
x = 1
state = list(map(int,input().split()))
goal = list(map(int,input().split()))
c = 0
x = 1
parent = 0
d1 = DFS(d,x,parent,visited)
visited = [0 for i in range(n+1)]
l = []
ans = DFSop(d1,x,goal,state,visited)
for i in d[1]:
ans = ans + DFSop(d1,i,goal,state,visited)
ans = set(ans)
print(len(ans))
for i in ans:
print(i)
``` | instruction | 0 | 48,294 | 19 | 96,588 |
Yes | output | 1 | 48,294 | 19 | 96,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node x. Right after someone has picked node x, the value of node x flips, the values of sons of x remain the same, the values of sons of sons of x flips, the values of sons of sons of sons of x remain the same and so on.
The goal of the game is to get each node i to have value goali, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
Input
The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi.
The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also contains n integer numbers, the i-th number corresponds to goali (goali is either 0 or 1).
Output
In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi.
Examples
Input
10
2 1
3 1
4 2
5 1
6 2
7 5
8 6
9 8
10 5
1 0 1 1 0 1 0 1 0 1
1 0 1 0 0 1 1 1 0 1
Output
2
4
7
Submitted Solution:
```
n = int(input())
tree = {}
for i in range(n-1):
u, v = list(map(int, input().split(" ")))
tree[v] = tree.get(v, []) + [u]
print(tree)
init = list(map(int, input().split(" ")))
goal = list(map(int, input().split(" ")))
print("initial init", init)
print("goal", goal)
def flip(root, change=True):
global init
if change:
init[root-1] = abs(init[root-1]-1)
if root in tree.keys():
for vertex in tree[root]:
flip(vertex, change=False)
else:
if root in tree.keys():
for vertex in tree[root]:
flip(vertex, change=True)
ans = []
for i in range(n):
if init[i] != goal[i]:
flip(i+1)
ans.append(i+1)
print("changed", i+1)
print("init", init)
print(len(ans))
for a in ans:
print(a)
``` | instruction | 0 | 48,295 | 19 | 96,590 |
No | output | 1 | 48,295 | 19 | 96,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node x. Right after someone has picked node x, the value of node x flips, the values of sons of x remain the same, the values of sons of sons of x flips, the values of sons of sons of sons of x remain the same and so on.
The goal of the game is to get each node i to have value goali, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
Input
The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi.
The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also contains n integer numbers, the i-th number corresponds to goali (goali is either 0 or 1).
Output
In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi.
Examples
Input
10
2 1
3 1
4 2
5 1
6 2
7 5
8 6
9 8
10 5
1 0 1 1 0 1 0 1 0 1
1 0 1 0 0 1 1 1 0 1
Output
2
4
7
Submitted Solution:
```
import sys
import threading
from collections import defaultdict
n = int(input())
adj = defaultdict(list)
for i in range(n-1):
x,y = map(int,input().split())
adj[x].append(y)
adj[y].append(x)
intial = list(map(int,input().split()))
target = list(map(int,input().split()))
# final = list(zip(intial,target))
# flip_count = 0
flip_node = []
global grandflip
grandflip=False
def dfs(node,par,grandParentFlip,parentFlip):
global grandflip
grandflip =False
if intial[node-1]!=target[node-1]:
if grandParentFlip%2==0:
flip_node.append(node)
grand_flip=True
else:
if grandParentFlip%2!=0:
flip_node.append(node)
grand_flip = True
for i in range(len(adj[node])):
if adj[node][i]!=par:
if grandflip==True:
dfs(adj[node][i],node,grandParentFlip+1,parentFlip)
else:
dfs(adj[node][i],node,grandParentFlip,parentFlip+1)
def main():
par = 0
grandParentFlip = 0
parentFlip = 0
dfs(1,par,grandParentFlip,parentFlip)
print(len(flip_node))
for i in flip_node :
print(i,end="\n")
if __name__=="__main__":
sys.setrecursionlimit(10**6)
threading.stack_size(10**8)
t = threading.Thread(target=main)
t.start()
t.join()
``` | instruction | 0 | 48,296 | 19 | 96,592 |
No | output | 1 | 48,296 | 19 | 96,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node x. Right after someone has picked node x, the value of node x flips, the values of sons of x remain the same, the values of sons of sons of x flips, the values of sons of sons of sons of x remain the same and so on.
The goal of the game is to get each node i to have value goali, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
Input
The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi.
The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also contains n integer numbers, the i-th number corresponds to goali (goali is either 0 or 1).
Output
In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi.
Examples
Input
10
2 1
3 1
4 2
5 1
6 2
7 5
8 6
9 8
10 5
1 0 1 1 0 1 0 1 0 1
1 0 1 0 0 1 1 1 0 1
Output
2
4
7
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7
import threading
threading.stack_size(10**8)
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def solve():
n = int(ri())
g = [[ ] for i in range(n)]
for i in range(n-1):
a,b = Ri();a-=1;b-=1
g[a].append(b);g[b].append(a)
a= Ri();b= Ri()
cnt = [0]
ans = []
def dfs(cur, par, parf, gparf):
if a[cur]^gparf == b[cur]:
flip = 0
else:
cnt[0]+=1
ans.append(cur+1)
flip = 1
for child in g[cur]:
if child == par : continue
dfs(child, cur, gparf^flip ,parf)
dfs(0,-1, 0, 0)
print(*cnt)
for i in ans:
print(i)
threading.Thread(target= solve).start()
``` | instruction | 0 | 48,297 | 19 | 96,594 |
No | output | 1 | 48,297 | 19 | 96,595 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node x. Right after someone has picked node x, the value of node x flips, the values of sons of x remain the same, the values of sons of sons of x flips, the values of sons of sons of sons of x remain the same and so on.
The goal of the game is to get each node i to have value goali, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
Input
The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi.
The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also contains n integer numbers, the i-th number corresponds to goali (goali is either 0 or 1).
Output
In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi.
Examples
Input
10
2 1
3 1
4 2
5 1
6 2
7 5
8 6
9 8
10 5
1 0 1 1 0 1 0 1 0 1
1 0 1 0 0 1 1 1 0 1
Output
2
4
7
Submitted Solution:
```
class MyNode:
def __init__(self, tag):
self.tag = tag
self.parent = None
self.children = []
self.operations = 0
def prepare(self):
if self.grand_parent() != None:
self.operations = self.grand_parent().operations
def operate(self):
self.operations += 1
def add_child(self, node):
self.children.append(node)
def grand_parent(self):
if self.parent == None:
return None
return self.parent.parent
nodes = {}
ordered_nodes = []
n = int(input())
for i in range(1, n):
current_tag, parent_tag = (int(x) for x in input().split(' '))
if not current_tag in nodes:
nodes[current_tag] = MyNode(current_tag)
if not parent_tag in nodes:
nodes[parent_tag] = MyNode(parent_tag)
nodes[current_tag].parent = nodes[parent_tag]
nodes[parent_tag].add_child(nodes[current_tag])
ordered_nodes.append(nodes[current_tag])
initial_values = [int(x) for x in input().split(' ')]
goal_values = [int(x) for x in input().split(' ')]
initial_values.insert(0, 0)
goal_values.insert(0, 0)
operations = []
def check_and_do_operation(node):
i = node.tag
node.prepare()
if (initial_values[i] != goal_values[i] and node.operations % 2 == 0) or (initial_values[i] == goal_values[i] and node.operations % 2 == 1):
operations.append(str(i))
node.operate()
for node in ordered_nodes:
check_and_do_operation(node)
print(str(len(operations)))
print('\n'.join(operations))
``` | instruction | 0 | 48,298 | 19 | 96,596 |
No | output | 1 | 48,298 | 19 | 96,597 |
Provide a correct Python 3 solution for this coding contest problem.
You are playing a solitaire puzzle called "Connect", which uses several letter tiles.
There are R × C empty cells. For each i (1 ≤ i ≤ R), you must put a string si (1 ≤ |si| ≤ C) in the i-th row of the table, without changing the letter order. In other words, you choose an integer sequence {aj} such that 1 ≤ a1 < a2 < ... < a|si| ≤ C , and put the j-th character of the string si in the aj-th column (1 ≤ j ≤ |si|).
For example, when C = 8 and si = "ICPC", you can put si like followings.
I_C_P_C_
ICPC____
_IC___PC
'_' represents an empty cell.
For each non-empty cell x, you get a point equal to the number of adjacent cells which have the same character as x. Two cells are adjacent if they share an edge.
Calculate the maximum total point you can get.
Input
The first line contains two integers R and C (1 ≤ R ≤ 128, 1 ≤ C ≤ 16).
Then R lines follow, each of which contains si (1 ≤ |si| ≤ C). All characters of si are uppercase letters.
Output
Output the maximum total point in a line.
Examples
Input
2 4
ACM
ICPC
Output
2
Input
2 9
PROBLEMF
CONNECT
Output
6
Input
4 16
INTERNATIONAL
COLLEGIATE
PROGRAMMING
CONTEST
Output
18 | instruction | 0 | 48,769 | 19 | 97,538 |
"Correct Solution:
```
# seishin.py
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def gen(N, K):
if K == 0:
yield 0
return
v = (1 << K) - 1
N2 = (1 << N)
while v < N2:
yield v
x = v & -v; y = v + x
v = ((v & ~y) // x >> 1) | y
def solve():
R, C = map(int, readline().split())
S = [readline().strip() for i in range(R)]
C2 = (1 << C)
bc = [0]*C2
for state in range(1, C2):
bc[state] = bc[state ^ (state & -state)] + 1
LI = [None]*(C+1)
RI = [None]*(C+1)
for sl in range(C+1):
r0 = [None]*(C+1)
r1 = [None]*(C+1)
for j in range(C+1):
sr = sl - (C-j)
e0 = []
for k in range(max(sr, 0), min(sl, C)+1):
e0.extend(gen(j, k))
r0[j] = e0
r1[j] = [state << (C-j) for state in e0]
LI[sl] = r0
RI[sl] = r1
dp0 = [0]*C2; dp1 = [0]*C2
zeros = [0]*C2
s = S[0]; sl = len(s)
for j in range(1, C):
dp1[:] = zeros
b0 = (1 << (j-1))
b1 = (1 << j)
for state in LI[sl][j]:
ll = bc[state]
dp1[state] = dp0[state]
if ll < sl:
if state & b0 and s[ll-1] == s[ll]:
dp1[state | b1] = dp0[state] + 2
else:
dp1[state | b1] = dp0[state]
dp0, dp1 = dp1, dp0
for i in range(1, R):
p = S[i-1]; pl = len(p)
s = S[i]; sl = len(s)
for j in range(C):
dp1[:] = zeros
b0 = (1 << (j-1)) if j else 0
b1 = (1 << j)
L0 = LI[sl][j]; R0 = RI[pl][C-j-1]
for state1 in L0:
ll = bc[state1]
if ll < sl:
c = s[ll]
for state2 in R0:
rl = bc[state2]
state = state1 | state2
n_state = state | b1
if j < C-1:
dp1[state] = max(dp0[state], dp0[n_state]) if rl < pl else dp0[state]
r1 = max(dp0[state], (dp0[n_state] + 2 if (p[-rl-1] == c) else dp0[n_state])) if rl < pl else dp0[state]
if state & b0 and s[ll-1] == c:
dp1[n_state] = r1 + 2
else:
dp1[n_state] = r1
else:
for state2 in R0:
state = state1 | state2
if bc[state2] < pl:
dp1[state] = max(dp0[state], dp0[state | b1])
else:
dp1[state] = dp0[state]
dp0, dp1 = dp1, dp0
write("%d\n" % max(dp0))
solve()
``` | output | 1 | 48,769 | 19 | 97,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly k consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these n cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5).
The second line contains a single string of length n that only consists of 0 and 1, representing the situation of these n cards, where the color side of the i-th card faces up if the i-th character is 1, or otherwise, it faces down and the i-th character is 0.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 10^9, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again
Note
In the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.
In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.
In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.
The fourth example can be explained in the same way as the second example does. | instruction | 0 | 48,907 | 19 | 97,814 |
Tags: brute force, games, greedy
Correct Solution:
```
from sys import stdin, stdout, exit
n,k = map(int, stdin.readline().split())
s = stdin.readline().strip()
def z(winner):
return 'tokitsukaze' if winner == 0 else 'quailty'
ones = [i for i in range(n) if s[i] == '1']
zeros = [i for i in range(n) if s[i] == '0']
if not ones or not zeros:
print(z(0))
exit()
if max(ones) - min(ones)+1 <= k or max(zeros) - min(zeros)+1 <= k:
print(z(0))
exit()
if max(ones) - min(ones)+1 >= k+2 or max(zeros) - min(zeros)+1 >= k+2:
print("once again")
exit()
if n == 2*(k+1):
print("once again")
exit()
print(z(1))
``` | output | 1 | 48,907 | 19 | 97,815 |
Provide tags and a correct Python 3 solution for this coding contest problem.
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly k consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these n cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5).
The second line contains a single string of length n that only consists of 0 and 1, representing the situation of these n cards, where the color side of the i-th card faces up if the i-th character is 1, or otherwise, it faces down and the i-th character is 0.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 10^9, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again
Note
In the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.
In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.
In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.
The fourth example can be explained in the same way as the second example does. | instruction | 0 | 48,908 | 19 | 97,816 |
Tags: brute force, games, greedy
Correct Solution:
```
#!/usr/bin/env python3
def win1():
if n==k or r[k+1]==n or l[n-k]==1:
return True
for i in range(2,n-k+1):
if l[i-1]==1 and r[i+k]==n and a[i-1]==a[i+k]:
return True
return False
def win2():
if 2*k<n:
return False
for i in range(2,n-k+1):
if l[i-1]!=1 or r[i+k]!=n:
return False
return True
if __name__ == "__main__":
s=input().split()
n,k=int(s[0]),int(s[1])
s=input().split()
a=[0]
l=[0 for i in range(n+1)]
r=[0 for i in range(n+1)]
for c in s[0]:
a.append(int(c))
l[1],r[n]=1,n
for i in range(2,n+1):
if a[i-1]==a[i]:
l[i]=l[i-1]
else:
l[i]=i
if a[n-i+1]==a[n-i+2]:
r[n-i+1]=r[n-i+2]
else:
r[n-i+1]=n-i+1
# print(l,r)
if win1():
print("tokitsukaze")
elif win2():
print("quailty")
else:
print("once again")
``` | output | 1 | 48,908 | 19 | 97,817 |
Provide tags and a correct Python 3 solution for this coding contest problem.
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly k consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these n cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5).
The second line contains a single string of length n that only consists of 0 and 1, representing the situation of these n cards, where the color side of the i-th card faces up if the i-th character is 1, or otherwise, it faces down and the i-th character is 0.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 10^9, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again
Note
In the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.
In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.
In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.
The fourth example can be explained in the same way as the second example does. | instruction | 0 | 48,909 | 19 | 97,818 |
Tags: brute force, games, greedy
Correct Solution:
```
from collections import defaultdict
import sys
input = sys.stdin.readline
'''
for CASES in range(int(input())):
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
sys.stdout.write()
'''
inf = 100000000000000000 # 1e17
mod = 998244353
n, m = map(int, input().split())
S = input().strip()
SUM0 = [0] * (n + 3)
SUM1 = [0] * (n + 3)
for i in range(len(S)):
SUM1[i + 1] = SUM1[i]
if S[i] == '1':
SUM1[i + 1] += 1
SUM0[i + 1] = SUM0[i]
if S[i] == '0':
SUM0[i + 1] += 1
for i in range(1, n + 1):
if i + m - 1 > n:
break
l = i
r = i + m - 1
if SUM1[l - 1] == SUM1[n] - SUM1[r] == 0 or SUM0[l - 1] == SUM0[n] - SUM0[r] == 0:
print("tokitsukaze")
sys.exit()
if 2 * m < n or m == 1:
print("once again")
sys.exit()
flag = 0
for i in range(2, n + 1):
if i + m - 1 > n-1:
break
l = i
r = i + m - 1
if ((SUM1[l - 1] == 0 and SUM0[n] - SUM0[r] == 0) or \
(SUM0[l - 1] == 0 and SUM1[n] - SUM1[r] == 0))==False:
flag = 1
if flag == 0:
print("quailty")
sys.exit()
print("once again")
# the end
``` | output | 1 | 48,909 | 19 | 97,819 |
Provide tags and a correct Python 3 solution for this coding contest problem.
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly k consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these n cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5).
The second line contains a single string of length n that only consists of 0 and 1, representing the situation of these n cards, where the color side of the i-th card faces up if the i-th character is 1, or otherwise, it faces down and the i-th character is 0.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 10^9, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again
Note
In the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.
In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.
In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.
The fourth example can be explained in the same way as the second example does. | instruction | 0 | 48,910 | 19 | 97,820 |
Tags: brute force, games, greedy
Correct Solution:
```
import sys
def Check():
for j in [0,1]:
if R[j][1] + L[j][n] + k >= n:
return 1
return 0
n,k = [int(i) for i in input().split()]
S = [int(i) for i in input()]
R = [[0]*(n+2),[0]*(n+2)]
L = [[0]*(n+2),[0]*(n+2)]
for j in [0,1]:
for i in range(n):
if S[i]==j:
L[j][i+1] = L[j][i]+1
for j in [0,1]:
for i in range(n-1,-1,-1):
if S[i]==j:
R[j][i+1] = R[j][i+2]+1
if Check():
print("tokitsukaze")
sys.exit(0)
for j in [0,1]:
for r in range(k,n+1):
l = r-k+1
t = [R[j][1],L[j][n],R[j^1][1],L[j^1][n]]
if R[j][1] >= l-1:
R[j][1] = r+R[j][r+1]
if L[j][n] >= n-r:
L[j][n] = n-l+1+L[j][l-1]
if R[j^1][1] > l-1:
R[j^1][1] = l-1
if L[j^1][n] > n-r:
L[j^1][n] = n-r
if not Check():
print("once again")
sys.exit(0)
R[j][1],L[j][n],R[j^1][1],L[j^1][n] = t
print("quailty")
``` | output | 1 | 48,910 | 19 | 97,821 |
Provide tags and a correct Python 3 solution for this coding contest problem.
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly k consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these n cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5).
The second line contains a single string of length n that only consists of 0 and 1, representing the situation of these n cards, where the color side of the i-th card faces up if the i-th character is 1, or otherwise, it faces down and the i-th character is 0.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 10^9, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again
Note
In the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.
In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.
In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.
The fourth example can be explained in the same way as the second example does. | instruction | 0 | 48,911 | 19 | 97,822 |
Tags: brute force, games, greedy
Correct Solution:
```
import sys
import copy
input = sys.stdin.readline
n,k=map(int,input().split())
C=list(input().strip())
def JUDGE(C):
ANS_one=0
ANS_zero=0
for c in C:
if c=="0":
ANS_zero+=1
else:
break
for c in C[::-1]:
if c=="0":
ANS_zero+=1
else:
break
for c in C:
if c=="1":
ANS_one+=1
else:
break
for c in C[::-1]:
if c=="1":
ANS_one+=1
else:
break
if ANS_zero>=n-k or ANS_one>=n-k:
return 1
else:
return 0
if JUDGE(C)==1:
print("tokitsukaze")
sys.exit()
if k>=n-1:
print("quailty")
sys.exit()
if k<n/2:
print("once again")
sys.exit()
CAN1=copy.copy(C)
CAN2=copy.copy(C)
if C[0]=="0":
for i in range(1,k+1):
CAN1[i]="1"
else:
for i in range(1,k+1):
CAN1[i]="0"
if C[-1]=="0":
for i in range(n-1,n-k-1,-1):
CAN2[i]="1"
else:
for i in range(n-2,n-k-2,-1):
CAN2[i]="0"
if JUDGE(CAN1)==1 and JUDGE(CAN2)==1:
print("quailty")
sys.exit()
else:
print("once again")
sys.exit()
``` | output | 1 | 48,911 | 19 | 97,823 |
Provide tags and a correct Python 3 solution for this coding contest problem.
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly k consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these n cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5).
The second line contains a single string of length n that only consists of 0 and 1, representing the situation of these n cards, where the color side of the i-th card faces up if the i-th character is 1, or otherwise, it faces down and the i-th character is 0.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 10^9, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again
Note
In the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.
In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.
In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.
The fourth example can be explained in the same way as the second example does. | instruction | 0 | 48,912 | 19 | 97,824 |
Tags: brute force, games, greedy
Correct Solution:
```
n, k = map(int, input().strip().split())
t = input().strip()
l1 = t.rfind('1') - t.find('1') + 1
l2 = t.rfind('0') - t.find('0') + 1
if l1 <= k or l2 <= k:
print('tokitsukaze')
elif k < n // 2 or l1 > k + 1 or l2 > k + 1:
print('once again')
else:
print('quailty')
``` | output | 1 | 48,912 | 19 | 97,825 |
Provide tags and a correct Python 3 solution for this coding contest problem.
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly k consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these n cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5).
The second line contains a single string of length n that only consists of 0 and 1, representing the situation of these n cards, where the color side of the i-th card faces up if the i-th character is 1, or otherwise, it faces down and the i-th character is 0.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 10^9, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again
Note
In the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.
In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.
In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.
The fourth example can be explained in the same way as the second example does. | instruction | 0 | 48,913 | 19 | 97,826 |
Tags: brute force, games, greedy
Correct Solution:
```
import sys
def Check():
for j in [0,1]:
if R[j][1] + L[j][n] + k >= n:
return 1
return 0
n,k = [int(i) for i in input().split()]
S = [int(i) for i in input()]
R = [[0]*(n+2),[0]*(n+2)]
L = [[0]*(n+2),[0]*(n+2)]
for j in [0,1]:
L[S[0]][1] = 1
for i in range(1,n):
if S[i]==j:
L[j][i+1] = L[j][i]+1
for j in [0,1]:
R[S[n-1]][n] = 1
for i in range(n-2,-1,-1):
if S[i]==j:
R[j][i+1] = R[j][i+2]+1
if Check():
print("tokitsukaze")
sys.exit(0)
for j in [0,1]:
for r in range(k,n+1):
l = r-k+1
t = [R[j][1],L[j][n],R[j^1][1],L[j^1][n]]
if R[j][1] >= l-1:
R[j][1] = r+R[j][r+1]
if L[j][n] >= n-r:
L[j][n] = n-l+1+L[j][l-1]
if R[j^1][1] > l-1:
R[j^1][1] = l-1
if L[j^1][n] > n-r:
L[j^1][n] = n-r
if not Check():
print("once again")
sys.exit(0)
R[j][1],L[j][n],R[j^1][1],L[j^1][n] = t
print("quailty")
``` | output | 1 | 48,913 | 19 | 97,827 |
Provide tags and a correct Python 3 solution for this coding contest problem.
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly k consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these n cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5).
The second line contains a single string of length n that only consists of 0 and 1, representing the situation of these n cards, where the color side of the i-th card faces up if the i-th character is 1, or otherwise, it faces down and the i-th character is 0.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 10^9, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again
Note
In the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.
In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.
In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.
The fourth example can be explained in the same way as the second example does. | instruction | 0 | 48,914 | 19 | 97,828 |
Tags: brute force, games, greedy
Correct Solution:
```
import sys
import math
import bisect
from collections import deque
sys.setrecursionlimit(1000000000)
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def finput():
return float(input())
def tinput():
return input().split()
def rinput():
return map(int, tinput())
def rlinput():
return list(rinput())
def modst(a, s):
res = 1
while s:
if s % 2:
res *= a
a *= a
s //= 2
return res
def main():
n, k = rinput()
s = input()
q = -1
w = -1
e = -1
r = -1
for i in range(n):
if(s[i] == '0'):
if(q == -1):
q = i
w = i
else:
if(e == -1):
e = i
r = i
z = w - q
x = r - e
if(min(z, x) < k):
return ('tokitsukaze')
if(z > k or x > k):
return ('once again')
c = 0
v = 0
for i in range(n):
if(s[i] == '0'):
v += 1
c = 0
else:
c += 1
v = 0
if(c >= k or v >= k):
return ('once again')
return ('quailty')
for i in range(1):
print(main())
``` | output | 1 | 48,914 | 19 | 97,829 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly k consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these n cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5).
The second line contains a single string of length n that only consists of 0 and 1, representing the situation of these n cards, where the color side of the i-th card faces up if the i-th character is 1, or otherwise, it faces down and the i-th character is 0.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 10^9, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again
Note
In the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.
In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.
In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.
The fourth example can be explained in the same way as the second example does.
Submitted Solution:
```
n, k = map(int,input().split())
s= input()
fir0 = -1
last0 = -1
fir1 = -1
last1 = -1
for i in range(n):
if(s[i] == '0'):
if(fir0 == -1):
fir0 = i
last0 = i
else:
if(fir1 == -1):
fir1 = i
last1 = i
d0 = last0 - fir0
d1 = last1 - fir1
if(min(d0, d1) < k):
print('tokitsukaze')
elif(d0 > k or d1 > k):
print('once again')
else:
cnt1 = 0
cnt0 = 0
for i in range(n):
if(s[i] == '0'):
cnt0 += 1
cnt1 = 0
else:
cnt1 += 1
cnt0 = 0
if(cnt1 >= k or cnt0 >= k):
print('once again')
exit()
print('quailty')
``` | instruction | 0 | 48,915 | 19 | 97,830 |
Yes | output | 1 | 48,915 | 19 | 97,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly k consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these n cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5).
The second line contains a single string of length n that only consists of 0 and 1, representing the situation of these n cards, where the color side of the i-th card faces up if the i-th character is 1, or otherwise, it faces down and the i-th character is 0.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 10^9, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again
Note
In the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.
In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.
In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.
The fourth example can be explained in the same way as the second example does.
Submitted Solution:
```
n, k = map(int, input().split())
a = input()
A = 0
for i in range(n):
A += int(a[i])
s=0
c=0
W=False
L=False
D=False
for i in range(n):
s += int(a[i])
if i >= k:
s -= int(a[i-k])
c += int(a[i-k])
if i >= k-1:
if s == A:
W = True
elif A - s + k == n:
W = True
elif c > 0 and A - s - c>0:
D = True
elif c == 0 and i >= k and i < n-1 and c == 0 and A -s -c == 0:
D = True
if W:
print('tokitsukaze')
elif D or k * 2 < n:
print('once again')
else:
print('quailty')
``` | instruction | 0 | 48,916 | 19 | 97,832 |
Yes | output | 1 | 48,916 | 19 | 97,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are n cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly k consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these n cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5).
The second line contains a single string of length n that only consists of 0 and 1, representing the situation of these n cards, where the color side of the i-th card faces up if the i-th character is 1, or otherwise, it faces down and the i-th character is 0.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 10^9, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again
Note
In the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.
In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.
In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.
The fourth example can be explained in the same way as the second example does.
Submitted Solution:
```
n, k = map(int,input().split())
s = input()
def func(s):
num = 1
num2 = 1
for i in range(1,n):
if s[i] != s[i-1]:
break
num += 1
for i in range(n-1,0,-1):
if s[i] != s[i-1]:
break
num2 += 1
if k + num >= n or k + num2 >= n:
return 0
elif s[-1] == s[0] and k + num + num2 >= n:
return 0
else:
return 1
if func(s) == 0:
print("tokitsukaze")
else:
s2 = list(s)
nums = [0] * 8
s3 = list(s)
for i in range(k):
s3[i] = '1'
s4= list(s)
for i in range(k):
s4[i] = '0'
s5 = list(s)
for i in range(n-1,n-k-1,-1):
s5[i] = '1'
s6 = list(s)
for i in range(n-1,n-k-1,-1):
s6[i] = '0'
s7 = list(s)
for i in range(1,k+1):
s7[i] = '1'
s8 = list(s)
for i in range(1,k+1):
s8[i] = '0'
s9 = list(s)
for i in range(n-2,n-k-2,-1):
s9[i] = '1'
s10 = list(s)
for i in range(n-2,n-k-2,-1):
s10[i] = '0'
nums[0] = func(s3)
nums[1] = func(s4)
nums[2] = func(s5)
nums[3] = func(s6)
nums[4] = func(s7)
nums[5] = func(s8)
nums[6] = func(s9)
nums[7] = func(s10)
if sum(nums) != 0:
print("once again")
else:
print("quailty")
``` | instruction | 0 | 48,917 | 19 | 97,834 |
Yes | output | 1 | 48,917 | 19 | 97,835 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.