message stringlengths 2 39.6k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 219 108k | cluster float64 11 11 | __index_level_0__ int64 438 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were just stains of ink.
His headache came from the ``creativity'' of his students. They provided him a variety of ways to answer each problem. He has his own answer to each problem, which is correct, of course, and the best from his aesthetic point of view.
Some of his students wrote algebraic expressions equivalent to the expected answer, but many of them look quite different from Mr. Simpson's answer in terms of their literal forms. Some wrote algebraic expressions not equivalent to his answer, but they look quite similar to it. Only a few of the students' answers were exactly the same as his.
It is his duty to check if each expression is mathematically equivalent to the answer he has prepared. This is to prevent expressions that are equivalent to his from being marked as ``incorrect'', even if they are not acceptable to his aesthetic moral.
He had now spent five days checking the expressions. Suddenly, he stood up and yelled, ``I've had enough! I must call for help.''
Your job is to write a program to help Mr. Simpson to judge if each answer is equivalent to the ``correct'' one. Algebraic expressions written on the papers are multi-variable polynomials over variable symbols a, b,..., z with integer coefficients, e.g., (a + b2)(a - b2), ax2 +2bx + c and (x2 +5x + 4)(x2 + 5x + 6) + 1.
Mr. Simpson will input every answer expression as it is written on the papers; he promises you that an algebraic expression he inputs is a sequence of terms separated by additive operators `+' and `-', representing the sum of the terms with those operators, if any; a term is a juxtaposition of multiplicands, representing their product; and a multiplicand is either (a) a non-negative integer as a digit sequence in decimal, (b) a variable symbol (one of the lowercase letters `a' to `z'), possibly followed by a symbol `^' and a non-zero digit, which represents the power of that variable, or (c) a parenthesized algebraic expression, recursively. Note that the operator `+' or `-' appears only as a binary operator and not as a unary operator to specify the sing of its operand.
He says that he will put one or more space characters before an integer if it immediately follows another integer or a digit following the symbol `^'. He also says he may put spaces here and there in an expression as an attempt to make it readable, but he will never put a space between two consecutive digits of an integer. He remarks that the expressions are not so complicated, and that any expression, having its `-'s replaced with `+'s, if any, would have no variable raised to its 10th power, nor coefficient more than a billion, even if it is fully expanded into a form of a sum of products of coefficients and powered variables.
Input
The input to your program is a sequence of blocks of lines. A block consists of lines, each containing an expression, and a terminating line. After the last block, there is another terminating line. A terminating line is a line solely consisting of a period symbol.
The first expression of a block is one prepared by Mr. Simpson; all that follow in a block are answers by the students. An expression consists of lowercase letters, digits, operators `+', `-' and `^', parentheses `(' and `)', and spaces. A line containing an expression has no more than 80 characters.
Output
Your program should produce a line solely consisting of ``yes'' or ``no'' for each answer by the students corresponding to whether or not it is mathematically equivalent to the expected answer. Your program should produce a line solely containing a period symbol after each block.
Example
Input
a+b+c
(a+b)+c
a- (b-c)+2
.
4ab
(a - b) (0-b+a) - 1a ^ 2 - b ^ 2
2 b 2 a
.
108 a
2 2 3 3 3 a
4 a^1 27
.
.
Output
yes
no
.
no
yes
.
yes
yes
. | instruction | 0 | 28,209 | 11 | 56,418 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
from string import digits
def convert(S):
S = S + "$"
cur = 0
def expr():
nonlocal cur
res = []
op = '+'
while 1:
r = fact()
if op == '-':
for e in r:
e[0] *= -1
res.extend(r)
if S[cur] not in '+-':
break
op = S[cur]
cur += 1 # '+' or '-'
r = []
for e0 in res:
k0, es0 = e0
for e1 in r:
k1, es1 = e1
if es0 == es1:
e1[0] += k0
break
else:
r.append(e0)
res = list(filter(lambda x: x[0] != 0, r))
res.sort()
return res
def fact():
nonlocal cur
res = [[1, []]]
while 1:
r = idt()
r0 = []
for v0, es0 in res:
for v1, es1 in r:
d = {}
for k, v in es0:
d[k] = d.get(k, 0) + v
for k, v in es1:
d[k] = d.get(k, 0) + v
*es, = d.items()
es.sort()
r0.append([v0*v1, es])
res = r0
while S[cur] == ' ':
cur += 1 # ' '
if S[cur] in '+-$)':
break
return res
def idt():
nonlocal cur
while S[cur] == ' ':
cur += 1 # ' '
if S[cur] == '(':
cur += 1 # '('
r = expr()
cur += 1 # ')'
elif S[cur] in digits:
v = number()
r = [[v, []]]
else:
c = S[cur]
cur += 1 # 'a' ~ 'z'
while S[cur] == ' ':
cur += 1 # ' '
if S[cur] == '^':
cur += 1 # '^'
while S[cur] == ' ':
cur += 1 # ' '
v = number()
else:
v = 1
r = [[1, [(c, v)]]]
return r
def number():
nonlocal cur
v = 0
while 1:
c = S[cur]
if c not in digits:
break
v = 10*v + int(c)
cur += 1 # '0' ~ '9'
return v
res = expr()
return res
def solve():
s0 = readline().strip()
if s0 == '.':
return False
d0 = convert(s0)
while 1:
s = readline().strip()
if s == '.':
break
d = convert(s)
write("yes\n" if d0 == d else "no\n")
write(".\n")
return True
while solve():
...
``` | output | 1 | 28,209 | 11 | 56,419 |
Provide a correct Python 3 solution for this coding contest problem.
Example
Input
acmicpc
tsukuba
Output
No | instruction | 0 | 28,214 | 11 | 56,428 |
"Correct Solution:
```
def judge(s):
if len(s) == 0: return True
si = 0
for t in T:
if t == s[si]:
si += 1
if si == len(s): return True
return False
S,T = input(),input()
N = len(S)
print('Yes' if judge(S[::2]) or judge(S[1::2]) else 'No')
``` | output | 1 | 28,214 | 11 | 56,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Example
Input
acmicpc
tsukuba
Output
No
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
s = S()
t = S()
def f(s):
return '.*'.join(['']+[c for c in s]+[''])
if re.match(f(s[0::2]), t) or re.match(f(s[1::2]), t):
rr.append('Yes')
else:
rr.append('No')
break
return '\n'.join(map(str, rr))
print(main())
``` | instruction | 0 | 28,217 | 11 | 56,434 |
No | output | 1 | 28,217 | 11 | 56,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Example
Input
acmicpc
tsukuba
Output
No
Submitted Solution:
```
def judge(s):
si = 0
for t in T:
if t == s[si]:
si += 1
if si == len(s): return True
return False
S,T = input(),input()
N = len(S)
print('Yes' if judge(S[::2]) or judge(S[1::2]) else 'No')
``` | instruction | 0 | 28,218 | 11 | 56,436 |
No | output | 1 | 28,218 | 11 | 56,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place:
* A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars.
* Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it.
Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally.
Input
The first input line contains number n (1 β€ n β€ 5000) β amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 β€ x β€ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 β€ x β€ 2000).
Output
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
Examples
Input
7
win 10
win 5
win 3
sell 5
sell 3
win 10
sell 10
Output
1056
Input
3
win 5
sell 6
sell 4
Output
0
Submitted Solution:
```
a = [-1] * 2002
a[0] = 0
for i in range(int(input())):
s, t= input().split()
t = int(t) + 1
#t = int(input())
if(s[0] == 'w'):
a[t] = a[0]
elif a[t] >= 0:
a[0] = max(a[0], a[t] + (1<<(t-1)))
print(a[0])
``` | instruction | 0 | 28,547 | 11 | 57,094 |
Yes | output | 1 | 28,547 | 11 | 57,095 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place:
* A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars.
* Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it.
Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally.
Input
The first input line contains number n (1 β€ n β€ 5000) β amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 β€ x β€ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 β€ x β€ 2000).
Output
Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.
Examples
Input
7
win 10
win 5
win 3
sell 5
sell 3
win 10
sell 10
Output
1056
Input
3
win 5
sell 6
sell 4
Output
0
Submitted Solution:
```
dp = [-1] * 2005
ans = 0
t = int(input())
now = 0
maxx = 0
for i in range(1, t + 1):
a, b = input().split(' ')
x = int(b)
if a == "win":
dp[x] = max(dp[x], maxx)
else:
if dp[x] != -1:
dp[2001] = max(dp[2001], dp[x] + pow(2, x))
maxx = max(maxx, dp[2001])
ans = 0
for i in range(2005):
ans = max(dp[i], ans)
print(ans)
``` | instruction | 0 | 28,549 | 11 | 57,098 |
Yes | output | 1 | 28,549 | 11 | 57,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.
Help guys determine the winner photo by the records of likes.
Input
The first line of the input contains a single integer n (1 β€ n β€ 1000) β the total likes to the published photoes.
The second line contains n positive integers a1, a2, ..., an (1 β€ ai β€ 1 000 000), where ai is the identifier of the photo which got the i-th like.
Output
Print the identifier of the photo which won the elections.
Examples
Input
5
1 3 2 2 1
Output
2
Input
9
100 200 300 200 100 300 300 100 200
Output
300
Note
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
* more likes than the photo with id 3;
* as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.
Submitted Solution:
```
n = int(input())
foto = [int(i) for i in input().split()]
rat = {}
max_like = [0, 0]
for i in foto:
if rat.get(i):
rat[i] += 1
else:
rat.update({i: 1})
if rat[i] > max_like[0]:
max_like[0] = rat[i]
max_like[1] = i
print(max_like[1])
``` | instruction | 0 | 28,684 | 11 | 57,368 |
Yes | output | 1 | 28,684 | 11 | 57,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.
Help guys determine the winner photo by the records of likes.
Input
The first line of the input contains a single integer n (1 β€ n β€ 1000) β the total likes to the published photoes.
The second line contains n positive integers a1, a2, ..., an (1 β€ ai β€ 1 000 000), where ai is the identifier of the photo which got the i-th like.
Output
Print the identifier of the photo which won the elections.
Examples
Input
5
1 3 2 2 1
Output
2
Input
9
100 200 300 200 100 300 300 100 200
Output
300
Note
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
* more likes than the photo with id 3;
* as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.
Submitted Solution:
```
n = int(input())
data = [int(i) for i in input().split()]
dct = {}
keys = []
mx = 0
ret = 0
for box in data:
if box in keys:
dct[box] += 1
else:
dct[box] = 1
keys.append(box)
if dct[box] > mx:
mx = dct[box]
ret = box
print(ret)
``` | instruction | 0 | 28,685 | 11 | 57,370 |
Yes | output | 1 | 28,685 | 11 | 57,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.
Help guys determine the winner photo by the records of likes.
Input
The first line of the input contains a single integer n (1 β€ n β€ 1000) β the total likes to the published photoes.
The second line contains n positive integers a1, a2, ..., an (1 β€ ai β€ 1 000 000), where ai is the identifier of the photo which got the i-th like.
Output
Print the identifier of the photo which won the elections.
Examples
Input
5
1 3 2 2 1
Output
2
Input
9
100 200 300 200 100 300 300 100 200
Output
300
Note
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
* more likes than the photo with id 3;
* as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
d = dict()
d[0] = 0
mx = 0
for i in a:
d[i] = d.get(i, 0) + 1
if d[i] > d[mx]:
mx = i
print(mx)
``` | instruction | 0 | 28,686 | 11 | 57,372 |
Yes | output | 1 | 28,686 | 11 | 57,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.
Help guys determine the winner photo by the records of likes.
Input
The first line of the input contains a single integer n (1 β€ n β€ 1000) β the total likes to the published photoes.
The second line contains n positive integers a1, a2, ..., an (1 β€ ai β€ 1 000 000), where ai is the identifier of the photo which got the i-th like.
Output
Print the identifier of the photo which won the elections.
Examples
Input
5
1 3 2 2 1
Output
2
Input
9
100 200 300 200 100 300 300 100 200
Output
300
Note
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
* more likes than the photo with id 3;
* as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
ma=0
d={}
indx=-1
for i in range(n) :
v=d.get(l[i],0)+1
if ma<v :
ma=v
indx=l[i]
d[l[i]]=v
print(indx)
``` | instruction | 0 | 28,687 | 11 | 57,374 |
Yes | output | 1 | 28,687 | 11 | 57,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.
Help guys determine the winner photo by the records of likes.
Input
The first line of the input contains a single integer n (1 β€ n β€ 1000) β the total likes to the published photoes.
The second line contains n positive integers a1, a2, ..., an (1 β€ ai β€ 1 000 000), where ai is the identifier of the photo which got the i-th like.
Output
Print the identifier of the photo which won the elections.
Examples
Input
5
1 3 2 2 1
Output
2
Input
9
100 200 300 200 100 300 300 100 200
Output
300
Note
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
* more likes than the photo with id 3;
* as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.
Submitted Solution:
```
n = int(input())
likes = input().split()
likes = [int(x) for x in likes]
max = 0
x = []
for i in likes:
if i not in x:
x.append(i)
if likes.count(i) > max:
max = likes.count(i)
print(max)
``` | instruction | 0 | 28,688 | 11 | 57,376 |
No | output | 1 | 28,688 | 11 | 57,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.
Help guys determine the winner photo by the records of likes.
Input
The first line of the input contains a single integer n (1 β€ n β€ 1000) β the total likes to the published photoes.
The second line contains n positive integers a1, a2, ..., an (1 β€ ai β€ 1 000 000), where ai is the identifier of the photo which got the i-th like.
Output
Print the identifier of the photo which won the elections.
Examples
Input
5
1 3 2 2 1
Output
2
Input
9
100 200 300 200 100 300 300 100 200
Output
300
Note
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
* more likes than the photo with id 3;
* as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.
Submitted Solution:
```
import sys
lines = sys.stdin.readlines()
array_of_images_ids = lines[1].split(' ') # str array
dict_of_likes = {}
for i in set(array_of_images_ids):
dict_of_likes[i] = array_of_images_ids.count(i)
supposed_id = str(max(dict_of_likes.keys(), key=(lambda key: int(dict_of_likes[key]))))
max_number = int(dict_of_likes[supposed_id])
supposed_ids = [supposed_id]
for key in dict_of_likes.keys():
if int(dict_of_likes[key]) == max_number and supposed_id != key:
supposed_ids.append(key)
has_run = False
position = 1
for item in supposed_ids:
if not has_run:
position = array_of_images_ids.index(item)
has_run = True
continue
p = array_of_images_ids.index(item)
if p < position:
position = p
print(array_of_images_ids[position])
``` | instruction | 0 | 28,689 | 11 | 57,378 |
No | output | 1 | 28,689 | 11 | 57,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.
Help guys determine the winner photo by the records of likes.
Input
The first line of the input contains a single integer n (1 β€ n β€ 1000) β the total likes to the published photoes.
The second line contains n positive integers a1, a2, ..., an (1 β€ ai β€ 1 000 000), where ai is the identifier of the photo which got the i-th like.
Output
Print the identifier of the photo which won the elections.
Examples
Input
5
1 3 2 2 1
Output
2
Input
9
100 200 300 200 100 300 300 100 200
Output
300
Note
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
* more likes than the photo with id 3;
* as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.
Submitted Solution:
```
import sys
lines = sys.stdin.readlines()
array_of_images_ids = lines[1].split(' ') # str array
reversed_array_of_images_ids = array_of_images_ids[::-1]
dict_of_likes = {}
for i in set(array_of_images_ids):
dict_of_likes[i] = array_of_images_ids.count(i)
supposed_id = str(max(dict_of_likes.keys(), key=(lambda key: int(dict_of_likes[key]))))
max_number = int(dict_of_likes[supposed_id])
supposed_ids = [supposed_id]
for key in dict_of_likes.keys():
if int(dict_of_likes[key]) == max_number and supposed_id != key:
supposed_ids.append(key)
has_run = False
position = 1
array_len = len(array_of_images_ids)
for item in supposed_ids:
if not has_run:
position = array_len - reversed_array_of_images_ids.index(item) - 1
has_run = True
continue
p = array_len - reversed_array_of_images_ids.index(item) - 1
if p < position:
position = p
print(array_of_images_ids[position])
``` | instruction | 0 | 28,690 | 11 | 57,380 |
No | output | 1 | 28,690 | 11 | 57,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.
Help guys determine the winner photo by the records of likes.
Input
The first line of the input contains a single integer n (1 β€ n β€ 1000) β the total likes to the published photoes.
The second line contains n positive integers a1, a2, ..., an (1 β€ ai β€ 1 000 000), where ai is the identifier of the photo which got the i-th like.
Output
Print the identifier of the photo which won the elections.
Examples
Input
5
1 3 2 2 1
Output
2
Input
9
100 200 300 200 100 300 300 100 200
Output
300
Note
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
* more likes than the photo with id 3;
* as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.
Submitted Solution:
```
n = int(input())
lis = list(map(int, input().split()))
dic = {}
val = -999999999999999999999
ans = 0
for i in lis:
if i in dic:
dic[i]+=1
if dic[i]>val:
ans=i
val = dic[i]
else:
dic[i]=1
print(ans)
``` | instruction | 0 | 28,691 | 11 | 57,382 |
No | output | 1 | 28,691 | 11 | 57,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) β who knows?
Every one of them has an integer sequences a and b of length n. Being given a query of the form of pair of integers (l, r), Mike can instantly tell the value of <image> while !Mike can instantly tell the value of <image>.
Now suppose a robot (you!) asks them all possible different queries of pairs of integers (l, r) (1 β€ l β€ r β€ n) (so he will make exactly n(n + 1) / 2 queries) and counts how many times their answers coincide, thus for how many pairs <image> is satisfied.
How many occasions will the robot count?
Input
The first line contains only integer n (1 β€ n β€ 200 000).
The second line contains n integer numbers a1, a2, ..., an ( - 109 β€ ai β€ 109) β the sequence a.
The third line contains n integer numbers b1, b2, ..., bn ( - 109 β€ bi β€ 109) β the sequence b.
Output
Print the only integer number β the number of occasions the robot will count, thus for how many pairs <image> is satisfied.
Examples
Input
6
1 2 3 2 1 4
6 7 1 2 3 2
Output
2
Input
3
3 3 3
1 1 1
Output
0
Note
The occasions in the first sample case are:
1.l = 4,r = 4 since max{2} = min{2}.
2.l = 4,r = 5 since max{2, 1} = min{2, 3}.
There are no occasions in the second sample case since Mike will answer 3 to any query pair, but !Mike will always answer 1.
Submitted Solution:
```
def solve():
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
maxi=a[0]
mini=b[0]
count=0
if maxi==mini:
count+=1
flag=0
for i in range(1,n):
#print(mini,maxi,a[i])
if a[i]==b[i]:
count+=1
#print(maxi)
if a[i]<maxi and maxi>mini:
maxi=a[i]
mini=b[i]
if a[i]>maxi:
maxi=a[i]
if b[i]<mini :
#print(mini,maxi)
mini=b[i]
if maxi==mini and a[i]!=b[i]:
count+=1
print(count)
solve()
``` | instruction | 0 | 28,709 | 11 | 57,418 |
No | output | 1 | 28,709 | 11 | 57,419 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) β who knows?
Every one of them has an integer sequences a and b of length n. Being given a query of the form of pair of integers (l, r), Mike can instantly tell the value of <image> while !Mike can instantly tell the value of <image>.
Now suppose a robot (you!) asks them all possible different queries of pairs of integers (l, r) (1 β€ l β€ r β€ n) (so he will make exactly n(n + 1) / 2 queries) and counts how many times their answers coincide, thus for how many pairs <image> is satisfied.
How many occasions will the robot count?
Input
The first line contains only integer n (1 β€ n β€ 200 000).
The second line contains n integer numbers a1, a2, ..., an ( - 109 β€ ai β€ 109) β the sequence a.
The third line contains n integer numbers b1, b2, ..., bn ( - 109 β€ bi β€ 109) β the sequence b.
Output
Print the only integer number β the number of occasions the robot will count, thus for how many pairs <image> is satisfied.
Examples
Input
6
1 2 3 2 1 4
6 7 1 2 3 2
Output
2
Input
3
3 3 3
1 1 1
Output
0
Note
The occasions in the first sample case are:
1.l = 4,r = 4 since max{2} = min{2}.
2.l = 4,r = 5 since max{2, 1} = min{2, 3}.
There are no occasions in the second sample case since Mike will answer 3 to any query pair, but !Mike will always answer 1.
Submitted Solution:
```
def solve():
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
maxi=a[0]
mini=b[0]
count=0
if maxi==mini:
count+=1
flag=0
for i in range(1,n):
#print(mini,maxi,a[i])
if a[i]==b[i]:
count+=1
maxi=a[i]
mini=b[i]
#print(maxi)
if a[i]<maxi and maxi>mini:
maxi=a[i]
mini=b[i]
if a[i]>maxi:
maxi=a[i]
if b[i]<mini :
#print(mini,maxi)
mini=b[i]
if maxi==mini and a[i]!=b[i]:
count+=1
if count==19:
print("22")
else:
print(count)
solve()
``` | instruction | 0 | 28,710 | 11 | 57,420 |
No | output | 1 | 28,710 | 11 | 57,421 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) β who knows?
Every one of them has an integer sequences a and b of length n. Being given a query of the form of pair of integers (l, r), Mike can instantly tell the value of <image> while !Mike can instantly tell the value of <image>.
Now suppose a robot (you!) asks them all possible different queries of pairs of integers (l, r) (1 β€ l β€ r β€ n) (so he will make exactly n(n + 1) / 2 queries) and counts how many times their answers coincide, thus for how many pairs <image> is satisfied.
How many occasions will the robot count?
Input
The first line contains only integer n (1 β€ n β€ 200 000).
The second line contains n integer numbers a1, a2, ..., an ( - 109 β€ ai β€ 109) β the sequence a.
The third line contains n integer numbers b1, b2, ..., bn ( - 109 β€ bi β€ 109) β the sequence b.
Output
Print the only integer number β the number of occasions the robot will count, thus for how many pairs <image> is satisfied.
Examples
Input
6
1 2 3 2 1 4
6 7 1 2 3 2
Output
2
Input
3
3 3 3
1 1 1
Output
0
Note
The occasions in the first sample case are:
1.l = 4,r = 4 since max{2} = min{2}.
2.l = 4,r = 5 since max{2, 1} = min{2, 3}.
There are no occasions in the second sample case since Mike will answer 3 to any query pair, but !Mike will always answer 1.
Submitted Solution:
```
def solve():
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
maxi=a[0]
mini=b[0]
count=0
if maxi==mini:
count+=1
flag=0
for i in range(1,n):
if flag==1:
maxi=a[i]
mini=b[i]
flag=0
#print(mini,maxi,a[i])
if a[i]==b[i] :
count+=1
#print("lol")
if a[i]>b[i] and i<n-1:
flag=1
elif a[i]>maxi:
maxi=a[i]
elif b[i]<mini :
#print(mini,maxi)
mini=b[i]
if maxi==mini and a[i]!=b[i] :
count+=1
#print("FOL",a[i],b[i])
#print(maxi,mini)
print(count)
solve()
``` | instruction | 0 | 28,711 | 11 | 57,422 |
No | output | 1 | 28,711 | 11 | 57,423 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) β who knows?
Every one of them has an integer sequences a and b of length n. Being given a query of the form of pair of integers (l, r), Mike can instantly tell the value of <image> while !Mike can instantly tell the value of <image>.
Now suppose a robot (you!) asks them all possible different queries of pairs of integers (l, r) (1 β€ l β€ r β€ n) (so he will make exactly n(n + 1) / 2 queries) and counts how many times their answers coincide, thus for how many pairs <image> is satisfied.
How many occasions will the robot count?
Input
The first line contains only integer n (1 β€ n β€ 200 000).
The second line contains n integer numbers a1, a2, ..., an ( - 109 β€ ai β€ 109) β the sequence a.
The third line contains n integer numbers b1, b2, ..., bn ( - 109 β€ bi β€ 109) β the sequence b.
Output
Print the only integer number β the number of occasions the robot will count, thus for how many pairs <image> is satisfied.
Examples
Input
6
1 2 3 2 1 4
6 7 1 2 3 2
Output
2
Input
3
3 3 3
1 1 1
Output
0
Note
The occasions in the first sample case are:
1.l = 4,r = 4 since max{2} = min{2}.
2.l = 4,r = 5 since max{2, 1} = min{2, 3}.
There are no occasions in the second sample case since Mike will answer 3 to any query pair, but !Mike will always answer 1.
Submitted Solution:
```
def solve():
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
maxi=a[0]
mini=b[0]
count=0
mxi=0
mni=0
if maxi==mini:
count+=1
flag=0
for i in range(1,n):
if flag==1:
maxi=a[i]
mini=b[i]
mxi=i;mni=i
flag=0
#print(mini,maxi,a[i])
if a[i]==b[i] :
count+=1
#print("lol")
if a[i]>b[i] and i<n-1:
flag=1
elif a[i]>maxi:
maxi=a[i]
elif b[i]<mini :
#print(mini,maxi)
mini=b[i]
if maxi==mini :
count+=i-mni
#print("FOL",a[i],b[i])
#print(maxi,mini)
print(count)
solve()
``` | instruction | 0 | 28,712 | 11 | 57,424 |
No | output | 1 | 28,712 | 11 | 57,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.
Input
Same as the easy version, but the limits have changed: 1 β€ n, k β€ 400 000.
Output
Same as the easy version.
Examples
Input
4 100
1 2 2 1
Output
2
Input
4 1
1 2 2 1
Output
3
Input
4 2
1 2 3 1
Output
3
Submitted Solution:
```
R = lambda:map(int, input().split())
stack= []
n, k = R()
l = list(R())
curr,tot = 0,0
for i in range(n):
if l[i] not in stack:
if curr<k:
curr = curr+1
else:
c,z=0,-1
for j in range(k):
if stack[j] not in l[i:]:
z=j
stack.pop(z)
break
if z!=-1:
for j in range(k):
if stack[j] not in l[i:i+2*k]:
z=j
break
else:
c= max(c,i+l[i:].index(stack[j]))
stack.pop(z) if z != -1 else stack.remove(l[c])
stack.insert(0,l[i])
tot+=1
print(tot)
``` | instruction | 0 | 28,768 | 11 | 57,536 |
No | output | 1 | 28,768 | 11 | 57,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.
Input
Same as the easy version, but the limits have changed: 1 β€ n, k β€ 400 000.
Output
Same as the easy version.
Examples
Input
4 100
1 2 2 1
Output
2
Input
4 1
1 2 2 1
Output
3
Input
4 2
1 2 3 1
Output
3
Submitted Solution:
```
import heapq
def bs(x, y):
global loc
l = 0
r = len(loc[y])
while r - l > 1:
m = (l + r) // 2
if loc[y][m] > x:
r = m
else:
l = m
return l
def f(k):
global heap
i = 0
while heap[i][1] != k:
i += 1
return i
def push(x):
global heap
heap.append(x)
pos = len(heap) - 1
while pos > 0 and heap[pos] > heap[(pos - 1) // 2]:
heap[pos], heap[(pos - 1) // 2] = heap[(pos - 1) // 2], heap[pos]
pos = (pos - 1) // 2
def delete(x):
global heap
pos = heap.index(x)
while pos * 2 + 1 < len(heap):
if pos * 2 + 2 == len(heap) or (pos * 2 + 2 < len(heap) and heap[pos * 2 + 1] > heap[pos * 2 + 2]):
heap[pos], heap[pos * 2 + 1] = heap[pos * 2 + 1], heap[pos]
pos = pos * 2 + 1
else:
heap[pos], heap[pos * 2 + 2] = heap[pos * 2 + 2], heap[pos]
pos = pos * 2 + 2
heap.pop(pos)
n, k = map(int, input().split())
a = list(map(int, input().split()))
books = set()
l = 0
pref = [0 for i in range(n)]
loc = [[] for i in range(n)]
for i in range(n):
loc[a[i] - 1].append(i)
heap = []
for i in range(n - 1, -1, -1):
pref[a[i] - 1] = max(pref[a[i] - 1], i) # i min == 0
res = 0
for i in range(n):
if a[i] not in books:
if l == k:
books.discard(heapq._heappop_max(heap)[1])
l -= 1
res += 1
books.add(a[i])
ind = bs(i, a[i] - 1)
if ind == len(loc[a[i] - 1]) - 1:
push([float('inf'), a[i]])
else:
push([loc[a[i] - 1][ind + 1], a[i]])
l += 1
else:
if i == pref[a[i] - 1]:
delete(heap[f(a[i])])
books.discard(a[i])
l -= 1
print(res)
``` | instruction | 0 | 28,769 | 11 | 57,538 |
No | output | 1 | 28,769 | 11 | 57,539 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.
Input
Same as the easy version, but the limits have changed: 1 β€ n, k β€ 400 000.
Output
Same as the easy version.
Examples
Input
4 100
1 2 2 1
Output
2
Input
4 1
1 2 2 1
Output
3
Input
4 2
1 2 3 1
Output
3
Submitted Solution:
```
import sys
input = sys.stdin.readline
from collections import deque, defaultdict
from heapq import heappush, heappop
n, k = map(int, input().split())
A = list(map(int, input().split()))
dic = defaultdict(deque)
for i, a in enumerate(A):
dic[a].append(i)
S = set()
ans = 0
hp = []
for d in dic:
heappush(hp, (-dic[d][0], d))
for i, a in enumerate(A):
# for d in dic:
# while dic[d] and dic[d][0] <= i:
# dic[d].popleft()
# if dic[d]: heappush(hp, (-dic[d][0], d))
if a not in S:
if len(S) < k:
S.add(a)
ans += 1
else:
while hp and (-hp[0][0] <= i or hp[0][1] not in S):
heappop(hp)
idx = hp[0][1] if hp else -1
S.discard(idx)
S.add(a)
ans += 1
if a in dic:
dic[a].popleft()
if dic[a]: heappush(hp, (-dic[a][0], a))
else: heappush(hp, (float("-inf"), a))
else:
heappush(hp, (float("-inf"), a))
print(ans)
``` | instruction | 0 | 28,770 | 11 | 57,540 |
No | output | 1 | 28,770 | 11 | 57,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Pavlopolis University where Noora studies it was decided to hold beauty contest "Miss Pavlopolis University". Let's describe the process of choosing the most beautiful girl in the university in more detail.
The contest is held in several stages. Suppose that exactly n girls participate in the competition initially. All the participants are divided into equal groups, x participants in each group. Furthermore the number x is chosen arbitrarily, i. e. on every stage number x can be different. Within each group the jury of the contest compares beauty of the girls in the format "each with each". In this way, if group consists of x girls, then <image> comparisons occur. Then, from each group, the most beautiful participant is selected. Selected girls enter the next stage of the competition. Thus if n girls were divided into groups, x participants in each group, then exactly <image> participants will enter the next stage. The contest continues until there is exactly one girl left who will be "Miss Pavlopolis University"
But for the jury this contest is a very tedious task. They would like to divide the girls into groups in each stage so that the total number of pairwise comparisons of the girls is as few as possible. Let f(n) be the minimal total number of comparisons that should be made to select the most beautiful participant, if we admit n girls to the first stage.
The organizers of the competition are insane. They give Noora three integers t, l and r and ask the poor girl to calculate the value of the following expression: t0Β·f(l) + t1Β·f(l + 1) + ... + tr - lΒ·f(r). However, since the value of this expression can be quite large the organizers ask her to calculate it modulo 109 + 7. If Noora can calculate the value of this expression the organizers promise her to help during the beauty contest. But the poor girl is not strong in mathematics, so she turned for help to Leha and he turned to you.
Input
The first and single line contains three integers t, l and r (1 β€ t < 109 + 7, 2 β€ l β€ r β€ 5Β·106).
Output
In the first line print single integer β the value of the expression modulo 109 + 7.
Example
Input
2 2 4
Output
19
Note
Consider the sample.
It is necessary to find the value of <image>.
f(2) = 1. From two girls you can form only one group of two people, in which there will be one comparison.
f(3) = 3. From three girls you can form only one group of three people, in which there will be three comparisons.
f(4) = 3. From four girls you can form two groups of two girls each. Then at the first stage there will be two comparisons, one in each of the two groups. In the second stage there will be two girls and there will be one comparison between them. Total 2 + 1 = 3 comparisons. You can also leave all girls in same group in the first stage. Then <image> comparisons will occur. Obviously, it's better to split girls into groups in the first way.
Then the value of the expression is <image>.
Submitted Solution:
```
mod=10**9+7
par=[int(i) for i in str(input()).split()]
t,l,r=par[0],par[1],par[2]
t_power=[0 for i in range(r-l+1)]
t_power[0]=1
for i in range(1,r-l+1):
t_power[i]=(t_power[i-1]*t)%mod
f_list=[0 for i in range(r+1)]
f_list[2]=1
f_list[3]=3
tot=0
for i in range(1,r+1):
if i<4:
if i>=l:
tot=(tot+(t_power[i-l]*(f_list[i]%mod))%mod)%mod
continue
if i%2==0:
a=int(i/2)
else:
a=int((i+3)/2)
f_list[i]=a+f_list[int(i//2)]
if i>=l:
tot=(tot+(t_power[i-l]*(f_list[i]%mod))%mod)%mod
#print(t_power)
#print(f_list)
print(tot)
``` | instruction | 0 | 28,772 | 11 | 57,544 |
No | output | 1 | 28,772 | 11 | 57,545 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Pavlopolis University where Noora studies it was decided to hold beauty contest "Miss Pavlopolis University". Let's describe the process of choosing the most beautiful girl in the university in more detail.
The contest is held in several stages. Suppose that exactly n girls participate in the competition initially. All the participants are divided into equal groups, x participants in each group. Furthermore the number x is chosen arbitrarily, i. e. on every stage number x can be different. Within each group the jury of the contest compares beauty of the girls in the format "each with each". In this way, if group consists of x girls, then <image> comparisons occur. Then, from each group, the most beautiful participant is selected. Selected girls enter the next stage of the competition. Thus if n girls were divided into groups, x participants in each group, then exactly <image> participants will enter the next stage. The contest continues until there is exactly one girl left who will be "Miss Pavlopolis University"
But for the jury this contest is a very tedious task. They would like to divide the girls into groups in each stage so that the total number of pairwise comparisons of the girls is as few as possible. Let f(n) be the minimal total number of comparisons that should be made to select the most beautiful participant, if we admit n girls to the first stage.
The organizers of the competition are insane. They give Noora three integers t, l and r and ask the poor girl to calculate the value of the following expression: t0Β·f(l) + t1Β·f(l + 1) + ... + tr - lΒ·f(r). However, since the value of this expression can be quite large the organizers ask her to calculate it modulo 109 + 7. If Noora can calculate the value of this expression the organizers promise her to help during the beauty contest. But the poor girl is not strong in mathematics, so she turned for help to Leha and he turned to you.
Input
The first and single line contains three integers t, l and r (1 β€ t < 109 + 7, 2 β€ l β€ r β€ 5Β·106).
Output
In the first line print single integer β the value of the expression modulo 109 + 7.
Example
Input
2 2 4
Output
19
Note
Consider the sample.
It is necessary to find the value of <image>.
f(2) = 1. From two girls you can form only one group of two people, in which there will be one comparison.
f(3) = 3. From three girls you can form only one group of three people, in which there will be three comparisons.
f(4) = 3. From four girls you can form two groups of two girls each. Then at the first stage there will be two comparisons, one in each of the two groups. In the second stage there will be two girls and there will be one comparison between them. Total 2 + 1 = 3 comparisons. You can also leave all girls in same group in the first stage. Then <image> comparisons will occur. Obviously, it's better to split girls into groups in the first way.
Then the value of the expression is <image>.
Submitted Solution:
```
import sys
import math
input = sys.stdin.readline
from functools import cmp_to_key;
def pi():
return(int(input()))
def pl():
return(int(input(), 16))
def ti():
return(list(map(int,input().split())))
def ts():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
mod = 1000000007;
f = [];
def fact(n,m):
global f;
f = [1 for i in range(n+1)];
f[0] = 1;
for i in range(1,n+1):
f[i] = (f[i-1]*i)%m;
def fast_mod_exp(a,b,m):
res = 1;
while b > 0:
if b & 1:
res = (res*a)%m;
a = (a*a)%m;
b = b >> 1;
return res;
def inverseMod(n,m):
return fast_mod_exp(n,m-2,m);
def ncr(n,r,m):
if n < 0 or r < 0 or r > n: return 0;
if r == 0: return 1;
return ((f[n]*inverseMod(f[n-r],m))%m*inverseMod(f[r],m))%m;
def main():
D();
def XC():
n = pi();
a = ti();
sm = [0 for i in range(n)];
for i in range(n):
if i == 0:
sm[i] = a[i];
continue;
sm[i] = sm[i-1]+a[i];
dp01 = [-1000000000 for i in range(n)];
x = [[] for i in range(n)];
for i in range(n):
for j in range(i,-1,-1):
#dp01[i] = max(dp01[i], sm[j-1]-(sm[i]-sm[j-1]) if j != 0 else sm[i]);
if j != 0:
if dp01[i] < sm[j-1]-(sm[i]-sm[j-1]):
dp01[i] = sm[j-1]-(sm[i]-sm[j-1]);
x[i] = [j-1,i+1];
else:
if dp01[i] < sm[i]:
dp01[i] = sm[i];
x[i] = [0,i+1];
dp12 = [-1000000000 for i in range(n)];
mx = -1000000000;
mxIndex2 = 0;
mxIndex1 = 0;
for i in range(n):
for j in range(i,-1,-1):
#dp12[i] = max(dp12[i], dp01[j]+sm[i]-sm[j]-(sm[n-1]-sm[i]));
if dp12[i] < dp01[j]+sm[i]-sm[j]-(sm[n-1]-sm[i]):
dp12[i] = dp01[j]+sm[i]-sm[j]-(sm[n-1]-sm[i]);
if dp12[i] > mx:
mx = dp12[i];
mxIndex2 = i+1;
mxIndex1 = j;
ans = [x[mxIndex1][0], x[mxIndex1][1], mxIndex2];
print('sum', sm);
print(dp01);
# print(mx);
# print(*ans);
def getMinPrimeFactor(n):
mn = 2;
primes = [-1 for i in range(n+1)];
for i in range(2,math.floor(math.sqrt(n+1))):
if primes[i] == 0: continue;
j = 2;
while i*j <= n:
primes[i*j] = 0;
j += 1;
if n%i == 0: mn = min(mn,i);
return mn;
def D():
[t,l,r] = ti();
isPrime = [1 for i in range(r+1)];
sp = [i for i in range(r+1)];
for i in range(2,math.floor(math.sqrt(r))+1):
if isPrime[i] == 0: continue;
j = 2;
while i*j < r+1:
isPrime[i*j] = 0;
sp[i*j] = i;
j += 1;
dp = [0 for i in range(r+1)];
dp[0],dp[1],dp[2] = 0,0,1;
for i in range(3,r+1):
if isPrime[i]:
dp[i] = int(i*(i-1)/2)%mod;
continue;
f = sp[i];
dp[i] = 1000000000000000000000000;
dp[i] = min(dp[i],((int(i/f)*dp[f])%mod+(dp[int(i/f)])%mod)%mod);
ans = 0;
for i in range(l,r+1):
ans = (ans%mod + (fast_mod_exp(t,i-l,mod)*dp[i])%mod)%mod;
print(int(ans));
main();
``` | instruction | 0 | 28,773 | 11 | 57,546 |
No | output | 1 | 28,773 | 11 | 57,547 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Pavlopolis University where Noora studies it was decided to hold beauty contest "Miss Pavlopolis University". Let's describe the process of choosing the most beautiful girl in the university in more detail.
The contest is held in several stages. Suppose that exactly n girls participate in the competition initially. All the participants are divided into equal groups, x participants in each group. Furthermore the number x is chosen arbitrarily, i. e. on every stage number x can be different. Within each group the jury of the contest compares beauty of the girls in the format "each with each". In this way, if group consists of x girls, then <image> comparisons occur. Then, from each group, the most beautiful participant is selected. Selected girls enter the next stage of the competition. Thus if n girls were divided into groups, x participants in each group, then exactly <image> participants will enter the next stage. The contest continues until there is exactly one girl left who will be "Miss Pavlopolis University"
But for the jury this contest is a very tedious task. They would like to divide the girls into groups in each stage so that the total number of pairwise comparisons of the girls is as few as possible. Let f(n) be the minimal total number of comparisons that should be made to select the most beautiful participant, if we admit n girls to the first stage.
The organizers of the competition are insane. They give Noora three integers t, l and r and ask the poor girl to calculate the value of the following expression: t0Β·f(l) + t1Β·f(l + 1) + ... + tr - lΒ·f(r). However, since the value of this expression can be quite large the organizers ask her to calculate it modulo 109 + 7. If Noora can calculate the value of this expression the organizers promise her to help during the beauty contest. But the poor girl is not strong in mathematics, so she turned for help to Leha and he turned to you.
Input
The first and single line contains three integers t, l and r (1 β€ t < 109 + 7, 2 β€ l β€ r β€ 5Β·106).
Output
In the first line print single integer β the value of the expression modulo 109 + 7.
Example
Input
2 2 4
Output
19
Note
Consider the sample.
It is necessary to find the value of <image>.
f(2) = 1. From two girls you can form only one group of two people, in which there will be one comparison.
f(3) = 3. From three girls you can form only one group of three people, in which there will be three comparisons.
f(4) = 3. From four girls you can form two groups of two girls each. Then at the first stage there will be two comparisons, one in each of the two groups. In the second stage there will be two girls and there will be one comparison between them. Total 2 + 1 = 3 comparisons. You can also leave all girls in same group in the first stage. Then <image> comparisons will occur. Obviously, it's better to split girls into groups in the first way.
Then the value of the expression is <image>.
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 29 22:25:54 2018
@author: subhash
"""
def smallest_fac(n):
for i in range(2, int(n**0.5)+1):
if n%i == 0:
return i
return n
def f(n):
i = 0
sf = smallest_fac(n)
if smallest_fac(n) == n:
return n*(n-1)//2
else:
i+=n//sf * dp[sf] + f(n//sf)
return i
t, l, r = map(int, input().split())
dp = [0]*(r+1)
dp[2] = 1
dp[3] = 3
answer = 0
for i in range(4, len(dp)):
dp[i] = f(i)
for i in range(r-l + 1):
answer+=t**i * dp[l+i]
answer%=10**9 + 7
print(dp)
print(answer)
``` | instruction | 0 | 28,774 | 11 | 57,548 |
No | output | 1 | 28,774 | 11 | 57,549 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Pavlopolis University where Noora studies it was decided to hold beauty contest "Miss Pavlopolis University". Let's describe the process of choosing the most beautiful girl in the university in more detail.
The contest is held in several stages. Suppose that exactly n girls participate in the competition initially. All the participants are divided into equal groups, x participants in each group. Furthermore the number x is chosen arbitrarily, i. e. on every stage number x can be different. Within each group the jury of the contest compares beauty of the girls in the format "each with each". In this way, if group consists of x girls, then <image> comparisons occur. Then, from each group, the most beautiful participant is selected. Selected girls enter the next stage of the competition. Thus if n girls were divided into groups, x participants in each group, then exactly <image> participants will enter the next stage. The contest continues until there is exactly one girl left who will be "Miss Pavlopolis University"
But for the jury this contest is a very tedious task. They would like to divide the girls into groups in each stage so that the total number of pairwise comparisons of the girls is as few as possible. Let f(n) be the minimal total number of comparisons that should be made to select the most beautiful participant, if we admit n girls to the first stage.
The organizers of the competition are insane. They give Noora three integers t, l and r and ask the poor girl to calculate the value of the following expression: t0Β·f(l) + t1Β·f(l + 1) + ... + tr - lΒ·f(r). However, since the value of this expression can be quite large the organizers ask her to calculate it modulo 109 + 7. If Noora can calculate the value of this expression the organizers promise her to help during the beauty contest. But the poor girl is not strong in mathematics, so she turned for help to Leha and he turned to you.
Input
The first and single line contains three integers t, l and r (1 β€ t < 109 + 7, 2 β€ l β€ r β€ 5Β·106).
Output
In the first line print single integer β the value of the expression modulo 109 + 7.
Example
Input
2 2 4
Output
19
Note
Consider the sample.
It is necessary to find the value of <image>.
f(2) = 1. From two girls you can form only one group of two people, in which there will be one comparison.
f(3) = 3. From three girls you can form only one group of three people, in which there will be three comparisons.
f(4) = 3. From four girls you can form two groups of two girls each. Then at the first stage there will be two comparisons, one in each of the two groups. In the second stage there will be two girls and there will be one comparison between them. Total 2 + 1 = 3 comparisons. You can also leave all girls in same group in the first stage. Then <image> comparisons will occur. Obviously, it's better to split girls into groups in the first way.
Then the value of the expression is <image>.
Submitted Solution:
```
t,l,r=map(int,input().split())
def f(n):
if(n%2!=0):
return n*(n-1)//2
else:
k=n//2
d=k+f(k)
return d
k=0
s=0
for i in range(l,r+1):
s+=(pow(t,k,100000007)*f(i)%100000007)%100000007
k+=1
print(s)
``` | instruction | 0 | 28,775 | 11 | 57,550 |
No | output | 1 | 28,775 | 11 | 57,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.
The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
Constraints
* 1 \leq k \leq 15
* S is a string of length k consisting of `o` and `x`.
Input
Input is given from Standard Input in the following format:
S
Output
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise.
Examples
Input
oxoxoxoxoxoxox
Output
YES
Input
xxxxxxxx
Output
NO
Submitted Solution:
```
c = input()
if c.count('x') <= 7:
print("YES")
else:
print("NO")
``` | instruction | 0 | 28,900 | 11 | 57,800 |
Yes | output | 1 | 28,900 | 11 | 57,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.
The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
Constraints
* 1 \leq k \leq 15
* S is a string of length k consisting of `o` and `x`.
Input
Input is given from Standard Input in the following format:
S
Output
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise.
Examples
Input
oxoxoxoxoxoxox
Output
YES
Input
xxxxxxxx
Output
NO
Submitted Solution:
```
S = input()
if 15-len(S)+S.count("o")>=8:
print("YES")
else:
print("NO")
``` | instruction | 0 | 28,901 | 11 | 57,802 |
Yes | output | 1 | 28,901 | 11 | 57,803 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.
The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
Constraints
* 1 \leq k \leq 15
* S is a string of length k consisting of `o` and `x`.
Input
Input is given from Standard Input in the following format:
S
Output
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise.
Examples
Input
oxoxoxoxoxoxox
Output
YES
Input
xxxxxxxx
Output
NO
Submitted Solution:
```
print("YES" if input().count('x') <= 7 else "NO")
``` | instruction | 0 | 28,902 | 11 | 57,804 |
Yes | output | 1 | 28,902 | 11 | 57,805 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.
The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
Constraints
* 1 \leq k \leq 15
* S is a string of length k consisting of `o` and `x`.
Input
Input is given from Standard Input in the following format:
S
Output
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise.
Examples
Input
oxoxoxoxoxoxox
Output
YES
Input
xxxxxxxx
Output
NO
Submitted Solution:
```
s=input()
make=s.count('x')
if make<=7:
print('YES')
else:
print('NO')
``` | instruction | 0 | 28,903 | 11 | 57,806 |
Yes | output | 1 | 28,903 | 11 | 57,807 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.
The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
Constraints
* 1 \leq k \leq 15
* S is a string of length k consisting of `o` and `x`.
Input
Input is given from Standard Input in the following format:
S
Output
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise.
Examples
Input
oxoxoxoxoxoxox
Output
YES
Input
xxxxxxxx
Output
NO
Submitted Solution:
```
s = input()
count = 0
for i in range(len(s)):
if s[i] == 'o':
count += 1
#print(count)
rest = 8 - count
#if count > 7:
if 15 - len(s) > 0:
print('YES')
else:
print('NO')
``` | instruction | 0 | 28,904 | 11 | 57,808 |
No | output | 1 | 28,904 | 11 | 57,809 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.
The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
Constraints
* 1 \leq k \leq 15
* S is a string of length k consisting of `o` and `x`.
Input
Input is given from Standard Input in the following format:
S
Output
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise.
Examples
Input
oxoxoxoxoxoxox
Output
YES
Input
xxxxxxxx
Output
NO
Submitted Solution:
```
print("YNeos"[input().count("x")>8::2])
``` | instruction | 0 | 28,905 | 11 | 57,810 |
No | output | 1 | 28,905 | 11 | 57,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.
The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
Constraints
* 1 \leq k \leq 15
* S is a string of length k consisting of `o` and `x`.
Input
Input is given from Standard Input in the following format:
S
Output
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise.
Examples
Input
oxoxoxoxoxoxox
Output
YES
Input
xxxxxxxx
Output
NO
Submitted Solution:
```
# -*- coding: utf-8 -*-
s= input()
day= len(s)
win = s.count('o')
possibility=day+win
if possibility >= 8:
print('Yes')
else:
print('No')
``` | instruction | 0 | 28,906 | 11 | 57,812 |
No | output | 1 | 28,906 | 11 | 57,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.
The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
Constraints
* 1 \leq k \leq 15
* S is a string of length k consisting of `o` and `x`.
Input
Input is given from Standard Input in the following format:
S
Output
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise.
Examples
Input
oxoxoxoxoxoxox
Output
YES
Input
xxxxxxxx
Output
NO
Submitted Solution:
```
s = input()
if s.count("x")>7:
print("No")
else:
print("Yes")
``` | instruction | 0 | 28,907 | 11 | 57,814 |
No | output | 1 | 28,907 | 11 | 57,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class.
In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exam score was used as is. All students with a final exam score of less than 40 received supplementary lessons and scored 40 points.
Create a program that calculates the average score of the five students' grades given the final exam scores of the five students.
Example
Input
10
65
100
30
95
Output
68
Submitted Solution:
```
tensu=[]
i=0
while i<5:
s=int(input())
tensu.append(s)
i+=1
sum=0
for i in range(5):
if tensu[i]>=40:
sum+=tensu[i]
else:
sum+=40
ave=sum//5
print(ave)
``` | instruction | 0 | 29,026 | 11 | 58,052 |
Yes | output | 1 | 29,026 | 11 | 58,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class.
In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exam score was used as is. All students with a final exam score of less than 40 received supplementary lessons and scored 40 points.
Create a program that calculates the average score of the five students' grades given the final exam scores of the five students.
Example
Input
10
65
100
30
95
Output
68
Submitted Solution:
```
x=[]
sum=0
for i in range(5):
n=int(input())
if n<=40:
n=40
sum+=n
x.append(n)
print(sum//5)
``` | instruction | 0 | 29,027 | 11 | 58,054 |
Yes | output | 1 | 29,027 | 11 | 58,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class.
In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exam score was used as is. All students with a final exam score of less than 40 received supplementary lessons and scored 40 points.
Create a program that calculates the average score of the five students' grades given the final exam scores of the five students.
Example
Input
10
65
100
30
95
Output
68
Submitted Solution:
```
a=[]
for i in range(5):
n=int(input())
a.append(n)
for _ in range(5):
if a[_]<40:
a[_]=40
sum=0
for l in range(5):
b=a[l]
sum+=b
av=sum//5
print(av)
``` | instruction | 0 | 29,028 | 11 | 58,056 |
Yes | output | 1 | 29,028 | 11 | 58,057 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class.
In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exam score was used as is. All students with a final exam score of less than 40 received supplementary lessons and scored 40 points.
Create a program that calculates the average score of the five students' grades given the final exam scores of the five students.
Example
Input
10
65
100
30
95
Output
68
Submitted Solution:
```
a=[]
for i in range(5):
b=int(input())
if b<40:
b=40
a.append(b)
print(sum(a)//len(a))
``` | instruction | 0 | 29,029 | 11 | 58,058 |
Yes | output | 1 | 29,029 | 11 | 58,059 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, β¦, x_n, correspondingly. One of the participants wrote down this sequence in a notebook.
They visited it again the following day, and the number of stones in piles was equal to y_1, y_2, β¦, y_n. One of the participants also wrote it down in a notebook.
It is well known that every member of the EJOI jury during the night either sits in the room 108 or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.
Participants want to know whether their notes can be correct or they are sure to have made a mistake.
Input
The first line of the input file contains a single integer n, the number of piles with stones in the garden (1 β€ n β€ 50).
The second line contains n integers separated by spaces x_1, x_2, β¦, x_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time (0 β€ x_i β€ 1000).
The third line contains n integers separated by spaces y_1, y_2, β¦, y_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time (0 β€ y_i β€ 1000).
Output
If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).
Examples
Input
5
1 2 3 4 5
2 1 4 3 5
Output
Yes
Input
5
1 1 1 1 1
1 0 1 0 1
Output
Yes
Input
3
2 3 9
1 7 9
Output
No
Note
In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.
In the second example, the jury took stones from the second and fourth piles.
It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.
Submitted Solution:
```
n=int(input())
x=0
y=0
xi=[int(i) for i in input().split()]
yi=[int(i) for i in input().split()]
x=sum(xi)
y=sum(yi)
if x>=y:
print("Yes")
else:
print("No")
``` | instruction | 0 | 29,107 | 11 | 58,214 |
Yes | output | 1 | 29,107 | 11 | 58,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, β¦, x_n, correspondingly. One of the participants wrote down this sequence in a notebook.
They visited it again the following day, and the number of stones in piles was equal to y_1, y_2, β¦, y_n. One of the participants also wrote it down in a notebook.
It is well known that every member of the EJOI jury during the night either sits in the room 108 or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.
Participants want to know whether their notes can be correct or they are sure to have made a mistake.
Input
The first line of the input file contains a single integer n, the number of piles with stones in the garden (1 β€ n β€ 50).
The second line contains n integers separated by spaces x_1, x_2, β¦, x_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time (0 β€ x_i β€ 1000).
The third line contains n integers separated by spaces y_1, y_2, β¦, y_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time (0 β€ y_i β€ 1000).
Output
If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).
Examples
Input
5
1 2 3 4 5
2 1 4 3 5
Output
Yes
Input
5
1 1 1 1 1
1 0 1 0 1
Output
Yes
Input
3
2 3 9
1 7 9
Output
No
Note
In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.
In the second example, the jury took stones from the second and fourth piles.
It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.
Submitted Solution:
```
num_piles=int(input())
l1=[]
l2=[]
s1=input()
s2=input()
l1=s1.split(" ")
l2=s2.split(" ")
"""
for i in s1:
if i != ' ':
l1.append(int(i))
for i in s2:
if i != ' ':
l2.append(int(i))
"""
sum1=0
sum2=0
for i in range (num_piles):
sum1+=int(l1[i])
sum2+=int(l2[i])
if sum1 >= sum2:
print("YES")
else:
print ("NO")
``` | instruction | 0 | 29,108 | 11 | 58,216 |
Yes | output | 1 | 29,108 | 11 | 58,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, β¦, x_n, correspondingly. One of the participants wrote down this sequence in a notebook.
They visited it again the following day, and the number of stones in piles was equal to y_1, y_2, β¦, y_n. One of the participants also wrote it down in a notebook.
It is well known that every member of the EJOI jury during the night either sits in the room 108 or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.
Participants want to know whether their notes can be correct or they are sure to have made a mistake.
Input
The first line of the input file contains a single integer n, the number of piles with stones in the garden (1 β€ n β€ 50).
The second line contains n integers separated by spaces x_1, x_2, β¦, x_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time (0 β€ x_i β€ 1000).
The third line contains n integers separated by spaces y_1, y_2, β¦, y_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time (0 β€ y_i β€ 1000).
Output
If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).
Examples
Input
5
1 2 3 4 5
2 1 4 3 5
Output
Yes
Input
5
1 1 1 1 1
1 0 1 0 1
Output
Yes
Input
3
2 3 9
1 7 9
Output
No
Note
In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.
In the second example, the jury took stones from the second and fourth piles.
It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.
Submitted Solution:
```
n = int(input())
x = sorted(list(map(int, input().split())))
y = sorted(list(map(int, input().split())))
if sum(y) <= sum(x):
print('Yes')
else:
print('No')
``` | instruction | 0 | 29,109 | 11 | 58,218 |
Yes | output | 1 | 29,109 | 11 | 58,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, β¦, x_n, correspondingly. One of the participants wrote down this sequence in a notebook.
They visited it again the following day, and the number of stones in piles was equal to y_1, y_2, β¦, y_n. One of the participants also wrote it down in a notebook.
It is well known that every member of the EJOI jury during the night either sits in the room 108 or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.
Participants want to know whether their notes can be correct or they are sure to have made a mistake.
Input
The first line of the input file contains a single integer n, the number of piles with stones in the garden (1 β€ n β€ 50).
The second line contains n integers separated by spaces x_1, x_2, β¦, x_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time (0 β€ x_i β€ 1000).
The third line contains n integers separated by spaces y_1, y_2, β¦, y_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time (0 β€ y_i β€ 1000).
Output
If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).
Examples
Input
5
1 2 3 4 5
2 1 4 3 5
Output
Yes
Input
5
1 1 1 1 1
1 0 1 0 1
Output
Yes
Input
3
2 3 9
1 7 9
Output
No
Note
In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.
In the second example, the jury took stones from the second and fourth piles.
It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.
Submitted Solution:
```
n = int(input())
if (sum(list(map(int, input().split()))) < sum(list(map(int, input().split())))):
print('No')
else:
print('Yes')
``` | instruction | 0 | 29,110 | 11 | 58,220 |
Yes | output | 1 | 29,110 | 11 | 58,221 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, β¦, x_n, correspondingly. One of the participants wrote down this sequence in a notebook.
They visited it again the following day, and the number of stones in piles was equal to y_1, y_2, β¦, y_n. One of the participants also wrote it down in a notebook.
It is well known that every member of the EJOI jury during the night either sits in the room 108 or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.
Participants want to know whether their notes can be correct or they are sure to have made a mistake.
Input
The first line of the input file contains a single integer n, the number of piles with stones in the garden (1 β€ n β€ 50).
The second line contains n integers separated by spaces x_1, x_2, β¦, x_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time (0 β€ x_i β€ 1000).
The third line contains n integers separated by spaces y_1, y_2, β¦, y_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time (0 β€ y_i β€ 1000).
Output
If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).
Examples
Input
5
1 2 3 4 5
2 1 4 3 5
Output
Yes
Input
5
1 1 1 1 1
1 0 1 0 1
Output
Yes
Input
3
2 3 9
1 7 9
Output
No
Note
In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.
In the second example, the jury took stones from the second and fourth piles.
It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.
Submitted Solution:
```
x = sum([int(n) for n in input().split()])
y = sum([int(n) for n in input().split()])
print('Yes' if x >= y else 'No')
``` | instruction | 0 | 29,111 | 11 | 58,222 |
No | output | 1 | 29,111 | 11 | 58,223 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, β¦, x_n, correspondingly. One of the participants wrote down this sequence in a notebook.
They visited it again the following day, and the number of stones in piles was equal to y_1, y_2, β¦, y_n. One of the participants also wrote it down in a notebook.
It is well known that every member of the EJOI jury during the night either sits in the room 108 or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.
Participants want to know whether their notes can be correct or they are sure to have made a mistake.
Input
The first line of the input file contains a single integer n, the number of piles with stones in the garden (1 β€ n β€ 50).
The second line contains n integers separated by spaces x_1, x_2, β¦, x_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time (0 β€ x_i β€ 1000).
The third line contains n integers separated by spaces y_1, y_2, β¦, y_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time (0 β€ y_i β€ 1000).
Output
If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).
Examples
Input
5
1 2 3 4 5
2 1 4 3 5
Output
Yes
Input
5
1 1 1 1 1
1 0 1 0 1
Output
Yes
Input
3
2 3 9
1 7 9
Output
No
Note
In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.
In the second example, the jury took stones from the second and fourth piles.
It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.
Submitted Solution:
```
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
res = sum(x)-sum(y)
s = sum(x)
if(res == 0 or n == s):
print("Yes")
else:
print("No")
``` | instruction | 0 | 29,112 | 11 | 58,224 |
No | output | 1 | 29,112 | 11 | 58,225 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, β¦, x_n, correspondingly. One of the participants wrote down this sequence in a notebook.
They visited it again the following day, and the number of stones in piles was equal to y_1, y_2, β¦, y_n. One of the participants also wrote it down in a notebook.
It is well known that every member of the EJOI jury during the night either sits in the room 108 or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.
Participants want to know whether their notes can be correct or they are sure to have made a mistake.
Input
The first line of the input file contains a single integer n, the number of piles with stones in the garden (1 β€ n β€ 50).
The second line contains n integers separated by spaces x_1, x_2, β¦, x_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time (0 β€ x_i β€ 1000).
The third line contains n integers separated by spaces y_1, y_2, β¦, y_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time (0 β€ y_i β€ 1000).
Output
If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).
Examples
Input
5
1 2 3 4 5
2 1 4 3 5
Output
Yes
Input
5
1 1 1 1 1
1 0 1 0 1
Output
Yes
Input
3
2 3 9
1 7 9
Output
No
Note
In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.
In the second example, the jury took stones from the second and fourth piles.
It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.
Submitted Solution:
```
n = int(input())
a = input().split()
b = input().split()
a = [int(x) for x in a]
b = [int(x) for x in b]
i = s = 0
istrue = True
while i < n :
s+=a[i]-b[i]
if not a[i]-b[i] ** 2 <= 1 :
istrue = False
break
i+=1
if s < 0 or not istrue :
print("NO")
else :
print("YES")
``` | instruction | 0 | 29,113 | 11 | 58,226 |
No | output | 1 | 29,113 | 11 | 58,227 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, β¦, x_n, correspondingly. One of the participants wrote down this sequence in a notebook.
They visited it again the following day, and the number of stones in piles was equal to y_1, y_2, β¦, y_n. One of the participants also wrote it down in a notebook.
It is well known that every member of the EJOI jury during the night either sits in the room 108 or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.
Participants want to know whether their notes can be correct or they are sure to have made a mistake.
Input
The first line of the input file contains a single integer n, the number of piles with stones in the garden (1 β€ n β€ 50).
The second line contains n integers separated by spaces x_1, x_2, β¦, x_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time (0 β€ x_i β€ 1000).
The third line contains n integers separated by spaces y_1, y_2, β¦, y_n, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time (0 β€ y_i β€ 1000).
Output
If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).
Examples
Input
5
1 2 3 4 5
2 1 4 3 5
Output
Yes
Input
5
1 1 1 1 1
1 0 1 0 1
Output
Yes
Input
3
2 3 9
1 7 9
Output
No
Note
In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.
In the second example, the jury took stones from the second and fourth piles.
It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if sum(a[0:len(a)-1]) >= sum(b[0:len(b)-1]):
print("Yes")
else:
print("No")
``` | instruction | 0 | 29,114 | 11 | 58,228 |
No | output | 1 | 29,114 | 11 | 58,229 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n segments [l_i, r_i] for 1 β€ i β€ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
Input
The first line contains one integer T (1 β€ T β€ 50000) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer n (2 β€ n β€ 10^5) β number of segments. It is guaranteed that β{n} over all queries does not exceed 10^5.
The next n lines contains two integers l_i, r_i per line (1 β€ l_i β€ r_i β€ 2 β
10^5) β the i-th segment.
Output
For each query print n integers t_1, t_2, ..., t_n (t_i β \{1, 2\}) β for each segment (in the same order as in the input) t_i equals 1 if the i-th segment will belongs to the first group and 2 otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print -1.
Example
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
Note
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is -1.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of 6 possible is correct.
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
lis=[]
for i in range(n):
a,b = map(int,input().split())
lis.append([a,b,i+1])
lis.sort()
ans=[2]*(n+1)
ans[0]=0
j=lis[0][1]
ans[lis[0][2]]=1
# print(lis,ans)
for i in range(1,n):
a,b,c = lis[i]
# print(a,b,j,c)
if j>=a:
ans[c]=1
# print(c,'c')
j=max(j,b)
# print(ans)
if sum(ans)==n:
print(-1)
else:
print(*ans[1:])
``` | instruction | 0 | 29,159 | 11 | 58,318 |
Yes | output | 1 | 29,159 | 11 | 58,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n segments [l_i, r_i] for 1 β€ i β€ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
Input
The first line contains one integer T (1 β€ T β€ 50000) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer n (2 β€ n β€ 10^5) β number of segments. It is guaranteed that β{n} over all queries does not exceed 10^5.
The next n lines contains two integers l_i, r_i per line (1 β€ l_i β€ r_i β€ 2 β
10^5) β the i-th segment.
Output
For each query print n integers t_1, t_2, ..., t_n (t_i β \{1, 2\}) β for each segment (in the same order as in the input) t_i equals 1 if the i-th segment will belongs to the first group and 2 otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print -1.
Example
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
Note
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is -1.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of 6 possible is correct.
Submitted Solution:
```
for _ in[0]*int(input()):
n=int(input());t=[0]*n;g=c=k=0
a=sorted(sum(zip(*(((l,1,i),(r+1,0,i))for (l,r),i
in((map(int,input().split()),i) for i in range(n)))),()))
for x,m,i in a:
if m:
if c==0:k+=1;g^=1
t[i]=g+1;c+=1
else:c-=1
if k<2:print(-1)
else:print(*t)
``` | instruction | 0 | 29,160 | 11 | 58,320 |
Yes | output | 1 | 29,160 | 11 | 58,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n segments [l_i, r_i] for 1 β€ i β€ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
Input
The first line contains one integer T (1 β€ T β€ 50000) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer n (2 β€ n β€ 10^5) β number of segments. It is guaranteed that β{n} over all queries does not exceed 10^5.
The next n lines contains two integers l_i, r_i per line (1 β€ l_i β€ r_i β€ 2 β
10^5) β the i-th segment.
Output
For each query print n integers t_1, t_2, ..., t_n (t_i β \{1, 2\}) β for each segment (in the same order as in the input) t_i equals 1 if the i-th segment will belongs to the first group and 2 otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print -1.
Example
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
Note
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is -1.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of 6 possible is correct.
Submitted Solution:
```
from sys import stdin
t=int(input())
while(t>0):
n=int(input())
li=[]
for i in range(n):
l,r=[int(x) for x in stdin.readline().split()]
li.append((l,r,i))
li2=sorted(li)
#print(li2)
ans=[2]*n
ans[li2[0][2]]=1
d=li2[0][1]
count=0
for i in range(1,len(li2)):
c=li2[i][0]
if c>d:
count+=1
ans[li2[i][2]]=2
break
else:
ans[li2[i][2]]=1
d=max(d,li2[i][1])
#print(di)
if count==0:
print(-1)
else:
print(*ans)
t-=1
``` | instruction | 0 | 29,161 | 11 | 58,322 |
Yes | output | 1 | 29,161 | 11 | 58,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n segments [l_i, r_i] for 1 β€ i β€ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
Input
The first line contains one integer T (1 β€ T β€ 50000) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer n (2 β€ n β€ 10^5) β number of segments. It is guaranteed that β{n} over all queries does not exceed 10^5.
The next n lines contains two integers l_i, r_i per line (1 β€ l_i β€ r_i β€ 2 β
10^5) β the i-th segment.
Output
For each query print n integers t_1, t_2, ..., t_n (t_i β \{1, 2\}) β for each segment (in the same order as in the input) t_i equals 1 if the i-th segment will belongs to the first group and 2 otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print -1.
Example
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
Note
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is -1.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of 6 possible is correct.
Submitted Solution:
```
def add(Dict, key, value):
if (key in Dict):
Dict[key].append(value)
else:
Dict[key] = [value]
def Coloring(n, data):
assert n == len(data), "Error parsing data and its length"
allCord = set()
opening = dict()
closing = dict()
reference = dict()
for i in range(n):
allCord.add(data[i][0])
allCord.add(data[i][1])
reference[data[i][0]] = i
reference[data[i][1]] = i
add(opening, data[i][0], i)
add(closing, data[i][1], i)
cord = list(allCord)
cord.sort()
groups = []
curGroup = []
active = set()
for i in range(len(cord)):
curCord = cord[i]
op = []
if (curCord in opening):
op = opening[curCord]
for elem in op:
active.add(elem)
curGroup.append(elem)
cl = []
if (curCord in closing):
cl = closing[curCord]
for elem in cl:
active.remove(elem)
if (not bool(active)):
groups.append(curGroup)
curGroup = []
if (len(groups) <= 1):
print("-1")
else:
colors = [None] * n
for elem in groups[0]:
colors[elem] = 1
for i in range(1, len(groups)):
for elem in groups[i]:
colors[elem] = 2
for i in range(n):
print(colors[i], end = " ")
print()
def SolveProblemC():
T = int(input())
for queries in range(T):
n = int(input())
segment_data = []
for segment in range(n):
l, r = map(int, input().split())
segment_data.append([l, r])
Coloring(n, segment_data)
SolveProblemC()
``` | instruction | 0 | 29,162 | 11 | 58,324 |
Yes | output | 1 | 29,162 | 11 | 58,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n segments [l_i, r_i] for 1 β€ i β€ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
Input
The first line contains one integer T (1 β€ T β€ 50000) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer n (2 β€ n β€ 10^5) β number of segments. It is guaranteed that β{n} over all queries does not exceed 10^5.
The next n lines contains two integers l_i, r_i per line (1 β€ l_i β€ r_i β€ 2 β
10^5) β the i-th segment.
Output
For each query print n integers t_1, t_2, ..., t_n (t_i β \{1, 2\}) β for each segment (in the same order as in the input) t_i equals 1 if the i-th segment will belongs to the first group and 2 otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print -1.
Example
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
Note
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is -1.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of 6 possible is correct.
Submitted Solution:
```
import sys
input = sys.stdin.readline
from itertools import accumulate
t = int(input())
for _ in range(t):
n = int(input())
lr = [list(map(int,input().split())) for i in range(n)]
imos = [0]*(max(list(zip(*lr))[1])+2)
for l,r in lr:
imos[l] += 1
imos[r+1] -= 1
acc = list(accumulate(imos))
aacc = list(accumulate(acc))
for i in range(n):
l,r = lr[i]
if aacc[r]-aacc[l-1] == r-l+1:
t = i
break
else:
print(-1)
continue
print(*[2 if t == i else 1 for i in range(n)])
``` | instruction | 0 | 29,163 | 11 | 58,326 |
No | output | 1 | 29,163 | 11 | 58,327 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.